You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
#[target_feature(enable = "simd128")] does not work properly on 1.73, but work fine on 1.72.1 #116516
Compiled it with cargo build --target=wasm32-unknown-unknown, I expected it to compile fine as on previous 1.72.1, but it gave me these errors:
$ cargo build --target=wasm32-unknown-unknown
Compiling regression_test v0.1.0 (C:\Users\123\Desktop\regression_test)
error[E0080]: evaluation of constant value failed
--> src\main.rs:5:20
|
5 | const FOO: v128 = i8x16(0, 1, -1, -1, -1, -1, -1, -1, 2, 3, -1, -1, -1, -1, -1, -1);| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a functionthat requires unavailable target features: simd128
note: erroneous constant used
--> src\main.rs:6:19
|
6 | println!("{:?}", FOO);| ^^^
note: erroneous constant used
--> src\main.rs:6:19
|
6 | println!("{:?}", FOO);| ^^^
|
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0080`.
error: could not compile `regression_test` (bin "regression_test") due to previous error
Version it worked on
It most recently worked on: 1.72.1
Output:
$ cargo build --target=wasm32-unknown-unknown
Compiling regression_test v0.1.0 (C:\Users\123\Desktop\regression_test)
Finished dev [unoptimized + debuginfo] target(s) in 0.13s
I read release notes for 1.73 and couldn't find anything that could be related to this, also tried to search for an existing issue about this - no luck. This issue also broke compilation of fast_image_resize crate and transitively, Fyrox game engine.
In principle we could probably silence this check on wasm, since we document wasm to be a target where calling functions with unsupported target features is safe.
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc{
// The `#[target_feature]` attribute is allowed on
// WebAssembly targets on all functions, including safe
// ones. Other targets require that `#[target_feature]` is
// only applied to unsafe functions (pending the
// `target_feature_11` feature) because on most targets
// execution of instructions that are not supported is
// considered undefined behavior. For WebAssembly which is a
// 100% safe target at execution time it's not possible to
// execute undefined instructions, and even if a future
// feature was added in some form for this it would be a
// deterministic trap. There is no undefined behavior when
// executing WebAssembly so `#[target_feature]` is allowed
// on safe functions (but again, only for WebAssembly)
//
// Note that this is also allowed if `actually_rustdoc` so
// if a target is documenting some wasm-specific code then
// it's not spuriously denied.
//
// This exception needs to be kept in sync with allowing
// `#[target_feature]` on `main` and `start`.
}elseif !tcx.features().target_feature_11{
letmut err = feature_err(
&tcx.sess.parse_sess,
sym::target_feature_11,
attr.span,
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
);
err.span_label(tcx.def_span(did),"not an `unsafe` function");
err.emit();
}else{
We should probably have the same exception in the target-feature check in the interpreter. @eduardosm do you have the time for a follow-up PR implementing that?
Activity
ehuss commentedon Oct 7, 2023
Bisected to #113720. cc @RalfJung
saethlin commentedon Oct 7, 2023
And then this was fixed by (or at least it started compiling since) #115580
RalfJung commentedon Oct 8, 2023
Hm, why does it think that the
i8x16function requires that target feature? That function doesn't have anytarget_featureattribute...Cc @eduardosm
RalfJung commentedon Oct 8, 2023
Ah, that's what changed in #115580 -- that attribute got removed from a bunch of functions.
This was changed in rust-lang/stdarch#1448. Cc @Amanieu
Amanieu commentedon Oct 8, 2023
That was changed in stdarch specifically in response to #113720, to avoid breaking users who were using the
const fnalready.RalfJung commentedon Oct 8, 2023
In principle we could probably silence this check on wasm, since we document wasm to be a target where calling functions with unsupported target features is safe.
eduardosm commentedon Oct 8, 2023
What happens in wasm when you call a function that requires an unavailable target feature?
RalfJung commentedon Oct 8, 2023
I am told that the wasm runtime will refuse to even load a module that contains invalid operations, so there are two options:
apiraino commentedon Oct 9, 2023
@mrDIMAS can you check on of the latest nightlies to verify if it works for you? (ref. comment)
RalfJung commentedon Oct 9, 2023
We have a special exception for wasm that allows target_feature functions to not be marked unsafe:
rust/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Lines 279 to 309 in 8fa7bdf
We should probably have the same exception in the target-feature check in the interpreter. @eduardosm do you have the time for a follow-up PR implementing that?
mrDIMAS commentedon Oct 9, 2023
@apiraino I re-checked on latest nightly and seems to work fine:
eduardosm commentedon Oct 9, 2023
I will do that
apiraino commentedon Oct 11, 2023
WG-prioritization assigning priority (Zulip discussion).
Issue is fixed on nightly+beta, leaving open to follow PR #116576 fixing this comment
@rustbot label -I-prioritize +P-medium
Rollup merge of rust-lang#116576 - eduardosm:const-eval-wasm-target-f…
Unrolled build for rust-lang#116576
mrDIMAS commentedon Oct 15, 2023
In which version this fix will be included?
apiraino commentedon Oct 15, 2023
Should land in stable 1.74 (around mid November), iiuc.
See release cycle or an easier to read calendar
Rollup merge of #116576 - eduardosm:const-eval-wasm-target-features, …