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

Use #[rustc_inherit_overflow_checks] instead of Add::add etc. #81732

Merged
merged 1 commit into from
Feb 22, 2021

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Feb 3, 2021

See #81721

@m-ou-se m-ou-se added the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label Feb 3, 2021
@rust-log-analyzer

This comment has been minimized.

@m-ou-se m-ou-se force-pushed the inherit-overflow-checks branch from 96cc6e5 to 721e9b7 Compare February 3, 2021 23:25
@rust-log-analyzer

This comment has been minimized.

@m-ou-se m-ou-se force-pushed the inherit-overflow-checks branch from 721e9b7 to bd1eb21 Compare February 3, 2021 23:28
@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 3, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 3, 2021
@bors
Copy link
Contributor

bors commented Feb 3, 2021

⌛ Trying commit bd1eb210f1636b4e69055bc37b1a5b118a2fed26 with merge 373cca1b4f95bdf0298d4add9943f805161c8c87...

#[rustc_inherit_overflow_checks]
|a, b| a + b,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, does this work? I half-expected it not to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, this was your suggestion.. But yeah, it compiles. I think it works too, but I should check if it actually gets tested for this behaviour. :)

Copy link
Member

@eddyb eddyb Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was going off having seen #[inline(never)], IIRC, on closures, but I wasn't sure it would work out of the box.

@bors
Copy link
Contributor

bors commented Feb 4, 2021

☀️ Try build successful - checks-actions
Build commit: 373cca1b4f95bdf0298d4add9943f805161c8c87 (373cca1b4f95bdf0298d4add9943f805161c8c87)

@rust-timer
Copy link
Collaborator

Queued 373cca1b4f95bdf0298d4add9943f805161c8c87 with parent e708cbd, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (373cca1b4f95bdf0298d4add9943f805161c8c87): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 4, 2021
@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 5, 2021

Okay this looks good, no regression in performance, and even a few percent improvement for cranelift.

To do: Verify that it actually works the same as before. I'm not sure if we test all these cases for ther release/debug-mode panic behaviour.

@m-ou-se m-ou-se added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Feb 14, 2021
@m-ou-se m-ou-se self-assigned this Feb 14, 2021
@m-ou-se m-ou-se force-pushed the inherit-overflow-checks branch from bd1eb21 to 053769d Compare February 14, 2021 22:06
@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 14, 2021

To do: Verify that it actually works the same as before. I'm not sure if we test all these cases for ther release/debug-mode panic behaviour.

Manually verified that it behaves the same. Looks like there's also already tests for these in src/test/ui/iterators/iter-*-overflow-debug.rs.

@m-ou-se m-ou-se marked this pull request as ready for review February 14, 2021 22:10
@m-ou-se m-ou-se removed the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label Feb 14, 2021
@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 14, 2021

r? @Mark-Simulacrum

iter.fold($zero, Add::add)
iter.fold(
$zero,
#[rustc_inherit_overflow_checks]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, so I initially thought "this seems wrong, don't we need it on the fn sum too? But it looks like in practice inherit is a bit wrong - this attribute just forces the MIR to contain overflow checks in all cases, and then when we codegen (potentially in a downstream crate) they'll get removed. So I think we're good -- not sure what a better name for the attribute is, but inherit definitely feels a bit off.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the inherit here is about crates rather than functions, in some sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, "inherit" refers to the crate it's codegen'd in. So it's more "defer"? Or we can go more explicit really:

#[rustc_use_overflow_checks_settings_from_user_crate]

We could also make the attribute warn/error if building the MIR doesn't end up making a decision based on it, because that's what usually happens if it's applied to the wrong thing (e.g. a function doing iter.fold(...) instead of a closure).

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 20, 2021

📌 Commit 053769d has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 20, 2021
@bors
Copy link
Contributor

bors commented Feb 22, 2021

⌛ Testing commit 053769d with merge e952db8...

@bors
Copy link
Contributor

bors commented Feb 22, 2021

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing e952db8 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants