Skip to content

Commit 11cf3ce

Browse files
committed
[Concurrency] Eliminate actor isolation checking for subclasses.
Subclasses inherit the global actor from their superclass by default, but it's okay to change it---it's just a default that can be overridden on a per-member basis anyway.
1 parent 18fd4be commit 11cf3ce

File tree

5 files changed

+4
-41
lines changed

5 files changed

+4
-41
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,9 +4265,6 @@ ERROR(actor_isolation_multiple_attr,none,
42654265
ERROR(actor_isolation_override_mismatch,none,
42664266
"%0 %1 %2 has different actor isolation from %3 overridden declaration",
42674267
(ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
4268-
ERROR(actor_isolation_superclass_mismatch,none,
4269-
"%0 class %1 has different actor isolation from %2 superclass %3",
4270-
(ActorIsolation, Identifier, ActorIsolation, Identifier))
42714268

42724269
//------------------------------------------------------------------------------
42734270
// MARK: Type Check Types

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,31 +1252,3 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
12521252
value->getDescriptiveKind(), value->getName(), overriddenIsolation);
12531253
overridden->diagnose(diag::overridden_here);
12541254
}
1255-
1256-
void swift::checkSubclassActorIsolation(ClassDecl *classDecl) {
1257-
auto superclassDecl = classDecl->getSuperclassDecl();
1258-
if (!superclassDecl)
1259-
return;
1260-
1261-
auto isolation = getActorIsolation(classDecl);
1262-
auto superclassIsolation = getActorIsolation(superclassDecl);
1263-
1264-
if (superclassIsolation.requiresSubstitution()) {
1265-
Type superclassType = classDecl->getSuperclass();
1266-
if (!superclassType)
1267-
return;
1268-
1269-
SubstitutionMap subs = superclassType->getMemberSubstitutionMap(
1270-
classDecl->getModuleContext(), classDecl);
1271-
superclassIsolation = superclassIsolation.subst(subs);
1272-
}
1273-
1274-
if (isolation == superclassIsolation)
1275-
return;
1276-
1277-
// Diagnose mismatch.
1278-
classDecl->diagnose(
1279-
diag::actor_isolation_superclass_mismatch, isolation,
1280-
classDecl->getName(), superclassIsolation, superclassDecl->getName());
1281-
superclassDecl->diagnose(diag::decl_declared_here, superclassDecl->getName());
1282-
}

lib/Sema/TypeCheckConcurrency.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ class ActorIsolationRestriction {
148148
/// overridden declaration.
149149
void checkOverrideActorIsolation(ValueDecl *value);
150150

151-
/// Check that the actor isolation of a class matches that of its superclass.
152-
void checkSubclassActorIsolation(ClassDecl *classDecl);
153-
154151
} // end namespace swift
155152

156153
#endif /* SWIFT_SEMA_TYPECHECKCONCURRENCY_H */

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
13901390
(void) VD->isObjC();
13911391
(void) VD->isDynamic();
13921392

1393-
// For a class, check actor isolation.
1394-
if (auto classDecl = dyn_cast<ClassDecl>(VD))
1395-
checkSubclassActorIsolation(classDecl);
1396-
13971393
// If this is a member of a nominal type, don't allow it to have a name of
13981394
// "Type" or "Protocol" since we reserve the X.Type and X.Protocol
13991395
// expressions to mean something builtin to the language. We *do* allow

test/Concurrency/global_actor_inference.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,14 @@ actor class GenericSub<T> : GenericSuper<[T]> {
134134
}
135135

136136
// ----------------------------------------------------------------------
137-
// Global actor checking for supeclasses
137+
// Global actor inference for superclasses
138138
// ----------------------------------------------------------------------
139139
struct Container<T> {
140-
@GenericGlobalActor<T> class Superclass { } // expected-note{{'Superclass' declared here}}
140+
@GenericGlobalActor<T> class Superclass { }
141141
}
142142

143143
struct OtherContainer<U> {
144+
// Okay to change the global actor in a subclass.
144145
@GenericGlobalActor<[U]> class Subclass1 : Container<[U]>.Superclass { }
145-
@GenericGlobalActor<U> class Subclass2 : Container<[U]>.Superclass { } // expected-error{{global actor 'GenericGlobalActor<U>'-isolated class 'Subclass2' has different actor isolation from global actor 'GenericGlobalActor<[U]>'-isolated superclass 'Superclass'}}
146+
@GenericGlobalActor<U> class Subclass2 : Container<[U]>.Superclass { }
146147
}

0 commit comments

Comments
 (0)