Skip to content

Commit 0760739

Browse files
committed
Propagate global actor to a closure from its contextual type.
1 parent dbc63eb commit 0760739

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6842,6 +6842,22 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
68426842
}
68436843
}
68446844

6845+
// If we have a ClosureExpr, then we can safely propagate a global actor
6846+
// to the closure without invalidating prior analysis.
6847+
fromEI = fromFunc->getExtInfo();
6848+
if (toEI.getGlobalActor() && !fromEI.getGlobalActor()) {
6849+
auto newFromFuncType = fromFunc->withExtInfo(
6850+
fromEI.withGlobalActor(toEI.getGlobalActor()));
6851+
if (applyTypeToClosureExpr(cs, expr, newFromFuncType)) {
6852+
fromFunc = newFromFuncType->castTo<FunctionType>();
6853+
6854+
// Propagating the global actor bit might have satisfied the entire
6855+
// conversion. If so, we're done, otherwise keep converting.
6856+
if (fromFunc->isEqual(toType))
6857+
return expr;
6858+
}
6859+
}
6860+
68456861
// If we have a ClosureExpr, then we can safely propagate the 'no escape'
68466862
// bit to the closure without invalidating prior analysis.
68476863
fromEI = fromFunc->getExtInfo();

test/Concurrency/global_actor_function_types.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,13 @@ func testClosures() {
4646
acceptOnSomeGlobalActor { @SomeGlobalActor in
4747
onSomeGlobalActor()
4848
}
49+
50+
acceptOnSomeGlobalActor {
51+
onSomeGlobalActor()
52+
}
53+
54+
acceptOnSomeGlobalActor { () -> Int in
55+
let i = onSomeGlobalActor()
56+
return i
57+
}
4958
}

0 commit comments

Comments
 (0)