Skip to content

🌸 [PrintAsClang] Fix thunks for Never funcs #72751

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 3 commits into from
Apr 2, 2024

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Apr 1, 2024

  • Explanation: Swift-to-C++ thunk printing did not correctly handle Never return types. This PR adds support for both non-throwing and throwing functions that return Never.
  • Scope: Affects projects that expose a Never-returning function to C++. Swift currently prints C++ code with extra return statements that do not compile.
  • Issue: rdar://124137073
  • Original PR: [PrintAsClang] Fix thunks for Never funcs  #72402
  • Risk: Very low. The affected functions currently aren't compiling at all.
  • Testing: Unit tests are included.
  • Reviewer: @hyp

beccadax added 3 commits April 1, 2024 14:55
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()`.
@beccadax beccadax added the 🍒 release cherry pick Flag: Release branch cherry picks label Apr 1, 2024
@beccadax beccadax requested a review from a team as a code owner April 1, 2024 22:49
@beccadax
Copy link
Contributor Author

beccadax commented Apr 1, 2024

@swift-ci test

@nkcsgexi
Copy link
Contributor

nkcsgexi commented Apr 1, 2024

@swift-ci test

@beccadax beccadax merged commit e2696ad into swiftlang:release/6.0 Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants