Skip to content

Commit 2fc2273

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 d779a8f commit 2fc2273

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
}
@@ -2810,22 +2812,25 @@ namespace {
28102812
struct AccessEmitter {
28112813
SILGenFunction &SGF;
28122814
StorageType *Storage;
2815+
SubstitutionMap Subs;
28132816
CanType FormalRValueType;
28142817
SGFAccessKind AccessKind;
28152818

28162819
Impl &asImpl() { return static_cast<Impl&>(*this); }
28172820

28182821
AccessEmitter(SILGenFunction &SGF, StorageType *storage,
2819-
SGFAccessKind accessKind, CanType formalRValueType)
2820-
: SGF(SGF), Storage(storage), FormalRValueType(formalRValueType),
2821-
AccessKind(accessKind) {}
2822+
SubstitutionMap subs, SGFAccessKind accessKind,
2823+
CanType formalRValueType)
2824+
: SGF(SGF), Storage(storage), Subs(subs),
2825+
FormalRValueType(formalRValueType), AccessKind(accessKind) {}
28222826

28232827
void emitUsingStrategy(AccessStrategy strategy) {
28242828
switch (strategy.getKind()) {
28252829
case AccessStrategy::Storage: {
28262830
auto typeData =
28272831
getPhysicalStorageTypeData(SGF.getTypeExpansionContext(), SGF.SGM,
2828-
AccessKind, Storage, FormalRValueType);
2832+
AccessKind, Storage, Subs,
2833+
FormalRValueType);
28292834
return asImpl().emitUsingStorage(typeData);
28302835
}
28312836

@@ -2871,15 +2876,17 @@ namespace {
28712876
case AccessorKind::MutableAddress: {
28722877
auto typeData =
28732878
getPhysicalStorageTypeData(SGF.getTypeExpansionContext(), SGF.SGM,
2874-
AccessKind, Storage, FormalRValueType);
2879+
AccessKind, Storage, Subs,
2880+
FormalRValueType);
28752881
return asImpl().emitUsingAddressor(accessor, isDirect, typeData);
28762882
}
28772883

28782884
case AccessorKind::Read:
28792885
case AccessorKind::Modify: {
28802886
auto typeData =
28812887
getPhysicalStorageTypeData(SGF.getTypeExpansionContext(), SGF.SGM,
2882-
AccessKind, Storage, FormalRValueType);
2888+
AccessKind, Storage, Subs,
2889+
FormalRValueType);
28832890
return asImpl().emitUsingCoroutineAccessor(accessor, isDirect,
28842891
typeData);
28852892
}
@@ -2953,7 +2960,6 @@ void LValue::addNonMemberVarComponent(SILGenFunction &SGF, SILLocation loc,
29532960
AccessEmitter<NonMemberVarAccessEmitter, VarDecl> {
29542961
LValue &LV;
29552962
SILLocation Loc;
2956-
SubstitutionMap Subs;
29572963
LValueOptions Options;
29582964
Optional<ActorIsolation> ActorIso;
29592965

@@ -2964,8 +2970,8 @@ void LValue::addNonMemberVarComponent(SILGenFunction &SGF, SILLocation loc,
29642970
LValueOptions options,
29652971
Optional<ActorIsolation> actorIso,
29662972
LValue &lv)
2967-
: AccessEmitter(SGF, var, accessKind, formalRValueType),
2968-
LV(lv), Loc(loc), Subs(subs), Options(options), ActorIso(actorIso) {}
2973+
: AccessEmitter(SGF, var, subs, accessKind, formalRValueType),
2974+
LV(lv), Loc(loc), Options(options), ActorIso(actorIso) {}
29692975

29702976
void emitUsingAddressor(SILDeclRef addressor, bool isDirect,
29712977
LValueTypeData typeData) {
@@ -3512,14 +3518,14 @@ struct MemberStorageAccessEmitter : AccessEmitter<Impl, StorageType> {
35123518
using super = AccessEmitter<Impl, StorageType>;
35133519
using super::SGF;
35143520
using super::Storage;
3521+
using super::Subs;
35153522
using super::FormalRValueType;
35163523
LValue &LV;
35173524
LValueOptions Options;
35183525
SILLocation Loc;
35193526
bool IsSuper;
35203527
bool IsOnSelfParameter; // Is self the self parameter in context.
35213528
CanType BaseFormalType;
3522-
SubstitutionMap Subs;
35233529
ArgumentList *ArgListForDiagnostics;
35243530
PreparedArguments Indices;
35253531
// If any, holds the actor we must switch to when performing the access.
@@ -3532,9 +3538,9 @@ struct MemberStorageAccessEmitter : AccessEmitter<Impl, StorageType> {
35323538
LValue &lv, ArgumentList *argListForDiagnostics,
35333539
PreparedArguments &&indices, bool isSelf = false,
35343540
Optional<ActorIsolation> actorIso = None)
3535-
: super(SGF, storage, accessKind, formalRValueType), LV(lv),
3541+
: super(SGF, storage, subs, accessKind, formalRValueType), LV(lv),
35363542
Options(options), Loc(loc), IsSuper(isSuper), IsOnSelfParameter(isSelf),
3537-
BaseFormalType(lv.getSubstFormalType()), Subs(subs),
3543+
BaseFormalType(lv.getSubstFormalType()),
35383544
ArgListForDiagnostics(argListForDiagnostics),
35393545
Indices(std::move(indices)), ActorIso(actorIso) {}
35403546

0 commit comments

Comments
 (0)