Skip to content

Commit b593062

Browse files
authored
Merge pull request swiftlang#74315 from xedin/rdar-129599097
[AST] `@preconcurrency` conformance applies to implied conformances a…
2 parents 8be6286 + 414295d commit b593062

5 files changed

+169
-1
lines changed

include/swift/AST/ProtocolConformance.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,12 @@ class NormalProtocolConformance : public RootProtocolConformance,
681681
assert(sourceKind != ConformanceEntryKind::PreMacroExpansion &&
682682
"cannot create conformance pre-macro-expansion");
683683
Bits.NormalProtocolConformance.SourceKind = unsigned(sourceKind);
684-
ImplyingConformance = implyingConformance;
684+
if (auto implying = implyingConformance) {
685+
ImplyingConformance = implying;
686+
PreconcurrencyLoc = implying->getPreconcurrencyLoc();
687+
Bits.NormalProtocolConformance.IsPreconcurrency =
688+
implying->isPreconcurrency();
689+
}
685690
}
686691

687692
/// Determine whether this conformance is lazily loaded.

test/Concurrency/preconcurrency_conformances.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,19 @@ do {
182182
func test() {}
183183
}
184184
}
185+
186+
// https://github.com/apple/swift/issues/74294
187+
protocol Parent {
188+
func a()
189+
}
190+
191+
protocol Child: Parent {
192+
func b()
193+
}
194+
195+
do {
196+
actor Test: @preconcurrency Child {
197+
func a() {} // Ok
198+
func b() {} // Ok
199+
}
200+
}

test/Interpreter/preconcurrency_conformances.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
// RUN: not --crash env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=legacy SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash4.out 2>&1 | %FileCheck %t/src/Crash4.swift --check-prefix=LEGACY_CHECK
3535
// RUN: not --crash env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=swift6 SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash4.out 2>&1 | %FileCheck %t/src/Crash4.swift --check-prefix=SWIFT6_CHECK --dump-input=always
3636

37+
// RUN: %target-build-swift -Xfrontend -enable-upcoming-feature -Xfrontend DynamicActorIsolation -I %t -L %t -l Types %t/src/Crash5.swift -o %t/crash5.out
38+
// RUN: %target-codesign %t/crash5.out
39+
// RUN: not --crash env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=legacy SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash5.out 2>&1 | %FileCheck %t/src/Crash5.swift --check-prefix=LEGACY_CHECK
40+
// RUN: not --crash env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=swift6 SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash5.out 2>&1 | %FileCheck %t/src/Crash5.swift --check-prefix=SWIFT6_CHECK --dump-input=always
41+
42+
// RUN: %target-build-swift -Xfrontend -enable-upcoming-feature -Xfrontend DynamicActorIsolation -I %t -L %t -l Types %t/src/Crash6.swift -o %t/crash6.out
43+
// RUN: %target-codesign %t/crash6.out
44+
// RUN: not --crash env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=legacy SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash6.out 2>&1 | %FileCheck %t/src/Crash6.swift --check-prefix=LEGACY_CHECK
45+
// RUN: not --crash env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=swift6 SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/crash6.out 2>&1 | %FileCheck %t/src/Crash6.swift --check-prefix=SWIFT6_CHECK --dump-input=always
46+
3747
// REQUIRES: asserts
3848
// REQUIRES: concurrency
3949
// REQUIRES: concurrency_runtime
@@ -51,6 +61,10 @@ public protocol P {
5161
func test() -> Int
5262
}
5363

64+
public protocol Q : P {
65+
func childTest()
66+
}
67+
5468
//--- Types.swift
5569
import Interface
5670

@@ -87,6 +101,21 @@ extension ActorTest : @preconcurrency P {
87101
public func test() -> Int { x }
88102
}
89103

104+
@MainActor
105+
public struct TestWithParent : @preconcurrency Q {
106+
public var prop: [String] = []
107+
108+
public init() {}
109+
110+
public func test() -> Int { 42 }
111+
public func childTest() {}
112+
}
113+
114+
public func runChildTest<T: Q>(_ type: T.Type) async {
115+
let v = type.init()
116+
return v.childTest()
117+
}
118+
90119
//--- Crash1.swift
91120
import Types
92121
print(await runTest(Test.self))
@@ -122,3 +151,21 @@ print("OK")
122151

123152
// SWIFT6_CHECK: Incorrect actor executor assumption
124153
// SWIFT6_CHECK-NOT: OK
154+
155+
//--- Crash5.swift
156+
import Types
157+
print(await runTest(TestWithParent.self))
158+
print("OK")
159+
// LEGACY_CHECK: data race detected: @MainActor function at Types/Types.swift:40 was not called on the main thread
160+
161+
// Crash without good message, since via 'dispatch_assert_queue'
162+
// SWIFT6_CHECK-NOT: OK
163+
164+
//--- Crash6.swift
165+
import Types
166+
print(await runChildTest(TestWithParent.self))
167+
print("OK")
168+
// LEGACY_CHECK: data race detected: @MainActor function at Types/Types.swift:40 was not called on the main thread
169+
170+
// Crash without good message, since via 'dispatch_assert_queue'
171+
// SWIFT6_CHECK-NOT: OK

test/Interpreter/preconcurrency_conformances_with_disabled_checks.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
// RUN: env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=legacy SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test4.out 2>&1 | %FileCheck %t/src/Test4.swift
4040
// RUN: env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=swift6 SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test4.out 2>&1 | %FileCheck %t/src/Test4.swift
4141

