@@ -614,12 +614,19 @@ bool swift::_conformsToProtocolInContext(
614
614
const OpaqueValue *value,
615
615
const Metadata *type,
616
616
ProtocolDescriptorRef protocol,
617
- const WitnessTable **conformance) {
617
+ const WitnessTable **conformance,
618
+ bool prohibitIsolatedConformances) {
618
619
619
620
ConformanceExecutionContext context;
620
621
if (!_conformsToProtocol (value, type, protocol, conformance, &context))
621
622
return false ;
622
623
624
+ // If we aren't allowed to use isolated conformances and we ended up with
625
+ // one, fail.
626
+ if (prohibitIsolatedConformances &&
627
+ context.globalActorIsolationType )
628
+ return false ;
629
+
623
630
if (!swift_isInConformanceExecutionContext (type, &context))
624
631
return false ;
625
632
@@ -631,7 +638,8 @@ bool swift::_conformsToProtocolInContext(
631
638
static bool _conformsToProtocols (const OpaqueValue *value,
632
639
const Metadata *type,
633
640
const ExistentialTypeMetadata *existentialType,
634
- const WitnessTable **conformances) {
641
+ const WitnessTable **conformances,
642
+ bool prohibitIsolatedConformances) {
635
643
if (auto *superclass = existentialType->getSuperclassConstraint ()) {
636
644
if (!swift_dynamicCastMetatype (type, superclass))
637
645
return false ;
@@ -644,7 +652,7 @@ static bool _conformsToProtocols(const OpaqueValue *value,
644
652
645
653
for (auto protocol : existentialType->getProtocols ()) {
646
654
if (!_conformsToProtocolInContext (
647
- value, type, protocol, conformances))
655
+ value, type, protocol, conformances, prohibitIsolatedConformances ))
648
656
return false ;
649
657
if (conformances != nullptr && protocol.needsWitnessTable ()) {
650
658
assert (*conformances != nullptr );
@@ -1050,9 +1058,10 @@ swift_dynamicCastMetatypeImpl(const Metadata *sourceType,
1050
1058
}
1051
1059
1052
1060
static const Metadata *
1053
- swift_dynamicCastMetatypeUnconditionalImpl (const Metadata *sourceType,
1054
- const Metadata *targetType,
1055
- const char *file, unsigned line, unsigned column) {
1061
+ swift_dynamicCastMetatypeUnconditionalImpl (
1062
+ const Metadata *sourceType,
1063
+ const Metadata *targetType,
1064
+ const char *file, unsigned line, unsigned column) {
1056
1065
auto origSourceType = sourceType;
1057
1066
1058
1067
// Identical types always succeed
@@ -1138,7 +1147,8 @@ swift_dynamicCastMetatypeUnconditionalImpl(const Metadata *sourceType,
1138
1147
1139
1148
case MetadataKind::Existential: {
1140
1149
auto targetTypeAsExistential = static_cast <const ExistentialTypeMetadata *>(targetType);
1141
- if (_conformsToProtocols (nullptr , sourceType, targetTypeAsExistential, nullptr ))
1150
+ if (_conformsToProtocols (nullptr , sourceType, targetTypeAsExistential,
1151
+ nullptr , /* prohibitIsolatedConformances=*/ false ))
1142
1152
return origSourceType;
1143
1153
swift_dynamicCastFailure (sourceType, targetType);
1144
1154
}
0 commit comments