-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Mark float intrinsics with no preconditions as safe #146683
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
Conversation
cc @tgross35 Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter |
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
3cd0908
to
6e2a954
Compare
// fma is not yet available in `core` | ||
if #[cfg(intrinsics_enabled)] { | ||
unsafe{ core::intrinsics::$fma_intrinsic(self, y, z) } | ||
core::intrinsics::$fma_intrinsic(self, y, z) |
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 don't think it's possible to make this change separately, unfortunately. The best we could do is allow the lint for an unnecessary unsafe block, but that also would presumably require modifying the code within this crate, so, 🤷🏻
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.
Yeah there's no problem with this bit 👍
This comment has been minimized.
This comment has been minimized.
6e2a954
to
f4cd142
Compare
cc @Amanieu, @folkertdev, @sayantn |
- [f16, 'h_'] | ||
compose: | ||
- FnCall: [roundf16, [a], [], true] | ||
- FnCall: [roundf16, [a], []] |
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.
These also seem to be difficult/not possible to do separately from modifying the intrinsics, since they otherwise throw unnecessary unsafe blocks.
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.
Yeah this kind of change is exactly why we use subtrees instead of submodules :)
f4cd142
to
a5c7cdc
Compare
This comment has been minimized.
This comment has been minimized.
library/core/src/intrinsics/mod.rs
Outdated
pub const fn roundf128(x: f128) -> f128; | ||
|
||
/// Float addition that allows optimizations based on algebraic rules. | ||
/// May assume inputs are finite. |
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.
This line should really say
/// Safety: all inputs the result must be finite.
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.
We unfortunately haven't adopted a proper safety section convention for intrinsics since some of them became safe, but a lot of them mention UB directly as a keyword to search for, so, I reworded it to:
Requires that inputs are finite, and can cause UB otherwise.
Hopefully that's a bit clearer for now until someone wants to properly clean up all the intrinsic documentation.
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.
Inputs and output must be finite, as noted in my comment. (Though I typod it so it was probably hard to understand.)
Also, this will cause UB otherwise. "can" sounds like maybe it does, maybe it doesn't.
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.
How would the output potentially not be finite if the input is finite?
… I asked before realising the answer. Okay, fair. That definitely is worth pointing out.
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.
Finally got to this, new comment is:
Requires that both input and output of the operation are finite, causing UB otherwise.
This also got me curious whether the remainder of division by zero was finite by some weird chance, and it's NaN, so, this should be sufficient for all cases. (If it were something weird like rem-0 = 0, then I would have had to specify for remainder specifically that the division also has to be finite, but it's okay here, I think.)
a5c7cdc
to
36b2e8c
Compare
This comment has been minimized.
This comment has been minimized.
36b2e8c
to
876ebe1
Compare
The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
876ebe1
to
269b547
Compare
This comment has been minimized.
This comment has been minimized.
5bc75f8
to
5b43b5e
Compare
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.
r=me on the intrinsic changes. I don't know stdarch well enough to comment on the diff there. @Amanieu could you take a look?
library/core/src/intrinsics/mod.rs
Outdated
|
||
/// Float addition that allows optimizations based on algebraic rules. | ||
/// May assume inputs are finite. | ||
/// Requires that both input and output of the operation are finite, causing UB otherwise. |
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.
Should probably say "inputs" since there is more than one
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.
Fair, now says "inputs and output" instead of "both input and output" so it's a bit clearer
LGTM on the stdarch side, this is just removing some unnecessary unsafe blocks. |
5b43b5e
to
7f207f4
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
@bors retry curl: (35) Recv failure: Connection was reset |
Fwiw when this came up before, a concern was raised about whether linkers must raise an error when symbols aren't found. Discussion starting around #t-libs > Different Safety Levels of the Same API in Intrinsic and std @ 💬. I don't really think that's something we should be worried about here though. |
☀️ Test successful - checks-actions |
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing 29005cb (parent) -> ce4beeb (this PR) Test differencesShow 182 test diffs182 doctest diffs were found. These are ignored, as they are noisy. Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard ce4beebecb77821734079cff47d8af08f9f27f11 --output-dir test-dashboard And then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
Finished benchmarking commit (ce4beeb): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 0.6%, secondary 0.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 472.389s -> 472.191s (-0.04%) |
…alfJung Make missed precondition-free float intrinsics safe So, in my defence, these were both separated out from the other intrinsics in the file *and* had a different safety comment in the stable versions, so, I didn't notice them before. But, in my offence, the entire reason I did the previous PR was because I was using them for SIMD intrinsic fallbacks, and `fabs` is needed for those too, so, I don't really have an excuse. Extra follow-up to rust-lang#146683. r? `@RalfJung` who reviewed the previous one These don't appear to be used anywhere outside of the standard locations, at least.
…ung,Amanieu Mark float intrinsics with no preconditions as safe Note: for ease of reviewing, the list of safe intrinsics is sorted in the first commit, and then safe intrinsics are added in the second commit. All *recently added* float intrinsics have been correctly marked as safe to call due to the fact that they have no preconditions. This adds the remaining float intrinsics which are safe to call to the safe intrinsic list, and removes the unsafe blocks around their calls. --- Side note: this may want a try run before being added to the queue, since I'm not sure if there's any tier-2 code that uses these intrinsics that might not be tested on the usual PR flow. We've already uncovered a few places in subtrees that do this, and it's worth double-checking before clogging up the queue.
…alfJung Make missed precondition-free float intrinsics safe So, in my defence, these were both separated out from the other intrinsics in the file *and* had a different safety comment in the stable versions, so, I didn't notice them before. But, in my offence, the entire reason I did the previous PR was because I was using them for SIMD intrinsic fallbacks, and `fabs` is needed for those too, so, I don't really have an excuse. Extra follow-up to rust-lang#146683. r? ``@RalfJung`` who reviewed the previous one These don't appear to be used anywhere outside of the standard locations, at least.
…alfJung Make missed precondition-free float intrinsics safe So, in my defence, these were both separated out from the other intrinsics in the file *and* had a different safety comment in the stable versions, so, I didn't notice them before. But, in my offence, the entire reason I did the previous PR was because I was using them for SIMD intrinsic fallbacks, and `fabs` is needed for those too, so, I don't really have an excuse. Extra follow-up to rust-lang#146683. r? ```@RalfJung``` who reviewed the previous one These don't appear to be used anywhere outside of the standard locations, at least.
Rollup merge of #146915 - clarfonthey:safe-intrinsics-2, r=RalfJung Make missed precondition-free float intrinsics safe So, in my defence, these were both separated out from the other intrinsics in the file *and* had a different safety comment in the stable versions, so, I didn't notice them before. But, in my offence, the entire reason I did the previous PR was because I was using them for SIMD intrinsic fallbacks, and `fabs` is needed for those too, so, I don't really have an excuse. Extra follow-up to #146683. r? ```@RalfJung``` who reviewed the previous one These don't appear to be used anywhere outside of the standard locations, at least.
Note: for ease of reviewing, the list of safe intrinsics is sorted in the first commit, and then safe intrinsics are added in the second commit.
All recently added float intrinsics have been correctly marked as safe to call due to the fact that they have no preconditions. This adds the remaining float intrinsics which are safe to call to the safe intrinsic list, and removes the unsafe blocks around their calls.
Side note: this may want a try run before being added to the queue, since I'm not sure if there's any tier-2 code that uses these intrinsics that might not be tested on the usual PR flow. We've already uncovered a few places in subtrees that do this, and it's worth double-checking before clogging up the queue.