Skip to content

Commit 60615b8

Browse files
committed
SIL: Handle captured environments in SILFunction::mapTypeIntoContext()
1 parent 7d0e041 commit 60615b8

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

lib/SIL/IR/SILFunction.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/Expr.h"
1818
#include "swift/AST/GenericEnvironment.h"
1919
#include "swift/AST/IRGenOptions.h"
20+
#include "swift/AST/LocalArchetypeRequirementCollector.h"
2021
#include "swift/AST/Module.h"
2122
#include "swift/AST/Stmt.h"
2223
#include "swift/Basic/OptimizationMode.h"
@@ -492,24 +493,51 @@ bool SILFunction::shouldOptimize() const {
492493
}
493494

494495
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;
497515
}
498516

499517
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());
502530
return type;
503531
}
504532

505533
SILType GenericEnvironment::mapTypeIntoContext(SILModule &M,
506534
SILType type) const {
507-
assert(!type.hasArchetype());
535+
assert(!type.hasPrimaryArchetype());
508536

509537
auto genericSig = getGenericSignature().getCanonicalSignature();
510538
return type.subst(M,
511539
QueryInterfaceTypeSubstitutions(this),
512-
LookUpConformanceInSignature(genericSig.getPointer()),
540+
LookUpConformanceInModule(M.getSwiftModule()),
513541
genericSig,
514542
SubstFlags::PreservePackExpansionLevel);
515543
}

0 commit comments

Comments
 (0)