Skip to content

Commit 1cd181d

Browse files
committed
[Sema] Only @execution(concurrent) cannot be used with other forms of isolation
1 parent cdb5396 commit 1cd181d

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,35 +4203,37 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42034203
diag::attr_execution_type_attr_only_on_async);
42044204
}
42054205

4206-
switch (isolation.getKind()) {
4207-
case FunctionTypeIsolation::Kind::NonIsolated:
4208-
break;
4209-
4210-
case FunctionTypeIsolation::Kind::GlobalActor:
4211-
diagnoseInvalid(
4212-
repr, executionAttr->getAtLoc(),
4213-
diag::
4214-
attr_execution_concurrent_type_attr_incompatible_with_global_isolation,
4215-
isolation.getGlobalActorType());
4216-
break;
4206+
if (executionAttr->getBehavior() == ExecutionKind::Concurrent) {
4207+
switch (isolation.getKind()) {
4208+
case FunctionTypeIsolation::Kind::NonIsolated:
4209+
break;
42174210

4218-
case FunctionTypeIsolation::Kind::Parameter:
4219-
diagnoseInvalid(
4220-
repr, executionAttr->getAtLoc(),
4221-
diag::
4222-
attr_execution_concurrent_type_attr_incompatible_with_isolated_param);
4223-
break;
4211+
case FunctionTypeIsolation::Kind::GlobalActor:
4212+
diagnoseInvalid(
4213+
repr, executionAttr->getAtLoc(),
4214+
diag::
4215+
attr_execution_concurrent_type_attr_incompatible_with_global_isolation,
4216+
isolation.getGlobalActorType());
4217+
break;
42244218

4225-
case FunctionTypeIsolation::Kind::Erased:
4226-
diagnoseInvalid(
4227-
repr, executionAttr->getAtLoc(),
4228-
diag::
4229-
attr_execution_concurrent_type_attr_incompatible_with_isolated_any);
4230-
break;
4219+
case FunctionTypeIsolation::Kind::Parameter:
4220+
diagnoseInvalid(
4221+
repr, executionAttr->getAtLoc(),
4222+
diag::
4223+
attr_execution_concurrent_type_attr_incompatible_with_isolated_param);
4224+
break;
42314225

4232-
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
4233-
llvm_unreachable("cannot happen because multiple @execution attributes "
4234-
"aren't allowed.");
4226+
case FunctionTypeIsolation::Kind::Erased:
4227+
diagnoseInvalid(
4228+
repr, executionAttr->getAtLoc(),
4229+
diag::
4230+
attr_execution_concurrent_type_attr_incompatible_with_isolated_any);
4231+
break;
4232+
4233+
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
4234+
llvm_unreachable("cannot happen because multiple @execution attributes "
4235+
"aren't allowed.");
4236+
}
42354237
}
42364238

42374239
if (!repr->isInvalid()) {

test/attr/attr_execution.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ struct TestAttributeCollisions {
5353
@MainActor @execution(concurrent) func testGlobalActor() async {}
5454
// expected-warning @-1 {{instance method 'testGlobalActor()' has multiple actor-isolation attributes ('MainActor' and 'execution(concurrent)')}}
5555

56+
@execution(caller) nonisolated func testNonIsolatedCaller() async {} // Ok
57+
@MainActor @execution(caller) func testGlobalActorCaller() async {}
58+
// expected-warning@-1 {{instance method 'testGlobalActorCaller()' has multiple actor-isolation attributes ('MainActor' and 'execution(caller)')}}
59+
@execution(caller) func testCaller(arg: isolated MainActor) async {} // Ok
60+
5661
@execution(concurrent) @Sendable func test(_: @Sendable () -> Void, _: sending Int) async {} // Ok
62+
@execution(caller) @Sendable func testWithSendableCaller(_: @Sendable () -> Void, _: sending Int) async {} // Ok
5763
}
5864

5965
@MainActor

0 commit comments

Comments
 (0)