@@ -7393,15 +7393,38 @@ RValue RValueEmitter::visitMacroExpansionExpr(MacroExpansionExpr *E,
73937393 return RValue ();
73947394}
73957395
7396+ // / getActorIsolationOfContext doesn't return the right isolation for
7397+ // / initializer contexts. Fixing that is a lot of work, so just
7398+ // / hack around it for now here.
7399+ static ActorIsolation getRealActorIsolationOfContext (DeclContext *DC) {
7400+ if (auto init = dyn_cast<Initializer>(DC)) {
7401+ return getActorIsolation (init);
7402+ } else {
7403+ return getActorIsolationOfContext (DC);
7404+ }
7405+ }
7406+
73967407RValue RValueEmitter::visitCurrentContextIsolationExpr (
73977408 CurrentContextIsolationExpr *E, SGFContext C) {
7398- auto afd =
7399- dyn_cast_or_null<AbstractFunctionDecl>(SGF.F .getDeclRef ().getDecl ());
7400- if (afd) {
7401- auto isolation = getActorIsolation (afd);
7402- auto ctor = dyn_cast_or_null<ConstructorDecl>(afd);
7409+
7410+ auto isolation = getRealActorIsolationOfContext (SGF.FunctionDC );
7411+
7412+ if (isolation == ActorIsolation::CallerIsolationInheriting) {
7413+ auto *isolatedArg = SGF.F .maybeGetIsolatedArgument ();
7414+ assert (isolatedArg &&
7415+ " Caller Isolation Inheriting without isolated parameter" );
7416+ ManagedValue isolatedMV;
7417+ if (isolatedArg->getOwnershipKind () == OwnershipKind::Guaranteed) {
7418+ isolatedMV = ManagedValue::forBorrowedRValue (isolatedArg);
7419+ } else {
7420+ isolatedMV = ManagedValue::forUnmanagedOwnedValue (isolatedArg);
7421+ }
7422+ return RValue (SGF, E, isolatedMV);
7423+ }
7424+
7425+ if (isolation == ActorIsolation::ActorInstance) {
7426+ auto ctor = dyn_cast<ConstructorDecl>(SGF.FunctionDC );
74037427 if (ctor && ctor->isDesignatedInit () &&
7404- isolation == ActorIsolation::ActorInstance &&
74057428 isolation.getActorInstance () == ctor->getImplicitSelfDecl ()) {
74067429 // If we are in an actor initializer that is isolated to self, the
74077430 // current isolation is flow-sensitive; use that instead of the
@@ -7410,21 +7433,11 @@ RValue RValueEmitter::visitCurrentContextIsolationExpr(
74107433 SGF.emitFlowSensitiveSelfIsolation (E, isolation);
74117434 return RValue (SGF, E, isolationValue);
74127435 }
7413-
7414- if (isolation == ActorIsolation::CallerIsolationInheriting) {
7415- auto *isolatedArg = SGF.F .maybeGetIsolatedArgument ();
7416- assert (isolatedArg &&
7417- " Caller Isolation Inheriting without isolated parameter" );
7418- ManagedValue isolatedMV;
7419- if (isolatedArg->getOwnershipKind () == OwnershipKind::Guaranteed) {
7420- isolatedMV = ManagedValue::forBorrowedRValue (isolatedArg);
7421- } else {
7422- isolatedMV = ManagedValue::forUnmanagedOwnedValue (isolatedArg);
7423- }
7424- return RValue (SGF, E, isolatedMV);
7425- }
74267436 }
74277437
7438+ // Otherwise, just trust the underlying expression. We really don't
7439+ // need to do this at all --- we assume we can produce the isolation
7440+ // value from scratch in other situations --- but whatever.
74287441 return visit (E->getActor (), C);
74297442}
74307443
0 commit comments