|
12 | 12 |
|
13 | 13 | #include "ArgumentSource.h"
|
14 | 14 | #include "Conversion.h"
|
| 15 | +#include "ExecutorBreadcrumb.h" |
15 | 16 | #include "Initialization.h"
|
16 | 17 | #include "LValue.h"
|
17 | 18 | #include "RValue.h"
|
@@ -357,6 +358,13 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
|
357 | 358 | ctor->getThrowsLoc());
|
358 | 359 | emitConstructorMetatypeArg(*this, ctor);
|
359 | 360 |
|
| 361 | + // Make sure we've hopped to the right global actor, if any. |
| 362 | + if (ctor->hasAsync()) { |
| 363 | + SILLocation prologueLoc(selfDecl); |
| 364 | + prologueLoc.markAsPrologue(); |
| 365 | + emitConstructorPrologActorHop(prologueLoc, getActorIsolation(ctor)); |
| 366 | + } |
| 367 | + |
360 | 368 | // Create a basic block to jump to for the implicit 'self' return.
|
361 | 369 | // We won't emit this until after we've emitted the body.
|
362 | 370 | // The epilog takes a void return because the return of 'self' is implicit.
|
@@ -662,6 +670,18 @@ static void emitDefaultActorInitialization(SILGenFunction &SGF,
|
662 | 670 | { self.borrow(SGF, loc).getValue() });
|
663 | 671 | }
|
664 | 672 |
|
| 673 | +void SILGenFunction::emitConstructorPrologActorHop( |
| 674 | + SILLocation loc, |
| 675 | + Optional<ActorIsolation> maybeIso) { |
| 676 | + if (!maybeIso) |
| 677 | + return; |
| 678 | + |
| 679 | + if (auto executor = emitExecutor(loc, *maybeIso, None)) { |
| 680 | + ExpectedExecutor = *executor; |
| 681 | + B.createHopToExecutor(loc, *executor); |
| 682 | + } |
| 683 | +} |
| 684 | + |
665 | 685 | void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
|
666 | 686 | MagicFunctionName = SILGenModule::getMagicFunctionName(ctor);
|
667 | 687 |
|
@@ -724,6 +744,13 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
|
724 | 744 | SILType selfTy = getLoweredLoadableType(selfDecl->getType());
|
725 | 745 | ManagedValue selfArg = B.createInputFunctionArgument(selfTy, selfDecl);
|
726 | 746 |
|
| 747 | + // Make sure we've hopped to the right global actor, if any. |
| 748 | + if (ctor->hasAsync() && !selfClassDecl->isActor()) { |
| 749 | + SILLocation prologueLoc(selfDecl); |
| 750 | + prologueLoc.markAsPrologue(); |
| 751 | + emitConstructorPrologActorHop(prologueLoc, getActorIsolation(ctor)); |
| 752 | + } |
| 753 | + |
727 | 754 | if (!NeedsBoxForSelf) {
|
728 | 755 | SILLocation PrologueLoc(selfDecl);
|
729 | 756 | PrologueLoc.markAsPrologue();
|
|
0 commit comments