Skip to content

[AST] @preconcurrency conformance applies to implied conformances a… #74315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/swift/AST/ProtocolConformance.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,12 @@ class NormalProtocolConformance : public RootProtocolConformance,
assert(sourceKind != ConformanceEntryKind::PreMacroExpansion &&
"cannot create conformance pre-macro-expansion");
Bits.NormalProtocolConformance.SourceKind = unsigned(sourceKind);
ImplyingConformance = implyingConformance;
if (auto implying = implyingConformance) {
ImplyingConformance = implying;
PreconcurrencyLoc = implying->getPreconcurrencyLoc();
Bits.NormalProtocolConformance.IsPreconcurrency =
implying->isPreconcurrency();
}
}

/// Determine whether this conformance is lazily loaded.
Expand Down
16 changes: 16 additions & 0 deletions test/Concurrency/preconcurrency_conformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,19 @@ do {
func test() {}
}
}

// https://github.com/apple/swift/issues/74294
protocol Parent {
func a()
}

protocol Child: Parent {
func b()
}

do {
actor Test: @preconcurrency Child {
func a() {} // Ok
func b() {} // Ok
}
}
47 changes: 47 additions & 0 deletions test/Interpreter/preconcurrency_conformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
// 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
// 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

// RUN: %target-build-swift -Xfrontend -enable-upcoming-feature -Xfrontend DynamicActorIsolation -I %t -L %t -l Types %t/src/Crash5.swift -o %t/crash5.out
// RUN: %target-codesign %t/crash5.out
// 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
// 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

// RUN: %target-build-swift -Xfrontend -enable-upcoming-feature -Xfrontend DynamicActorIsolation -I %t -L %t -l Types %t/src/Crash6.swift -o %t/crash6.out
// RUN: %target-codesign %t/crash6.out
// 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
// 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

// REQUIRES: asserts
// REQUIRES: concurrency
// REQUIRES: concurrency_runtime
Expand All @@ -51,6 +61,10 @@ public protocol P {
func test() -> Int
}

public protocol Q : P {
func childTest()
}

//--- Types.swift
import Interface

Expand Down Expand Up @@ -87,6 +101,21 @@ extension ActorTest : @preconcurrency P {
public func test() -> Int { x }
}

@MainActor
public struct TestWithParent : @preconcurrency Q {
public var prop: [String] = []

public init() {}

public func test() -> Int { 42 }
public func childTest() {}
}

public func runChildTest<T: Q>(_ type: T.Type) async {
let v = type.init()
return v.childTest()
}

//--- Crash1.swift
import Types
print(await runTest(Test.self))
Expand Down Expand Up @@ -122,3 +151,21 @@ print("OK")

// SWIFT6_CHECK: Incorrect actor executor assumption
// SWIFT6_CHECK-NOT: OK

//--- Crash5.swift
import Types
print(await runTest(TestWithParent.self))
print("OK")
// LEGACY_CHECK: data race detected: @MainActor function at Types/Types.swift:40 was not called on the main thread

// Crash without good message, since via 'dispatch_assert_queue'
// SWIFT6_CHECK-NOT: OK

//--- Crash6.swift
import Types
print(await runChildTest(TestWithParent.self))
print("OK")
// LEGACY_CHECK: data race detected: @MainActor function at Types/Types.swift:40 was not called on the main thread

// Crash without good message, since via 'dispatch_assert_queue'
// SWIFT6_CHECK-NOT: OK
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
// 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
// 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

// RUN: %target-build-swift -I %t -L %t -l Types %t/src/Test5.swift -o %t/test5.out
// RUN: %target-codesign %t/test5.out
// RUN: env SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test5.out 2>&1 | %FileCheck %t/src/Test5.swift
// 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
// 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

// RUN: %target-build-swift -I %t -L %t -l Types %t/src/Test6.swift -o %t/test6.out
// RUN: %target-codesign %t/test6.out
// RUN: env SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=2 %target-run %t/test6.out 2>&1 | %FileCheck %t/src/Test6.swift
// 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
// 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

