@@ -267,7 +267,7 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
267267 Kind : 2
268268 );
269269
270- SWIFT_INLINE_BITFIELD (ClosureExpr, AbstractClosureExpr, 1 +1 +1 +1 +1 +1 +1 +1 ,
270+ SWIFT_INLINE_BITFIELD (ClosureExpr, AbstractClosureExpr, 1 +1 +1 +1 +1 +1 +1 +1 + 1 ,
271271 // / True if closure parameters were synthesized from anonymous closure
272272 // / variables.
273273 HasAnonymousClosureVars : 1 ,
@@ -276,9 +276,11 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
276276 // / on each member reference.
277277 ImplicitSelfCapture : 1 ,
278278
279- // / True if this @Sendable async closure parameter should implicitly
280- // / inherit the actor context from where it was formed.
279+ // / True if this closure parameter should implicitly inherit the actor
280+ // / context from where it was formed.
281281 InheritActorContext : 1 ,
282+ // / The kind for inheritance - none or always at the moment.
283+ InheritActorContextKind : 1 ,
282284
283285 // / True if this closure's actor isolation behavior was determined by an
284286 // / \c \@preconcurrency declaration.
@@ -4318,6 +4320,7 @@ class ClosureExpr : public AbstractClosureExpr {
43184320 Bits.ClosureExpr .HasAnonymousClosureVars = false ;
43194321 Bits.ClosureExpr .ImplicitSelfCapture = false ;
43204322 Bits.ClosureExpr .InheritActorContext = false ;
4323+ Bits.ClosureExpr .InheritActorContextKind = 0 ;
43214324 Bits.ClosureExpr .IsPassedToSendingParameter = false ;
43224325 Bits.ClosureExpr .NoGlobalActorAttribute = false ;
43234326 Bits.ClosureExpr .RequiresDynamicIsolationChecking = false ;
@@ -4366,8 +4369,29 @@ class ClosureExpr : public AbstractClosureExpr {
43664369 return Bits.ClosureExpr .InheritActorContext ;
43674370 }
43684371
4369- void setInheritsActorContext (bool value = true ) {
4372+ // / Whether this closure should _always_ implicitly inherit the actor context
4373+ // / regardless of whether the isolation parameter is captured or not.
4374+ bool alwaysInheritsActorContext () const {
4375+ if (!inheritsActorContext ())
4376+ return false ;
4377+ return getInheritActorIsolationModifier () ==
4378+ InheritActorContextModifier::Always;
4379+ }
4380+
4381+ void setInheritsActorContext (bool value = true ,
4382+ InheritActorContextModifier modifier =
4383+ InheritActorContextModifier::None) {
43704384 Bits.ClosureExpr .InheritActorContext = value;
4385+ Bits.ClosureExpr .InheritActorContextKind = uint8_t (modifier);
4386+ assert ((static_cast <InheritActorContextModifier>(
4387+ Bits.ClosureExpr .InheritActorContextKind ) == modifier) &&
4388+ " not enough bits for modifier" );
4389+ }
4390+
4391+ InheritActorContextModifier getInheritActorIsolationModifier () const {
4392+ assert (inheritsActorContext ());
4393+ return static_cast <InheritActorContextModifier>(
4394+ Bits.ClosureExpr .InheritActorContextKind );
43714395 }
43724396
43734397 // / Whether the closure's concurrency behavior was determined by an
0 commit comments