Skip to content

[6.0] Compute spare bit mask from first principles #73624

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 2 commits into from
May 17, 2024

Conversation

tbkka
Copy link
Contributor

@tbkka tbkka commented May 14, 2024

Description: This overhauls the spare bit mask calculation to cover a range of enum cases as well. This allows RemoteMirror to accurately project at least some multi-payload enums without relying on any additional data from the compiler.

Risk: This library is used by LLDB and other tools; the new code may be overly optimistic and claim to support enums that it does not actually understand, leading these tools to present incorrect information. In particular, we know that some resilient enums will be incorrectly projected by this code, since resilience (which is generally known only within the compiler) causes some enums to not use spare bits when this code thinks they will.

Testing: New test cases and some ad hoc checking by @kastiglione to verify that this enables LLDB to print enums that it previously could not.

Original PR: #73491

Reviewed By: TBD

Resolves: rdar://127613238

Calculate spare bits for multi-payload enums from first principles

This adds a getSpareBits method to all the TypeInfo classes
that returns a suitable bitmask indicating the spare bits available
in values of this type. This gives us a way to recursively explore
the type tree and build up a full spare bit mask for an arbitrary type.

We mostly have enough information to do this calculation entirely from first
principles, without requiring additional reflection information. So once this is
stable, we should remove my earlier incomplete effort to publish spare bit mask
info in the reflection data, as that adds unnecessary metadata to every binary.

TODO: Resilience forces some enums to not use spare bits even though
they otherwise would be able to.  We should have the compiler add a single
bit to the reflectio data indicating whether or not spare bits were used
and then rely on this code to actually compute the spare bits.

This doubtless still has plenty of holes, but seems sufficient
to handle a few basic enum types, including the stdlib DecodingError
which was used as an example to work out some key issues.

Resolves rdar://126563813
@tbkka tbkka requested a review from a team as a code owner May 14, 2024 19:36
@tbkka
Copy link
Contributor Author

tbkka commented May 14, 2024

@swift-ci Please test

Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

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

LGTM. One little naming suggestion. I think I even understood it.

@tbkka
Copy link
Contributor Author

tbkka commented May 15, 2024

@swift-ci Please test

1 similar comment
@tbkka
Copy link
Contributor Author

tbkka commented May 15, 2024

@swift-ci Please test

@tbkka
Copy link
Contributor Author

tbkka commented May 16, 2024

@swift-ci Please test Linux Platform

@tbkka
Copy link
Contributor Author

tbkka commented May 16, 2024

@swift-ci Please test macOS Platform

@tbkka
Copy link
Contributor Author

tbkka commented May 17, 2024

@swift-ci Please test Linux Platform

@tbkka tbkka merged commit 5e12567 into swiftlang:release/6.0 May 17, 2024
5 checks passed
@tbkka tbkka deleted the tbkka-mpe-sparebits-6.0 branch August 1, 2024 16:38
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