|
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" |
@@ -245,7 +246,6 @@ void SILFunction::init( |
245 | 246 | "function type has open type parameters"); |
246 | 247 |
|
247 | 248 | this->LoweredType = LoweredType; |
248 | | - this->GenericEnv = genericEnv; |
249 | 249 | this->SpecializationInfo = nullptr; |
250 | 250 | this->EntryCount = entryCount; |
251 | 251 | this->Availability = AvailabilityContext::alwaysAvailable(); |
@@ -282,6 +282,7 @@ void SILFunction::init( |
282 | 282 | assert(!Transparent || !IsDynamicReplaceable); |
283 | 283 | validateSubclassScope(classSubclassScope, isThunk, nullptr); |
284 | 284 | setDebugScope(DebugScope); |
| 285 | + setGenericEnvironment(genericEnv); |
285 | 286 | } |
286 | 287 |
|
287 | 288 | SILFunction::~SILFunction() { |
@@ -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 | } |
@@ -1033,14 +1061,10 @@ void SILFunction::eraseAllBlocks() { |
1033 | 1061 | BlockList.clear(); |
1034 | 1062 | } |
1035 | 1063 |
|
1036 | | -SubstitutionMap SILFunction::getForwardingSubstitutionMap() { |
1037 | | - if (ForwardingSubMap) |
1038 | | - return ForwardingSubMap; |
1039 | | - |
1040 | | - if (auto *env = getGenericEnvironment()) |
1041 | | - ForwardingSubMap = env->getForwardingSubstitutionMap(); |
1042 | | - |
1043 | | - return ForwardingSubMap; |
| 1064 | +void SILFunction::setGenericEnvironment(GenericEnvironment *env) { |
| 1065 | + setGenericEnvironment(env, ArrayRef<GenericEnvironment *>(), |
| 1066 | + env ? env->getForwardingSubstitutionMap() |
| 1067 | + : SubstitutionMap()); |
1044 | 1068 | } |
1045 | 1069 |
|
1046 | 1070 | bool SILFunction::shouldVerifyOwnership() const { |
|
0 commit comments