@@ -55,7 +55,6 @@ SubstitutionMap::Storage::Storage(
55
55
getReplacementTypes ().data ());
56
56
std::copy (conformances.begin (), conformances.end (),
57
57
getConformances ().data ());
58
- populatedAllReplacements = false ;
59
58
}
60
59
61
60
SubstitutionMap::SubstitutionMap (
@@ -69,20 +68,6 @@ SubstitutionMap::SubstitutionMap(
69
68
#endif
70
69
}
71
70
72
- ArrayRef<Type> SubstitutionMap::getReplacementTypesBuffer () const {
73
- return storage ? storage->getReplacementTypes () : ArrayRef<Type>();
74
- }
75
-
76
- MutableArrayRef<Type> SubstitutionMap::getReplacementTypesBuffer () {
77
- return storage ? storage->getReplacementTypes () : MutableArrayRef<Type>();
78
- }
79
-
80
- MutableArrayRef<ProtocolConformanceRef>
81
- SubstitutionMap::getConformancesBuffer () {
82
- return storage ? storage->getConformances ()
83
- : MutableArrayRef<ProtocolConformanceRef>();
84
- }
85
-
86
71
ArrayRef<ProtocolConformanceRef> SubstitutionMap::getConformances () const {
87
72
return storage ? storage->getConformances ()
88
73
: ArrayRef<ProtocolConformanceRef>();
@@ -91,16 +76,7 @@ ArrayRef<ProtocolConformanceRef> SubstitutionMap::getConformances() const {
91
76
ArrayRef<Type> SubstitutionMap::getReplacementTypes () const {
92
77
if (empty ()) return { };
93
78
94
- // Make sure we've filled in all of the replacement types.
95
- if (!storage->populatedAllReplacements ) {
96
- for (auto gp : getGenericSignature ().getGenericParams ()) {
97
- (void )lookupSubstitution (cast<SubstitutableType>(gp->getCanonicalType ()));
98
- }
99
-
100
- storage->populatedAllReplacements = true ;
101
- }
102
-
103
- return getReplacementTypesBuffer ();
79
+ return storage->getReplacementTypes ();
104
80
}
105
81
106
82
ArrayRef<Type> SubstitutionMap::getInnermostReplacementTypes () const {
@@ -126,32 +102,32 @@ bool SubstitutionMap::hasAnySubstitutableParams() const {
126
102
}
127
103
128
104
bool SubstitutionMap::hasArchetypes () const {
129
- for (Type replacementTy : getReplacementTypesBuffer ()) {
130
- if (replacementTy && replacementTy ->hasArchetype ())
105
+ for (Type replacementTy : getReplacementTypes ()) {
106
+ if (replacementTy->hasArchetype ())
131
107
return true ;
132
108
}
133
109
return false ;
134
110
}
135
111
136
112
bool SubstitutionMap::hasLocalArchetypes () const {
137
- for (Type replacementTy : getReplacementTypesBuffer ()) {
138
- if (replacementTy && replacementTy ->hasLocalArchetype ())
113
+ for (Type replacementTy : getReplacementTypes ()) {
114
+ if (replacementTy->hasLocalArchetype ())
139
115
return true ;
140
116
}
141
117
return false ;
142
118
}
143
119
144
120
bool SubstitutionMap::hasOpaqueArchetypes () const {
145
- for (Type replacementTy : getReplacementTypesBuffer ()) {
146
- if (replacementTy && replacementTy ->hasOpaqueArchetype ())
121
+ for (Type replacementTy : getReplacementTypes ()) {
122
+ if (replacementTy->hasOpaqueArchetype ())
147
123
return true ;
148
124
}
149
125
return false ;
150
126
}
151
127
152
128
bool SubstitutionMap::hasDynamicSelf () const {
153
- for (Type replacementTy : getReplacementTypesBuffer ()) {
154
- if (replacementTy && replacementTy ->hasDynamicSelfType ())
129
+ for (Type replacementTy : getReplacementTypes ()) {
130
+ if (replacementTy->hasDynamicSelfType ())
155
131
return true ;
156
132
}
157
133
return false ;
@@ -162,8 +138,8 @@ bool SubstitutionMap::isCanonical() const {
162
138
163
139
if (!getGenericSignature ()->isCanonical ()) return false ;
164
140
165
- for (Type replacementTy : getReplacementTypesBuffer ()) {
166
- if (replacementTy && !replacementTy->isCanonical ())
141
+ for (Type replacementTy : getReplacementTypes ()) {
142
+ if (!replacementTy->isCanonical ())
167
143
return false ;
168
144
}
169
145
@@ -182,11 +158,8 @@ SubstitutionMap SubstitutionMap::getCanonical(bool canonicalizeSignature) const
182
158
if (canonicalizeSignature) sig = sig.getCanonicalSignature ();
183
159
184
160
SmallVector<Type, 4 > replacementTypes;
185
- for (Type replacementType : getReplacementTypesBuffer ()) {
186
- if (replacementType)
187
- replacementTypes.push_back (replacementType->getCanonicalType ());
188
- else
189
- replacementTypes.push_back (nullptr );
161
+ for (Type replacementType : getReplacementTypes ()) {
162
+ replacementTypes.push_back (replacementType->getCanonicalType ());
190
163
}
191
164
192
165
SmallVector<ProtocolConformanceRef, 4 > conformances;
@@ -237,13 +210,7 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
237
210
SmallVector<Type, 4 > replacementTypes;
238
211
replacementTypes.reserve (genericSig.getGenericParams ().size ());
239
212
240
- genericSig->forEachParam ([&](GenericTypeParamType *gp, bool canonical) {
241
- // Don't eagerly form replacements for non-canonical generic parameters.
242
- if (!canonical) {
243
- replacementTypes.push_back (Type ());
244
- return ;
245
- }
246
-
213
+ for (auto *gp : genericSig.getGenericParams ()) {
247
214
// Record the replacement.
248
215
Type replacement = Type (gp).subst (IFS);
249
216
@@ -252,7 +219,7 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
252
219
" replacement for pack parameter must be a pack type" );
253
220
254
221
replacementTypes.push_back (replacement);
255
- });
222
+ }
256
223
257
224
// Form the stored conformances.
258
225
SmallVector<ProtocolConformanceRef, 4 > conformances;
@@ -292,11 +259,7 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
292
259
// Find the index of the replacement type based on the generic parameter we
293
260
// have.
294
261
auto genericParam = cast<GenericTypeParamType>(type);
295
- auto mutableThis = const_cast <SubstitutionMap *>(this );
296
- auto replacementTypes = mutableThis->getReplacementTypesBuffer ();
297
- auto genericSig = getGenericSignature ();
298
- assert (genericSig);
299
- auto genericParams = genericSig.getGenericParams ();
262
+ auto genericParams = getGenericSignature ().getGenericParams ();
300
263
auto replacementIndex =
301
264
GenericParamKey (genericParam).findIndexIn (genericParams);
302
265
@@ -305,45 +268,7 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
305
268
if (replacementIndex == genericParams.size ())
306
269
return Type ();
307
270
308
- // If we already have a replacement type, return it.
309
- Type &replacementType = replacementTypes[replacementIndex];
310
- if (replacementType)
311
- return replacementType;
312
-
313
- // The generic parameter may have been made concrete by the generic signature,
314
- // substitute into the concrete type.
315
- if (auto concreteType = genericSig->getConcreteType (genericParam)) {
316
- // Set the replacement type to an error, to block infinite recursion.
317
- replacementType = ErrorType::get (concreteType);
318
-
319
- // Substitute into the replacement type.
320
- replacementType = concreteType.subst (*this );
321
-
322
- // If the generic signature is canonical, canonicalize the replacement type.
323
- if (getGenericSignature ()->isCanonical ())
324
- replacementType = replacementType->getCanonicalType ();
325
-
326
- return replacementType;
327
- }
328
-
329
- // The generic parameter may not be reduced. Retrieve the reduced
330
- // type, which will be dependent.
331
- CanType canonicalType = genericSig.getReducedType (genericParam);
332
-
333
- // If nothing changed, we don't have a replacement.
334
- if (canonicalType == type) return Type ();
335
-
336
- // If we're left with a substitutable type, substitute into that.
337
- // First, set the replacement type to an error, to block infinite recursion.
338
- replacementType = ErrorType::get (type);
339
-
340
- replacementType = lookupSubstitution (cast<SubstitutableType>(canonicalType));
341
-
342
- // If the generic signature is canonical, canonicalize the replacement type.
343
- if (getGenericSignature ()->isCanonical ())
344
- replacementType = replacementType->getCanonicalType ();
345
-
346
- return replacementType;
271
+ return getReplacementTypes ()[replacementIndex];
347
272
}
348
273
349
274
ProtocolConformanceRef
@@ -500,12 +425,7 @@ SubstitutionMap SubstitutionMap::subst(InFlightSubstitution &IFS) const {
500
425
if (empty ()) return SubstitutionMap ();
501
426
502
427
SmallVector<Type, 4 > newSubs;
503
- for (Type type : getReplacementTypesBuffer ()) {
504
- if (!type) {
505
- // Non-canonical parameter.
506
- newSubs.push_back (Type ());
507
- continue ;
508
- }
428
+ for (Type type : getReplacementTypes ()) {
509
429
newSubs.push_back (type.subst (IFS));
510
430
assert (type->is <PackType>() == newSubs.back ()->is <PackType>() &&
511
431
" substitution changed the pack-ness of a replacement type" );
@@ -843,7 +763,7 @@ bool SubstitutionMap::isIdentity() const {
843
763
844
764
GenericSignature sig = getGenericSignature ();
845
765
bool hasNonIdentityReplacement = false ;
846
- auto replacements = getReplacementTypesBuffer ();
766
+ auto replacements = getReplacementTypes ();
847
767
848
768
sig->forEachParam ([&](GenericTypeParamType *paramTy, bool isCanonical) {
849
769
if (isCanonical) {
0 commit comments