-
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
target_feature 1.1 error should print the list of missing target features #108680
Comments
This seems like a nice first issue to me, I can mentor someone who would want to pick this up. Mentoring instructionsThe error originates from rust/compiler/rustc_mir_transform/src/check_unsafety.rs Lines 363 to 373 in 18caf88
The missing features should probably be added as additional context to The error is then emitted in rust/compiler/rustc_mir_transform/src/check_unsafety.rs Lines 557 to 611 in 18caf88
where it can be tweaked as required, through the usual @rustbot label: +E-easy +E-mentor |
@rustbot claim |
@LeSeulArtichaut Thank you for the opportunity! |
Basically, yes. Make sure to add it to both the hard error (in |
@rustbot claim |
For greater clarity, I have amended the issue description with a TLDR consisting of a list of the changes I'd like there to be. |
@est31 I'm trying to replicate the same error but I'm getting a different output when running the test. I already tried with different parameters but it's still the same. #![feature(target_feature_11)]
#[target_feature(enable = "sse2", enable = "avx", enable = "sse")]
pub fn foo() {}
#[target_feature(enable = "sse")]
fn bar() {
foo();
//~^ ERROR call to function with #[target_feature] is unsafe and requires unsafe function or block
}
fn main() {
bar();
} I'm getting this error messages
And with this file I'm getting the same #![feature(target_feature_11)]
#[target_feature(enable = "sse2", enable = "avx", enable = "sse")]
pub fn foo() {}
#[target_feature(enable = "sse")]
fn bar() {
foo();
//~^ ERROR call to function with #[target_feature] is unsafe and requires unsafe function or block
} Also, I have a question, I want to "print" some variables during the tests execution but it seems like I need to use |
@rohaquinlop sse, avx and sse2 are target features for the x86 target family, so likely you have a different target. Are you on an M1/M2? Maybe you could replace the target features with ones for aarch64 then? Example features are Given that The error message you quoted is definitely also improvement worthy. Something like " |
@est31 Ohhh I see, thank you, I'll continue working on it |
@est31 Once I solve this issue we could work on the error message that I was getting |
@est31 I'm having troubles trying to get the variables This is what I'm trying
But I'm getting the same Vec for both variables. So Basically I don't know how to get the |
@rohaquinlop you are passing it the same two def ids, you need the def id for the called function. You should modify the |
@est31 It's almost done, one thing that I don't understand well is the new note, how can I check which target-features were given in the build config? Here's how it's looking now.
Also, just for testing the output with the limit of 3 features in the
|
@rohaquinlop That's great progress already!
I think you could look for the feature in |
Make doc comment a little bit more accurate It queries not LLVM in particular but the codegen backend *in general*. While cranelift does not provide target features, other codegen backends do. Found while looking for [this answer](rust-lang#108680 (comment)).
@est31 I Think I found where is the target-feature stored when it's given through the build config which is in this variable I'm trying in this way, but it's not working, it gives me an error: |
What you gave tracks the command line flags given to rustc directly. That's not what we want: some target-features are enabled by default, and some might be enabled through other cli args like Regarding the second, you should add a comment like |
@est31 OMG! And I spent all the last days finding how to do it!!! 🤦🏾♂️ |
…tures, r=est31 Print list of missing target features when calling a function with target features outside an unsafe block Fixes rust-lang#108680 Supersedes rust-lang#109710. I used the same wording for the messages, but the implementation is different. r? `@est31`
…tures, r=est31 Print list of missing target features when calling a function with target features outside an unsafe block Fixes rust-lang#108680 Supersedes rust-lang#109710. I used the same wording for the messages, but the implementation is different. r? ``@est31``
Rollup merge of rust-lang#118333 - eduardosm:print-missing-target-features, r=est31 Print list of missing target features when calling a function with target features outside an unsafe block Fixes rust-lang#108680 Supersedes rust-lang#109710. I used the same wording for the messages, but the implementation is different. r? `@est31`
Given the following code:
The current output is:
The note is easy to be misinterpreted: the function can also be called if the target features are not available, but it requires an
unsafe
annotation.I think it would be nice for the note to list the missing target features. In this case, this would be
sse2
andavx
.If one or more of the missing target features are enabled in the current build config, like via
-C target-feature
or-C target-cpu
, or because the default is just that, then it should acknowledge this situation and explain that a#[target_feature]
is still required.So I'd imagine something like:
TLDR: I ask for two things:
note
in the general case (I think what it contains is already said in the main error msg), but if there are missing target features that are enabled in the build configuration, emit a note to point out that even though they are enabled, this has no influence on#[target_feature]
(it's two different systems; see my example for the proposed wording)help
that lists the missing target features (ideally if too many like more than 5 are missing, then cut the list to keep the error message short ("avx, sse2, sse, aes, foobar, and 3 more"))cc #69098
@rustbot label A-diagnostics F-target_feature_11
The text was updated successfully, but these errors were encountered: