rust-lang / rust-lang/rust-bindgen
Compute padding outside of codegen
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Right now, we compute a struct's padding fields while we are codegen'ing it.
Instead, we should have a dedicated phase for computing implicit padding fields that transforms from structs-with-only-explicit-fields to structs-with-explicit-fields-and-implicit-padding-fields.
Benefits this will give us:
-
The ability to precisely derive various traits for structs with large alignment (right now we are conservatively pessimistic). See for example https://github.com/rust-lang-nursery/rust-bindgen/blob/b13f0766e28cf75dd04f358bf64d87ea96b111c3/src/ir/analysis/derive_debug.rs#L160-L170
-
Separation of concerns, simpler code
This new phase should probably happen either right before or right after we compute allocation units for bitfields. I'm not 100% sure which, and determining it requires further investigation/experimentation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing where struct padding is computed during code generation and where bitfield allocation units are computed. Read src/ir/analysis/derive_debug.rs, especially the referenced trait-derivation logic, and investigate whether the new padding phase belongs before or after bitfield allocation. Done means structs are transformed to include implicit padding before later analyses can derive precise traits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100