Skip to content

Commit a275780

Browse files
committed
AST: Simplify SubstitutionMap::lookupSubstitution()
1 parent 632fd49 commit a275780

File tree

4 files changed

+6
-29
lines changed

4 files changed

+6
-29
lines changed

include/swift/AST/SubstitutionMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class SubstitutionMap {
277277
/// Note that this only finds replacements for maps that are directly
278278
/// stored inside the map. In most cases, you should call Type::subst()
279279
/// instead, since that will resolve member types also.
280-
Type lookupSubstitution(CanSubstitutableType type) const;
280+
Type lookupSubstitution(GenericTypeParamType *type) const;
281281
};
282282

283283
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,

lib/AST/GenericEnvironment.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,7 @@ GenericEnvironment::mapElementTypeIntoPackContext(Type type) const {
739739
QueryInterfaceTypeSubstitutions mapIntoContext(this);
740740
return type.subst(
741741
[&](SubstitutableType *type) {
742-
auto *genericParam = type->getAs<GenericTypeParamType>();
743-
if (!genericParam)
744-
return Type();
745-
742+
auto *genericParam = cast<GenericTypeParamType>(type);
746743
if (genericParam->getDepth() == elementDepth) {
747744
genericParam = members[genericParam->getIndex()];
748745
assert(genericParam->isParameterPack());
@@ -772,7 +769,7 @@ class BuildForwardingSubstitutions {
772769

773770
Type BuildForwardingSubstitutions::operator()(SubstitutableType *type) const {
774771
if (auto resultType = Query(type)) {
775-
auto param = type->castTo<GenericTypeParamType>();
772+
auto param = cast<GenericTypeParamType>(type);
776773
if (!param->isParameterPack())
777774
return resultType;
778775
if (resultType->is<PackType>())

lib/AST/SubstitutionMap.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
154154
return SubstitutionMap();
155155

156156
return SubstitutionMap::get(genericSig,
157-
[&](SubstitutableType *type) -> Type {
158-
return substitutions.lookupSubstitution(
159-
cast<SubstitutableType>(type->getCanonicalType()));
160-
},
157+
QuerySubstitutionMap{substitutions},
161158
LookUpConformanceInSubstitutionMap(substitutions));
162159
}
163160

@@ -213,29 +210,13 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
213210
return SubstitutionMap(genericSig, replacementTypes, conformances);
214211
}
215212

216-
Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
213+
Type SubstitutionMap::lookupSubstitution(GenericTypeParamType *genericParam) const {
217214
if (empty())
218215
return Type();
219216

220-
// If we have an archetype, map out of the context so we can compute a
221-
// conformance access path.
222-
if (auto archetype = dyn_cast<ArchetypeType>(type)) {
223-
// Only consider root archetypes.
224-
if (!archetype->isRoot())
225-
return Type();
226-
227-
if (!isa<PrimaryArchetypeType>(archetype) &&
228-
!isa<PackArchetypeType>(archetype))
229-
return Type();
230-
231-
type = cast<GenericTypeParamType>(
232-
archetype->getInterfaceType()->getCanonicalType());
233-
}
234-
235217
// Find the index of the replacement type based on the generic parameter we
236218
// have.
237219
GenericSignature genericSig = getGenericSignature();
238-
auto genericParam = cast<GenericTypeParamType>(type);
239220
auto genericParams = genericSig.getGenericParams();
240221
auto replacementIndex =
241222
GenericParamKey(genericParam).findIndexIn(genericParams);

lib/AST/TypeSubstitution.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ Type QueryTypeSubstitutionMap::operator()(SubstitutableType *type) const {
5555
}
5656

5757
Type QuerySubstitutionMap::operator()(SubstitutableType *type) const {
58-
auto key = cast<SubstitutableType>(type->getCanonicalType());
59-
return subMap.lookupSubstitution(key);
58+
return subMap.lookupSubstitution(cast<GenericTypeParamType>(type));
6059
}
6160

6261
FunctionType *

0 commit comments

Comments
 (0)