42+
// RUN: %target-build-swift -I %t -L %t -l Types %t/src/Test5.swift -o %t/test5.out
43+
// RUN: %target-codesign %t/test5.out
44+
// RUN: env SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test5.out 2>&1 | %FileCheck %t/src/Test5.swift
45+
// RUN: env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=legacy SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test5.out 2>&1 | %FileCheck %t/src/Test5.swift
46+
// RUN: env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=swift6 SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test5.out 2>&1 | %FileCheck %t/src/Test5.swift
47+
48+
// RUN: %target-build-swift -I %t -L %t -l Types %t/src/Test6.swift -o %t/test6.out
49+
// RUN: %target-codesign %t/test6.out
50+
// RUN: env SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test6.out 2>&1 | %FileCheck %t/src/Test6.swift
51+
// RUN: env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=legacy SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test6.out 2>&1 | %FileCheck %t/src/Test6.swift
52+
// RUN: env SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=swift6 SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test6.out 2>&1 | %FileCheck %t/src/Test6.swift
53+
4254
// REQUIRES: asserts
4355
// REQUIRES: concurrency
4456
// REQUIRES: concurrency_runtime
@@ -56,6 +68,10 @@ public protocol P {
5668
func test() -> Int
5769
}
5870

71+
public protocol Q : P {
72+
func childTest()
73+
}
74+
5975
//--- Types.swift
6076
import Interface
6177

@@ -92,6 +108,21 @@ extension ActorTest : @preconcurrency P {
92108
public func test() -> Int { x }
93109
}
94110

111+
@MainActor
112+
public struct TestWithParent : @preconcurrency Q {
113+
public var prop: [String] = []
114+
115+
public init() {}
116+
117+
public func test() -> Int { 42 }
118+
public func childTest() {}
119+
}
120+
121+
public func runChildTest<T: Q>(_ type: T.Type) async {
122+
let v = type.init()
123+
return v.childTest()
124+
}
125+
95126
//--- Test1.swift
96127
import Types
97128
print(await runTest(Test.self))
@@ -111,3 +142,13 @@ print(await runTest(ActorTest.self))
111142
import Types
112143
print(await runAccessors(ActorTest.self))
113144
// CHECK-NOT: Incorrect actor executor assumption
145+
146+
//--- Test5.swift
147+
import Types
148+
print(await runTest(TestWithParent.self))
149+
// CHECK-NOT: Incorrect actor executor assumption
150+
151+
//--- Test6.swift
152+
import Types
153+
print(await runChildTest(TestWithParent.self))
154+
// CHECK-NOT: Incorrect actor executor assumption

test/SILGen/preconcurrency_conformances.swift

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,39 @@ extension MyActor : @preconcurrency Q {
276276
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
277277
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])
278278

279+
// https://github.com/apple/swift/issues/74294
280+
protocol Parent {
281+
func a()
282+
}
283+
284+
protocol Child : Parent {
285+
func b()
286+
}
287+
288+
@MainActor
289+
struct PreconcurrencyAppliesToParentToo : @preconcurrency Child {
290+
func a() {
291+
}
292+
293+
func b() {
294+
}
295+
}
296+
297+
// protocol witness for Child.b() in conformance PreconcurrencyAppliesToParentToo
298+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances32PreconcurrencyAppliesToParentTooVAA5ChildA2aDP1byyFTW : $@convention(witness_method: Child) (@in_guaranteed PreconcurrencyAppliesToParentToo) -> ()
299+
// CHECK: [[MAIN_ACTOR:%.*]] = begin_borrow {{.*}} : $MainActor
300+
// CHECK-NEXT: [[EXEC:%.*]] = extract_executor [[MAIN_ACTOR]] : $MainActor
301+
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
302+
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])
303+
304+
305+
// protocol witness for Parent.a() in conformance PreconcurrencyAppliesToParentToo
306+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances32PreconcurrencyAppliesToParentTooVAA0F0A2aDP1ayyFTW : $@convention(witness_method: Parent) (@in_guaranteed PreconcurrencyAppliesToParentToo) -> ()
307+
// CHECK: [[MAIN_ACTOR:%.*]] = begin_borrow {{.*}} : $MainActor
308+
// CHECK-NEXT: [[EXEC:%.*]] = extract_executor [[MAIN_ACTOR]] : $MainActor
309+
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
310+
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])
311+
279312
//--- checks_disabled.swift
280313
protocol P {
281314
associatedtype T
@@ -439,3 +472,29 @@ extension MyActor : @preconcurrency Q {
439472
// protocol witness for static Q.data.modify in conformance MyActor
440473
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances7MyActorCAA1QA2aDP4dataSaySiGSgvMZTW : $@yield_once @convention(witness_method: Q) @substituted <τ_0_0> (@thick τ_0_0.Type) -> @yields @inout Optional<Array<Int>> for <MyActor>
441474
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
475+
476+
// https://github.com/apple/swift/issues/74294
477+
protocol Parent {
478+
func a()
479+
}
480+
481+
protocol Child : Parent {
482+
func b()
483+
}
484+
485+
@MainActor
486+
struct PreconcurrencyAppliesToParentToo : @preconcurrency Child {
487+
func a() {
488+
}
489+
490+
func b() {
491+
}
492+
}
493+
494+
// protocol witness for Child.b() in conformance PreconcurrencyAppliesToParentToo
495+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances32PreconcurrencyAppliesToParentTooVAA5ChildA2aDP1byyFTW : $@convention(witness_method: Child) (@in_guaranteed PreconcurrencyAppliesToParentToo) -> ()
496+
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
497+
498+
// protocol witness for Parent.a() in conformance PreconcurrencyAppliesToParentToo
499+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances32PreconcurrencyAppliesToParentTooVAA0F0A2aDP1ayyFTW : $@convention(witness_method: Parent) (@in_guaranteed PreconcurrencyAppliesToParentToo) -> ()
500+
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF

0 commit comments

Comments
 (0)