Skip to content

Commit 7e66535

Browse files
committed
Correct the assertion that this memo is only ever used for a single type
1 parent f312f6d commit 7e66535

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

stdlib/public/runtime/DynamicCast.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,15 @@ bool _swift_dictionaryDownCastConditionalIndirect(OpaqueValue *destination,
619619
// Swift struct type. This is used to speed up the most common
620620
// ObjC->Swift bridging conversions by eliminating repeeated
621621
// protocol conformance lookups.
622+
623+
// Currently used only for String, which may be the only
624+
// type used often enough to justify the extra static memory.
622625
struct ObjCBridgeMemo {
626+
#if !NDEBUG
627+
// Used in assert build to verify that we always get called with
628+
// the same destType
623629
const Metadata *destType;
630+
#endif
624631
const _ObjectiveCBridgeableWitnessTable *destBridgeWitness;
625632
const Metadata *targetBridgedType;
626633
Class targetBridgedObjCClass;
@@ -641,21 +648,25 @@ struct ObjCBridgeMemo {
641648
[](void *data) {
642649
struct SetupData *setupData = (struct SetupData *)data;
643650
struct ObjCBridgeMemo *memo = setupData->memo;
644-
// Check that this always gets called with the same destType.
645-
assert((memo->destType == nullptr) || (memo->destType == setupData->destType));
651+
#if !NDEBUG
646652
memo->destType = setupData->destType;
647-
memo->destBridgeWitness = findBridgeWitness(memo->destType);
653+
#endif
654+
memo->destBridgeWitness = findBridgeWitness(setupData->destType);
648655
if (memo->destBridgeWitness == nullptr) {
649656
memo->targetBridgedType = nullptr;
650657
memo->targetBridgedObjCClass = nullptr;
651658
} else {
652659
memo->targetBridgedType = _getBridgedObjectiveCType(
653-
MetadataState::Complete, memo->destType, memo->destBridgeWitness).Value;
660+
MetadataState::Complete, setupData->destType, memo->destBridgeWitness).Value;
654661
assert(memo->targetBridgedType->getKind() == MetadataKind::ObjCClassWrapper);
655662
memo->targetBridgedObjCClass = memo->targetBridgedType->getObjCClassObject();
656663
assert(memo->targetBridgedObjCClass != nullptr);
657664
}
658665
}, (void *)&setupData);
666+
667+
// Check that this always gets called with the same destType.
668+
assert((destType == this->destType) && "ObjC casting memo used inconsistently");
669+
659670
// !! If bridging is not usable, stop here.
660671
if (targetBridgedObjCClass == nullptr) {
661672
return DynamicCastResult::Failure;

0 commit comments

Comments
 (0)