Skip to content

Commit 04fd5a2

Browse files
committed
[Sema] Emit dynamic actor isolation checks for derived Equatable/Hashable protocol witnesses
1 parent f10a481 commit 04fd5a2

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ deriveEquatable_eq(
428428
return nullptr;
429429
}
430430

431-
addNonIsolatedToSynthesized(derived.Nominal, eqDecl);
431+
addNonIsolatedToSynthesized(derived, eqDecl);
432432

433433
eqDecl->setBodySynthesizer(bodySynthesizer);
434434

@@ -553,7 +553,7 @@ deriveHashable_hashInto(
553553
/*sourceIsParentContext=*/true);
554554

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

915915
// The derived hashValue of an actor must be nonisolated.
916-
if (!addNonIsolatedToSynthesized(derived.Nominal, hashValueDecl) &&
916+
if (!addNonIsolatedToSynthesized(derived, hashValueDecl) &&
917917
derived.Nominal->isActor())
918918
hashValueDecl->getAttrs().add(
919919
new (C) NonisolatedAttr(/*unsafe*/ false, /*implicit*/ true));

test/SILGen/preconcurrency_conformances.swift

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,51 @@ struct PreconcurrencyAppliesToParentToo : @preconcurrency Child {
309309
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
310310
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])
311311

312+
@available(*, unavailable)
313+
extension NotSendable: Sendable {}
314+
315+
struct NotSendable: Equatable, Hashable {
316+
}
317+
318+
@MainActor
319+
struct TestDerivedEquatable : @preconcurrency Equatable {
320+
var x: NotSendable
321+
}
322+
323+
// protocol witness for static Equatable.== infix(_:_:) in conformance TestDerivedEquatable
324+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances20TestDerivedEquatableVSQAASQ2eeoiySbx_xtFZTW
325+
// CHECK: [[MAIN_ACTOR:%.*]] = begin_borrow {{.*}} : $MainActor
326+
// CHECK-NEXT: [[EXEC:%.*]] = extract_executor [[MAIN_ACTOR]] : $MainActor
327+
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
328+
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])
329+
330+
@MainActor
331+
struct TestDerivedHashable : @preconcurrency Hashable {
332+
var x: NotSendable
333+
}
334+
335+
// protocol witness for Hashable.hashValue.getter in conformance TestDerivedHashable
336+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSHAASH9hashValueSivgTW
337+
// CHECK: [[MAIN_ACTOR:%.*]] = begin_borrow {{.*}} : $MainActor
338+
// CHECK-NEXT: [[EXEC:%.*]] = extract_executor [[MAIN_ACTOR]] : $MainActor
339+
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
340+
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])
341+
342+
// protocol witness for Hashable.hash(into:) in conformance TestDerivedHashable
343+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSHAASH4hash4intoys6HasherVz_tFTW
344+
// CHECK: [[MAIN_ACTOR:%.*]] = begin_borrow {{.*}} : $MainActor
345+
// CHECK-NEXT: [[EXEC:%.*]] = extract_executor [[MAIN_ACTOR]] : $MainActor
346+
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
347+
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])
348+
349+
// protocol witness for static Equatable.== infix(_:_:) in conformance TestDerivedHashable
350+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSQAASQ2eeoiySbx_xtFZTW
351+
// CHECK: [[MAIN_ACTOR:%.*]] = begin_borrow {{.*}} : $MainActor
352+
// CHECK-NEXT: [[EXEC:%.*]] = extract_executor [[MAIN_ACTOR]] : $MainActor
353+
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
354+
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])
355+
356+
312357
//--- checks_disabled.swift
313358
protocol P {
314359
associatedtype T
@@ -498,3 +543,35 @@ struct PreconcurrencyAppliesToParentToo : @preconcurrency Child {
498543
// protocol witness for Parent.a() in conformance PreconcurrencyAppliesToParentToo
499544
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances32PreconcurrencyAppliesToParentTooVAA0F0A2aDP1ayyFTW : $@convention(witness_method: Parent) (@in_guaranteed PreconcurrencyAppliesToParentToo) -> ()
500545
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
546+
547+
@available(*, unavailable)
548+
extension NotSendable: Sendable {}
549+
550+
struct NotSendable: Equatable, Hashable {
551+
}
552+
553+
@MainActor
554+
struct TestDerivedEquatable : @preconcurrency Equatable {
555+
var x: NotSendable
556+
}
557+
558+
// protocol witness for static Equatable.== infix(_:_:) in conformance TestDerivedEquatable
559+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances20TestDerivedEquatableVSQAASQ2eeoiySbx_xtFZTW
560+
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
561+
562+
@MainActor
563+
struct TestDerivedHashable : @preconcurrency Hashable {
564+
var x: NotSendable
565+
}
566+
567+
// protocol witness for Hashable.hashValue.getter in conformance TestDerivedHashable
568+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSHAASH9hashValueSivgTW
569+
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
570+
571+
// protocol witness for Hashable.hash(into:) in conformance TestDerivedHashable
572+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSHAASH4hash4intoys6HasherVz_tFTW
573+
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
574+
575+
// protocol witness for static Equatable.== infix(_:_:) in conformance TestDerivedHashable
576+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s27preconcurrency_conformances19TestDerivedHashableVSQAASQ2eeoiySbx_xtFZTW
577+
// CHECK-NOT: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF

0 commit comments

Comments
 (0)