Skip to content

Require MainActor isolation on main() function #39503

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

Merged
merged 2 commits into from
Oct 5, 2021

Conversation

etcwilde
Copy link
Member

This patch forces the main function to be protected behind MainActor
isolation.

This implements the other part of SE-0323.

@etcwilde etcwilde requested a review from DougGregor September 29, 2021 09:49
@etcwilde
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 41efb8597c7abb46061d3a66e9ed215b4d624f9c

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 41efb8597c7abb46061d3a66e9ed215b4d624f9c

@etcwilde etcwilde force-pushed the ewilde/mainactor-the-mains branch from 41efb85 to e96b3f0 Compare October 2, 2021 05:39
@etcwilde
Copy link
Member Author

etcwilde commented Oct 2, 2021

@swift-ci please test

@etcwilde
Copy link
Member Author

etcwilde commented Oct 2, 2021

@swift-ci please test Windows platform

@etcwilde
Copy link
Member Author

etcwilde commented Oct 3, 2021

@swift-ci please test Linux platform

@etcwilde
Copy link
Member Author

etcwilde commented Oct 3, 2021

@swift-ci please test macOS platform

@etcwilde etcwilde marked this pull request as ready for review October 3, 2021 05:30
Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Looks good!

This patch forces the main function to be protected behind MainActor
isolation. If no actor isolation is specified, the main function will
implicitly have MainActor isolation.
Putting the main function under the MainActor appears to have
accidentally "fixed" the resilience tests on Windows. I've put the entry
to those tests under a separate task to try and avoid accidentally
hiding the bug behind the main actor.
@etcwilde etcwilde force-pushed the ewilde/mainactor-the-mains branch from 7ee8ea6 to fa00a32 Compare October 4, 2021 22:19
@etcwilde
Copy link
Member Author

etcwilde commented Oct 4, 2021

@swift-ci please test

@etcwilde etcwilde changed the title Force MainActor isolation on main() function Require MainActor isolation on main() function Oct 4, 2021
@etcwilde etcwilde merged commit 7dd295f into swiftlang:main Oct 5, 2021
ASTContext &ctx = fnDecl->getASTContext();

const bool isMainMain = fnDecl->isMainTypeMainMethod();
const bool isMain$Main =
Copy link
Member

Choose a reason for hiding this comment

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

In theory, I think a C compiler can reject this.

Copy link
Member Author

Choose a reason for hiding this comment

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

*pulls out C++ spec*
Yes you are correct. $ is not a valid C++14 identifier-nondigit per 2.10. Will fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

4 participants