-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
fix unsoundness in Step::forward_unchecked for signed integers #122461
Conversation
This comment has been minimized.
This comment has been minimized.
ed3e39f
to
f0487c0
Compare
This comment has been minimized.
This comment has been minimized.
f0487c0
to
d3cab9f
Compare
The Miri subtree was changed cc @rust-lang/miri |
@@ -1 +1 @@ | |||
The loop took around 7s | |||
The loop took around 12s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test contains a loop over a range of unconstrained integer types which defaults to i32.
Aiui in miri "time" ticks based on the number of mir statements executed or something like that. Since the Range impl changed this also affects rate of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh this test again. We should probably do something a bit better here.
When isolation is enabled (the default), Miri doesn't have access to the system clock, so we use the end of a basic block as an extremely crude approximation of clock ticks, so that we can have a clock when isolation is enabled. This test asserts that the magic number for NANOSECONDS_PER_BASIC_BLOCK
gets us an isolation clock that's remotely close to the real passage of time. Because when we first did this I think it was off by a factor of 100.
This diff is fine for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still a bit surprised that the number of basic blocks is almost doubling?
@bors r+ |
…, r=Amanieu fix unsoundness in Step::forward_unchecked for signed integers Fixes rust-lang#122420 ```rust pub fn foo(a: i8, b: u8) -> i8 { unsafe { a.checked_add_unsigned(b).unwrap_unchecked() } } ``` still compiles down to a single arithmetic instruction ([godbolt](https://rust.godbolt.org/z/qsd3xYWfE)). But we may be losing some loop optimizations if llvm can no longer easily derive that it's a finite counted loop from the no-wrapping flags.
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#104353 (Add CStr::bytes iterator) - rust-lang#114038 (unix time module now return result) - rust-lang#119676 (rustdoc-search: search types by higher-order functions) - rust-lang#120699 (Document `TRACK_DIAGNOSTIC` calls.) - rust-lang#121899 (Document how removing a type's field can be bad and what to do instead) - rust-lang#121940 (Mention Register Size in `#[warn(asm_sub_register)]`) - rust-lang#122397 (Various cleanups around the const eval query providers) - rust-lang#122405 (Add methods to create StableMIR constant) - rust-lang#122416 (Various style improvements to `rustc_lint::levels`) - rust-lang#122440 (const-eval: organize and extend tests for required-consts) - rust-lang#122461 (fix unsoundness in Step::forward_unchecked for signed integers) r? `@ghost` `@rustbot` modify labels: rollup
…, r=Amanieu fix unsoundness in Step::forward_unchecked for signed integers Fixes rust-lang#122420 ```rust pub fn foo(a: i8, b: u8) -> i8 { unsafe { a.checked_add_unsigned(b).unwrap_unchecked() } } ``` still compiles down to a single arithmetic instruction ([godbolt](https://rust.godbolt.org/z/qsd3xYWfE)). But we may be losing some loop optimizations if llvm can no longer easily derive that it's a finite counted loop from the no-wrapping flags.
…, r=Amanieu fix unsoundness in Step::forward_unchecked for signed integers Fixes rust-lang#122420 ```rust pub fn foo(a: i8, b: u8) -> i8 { unsafe { a.checked_add_unsigned(b).unwrap_unchecked() } } ``` still compiles down to a single arithmetic instruction ([godbolt](https://rust.godbolt.org/z/qsd3xYWfE)). But we may be losing some loop optimizations if llvm can no longer easily derive that it's a finite counted loop from the no-wrapping flags.
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#104353 (Add CStr::bytes iterator) - rust-lang#119676 (rustdoc-search: search types by higher-order functions) - rust-lang#120699 (Document `TRACK_DIAGNOSTIC` calls.) - rust-lang#121899 (Document how removing a type's field can be bad and what to do instead) - rust-lang#122405 (Add methods to create StableMIR constant) - rust-lang#122416 (Various style improvements to `rustc_lint::levels`) - rust-lang#122421 (Improve `Step` docs) - rust-lang#122440 (const-eval: organize and extend tests for required-consts) - rust-lang#122461 (fix unsoundness in Step::forward_unchecked for signed integers) Failed merges: - rust-lang#122397 (Various cleanups around the const eval query providers) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#122461 - the8472:fix-step-forward-unchecked, r=Amanieu fix unsoundness in Step::forward_unchecked for signed integers Fixes rust-lang#122420 ```rust pub fn foo(a: i8, b: u8) -> i8 { unsafe { a.checked_add_unsigned(b).unwrap_unchecked() } } ``` still compiles down to a single arithmetic instruction ([godbolt](https://rust.godbolt.org/z/qsd3xYWfE)). But we may be losing some loop optimizations if llvm can no longer easily derive that it's a finite counted loop from the no-wrapping flags.
Fixes #122420
still compiles down to a single arithmetic instruction (godbolt).
But we may be losing some loop optimizations if llvm can no longer easily derive that it's a finite counted loop from the no-wrapping flags.