Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change 'actor class' to 'actor' #35794

Merged

Conversation

etcwilde
Copy link
Member

@etcwilde etcwilde commented Feb 5, 2021

We've decided to go with calling actor classes actor instead of actor class.
We still want to be able to parse in actor class and recommend the correct fix-its to make it just actor. This is a little challenging since we parse other modifiers in any order, so actor public class Foo and public actor class Foo were both totally parsable. We still need to be able to do that, which makes this change less pleasant.

Furthermore, we want to make it a contextual keyword instead of an actual keyword so that we avoid breaking as much source. This also adds to the complexity.

I will update the diagnostics to refer to actor later.

Resolves: rdar://73728503

@etcwilde etcwilde requested a review from rintaro February 5, 2021 20:20

class NonActor { }

actor class NonActorSubclass : NonActor { } // expected-error{{actor class cannot inherit from non-actor class 'NonActor'}}
actor NonActorSubclass : NonActor { } // expected-error{{actor class cannot inherit from non-actor class 'NonActor'}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we instead be calling them "actor" rather than actor class in all diagnostics from here on?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that seems like a good idea.

@etcwilde etcwilde force-pushed the ewilde/all-the-world-is-a-stage-with-actors branch 2 times, most recently from ad4664d to 4487f9c Compare February 9, 2021 19:24
@etcwilde etcwilde marked this pull request as ready for review February 9, 2021 19:35
@etcwilde
Copy link
Member Author

etcwilde commented Feb 9, 2021

@swift-ci please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great; just two trivial comments that shouldn't block you from merging.

@@ -4148,6 +4206,13 @@ Parser::parseDecl(ParseDeclOptions Flags,
// Obvious nonsense.
default:

if (shouldParseExperimentalConcurrency() && Tok.is(tok::identifier) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the Tok.is(too::identifier) here, because it's part of Tok.isContextualKeyword.

@@ -3587,7 +3590,8 @@ class ClassDecl final : public NominalTypeDecl {
public:
ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc,
ArrayRef<TypeLoc> Inherited,
GenericParamList *GenericParams, DeclContext *DC);
GenericParamList *GenericParams, DeclContext *DC,
bool isActor=false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth dropping the default argument so we don't forget to pass it somewhere in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping it got a little nastier than intended. The unit tests have a makeNominal that will construct something based on a template argument. That thing is either a ClassDecl or a StructDecl.

Ended up with this little specialization of makeNominal. Not great, but not terrible.

  template <typename Nominal>
  Nominal *makeNominal(StringRef name,
                       GenericParamList *genericParams = nullptr) {

    auto result = new (Ctx) Nominal(SourceLoc(), Ctx.getIdentifier(name),
                                    SourceLoc(), /*inherited*/{},
                                    genericParams, FileForLookups);
    result->setAccess(AccessLevel::Internal);
    return result;
  }

  template <>
  swift::ClassDecl *makeNominal(StringRef name,
                                GenericParamList *genericParams) {
    auto result = new (Ctx) ClassDecl(SourceLoc(), Ctx.getIdentifier(name),
                                      SourceLoc(), /*inherited*/{},
                                      genericParams, FileForLookups,
                                      /*isActor*/false);
    result->setAccess(AccessLevel::Internal);
    return result;
  }

@etcwilde etcwilde force-pushed the ewilde/all-the-world-is-a-stage-with-actors branch from c611913 to 67cd3ad Compare February 9, 2021 20:02
@etcwilde
Copy link
Member Author

etcwilde commented Feb 9, 2021

@swift-ci please test

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 9, 2021

Build failed
Swift Test OS X Platform
Git Sha - 67cd3ad32151259ee2562d3d39ecd4e66bff53be

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 9, 2021

Build failed
Swift Test Linux Platform
Git Sha - 67cd3ad32151259ee2562d3d39ecd4e66bff53be

@etcwilde
Copy link
Member Author

etcwilde commented Feb 9, 2021

Heh, there were more places where constructed ClassDecls. :) I think I have all of them fixed, just testing locally.

@etcwilde etcwilde force-pushed the ewilde/all-the-world-is-a-stage-with-actors branch from 67cd3ad to d34e546 Compare February 9, 2021 21:59
@etcwilde
Copy link
Member Author

etcwilde commented Feb 9, 2021

@swift-ci please test

@etcwilde etcwilde force-pushed the ewilde/all-the-world-is-a-stage-with-actors branch from d34e546 to ecf7b81 Compare February 9, 2021 22:10
@etcwilde
Copy link
Member Author

etcwilde commented Feb 9, 2021

@swift-ci please test

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 9, 2021

Build failed
Swift Test Linux Platform
Git Sha - ecf7b81c31610a42911766da39b19edf865ddd5d

@etcwilde etcwilde force-pushed the ewilde/all-the-world-is-a-stage-with-actors branch from ecf7b81 to 1fcc706 Compare February 9, 2021 23:13
@etcwilde
Copy link
Member Author

etcwilde commented Feb 9, 2021

@swift-ci please test

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - 1fcc7065f3bdeef8729c8e9fa5e58ebf95b8ad5d

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - 1fcc7065f3bdeef8729c8e9fa5e58ebf95b8ad5d

@etcwilde etcwilde force-pushed the ewilde/all-the-world-is-a-stage-with-actors branch from 1fcc706 to 15ca7a4 Compare February 10, 2021 01:12
@etcwilde
Copy link
Member Author

@swift-ci please test

@etcwilde etcwilde force-pushed the ewilde/all-the-world-is-a-stage-with-actors branch from 15ca7a4 to a9ab561 Compare February 10, 2021 04:21
@etcwilde
Copy link
Member Author

@swift-ci please smoke test

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - 15ca7a4cd6e476db08379131ed7f697234ec7633

This patch softly updates the spelling of actors from `actor class` to
`actor`. We still accept using `actor` as a modifying attribute of
class, but emit a warning and fix-it to make the change.

One of the challenges that makes this messier is that the modifier list
can be in any order. e.g, `public actor class Foo {}` is the same as
`actor public class Foo {}`.

Classes have been updated to include whether they were explicitly
declared as an actor. This change updates the swiftmodule serialization
version number to 0.591. The additional bit only gets set of the class
declaration was declared as an actor, not if the actor was applied as an
attribute. This allows us to correctly emit `actor class` vs `actor`
emitting the code back out.
This patch updates the once instance of actor class in the concurrency
library to actor. This is the actor for the MainActor global actor.
This patch updates the `actor class` spelling to `actor` in almost all
of the tests. There are places where I verify that we sanely handle
`actor` as an attribute though. These include:

 - test/decl/class/actor/basic.swift
 - test/decl/protocol/special/Actor.swift
 - test/SourceKit/CursorInfo/cursor_info_concurrency.swift
 - test/attr/attr_objc_async.swift
 - test/ModuleInterface/actor_protocol.swift
@etcwilde etcwilde force-pushed the ewilde/all-the-world-is-a-stage-with-actors branch from a9ab561 to 8b80331 Compare February 10, 2021 16:09
@etcwilde
Copy link
Member Author

@swift-ci please smoke test

@etcwilde etcwilde merged commit 1f3879b into apple:main Feb 10, 2021
@etcwilde etcwilde deleted the ewilde/all-the-world-is-a-stage-with-actors branch February 10, 2021 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants