@@ -232,19 +232,21 @@ class TypeComparator : public TypeMatcher<TypeComparator> {
232
232
233
233
} // anonymous namespace
234
234
235
- // / Checks if a second substitution list is an expanded version of
236
- // / the first substitution list .
235
+ // / Checks if a second substitution map is an expanded version of
236
+ // / the first substitution map .
237
237
// / This is the case if at least one of the substitution type in Subs2 is
238
238
// / "bigger" than the corresponding substitution type in Subs1.
239
239
// / Type T2 is "smaller" than type T1 if T2 is structurally contained in T1.
240
- static bool growingSubstitutions (SubstitutionList Subs1,
241
- SubstitutionList Subs2) {
242
- assert (Subs1.size () == Subs2.size ());
240
+ static bool growingSubstitutions (SubstitutionMap Subs1,
241
+ SubstitutionMap Subs2) {
242
+ auto Replacements1 = Subs1.getReplacementTypes ();
243
+ auto Replacements2 = Subs2.getReplacementTypes ();
244
+ assert (Replacements1.size () == Replacements2.size ());
243
245
TypeComparator TypeCmp;
244
246
// Perform component-wise comparisions for substitutions.
245
- for (unsigned idx = 0 , e = Subs1. size (); idx < e; ++idx ) {
246
- auto Type1 = Subs1 [idx]. getReplacement () ->getCanonicalType ();
247
- auto Type2 = Subs2 [idx]. getReplacement () ->getCanonicalType ();
247
+ for (unsigned idx : indices (Replacements1) ) {
248
+ auto Type1 = Replacements1 [idx]->getCanonicalType ();
249
+ auto Type2 = Replacements2 [idx]->getCanonicalType ();
248
250
// If types are the same, the substitution type does not grow.
249
251
if (TypeCmp.isEqual (Type2, Type1))
250
252
continue ;
@@ -255,7 +257,7 @@ static bool growingSubstitutions(SubstitutionList Subs1,
255
257
if (TypeCmp.isPartiallyContainedIn (Type1, Type2)) {
256
258
DEBUG (llvm::dbgs () << " Type:\n " ; Type1.dump ();
257
259
llvm::dbgs () << " is (partially) contained in type:\n " ; Type2.dump ();
258
- llvm::dbgs () << " SubstitutionList [" << idx
260
+ llvm::dbgs () << " Replacements [" << idx
259
261
<< " ] has got bigger since last time.\n " );
260
262
return true ;
261
263
}
@@ -317,8 +319,8 @@ static bool createsInfiniteSpecializationLoop(ApplySite Apply) {
317
319
DEBUG (llvm::dbgs () << " Found a call graph loop, checking substitutions\n " );
318
320
// Consider if components of the substitution list gets bigger compared to
319
321
// the previously seen specialization of the same generic function.
320
- if (growingSubstitutions (CurSpecializationInfo->getSubstitutions (). toList () ,
321
- Apply.getSubstitutions ())) {
322
+ if (growingSubstitutions (CurSpecializationInfo->getSubstitutions (),
323
+ Apply.getSubstitutionMap ())) {
322
324
DEBUG (llvm::dbgs () << " Found a generic specialization loop!\n " );
323
325
return true ;
324
326
}
@@ -346,11 +348,11 @@ static bool createsInfiniteSpecializationLoop(ApplySite Apply) {
346
348
// =============================================================================
347
349
348
350
static bool shouldNotSpecializeCallee (SILFunction *Callee,
349
- SubstitutionList Subs = {}) {
351
+ SubstitutionMap Subs = {}) {
350
352
if (Callee->hasSemanticsAttr (" optimize.sil.specialize.generic.never" ))
351
353
return true ;
352
354
353
- if (! Subs.empty () &&
355
+ if (Subs.hasAnySubstitutableParams () &&
354
356
Callee->hasSemanticsAttr (" optimize.sil.specialize.generic.partial.never" ))
355
357
return true ;
356
358
@@ -467,7 +469,7 @@ bool ReabstractionInfo::prepareAndCheck(ApplySite Apply, SILFunction *Callee,
467
469
return false ;
468
470
469
471
// Bail if the callee should not be partially specialized.
470
- if (shouldNotSpecializeCallee (Callee, ParamSubs. toList () ))
472
+ if (shouldNotSpecializeCallee (Callee, ParamSubs))
471
473
return false ;
472
474
}
473
475
@@ -978,7 +980,6 @@ static void collectRequirements(ArchetypeType *Archetype, GenericSignature *Sig,
978
980
// / really used?
979
981
static bool
980
982
shouldBePartiallySpecialized (Type Replacement,
981
- ArrayRef<ProtocolConformanceRef> Conformances,
982
983
GenericSignature *Sig, GenericEnvironment *Env) {
983
984
// If replacement is a concrete type, this substitution
984
985
// should participate.
@@ -1024,8 +1025,8 @@ shouldBePartiallySpecialized(Type Replacement,
1024
1025
1025
1026
if (OptimizeGenericSubstitutions) {
1026
1027
// Is it an unconstrained generic parameter?
1027
- if (Conformances. empty ()) {
1028
- if (Replacement-> is <ArchetypeType> ()) {
1028
+ if (auto Archetype = Replacement-> getAs <ArchetypeType> ()) {
1029
+ if (Archetype-> getConformsTo (). empty ()) {
1029
1030
// TODO: If Replacement add a new layout constraint, then
1030
1031
// it may be still useful to perform the partial specialization.
1031
1032
return false ;
@@ -1128,7 +1129,7 @@ class FunctionSignaturePartialSpecializer {
1128
1129
// / Take into account only those archetypes that occur in the
1129
1130
// / substitutions of generic parameters which will be partially
1130
1131
// / specialized. Ignore all others.
1131
- void collectUsedCallerArchetypes (SubstitutionList ParamSubs);
1132
+ void collectUsedCallerArchetypes (SubstitutionMap ParamSubs);
1132
1133
1133
1134
// / Create a new generic parameter.
1134
1135
GenericTypeParamType *createGenericParam ();
@@ -1139,15 +1140,14 @@ class FunctionSignaturePartialSpecializer {
1139
1140
GenericEnvironment *CallerGenericEnv,
1140
1141
GenericSignature *CalleeGenericSig,
1141
1142
GenericEnvironment *CalleeGenericEnv,
1142
- SubstitutionList ParamSubs)
1143
+ SubstitutionMap ParamSubs)
1143
1144
: CallerGenericSig(CallerGenericSig), CallerGenericEnv(CallerGenericEnv),
1144
1145
CalleeGenericSig (CalleeGenericSig), CalleeGenericEnv(CalleeGenericEnv),
1145
1146
M(M), SM(M.getSwiftModule()), Ctx(M.getASTContext()),
1146
1147
Builder(Ctx) {
1147
1148
SpecializedGenericSig = nullptr ;
1148
1149
SpecializedGenericEnv = nullptr ;
1149
- CalleeInterfaceToCallerArchetypeMap =
1150
- CalleeGenericSig->getSubstitutionMap (ParamSubs);
1150
+ CalleeInterfaceToCallerArchetypeMap = ParamSubs;
1151
1151
}
1152
1152
1153
1153
// / This constructor is used by when processing @_specialize.
@@ -1194,7 +1194,7 @@ class FunctionSignaturePartialSpecializer {
1194
1194
return SpecializedGenericEnv;
1195
1195
}
1196
1196
1197
- void createSpecializedGenericSignature (SubstitutionList ParamSubs);
1197
+ void createSpecializedGenericSignature (SubstitutionMap ParamSubs);
1198
1198
1199
1199
void createSpecializedGenericSignatureWithNonGenericSubs ();
1200
1200
@@ -1217,16 +1217,15 @@ FunctionSignaturePartialSpecializer::createGenericParam() {
1217
1217
1218
1218
// / Collect all used caller's archetypes from all the substitutions.
1219
1219
void FunctionSignaturePartialSpecializer::collectUsedCallerArchetypes (
1220
- SubstitutionList ParamSubs) {
1221
- for (auto Sub : ParamSubs) {
1222
- auto Replacement = Sub.getReplacement ();
1220
+ SubstitutionMap ParamSubs) {
1221
+ for (auto Replacement : ParamSubs.getReplacementTypes ()) {
1223
1222
if (!Replacement->hasArchetype ())
1224
1223
continue ;
1225
1224
1226
1225
// If the substitution will not be performed in the specialized
1227
1226
// function, there is no need to check for any archetypes inside
1228
1227
// the replacement.
1229
- if (!shouldBePartiallySpecialized (Replacement, Sub. getConformances (),
1228
+ if (!shouldBePartiallySpecialized (Replacement,
1230
1229
CallerGenericSig, CallerGenericEnv))
1231
1230
continue ;
1232
1231
@@ -1350,7 +1349,7 @@ void FunctionSignaturePartialSpecializer::
1350
1349
DEBUG (llvm::dbgs () << " Replacement found:\n " ; Replacement->dump ());
1351
1350
1352
1351
bool ShouldSpecializeGP = shouldBePartiallySpecialized (
1353
- Replacement, {}, CallerGenericSig, CallerGenericEnv);
1352
+ Replacement, CallerGenericSig, CallerGenericEnv);
1354
1353
1355
1354
if (ShouldSpecializeGP) {
1356
1355
DEBUG (llvm::dbgs () << " Should be partially specialized.\n " );
@@ -1559,7 +1558,7 @@ void FunctionSignaturePartialSpecializer::
1559
1558
}
1560
1559
1561
1560
void FunctionSignaturePartialSpecializer::createSpecializedGenericSignature (
1562
- SubstitutionList ParamSubs) {
1561
+ SubstitutionMap ParamSubs) {
1563
1562
// Collect all used caller's archetypes from all the substitutions.
1564
1563
collectUsedCallerArchetypes (ParamSubs);
1565
1564
@@ -1644,11 +1643,11 @@ void ReabstractionInfo::performPartialSpecializationPreparation(
1644
1643
FunctionSignaturePartialSpecializer FSPS (M,
1645
1644
CallerGenericSig, CallerGenericEnv,
1646
1645
CalleeGenericSig, CalleeGenericEnv,
1647
- ParamSubs. toList () );
1646
+ ParamSubs);
1648
1647
1649
1648
// Create the partially specialized generic signature and generic environment.
1650
1649
if (SupportGenericSubstitutions)
1651
- FSPS.createSpecializedGenericSignature (ParamSubs. toList () );
1650
+ FSPS.createSpecializedGenericSignature (ParamSubs);
1652
1651
else
1653
1652
FSPS.createSpecializedGenericSignatureWithNonGenericSubs ();
1654
1653
0 commit comments