Skip to content

Commit 8e5d947

Browse files
committed
SIL: Handle captured environments in SILFunction::mapTypeIntoContext()
1 parent 85f61c5 commit 8e5d947

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

lib/SIL/IR/SILFunction.cpp

Lines changed: 26 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,43 @@ 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+
return type.subst(MapIntoLocalArchetypeContext(GenericEnv, CapturedEnvs),
498+
LookUpConformanceInModule(Module.getSwiftModule()),
499+
SubstFlags::AllowLoweredTypes |
500+
SubstFlags::PreservePackExpansionLevel);
501+
}
502+
503+
assert(!type->hasTypeParameter());
504+
return type;
495505
}
496506

497507
SILType SILFunction::mapTypeIntoContext(SILType type) const {
498-
if (auto *genericEnv = getGenericEnvironment())
499-
return genericEnv->mapTypeIntoContext(getModule(), type);
508+
assert(!type.hasPrimaryArchetype());
509+
510+
if (GenericEnv) {
511+
auto genericSig = GenericEnv->getGenericSignature().getCanonicalSignature();
512+
return type.subst(Module,
513+
MapIntoLocalArchetypeContext(GenericEnv, CapturedEnvs),
514+
LookUpConformanceInModule(Module.getSwiftModule()),
515+
genericSig,
516+
SubstFlags::PreservePackExpansionLevel);
517+
}
518+
519+
assert(!type.hasTypeParameter());
500520
return type;
501521
}
502522

503523
SILType GenericEnvironment::mapTypeIntoContext(SILModule &M,
504524
SILType type) const {
505-
assert(!type.hasArchetype());
525+
assert(!type.hasPrimaryArchetype());
506526

507527
auto genericSig = getGenericSignature().getCanonicalSignature();
508528
return type.subst(M,
509529
QueryInterfaceTypeSubstitutions(this),
510-
LookUpConformanceInSignature(genericSig.getPointer()),
530+
LookUpConformanceInModule(M.getSwiftModule()),
511531
genericSig,
512532
SubstFlags::PreservePackExpansionLevel);
513533
}

0 commit comments

Comments
 (0)