Skip to content

Commit 5942049

Browse files
committed
Set substitutions on storage abstraction patterns in l-value access.
Fixes a host of problems with stored type members with types dependent on a type parameter pack; I ran into it specifically with vanishing tuples. Test to follow.
1 parent df82443 commit 5942049

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ static LValueTypeData getPhysicalStorageTypeData(TypeExpansionContext context,
233233
SILGenModule &SGM,
234234
SGFAccessKind accessKind,
235235
AbstractStorageDecl *storage,
236+
SubstitutionMap subs,
236237
CanType substFormalType) {
237238
assert(!isa<ReferenceStorageType>(substFormalType));
238239
auto origFormalType = SGM.Types.getAbstractionPattern(storage)
239-
.getReferenceStorageReferentType();
240+
.getReferenceStorageReferentType()
241+
.withSubstitutions(subs);
240242
return getAbstractedTypeData(context, SGM, accessKind, origFormalType,
241243
substFormalType);
242244
}
@@ -2801,22 +2803,25 @@ namespace {
28012803
struct AccessEmitter {
28022804
SILGenFunction &SGF;
28032805
StorageType *Storage;
2806+
SubstitutionMap Subs;
28042807
CanType FormalRValueType;
28052808
SGFAccessKind AccessKind;
28062809

28072810
Impl &asImpl() { return static_cast<Impl&>(*this); }
28082811

28092812
AccessEmitter(SILGenFunction &SGF, StorageType *storage,
2810-
SGFAccessKind accessKind, CanType formalRValueType)
2811-
: SGF(SGF), Storage(storage), FormalRValueType(formalRValueType),
2812-
AccessKind(accessKind) {}
2813+
SubstitutionMap subs, SGFAccessKind accessKind,
2814+
CanType formalRValueType)
2815+
: SGF(SGF), Storage(storage), Subs(subs),
2816+
FormalRValueType(formalRValueType), AccessKind(accessKind) {}
28132817

28142818
void emitUsingStrategy(AccessStrategy strategy) {
28152819
switch (strategy.getKind()) {
28162820
case AccessStrategy::Storage: {
28172821
auto typeData =
28182822
getPhysicalStorageTypeData(SGF.getTypeExpansionContext(), SGF.SGM,
2819-
AccessKind, Storage, FormalRValueType);
2823+
AccessKind, Storage, Subs,
2824+
FormalRValueType);
28202825
return asImpl().emitUsingStorage(typeData);
28212826
}
28222827

@@ -2862,15 +2867,17 @@ namespace {
28622867
case AccessorKind::MutableAddress: {
28632868
auto typeData =
28642869
getPhysicalStorageTypeData(SGF.getTypeExpansionContext(), SGF.SGM,
2865-
AccessKind, Storage, FormalRValueType);
2870+
AccessKind, Storage, Subs,
2871+
FormalRValueType);
28662872
return asImpl().emitUsingAddressor(accessor, isDirect, typeData);
28672873
}
28682874

28692875
case AccessorKind::Read:
28702876
case AccessorKind::Modify: {
28712877
auto typeData =
28722878
getPhysicalStorageTypeData(SGF.getTypeExpansionContext(), SGF.SGM,
2873-
AccessKind, Storage, FormalRValueType);
2879+
AccessKind, Storage, Subs,
2880+
FormalRValueType);
28742881
return asImpl().emitUsingCoroutineAccessor(accessor, isDirect,
28752882
typeData);
28762883
}
@@ -2944,7 +2951,6 @@ void LValue::addNonMemberVarComponent(SILGenFunction &SGF, SILLocation loc,
29442951
AccessEmitter<NonMemberVarAccessEmitter, VarDecl> {
29452952
LValue &LV;
29462953
SILLocation Loc;
2947-
SubstitutionMap Subs;
29482954
LValueOptions Options;
29492955
Optional<ActorIsolation> ActorIso;
29502956

@@ -2955,8 +2961,8 @@ void LValue::addNonMemberVarComponent(SILGenFunction &SGF, SILLocation loc,
29552961
LValueOptions options,
29562962
Optional<ActorIsolation> actorIso,
29572963
LValue &lv)
2958-
: AccessEmitter(SGF, var, accessKind, formalRValueType),
2959-
LV(lv), Loc(loc), Subs(subs), Options(options), ActorIso(actorIso) {}
2964+
: AccessEmitter(SGF, var, subs, accessKind, formalRValueType),
2965+
LV(lv), Loc(loc), Options(options), ActorIso(actorIso) {}
29602966

29612967
void emitUsingAddressor(SILDeclRef addressor, bool isDirect,
29622968
LValueTypeData typeData) {
@@ -3538,14 +3544,14 @@ struct MemberStorageAccessEmitter : AccessEmitter<Impl, StorageType> {
35383544
using super = AccessEmitter<Impl, StorageType>;
35393545
using super::SGF;
35403546
using super::Storage;
3547+
using super::Subs;
35413548
using super::FormalRValueType;
35423549
LValue &LV;
35433550
LValueOptions Options;
35443551
SILLocation Loc;
35453552
bool IsSuper;
35463553
bool IsOnSelfParameter; // Is self the self parameter in context.
35473554
CanType BaseFormalType;
3548-
SubstitutionMap Subs;
35493555
ArgumentList *ArgListForDiagnostics;
35503556
PreparedArguments Indices;
35513557
// If any, holds the actor we must switch to when performing the access.
@@ -3558,9 +3564,9 @@ struct MemberStorageAccessEmitter : AccessEmitter<Impl, StorageType> {
35583564
LValue &lv, ArgumentList *argListForDiagnostics,
35593565
PreparedArguments &&indices, bool isSelf = false,
35603566
Optional<ActorIsolation> actorIso = None)
3561-
: super(SGF, storage, accessKind, formalRValueType), LV(lv),
3567+
: super(SGF, storage, subs, accessKind, formalRValueType), LV(lv),
35623568
Options(options), Loc(loc), IsSuper(isSuper), IsOnSelfParameter(isSelf),
3563-
BaseFormalType(lv.getSubstFormalType()), Subs(subs),
3569+
BaseFormalType(lv.getSubstFormalType()),
35643570
ArgListForDiagnostics(argListForDiagnostics),
35653571
Indices(std::move(indices)), ActorIso(actorIso) {}
35663572

0 commit comments

Comments
 (0)