File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -1593,7 +1593,10 @@ static void unwrapExistential(OpaqueValue *src,
1593
1593
auto opaqueContainer = reinterpret_cast <OpaqueExistentialContainer*>(src);
1594
1594
srcCapturedType = opaqueContainer->Type ;
1595
1595
srcValue = srcType->projectValue (src);
1596
- canTake = false ;
1596
+ // Can't take out of possibly shared existential boxes.
1597
+ canTake = (src == srcValue);
1598
+ assert (canTake == srcCapturedType->getValueWitnesses ()->isValueInline () &&
1599
+ " Only inline storage is take-able" );
1597
1600
#else
1598
1601
auto opaqueContainer = reinterpret_cast <OpaqueExistentialContainer*>(src);
1599
1602
srcCapturedType = opaqueContainer->Type ;
@@ -1653,9 +1656,7 @@ static bool _dynamicCastFromExistential(OpaqueValue *dest,
1653
1656
} else {
1654
1657
#ifdef SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS
1655
1658
assert (!isOutOfLine &&
1656
- srcType->getRepresentation () !=
1657
- ExistentialTypeRepresentation::Opaque &&
1658
- " Should only see inline represenations and no opaque existential" );
1659
+ " Should only see inline represenations of existentials" );
1659
1660
#else
1660
1661
// swift_dynamicCast took or destroyed the value as per the original request
1661
1662
// We may still have an opaque existential container to deallocate.
Original file line number Diff line number Diff line change @@ -2228,8 +2228,13 @@ ExistentialTypeMetadata::mayTakeValue(const OpaqueValue *container) const {
2228
2228
// Opaque existential containers uniquely own their contained value.
2229
2229
case ExistentialTypeRepresentation::Opaque:
2230
2230
#ifdef SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS
2231
+ {
2231
2232
// We can't take from a shared existential box without checking uniqueness.
2232
- return false ;
2233
+ auto *opaque =
2234
+ reinterpret_cast <const OpaqueExistentialContainer *>(container);
2235
+ auto *vwt = opaque->Type ->getValueWitnesses ();
2236
+ return vwt->isValueInline ();
2237
+ }
2233
2238
#else
2234
2239
return true ;
2235
2240
#endif
You can’t perform that action at this time.
0 commit comments