Skip to content

Commit 4abc3be

Browse files
committed
Revert "[CSGen] Prevent @concurrent on closures from skipping throws inference"
This reverts commit cda9866.
1 parent 893f6aa commit 4abc3be

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,11 @@ FunctionType::ExtInfo ClosureEffectsRequest::evaluate(
14141414
bool async = expr->getAsyncLoc().isValid();
14151415
bool sendable = expr->getAttrs().hasAttribute<SendableAttr>();
14161416

1417+
// `@concurrent` attribute is only valid on asynchronous function types.
1418+
if (expr->getAttrs().hasAttribute<ConcurrentAttr>()) {
1419+
async = true;
1420+
}
1421+
14171422
if (throws || async) {
14181423
return ASTExtInfoBuilder()
14191424
.withThrows(throws, /*FIXME:*/Type())
@@ -1427,17 +1432,11 @@ FunctionType::ExtInfo ClosureEffectsRequest::evaluate(
14271432
if (!body)
14281433
return ASTExtInfoBuilder().withSendable(sendable).build();
14291434

1430-
// `@concurrent` attribute is only valid on asynchronous function types.
1431-
bool asyncFromAttr = false;
1432-
if (expr->getAttrs().hasAttribute<ConcurrentAttr>()) {
1433-
asyncFromAttr = true;
1434-
}
1435-
14361435
auto throwFinder = FindInnerThrows(expr);
14371436
body->walk(throwFinder);
14381437
return ASTExtInfoBuilder()
14391438
.withThrows(throwFinder.foundThrow(), /*FIXME:*/Type())
1440-
.withAsync(asyncFromAttr || bool(findAsyncNode(expr)))
1439+
.withAsync(bool(findAsyncNode(expr)))
14411440
.withSendable(sendable)
14421441
.build();
14431442
}

test/attr/execution_behavior_attrs.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,3 @@ _ = { @MainActor @concurrent in
137137
_ = { @concurrent () -> Int in
138138
// expected-error@-1 {{@concurrent on non-async closure}}
139139
}
140-
141-
// Make sure that explicit use of `@concurrent` doesn't interfere with inference of `throws` from the body.
142-
do {
143-
func acceptsThrowing(_ body: () async throws -> Void) async {
144-
}
145-
146-
struct Invocation {
147-
func throwingFn() async throws {
148-
}
149-
}
150-
151-
func test(invocation: Invocation) async {
152-
await acceptsThrowing({ @concurrent in try await invocation.throwingFn() }) // Ok
153-
await acceptsThrowing({ @concurrent [invocation] in try await invocation.throwingFn() }) // Ok
154-
155-
await acceptsThrowing({ @concurrent in // Ok
156-
_ = 42
157-
try await invocation.throwingFn()
158-
})
159-
}
160-
}

0 commit comments

Comments
 (0)