Skip to content

Commit 29d86a6

Browse files
committed
[Parse] Disallow use of actor as a declaration modifier
`actor` is a standalone contextual keyword now and should be treated as such, `actor class` is no longer allowed and results in a parse error. Resolves: rdar://75753598 (cherry picked from commit aeddab4)
1 parent 15fa94d commit 29d86a6

File tree

6 files changed

+16
-55
lines changed

6 files changed

+16
-55
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,41 +3626,25 @@ bool Parser::parseDeclModifierList(DeclAttributes &Attributes,
36263626
// that scope, so we have to store enough state to emit the diagnostics
36273627
// outside of the scope.
36283628
bool isActorModifier = false;
3629-
bool isClassNext = false;
36303629
SourceLoc actorLoc = Tok.getLoc();
3631-
SourceLoc classLoc;
3630+
36323631
{
36333632
BacktrackingScope Scope(*this);
36343633

3635-
// Is this the class token before the identifier?
3636-
auto atClassDecl = [this]() -> bool {
3637-
return peekToken().is(tok::identifier) ||
3638-
Tok.is(tok::kw_class) ||
3639-
Tok.is(tok::kw_enum) ||
3640-
Tok.is(tok::kw_struct);
3641-
};
36423634
consumeToken(); // consume actor
36433635
isActorModifier = isStartOfSwiftDecl();
3644-
if (isActorModifier) {
3645-
isClassNext = atClassDecl();
3646-
while (!atClassDecl())
3647-
consumeToken();
3648-
classLoc = Tok.getLoc();
3649-
}
36503636
}
36513637

36523638
if (!isActorModifier)
36533639
break;
36543640

3655-
auto diag = diagnose(actorLoc,
3656-
diag::renamed_platform_condition_argument, "actor class", "actor");
3657-
if (isClassNext)
3658-
diag.fixItRemove(classLoc);
3659-
else
3660-
diag.fixItReplace(classLoc, "actor")
3661-
.fixItRemove(actorLoc);
3662-
Attributes.add(new (Context) ActorAttr({}, Tok.getLoc()));
3663-
consumeToken();
3641+
// Actor is a standalone keyword now, so it can't be used
3642+
// as a modifier. Let's diagnose and recover.
3643+
isError = true;
3644+
3645+
consumeToken(); // consume 'actor'
3646+
3647+
diagnose(actorLoc, diag::keyword_cant_be_identifier, Tok.getText());
36643648
continue;
36653649
}
36663650

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ bool IsActorRequest::evaluate(
271271
if (!classDecl)
272272
return false;
273273

274-
return classDecl->isExplicitActor() ||
275-
classDecl->getAttrs().getAttribute<ActorAttr>();
274+
return classDecl->isExplicitActor();
276275
}
277276

278277
bool IsDefaultActorRequest::evaluate(

test/ModuleInterface/actor_protocol.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ public actor ExplicitActorClass : Actor {
2727
@available(SwiftStdlib 5.5, *)
2828
public actor EmptyActor {}
2929

30-
// CHECK: actor public class EmptyActorClass {
31-
@available(SwiftStdlib 5.5, *)
32-
public actor class EmptyActorClass {}
33-
3430
// CHECK: public protocol Cat : _Concurrency.Actor {
3531
@available(SwiftStdlib 5.5, *)
3632
public protocol Cat : Actor {

test/SourceKit/CursorInfo/cursor_info_concurrency.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ func test(act: MyActor) async throws {
77
try await act.asyncFunc {}
88
}
99

10-
public actor class MyActorClass {
11-
public func asyncFunc(fn: () async -> Void) async throws {}
12-
}
13-
14-
func test(act: MyActorClass) async throws {
15-
try await act.asyncFunc {}
16-
}
17-
1810
// BEGIN App.swift
1911
import MyModule
2012

@@ -35,15 +27,9 @@ func test(act: MyActor) async throws {
3527
// RUN: %sourcekitd-test -req=cursor -pos=5:16 %t/MyModule.swift -- %t/MyModule.swift -target %target-triple -Xfrontend -enable-experimental-concurrency | %FileCheck -check-prefix=ACTOR %s
3628
// RUN: %sourcekitd-test -req=cursor -pos=6:19 %t/MyModule.swift -- %t/MyModule.swift -target %target-triple -Xfrontend -enable-experimental-concurrency | %FileCheck -check-prefix=FUNC %s
3729

38-
// RUN: %sourcekitd-test -req=cursor -pos=9:20 %t/MyModule.swift -- %t/MyModule.swift -target %target-triple -Xfrontend -enable-experimental-concurrency | %FileCheck -check-prefix=CLASSACTOR %s
39-
// RUN: %sourcekitd-test -req=cursor -pos=13:16 %t/MyModule.swift -- %t/MyModule.swift -target %target-triple -Xfrontend -enable-experimental-concurrency | %FileCheck -check-prefix=CLASSACTOR %s
40-
4130
// ACTOR: <Declaration>public actor MyActor</Declaration>
4231
// ACTOR: <decl.class><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>actor</syntaxtype.keyword> <decl.name>MyActor</decl.name></decl.class>
4332

44-
// CLASSACTOR: <Declaration>public actor class MyActorClass</Declaration>
45-
// CLASSACTOR: <decl.class><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>actor</syntaxtype.keyword> <syntaxtype.keyword>class</syntaxtype.keyword> <decl.name>MyActorClass</decl.name></decl.class>
46-
4733
// FUNC: <Declaration>public func asyncFunc(fn: () async -&gt; <Type usr="s:s4Voida">Void</Type>) async throws</Declaration>
4834
// FUNC: <decl.function.method.instance><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>asyncFunc</decl.name>(<decl.var.parameter><decl.var.parameter.argument_label>fn</decl.var.parameter.argument_label>: <decl.var.parameter.type>() <syntaxtype.keyword>async</syntaxtype.keyword> -&gt; <decl.function.returntype><ref.typealias usr="s:s4Voida">Void</ref.typealias></decl.function.returntype></decl.var.parameter.type></decl.var.parameter>) <syntaxtype.keyword>async</syntaxtype.keyword> <syntaxtype.keyword>throws</syntaxtype.keyword></decl.function.method.instance>
4935

test/attr/attr_objc_async.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ actor MyActor {
4747
@objc nonisolated func synchronousGood() { }
4848
}
4949

50-
// CHECK: actor class MyActor2
5150
actor class MyActor2 { }
52-
// expected-warning@-1{{'actor class' has been renamed to 'actor'}}{{7-13=}}
51+
// expected-error@-1 {{keyword 'class' cannot be used as an identifier here}}
5352

5453
// CHECK: @objc actor MyObjCActor
5554
@objc actor MyObjCActor: NSObject { }
5655

57-
// CHECK: @objc actor class MyObjCActor2
5856
@objc actor class MyObjCActor2: NSObject {}
59-
// expected-warning@-1{{'actor class' has been renamed to 'actor'}}{{13-19=}}
57+
// expected-error@-1 {{keyword 'class' cannot be used as an identifier here}}

test/decl/class/actor/basic.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@ class MyActorSubclass1: MyActor { } // expected-error{{actor types do not suppor
99

1010
actor MyActorSubclass2: MyActor { } // expected-error{{actor types do not support inheritance}}
1111

12-
// expected-warning@+1{{'actor class' has been renamed to 'actor'}}{{7-13=}}
12+
// expected-error@+1{{keyword 'class' cannot be used as an identifier here}}
1313
actor class MyActorClass { }
1414

1515
class NonActor { }
1616

1717
actor NonActorSubclass : NonActor { } // expected-error{{actor types do not support inheritance}}
1818

19-
// expected-warning@+1{{'actor class' has been renamed to 'actor'}}{{14-20=}}
19+
// expected-error@+1{{keyword 'class' cannot be used as an identifier here}}
2020
public actor class BobHope {}
21-
// expected-warning@+1{{'actor class' has been renamed to 'actor'}}{{14-19=actor}}{{1-7=}}
21+
// expected-error@+1{{keyword 'public' cannot be used as an identifier here}}
2222
actor public class BarbraStreisand {}
23-
// expected-warning@+2{{'actor class' has been renamed to 'actor'}}{{14-21=}}
24-
// expected-error@+1{{'actor' may only be used on 'class' declarations}}
23+
// expected-error@+1{{keyword 'struct' cannot be used as an identifier here}}
2524
public actor struct JulieAndrews {}
26-
// expected-warning@+2{{'actor class' has been renamed to 'actor'}}{{14-18=actor}}{{1-7=}}
27-
// expected-error@+1{{'actor' may only be used on 'class' declarations}}
25+
// expected-error@+1{{keyword 'public' cannot be used as an identifier here}}
2826
actor public enum TomHanks {}

0 commit comments

Comments
 (0)