Skip to content

[Concurency] Allow declarations with @isolated(any) parameters be m… #82689

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
Jul 2, 2025
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
5 changes: 0 additions & 5 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -8735,11 +8735,6 @@ ERROR(execution_behavior_incompatible_isolated_parameter,none,
"an isolated parameter: %2",
(DeclAttribute, ValueDecl *, ValueDecl *))

ERROR(execution_behavior_incompatible_dynamically_isolated_parameter,none,
"cannot use %0 on %kind1 because it has "
"a dynamically isolated parameter: %2",
(DeclAttribute, ValueDecl *, ValueDecl *))

ERROR(execution_behavior_attr_incompatible_with_global_isolation,none,
"cannot use %0 because function type is isolated to a global actor %1",
(DeclAttribute, Type))
Expand Down
11 changes: 0 additions & 11 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
attr, decl, P);
return;
}

if (auto *attrType = dyn_cast<AttributedTypeRepr>(repr)) {
if (attrType->has(TypeAttrKind::Isolated)) {
diagnoseAndRemoveAttr(
attr,
diag::
execution_behavior_incompatible_dynamically_isolated_parameter,
attr, decl, P);
return;
}
}
}
}

Expand Down
35 changes: 34 additions & 1 deletion test/SILGen/execution_attr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault

// Validate that both with and without the experimental flag we properly codegen
// execution(caller) and execution(concurrent).
// `@concurrent` and `nonisolated(nonsending)`

// CHECK-LABEL: // executionCaller()
// CHECK-NEXT: // Isolation: caller_isolation_inheriting
Expand Down Expand Up @@ -62,3 +62,36 @@ extension S {
// CHECK: sil hidden [ossa] @$s14execution_attr1SV0A17CallerFieldMethodyyyyYaYCXEF : $@convention(method) (@guaranteed @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> (), @guaranteed S) -> () {
func executionCallerFieldMethod(_ x: nonisolated(nonsending) () async -> ()) {}
}

// CHECK-LABEL: sil hidden [ossa] @$s14execution_attr24testWithDynamicIsolation2fnyyyYAXE_tYaF : $@convention(thin) @async (@guaranteed @isolated(any) @noescape @callee_guaranteed () -> ()) -> () {
// CHECK: bb0([[PARAM_FN:%.*]] : @guaranteed $@isolated(any) @noescape @callee_guaranteed () -> ()):
// CHECK: [[GENERIC_EXEC:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]]
// CHECK-NEXT: [[FN:%.*]] = copy_value [[PARAM_FN]]
// CHECK-NEXT: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK-NEXT: [[FN_ISOLATION:%.*]] = function_extract_isolation [[BORROWED_FN]]
// CHECK-NEXT: hop_to_executor [[FN_ISOLATION]]
// CHECK-NEXT: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK-NEXT: apply [[BORROWED_FN]]()
// CHECK: hop_to_executor [[GENERIC_EXEC]]
// CHECK: } // end sil function '$s14execution_attr24testWithDynamicIsolation2fnyyyYAXE_tYaF'
@concurrent
func testWithDynamicIsolation(fn: @isolated(any) () -> Void) async {
await fn()
}

// CHECK-LABEL: sil hidden [ossa] @$s14execution_attr38testCallerIsolatedWithDynamicIsolation2fnyyyYAXE_tYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @guaranteed @isolated(any) @noescape @callee_guaranteed () -> ()) -> () {
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Optional<any Actor>, [[PARAM_FN:%.*]] : @guaranteed $@isolated(any) @noescape @callee_guaranteed () -> ()):
// CHECK: hop_to_executor [[ISOLATION]]
// CHECK-NEXT: [[FN:%.*]] = copy_value [[PARAM_FN]]
// CHECK-NEXT: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK-NEXT: [[FN_ISOLATION:%.*]] = function_extract_isolation [[BORROWED_FN]]
// CHECK-NEXT: hop_to_executor [[FN_ISOLATION]]
// CHECK-NEXT: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK-NEXT: apply [[BORROWED_FN]]()
// CHECK: hop_to_executor [[ISOLATION]]
// CHECK: } // end sil function '$s14execution_attr38testCallerIsolatedWithDynamicIsolation2fnyyyYAXE_tYaF'
nonisolated(nonsending)
func testCallerIsolatedWithDynamicIsolation(fn: @isolated(any) () -> Void) async {
await fn()
}
12 changes: 10 additions & 2 deletions test/attr/execution_behavior_attrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ struct TestAttributeCollisions {
}

@concurrent func testIsolationAny(arg: @isolated(any) () -> Void) async {}
// expected-error@-1 {{cannot use @concurrent on instance method 'testIsolationAny(arg:)' because it has a dynamically isolated parameter: 'arg'}}
@concurrent subscript(testIsolationAny arg: @isolated(any) () -> Void) -> Int {
// expected-error@-1 {{cannot use @concurrent on subscript 'subscript(testIsolationAny:)' because it has a dynamically isolated parameter: 'arg'}}
get async {}
}

Expand Down Expand Up @@ -158,3 +156,13 @@ do {
})
}
}

do {
nonisolated(nonsending)
func testOnDecl(_: @isolated(any) () -> Void) async {} // Ok

func testOnType1(_: nonisolated(nonsending) @isolated(any) () async -> Void) {}
// expected-error@-1 {{cannot use 'nonisolated(nonsending)' together with '@isolated(any)'}}
func testOnType2(_: @concurrent @isolated(any) () async -> Void) {}
// expected-error@-1 {{cannot use '@concurrent' together with '@isolated(any)'}}
}