@@ -2999,8 +2999,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
2999
2999
SILLocation loc,
3000
3000
SILValue paramArg,
3001
3001
CanType &baseType,
3002
- SubstitutionList &subs,
3003
- SmallVectorImpl<Substitution> &subsBuf) {
3002
+ SubstitutionMap subs) {
3004
3003
// If the storage is at global scope, then the base value () is a formality.
3005
3004
// There no real argument to pass to the underlying accessors.
3006
3005
if (!storage->getDeclContext ()->isTypeContext ())
@@ -3026,7 +3025,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
3026
3025
if (storage->getDeclContext ()->getAsClassOrClassExtensionContext ()) {
3027
3026
opened = ArchetypeType::getOpened (baseType);
3028
3027
} else {
3029
- opened = subs[ 0 ]. getReplacement () ->castTo <ArchetypeType>();
3028
+ opened = subs. getReplacementTypes ()[ 0 ] ->castTo <ArchetypeType>();
3030
3029
}
3031
3030
assert (opened->isOpenedExistential ());
3032
3031
@@ -3104,7 +3103,7 @@ static RValue loadIndexValuesForKeyPathComponent(SILGenFunction &SGF,
3104
3103
static SILFunction *getOrCreateKeyPathGetter (SILGenModule &SGM,
3105
3104
SILLocation loc,
3106
3105
AbstractStorageDecl *property,
3107
- SubstitutionList subs,
3106
+ SubstitutionMap subs,
3108
3107
AccessStrategy strategy,
3109
3108
GenericEnvironment *genericEnv,
3110
3109
ArrayRef<IndexTypePair> indexes,
@@ -3152,10 +3151,9 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3152
3151
3153
3152
// Find the function and see if we already created it.
3154
3153
SmallVector<CanType, 2 > interfaceSubs;
3155
- for (auto &sub : subs) {
3154
+ for (auto replacement : subs. getReplacementTypes () ) {
3156
3155
interfaceSubs.push_back (
3157
- sub.getReplacement ()->mapTypeOutOfContext ()
3158
- ->getCanonicalType ());
3156
+ replacement->mapTypeOutOfContext ()->getCanonicalType ());
3159
3157
}
3160
3158
auto name = Mangle::ASTMangler ()
3161
3159
.mangleKeyPathGetterThunkHelper (property, genericSig, baseType,
@@ -3193,11 +3191,9 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3193
3191
3194
3192
Scope scope (subSGF, loc);
3195
3193
3196
- SmallVector<Substitution, 2 > subsBuf;
3197
-
3198
3194
auto baseSubstValue = emitKeyPathRValueBase (subSGF, property,
3199
3195
loc, baseArg,
3200
- baseType, subs, subsBuf );
3196
+ baseType, subs);
3201
3197
3202
3198
RValue indexValue = loadIndexValuesForKeyPathComponent (subSGF, loc,
3203
3199
indexes,
@@ -3206,7 +3202,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3206
3202
auto resultSubst = subSGF.emitRValueForStorageLoad (loc, baseSubstValue,
3207
3203
baseType, /* super*/ false ,
3208
3204
property, std::move (indexValue),
3209
- subs, AccessSemantics::Ordinary,
3205
+ subs. toList () , AccessSemantics::Ordinary,
3210
3206
propertyType, SGFContext ())
3211
3207
.getAsSingleValue (subSGF, loc);
3212
3208
if (resultSubst.getType ().getAddressType () != resultArg->getType ())
@@ -3225,7 +3221,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3225
3221
SILFunction *getOrCreateKeyPathSetter (SILGenModule &SGM,
3226
3222
SILLocation loc,
3227
3223
AbstractStorageDecl *property,
3228
- SubstitutionList subs,
3224
+ SubstitutionMap subs,
3229
3225
AccessStrategy strategy,
3230
3226
GenericEnvironment *genericEnv,
3231
3227
ArrayRef<IndexTypePair> indexes,
@@ -3280,10 +3276,9 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3280
3276
SmallString<64 > nameBuf;
3281
3277
3282
3278
SmallVector<CanType, 2 > interfaceSubs;
3283
- for (auto &sub : subs) {
3279
+ for (Type replacement : subs. getReplacementTypes () ) {
3284
3280
interfaceSubs.push_back (
3285
- sub.getReplacement ()->mapTypeOutOfContext ()
3286
- ->getCanonicalType ());
3281
+ replacement->mapTypeOutOfContext ()->getCanonicalType ());
3287
3282
}
3288
3283
auto name = Mangle::ASTMangler ().mangleKeyPathSetterThunkHelper (property,
3289
3284
genericSig,
@@ -3338,12 +3333,11 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3338
3333
propertyType);
3339
3334
3340
3335
LValue lv;
3341
- SmallVector<Substitution, 2 > subsBuf;
3342
3336
3343
3337
if (!property->isSetterMutating ()) {
3344
3338
auto baseSubst = emitKeyPathRValueBase (subSGF, property,
3345
3339
loc, baseArg,
3346
- baseType, subs, subsBuf );
3340
+ baseType, subs);
3347
3341
3348
3342
lv = LValue::forValue (baseSubst, baseType);
3349
3343
} else {
@@ -3354,7 +3348,7 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3354
3348
3355
3349
// Open an existential lvalue, if necessary.
3356
3350
if (baseType->isAnyExistentialType ()) {
3357
- auto opened = subs[ 0 ]. getReplacement () ->castTo <ArchetypeType>();
3351
+ auto opened = subs. getReplacementTypes ()[ 0 ] ->castTo <ArchetypeType>();
3358
3352
assert (opened->isOpenedExistential ());
3359
3353
baseType = opened->getCanonicalType ();
3360
3354
lv = subSGF.emitOpenExistentialLValue (loc, std::move (lv),
@@ -3366,12 +3360,12 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3366
3360
3367
3361
LValueOptions lvOptions;
3368
3362
if (auto var = dyn_cast<VarDecl>(property)) {
3369
- lv.addMemberVarComponent (subSGF, loc, var, subs, lvOptions,
3363
+ lv.addMemberVarComponent (subSGF, loc, var, subs. toList () , lvOptions,
3370
3364
/* super*/ false , AccessKind::Write,
3371
3365
AccessSemantics::Ordinary, strategy, propertyType);
3372
3366
} else {
3373
3367
auto sub = cast<SubscriptDecl>(property);
3374
- lv.addMemberSubscriptComponent (subSGF, loc, sub, subs, lvOptions,
3368
+ lv.addMemberSubscriptComponent (subSGF, loc, sub, subs. toList () , lvOptions,
3375
3369
/* super*/ false , AccessKind::Write,
3376
3370
AccessSemantics::Ordinary, strategy, propertyType,
3377
3371
std::move (indexValue));
@@ -3741,23 +3735,22 @@ lowerKeyPathSubscriptIndexTypes(
3741
3735
SILGenModule &SGM,
3742
3736
SmallVectorImpl<IndexTypePair> &indexPatterns,
3743
3737
SubscriptDecl *subscript,
3744
- SubstitutionList subscriptSubs,
3738
+ SubstitutionMap subscriptSubs,
3745
3739
bool &needsGenericContext) {
3746
3740
// Capturing an index value dependent on the generic context means we
3747
3741
// need the generic context captured in the key path.
3748
3742
auto subscriptSubstTy = subscript->getInterfaceType ();
3749
3743
SubstitutionMap subMap;
3750
3744
auto sig = subscript->getGenericSignature ();
3751
3745
if (sig) {
3752
- subMap = sig->getSubstitutionMap (subscriptSubs);
3753
- subscriptSubstTy = subscriptSubstTy.subst (subMap);
3746
+ subscriptSubstTy = subscriptSubstTy.subst (subscriptSubs);
3754
3747
}
3755
3748
needsGenericContext |= subscriptSubstTy->hasArchetype ();
3756
3749
3757
3750
for (auto *index : *subscript->getIndices ()) {
3758
3751
auto indexTy = index->getInterfaceType ();
3759
3752
if (sig) {
3760
- indexTy = indexTy.subst (subMap );
3753
+ indexTy = indexTy.subst (subscriptSubs );
3761
3754
}
3762
3755
auto indexLoweredTy = SGM.Types .getLoweredType (
3763
3756
AbstractionPattern::getOpaque (),
@@ -3796,7 +3789,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3796
3789
GenericEnvironment *genericEnv,
3797
3790
unsigned &baseOperand,
3798
3791
bool &needsGenericContext,
3799
- SubstitutionList subs,
3792
+ SubstitutionMap subs,
3800
3793
AbstractStorageDecl *storage,
3801
3794
ArrayRef<ProtocolConformanceRef> indexHashables,
3802
3795
CanType baseTy,
@@ -3823,8 +3816,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3823
3816
auto componentObjTy = componentTy->getWithoutSpecifierType ();
3824
3817
if (genericEnv)
3825
3818
componentObjTy = genericEnv->mapTypeIntoContext (componentObjTy);
3826
- auto storageTy = Types.getSubstitutedStorageType (var,
3827
- componentObjTy);
3819
+ auto storageTy = Types.getSubstitutedStorageType (var, componentObjTy);
3828
3820
auto opaqueTy = Types
3829
3821
.getLoweredType (AbstractionPattern::getOpaque (), componentObjTy);
3830
3822
@@ -4008,7 +4000,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
4008
4000
auto sub = cast<SubscriptDecl>(component.getDeclRef ().getDecl ());
4009
4001
lowerKeyPathSubscriptIndexTypes (
4010
4002
SGF.SGM , indexTypes, sub,
4011
- component.getDeclRef ().getSubstitutions (). toList () ,
4003
+ component.getDeclRef ().getSubstitutions (),
4012
4004
needsGenericContext);
4013
4005
lowerKeyPathSubscriptIndexPatterns (indices, indexTypes,
4014
4006
component.getSubscriptIndexHashableConformances (),
@@ -4044,7 +4036,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
4044
4036
SGF.F .getGenericEnvironment (),
4045
4037
numOperands,
4046
4038
needsGenericContext,
4047
- component.getDeclRef ().getSubstitutions (). toList (),
4039
+ component.getDeclRef ().getSubstitutions (),
4048
4040
decl,
4049
4041
component.getSubscriptIndexHashableConformances (),
4050
4042
baseTy,
0 commit comments