Skip to content

[6.1] [rbi] Fix demangling of sending results when demangling impl-function-type #78666

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
Jan 30, 2025

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Jan 15, 2025

This change fixes the demangling of sending results in the non-ABI impl-function-type part of the mangling that is used during reabstraction thunk generation.

Swift's mangling is a postfix mangling. We treat impl-function-type's mangling character 'I' as an operator that takes the types for parameters, results, yields, error result as parameters to the operator. The implementation of the demangler assumed that as it parsed nodes that all nodes that it demangled from impl-function-type (e.x.: flags on the function, information about params/results) would always have nodes that needed to be paired with the typed arguments to the operator were always at the end in the same order as the arguments. The demangler would after parsing the actual impl-function-type walk backwards along the child node list and add the typed argument information to the child node.

With that information in hand, the bug that occurred here is that the flag for sending results was originally placed in between the parameter and result information in impl-function-type. This would cause the nodes that were supposed to become children of the result nodes to instead be placed on the sending result flag node. The fix was to take advantage of this not being ABI to just move the bit to before the param part of the mangling so this can no longer happen.

While doing this, I also discovered a few other places where we were missing support for sending results in the old demangler/remangler so I added some quick support there as well just in case.

Scope: Affects demangle paths where a reabstraction thunk is used to reabstract in some way a function with a sending result. We produce a correct mangling, but the actual demangling will produce a bogus demangling tree, so anything that relies on being able to demangle the reabstraction thunk will cause issues. Luckily reabstraction thunks are not exported symbols so nothing can rely in the wild on linking against such a demangled symbol.
Risk: Low
Testing: Added new demangling tests and also added the specific swift example that exposed the code
Issue: rdar://141962865
Reviewer: @rjmccall
Original PRs:
#78612
#78660
#78889

…}() propagates result options.

I discovered this while trying to figure out why we were dropping a sending bit
when computing a reabstraction thunk in the tests for the following commit. This
turned out to be the reason why.

(cherry picked from commit bd37998)
The issue here is that the demangler (since we have a postfix mangling) parses
parameters/results/etc and then uses earlier postfix type arguments to attach
the relevant types to the parameters/results/etc. Since the flag for a sending
result was placed in between the parameters and results, we get an off by one
error.

Rather than fix that specific issue by introducing an offset for the off by one
error, I used the fact that the impl-function part of the mangling is not ABI
and can be modified to move the bit used to signify a sending result to before
the parameters so the whole problem is avoided.

I also while I was doing this looked through the sending result mangling for any
further issues and fixed them as I found them.

rdar://141962865
(cherry picked from commit cb2d756)
(cherry picked from commit 9960079)
@gottesmm gottesmm requested a review from a team as a code owner January 15, 2025 22:44
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

Just for ease of reference the two main PRs:

#78612
#78660

@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm gottesmm changed the title [6.1] [rbi] Fix demangling of sending results. [6.1] [rbi] Fix demangling of sending results when detangling impl-function-type Jan 29, 2025
@gottesmm gottesmm changed the title [6.1] [rbi] Fix demangling of sending results when detangling impl-function-type [6.1] [rbi] Fix demangling of sending results when demangling impl-function-type Jan 29, 2025
@gottesmm
Copy link
Contributor Author

@rjmccall can I get a review again here?

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

Same patch as main, still LGTM

@gottesmm gottesmm merged commit 4420210 into swiftlang:release/6.1 Jan 30, 2025
5 checks passed
@gottesmm gottesmm deleted the release/6.1-rdar141962865 branch January 30, 2025 22:08
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.

3 participants