Skip to content

Commit a32470f

Browse files
committed
Correct the region isolation rule for metatype extraction instructions
Now that metatypes might not be Sendable, we need the Assign rule for operations that produce the metatype of a value or existential.
1 parent e24598b commit a32470f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,8 @@ CONSTANT_TRANSLATION(IndexRawPointerInst, Assign)
30023002
CONSTANT_TRANSLATION(InitExistentialMetatypeInst, Assign)
30033003
CONSTANT_TRANSLATION(OpenExistentialMetatypeInst, Assign)
30043004
CONSTANT_TRANSLATION(ObjCToThickMetatypeInst, Assign)
3005+
CONSTANT_TRANSLATION(ValueMetatypeInst, Assign)
3006+
CONSTANT_TRANSLATION(ExistentialMetatypeInst, Assign)
30053007

30063008
// These are used by SIL to aggregate values together in a gep like way. We
30073009
// want to look at uses of structs, not the struct uses itself. So just
@@ -3124,10 +3126,6 @@ CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Require)
31243126
CONSTANT_TRANSLATION(RebindMemoryInst, Require)
31253127
CONSTANT_TRANSLATION(BindMemoryInst, Require)
31263128
CONSTANT_TRANSLATION(BeginUnpairedAccessInst, Require)
3127-
// Require of the value we extract the metatype from.
3128-
CONSTANT_TRANSLATION(ValueMetatypeInst, Require)
3129-
// Require of the value we extract the metatype from.
3130-
CONSTANT_TRANSLATION(ExistentialMetatypeInst, Require)
31313129
// These can take a parameter. If it is non-Sendable, use a require.
31323130
CONSTANT_TRANSLATION(GetAsyncContinuationAddrInst, Require)
31333131

test/Concurrency/sendable_metatype.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@ nonisolated func passSendableToMainActorSmuggledAny<T: Sendable>(_: T.Type) asyn
6666
let x: Sendable.Type = T.self
6767
await acceptMetaOnMainActor(x)
6868
}
69+
70+
// -------------------------------------------------------------------------
71+
// Existential opening
72+
// -------------------------------------------------------------------------
73+
nonisolated func passMetaSmuggledAnyFromExistential(_ qT: Q.Type) {
74+
let x: Any.Type = qT
75+
Task.detached { // expected-error{{risks causing data races}}
76+
acceptMeta(x) // expected-note{{closure captures 'x' which is accessible to code in the current task}}
77+
}
78+
}

0 commit comments

Comments
 (0)