Fix missed embedded-payload niche enum optimization (size enums) - #2
Open
LusterSourav wants to merge 1 commit into
Open
Fix missed embedded-payload niche enum optimization (size enums)#2LusterSourav wants to merge 1 commit into
LusterSourav wants to merge 1 commit into
Conversation
When the last variant of a niche-encoded enum has exactly one scalar
field at offset 0, its payload can be stored in the otherwise unused
tag bits, shrinking enums such as:
enum Unwind { Terminate(Reason), Cleanup(BasicBlock) }
from 8 bytes to 4 bytes.
`TagEncoding::Niche` gains `embedded_payload: Option<(VariantIdx, u128)>`
recording the embedded variant and how many distinct payload values fit
in the tag. The stable rustc_public mirror carries the same field so
serialized layouts round-trip. All existing consumers only pattern-match
the tag encoding with `..`.
Fixes rust-lang#160054.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes rust-lang#160054. An enum whose last niche variant has a single scalar payload field at offset 0 can store that payload in the tag's remaining bits.
embedded_payload: Option<(VariantIdx, u128)>torustc_abi::TagEncoding::Nicheall_variants_fitskips the embedded variant's own layout; tag =niche_start + (i - start) + payloadrustc_publicso serialized layouts stay stableNichematches to..(const_eval, codegen_ssa, cranelift, llvm debuginfo, ty_utils, ty::layout)enum Unwind { Terminate(Reason), Cleanup(BasicBlock) }now 4 bytes (was 8), niche_start 0xFFFF_FF01, embedded_payload Some((2,2))Local: rustc_abi full test suite passes (incl. embedded_payload_niche_layout). LLVM/Cranelift paths covered by CI.