Skip to content

Commit f8b667a

Browse files
committed
Sema: Remove some usages of TypeSubstitutionMap
1 parent 4d01253 commit f8b667a

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,10 +2685,8 @@ bool AssociatedTypeInference::simplifyCurrentTypeWitnesses() {
26852685
abort();
26862686
}
26872687

2688-
TypeSubstitutionMap substitutions;
2689-
auto selfTy = cast<SubstitutableType>(
2690-
proto->getSelfInterfaceType()->getCanonicalType());
2691-
substitutions[selfTy] = dc->mapTypeIntoContext(conformance->getType());
2688+
auto selfTy = proto->getSelfInterfaceType()->getCanonicalType();
2689+
auto substSelfTy = dc->mapTypeIntoContext(conformance->getType());
26922690

26932691
for (auto assocType : proto->getAssociatedTypeMembers()) {
26942692
if (conformance->hasTypeWitness(assocType))
@@ -2716,13 +2714,14 @@ bool AssociatedTypeInference::simplifyCurrentTypeWitnesses() {
27162714
if (!type->isTypeParameter())
27172715
return std::nullopt;
27182716

2719-
auto *rootParam = type->getRootGenericParam();
2720-
assert(rootParam->isEqual(selfTy));
2721-
27222717
// Replace Self with the concrete conforming type.
2723-
auto substType = Type(type).subst(QueryTypeSubstitutionMap{substitutions},
2724-
LookUpConformanceInModule(),
2725-
options);
2718+
auto substType = Type(type).subst(
2719+
[&](SubstitutableType *type) -> Type {
2720+
ASSERT(type->isEqual(selfTy));
2721+
return substSelfTy;
2722+
},
2723+
LookUpConformanceInModule(),
2724+
options);
27262725

27272726
// If we don't have enough type witnesses to substitute fully,
27282727
// leave the original type parameter in place.
@@ -2914,12 +2913,12 @@ bool AssociatedTypeInference::checkCurrentTypeWitnesses(
29142913

29152914
bool AssociatedTypeInference::checkConstrainedExtension(ExtensionDecl *ext) {
29162915
auto typeInContext = dc->mapTypeIntoContext(adoptee);
2917-
auto subs = typeInContext->getContextSubstitutions(ext);
2916+
auto subs = typeInContext->getContextSubstitutionMap(ext->getExtendedNominal());
29182917

29192918
SubstOptions options = getSubstOptionsWithCurrentTypeWitnesses();
29202919
switch (checkRequirements(
29212920
ext->getGenericSignature().getRequirements(),
2922-
QueryTypeSubstitutionMap{subs}, options)) {
2921+
QuerySubstitutionMap{subs}, options)) {
29232922
case CheckRequirementsResult::Success:
29242923
case CheckRequirementsResult::SubstitutionFailure:
29252924
return false;

lib/Sema/TypeCheckType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,9 @@ bool TypeChecker::checkContextualRequirements(GenericTypeDecl *decl,
643643
noteLoc = loc;
644644
}
645645

646-
const auto subMap = parentTy->getContextSubstitutions(dc);
646+
const auto subMap = parentTy->getContextSubstitutionMap(dc);
647647
const auto substitutions = [&](SubstitutableType *type) -> Type {
648-
auto result = QueryTypeSubstitutionMap{subMap}(type);
648+
auto result = QuerySubstitutionMap{subMap}(type);
649649
if (result->hasTypeParameter()) {
650650
if (contextSig) {
651651
// Avoid building this generic environment unless we need it.

0 commit comments

Comments
 (0)