Skip to content

Commit ac19db2

Browse files
committed
Collapse ActorIsolationRestriction::CrossGlobalActor into GlobalActor.
Whether it's a cross-actor reference is better modeled as a separate axis rather than part of the "kind". All of the clients were treating it this was already.
1 parent 3e6b369 commit ac19db2

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

lib/Sema/TypeCheckConcurrency.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,6 @@ namespace {
12971297
case ActorIsolationRestriction::Unrestricted:
12981298
case ActorIsolationRestriction::Unsafe:
12991299
break;
1300-
case ActorIsolationRestriction::CrossGlobalActor:
13011300
case ActorIsolationRestriction::GlobalActor: {
13021301
ctx.Diags.diagnose(argLoc, diag::actor_isolated_inout_state,
13031302
decl->getDescriptiveKind(), decl->getName(),
@@ -1683,11 +1682,9 @@ namespace {
16831682
case ActorIsolationRestriction::ActorSelf:
16841683
llvm_unreachable("non-member reference into an actor");
16851684

1686-
case ActorIsolationRestriction::CrossGlobalActor:
16871685
case ActorIsolationRestriction::GlobalActor:
16881686
return checkGlobalActorReference(
1689-
valueRef, loc, isolation.getGlobalActor(),
1690-
isolation == ActorIsolationRestriction::CrossGlobalActor);
1687+
valueRef, loc, isolation.getGlobalActor(), isolation.isCrossActor);
16911688

16921689
case ActorIsolationRestriction::Unsafe:
16931690
return diagnoseReferenceToUnsafeGlobal(value, loc);
@@ -1855,11 +1852,10 @@ namespace {
18551852
llvm_unreachable("Unhandled actor isolation");
18561853
}
18571854

1858-
case ActorIsolationRestriction::CrossGlobalActor:
18591855
case ActorIsolationRestriction::GlobalActor:
18601856
return checkGlobalActorReference(
18611857
memberRef, memberLoc, isolation.getGlobalActor(),
1862-
isolation == ActorIsolationRestriction::CrossGlobalActor);
1858+
isolation.isCrossActor);
18631859

18641860
case ActorIsolationRestriction::Unsafe:
18651861
// This case is hit when passing actor state inout to functions in some

lib/Sema/TypeCheckConcurrency.h

+18-16
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,13 @@ class ActorIsolationRestriction {
8686
/// the actor's isolation domain.
8787
ActorSelf,
8888

89-
/// References to a declaration that is part of a global actor are only
90-
/// permitted from other declarations with that same global actor.
89+
/// References to a declaration that is part of a global actor are
90+
/// permitted from other declarations with that same global actor or
91+
/// are permitted from elsewhere as a cross-actor reference.
9192
GlobalActor,
92-
93-
/// References to this entity are allowed from anywhere, but doing so may
94-
/// cross an actor boundary if it is not from the same global actor.
95-
CrossGlobalActor,
9693
};
9794

9895
private:
99-
/// The kind of restriction.
100-
Kind kind;
101-
10296
union {
10397
/// The local context that an entity is tied to.
10498
DeclContext *localContext;
@@ -110,9 +104,17 @@ class ActorIsolationRestriction {
110104
TypeBase *globalActor;
111105
} data;
112106

113-
explicit ActorIsolationRestriction(Kind kind) : kind(kind) { }
107+
explicit ActorIsolationRestriction(Kind kind, bool isCrossActor)
108+
: kind(kind), isCrossActor(isCrossActor) { }
114109

115110
public:
111+
/// The kind of restriction.
112+
const Kind kind;
113+
114+
/// Whether referencing this from another actor constitutes a cross-acter
115+
/// reference.
116+
const bool isCrossActor;
117+
116118
Kind getKind() const { return kind; }
117119

118120
/// Retrieve the actor class that the declaration is within.
@@ -123,25 +125,26 @@ class ActorIsolationRestriction {
123125

124126
/// Retrieve the actor class that the declaration is within.
125127
Type getGlobalActor() const {
126-
assert(kind == GlobalActor || kind == CrossGlobalActor);
128+
assert(kind == GlobalActor);
127129
return Type(data.globalActor);
128130
}
129131

130132
/// There are no restrictions on the use of the entity.
131133
static ActorIsolationRestriction forUnrestricted() {
132-
return ActorIsolationRestriction(Unrestricted);
134+
return ActorIsolationRestriction(Unrestricted, /*isCrossActor=*/false);
133135
}
134136

135137
/// Accesses to the given declaration are unsafe.
136138
static ActorIsolationRestriction forUnsafe() {
137-
return ActorIsolationRestriction(Unsafe);
139+
return ActorIsolationRestriction(Unsafe, /*isCrossActor=*/false);
138140
}
139141

140142
/// Accesses to the given declaration can only be made via the 'self' of
141143
/// the current actor or is a cross-actor access.
142144
static ActorIsolationRestriction forActorSelf(
143145
ClassDecl *actorClass, bool isCrossActor) {
144-
ActorIsolationRestriction result(isCrossActor? CrossActorSelf : ActorSelf);
146+
ActorIsolationRestriction result(isCrossActor? CrossActorSelf : ActorSelf,
147+
isCrossActor);
145148
result.data.actorClass = actorClass;
146149
return result;
147150
}
@@ -150,8 +153,7 @@ class ActorIsolationRestriction {
150153
/// global actor or is a cross-actor access.
151154
static ActorIsolationRestriction forGlobalActor(
152155
Type globalActor, bool isCrossActor) {
153-
ActorIsolationRestriction result(
154-
isCrossActor ? CrossGlobalActor : GlobalActor);
156+
ActorIsolationRestriction result(GlobalActor, isCrossActor);
155157
result.data.globalActor = globalActor.getPointer();
156158
return result;
157159
}

lib/Sema/TypeCheckDeclObjC.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ static bool checkObjCActorIsolation(const ValueDecl *VD,
408408
}
409409
return true;
410410

411-
case ActorIsolationRestriction::CrossGlobalActor:
412411
case ActorIsolationRestriction::GlobalActor:
413412
// FIXME: Consider whether to limit @objc on global-actor-qualified
414413
// declarations.

lib/Sema/TypeCheckProtocol.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -2762,13 +2762,10 @@ bool ConformanceChecker::checkActorIsolation(
27622762
return diagnoseNonConcurrentTypesInReference(
27632763
witness, DC, witness->getLoc(), ConcurrentReferenceKind::CrossActor);
27642764

2765-
case ActorIsolationRestriction::CrossGlobalActor:
2766-
isCrossActor = true;
2767-
LLVM_FALLTHROUGH;
2768-
27692765
case ActorIsolationRestriction::GlobalActor: {
27702766
// Hang on to the global actor that's used for the witness. It will need
27712767
// to match that of the requirement.
2768+
isCrossActor = witnessRestriction.isCrossActor;
27722769
witnessGlobalActor = witness->getDeclContext()->mapTypeIntoContext(
27732770
witnessRestriction.getGlobalActor());
27742771
break;

0 commit comments

Comments
 (0)