@@ -2408,37 +2408,34 @@ namespace {
2408
2408
};
2409
2409
}
2410
2410
2411
- SubstitutionMap
2412
- SILGenModule::getNonMemberVarDeclSubstitutions (VarDecl *var) {
2413
- auto *dc = var->getDeclContext ();
2414
- if (auto *genericEnv = dc->getGenericEnvironmentOfContext ())
2415
- return genericEnv->getForwardingSubstitutionMap ();
2416
-
2417
- return SubstitutionMap ();
2418
- }
2419
-
2420
2411
static LValue emitLValueForNonMemberVarDecl (SILGenFunction &SGF,
2421
- SILLocation loc, VarDecl *var,
2412
+ SILLocation loc,
2413
+ ConcreteDeclRef declRef,
2422
2414
CanType formalRValueType,
2423
2415
SGFAccessKind accessKind,
2424
2416
LValueOptions options,
2425
2417
AccessSemantics semantics) {
2426
2418
LValue lv;
2427
2419
2420
+ auto *var = cast<VarDecl>(declRef.getDecl ());
2421
+ auto subs = declRef.getSubstitutions ();
2422
+ if (!subs)
2423
+ subs = SGF.F .getForwardingSubstitutionMap ();
2424
+
2428
2425
auto access = getFormalAccessKind (accessKind);
2429
2426
auto strategy = var->getAccessStrategy (semantics, access,
2430
2427
SGF.SGM .M .getSwiftModule (),
2431
2428
SGF.F .getResilienceExpansion ());
2432
2429
2433
- lv.addNonMemberVarComponent (SGF, loc, var, /* be lazy */ None ,
2430
+ lv.addNonMemberVarComponent (SGF, loc, var, subs ,
2434
2431
options, accessKind, strategy, formalRValueType);
2435
2432
2436
2433
return lv;
2437
2434
}
2438
2435
2439
2436
void LValue::addNonMemberVarComponent (SILGenFunction &SGF, SILLocation loc,
2440
2437
VarDecl *var,
2441
- Optional< SubstitutionMap> subs,
2438
+ SubstitutionMap subs,
2442
2439
LValueOptions options,
2443
2440
SGFAccessKind accessKind,
2444
2441
AccessStrategy strategy,
@@ -2447,17 +2444,11 @@ void LValue::addNonMemberVarComponent(SILGenFunction &SGF, SILLocation loc,
2447
2444
AccessEmitter<NonMemberVarAccessEmitter, VarDecl> {
2448
2445
LValue &LV;
2449
2446
SILLocation Loc;
2450
- Optional< SubstitutionMap> Subs;
2447
+ SubstitutionMap Subs;
2451
2448
LValueOptions Options;
2452
2449
2453
- SubstitutionMap getSubs () {
2454
- if (Subs) return *Subs;
2455
- Subs = SGF.SGM .getNonMemberVarDeclSubstitutions (Storage);
2456
- return *Subs;
2457
- }
2458
-
2459
2450
NonMemberVarAccessEmitter (SILGenFunction &SGF, SILLocation loc,
2460
- VarDecl *var, Optional< SubstitutionMap> subs,
2451
+ VarDecl *var, SubstitutionMap subs,
2461
2452
SGFAccessKind accessKind,
2462
2453
CanType formalRValueType,
2463
2454
LValueOptions options, LValue &lv)
@@ -2469,7 +2460,7 @@ void LValue::addNonMemberVarComponent(SILGenFunction &SGF, SILLocation loc,
2469
2460
SILType storageType =
2470
2461
SGF.getLoweredType (Storage->getType ()).getAddressType ();
2471
2462
LV.add <AddressorComponent>(Storage, addressor,
2472
- /* isSuper=*/ false , isDirect, getSubs () ,
2463
+ /* isSuper=*/ false , isDirect, Subs ,
2473
2464
CanType (), typeData, storageType, nullptr ,
2474
2465
PreparedArguments (),
2475
2466
/* isOnSelfParameter */ false );
@@ -2479,23 +2470,23 @@ void LValue::addNonMemberVarComponent(SILGenFunction &SGF, SILLocation loc,
2479
2470
LValueTypeData typeData) {
2480
2471
LV.add <CoroutineAccessorComponent>(
2481
2472
Storage, accessor,
2482
- /* isSuper*/ false , isDirect, getSubs () , CanType (), typeData, nullptr ,
2473
+ /* isSuper*/ false , isDirect, Subs , CanType (), typeData, nullptr ,
2483
2474
PreparedArguments (), /* isOnSelfParameter*/ false );
2484
2475
}
2485
2476
2486
2477
void emitUsingGetterSetter (SILDeclRef accessor, bool isDirect,
2487
2478
LValueTypeData typeData) {
2488
2479
LV.add <GetterSetterComponent>(
2489
2480
Storage, accessor,
2490
- /* isSuper=*/ false , isDirect, getSubs () , CanType (), typeData, nullptr ,
2481
+ /* isSuper=*/ false , isDirect, Subs , CanType (), typeData, nullptr ,
2491
2482
PreparedArguments (), /* isOnSelfParameter */ false );
2492
2483
}
2493
2484
2494
2485
void emitUsingMaterialization (AccessStrategy readStrategy,
2495
2486
AccessStrategy writeStrategy,
2496
2487
LValueTypeData typeData) {
2497
2488
LV.add <MaterializeToTemporaryComponent>(
2498
- Storage, /* super*/ false , getSubs () , Options, readStrategy,
2489
+ Storage, /* super*/ false , Subs , Options, readStrategy,
2499
2490
writeStrategy,
2500
2491
/* base type*/ CanType (), typeData, nullptr , PreparedArguments (),
2501
2492
/* isOnSelfParameter */ false );
@@ -2574,13 +2565,14 @@ SILGenFunction::emitAddressOfLocalVarDecl(SILLocation loc, VarDecl *var,
2574
2565
}
2575
2566
2576
2567
RValue SILGenFunction::emitRValueForNonMemberVarDecl (SILLocation loc,
2577
- VarDecl *var ,
2568
+ ConcreteDeclRef declRef ,
2578
2569
CanType formalRValueType,
2579
2570
AccessSemantics semantics,
2580
2571
SGFContext C) {
2581
2572
// Any writebacks for this access are tightly scoped.
2582
2573
FormalEvaluationScope scope (*this );
2583
2574
2575
+ auto *var = cast<VarDecl>(declRef.getDecl ());
2584
2576
auto localValue = maybeEmitValueOfLocalVarDecl (var);
2585
2577
2586
2578
// If this VarDecl is represented as an address, emit it as an lvalue, then
@@ -2678,7 +2670,8 @@ RValue SILGenFunction::emitRValueForNonMemberVarDecl(SILLocation loc,
2678
2670
? Result : Result.copyUnmanaged (*this , loc));
2679
2671
}
2680
2672
2681
- LValue lv = emitLValueForNonMemberVarDecl (*this , loc, var, formalRValueType,
2673
+ LValue lv = emitLValueForNonMemberVarDecl (*this , loc, declRef,
2674
+ formalRValueType,
2682
2675
SGFAccessKind::OwnedObjectRead,
2683
2676
LValueOptions (), semantics);
2684
2677
return emitLoadOfLValue (loc, std::move (lv), C);
@@ -2703,8 +2696,7 @@ LValue SILGenLValue::visitDiscardAssignmentExpr(DiscardAssignmentExpr *e,
2703
2696
2704
2697
LValue SILGenLValue::visitDeclRefExpr (DeclRefExpr *e, SGFAccessKind accessKind,
2705
2698
LValueOptions options) {
2706
- // The only non-member decl that can be an lvalue is VarDecl.
2707
- return emitLValueForNonMemberVarDecl (SGF, e, cast<VarDecl>(e->getDecl ()),
2699
+ return emitLValueForNonMemberVarDecl (SGF, e, e->getDeclRef (),
2708
2700
getSubstFormalRValueType (e),
2709
2701
accessKind, options,
2710
2702
e->getAccessSemantics ());
0 commit comments