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