// REQUIRES: asserts
// REQUIRES: concurrency
// REQUIRES: concurrency_runtime
Expand All @@ -56,6 +68,10 @@ public protocol P {
func test() -> Int
}

public protocol Q : P {
func childTest()
}

//--- Types.swift
import Interface

Expand Down Expand Up @@ -92,6 +108,21 @@ extension ActorTest : @preconcurrency P {
public func test() -> Int { x }
}

@MainActor
public struct TestWithParent : @preconcurrency Q {
public var prop: [String] = []

public init() {}

public func test() -> Int { 42 }
public func childTest() {}
}

public func runChildTest<T: Q>(_ type: T.Type) async {
let v = type.init()
return v.childTest()
}

//--- Test1.swift
import Types
print(await runTest(Test.self))
Expand All @@ -111,3 +142,13 @@ print(await runTest(ActorTest.self))
import Types
print(await runAccessors(ActorTest.self))
// CHECK-NOT: Incorrect actor executor assumption

//--- Test5.swift
import Types
print(await runTest(TestWithParent.self))
// CHECK-NOT: Incorrect actor executor assumption

//--- Test6.swift
import Types
print(await runChildTest(TestWithParent.self))
// CHECK-NOT: Incorrect actor executor assumption
59 changes: 59 additions & 0 deletions test/SILGen/preconcurrency_conformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,39 @@ extension MyActor : @preconcurrency Q {
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])

// https://github.com/apple/swift/issues/74294
protocol Parent {
func a()
}

protocol Child : Parent {
func b()
}

@MainActor
struct PreconcurrencyAppliesToParentToo : @preconcurrency Child {
func a() {
}

func b() {
}
}

// protocol witness for Child.b() in conformance PreconcurrencyAppliesToParentToo
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances32PreconcurrencyAppliesToParentTooVAA5ChildA2aDP1byyFTW : $@convention(witness_method: Child) (@in_guaranteed PreconcurrencyAppliesToParentToo) -> ()
// CHECK: [[MAIN_ACTOR:%.*]] = begin_borrow {{.*}} : $MainActor
// CHECK-NEXT: [[EXEC:%.*]] = extract_executor [[MAIN_ACTOR]] : $MainActor
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])


// protocol witness for Parent.a() in conformance PreconcurrencyAppliesToParentToo
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances32PreconcurrencyAppliesToParentTooVAA0F0A2aDP1ayyFTW : $@convention(witness_method: Parent) (@in_guaranteed PreconcurrencyAppliesToParentToo) -> ()
// CHECK: [[MAIN_ACTOR:%.*]] = begin_borrow {{.*}} : $MainActor
// CHECK-NEXT: [[EXEC:%.*]] = extract_executor [[MAIN_ACTOR]] : $MainActor
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])

//--- checks_disabled.swift
protocol P {
associatedtype T
Expand Down Expand Up @@ -439,3 +472,29 @@ extension MyActor : @preconcurrency Q {
// protocol witness for static Q.data.modify in conformance MyActor
// 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>
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF

// https://github.com/apple/swift/issues/74294
protocol Parent {
func a()
}

protocol Child : Parent {
func b()
}

@MainActor
struct PreconcurrencyAppliesToParentToo : @preconcurrency Child {
func a() {
}

func b() {
}
}

// protocol witness for Child.b() in conformance PreconcurrencyAppliesToParentToo
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances32PreconcurrencyAppliesToParentTooVAA5ChildA2aDP1byyFTW : $@convention(witness_method: Child) (@in_guaranteed PreconcurrencyAppliesToParentToo) -> ()
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF

// protocol witness for Parent.a() in conformance PreconcurrencyAppliesToParentToo
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances32PreconcurrencyAppliesToParentTooVAA0F0A2aDP1ayyFTW : $@convention(witness_method: Parent) (@in_guaranteed PreconcurrencyAppliesToParentToo) -> ()
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF