-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fixing async main resolution #42142
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
Fixing async main resolution #42142
Conversation
@swift-ci please test |
Windows failure https://ci-external.swift.org/job/swift-PR-windows/254/:
|
@swift-ci please test Windows |
@swift-ci please test |
@@ -50,6 +51,8 @@ namespace swift { | |||
class ConstraintSystem; | |||
class Solution; | |||
class SolutionApplicationTarget; | |||
enum class ConstraintSystemFlags; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this makes me slightly uncomfortable, if there is ever a size mismatch between the forward declaration and the full definition with enum members, there is a compile-time error.
e.g.
swift/include/swift/Sema/IDETypeChecking.h:54:14: error: enumeration redeclared with different underlying type 'long' (was 'int')
enum class ConstraintSystemFlags : long;
^
swift/include/swift/Sema/ConstraintSystem.h:1453:12: note: previous declaration is here
enum class ConstraintSystemFlags {
^
@swift-ci please test Windows |
@swift-ci please test |
@swift-ci please test Windows |
@swift-ci please test |
@swift-ci please test Windows |
This flag biases the overload checker in favor of selecting an asynchronous main function over a synchronous main. If no asynchronous main function exists, a synchronous one will still be selected. Likewise, if the flag is not passed and there are only asynchronous main functions available, the most specific asynchronous main function will still be selected.
The async main resolution has dropped the custom availability checking, so I am able to collapse the resolution checking into a single test (deleting the macos-specific one). Selection of an asynchronous main vs a synchronous main is dependent on an `-async-main` flag. Due to the scoring mechanism, and that the specificity of a given resolution doesn't affect the score, a more general synchronous main will be selected over a more specific asynchronous main when the `-async-main` flag is not passed. If the flag is not passed and the program only contains an asynchronous main, or the asynchronous main is the only main function that is available given the constraints, then it will be selected. Conversely, if the flag is set and no valid asynchronous main functions exist, the main function will resolve to a synchronous main. This is the same behavior that is used to resolve an synchronous and asynchronous static function.
Something about including the constraint system in this file made Windows upset because full definitions. I'm trying again with a forward-declaration of the enum class inside of a `using`.
47e310e
to
a427c05
Compare
This patch adds an
-async-main
flag to bias the constraint solver in favor of selecting an asynchronous main.In the event that a program does not contain a valid asynchronous main, it will fall back on the most specific valid synchronous main function.
Conversely, if the flag is not passed and the program does not contain a valid synchronous main function, it will fall back on the most specific valid asynchronous main function.
The flag is a driver option, so it can be passed without needing to preface it with
-Xfrontend
.The flag sets a constraint-solver option when resolving the main function that sets
NominalTypeDecl
contexts as asynchronous contexts.rdar://91156901