@@ -3776,108 +3776,6 @@ getFormalStorageAbstractionPattern(SILGenFunction &SGF, AbstractStorageDecl *fie
3776
3776
return SGF.SGM .Types .getAbstractionPattern (sub);
3777
3777
}
3778
3778
3779
- static SILDeclRef getRValueAccessorDeclRef (SILGenFunction &SGF,
3780
- AbstractStorageDecl *storage,
3781
- AccessStrategy strategy) {
3782
- switch (strategy.getKind ()) {
3783
- case AccessStrategy::BehaviorStorage:
3784
- llvm_unreachable (" shouldn't load an rvalue via behavior storage!" );
3785
-
3786
- case AccessStrategy::Storage:
3787
- llvm_unreachable (" should already have been filtered out!" );
3788
-
3789
- case AccessStrategy::MaterializeToTemporary:
3790
- llvm_unreachable (" never used for read accesses" );
3791
-
3792
- case AccessStrategy::DirectToAccessor:
3793
- case AccessStrategy::DispatchToAccessor: {
3794
- auto accessor = strategy.getAccessor ();
3795
- return SGF.SGM .getAccessorDeclRef (storage->getAccessor (accessor));
3796
- }
3797
- }
3798
- llvm_unreachable (" should already have been filtered out!" );
3799
- }
3800
-
3801
- static RValue getTargetRValue (SILGenFunction &SGF, SILLocation loc,
3802
- ManagedValue value,
3803
- AbstractionPattern origFormalType,
3804
- CanType substFormalType,
3805
- SGFContext C) {
3806
- SILType loweredSubstType = SGF.getLoweredType (substFormalType);
3807
-
3808
- bool hasAbstraction =
3809
- (loweredSubstType.getObjectType () != value.getType ().getObjectType ());
3810
-
3811
- if (value.isLValue () ||
3812
- (value.getType ().isAddress () && !loweredSubstType.isAddress ())) {
3813
- auto isTake =
3814
- IsTake_t (!value.isLValue () && !value.isPlusZeroRValueOrTrivial ());
3815
- value = SGF.emitLoad (loc,
3816
- (isTake ? value.forward (SGF)
3817
- : value.getUnmanagedValue ()),
3818
- SGF.getTypeLowering (value.getType ()),
3819
- (hasAbstraction ? SGFContext () : C),
3820
- isTake);
3821
- }
3822
-
3823
- RValue result (SGF, loc, substFormalType, value);
3824
- if (hasAbstraction) {
3825
- result = SGF.emitOrigToSubstValue (loc, std::move (result), origFormalType,
3826
- substFormalType, C);
3827
- }
3828
- return result;
3829
- }
3830
-
3831
- static RValue
3832
- emitRValueWithAccessor (SILGenFunction &SGF, SILLocation loc,
3833
- AbstractStorageDecl *storage,
3834
- SubstitutionMap substitutions,
3835
- ArgumentSource &&baseRV,
3836
- PreparedArguments &&subscriptIndices,
3837
- bool isSuper, AccessStrategy strategy,
3838
- SILDeclRef accessor,
3839
- AbstractionPattern origFormalType,
3840
- CanType substFormalType,
3841
- SGFContext C) {
3842
- assert (strategy.getKind () == AccessStrategy::DirectToAccessor ||
3843
- strategy.getKind () == AccessStrategy::DispatchToAccessor);
3844
- bool isDirectUse = (strategy.getKind () == AccessStrategy::DirectToAccessor);
3845
-
3846
- // The easy path here is if we don't need to use an addressor.
3847
- if (strategy.getAccessor () == AccessorKind::Get) {
3848
- return SGF.emitGetAccessor (loc, accessor, substitutions,
3849
- std::move (baseRV), isSuper, isDirectUse,
3850
- std::move (subscriptIndices), C);
3851
- }
3852
-
3853
- assert (strategy.getAccessor () == AccessorKind::Address);
3854
-
3855
- auto &storageTL = SGF.getTypeLowering (origFormalType, substFormalType);
3856
- SILType storageType = storageTL.getLoweredType ().getAddressType ();
3857
-
3858
- auto addressorResult =
3859
- SGF.emitAddressorAccessor (loc, accessor, substitutions,
3860
- std::move (baseRV), isSuper, isDirectUse,
3861
- std::move (subscriptIndices), storageType);
3862
-
3863
- RValue result = getTargetRValue (SGF, loc, addressorResult.first ,
3864
- origFormalType, substFormalType, C);
3865
-
3866
- switch (cast<AccessorDecl>(accessor.getDecl ())->getAddressorKind ()) {
3867
- case AddressorKind::NotAddressor: llvm_unreachable (" inconsistent" );
3868
- case AddressorKind::Unsafe:
3869
- // Nothing to do.
3870
- break ;
3871
- case AddressorKind::Owning:
3872
- case AddressorKind::NativeOwning:
3873
- // Emit the release immediately.
3874
- SGF.B .emitDestroyValueOperation (loc, addressorResult.second .forward (SGF));
3875
- break ;
3876
- }
3877
-
3878
- return result;
3879
- }
3880
-
3881
3779
// / Produce a singular RValue for a load from the specified property. This is
3882
3780
// / designed to work with RValue ManagedValue bases that are either +0 or +1.
3883
3781
RValue SILGenFunction::emitRValueForStorageLoad (
@@ -3892,21 +3790,25 @@ RValue SILGenFunction::emitRValueForStorageLoad(
3892
3790
3893
3791
// If we should call an accessor of some kind, do so.
3894
3792
if (strategy.getKind () != AccessStrategy::Storage) {
3895
- auto accessor = getRValueAccessorDeclRef (*this , storage, strategy);
3896
- ArgumentSource baseRV = prepareAccessorBaseArg (loc, base,
3897
- baseFormalType,
3898
- accessor);
3899
-
3900
- AbstractionPattern origFormalType =
3901
- getFormalStorageAbstractionPattern (*this , storage);
3902
- auto substFormalType = propTy->getCanonicalType ();
3903
-
3904
- return emitRValueWithAccessor (*this , loc, storage, substitutions,
3905
- std::move (baseRV),
3906
- std::move (subscriptIndices),
3907
- isSuper, strategy, accessor,
3908
- origFormalType, substFormalType, C);
3793
+ auto accessKind = SGFAccessKind::OwnedObjectRead;
3794
+
3795
+ LValue lv = [&] {
3796
+ if (!base) return LValue ();
3797
+
3798
+ auto baseAccess = getBaseAccessKind (SGM, storage, accessKind,
3799
+ strategy, baseFormalType);
3800
+ return LValue::forValue (baseAccess, base, baseFormalType);
3801
+ }();
3802
+
3803
+ lv.addMemberComponent (*this , loc, storage, substitutions, LValueOptions (),
3804
+ isSuper, accessKind, strategy,
3805
+ propTy->getCanonicalType (),
3806
+ std::move (subscriptIndices),
3807
+ /* index for diagnostics*/ nullptr );
3808
+
3809
+ return emitLoadOfLValue (loc, std::move (lv), C, isBaseGuaranteed);
3909
3810
}
3811
+
3910
3812
assert (isa<VarDecl>(storage) && " only properties should have storage" );
3911
3813
auto field = cast<VarDecl>(storage);
3912
3814
assert (field->hasStorage () &&
0 commit comments