-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[PrintAsClang] Fix thunks for Never funcs #72402
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
Conversation
@swift-ci please test |
@hyp If you're still available, it sounds like you're the best person to review changes to this part of the compiler. |
if (isResultType && Count == 0) { | ||
// A direct result with no record members can happen for uninhabited result | ||
// types like `Never`. | ||
os << "void"; |
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.
When I was working on this PR, I noticed that IRGen represents Never
return types as having one empty-tuple direct result, rather than as having no direct result. (This previously tripped an assert.) I'm assuming that this is correct, or at least that changing it would break the ABI, and that a void
return with swiftcall
is the correct prototype to use to call such a function from C++.
I'd love to get confirmation from someone who works on IRGen (maybe @aschwaighofer or @rjmccall?) that this is the right approach.
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.
Thanks!
@swift-ci please test |
1 similar comment
@swift-ci please test |
Swift-to-C++ thunk printing for functions didn’t really take into account Swift’s `Never` type. This type maps to `SWIFT_NORETURN`, but it also requires other tweaks to code generation, such as omitting the `return` keyword. (Removing that requires minor changes to many tests.) Fixes rdar://124137073.
Extend the previous commit’s support for functions that return Never to also properly generate code for *throwing* Never functions. This is a little subtle because: • At the SWIFT_CALL level, throwing Never functions are *not* noreturn • At the thunk level, throwing Never functions are noreturn *only* if you’re using exceptions; if you’re using swift::Expected, they should throw • In either case, the compiler cannot statically prove that thunks are noreturn except on the error path, so we need to add an abort() call on the success path
`simctl spawn` does not propagate exit codes through, so we need the test to exit using `exit(0)`, not `fatalError()`.
3ec1190
to
fa2ebd9
Compare
@swift-ci please test |
Swift-to-C++ thunk printing for functions didn’t really take into account Swift’s
Never
type. This type maps to avoid
return with theSWIFT_NORETURN
attribute, but it also requires other tweaks to code generation, such as omitting thereturn
keyword. (Removing that requires minor changes to many tests.)This PR also contains a follow-up fix for throwing
Never
functions, which have a number of subtleties.Fixes rdar://124137073.