@@ -1920,12 +1920,7 @@ void PatternMatchEmission::emitEnumElementObjectDispatch(
1920
1920
ManagedValue boxedValue =
1921
1921
SGF.B .createProjectBox (loc, origCMV.getFinalManagedValue (), 0 );
1922
1922
eltTL = &SGF.getTypeLowering (boxedValue.getType ());
1923
-
1924
- // TODO: If we have something that is not loadable
1925
1923
if (eltTL->isLoadable ()) {
1926
- // The boxed value may be shared, so we need to load the value at +0
1927
- // to make sure that we copy if we try to use it outside of the switch
1928
- // statement itself.
1929
1924
boxedValue = SGF.B .createLoadBorrow (loc, boxedValue);
1930
1925
eltCMV = {boxedValue, CastConsumptionKind::BorrowAlways};
1931
1926
} else {
@@ -2151,37 +2146,20 @@ void PatternMatchEmission::emitEnumElementDispatch(
2151
2146
2152
2147
// If the payload is boxed, project it.
2153
2148
if (elt->isIndirect () || elt->getParentEnum ()->isIndirect ()) {
2154
- SILValue boxedValue = SGF.B .createProjectBox (loc, origCMV.getValue (), 0 );
2155
- eltTL = &SGF.getTypeLowering (boxedValue->getType ());
2149
+ ManagedValue boxedValue =
2150
+ SGF.B .createProjectBox (loc, origCMV.getFinalManagedValue (), 0 );
2151
+ eltTL = &SGF.getTypeLowering (boxedValue.getType ());
2156
2152
if (eltTL->isLoadable ()) {
2157
- UnenforcedAccess access;
2158
- SILValue accessAddress =
2159
- access.beginAccess (SGF, loc, boxedValue, SILAccessKind::Read);
2160
-
2161
- // If we needed to do another begin_access, we need to perform a
2162
- // load_copy. This is because we are going to immediately close the
2163
- // access here. If we are already in a different access, we can
2164
- // perform a load_borrow instead here.
2165
- auto accessMV = ManagedValue::forUnmanaged (accessAddress);
2166
- ManagedValue newLoadedBoxValue;
2167
- if (accessAddress == boxedValue) {
2168
- eltCMV = {SGF.B .createLoadBorrow (loc, accessMV),
2169
- CastConsumptionKind::BorrowAlways};
2170
- } else {
2171
- // Since we made a copy, send down TakeAlways.
2172
- eltCMV = {SGF.B .createLoadCopy (loc, accessMV),
2173
- CastConsumptionKind::TakeAlways};
2174
- }
2175
- access.endAccess (SGF);
2153
+ boxedValue = SGF.B .createLoadBorrow (loc, boxedValue);
2154
+ eltCMV = {boxedValue, CastConsumptionKind::BorrowAlways};
2176
2155
} else {
2177
2156
// The boxed value may be shared, so we always have to copy it.
2178
- eltCMV = getManagedSubobject (SGF, boxedValue, *eltTL,
2157
+ eltCMV = getManagedSubobject (SGF, boxedValue. getValue () , *eltTL,
2179
2158
CastConsumptionKind::CopyOnSuccess);
2180
2159
}
2181
2160
}
2182
2161
2183
2162
// Reabstract to the substituted type, if needed.
2184
-
2185
2163
CanType substEltTy =
2186
2164
sourceType->getTypeOfMember (SGF.SGM .M .getSwiftModule (), elt,
2187
2165
elt->getArgumentInterfaceType ())
0 commit comments