about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret/intrinsics.rs
AgeCommit message (Collapse)AuthorLines
2025-09-24unstably constify float mul_add methodsJeremy Smart-0/+46
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-09-17Remove `DynKind`León Orell Valerian Liehr-1/+1
2025-07-23Remove useless lifetime parameter.Camille GILLOT-2/+1
2025-07-23Give an AllocId to ConstValue::Slice.Camille GILLOT-9/+11
2025-07-16type_id_eq: check that the hash fully matches the typeRalf Jung-45/+54
2025-07-14Give all bytes of TypeId provenanceOli Scherer-31/+37
2025-07-09Avoid creating a helper allocation for creating new `TypeId` values in the ↵Oli Scherer-38/+29
interpreter
2025-07-09Add opaque TypeId handles for CTFEOli Scherer-2/+77
2025-07-02miri: improve errors for type validity assertion failuresRalf Jung-38/+3
2025-06-30Remove the nullary intrinsic const eval logic and treat them like other ↵Oli Scherer-86/+72
intrinsics
2025-06-27Rollup merge of #143046 - RalfJung:zst-unsafe-cell, r=lcnr,oli-obkMatthias Krüger-1/+1
const validation: properly ignore zero-sized UnsafeCell Fixes https://github.com/rust-lang/rust/issues/142948 r? `@oli-obk`
2025-06-27Add InterpCx::layout_of with tracing, shadowing LayoutOfStypox-1/+1
2025-06-26make size_and_align_of_mplace work on all projectableRalf Jung-1/+1
2025-06-13Rollup merge of #142405 - oli-obk:type-once, r=RalfJungJubilee-7/+7
Don't hardcode the intrinsic return types twice in the compiler We already manually check intrinsic types in intrinsicck so we don't need to do it in the interpreter
2025-06-12intrinsics: rename min_align_of to align_ofRalf Jung-2/+2
2025-06-12Don't hardcode the intrinsic return types twice in the compilerOli Scherer-7/+7
2025-06-08Remove rustc's notion of "preferred" alignment AKA `__alignof`Jubilee Young-13/+2
In PR 90877 T-lang decided not to remove `intrinsics::pref_align_of`. However, the intrinsic and its supporting code 1. is a nightly feature, so can be removed at compiler/libs discretion 2. requires considerable effort in the compiler to support, as it necessarily complicates every single site reasoning about alignment 3. has been justified based on relevance to codegen, but it is only a requirement for C++ (not C, not Rust) stack frame layout for AIX, in ways Rust would not consider even with increased C++ interop 4. is only used by rustc to overalign some globals, not correctness 5. can be adequately replaced by other rules for globals, as it mostly affects alignments for a few types under 16 bytes of alignment 6. has only one clear benefactor: automating C -> Rust translation for GNU extensions like `__alignof` 7. such code was likely intended to be `alignof` or `_Alignof`, because the GNU extension is a "false friend" of the C keyword, which makes the choice to support such a mapping very questionable 8. makes it easy to do incorrect codegen in the compiler by its mere presence as usual Rust rules of alignment (e.g. `size == align * N`) do not hold with preferred alignment The implementation is clearly damaging the code quality of the compiler. Thus it is within the compiler team's purview to simply rip it out. If T-lang wishes to have this intrinsic restored for c2rust's benefit, it would have to use a radically different implementation that somehow does not cause internal incorrectness. Until then, remove the intrinsic and its supporting code, as one tool and an ill-considered GCC extension cannot justify risking correctness. Because we touch a fair amount of the compiler to change this at all, and unfortunately the duplication of AbiAndPrefAlign is deep-rooted, we keep an "AbiAlign" type which we can wean code off later.
2025-05-31Add const support for float rounding methodsRuan Comelli-0/+113
Add const support for the float rounding methods floor, ceil, trunc, fract, round and round_ties_even. This works by moving the calculation logic from src/tools/miri/src/intrinsics/mod.rs into compiler/rustc_const_eval/src/interpret/intrinsics.rs. All relevant method definitions were adjusted to include the `const` keyword for all supported float types: f16, f32, f64 and f128. The constness is hidden behind the feature gate feature(const_float_round_methods) which is tracked in https://github.com/rust-lang/rust/issues/141555 This commit is a squash of the following commits: - test: add tests that we expect to pass when float rounding becomes const - feat: make float rounding methods `const` - fix: replace `rustc_allow_const_fn_unstable(core_intrinsics)` attribute with `#[rustc_const_unstable(feature = "f128", issue = "116909")]` in `library/core/src/num/f128.rs` - revert: undo update to `library/stdarch` - refactor: replace multiple `float_<mode>_intrinsic` rounding methods with a single, parametrized one - fix: add `#[cfg(not(bootstrap))]` to new const method tests - test: add extra sign tests to check `+0.0` and `-0.0` - revert: undo accidental changes to `round` docs - fix: gate `const` float round method behind `const_float_round_methods` - fix: remove unnecessary `#![feature(const_float_methods)]` - fix: remove unnecessary `#![feature(const_float_methods)]` [2] - revert: undo changes to `tests/ui/consts/const-eval/float_methods.rs` - fix: adjust after rebase - test: fix float tests - test: add tests for `fract` - chore: add commented-out `const_float_round_methods` feature gates to `f16` and `f128` - fix: adjust NaN when rounding floats - chore: add FIXME comment for de-duplicating float tests - test: remove unnecessary test file `tests/ui/consts/const-eval/float_methods.rs` - test: fix tests after upstream simplification of how float tests are run
2025-05-27Rollup merge of #141513 - nia-e:allocbytes-extend, r=RalfJung许杰友 Jieyou Xu (Joe)-1/+1
interpret: add allocation parameters to `AllocBytes` Necessary for a better implementation of [rust-lang/miri#4343](https://github.com/rust-lang/miri/pull/4343). Also included here is the code from that PR, adapted to this new interface for the sake of example and so that CI can run on them; the Miri changes can be reverted and merged separately, though. r? `@RalfJung`
2025-05-26extend allocbytes with associated typeNia Espera-1/+1
2025-05-22interpret: do not force_allocate all return placesRalf Jung-11/+11
2025-05-09Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operationsUrgau-0/+42
2025-05-02Rollup merge of #140521 - RalfJung:oob-error, r=saethlinMatthias Krüger-3/+7
interpret: better error message for out-of-bounds pointer arithmetic and accesses Fixes https://github.com/rust-lang/rust/issues/93881 r? `@saethlin`
2025-04-30interpret: better error message for out-of-bounds pointer arithmetic and ↵Ralf Jung-3/+7
accesses
2025-04-30Rollup merge of #140439 - RalfJung:miri-algebraic-float-nondet, r=oli-obkMatthias Krüger-2/+1
miri: algebraic intrinsics: bring back float non-determinism Fixes https://github.com/rust-lang/miri/issues/4289 Cc ```@bjoernager``` r? ```@oli-obk```
2025-04-29miri: algebraic intrinsics: bring back float non-determinismRalf Jung-2/+1
2025-04-28Add or-patterns to pattern typesOli Scherer-5/+10
2025-04-23Make algebraic intrinsics into 'const fn' items; Make algebraic functions of ↵Gabriel Bjørnager Jensen-0/+25
'f16', 'f32', 'f64', and 'f128' into 'const fn' items;
2025-02-02miri: improve error when offset_from preconditions are violatedRalf Jung-1/+19
2025-01-31miri: make float min/max non-deterministicRalf Jung-2/+14
2024-12-25swap_typed_nonoverlapping: properly detect overlap even when swapping scalar ↵Ralf Jung-6/+22
values
2024-12-25rename typed_swap → typed_swap_nonoverlappingRalf Jung-1/+1
2024-12-25miri: add test for overlapping typed_swapRalf Jung-1/+1
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-0/+1
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-1/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-11-19`InterpCx` store `TypingEnv` instead of a `ParamEnv`lcnr-5/+4
2024-11-18Auto merge of #132460 - lcnr:questionable-uwu, r=compiler-errorsbors-3/+6
Use `TypingMode` throughout the compiler instead of `ParamEnv` Hopefully the biggest single PR as part of https://github.com/rust-lang/types-team/issues/128. ## `infcx.typing_env` while defining opaque types I don't know how'll be able to correctly handle opaque types when using something taking a `TypingEnv` while defining opaque types. To correctly handle the opaques we need to be able to pass in the current `opaque_type_storage` and return constraints, i.e. we need to use a proper canonical query. We should migrate all the queries used during HIR typeck and borrowck where this matters to proper canonical queries. This is ## `layout_of` and `Reveal::All` We convert the `ParamEnv` to `Reveal::All` right at the start of the `layout_of` query, so I've changed callers of `layout_of` to already use a post analysis `TypingEnv` when encountering it. https://github.com/rust-lang/rust/blob/ca87b535a05097df6abbe2a031b057de2cefac5b/compiler/rustc_ty_utils/src/layout.rs#L51 ## `Ty::is_[unpin|sized|whatever]` I haven't migrated `fn is_item_raw` to use `TypingEnv`, will do so in a followup PR, this should significantly reduce the amount of `typing_env.param_env`. At some point there will probably be zero such uses as using the type system while ignoring the `typing_mode` is incorrect. ## `MirPhase` and phase-transitions When inside of a MIR-body, we can mostly use its `MirPhase` to figure out the right `typing_mode`. This does not work during phase transitions, most notably when transitioning from `Analysis` to `Runtime`: https://github.com/rust-lang/rust/blob/dae7ac133b9eda152784c075facb31a6688c92b1/compiler/rustc_mir_transform/src/lib.rs#L606-L625 All these passes still run with `MirPhase::Analysis`, but we should only use `Reveal::All` once we're run the `RevealAll` pass. This required me to manually construct the right `TypingEnv` in all these passes. Given that it feels somewhat easy to accidentally miss this going forward, I would maybe like to change `Body::phase` to an `Option` and replace it at the start of phase transitions. This then makes it clear that the MIR is currently in a weird state. r? `@ghost`
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-3/+6
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-18remove pointless cold_path impl in interpreterRalf Jung-3/+0
2024-11-17Likely unlikely fixJiri Bobek-0/+3
2024-11-03compiler: Directly use rustc_abi in const_evalJubilee Young-1/+1
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-1/+1
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-28compiler: Add `is_uninhabited` and use LayoutS accessorsJubilee Young-1/+1
This reduces the need of the compiler to peek on the fields of LayoutS.
2024-10-19interpret errors: add map_err_kind, rename InterpError -> InterpErrorKindRalf Jung-2/+1
2024-10-15Make some float methods unstable `const fn`Eduardo Sánchez Muñoz-0/+80
Some float methods are now `const fn` under the `const_float_methods` feature gate. In order to support `min`, `max`, `abs` and `copysign`, the implementation of some intrinsics had to be moved from Miri to rustc_const_eval.
2024-10-01make InterpResult a dedicated type to avoid accidentally discarding the errorRalf Jung-13/+14
2024-09-29cleanup: don't `.into()` identical typesMatthias Krüger-5/+2
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-09-15also use compute_size_in_bytes for relevant multiplications in MiriRalf Jung-5/+6
2024-09-14interpret: fix dealing with overflow during slice indexingRalf Jung-4/+3