|
17 | 17 | #include "swift/AST/Expr.h"
|
18 | 18 | #include "swift/AST/GenericEnvironment.h"
|
19 | 19 | #include "swift/AST/IRGenOptions.h"
|
| 20 | +#include "swift/AST/LocalArchetypeRequirementCollector.h" |
20 | 21 | #include "swift/AST/Module.h"
|
21 | 22 | #include "swift/AST/Stmt.h"
|
22 | 23 | #include "swift/Basic/OptimizationMode.h"
|
@@ -492,24 +493,51 @@ bool SILFunction::shouldOptimize() const {
|
492 | 493 | }
|
493 | 494 |
|
494 | 495 | Type SILFunction::mapTypeIntoContext(Type type) const {
|
495 |
| - return GenericEnvironment::mapTypeIntoContext( |
496 |
| - getGenericEnvironment(), type); |
| 496 | + assert(!type->hasPrimaryArchetype()); |
| 497 | + |
| 498 | + if (GenericEnv) { |
| 499 | + // The complication here is that we sometimes call this with an AST interface |
| 500 | + // type, which might contain element archetypes, if it was the interface type |
| 501 | + // of a closure or local variable. |
| 502 | + if (type->hasElementArchetype()) |
| 503 | + return GenericEnv->mapTypeIntoContext(type); |
| 504 | + |
| 505 | + // Otherwise, assume we have an interface type for the "combined" captured |
| 506 | + // environment. |
| 507 | + return type.subst(MapIntoLocalArchetypeContext(GenericEnv, CapturedEnvs), |
| 508 | + LookUpConformanceInModule(Module.getSwiftModule()), |
| 509 | + SubstFlags::AllowLoweredTypes | |
| 510 | + SubstFlags::PreservePackExpansionLevel); |
| 511 | + } |
| 512 | + |
| 513 | + assert(!type->hasTypeParameter()); |
| 514 | + return type; |
497 | 515 | }
|
498 | 516 |
|
499 | 517 | SILType SILFunction::mapTypeIntoContext(SILType type) const {
|
500 |
| - if (auto *genericEnv = getGenericEnvironment()) |
501 |
| - return genericEnv->mapTypeIntoContext(getModule(), type); |
| 518 | + assert(!type.hasPrimaryArchetype()); |
| 519 | + |
| 520 | + if (GenericEnv) { |
| 521 | + auto genericSig = GenericEnv->getGenericSignature().getCanonicalSignature(); |
| 522 | + return type.subst(Module, |
| 523 | + MapIntoLocalArchetypeContext(GenericEnv, CapturedEnvs), |
| 524 | + LookUpConformanceInModule(Module.getSwiftModule()), |
| 525 | + genericSig, |
| 526 | + SubstFlags::PreservePackExpansionLevel); |
| 527 | + } |
| 528 | + |
| 529 | + assert(!type.hasTypeParameter()); |
502 | 530 | return type;
|
503 | 531 | }
|
504 | 532 |
|
505 | 533 | SILType GenericEnvironment::mapTypeIntoContext(SILModule &M,
|
506 | 534 | SILType type) const {
|
507 |
| - assert(!type.hasArchetype()); |
| 535 | + assert(!type.hasPrimaryArchetype()); |
508 | 536 |
|
509 | 537 | auto genericSig = getGenericSignature().getCanonicalSignature();
|
510 | 538 | return type.subst(M,
|
511 | 539 | QueryInterfaceTypeSubstitutions(this),
|
512 |
| - LookUpConformanceInSignature(genericSig.getPointer()), |
| 540 | + LookUpConformanceInModule(M.getSwiftModule()), |
513 | 541 | genericSig,
|
514 | 542 | SubstFlags::PreservePackExpansionLevel);
|
515 | 543 | }
|
|
0 commit comments