Proposal
Implement compiler support for alignment and size niches, as outlined in RFC 3204. This does not propose adding the RFC's WellFormed<T> type to std; only &T and &mut T are eligible for now.
The rough plan is:
- Add a new
naive_layout_of query (this was named min_layout_of in the RFC) that can be used to (under)estimate the size/align of a type behind an indirection without causing unwanted query cycles;
- Fix the various places in the compiler assuming references and pointers only ever have null niches:
- the niching logic in
rustc_abi (to maintain the null-pointer optimization guarantee in the presence of non-null niches);
- scalar checks in CTFE;
- some checks in the
improper_ctypes lint;
SizeSkeleton logic for transmute checks;
Ty::ty_and_layout_pointee_info_at;
- probably others I missed...
- Enable niches for references (maybe behind some unstable
-Z flag), using the size and alignment estimations provided by naive_layout_of.
Mentors or Reviewers
I already have a draft implementation of the naive_layout_of query (which I'll make into a PR once it's cleaned up), and got some good advice from @scottmcm (and others) on the Rust Discord server; but this is my first contribution to the rustc codebase and mentoring help for the trickier changes would be greatly appreciated.
Process
The main points of the Major Change Process are as follows:
You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
Proposal
Implement compiler support for alignment and size niches, as outlined in RFC 3204. This does not propose adding the RFC's
WellFormed<T>type tostd; only&Tand&mut Tare eligible for now.The rough plan is:
naive_layout_ofquery (this was namedmin_layout_ofin the RFC) that can be used to (under)estimate the size/align of a type behind an indirection without causing unwanted query cycles;rustc_abi(to maintain the null-pointer optimization guarantee in the presence of non-null niches);improper_ctypeslint;SizeSkeletonlogic for transmute checks;Ty::ty_and_layout_pointee_info_at;-Zflag), using the size and alignment estimations provided bynaive_layout_of.Mentors or Reviewers
I already have a draft implementation of the
naive_layout_ofquery (which I'll make into a PR once it's cleaned up), and got some good advice from @scottmcm (and others) on the Rust Discord server; but this is my first contribution to therustccodebase and mentoring help for the trickier changes would be greatly appreciated.Process
The main points of the Major Change Process are as follows:
@rustbot second.-C flag, then full team check-off is required.@rfcbot fcp mergeon either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.