Skip to content

Commit 0de3d6b

Browse files
committed
SIL: Handle captured environments in SILFunction::mapTypeIntoContext()
1 parent 77c3f15 commit 0de3d6b

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
@@ -16,6 +16,7 @@
1616
#include "swift/AST/Availability.h"
1717
#include "swift/AST/Expr.h"
1818
#include "swift/AST/GenericEnvironment.h"
19+
#include "swift/AST/LocalArchetypeRequirementCollector.h"
1920
#include "swift/AST/Module.h"
2021
#include "swift/AST/Stmt.h"
2122
#include "swift/Basic/OptimizationMode.h"
@@ -490,24 +491,51 @@ bool SILFunction::shouldOptimize() const {
490491
}
491492

492493
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;
495513
}
496514

497515
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());
500528
return type;
501529
}
502530

503531
SILType GenericEnvironment::mapTypeIntoContext(SILModule &M,
504532
SILType type) const {
505-
assert(!type.hasArchetype());
533+
assert(!type.hasPrimaryArchetype());
506534

507535
auto genericSig = getGenericSignature().getCanonicalSignature();
508536
return type.subst(M,
509537
QueryInterfaceTypeSubstitutions(this),
510-
LookUpConformanceInSignature(genericSig.getPointer()),
538+
LookUpConformanceInModule(M.getSwiftModule()),
511539
genericSig,
512540
SubstFlags::PreservePackExpansionLevel);
513541
}

0 commit comments

Comments
 (0)