Repository navigation
Make more float intrinsics generic - #162395
Conversation
|
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri
cc @rust-lang/miri
cc @tgross35 Some changes occurred to the CTFE machinery
cc @Amanieu, @folkertdev, @sayantn Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr
cc @rust-lang/miri Any special-casing of Miri in the standard library requires review. cc @rust-lang/miri
cc @bjorn3
cc @rust-lang/wg-const-eval |
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
| #[rustc_const_unstable(feature = "core_intrinsics", issue = "none")] | ||
| #[rustc_intrinsic_const_stable_indirect] |
There was a problem hiding this comment.
Noted this required adding #[rustc_const_unstable] to the whole intrinsic,
Why was this needed? I guess it is because the body now needs unstable const features, namely const traits? We should ensure const traits are stable enough before we do that.
(I now notice that you already did the same for fabs. We should have already checked this there then but forgot.)
@BoxyUwU @lcnr @oli-obk are const traits in a state where we can use them internally in const functions that can be called by public monomorphic stable const functions? I think this still allows us to change the syntax and logic for const traits pretty much arbitrarily as long as we keep some way of invoking trait functions in a const fn.
There was a problem hiding this comment.
cc @fee1-dead
This is not the only case of such usage. Equivalent behaviour is here to stay and syntactical changes don't cause bootstrap churn anymore, so to me personally it is fine to add more, especially for intrinsic bodies which can always be replaced by an actual impl again
d78924b to
06625b8
Compare
|
cc @rust-lang/clippy |
06625b8 to
da4599d
Compare
This comment has been minimized.
This comment has been minimized.
ca3f9a9 to
b4275be
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
b4275be to
49057d4
Compare
|
Please also update the PR description to reflect which intrinsics are actually being changed here now. |
This comment has been minimized.
This comment has been minimized.
| where | ||
| F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>, | ||
| { | ||
| let x: F = x.to_float()?; |
There was a problem hiding this comment.
By removing this here, now every caller needs to call to_float first... is that really better?
There was a problem hiding this comment.
i found it nicer, because it means outside of SIMD we only do the x: F = x.to_float()? thing in one place, avoiding additional wrappers or calls elsewhere. it does make the SIMD intrinsics slightly bigger but i think it's nicer for the more general case
2bb83cf to
33503c2
Compare
Rollup merge of #162395 - N1ark:more-float-generics, r=folkertdev Make more float intrinsics generic Another (big) step of #153834 + #160989 Makemore remaining float intrinsics generic! Each commit is self-contained. In order: - `ceil`, `floor`, `trunc`, `round`, `round_ties_even`, with const libm fallbacks (using `#[rustc_do_not_const_check]`, see #150961, cc @RalfJung @tgross35) - `sqrt`, with libm fallbacks - `powf`, with libm fallbacks - `fma` and `fmuladd`, with libm fallbacks (+`#[rustc_do_not_const_check]`) and a shared fallback, respectively. - `powi`, with no fallback (it already didn't have any) The first commit just removes the f16/f128 fallbacks for `fabs`, as mentioned [here](#160989 (comment)). I didn't try making the backends use more fallbacks, to make the PR less risky since it's quite large. Happy to do changes there though (cc @folkertdev) `copysign`, `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum` will be handled separately as they require `rustc_allow_const_fn_unstable`: #162414
…uwer Rollup of 5 pull requests Successful merges: - rust-lang/rust#162395 (Make more float intrinsics generic) - rust-lang/rust#164636 (Remove `record_*` macros from the metadata encoder) - rust-lang/rust#164624 (make `RustaceansAreAwesome` satisfy projection clauses) - rust-lang/rust#164695 ([tiny] Include trait definition line when pointing at assoc function in E0308) - rust-lang/rust#164744 (some `Attribute`/`AttributeExt` cleanups)
…uwer Rollup of 5 pull requests Successful merges: - rust-lang/rust#162395 (Make more float intrinsics generic) - rust-lang/rust#164636 (Remove `record_*` macros from the metadata encoder) - rust-lang/rust#164624 (make `RustaceansAreAwesome` satisfy projection clauses) - rust-lang/rust#164695 ([tiny] Include trait definition line when pointing at assoc function in E0308) - rust-lang/rust#164744 (some `Attribute`/`AttributeExt` cleanups)
…uwer Rollup of 5 pull requests Successful merges: - rust-lang/rust#162395 (Make more float intrinsics generic) - rust-lang/rust#164636 (Remove `record_*` macros from the metadata encoder) - rust-lang/rust#164624 (make `RustaceansAreAwesome` satisfy projection clauses) - rust-lang/rust#164695 ([tiny] Include trait definition line when pointing at assoc function in E0308) - rust-lang/rust#164744 (some `Attribute`/`AttributeExt` cleanups)
…uwer Rollup of 5 pull requests Successful merges: - rust-lang/rust#162395 (Make more float intrinsics generic) - rust-lang/rust#164636 (Remove `record_*` macros from the metadata encoder) - rust-lang/rust#164624 (make `RustaceansAreAwesome` satisfy projection clauses) - rust-lang/rust#164695 ([tiny] Include trait definition line when pointing at assoc function in E0308) - rust-lang/rust#164744 (some `Attribute`/`AttributeExt` cleanups)
|
Note that this seems to have caused a regression in cranelift rust-lang/rustc_codegen_cranelift#1717. I think we should be prepared to revert unless there's an easy fix. |
| @@ -39,7 +67,7 @@ macro_rules! intrinsic_dispatch_on_type { | |||
| } | |||
There was a problem hiding this comment.
This fn dispatch doesn't have #[inline] while the other instance does, perhaps that's related?
Make more float intrinsics generic Another (big) step of #153834 + #160989 Makemore remaining float intrinsics generic! Each commit is self-contained. In order: - `ceil`, `floor`, `trunc`, `round`, `round_ties_even`, with const libm fallbacks (using `#[rustc_do_not_const_check]`, see #150961, cc @RalfJung @tgross35) - `sqrt`, with libm fallbacks - `powf`, with libm fallbacks - `fma` and `fmuladd`, with libm fallbacks (+`#[rustc_do_not_const_check]`) and a shared fallback, respectively. - `powi`, with no fallback (it already didn't have any) The first commit just removes the f16/f128 fallbacks for `fabs`, as mentioned [here](#160989 (comment)). I didn't try making the backends use more fallbacks, to make the PR less risky since it's quite large. Happy to do changes there though (cc @folkertdev) `copysign`, `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum` will be handled separately as they require `rustc_allow_const_fn_unstable`: #162414
…uwer Rollup of 5 pull requests Successful merges: - rust-lang/rust#162395 (Make more float intrinsics generic) - rust-lang/rust#164636 (Remove `record_*` macros from the metadata encoder) - rust-lang/rust#164624 (make `RustaceansAreAwesome` satisfy projection clauses) - rust-lang/rust#164695 ([tiny] Include trait definition line when pointing at assoc function in E0308) - rust-lang/rust#164744 (some `Attribute`/`AttributeExt` cleanups)
…s, r=RalfJung Make min/max and copysign intrinsics generic Split off from rust-lang#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang#153834 (comment)](rust-lang#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang#162395 (comment) r? RalfJung
…s, r=RalfJung Make min/max and copysign intrinsics generic Split off from rust-lang#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang#153834 (comment)](rust-lang#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang#162395 (comment) r? RalfJung
…s, r=RalfJung Make min/max and copysign intrinsics generic Split off from rust-lang#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang#153834 (comment)](rust-lang#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang#162395 (comment) r? RalfJung
…s, r=RalfJung Make min/max and copysign intrinsics generic Split off from rust-lang#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang#153834 (comment)](rust-lang#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang#162395 (comment) r? RalfJung
…s, r=RalfJung Make min/max and copysign intrinsics generic Split off from rust-lang#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang#153834 (comment)](rust-lang#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang#162395 (comment) r? RalfJung
…s, r=RalfJung Make min/max and copysign intrinsics generic Split off from rust-lang#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang#153834 (comment)](rust-lang#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang#162395 (comment) r? RalfJung
…s, r=RalfJung Make min/max and copysign intrinsics generic Split off from rust-lang#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang#153834 (comment)](rust-lang#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang#162395 (comment) r? RalfJung
…s, r=RalfJung Make min/max and copysign intrinsics generic Split off from rust-lang#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang#153834 (comment)](rust-lang#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang#162395 (comment) r? RalfJung
Rollup merge of #162414 - N1ark:const-unstable-float-generics, r=RalfJung Make min/max and copysign intrinsics generic Split off from #162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [#153834 (comment)](#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See #162395 (comment) r? RalfJung
The automatic toolchain upgrade has been stuck since nightly-2026-10-24 (model-checking#5061). This brings the toolchain to nightly-2026-11-11, in four commits: 1. **nightly-2026-10-24.** rust-lang/rust#164744 removed `Attribute::span`, `get_normal_item` and `TyCtxt::get_attrs_by_path`; Kani's `kanitool::*` attributes are unparsed tool attributes, so `attrs_by_path` and `attr_span` read them directly. rust-lang/rust#162395 made `ceil`, `floor`, `trunc`, `round`, `round_ties_even`, `sqrt`, `powf`, `powi` and `fma` generic, with fallback bodies; the one for `powi` calls `__powisf2`/`__powidf2`, which CBMC does not model, so Kani keeps its CBMC models for f32 and f64 (`uses_kani_model`, shared by codegen and reachability). 2. **nightly-2026-11-11.** Tool attributes are now `Attribute::Tool` and lost `meta_item_list`/`is_word`; `AbiAlign` and `GenericArgsRef` were removed; `rustc_abi::Float::X87F80` is reported as unsupported, like `f16b`; and a new clippy lint. Two less obvious ones: - Cargo now reports only the hashed rlib of each Kani library (`libstd-<hash>.rlib`), while the driver links `libstd.rlib` by name, so every test failed to find `std`. `build-kani` renames Kani's rlibs to `lib<crate>.rlib` in the sysroot (renamed, not copied, so rustc never sees two candidates). - Calling a closure through a function pointer argument can now take a pointer to a capture-free closure, which the uninit checker rejected as unsupported (`uninit/delayed-ub` lost its expected failure). Zero-sized closures and function items have no bytes to track. 3. **A model of the `derive(Debug)` helpers.** rust-lang/rust#164726 made `derive(Debug)` pass all names as one space-separated string, which `Formatter::debug_struct_fields_finish` and `Formatter::debug_c_like_enum_write_str` split with `memchr`. Its word-at-a-time loop depends on pointer alignment, and verifying any derived `Debug` became orders of magnitude slower: | Nightly | rust-lang/rust#164726 | `cargo-kani/iss2857` | |---|---|---| | 2026-10-24 | no | 46s | | 2026-10-29 | no | 44s | | 2026-10-30 | yes | > 15 min (stopped) | | 2026-11-11 | yes | > 58 min, 9 GB (stopped) | | 2026-11-11, this PR | yes | 53s | Kani now replaces those two helpers (the `debug_struct_field{1..5}_finish` helpers forward to the first) with models that split the same string with a byte loop and format through the same public builders. `docs/src/soundness.md` lists them as assumptions. 4. **LLBC: zero-sized constants.** MIR now assigns `()` to the return place after the last call of a unit function (`_0 = ()`) as a zero-sized constant, which the LLBC backend did not translate (`todo!()`). It now builds zero-sized tuples and structs field by field, as in model-checking#5045; each LLBC expected output gains that one line. ### Testing - `kani-regression.sh` passes on nightly-2026-11-11 (run in a container with CBMC 6.11.0), apart from `script-based-pre/compiler_defaults` (needs `jq`) and `script-based-pre/cbmc_truncated_results` (depends on the memory limit), which fail only in that container. `kani-llbc-regression.sh` passes (the LLBC build and clippy with `-D warnings`, 20 expected tests and the cargo suite), and `kani-fmt.sh --check` and workspace clippy pass. - `library/kani/src/fmt_model_tests.rs` compares the models with the real `derive(Debug)` output natively (named, tuple and unit structs, more than five fields, nesting, `{:#?}`, widths, C-like enums with raw and non-ASCII names). Checking exact formatter output inside Kani takes over nine minutes per harness, with or without the models, so this is a native test; `tests/kani/FmtDerive` checks that Kani verifies formatting of each shape through the models (84s). - `cargo-kani/iss2857` is the performance regression test. Resolves model-checking#5061 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
…Jung Make min/max and copysign intrinsics generic Split off from rust-lang/rust#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang/rust#153834 (comment)](rust-lang/rust#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang/rust#162395 (comment) r? RalfJung
…s, r=RalfJung Make min/max and copysign intrinsics generic Split off from rust-lang#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang#153834 (comment)](rust-lang#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang#162395 (comment) r? RalfJung
…Jung Make min/max and copysign intrinsics generic Split off from rust-lang/rust#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang/rust#153834 (comment)](rust-lang/rust#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang/rust#162395 (comment) r? RalfJung
…Jung Make min/max and copysign intrinsics generic Split off from rust-lang/rust#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang/rust#153834 (comment)](rust-lang/rust#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang/rust#162395 (comment) r? RalfJung
…Jung Make min/max and copysign intrinsics generic Split off from rust-lang/rust#162395 Make the following intrinsics generic over the float type: - `copysign`, with a shared fallback (bit manipulations). Note that this required adding `#[rustc_const_unstable]` to the whole intrinsic, which `copysignf16` and `copysignf128` didn't have. This was already FCP'd, see [rust-lang/rust#153834 (comment)](rust-lang/rust#153834 (comment)). - `minimum_number_nsz`, `maximum_number_nsz`, `minimum`, `maximum`, with shared fallbacks. See rust-lang/rust#162395 (comment) r? RalfJung
View all comments
Another (big) step of #153834 + #160989
Makemore remaining float intrinsics generic! Each commit is self-contained.
In order:
ceil,floor,trunc,round,round_ties_even, with const libm fallbacks (using#[rustc_do_not_const_check], see Intrinsics should allow a non-const fallback body if hooked for CTFE #150961, cc @RalfJung @tgross35)sqrt, with libm fallbackspowf, with libm fallbacksfmaandfmuladd, with libm fallbacks (+#[rustc_do_not_const_check]) and a shared fallback, respectively.powi, with no fallback (it already didn't have any)The first commit just removes the f16/f128 fallbacks for
fabs, as mentioned here. I didn't try making the backends use more fallbacks, to make the PR less risky since it's quite large. Happy to do changes there though (cc @folkertdev)copysign,minimum_number_nsz,maximum_number_nsz,minimum,maximumwill be handled separately as they requirerustc_allow_const_fn_unstable: #162414