Skip to content

Commit aeddab4

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
1 parent 87113d7 commit aeddab4

File tree

5 files changed

+16
-51
lines changed

5 files changed

+16
-51
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,41 +3612,25 @@ bool Parser::parseDeclModifierList(DeclAttributes &Attributes,
36123612
// that scope, so we have to store enough state to emit the diagnostics
36133613
// outside of the scope.
36143614
bool isActorModifier = false;
3615-
bool isClassNext = false;
36163615
SourceLoc actorLoc = Tok.getLoc();
3617-
SourceLoc classLoc;
3616+
36183617
{
36193618
BacktrackingScope Scope(*this);
36203619

3621-
// Is this the class token before the identifier?
3622-
auto atClassDecl = [this]() -> bool {
3623-
return peekToken().is(tok::identifier) ||
3624-
Tok.is(tok::kw_class) ||
3625-
Tok.is(tok::kw_enum) ||
3626-
Tok.is(tok::kw_struct);
3627-
};
36283620
consumeToken(); // consume actor
36293621
isActorModifier = isStartOfSwiftDecl();
3630-
if (isActorModifier) {
3631-
isClassNext = atClassDecl();
3632-
while (!atClassDecl())
3633-
consumeToken();
3634-
classLoc = Tok.getLoc();
3635-
}
36363622
}
36373623

36383624
if (!isActorModifier)
36393625
break;
36403626

3641-
auto diag = diagnose(actorLoc,
3642-
diag::renamed_platform_condition_argument, "actor class", "actor");
3643-
if (isClassNext)
3644-
diag.fixItRemove(classLoc);
3645-
else
3646-
diag.fixItReplace(classLoc, "actor")
3647-
.fixItRemove(actorLoc);
3648-
Attributes.add(new (Context) ActorAttr({}, Tok.getLoc()));
3649-
consumeToken();
3627+
// Actor is a standalone keyword now, so it can't be used
3628+
// as a modifier. Let's diagnose and recover.
3629+
isError = true;
3630+
3631+
consumeToken(); // consume 'actor'
3632+
3633+
diagnose(actorLoc, diag::keyword_cant_be_identifier, Tok.getText());
36503634
continue;
36513635
}
36523636

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ bool IsActorRequest::evaluate(
107107
if (!classDecl)
108108
return false;
109109

110-
return classDecl->isExplicitActor() ||
111-
classDecl->getAttrs().getAttribute<ActorAttr>();
110+
return classDecl->isExplicitActor();
112111
}
113112

114113
bool IsDefaultActorRequest::evaluate(

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)