diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 93fcf15b3327b..46b92335f7f46 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -8647,11 +8647,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)) diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index e03c2ebb52de0..d0cef2d54be9e 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -230,17 +230,6 @@ class AttributeChecker : public AttributeVisitor { attr, decl, P); return; } - - if (auto *attrType = dyn_cast(repr)) { - if (attrType->has(TypeAttrKind::Isolated)) { - diagnoseAndRemoveAttr( - attr, - diag:: - execution_behavior_incompatible_dynamically_isolated_parameter, - attr, decl, P); - return; - } - } } } diff --git a/test/SILGen/execution_attr.swift b/test/SILGen/execution_attr.swift index 1d4de2b753585..63dc3f0aac675 100644 --- a/test/SILGen/execution_attr.swift +++ b/test/SILGen/execution_attr.swift @@ -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 @@ -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) -> (), @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, #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, @guaranteed @isolated(any) @noescape @callee_guaranteed () -> ()) -> () { +// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Optional, [[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() +} diff --git a/test/attr/execution_behavior_attrs.swift b/test/attr/execution_behavior_attrs.swift index c763e84ca0463..ee5ba48c3d908 100644 --- a/test/attr/execution_behavior_attrs.swift +++ b/test/attr/execution_behavior_attrs.swift @@ -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 {} } @@ -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)'}} +}