Skip to content

Implement alignment and size niches for references #641

@moulins

Description

@moulins

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:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

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.

Activity

added
major-changeA proposal to make a major change to rustc
T-compilerAdd this label so rfcbot knows to poll the compiler team
on Jun 22, 2023
rustbot

rustbot commented on Jun 22, 2023

@rustbot
Collaborator

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.

cc @rust-lang/compiler @rust-lang/compiler-contributors

oli-obk

oli-obk commented on Jun 23, 2023

@oli-obk
Contributor

@rustbot second

added
final-comment-periodThe FCP has started, most (if not all) team members are in agreement
on Jun 23, 2023
added a commit that references this issue on Jul 21, 2023
apiraino

apiraino commented on Jul 26, 2023

@apiraino
Contributor

@rustbot label -final-comment-period +major-change-accepted

added
to-announceAnnounce this issue on triage meeting
and removed
final-comment-periodThe FCP has started, most (if not all) team members are in agreement
on Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teammajor-changeA proposal to make a major change to rustcmajor-change-acceptedA major change proposal that was accepted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @oli-obk@apiraino@moulins@rustbot

        Issue actions

          Implement alignment and size niches for references · Issue #641 · rust-lang/compiler-team