Skip to content

Commit 7c336ea

Browse files
committed
Add support for @Concurrent attribute on closures.
1 parent 8448e61 commit 7c336ea

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2358,17 +2358,19 @@ FunctionType::ExtInfo ConstraintSystem::closureEffects(ClosureExpr *expr) {
23582358
// set of effects.
23592359
bool throws = expr->getThrowsLoc().isValid();
23602360
bool async = expr->getAsyncLoc().isValid();
2361+
bool concurrent = expr->getAttrs().hasAttribute<ConcurrentAttr>();
23612362
if (throws || async) {
23622363
return ASTExtInfoBuilder()
23632364
.withThrows(throws)
23642365
.withAsync(async)
2366+
.withConcurrent(concurrent)
23652367
.build();
23662368
}
23672369

23682370
// Scan the body to determine the effects.
23692371
auto body = expr->getBody();
23702372
if (!body)
2371-
return FunctionType::ExtInfo();
2373+
return ASTExtInfoBuilder().withConcurrent(concurrent).build();
23722374

23732375
auto throwFinder = FindInnerThrows(*this, expr);
23742376
body->walk(throwFinder);
@@ -2377,6 +2379,7 @@ FunctionType::ExtInfo ConstraintSystem::closureEffects(ClosureExpr *expr) {
23772379
auto result = ASTExtInfoBuilder()
23782380
.withThrows(throwFinder.foundThrow())
23792381
.withAsync(asyncFinder.foundAsync())
2382+
.withConcurrent(concurrent)
23802383
.build();
23812384
closureEffectsCache[expr] = result;
23822385
return result;

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5482,10 +5482,9 @@ namespace {
54825482
class ClosureAttributeChecker
54835483
: public AttributeVisitor<ClosureAttributeChecker> {
54845484
ASTContext &ctx;
5485-
ClosureExpr *closure;
54865485
public:
54875486
ClosureAttributeChecker(ClosureExpr *closure)
5488-
: ctx(closure->getASTContext()), closure(closure) { }
5487+
: ctx(closure->getASTContext()) { }
54895488

54905489
void visitDeclAttribute(DeclAttribute *attr) {
54915490
ctx.Diags.diagnose(
@@ -5494,6 +5493,10 @@ class ClosureAttributeChecker
54945493
.fixItRemove(attr->getRangeWithAt());
54955494
attr->setInvalid();
54965495
}
5496+
5497+
void visitConcurrentAttr(ConcurrentAttr *attr) {
5498+
// Nothing else to check.
5499+
}
54975500
};
54985501

54995502
}

test/attr/attr_concurrent.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,10 @@ func testCaseNonTrivialValue() {
118118

119119
j = 17
120120
}
121+
122+
func testExplicitConcurrentClosure() {
123+
let fn = { @concurrent in
124+
17
125+
}
126+
let _: String = fn // expected-error{{cannot convert value of type '@concurrent () -> Int' to specified type 'String'}}
127+
}

0 commit comments

Comments
 (0)