Skip to content
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

Let indirect enum cases export spare bits #77062

Merged
merged 3 commits into from
Jan 25, 2025

Conversation

tbkka
Copy link
Contributor

@tbkka tbkka commented Oct 17, 2024

To determine the correct enum layout, we first count various categories of cases. Before, we counted indirect generic cases as "generic", but regular "generic" cases can't export spare bits.

Change this to count "indirect" cases as a separate category. In particular, this ensures that fully-indirect enums use spare bits from the pointers even when some or all of the cases are generic.

Edited: A better approach is to treat indirect cases as non-generic & non-empty. Non-empty should be obvious. Non-generic because this code uses "generic" as a flag for whether to consider spare bits -- generic cases never export spare bits. Indirect cases always do, because of the pointer.

Resolves rdar://133890406

To determine the correct enum layout, we first count various
categories of cases.  Before, we counted indirect generic cases as
"generic", but regular "generic" cases can't export spare bits.

Change this to count "indirect" cases as a separate category.
In particular, this ensures that fully-indirect enums use
spare bits from the pointers even when some or all of the cases
are generic.

Resolves rdar://133890406
@tbkka tbkka requested review from slavapestov and a team as code owners October 17, 2024 01:45
@tbkka
Copy link
Contributor Author

tbkka commented Oct 17, 2024

@swift-ci Please test

Copy link
Contributor

@drexin drexin left a comment

Choose a reason for hiding this comment

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

LGTM

tbkka added 2 commits October 17, 2024 08:49
…c indirect vs. non-generic indirect.

Counting indirect cases as regular non-empty cases is a better fit.
// CHECK64-NEXT: (class_instance size=24 alignment=8 stride=24 num_extra_inhabitants=0 bitwise_takable=1
// CHECK64-NEXT: (field name=outer offset=16
// x86_64 and arm64 have different spare bit pointer masks, hence different numbers of extra inhabitants here
// CHECK64-NEXT: (multi_payload_enum size=8 alignment=8 stride=8 num_extra_inhabitants={{[0-9]+}} bitwise_takable=1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

More trivia.

@tbkka
Copy link
Contributor Author

tbkka commented Oct 17, 2024

@swift-ci Please test

@augusto2112
Copy link
Contributor

@swift-ci smoke test

@tbkka
Copy link
Contributor Author

tbkka commented Oct 17, 2024

@augusto2112 -- These changes need a full test, not just a smoke test, since the reflection tests are all under "validation-test" which isn't run for a smoke test.

@augusto2112
Copy link
Contributor

@tbkka I think you need to run smoke test to merge anyway, which is why I ran it :)

@drexin
Copy link
Contributor

drexin commented Oct 17, 2024

@augusto2112 A full test run will clear the smoke test check as well, so no need to run both.

@augusto2112
Copy link
Contributor

@drexin oh cool, I didn't know that, I always thought you needed to run both

@tbkka tbkka marked this pull request as draft January 24, 2025 23:07
@tbkka
Copy link
Contributor Author

tbkka commented Jan 24, 2025

Determining whether a particular case is "generic" is a lot more complex than this credits. Need to rethink the whole approach here.

@tbkka tbkka marked this pull request as ready for review January 24, 2025 23:57
@tbkka
Copy link
Contributor Author

tbkka commented Jan 24, 2025

On further consideration: This isn't a complete solution, since "generic" needs more work, but it does solve this specific case well enough to be landed.

@tbkka
Copy link
Contributor Author

tbkka commented Jan 24, 2025

@swift-ci Please test

@tbkka tbkka enabled auto-merge January 24, 2025 23:58
@tbkka tbkka merged commit 674c762 into swiftlang:main Jan 25, 2025
4 of 5 checks passed
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.

4 participants