Skip to content

Commit

Permalink
Merge pull request #16379 from DougGregor/sil-cloner-substitution-map
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci authored May 4, 2018
2 parents 7e8bfba + 5b6b335 commit 38cb9e9
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
}

SubstitutionMap getOpSubstitutionMap(SubstitutionMap Subs) {
// If we have open existentials to substitute, check whether that's
// relevant to this this particular substitution.
if (!OpenedExistentialSubs.empty()) {
for (auto ty : Subs.getReplacementTypes()) {
// If we found a type containing an opened existential, substitute
// open existentials throughout the substitution map.
if (ty->hasOpenedExistential()) {
Subs = Subs.subst(QueryTypeSubstitutionMapOrIdentity{
OpenedExistentialSubs},
MakeAbstractConformanceForGenericType());
break;
}
}
}

return asImpl().remapSubstitutionMap(Subs).getCanonical();
}

Expand Down Expand Up @@ -168,21 +183,17 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {

ProtocolConformanceRef getOpConformance(Type ty,
ProtocolConformanceRef conformance) {
auto newConformance =
conformance.subst(ty,
[&](SubstitutableType *t) -> Type {
if (t->isOpenedExistential()) {
auto found = OpenedExistentialSubs.find(
t->castTo<ArchetypeType>());
if (found != OpenedExistentialSubs.end())
return found->second;
return t;
}
return t;
},
MakeAbstractConformanceForGenericType());
// If we have open existentials to substitute, do so now.
if (ty->hasOpenedExistential() && !OpenedExistentialSubs.empty()) {
conformance =
conformance.subst(ty,
QueryTypeSubstitutionMapOrIdentity{
OpenedExistentialSubs},
MakeAbstractConformanceForGenericType());
}

return asImpl().remapConformance(getASTTypeInClonedContext(ty),
newConformance);
conformance);
}

ArrayRef<ProtocolConformanceRef>
Expand Down

0 comments on commit 38cb9e9

Please sign in to comment.