@@ -7393,15 +7393,38 @@ RValue RValueEmitter::visitMacroExpansionExpr(MacroExpansionExpr *E,
7393
7393
return RValue ();
7394
7394
}
7395
7395
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
+
7396
7407
RValue RValueEmitter::visitCurrentContextIsolationExpr (
7397
7408
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 );
7403
7427
if (ctor && ctor->isDesignatedInit () &&
7404
- isolation == ActorIsolation::ActorInstance &&
7405
7428
isolation.getActorInstance () == ctor->getImplicitSelfDecl ()) {
7406
7429
// If we are in an actor initializer that is isolated to self, the
7407
7430
// current isolation is flow-sensitive; use that instead of the
@@ -7410,21 +7433,11 @@ RValue RValueEmitter::visitCurrentContextIsolationExpr(
7410
7433
SGF.emitFlowSensitiveSelfIsolation (E, isolation);
7411
7434
return RValue (SGF, E, isolationValue);
7412
7435
}
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
- }
7426
7436
}
7427
7437
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.
7428
7441
return visit (E->getActor (), C);
7429
7442
}
7430
7443
0 commit comments