|
12 | 12 |
|
13 | 13 | #include "ArgumentScope.h" |
14 | 14 | #include "Callee.h" |
| 15 | +#include "ExecutorBreadcrumb.h" |
15 | 16 | #include "RValue.h" |
16 | 17 | #include "ResultPlan.h" |
17 | 18 | #include "SILGenFunction.h" |
@@ -1479,10 +1480,11 @@ SILFunction *SILGenFunction::emitNativeAsyncToForeignThunk(SILDeclRef thunk) { |
1479 | 1480 | } |
1480 | 1481 |
|
1481 | 1482 | // Create the closure implementation function. It has the same signature, |
1482 | | - // but is just swiftcc and async. |
| 1483 | + // but is swiftcc and async. |
1483 | 1484 | auto closureExtInfo = objcFnTy->getExtInfo().intoBuilder() |
1484 | 1485 | .withRepresentation(SILFunctionTypeRepresentation::Thin) |
1485 | 1486 | .withAsync() |
| 1487 | + .withConcurrent() |
1486 | 1488 | .build(); |
1487 | 1489 | auto closureTy = objcFnTy->getWithExtInfo(closureExtInfo); |
1488 | 1490 |
|
@@ -1556,6 +1558,22 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) { |
1556 | 1558 | auto loc = thunk.getAsRegularLocation(); |
1557 | 1559 | loc.markAutoGenerated(); |
1558 | 1560 | Scope scope(Cleanups, CleanupLocation(loc)); |
| 1561 | + |
| 1562 | + // Hop to the actor for the method's actor constraint, if any. |
| 1563 | + // Note that, since an async native-to-foreign thunk only ever runs in a |
| 1564 | + // task purpose-built for running the Swift async code triggering the |
| 1565 | + // completion handler, there is no need for us to hop back to the existing |
| 1566 | + // executor, since the task will end after we invoke the completion handler. |
| 1567 | + if (F.isAsync()) { |
| 1568 | + Optional<ActorIsolation> isolation; |
| 1569 | + if (thunk.hasDecl()) { |
| 1570 | + isolation = getActorIsolation(thunk.getDecl()); |
| 1571 | + } |
| 1572 | + |
| 1573 | + if (isolation) { |
| 1574 | + emitHopToTargetActor(loc, *isolation, None); |
| 1575 | + } |
| 1576 | + } |
1559 | 1577 |
|
1560 | 1578 | // If we are bridging a Swift method with an Any return value, create a |
1561 | 1579 | // stack allocation to hold the result, since Any is address-only. |
|
0 commit comments