Skip to content

Commit 28b2a82

Browse files
committed
AST: The input generic signature of a substitution map can be canonical
1 parent 125e54c commit 28b2a82

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

include/swift/AST/SubstitutionMap.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ class SubstitutionMap {
112112
static SubstitutionMap get(GenericSignature genericSig,
113113
InFlightSubstitution &IFS);
114114

115-
/// Retrieve the generic signature describing the environment in which
116-
/// substitutions occur.
117-
GenericSignature getGenericSignature() const;
115+
/// Retrieve the substitution map's input generic signature.
116+
CanGenericSignature getGenericSignature() const;
118117

119118
/// Retrieve the array of protocol conformances, which line up with the
120119
/// requirements of the generic signature.
@@ -152,7 +151,7 @@ class SubstitutionMap {
152151
bool isCanonical() const;
153152

154153
/// Return the canonical form of this substitution map.
155-
SubstitutionMap getCanonical(bool canonicalizeSignature = true) const;
154+
SubstitutionMap getCanonical() const;
156155

157156
/// Apply a substitution to all replacement types in the map. Does not
158157
/// change keys.

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
269269
}
270270

271271
SubstitutionMap getOpSubstitutionMap(SubstitutionMap Subs) {
272-
auto substSubs = asImpl().remapSubstitutionMap(Subs)
273-
.getCanonical(/*canonicalizeSignature*/false);
272+
auto substSubs = asImpl().remapSubstitutionMap(Subs).getCanonical();
274273

275274
#ifndef NDEBUG
276275
for (auto substConf : substSubs.getConformances()) {

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5372,7 +5372,7 @@ Type OpenedArchetypeType::getAny(Type existential) {
53725372

53735373
void SubstitutionMap::Storage::Profile(
53745374
llvm::FoldingSetNodeID &id,
5375-
GenericSignature genericSig,
5375+
CanGenericSignature genericSig,
53765376
ArrayRef<Type> replacementTypes,
53775377
ArrayRef<ProtocolConformanceRef> conformances) {
53785378
id.AddPointer(genericSig.getPointer());
@@ -5388,7 +5388,7 @@ void SubstitutionMap::Storage::Profile(
53885388
}
53895389

53905390
SubstitutionMap::Storage *SubstitutionMap::Storage::get(
5391-
GenericSignature genericSig,
5391+
CanGenericSignature genericSig,
53925392
ArrayRef<Type> replacementTypes,
53935393
ArrayRef<ProtocolConformanceRef> conformances) {
53945394
// If there is no generic signature, we need no storage.

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7021,7 +7021,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
70217021
// pack at the appropriate index. We only expect to actually do
70227022
// this once for each type, so it's fine to do it in the callback.
70237023
unsigned nextIndex = 0;
7024-
for (auto *genericParam : params) {
7024+
for (auto genericParam : params) {
70257025
if (!genericParam->isParameterPack())
70267026
continue;
70277027

lib/AST/SubstitutionMap.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
using namespace swift;
4444

4545
SubstitutionMap::Storage::Storage(
46-
GenericSignature genericSig,
46+
CanGenericSignature genericSig,
4747
ArrayRef<Type> replacementTypes,
4848
ArrayRef<ProtocolConformanceRef> conformances)
4949
: genericSig(genericSig),
@@ -62,7 +62,8 @@ SubstitutionMap::SubstitutionMap(
6262
GenericSignature genericSig,
6363
ArrayRef<Type> replacementTypes,
6464
ArrayRef<ProtocolConformanceRef> conformances)
65-
: storage(Storage::get(genericSig, replacementTypes, conformances)) {
65+
: storage(Storage::get(genericSig.getCanonicalSignature(),
66+
replacementTypes, conformances)) {
6667
#ifndef NDEBUG
6768
if (genericSig->getASTContext().LangOpts.VerifyAllSubstitutionMaps)
6869
verify();
@@ -87,7 +88,7 @@ ArrayRef<Type> SubstitutionMap::getInnermostReplacementTypes() const {
8788
getGenericSignature().getInnermostGenericParams().size());
8889
}
8990

90-
GenericSignature SubstitutionMap::getGenericSignature() const {
91+
CanGenericSignature SubstitutionMap::getGenericSignature() const {
9192
return storage ? storage->getGenericSignature() : nullptr;
9293
}
9394

@@ -127,12 +128,9 @@ bool SubstitutionMap::isCanonical() const {
127128
return true;
128129
}
129130

130-
SubstitutionMap SubstitutionMap::getCanonical(bool canonicalizeSignature) const {
131+
SubstitutionMap SubstitutionMap::getCanonical() const {
131132
if (empty()) return *this;
132133

133-
auto sig = getGenericSignature();
134-
if (canonicalizeSignature) sig = sig.getCanonicalSignature();
135-
136134
SmallVector<Type, 4> replacementTypes;
137135
for (Type replacementType : getReplacementTypes()) {
138136
replacementTypes.push_back(replacementType->getCanonicalType());
@@ -143,7 +141,7 @@ SubstitutionMap SubstitutionMap::getCanonical(bool canonicalizeSignature) const
143141
conformances.push_back(conf.getCanonicalConformanceRef());
144142
}
145143

146-
return SubstitutionMap::get(sig,
144+
return SubstitutionMap::get(getGenericSignature(),
147145
ArrayRef<Type>(replacementTypes),
148146
ArrayRef<ProtocolConformanceRef>(conformances));
149147
}

lib/AST/SubstitutionMapStorage.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ class SubstitutionMap::Storage final
3636
friend TrailingObjects;
3737

3838
/// The generic signature for which we are performing substitutions.
39-
GenericSignature genericSig;
39+
CanGenericSignature genericSig;
4040

4141
/// The number of conformance requirements, cached to avoid constantly
4242
/// recomputing it on conformance-buffer access.
4343
const unsigned numConformanceRequirements;
4444

4545
Storage() = delete;
4646

47-
Storage(GenericSignature genericSig,
47+
Storage(CanGenericSignature genericSig,
4848
ArrayRef<Type> replacementTypes,
4949
ArrayRef<ProtocolConformanceRef> conformances);
5050

@@ -66,13 +66,13 @@ class SubstitutionMap::Storage final
6666
public:
6767
/// Form storage for the given generic signature and its replacement
6868
/// types and conformances.
69-
static Storage *get(GenericSignature genericSig,
69+
static Storage *get(CanGenericSignature genericSig,
7070
ArrayRef<Type> replacementTypes,
7171
ArrayRef<ProtocolConformanceRef> conformances);
7272

7373
/// Retrieve the generic signature that describes the shape of this
7474
/// storage.
75-
GenericSignature getGenericSignature() const { return genericSig; }
75+
CanGenericSignature getGenericSignature() const { return genericSig; }
7676

7777
/// Retrieve the array of replacement types, which line up with the
7878
/// generic parameters.
@@ -108,7 +108,7 @@ class SubstitutionMap::Storage final
108108

109109
/// Profile the substitution map storage, for use with LLVM's FoldingSet.
110110
static void Profile(llvm::FoldingSetNodeID &id,
111-
GenericSignature genericSig,
111+
CanGenericSignature genericSig,
112112
ArrayRef<Type> replacementTypes,
113113
ArrayRef<ProtocolConformanceRef> conformances);
114114
};

0 commit comments

Comments
 (0)