-
Notifications
You must be signed in to change notification settings - Fork 13.3k
miri: fail when calling a function that requires an unavailable target feature #113720
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
r? @fee1-dead (rustbot has picked a reviewer for you, use r? to override) |
The Miri subtree was changed cc @rust-lang/miri Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
#113684 accidentally got merged due to a glitch in bors. We had to force push it away. It seems that you based this PR on the state of the repo when that PR was still merged. Could you please rebase and drop these commits? |
This comment has been minimized.
This comment has been minimized.
Done. Out of curiosity, why force pushing away those commits instead of reverting them? |
We could check this during const eval, too. On the miri side: are you worried this could cause real code to fail under miri, so you added an opt out flag for them to keep their miri tests passing and having time to fix their UB? |
I agree that it would make sense, but wouldn't it be a breaking change?
I mainly added it because there are already flags to disable other soundness checks, so I thought we would want one for this too. |
It's very unlikely anyone created const fns that also have target features. It's not like you could use the target features. And it's UB that you are catching, so we are allowed to break it. Wrt the flag, i'll let the other miri folk chime in on this, but I don't see the point of a flag for this one. |
I agree, we don't need a flag here. If someone complains that the check is annoying and they'd like to turn it off we can add one but I'd prefer we not add features (especially unsound ones), unless there's a well-known use case or a request for it. (I would actually prefer that we lose some of these |
…t feature miri will report an UB when calling a function that has a `#[target_feature(enable = ...)]` attribute is called and the required feature is not available. "Available features" are the same that `is_x86_feature_detected!` (or equivalent) reports to be available during miri execution (which can be enabled or disabled with the `-C target-feature` flag).
Removing the flag and checking unconditionally, then. |
Please also add a test of a sound and an unsound usage during const eval |
I am having trouble running compiletests locally.
There is some |
I added the tests and pushed without running the full test suite. |
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 looks great, thanks. :) Just some nits.
.iter() | ||
.copied() | ||
.filter(|feature| !self.tcx.sess.target_features.contains(feature)) | ||
.collect(); |
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 get measurable perf changes when avoiding allocations in this function. So we should not create a new Vec
here each time. Why do we need to manifest this list anyway? We just need to iterate over it and check if any of them is not in target_features
.
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 did not expect such impact from collect
ing into an empty Vec
, so I will avoid it.
* Split into its own function * Do not build a `Vec` of unavailable features
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit ae2a72d with merge 3ecfbdaab0a5f6c3fefde8060dde9ddd54f92a18... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (3ecfbdaab0a5f6c3fefde8060dde9ddd54f92a18): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
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: 658.073s -> 659.039s (0.15%) |
@bors r=RalfJung,oli-obk |
☀️ Test successful - checks-actions |
Finished benchmarking commit (1787f31): 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)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
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: 657.794s -> 657.068s (-0.11%) |
miri will report an UB when calling a function that has a
#[target_feature(enable = ...)]
attribute is called and the required feature is not available."Available features" are the same that
is_x86_feature_detected!
(or equivalent) reports to be available during miri execution (which can be enabled or disabled with the-C target-feature
flag).