Files
swift-mirror/test/embedded/exclusivity.swift
Doug Gregor cc2fc8ae65 [Embedded] Put dynamic exclusivity behind a second experimental feature
We need to stage in the behavior change to enable dynamic exclusivity
checking for Embedded Swift. For now, ignore
`-enforce-exclusivity=checked` in Embedded Swift unless the
experimental feature `EmbeddedDynamicExclusivity` is also enabled.

Addresses rdar://168618037, a regression in Embedded Swift code that
is passing `-enforce-exclusivity=checked` explicitly.
2026-01-22 21:22:19 -08:00

48 lines
1.6 KiB
Swift

// RUN: %target-swift-frontend -emit-ir %s -enforce-exclusivity=checked -enable-experimental-feature Embedded -enable-experimental-feature EmbeddedDynamicExclusivity -parse-as-library | %FileCheck -check-prefix DYNAMIC %s
// RUN: %target-swift-frontend -parse-as-library -emit-ir %s -enforce-exclusivity=unchecked -enable-experimental-feature Embedded | %FileCheck -check-prefix STATIC-ONLY %s
// RUN: %target-swift-frontend -parse-as-library -emit-ir %s -enforce-exclusivity=checked -enable-experimental-feature Embedded | %FileCheck -check-prefix STATIC-ONLY %s
// RUN: %target-swift-frontend -parse-as-library -emit-ir %s -enable-experimental-feature Embedded | %FileCheck -check-prefix STATIC-ONLY %s
// REQUIRES: swift_in_compiler
// REQUIRES: swift_feature_Embedded
// REQUIRES: swift_feature_EmbeddedDynamicExclusivity
func f() -> Bool? { return nil }
public class MyClass {
var handler: (()->())? = nil
func foo() {
handler?()
}
deinit { print("deinit") }
}
@main
struct Main {
static var o: MyClass? = nil
// CHECK: 4main
static func main() {
// DYNAMIC: call void @swift_beginAccess
// STATIC-ONLY-NOT: @swift_beginAccess
o = MyClass()
o!.handler = { print("no captures") }
o!.foo() // CHECK: no captures
o = nil // CHECK: deinit
var local = 42
o = MyClass()
o!.handler = { print("capture local"); local += 1 }
o!.foo() // CHECK: capture local
print(local == 43 ? "43" : "???") // CHECK: 43
o = nil // CHECK: deinit
let closure = {
guard var b = f() else { print("success"); return }
let c = { b = true }
_ = (b, c)
}
closure() // CHECK: success
}
}