Skip to content

Commit 1af6cb9

Browse files
committed
[SILGen] Remove SubstitutionList from most of key-path SIL generation.
1 parent 17572ce commit 1af6cb9

File tree

3 files changed

+24
-32
lines changed

3 files changed

+24
-32
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,9 +1264,9 @@ void SILGenModule::tryEmitPropertyDescriptor(AbstractStorageDecl *decl) {
12641264
return;
12651265
}
12661266

1267-
SubstitutionList subs = {};
1267+
SubstitutionMap subs = {};
12681268
if (genericEnv)
1269-
subs = genericEnv->getForwardingSubstitutions();
1269+
subs = genericEnv->getForwardingSubstitutionMap();
12701270

12711271
if (auto sub = dyn_cast<SubscriptDecl>(decl)) {
12721272
for (auto *index : *sub->getIndices()) {

lib/SILGen/SILGen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
344344
GenericEnvironment *genericEnv,
345345
unsigned &baseOperand,
346346
bool &needsGenericContext,
347-
SubstitutionList subs,
347+
SubstitutionMap subs,
348348
AbstractStorageDecl *storage,
349349
ArrayRef<ProtocolConformanceRef> indexHashables,
350350
CanType baseTy,

lib/SILGen/SILGenExpr.cpp

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,8 +2999,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
29992999
SILLocation loc,
30003000
SILValue paramArg,
30013001
CanType &baseType,
3002-
SubstitutionList &subs,
3003-
SmallVectorImpl<Substitution> &subsBuf) {
3002+
SubstitutionMap subs) {
30043003
// If the storage is at global scope, then the base value () is a formality.
30053004
// There no real argument to pass to the underlying accessors.
30063005
if (!storage->getDeclContext()->isTypeContext())
@@ -3026,7 +3025,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
30263025
if (storage->getDeclContext()->getAsClassOrClassExtensionContext()) {
30273026
opened = ArchetypeType::getOpened(baseType);
30283027
} else {
3029-
opened = subs[0].getReplacement()->castTo<ArchetypeType>();
3028+
opened = subs.getReplacementTypes()[0]->castTo<ArchetypeType>();
30303029
}
30313030
assert(opened->isOpenedExistential());
30323031

@@ -3104,7 +3103,7 @@ static RValue loadIndexValuesForKeyPathComponent(SILGenFunction &SGF,
31043103
static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
31053104
SILLocation loc,
31063105
AbstractStorageDecl *property,
3107-
SubstitutionList subs,
3106+
SubstitutionMap subs,
31083107
AccessStrategy strategy,
31093108
GenericEnvironment *genericEnv,
31103109
ArrayRef<IndexTypePair> indexes,
@@ -3152,10 +3151,9 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
31523151

31533152
// Find the function and see if we already created it.
31543153
SmallVector<CanType, 2> interfaceSubs;
3155-
for (auto &sub : subs) {
3154+
for (auto replacement : subs.getReplacementTypes()) {
31563155
interfaceSubs.push_back(
3157-
sub.getReplacement()->mapTypeOutOfContext()
3158-
->getCanonicalType());
3156+
replacement->mapTypeOutOfContext()->getCanonicalType());
31593157
}
31603158
auto name = Mangle::ASTMangler()
31613159
.mangleKeyPathGetterThunkHelper(property, genericSig, baseType,
@@ -3193,11 +3191,9 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
31933191

31943192
Scope scope(subSGF, loc);
31953193

3196-
SmallVector<Substitution, 2> subsBuf;
3197-
31983194
auto baseSubstValue = emitKeyPathRValueBase(subSGF, property,
31993195
loc, baseArg,
3200-
baseType, subs, subsBuf);
3196+
baseType, subs);
32013197

32023198
RValue indexValue = loadIndexValuesForKeyPathComponent(subSGF, loc,
32033199
indexes,
@@ -3206,7 +3202,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
32063202
auto resultSubst = subSGF.emitRValueForStorageLoad(loc, baseSubstValue,
32073203
baseType, /*super*/false,
32083204
property, std::move(indexValue),
3209-
subs, AccessSemantics::Ordinary,
3205+
subs.toList(), AccessSemantics::Ordinary,
32103206
propertyType, SGFContext())
32113207
.getAsSingleValue(subSGF, loc);
32123208
if (resultSubst.getType().getAddressType() != resultArg->getType())
@@ -3225,7 +3221,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
32253221
SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
32263222
SILLocation loc,
32273223
AbstractStorageDecl *property,
3228-
SubstitutionList subs,
3224+
SubstitutionMap subs,
32293225
AccessStrategy strategy,
32303226
GenericEnvironment *genericEnv,
32313227
ArrayRef<IndexTypePair> indexes,
@@ -3280,10 +3276,9 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
32803276
SmallString<64> nameBuf;
32813277

32823278
SmallVector<CanType, 2> interfaceSubs;
3283-
for (auto &sub : subs) {
3279+
for (Type replacement : subs.getReplacementTypes()) {
32843280
interfaceSubs.push_back(
3285-
sub.getReplacement()->mapTypeOutOfContext()
3286-
->getCanonicalType());
3281+
replacement->mapTypeOutOfContext()->getCanonicalType());
32873282
}
32883283
auto name = Mangle::ASTMangler().mangleKeyPathSetterThunkHelper(property,
32893284
genericSig,
@@ -3338,12 +3333,11 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
33383333
propertyType);
33393334

33403335
LValue lv;
3341-
SmallVector<Substitution, 2> subsBuf;
33423336

33433337
if (!property->isSetterMutating()) {
33443338
auto baseSubst = emitKeyPathRValueBase(subSGF, property,
33453339
loc, baseArg,
3346-
baseType, subs, subsBuf);
3340+
baseType, subs);
33473341

33483342
lv = LValue::forValue(baseSubst, baseType);
33493343
} else {
@@ -3354,7 +3348,7 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
33543348

33553349
// Open an existential lvalue, if necessary.
33563350
if (baseType->isAnyExistentialType()) {
3357-
auto opened = subs[0].getReplacement()->castTo<ArchetypeType>();
3351+
auto opened = subs.getReplacementTypes()[0]->castTo<ArchetypeType>();
33583352
assert(opened->isOpenedExistential());
33593353
baseType = opened->getCanonicalType();
33603354
lv = subSGF.emitOpenExistentialLValue(loc, std::move(lv),
@@ -3366,12 +3360,12 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
33663360

33673361
LValueOptions lvOptions;
33683362
if (auto var = dyn_cast<VarDecl>(property)) {
3369-
lv.addMemberVarComponent(subSGF, loc, var, subs, lvOptions,
3363+
lv.addMemberVarComponent(subSGF, loc, var, subs.toList(), lvOptions,
33703364
/*super*/ false, AccessKind::Write,
33713365
AccessSemantics::Ordinary, strategy, propertyType);
33723366
} else {
33733367
auto sub = cast<SubscriptDecl>(property);
3374-
lv.addMemberSubscriptComponent(subSGF, loc, sub, subs, lvOptions,
3368+
lv.addMemberSubscriptComponent(subSGF, loc, sub, subs.toList(), lvOptions,
33753369
/*super*/ false, AccessKind::Write,
33763370
AccessSemantics::Ordinary, strategy, propertyType,
33773371
std::move(indexValue));
@@ -3741,23 +3735,22 @@ lowerKeyPathSubscriptIndexTypes(
37413735
SILGenModule &SGM,
37423736
SmallVectorImpl<IndexTypePair> &indexPatterns,
37433737
SubscriptDecl *subscript,
3744-
SubstitutionList subscriptSubs,
3738+
SubstitutionMap subscriptSubs,
37453739
bool &needsGenericContext) {
37463740
// Capturing an index value dependent on the generic context means we
37473741
// need the generic context captured in the key path.
37483742
auto subscriptSubstTy = subscript->getInterfaceType();
37493743
SubstitutionMap subMap;
37503744
auto sig = subscript->getGenericSignature();
37513745
if (sig) {
3752-
subMap = sig->getSubstitutionMap(subscriptSubs);
3753-
subscriptSubstTy = subscriptSubstTy.subst(subMap);
3746+
subscriptSubstTy = subscriptSubstTy.subst(subscriptSubs);
37543747
}
37553748
needsGenericContext |= subscriptSubstTy->hasArchetype();
37563749

37573750
for (auto *index : *subscript->getIndices()) {
37583751
auto indexTy = index->getInterfaceType();
37593752
if (sig) {
3760-
indexTy = indexTy.subst(subMap);
3753+
indexTy = indexTy.subst(subscriptSubs);
37613754
}
37623755
auto indexLoweredTy = SGM.Types.getLoweredType(
37633756
AbstractionPattern::getOpaque(),
@@ -3796,7 +3789,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
37963789
GenericEnvironment *genericEnv,
37973790
unsigned &baseOperand,
37983791
bool &needsGenericContext,
3799-
SubstitutionList subs,
3792+
SubstitutionMap subs,
38003793
AbstractStorageDecl *storage,
38013794
ArrayRef<ProtocolConformanceRef> indexHashables,
38023795
CanType baseTy,
@@ -3823,8 +3816,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
38233816
auto componentObjTy = componentTy->getWithoutSpecifierType();
38243817
if (genericEnv)
38253818
componentObjTy = genericEnv->mapTypeIntoContext(componentObjTy);
3826-
auto storageTy = Types.getSubstitutedStorageType(var,
3827-
componentObjTy);
3819+
auto storageTy = Types.getSubstitutedStorageType(var, componentObjTy);
38283820
auto opaqueTy = Types
38293821
.getLoweredType(AbstractionPattern::getOpaque(), componentObjTy);
38303822

@@ -4008,7 +4000,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
40084000
auto sub = cast<SubscriptDecl>(component.getDeclRef().getDecl());
40094001
lowerKeyPathSubscriptIndexTypes(
40104002
SGF.SGM, indexTypes, sub,
4011-
component.getDeclRef().getSubstitutions().toList(),
4003+
component.getDeclRef().getSubstitutions(),
40124004
needsGenericContext);
40134005
lowerKeyPathSubscriptIndexPatterns(indices, indexTypes,
40144006
component.getSubscriptIndexHashableConformances(),
@@ -4044,7 +4036,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
40444036
SGF.F.getGenericEnvironment(),
40454037
numOperands,
40464038
needsGenericContext,
4047-
component.getDeclRef().getSubstitutions().toList(),
4039+
component.getDeclRef().getSubstitutions(),
40484040
decl,
40494041
component.getSubscriptIndexHashableConformances(),
40504042
baseTy,

0 commit comments

Comments
 (0)