Skip to content

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

Merged
merged 4 commits into from
Apr 4, 2022

Conversation

etcwilde
Copy link
Member

@etcwilde etcwilde commented Apr 1, 2022

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

@etcwilde etcwilde added the concurrency Feature: umbrella label for concurrency language features label Apr 1, 2022
@etcwilde
Copy link
Member Author

etcwilde commented Apr 1, 2022

@swift-ci please test

@etcwilde etcwilde removed the request for review from nate-chandler April 1, 2022 19:04
@etcwilde
Copy link
Member Author

etcwilde commented Apr 1, 2022

Windows failure https://ci-external.swift.org/job/swift-PR-windows/254/:

FAILED: source/Plugins/ExpressionParser/Swift/CMakeFiles/lldbPluginExpressionParserSwift.dir/SwiftREPL.cpp.obj 
C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1429~1.300\bin\Hostx64\x64\cl.exe  /nologo /TP -DGTEST_HAS_RTTI=0 -DLLDB_ENABLE_SWIFT -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Isource\Plugins\ExpressionParser\Swift -IC:\Users\swift-ci\jenkins\workspace\swift-PR-windows\llvm-project\lldb\source\Plugins\ExpressionParser\Swift -IC:\Users\swift-ci\jenkins\workspace\swift-PR-windows\llvm-project\lldb\include -Iinclude -IC:\Users\swift-ci\jenkins\workspace\swift-PR-windows\llvm-project\llvm\include -IT:\llvm\include -IC:\Users\swift-ci\jenkins\workspace\swift-PR-windows\llvm-project\clang\include -IT:\llvm\tools\clang\include -IT:\swift\include -IC:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include -IC:\Users\swift-ci\jenkins\workspace\swift-PR-windows\llvm-project\lldb\source -I"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\include" -IC:\Users\swift-ci\jenkins\workspace\swift-PR-windows\llvm-project\lldb\tools\clang\include -I..\clang\include -Isource /GS- /Oy /Zc:inline /Zc:__cplusplus /Zc:strictStrings /Oi /Zc:rvalueCast /bigobj /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd4324 -w14062 -we4238 /Gw /MD /O2 /Ob2   -wd4018 -wd4068 -wd4150 -wd4201 -wd4251 -wd4521 -wd4530  /EHs-c- /GR- -UNDEBUG -std:c++14 /showIncludes /Fosource\Plugins\ExpressionParser\Swift\CMakeFiles\lldbPluginExpressionParserSwift.dir\SwiftREPL.cpp.obj /Fdsource\Plugins\ExpressionParser\Swift\CMakeFiles\lldbPluginExpressionParserSwift.dir\lldbPluginExpressionParserSwift.pdb /FS -c C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\llvm-project\lldb\source\Plugins\ExpressionParser\Swift\SwiftREPL.cpp
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Syntax/Syntax.h(505): warning C4996: 'swift::syntax::RawSyntax::dump': only for use in the debugger
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(174): error C2672: 'isa': no matching overloaded function found
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(620): note: see reference to function template instantiation 'bool swift::constraints::ConstraintLocator::PathElement::is<swift::constraints::ConstraintLocator::PathElement::TupleElement>(void) const' being compiled
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(174): error C2440: 'initializing': cannot convert from 'const swift::constraints::ConstraintLocator::PathElement *' to 'const swift::constraints::LocatorPathElt &'
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(174): note: Reason: cannot convert from 'const swift::constraints::ConstraintLocator::PathElement *' to 'const swift::constraints::LocatorPathElt'
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(174): note: No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(162): error C2672: 'dyn_cast': no matching overloaded function found
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(1176): note: see reference to function template instantiation 'llvm::Optional<swift::constraints::ConstraintLocator::PathElement::AnyRequirement> swift::constraints::ConstraintLocator::PathElement::getAs<swift::constraints::ConstraintLocator::PathElement::AnyRequirement>(void) const' being compiled
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(162): error C2440: 'initializing': cannot convert from 'const swift::constraints::ConstraintLocator::PathElement *' to 'const swift::constraints::LocatorPathElt &'
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(162): note: Reason: cannot convert from 'const swift::constraints::ConstraintLocator::PathElement *' to 'const swift::constraints::LocatorPathElt'
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(162): note: No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(162): error C3536: 'result': cannot be used before it is initialized
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Sema/ConstraintLocator.h(163): error C2100: illegal indirection

@etcwilde
Copy link
Member Author

etcwilde commented Apr 1, 2022

@swift-ci please test Windows

@etcwilde
Copy link
Member Author

etcwilde commented Apr 1, 2022

@swift-ci please test

@@ -50,6 +51,8 @@ namespace swift {
class ConstraintSystem;
class Solution;
class SolutionApplicationTarget;
enum class ConstraintSystemFlags;
Copy link
Member Author

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 {
           ^

@etcwilde
Copy link
Member Author

etcwilde commented Apr 1, 2022

@swift-ci please test Windows

@etcwilde
Copy link
Member Author

etcwilde commented Apr 1, 2022

@swift-ci please test

@etcwilde
Copy link
Member Author

etcwilde commented Apr 1, 2022

@swift-ci please test Windows

@etcwilde
Copy link
Member Author

etcwilde commented Apr 2, 2022

@swift-ci please test

@etcwilde
Copy link
Member Author

etcwilde commented Apr 2, 2022

@swift-ci please test Windows

@etcwilde
Copy link
Member Author

etcwilde commented Apr 2, 2022

#42150
@swift-ci please test Windows

etcwilde added 3 commits April 2, 2022 16:14
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`.
@etcwilde etcwilde force-pushed the ewilde/async-main-resolution branch from 47e310e to a427c05 Compare April 2, 2022 23:14
@etcwilde
Copy link
Member Author

etcwilde commented Apr 2, 2022

#42150
@swift-ci please test

@etcwilde etcwilde requested a review from xedin April 4, 2022 12:34
@etcwilde etcwilde merged commit 4494db9 into swiftlang:main Apr 4, 2022
@etcwilde etcwilde deleted the ewilde/async-main-resolution branch April 4, 2022 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants