Skip to content

Commit 38a189f

Browse files
committed
[SubstitutionMap] Introduce hasAnySubstitutableParams().
Introduce an operation to check that a given substitution map is non-empty (i.e., corresponds to a generic signature) and that the generic signature has type parameters that aren’t bound to concrete types. This is the appropriate predicate for SIL-and-later to determine whether there will be any substitutions.
1 parent dc7a251 commit 38a189f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

include/swift/AST/SubstitutionMap.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ class SubstitutionMap {
133133
lookupConformance(CanType type, ProtocolDecl *proto) const;
134134

135135
/// Whether the substitution map is empty.
136-
bool empty() const { return getGenericSignature() == nullptr; }
136+
bool empty() const;
137+
138+
/// Whether the substitution has any substitutable parameters, i.e.,
139+
/// it is non-empty and at least one of the type parameters can be
140+
/// substituted (i.e., is not mapped to a concrete type).
141+
bool hasAnySubstitutableParams() const;
137142

138143
/// Whether the substitution map is non-empty.
139144
explicit operator bool() const { return !empty(); }

lib/AST/SubstitutionMap.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ GenericSignature *SubstitutionMap::getGenericSignature() const {
9191
return storage ? storage->getGenericSignature() : nullptr;
9292
}
9393

94+
bool SubstitutionMap::empty() const {
95+
return getGenericSignature() == nullptr;
96+
}
97+
98+
bool SubstitutionMap::hasAnySubstitutableParams() const {
99+
auto genericSig = getGenericSignature();
100+
if (!genericSig) return false;
101+
102+
return !genericSig->areAllParamsConcrete();
103+
}
104+
94105
bool SubstitutionMap::hasArchetypes() const {
95106
for (Type replacementTy : getReplacementTypes()) {
96107
if (replacementTy && replacementTy->hasArchetype())

0 commit comments

Comments
 (0)