Skip to content

Commit 8651e6a

Browse files
authored
Merge pull request #40090 from DougGregor/ibaction-implies-mainactor
2 parents 546f22a + ffd435d commit 8651e6a

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,6 +3435,15 @@ ActorIsolation ActorIsolationRequest::evaluate(
34353435
}
34363436
}
34373437

3438+
// @IBAction implies @MainActor(unsafe).
3439+
if (value->getAttrs().hasAttribute<IBActionAttr>()) {
3440+
ASTContext &ctx = value->getASTContext();
3441+
if (Type mainActor = ctx.getMainActorType()) {
3442+
return inferredIsolation(
3443+
ActorIsolation::forGlobalActor(mainActor, /*unsafe=*/true));
3444+
}
3445+
}
3446+
34383447
// Default isolation for this member.
34393448
return defaultIsolation;
34403449
}

test/Concurrency/global_actor_inference.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,15 @@ func useUnsafeMainActor() {
517517
}
518518
}
519519

520+
// ----------------------------------------------------------------------
521+
// @IBAction implies @MainActor(unsafe)
522+
// ----------------------------------------------------------------------
523+
class SomeWidgetThing {
524+
@IBAction func onTouch(_ object: AnyObject) {
525+
onlyOnMainActor() // okay
526+
}
527+
}
528+
520529
// ----------------------------------------------------------------------
521530
// @_inheritActorContext
522531
// ----------------------------------------------------------------------

test/IDE/print_ast_tc_decls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class d0170_TestAvailability {
536536
// PASS_COMMON-LABEL: {{^}}@objc class d0180_TestIBAttrs {{{$}}
537537

538538
@IBAction func anAction(_: AnyObject) {}
539-
// PASS_COMMON-NEXT: {{^}} @objc @IBAction func anAction(_: AnyObject){{$}}
539+
// PASS_COMMON-NEXT: {{^}} @objc @IBAction @MainActor func anAction(_: AnyObject){{$}}
540540

541541
@IBSegueAction func aSegueAction(_ coder: AnyObject, sender: AnyObject, identifier: AnyObject?) -> Any? { fatalError() }
542542
// PASS_COMMON-NEXT: {{^}} @objc @IBSegueAction func aSegueAction(_ coder: AnyObject, sender: AnyObject, identifier: AnyObject?) -> Any?{{$}}

test/attr/attr_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ class HasIBOutlet {
18681868
// CHECK-LABEL: {{^}}class HasIBAction {
18691869
class HasIBAction {
18701870
@IBAction func goodAction(_ sender: AnyObject?) { }
1871-
// CHECK: {{^}} @objc @IBAction func goodAction(_ sender: AnyObject?) {
1871+
// CHECK: {{^}} @objc @IBAction @MainActor func goodAction(_ sender: AnyObject?) {
18721872

18731873
@IBAction func badAction(_ sender: PlainStruct?) { }
18741874
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}

0 commit comments

Comments
 (0)