@@ -167,10 +167,6 @@ SILGenFunction::getUnknownEnforcement(VarDecl *var) {
167
167
class LLVM_LIBRARY_VISIBILITY SILGenLValue
168
168
: public Lowering::ExprVisitor<SILGenLValue, LValue, AccessKind>
169
169
{
170
- // / A mapping from opaque value expressions to the open-existential
171
- // / expression that determines them.
172
- llvm::SmallDenseMap<OpaqueValueExpr *, OpenExistentialExpr *>
173
- openedExistentials;
174
170
175
171
public:
176
172
SILGenFunction &SGF;
@@ -591,6 +587,8 @@ namespace {
591
587
" base for open existential component must be an existential" );
592
588
assert (base.getType ().isAddress () &&
593
589
" base value of open-existential component was not an address?" );
590
+ assert (base.getType ().getPreferredExistentialRepresentation (SGF.SGM .M )
591
+ == ExistentialRepresentation::Opaque);
594
592
595
593
SILValue addr = SGF.B .createOpenExistentialAddr (
596
594
loc, base.getValue (), getTypeOfRValue ().getAddressType (),
@@ -1909,11 +1907,11 @@ LValue SILGenLValue::visitDeclRefExpr(DeclRefExpr *e, AccessKind accessKind) {
1909
1907
LValue SILGenLValue::visitOpaqueValueExpr (OpaqueValueExpr *e,
1910
1908
AccessKind accessKind) {
1911
1909
// Handle an opaque lvalue that refers to an opened existential.
1912
- auto known = openedExistentials .find (e);
1913
- if (known != openedExistentials .end ()) {
1910
+ auto known = SGF. OpaqueValueExprs .find (e);
1911
+ if (known != SGF. OpaqueValueExprs .end ()) {
1914
1912
// Dig the open-existential expression out of the list.
1915
1913
OpenExistentialExpr *opened = known->second ;
1916
- openedExistentials .erase (known);
1914
+ SGF. OpaqueValueExprs .erase (known);
1917
1915
1918
1916
// Do formal evaluation of the underlying existential lvalue.
1919
1917
LValue lv = visitRec (opened->getExistentialValue (), accessKind);
@@ -2206,15 +2204,15 @@ LValue SILGenLValue::visitOpenExistentialExpr(OpenExistentialExpr *e,
2206
2204
2207
2205
// Record the fact that we're opening this existential. The actual
2208
2206
// opening operation will occur when we see the OpaqueValueExpr.
2209
- bool inserted = openedExistentials .insert ({e->getOpaqueValue (), e}).second ;
2207
+ bool inserted = SGF. OpaqueValueExprs .insert ({e->getOpaqueValue (), e}).second ;
2210
2208
(void )inserted;
2211
2209
assert (inserted && " already have this opened existential?" );
2212
2210
2213
2211
// Visit the subexpression.
2214
2212
LValue lv = visitRec (e->getSubExpr (), accessKind);
2215
2213
2216
2214
// Sanity check that we did see the OpaqueValueExpr.
2217
- assert (openedExistentials .count (e->getOpaqueValue ()) == 0 &&
2215
+ assert (SGF. OpaqueValueExprs .count (e->getOpaqueValue ()) == 0 &&
2218
2216
" opened existential not removed?" );
2219
2217
return lv;
2220
2218
}
@@ -2731,6 +2729,7 @@ static ManagedValue drillIntoComponent(SILGenFunction &SGF,
2731
2729
ManagedValue base,
2732
2730
AccessKind accessKind,
2733
2731
TSanKind tsanKind) {
2732
+ bool isRValue = component.isRValue ();
2734
2733
ManagedValue addr;
2735
2734
if (component.isPhysical ()) {
2736
2735
addr = std::move (component.asPhysical ()).offset (SGF, loc, base, accessKind);
@@ -2741,7 +2740,7 @@ static ManagedValue drillIntoComponent(SILGenFunction &SGF,
2741
2740
2742
2741
if (!SGF.getASTContext ().LangOpts .DisableTsanInoutInstrumentation &&
2743
2742
SGF.getModule ().getOptions ().Sanitize == SanitizerKind::Thread &&
2744
- tsanKind == TSanKind::InoutAccess && !component. isRValue () ) {
2743
+ tsanKind == TSanKind::InoutAccess && !isRValue) {
2745
2744
emitTsanInoutAccess (SGF, loc, addr);
2746
2745
}
2747
2746
@@ -2781,6 +2780,9 @@ RValue SILGenFunction::emitLoadOfLValue(SILLocation loc, LValue &&src,
2781
2780
// Any writebacks should be scoped to after the load.
2782
2781
FormalEvaluationScope scope (*this );
2783
2782
2783
+ auto substFormalType = src.getSubstFormalType ();
2784
+ auto &rvalueTL = getTypeLowering (src.getTypeOfRValue ());
2785
+
2784
2786
ManagedValue addr;
2785
2787
PathComponent &&component =
2786
2788
drillToLastComponent (*this , loc, std::move (src), addr, AccessKind::Read);
@@ -2789,9 +2791,9 @@ RValue SILGenFunction::emitLoadOfLValue(SILLocation loc, LValue &&src,
2789
2791
if (component.isPhysical ()) {
2790
2792
addr = std::move (component.asPhysical ())
2791
2793
.offset (*this , loc, addr, AccessKind::Read);
2792
- return RValue (*this , loc, src. getSubstFormalType () ,
2794
+ return RValue (*this , loc, substFormalType ,
2793
2795
emitLoad (loc, addr.getValue (),
2794
- getTypeLowering (src. getTypeOfRValue ()) , C, IsNotTake,
2796
+ rvalueTL , C, IsNotTake,
2795
2797
isGuaranteedValid));
2796
2798
}
2797
2799
@@ -2890,6 +2892,8 @@ void SILGenFunction::emitAssignLValueToLValue(SILLocation loc, LValue &&src,
2890
2892
return ;
2891
2893
}
2892
2894
2895
+ auto &rvalueTL = getTypeLowering (src.getTypeOfRValue ());
2896
+
2893
2897
auto srcAddr = emitAddressOfLValue (loc, std::move (src), AccessKind::Read)
2894
2898
.getUnmanagedValue ();
2895
2899
auto destAddr = emitAddressOfLValue (loc, std::move (dest), AccessKind::Write)
@@ -2899,9 +2903,7 @@ void SILGenFunction::emitAssignLValueToLValue(SILLocation loc, LValue &&src,
2899
2903
B.createCopyAddr (loc, srcAddr, destAddr, IsNotTake, IsNotInitialization);
2900
2904
} else {
2901
2905
// If there's a semantic conversion necessary, do a load then assign.
2902
- auto loaded = emitLoad (loc, srcAddr, getTypeLowering (src.getTypeOfRValue ()),
2903
- SGFContext (),
2904
- IsNotTake);
2906
+ auto loaded = emitLoad (loc, srcAddr, rvalueTL, SGFContext (), IsNotTake);
2905
2907
loaded.assignInto (*this , loc, destAddr);
2906
2908
}
2907
2909
}
0 commit comments