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

Add -C hint-mostly-unused option #829

Open
1 of 3 tasks
joshtriplett opened this issue Jan 17, 2025 · 3 comments
Open
1 of 3 tasks

Add -C hint-mostly-unused option #829

joshtriplett opened this issue Jan 17, 2025 · 3 comments
Labels
major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@joshtriplett
Copy link
Member

joshtriplett commented Jan 17, 2025

Proposal

Some libraries are extremely large, and users use only a small fraction of their surface area. Crate features aren't ideal for just reducing the size of a very large library; that would require the crate maintainer to predict and provide semantic subsets that people will use, and commit to maintaining those subsets indefinitely as a stable API. That also doesn't scale well to crates with thousands of functions or structures; having thousands of features is a problem for maintenance, and for usability (carefully enabling the needed subset).

Introduce an option, -C hint-mostly-unused, which hints to rustc that most of a crate's API surface area may go unused.

Currently, this will make a crate provide all its code as MIR, to be compiled only when referenced. This functionality already exists as -Zcross-crate-inline-threshold=always. I'm proposing to provide a stable hint option to access the same underlying functionality.

I've tested this on some crates with very large dependencies. On one project, adding this option to just the three largest dependencies reduced total compilation time from 10m30s to 6m12s.

(No attachment to the specific option name, happy to change it.)

I also intend to propose a corresponding option in Cargo, which can be enabled on a per-dependency basis. (And, later, we can add a way for large crates to hint that they should have this option enabled by default unless overridden.)

Inspired by @saethlin's MIR-only rlibs work at rust-lang/rust#119017 .

Notes

  • Need to make sure this does not override #[inline(never)].
  • The new option will need documentation.
  • This shouldn't be applied to the entire crate graph; it should be applied selectively. The documentation should provide guidance on when it may provide benefit.

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.

@joshtriplett joshtriplett added major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team labels Jan 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 17, 2025

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.

Concerns or objections to the proposal should be discussed on Zulip and formally registered here by adding a comment with the following syntax:

@rfcbot concern reason-for-concern 
<description of the concern> 

Concerns can be lifted with:

@rfcbot resolve reason-for-concern 

See documentation at https://forge.rust-lang.org

cc @rust-lang/compiler

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Jan 17, 2025
@joshtriplett joshtriplett changed the title Add -C defer-codegen option Add -C hint-mostly-unused option Jan 17, 2025
@joshtriplett
Copy link
Member Author

Implementation at rust-lang/rust#135656

@saethlin
Copy link
Member

@rfcbot concern prior-art-does-not-motivate-fast-stabilization
The proposal here is to land this as a -C flag, partly motivated by the fact that it is basically just -Zcross-crate-inline-threshold=always which has existed for some time. But the reference flag has basically no documentation and as far as I can tell from discussion on Zulip is not well-understood, so I do not think its existence is sufficient to motivate anything beyond our usual treatment of flags: Land them as -Z then stabilize by changing them to -C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants