Skip to content

Commit f5ca12d

Browse files
committed
Simplification: check for isolated conformances when simplifying metatype casts
rdar://147417762
1 parent 75a0cc0 commit f5ca12d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyCheckedCast.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ private extension UnconditionalCheckedCastInst {
8181
return
8282
}
8383
let conformance = sourceFormalType.instanceTypeOfMetatype.checkConformance(to: proto)
84-
guard conformance.isValid else {
84+
guard conformance.isValid,
85+
conformance.matchesActorIsolation(in: parentFunction)
86+
else {
8587
return
8688
}
8789

test/SILOptimizer/simplify_unconditional_check_cast.sil

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all %s -simplification -simplify-instruction=unconditional_checked_cast | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -simplification -simplify-instruction=unconditional_checked_cast -enable-experimental-feature IsolatedConformances | %FileCheck %s
2+
3+
// REQUIRES: swift_feature_IsolatedConformances
4+
// REQUIRES: concurrency
25

36
import Swift
47
import Builtin
8+
import _Concurrency
59

610
protocol P {}
711
protocol PC: AnyObject {}
@@ -12,6 +16,8 @@ struct T {}
1216

1317
class C {}
1418

19+
struct X : @MainActor P {}
20+
1521
// CHECK-LABEL: sil [ossa] @test_conforming_struct :
1622
// CHECK: %1 = init_existential_metatype %0, $@thick any P.Type
1723
// CHECK-NEXT: return %1
@@ -52,3 +58,14 @@ bb0(%0 : $@thick S.Type):
5258
%1 = unconditional_checked_cast %0 to Int.Type
5359
return %1
5460
}
61+
62+
// CHECK-LABEL: sil [ossa] @test_isolated_conformance :
63+
// CHECK: %1 = unconditional_checked_cast %0
64+
// CHECK-NEXT: return %1
65+
// CHECK: } // end sil function 'test_isolated_conformance'
66+
sil [ossa] @test_isolated_conformance : $@convention(thin) (@thick X.Type) -> @thick any P.Type {
67+
bb0(%0 : $@thick X.Type):
68+
%1 = unconditional_checked_cast %0 to any P.Type
69+
return %1
70+
}
71+

0 commit comments

Comments
 (0)