|
| 1 | +// RUN: %empty-directory(%t/src) |
| 2 | +// RUN: split-file %s %t/src |
| 3 | + |
| 4 | +// RUN: %target-build-swift %t/src/Interface.swift -swift-version 5 -emit-module -emit-library \ |
| 5 | +// RUN: -enable-library-evolution \ |
| 6 | +// RUN: -module-name Interface \ |
| 7 | +// RUN: -o %t/%target-library-name(Interface) \ |
| 8 | +// RUN: -emit-module-interface-path %t/Interface.swiftinterface |
| 9 | + |
| 10 | +// RUN: %target-build-swift %t/src/Types.swift -swift-version 5 -emit-module -emit-library -enable-library-evolution -module-name Types -o %t/%target-library-name(Types) \ |
| 11 | +// RUN: -I %t -L %t -l Interface \ |
| 12 | +// RUN: -emit-module-interface-path %t/Types.swiftinterface \ |
| 13 | +// RUN: -Xfrontend -enable-experimental-feature -Xfrontend PreconcurrencyConformances |
| 14 | + |
| 15 | +// RUN: %target-build-swift -Xfrontend -enable-experimental-feature -Xfrontend PreconcurrencyConformances -I %t -L %t -l Types %t/src/Crash1.swift -o %t/crash1.out |
| 16 | +// RUN: %target-codesign %t/crash1.out |
| 17 | +// RUN: not --crash env SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash1.out 2>&1 | %FileCheck %t/src/Crash1.swift |
| 18 | + |
| 19 | +// RUN: %target-build-swift -Xfrontend -enable-experimental-feature -Xfrontend PreconcurrencyConformances -I %t -L %t -l Types %t/src/Crash2.swift -o %t/crash2.out |
| 20 | +// RUN: %target-codesign %t/crash2.out |
| 21 | +// RUN: not --crash env SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash2.out 2>&1 | %FileCheck %t/src/Crash2.swift |
| 22 | + |
| 23 | +// RUN: %target-build-swift -Xfrontend -enable-experimental-feature -Xfrontend PreconcurrencyConformances -I %t -L %t -l Types %t/src/Crash3.swift -o %t/crash3.out |
| 24 | +// RUN: %target-codesign %t/crash3.out |
| 25 | +// RUN: not --crash env SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash3.out 2>&1 | %FileCheck %t/src/Crash3.swift |
| 26 | + |
| 27 | +// RUN: %target-build-swift -Xfrontend -enable-experimental-feature -Xfrontend PreconcurrencyConformances -I %t -L %t -l Types %t/src/Crash4.swift -o %t/crash4.out |
| 28 | +// RUN: %target-codesign %t/crash4.out |
| 29 | +// RUN: not --crash env SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash4.out 2>&1 | %FileCheck %t/src/Crash4.swift |
| 30 | + |
| 31 | +// REQUIRES: asserts |
| 32 | +// REQUIRES: concurrency |
| 33 | +// REQUIRES: executable_test |
| 34 | + |
| 35 | +//--- Interface.swift |
| 36 | +public protocol P { |
| 37 | + init() |
| 38 | + |
| 39 | + var prop: [String] { get set } |
| 40 | + func test() -> Int |
| 41 | +} |
| 42 | + |
| 43 | +//--- Types.swift |
| 44 | +import Interface |
| 45 | + |
| 46 | +public func runTest<T: P>(_ type: T.Type) async -> Int { |
| 47 | + let v = type.init() |
| 48 | + return v.test() |
| 49 | +} |
| 50 | + |
| 51 | +public func runAccessors<T: P>(_ type: T.Type) async -> [String] { |
| 52 | + var v = type.init() |
| 53 | + v.prop = ["a", "b", "c"] |
| 54 | + return v.prop |
| 55 | +} |
| 56 | + |
| 57 | +public final class Test : @preconcurrency P { |
| 58 | + @MainActor public var prop: [String] = [] |
| 59 | + @MainActor public func test() -> Int { 42 } |
| 60 | + |
| 61 | + public init() {} |
| 62 | +} |
| 63 | + |
| 64 | +public actor ActorTest { |
| 65 | + var x: Int = 0 |
| 66 | + |
| 67 | + public init() {} |
| 68 | +} |
| 69 | + |
| 70 | +extension ActorTest : @preconcurrency P { |
| 71 | + public var prop: [String] { |
| 72 | + get { [] } |
| 73 | + set { } |
| 74 | + } |
| 75 | + |
| 76 | + public func test() -> Int { x } |
| 77 | +} |
| 78 | + |
| 79 | +//--- Crash1.swift |
| 80 | +import Types |
| 81 | +print(await runTest(Test.self)) |
| 82 | +// CHECK: error: data race detected: @MainActor function at Types/Types.swift:16 was not called on the main thread |
| 83 | + |
| 84 | +//--- Crash2.swift |
| 85 | +import Types |
| 86 | +print(await runAccessors(Test.self)) |
| 87 | +// CHECK: error: data race detected: @MainActor function at Types/Types.swift:15 was not called on the main thread |
| 88 | + |
| 89 | +//--- Crash3.swift |
| 90 | +import Types |
| 91 | +print(await runTest(ActorTest.self)) |
| 92 | +// CHECK: error: data race detected: actor-isolated function at Types/Types.swift:33 was not called on the same actor |
| 93 | + |
| 94 | +//--- Crash4.swift |
| 95 | +import Types |
| 96 | +print(await runAccessors(ActorTest.self)) |
| 97 | +// CHECK: error: data race detected: actor-isolated function at Types/Types.swift:30 was not called on the same actor |
0 commit comments