Skip to content
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

[Sema] Emit dynamic actor isolation checks for derived protocol witnesses #78650

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[Sema] Emit dynamic actor isolation checks for derived Equatable/Hash…
…able protocol witnesses
  • Loading branch information
xedin committed Jan 15, 2025
commit 04fd5a2c2aaaf79518d371716b228f21cbaf76fa
6 changes: 3 additions & 3 deletions lib/Sema/DerivedConformanceEquatableHashable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ deriveEquatable_eq(
return nullptr;
}

addNonIsolatedToSynthesized(derived.Nominal, eqDecl);
addNonIsolatedToSynthesized(derived, eqDecl);

eqDecl->setBodySynthesizer(bodySynthesizer);

Expand Down Expand Up @@ -553,7 +553,7 @@ deriveHashable_hashInto(
/*sourceIsParentContext=*/true);

// The derived hash(into:) for an actor must be non-isolated.
if (!addNonIsolatedToSynthesized(derived.Nominal, hashDecl) &&
if (!addNonIsolatedToSynthesized(derived, hashDecl) &&
derived.Nominal->isActor())
hashDecl->getAttrs().add(
new (C) NonisolatedAttr(/*unsafe*/ false, /*implicit*/ true));
Expand Down Expand Up @@ -913,7 +913,7 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
hashValueDecl->setAccessors(SourceLoc(), {getterDecl}, SourceLoc());

// The derived hashValue of an actor must be nonisolated.
if (!addNonIsolatedToSynthesized(derived.Nominal, hashValueDecl) &&
if (!addNonIsolatedToSynthesized(derived, hashValueDecl) &&
derived.Nominal->isActor())
hashValueDecl->getAttrs().add(
new (C) NonisolatedAttr(/*unsafe*/ false, /*implicit*/ true));
Expand Down
77 changes: 77 additions & 0 deletions test/SILGen/preconcurrency_conformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,51 @@ struct PreconcurrencyAppliesToParentToo : @preconcurrency Child {
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])

@available(*, unavailable)
extension NotSendable: Sendable {}

struct NotSendable: Equatable, Hashable {
}

@MainActor
struct TestDerivedEquatable : @preconcurrency Equatable {
var x: NotSendable
}

// protocol witness for static Equatable.== infix(_:_:) in conformance TestDerivedEquatable
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances20TestDerivedEquatableVSQAASQ2eeoiySbx_xtFZTW
// 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]])

@MainActor
struct TestDerivedHashable : @preconcurrency Hashable {
var x: NotSendable
}

// protocol witness for Hashable.hashValue.getter in conformance TestDerivedHashable
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSHAASH9hashValueSivgTW
// 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 Hashable.hash(into:) in conformance TestDerivedHashable
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSHAASH4hash4intoys6HasherVz_tFTW
// 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 static Equatable.== infix(_:_:) in conformance TestDerivedHashable
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSQAASQ2eeoiySbx_xtFZTW
// 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 @@ -498,3 +543,35 @@ struct PreconcurrencyAppliesToParentToo : @preconcurrency Child {
// 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

@available(*, unavailable)
extension NotSendable: Sendable {}

struct NotSendable: Equatable, Hashable {
}

@MainActor
struct TestDerivedEquatable : @preconcurrency Equatable {
var x: NotSendable
}

// protocol witness for static Equatable.== infix(_:_:) in conformance TestDerivedEquatable
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances20TestDerivedEquatableVSQAASQ2eeoiySbx_xtFZTW
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF

@MainActor
struct TestDerivedHashable : @preconcurrency Hashable {
var x: NotSendable
}

// protocol witness for Hashable.hashValue.getter in conformance TestDerivedHashable
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSHAASH9hashValueSivgTW
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF

// protocol witness for Hashable.hash(into:) in conformance TestDerivedHashable
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSHAASH4hash4intoys6HasherVz_tFTW
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF

// protocol witness for static Equatable.== infix(_:_:) in conformance TestDerivedHashable
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSQAASQ2eeoiySbx_xtFZTW
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF