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

Dist rustc with overflow checks #724

Closed
1 of 3 tasks
Noratrieb opened this issue Feb 15, 2024 · 3 comments
Closed
1 of 3 tasks

Dist rustc with overflow checks #724

Noratrieb opened this issue Feb 15, 2024 · 3 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@Noratrieb
Copy link
Member

Proposal

Integer overflows are not good (citation needed). They haven't caused us huge trouble in the past, but we also haven't turned on the lights for our users, so maybe people are hitting them all the time in the dark (this seems a bit unlikely) but even if they aren't there is a clear benefit in preventing bugs. Especially as an overflow could result in some quite bad bugs (I don't think this has happened before, but could always happen).

Examples of previous (not that bad) integer overflow bugs: rust-lang/rust#104352 rust-lang/rust#119497.
I've also done a crater run of overflow checks recently and they were similarly uninteresting, only finding one of the bugs above: https://crater-reports.s3.amazonaws.com/pr-119440-1/index.html

This motivation seems solid but a bit weak. Let's look whether it holds up against the downsides.

But nils, won't this make the compiler slow and undo all of the awesome hard work people have done to speed up the compiler ( ❤️ to them) ?

Glad you asked! So did I. I'm not a benchmark suite, so asked rustc-perf instead. Many significant icount regression, few significant cycle regressions. Cachegrind revealed that it was mostly just checks in a few hot functions like siphash, so I removed their checks and tried again, now with mostly sub 1% icount regressions and no significant cycle count or wall time regressions.

rustc-perf did say ACTION NEEDED on the perf report so I'm doing the action of proposing to merge this.

Note that this also increases librustc_driver.so binary size by 3%. It's the only downside I see, which is not very big (literally) but also not awesome of course.

The icount regressions are large, but I have no reason to trust them to be useful. We use icounts as the primary metrics because they're a very not-noisy mostly decent-for-the-average-perf-change metric, but here they're pretty bad, since they penalize well-predicted branches (which this is, unless we start having a large number of overflows :D). So I don't really care about them, cycles are more revealing, and they don't say anything, and I'm interpreting their silence as an approval.

Another slight downside is that it probably does make sense to remove the checks from the hot code, which makes the code a bit uglier as it requires using explicit methods (I used wrapping in my PR, but it probably makes sense to have some sort of "overflow checks when debug_assertions are enabled" method) for them. It might also require care about this in the future if any very hot integer arithmetic is added and it might be non-obvious to contributors that their integer operations are being overflow checked.

One open question is the scope of this. We certainly don't want to do it for the standard library as well in this proposal (as for integer heavy code, there certainly is a perf impact). Doing it for all tooling sounds fine to me too, as the tooling probably also has the same perf effect (rustdoc is benched as well thanks to perf) but we may want to ask the teams too. This MCP is mostly about librustc_driver.so, but I'd imagine other teams may be interested as well.

I collected the data for this in rust-lang/rust#119440

Mentors or Reviewers

anyone ought to be brave enough to review this minor config change

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.

@Noratrieb Noratrieb added T-compiler Add this label so rfcbot knows to poll the compiler team major-change A proposal to make a major change to rustc labels Feb 15, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 15, 2024

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:

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

Concerns can be lifted with:

@rustbot resolve reason-for-concern 

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

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

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Feb 15, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Feb 22, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Mar 14, 2024

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Mar 14, 2024
@apiraino
Copy link
Contributor

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

@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Mar 26, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Apr 4, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 13, 2024
…esleywiser

Add add/sub methods that only panic with debug assertions to rustc

This mitigates the perf impact of enabling overflow checks on rustc. The change to use overflow checks will be done in a later PR.

For rust-lang/compiler-team#724, based on data gathered in rust-lang#119440.
RalfJung pushed a commit to RalfJung/miri that referenced this issue Apr 15, 2024
Add add/sub methods that only panic with debug assertions to rustc

This mitigates the perf impact of enabling overflow checks on rustc. The change to use overflow checks will be done in a later PR.

For rust-lang/compiler-team#724, based on data gathered in #119440.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 20, 2024
Add add/sub methods that only panic with debug assertions to rustc

This mitigates the perf impact of enabling overflow checks on rustc. The change to use overflow checks will be done in a later PR.

For rust-lang/compiler-team#724, based on data gathered in #119440.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Add add/sub methods that only panic with debug assertions to rustc

This mitigates the perf impact of enabling overflow checks on rustc. The change to use overflow checks will be done in a later PR.

For rust-lang/compiler-team#724, based on data gathered in #119440.
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 major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants