Skip to content

Commit a522448

Browse files
committed
[Concurency] Allow declarations with @isolated(any) parameters be marked as @concurrent/nonisolated(nonsending)
It's shouldn't be possible to use these attributes directly on the function type that is `@isolated(any)` as per SE-0461 proposal but it shouldn't preclude declarations that have parameters with `@isolated(any)` from using them. Resolves: rdar://154754939
1 parent 1c75d3b commit a522448

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8735,11 +8735,6 @@ ERROR(execution_behavior_incompatible_isolated_parameter,none,
87358735
"an isolated parameter: %2",
87368736
(DeclAttribute, ValueDecl *, ValueDecl *))
87378737

8738-
ERROR(execution_behavior_incompatible_dynamically_isolated_parameter,none,
8739-
"cannot use %0 on %kind1 because it has "
8740-
"a dynamically isolated parameter: %2",
8741-
(DeclAttribute, ValueDecl *, ValueDecl *))
8742-
87438738
ERROR(execution_behavior_attr_incompatible_with_global_isolation,none,
87448739
"cannot use %0 because function type is isolated to a global actor %1",
87458740
(DeclAttribute, Type))

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
228228
attr, decl, P);
229229
return;
230230
}
231-
232-
if (auto *attrType = dyn_cast<AttributedTypeRepr>(repr)) {
233-
if (attrType->has(TypeAttrKind::Isolated)) {
234-
diagnoseAndRemoveAttr(
235-
attr,
236-
diag::
237-
execution_behavior_incompatible_dynamically_isolated_parameter,
238-
attr, decl, P);
239-
return;
240-
}
241-
}
242231
}
243232
}
244233

test/SILGen/execution_attr.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
66

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

1010
// CHECK-LABEL: // executionCaller()
1111
// CHECK-NEXT: // Isolation: caller_isolation_inheriting
@@ -62,3 +62,36 @@ extension S {
6262
// 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) -> () {
6363
func executionCallerFieldMethod(_ x: nonisolated(nonsending) () async -> ()) {}
6464
}
65+
66+
// CHECK-LABEL: sil hidden [ossa] @$s14execution_attr24testWithDynamicIsolation2fnyyyYAXE_tYaF : $@convention(thin) @async (@guaranteed @isolated(any) @noescape @callee_guaranteed () -> ()) -> () {
67+
// CHECK: bb0([[PARAM_FN:%.*]] : @guaranteed $@isolated(any) @noescape @callee_guaranteed () -> ()):
68+
// CHECK: [[GENERIC_EXEC:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
69+
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]]
70+
// CHECK-NEXT: [[FN:%.*]] = copy_value [[PARAM_FN]]
71+
// CHECK-NEXT: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
72+
// CHECK-NEXT: [[FN_ISOLATION:%.*]] = function_extract_isolation [[BORROWED_FN]]
73+
// CHECK-NEXT: hop_to_executor [[FN_ISOLATION]]
74+
// CHECK-NEXT: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
75+
// CHECK-NEXT: apply [[BORROWED_FN]]()
76+
// CHECK: hop_to_executor [[GENERIC_EXEC]]
77+
// CHECK: } // end sil function '$s14execution_attr24testWithDynamicIsolation2fnyyyYAXE_tYaF'
78+
@concurrent
79+
func testWithDynamicIsolation(fn: @isolated(any) () -> Void) async {
80+
await fn()
81+
}
82+
83+
// 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 () -> ()) -> () {
84+
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Optional<any Actor>, [[PARAM_FN:%.*]] : @guaranteed $@isolated(any) @noescape @callee_guaranteed () -> ()):
85+
// CHECK: hop_to_executor [[ISOLATION]]
86+
// CHECK-NEXT: [[FN:%.*]] = copy_value [[PARAM_FN]]
87+
// CHECK-NEXT: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
88+
// CHECK-NEXT: [[FN_ISOLATION:%.*]] = function_extract_isolation [[BORROWED_FN]]
89+
// CHECK-NEXT: hop_to_executor [[FN_ISOLATION]]
90+
// CHECK-NEXT: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
91+
// CHECK-NEXT: apply [[BORROWED_FN]]()
92+
// CHECK: hop_to_executor [[ISOLATION]]
93+
// CHECK: } // end sil function '$s14execution_attr38testCallerIsolatedWithDynamicIsolation2fnyyyYAXE_tYaF'
94+
nonisolated(nonsending)
95+
func testCallerIsolatedWithDynamicIsolation(fn: @isolated(any) () -> Void) async {
96+
await fn()
97+
}

test/attr/execution_behavior_attrs.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ struct TestAttributeCollisions {
9494
}
9595

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

@@ -158,3 +156,13 @@ do {
158156
})
159157
}
160158
}
159+
160+
do {
161+
nonisolated(nonsending)
162+
func testOnDecl(_: @isolated(any) () -> Void) async {} // Ok
163+
164+
func testOnType1(_: nonisolated(nonsending) @isolated(any) () async -> Void) {}
165+
// expected-error@-1 {{cannot use 'nonisolated(nonsending)' together with '@isolated(any)'}}
166+
func testOnType2(_: @concurrent @isolated(any) () async -> Void) {}
167+
// expected-error@-1 {{cannot use '@concurrent' together with '@isolated(any)'}}
168+
}

0 commit comments

Comments
 (0)