about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
AgeCommit message (Collapse)AuthorLines
2025-07-01Remove support for dyn*Michael Goulet-100/+15
2025-06-30Rollup merge of #143140 - RalfJung:ptr-into-parts, r=oli-obkMatthias Krüger-9/+11
give Pointer::into_parts a more scary name and offer a safer alternative `into_parts` is a bit too innocent of a name for a somewhat subtle operation. r? `@oli-obk`
2025-06-30Remove the nullary intrinsic const eval logic and treat them like other ↵Oli Scherer-87/+72
intrinsics
2025-06-29rename Pointer::from_addr_invalid to match strict provenance APIRalf Jung-3/+3
2025-06-29give Pointer::into_parts a more scary name and offer a safer alternativeRalf Jung-6/+8
2025-06-27Rollup merge of #143046 - RalfJung:zst-unsafe-cell, r=lcnr,oli-obkMatthias Krüger-17/+22
const validation: properly ignore zero-sized UnsafeCell Fixes https://github.com/rust-lang/rust/issues/142948 r? `@oli-obk`
2025-06-27Rollup merge of #143084 - RalfJung:const-eval-recursive-static-write, r=oli-obkGuillaume Gomez-11/+25
const-eval: error when initializing a static writes to that static Fixes https://github.com/rust-lang/rust/issues/142404 by also calling the relevant hook for writes, not just reads. To avoid erroring during the actual write of the initial value, we neuter the hook when popping the final stack frame. Calling the hook during writes requires changing its signature since we cannot pass in the entire interpreter any more. While doing this I also realized a gap in https://github.com/rust-lang/rust/pull/142575 for zero-sized copies on the read side, so I fixed that and added a test. r? `@oli-obk`
2025-06-27Rollup merge of #143051 - Stypox:tracing-validity, r=RalfJungGuillaume Gomez-4/+11
Add tracing to `validate_operand` This PR adds a tracing call to keep track of how much time is spent in `validate_operand` and `const_validate_operand`. Let me know if more fine-grained tracing is needed (e.g. adding tracing to `validate_operand_internal` too, which is just called from those two functions). I also fixed the rustdoc of `validate_operand` and `const_validate_operand` since it was referencing an older name for the `val` parameter which was renamed in cbdcbf0d6a586792c5e0a0b8965a3179bac56120. Here is some tracing output when Miri is run on `src/tools/miri/tests/pass/hello.rs`, visualizable in [ui.perfetto.dev](https://ui.perfetto.dev/): [trace-1750932222218210.json](https://github.com/user-attachments/files/20924000/trace-1750932222218210.json) **Note: obtaining tracing output depends on https://github.com/rust-lang/miri/pull/4406, but this PR is standalone and can be merged without waiting for https://github.com/rust-lang/miri/pull/4406.** r? `@RalfJung`
2025-06-27const-eval: error when initializing a static writes to that staticRalf Jung-11/+25
2025-06-27Add InterpCx::layout_of with tracing, shadowing LayoutOfStypox-13/+26
2025-06-27Add tracing for instantiate_from_frame_and_normalize_erasing_regionsStypox-1/+7
2025-06-27Add tracing to validate_operandStypox-0/+7
2025-06-27Auto merge of #143074 - compiler-errors:rollup-cv64hdh, r=compiler-errorsbors-11/+10
Rollup of 18 pull requests Successful merges: - rust-lang/rust#137843 (make RefCell unstably const) - rust-lang/rust#140942 (const-eval: allow constants to refer to mutable/external memory, but reject such constants as patterns) - rust-lang/rust#142549 (small iter.intersperse.fold() optimization) - rust-lang/rust#142637 (Remove some glob imports from the type system) - rust-lang/rust#142647 ([perf] Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation) - rust-lang/rust#142700 (Remove incorrect comments in `Weak`) - rust-lang/rust#142927 (Add note to `find_const_ty_from_env`) - rust-lang/rust#142967 (Fix RwLock::try_write documentation for WouldBlock condition) - rust-lang/rust#142986 (Port `#[export_name]` to the new attribute parsing infrastructure) - rust-lang/rust#143001 (Rename run always ) - rust-lang/rust#143010 (Update `browser-ui-test` version to `0.20.7`) - rust-lang/rust#143015 (Add `sym::macro_pin` diagnostic item for `core::pin::pin!()`) - rust-lang/rust#143033 (Expand const-stabilized API links in relnotes) - rust-lang/rust#143041 (Remove cache for citool) - rust-lang/rust#143056 (Move an ACE test out of the GCI directory) - rust-lang/rust#143059 (Fix 1.88 relnotes) - rust-lang/rust#143067 (Tracking issue number for `iter_macro`) - rust-lang/rust#143073 (Fix some fixmes that were waiting for let chains) Failed merges: - rust-lang/rust#143020 (codegen_fn_attrs: make comment more precise) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-26const-eval: allow constants to refer to mutable/external memory, but reject ↵Ralf Jung-11/+10
such constants as patterns
2025-06-26Fix documentation of validate_operandStypox-4/+4
The name of the parameter changed from `op` to `val` in cbdcbf0d6a586792c5e0a0b8965a3179bac56120
2025-06-26make size_and_align_of_mplace work on all projectableRalf Jung-22/+16
2025-06-26const validation: properly ignore zero-sized UnsafeCellRalf Jung-3/+14
2025-06-25make `tidy-alphabetical` use a natural sortFolkert de Vries-3/+3
2025-06-22centralize `-Zmin-function-alignment` logicFolkert de Vries-6/+1
2025-06-20Ensure copy* intrinsics also perform the static self-init checksOli Scherer-1/+6
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-11Fix enter_trace_span!() using wrong $crate pathsStypox-2/+2
2025-06-10const_eval: fix some outdated commentsRalf Jung-8/+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-06-06Rollup merge of #142103 - scottmcm:fieldidx-in-interp, r=oli-obkGuillaume Gomez-30/+33
Update `InterpCx::project_field` to take `FieldIdx` As suggested by Ralf in https://github.com/rust-lang/rust/pull/142005#discussion_r2125839015
2025-06-05Update `InterpCx::project_field` to take `FieldIdx`Scott McMurray-30/+33
As suggested by Ralf in 142005.
2025-06-05Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of NoneOli Scherer-1/+2
2025-06-03Change `tag_field` to `FieldIdx` in `Variants::Multiple`Scott McMurray-5/+5
It was already available as a generic parameter anyway, and it's not like we'll ever put a tag in the 5-billionth field.
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 #141582 - RalfJung:cleanup, r=bjorn3Michael Goulet-1/+1
intrinsics, ScalarInt: minor cleanup Taken out of https://github.com/rust-lang/rust/pull/141507 while we resolve technical disagreements in that PR. r? ``@bjorn3``
2025-05-27Rollup merge of #141513 - nia-e:allocbytes-extend, r=RalfJung许杰友 Jieyou Xu (Joe)-5/+11
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-5/+11
2025-05-24ScalarInt: support conversion with signed int types and cmp::OrderingRalf Jung-1/+1
2025-05-22interpret: do not force_allocate all return placesRalf Jung-82/+72
2025-05-20Rollup merge of #140972 - Stypox:machine-tracing-flag, r=RalfJungMatthias Krüger-0/+25
Add TRACING_ENABLED to Machine and add enter_trace_span!() This PR adds the necessary infrastructure to make it possible to do tracing calls from within `rustc_const_eval` when running Miri, while making sure they don't impact the performance of normal compiler execution. This is done by adding a `const` boolean to `Machine`, false by default, but that will be set to true in Miri only. The tracing macro `enter_trace_span!()` checks if it is true before doing anything, and since the value of a `const` is known at compile time, if it it false it the whole tracing call should be optimized out. I will soon open further PRs to add tracing macro calls similar to this one, so that afterwards it will be possible to learn more about Miri's time spent in the various interpretation steps: ```rs let _guard = enter_trace_span!(M, "eval_statement", "{:?}", stmt); ``` r? `@RalfJung`
2025-05-20Add enter_trace_span!() that checks if tracing is enabledStypox-0/+19
2025-05-17Rollup merge of #135808 - tiif:conv_display, r=workingjubileeMatthias Krüger-2/+2
Implement Display for ``rustc_target::callconv::Conv`` Follow up of https://github.com/rust-lang/rust/pull/133103#discussion_r1885552854
2025-05-13Add TRACING_ENABLED to Machine traitStypox-0/+6
2025-05-09Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operationsUrgau-0/+42
2025-05-05Auto merge of #140453 - Zoxc:next-disambiguator, r=oli-obkbors-8/+27
Remove global `next_disambiguator` state and handle it with a `DisambiguatorState` type This removes `Definitions.next_disambiguator` as it doesn't guarantee deterministic def paths when `create_def` is called in parallel. Instead a new `DisambiguatorState` type is passed as a mutable reference to `create_def` to help create unique def paths. `create_def` calls with distinct `DisambiguatorState` instances must ensure that that the def paths are unique without its help. Anon associated types did rely on this global state for uniqueness and are changed to use (method they're defined in + their position in the method return type) as the `DefPathData` to ensure uniqueness. This also means that the method they're defined in appears in error messages, which is nicer. `DefPathData::NestedStatic` is added to use for nested data inside statics instead of reusing `DefPathData::AnonConst` to avoid conflicts with those. cc `@oli-obk`
2025-05-02Rollup merge of #140521 - RalfJung:oob-error, r=saethlinMatthias Krüger-12/+16
interpret: better error message for out-of-bounds pointer arithmetic and accesses Fixes https://github.com/rust-lang/rust/issues/93881 r? `@saethlin`
2025-05-02Move `DisambiguatorState` into `intern_const_alloc_recursive`John Kåre Alsaker-14/+28
2025-05-02Add `DefPathData::NestedStatic` instead of reusing `DefPathData::AnonConst`John Kåre Alsaker-4/+3
2025-04-30interpret: better error message for out-of-bounds pointer arithmetic and ↵Ralf Jung-12/+16
accesses
2025-04-30Rollup merge of #140439 - RalfJung:miri-algebraic-float-nondet, r=oli-obkMatthias Krüger-2/+9
miri: algebraic intrinsics: bring back float non-determinism Fixes https://github.com/rust-lang/miri/issues/4289 Cc ```@bjoernager``` r? ```@oli-obk```
2025-04-29Rollup merge of #139909 - oli-obk:or-patterns, r=BoxyUwUTrevor Gross-5/+18
implement or-patterns for pattern types These are necessary to represent `NonZeroI32`, as the range for that is `..0 | 1..`. The `rustc_scalar_layout_range_*` attributes avoided this by just implementing wraparound and having a single `1..=-1` range effectively. See https://rust-lang.zulipchat.com/#narrow/channel/481660-t-lang.2Fpattern-types/topic/.60or.20pattern.60.20representation.20in.20type.20system/with/504217694 for some background discussion cc https://github.com/rust-lang/rust/issues/123646 r? `@BoxyUwU`
2025-04-29Remove global `next_disambiguator` state and handle it with a ↵John Kåre Alsaker-7/+13
`DisambiguatorState` type
2025-04-29miri: algebraic intrinsics: bring back float non-determinismRalf Jung-2/+9