about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret/step.rs
AgeCommit message (Collapse)AuthorLines
2025-09-16Remove Rvalue::Len.Camille Gillot-7/+1
2025-09-10interpret: fix overlapping aggregate initializationRalf Jung-3/+13
2025-08-22miri: also detect aliasing of in-place argument and return placeRalf Jung-7/+16
2025-08-19Rollup merge of #145585 - RalfJung:miri-inplace-arg-checks, r=compiler-errors许杰友 Jieyou Xu (Joe)-19/+41
Miri: fix handling of in-place argument and return place handling This fixes two separate bugs (in two separate commits): - If the return place is `_local` and not `*ptr`, we didn't always properly protect it if there were other pointers pointing to that return place. - If two in-place arguments are *the same* local variable, we didn't always detect that aliasing.
2025-08-19Rollup merge of #145306 - Stypox:tracing-misc, r=RalfJung许杰友 Jieyou Xu (Joe)-1/+4
Add tracing to various miscellaneous functions This PR adds tracing to: - `ty.fn_sig()`. There is only one place where `fn_sig` is called for real within `rustc_const_eval`. There are three other places where it's called, but one is inside `ConstCx::fn_sig` (which does not seem to be used anywhere), another is under `if cfg!(debug_assertions)`, and the last is within `call_main` and thus gets called only once. - the two possible things `find_mir_or_eval_fn` can do: "emulate_foreign_item" and "load_mir" - all calls to `Const.eval()` within the Miri or the `rustc_const_eval` codebase. - a separate commit also fixes the style of some tracing macros Those are all quite long-lived operations, that in total make up for 6-7% of the total time spent in the program. I found out about them by looking for long periods of time that were previously not traced at all, using this SQL query in ui.perfetto.dev: ```sql with ordered as (select s1.*, row_number() over (order by s1.ts) as rn from slices as s1 where s1.parent_id is null and s1.dur > 0 and s1.name != "frame" and s1.name != "step" and s1.name != "backtrace") select a.ts+a.dur as ts, b.ts-a.ts-a.dur as dur, a.id, a.track_id, a.category, a.depth, a.stack_id, a.parent_stack_id, a.parent_id, a.arg_set_id, a.thread_ts, a.thread_instruction_count, a.thread_instruction_delta, a.cat, a.slice_id, "empty" as name from ordered as a inner join ordered as b on a.rn=b.rn-1 /*where b.ts-a.ts-a.dur > 5000*/ order by b.ts-a.ts-a.dur desc ``` <details> <summary>How the table was obtained</summary> The above image was obtained in ui.perfetto.dev with the following SQL query after obtaining a trace file by running Miri on the following Rust code with `n=100`. ```sql select "TOTAL PROGRAM DURATION" as name, count(*), max(ts + dur) as "sum(dur)", 100.0 as "%", null as "min(dur)", null as "max(dur)", null as "avg(dur)", null as "stddev(dur)" from slices union select "TOTAL OVER ALL SPANS (excluding events)" as name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" and dur > 0 union select name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" group by name order by sum(dur) desc, count(*) desc ``` ```rust fn main() { let n: usize = std::env::args().nth(1).unwrap().parse().unwrap(); let mut v = (0..n).into_iter().collect::<Vec<_>>(); for i in &mut v { *i += 1; } } ``` </details> <img width="1689" height="317" alt="image" src="https://github.com/user-attachments/assets/ee2c81f5-d74a-4da5-b4b6-ab2770175b14" />
2025-08-19miri: detect passing the same local twice as an in-place argumentRalf Jung-20/+41
2025-08-18Add tracing to various miscellaneous functionsStypox-1/+4
Also use tracing macro syntax instead of format()
2025-08-18interpret: fix in-place return place semantics when the return place ↵Ralf Jung-0/+1
expression is a local variable
2025-08-14Rollup merge of #144727 - Stypox:add-tracing-to-resolve, r=RalfJungGuillaume Gomez-1/+5
Add tracing to resolve-related functions Resolve-related functions are not called often but still make up for ~3% of execution time for non-repetitive programs (as seen in the first table below, obtained from running the rust snippet at the bottom with `n=1`). On the other hand, for repetitive programs they become less relevant (I tested the same snippet but with `n=100` and got ~1.5%), and it appears that only `try_resolve` is called more often (see the last two tables). The first table was obtained by opening the trace file in https://ui.perfetto.dev and running the following query: ```sql select "TOTAL PROGRAM DURATION" as name, count(*), max(ts + dur) as "sum(dur)", 100.0 as "%", null as "min(dur)", null as "max(dur)", null as "avg(dur)", null as "stddev(dur)" from slices union select "TOTAL OVER ALL SPANS (excluding events)" as name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" and dur > 0 union select name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" group by name order by sum(dur) desc, count(*) desc ``` <img width="1687" height="242" alt="image" src="https://github.com/user-attachments/assets/4d4bd890-869b-40f3-a473-8e4c42b02da4" /> The following two tables show how many `resolve` spans there per subname/subcategory, and how much time is spent in each. The first is for `n=1` and the second for `n=100`. The query that was used is: ```sql select args.string_value as name, count(*), max(dur), avg(dur), sum(dur) from slices inner join args USING (arg_set_id) where args.key = "args." || slices.name and name = "resolve" group by args.string_value ``` <img width="1688" height="159" alt="image" src="https://github.com/user-attachments/assets/a8749856-c099-492e-a86e-6d67b146af9c" /> <img width="1688" height="159" alt="image" src="https://github.com/user-attachments/assets/ce3ac1b5-5c06-47d9-85a6-9b921aea348e" /> The snippet I tested with Miri to obtain the above traces is: ```rust fn main() { let n: usize = std::env::args().nth(1).unwrap().parse().unwrap(); let mut v = (0..n).into_iter().collect::<Vec<_>>(); for i in &mut v { *i += 1; } } ```
2025-08-11Turn _span into _trace as trace span nameStypox-2/+2
_span could possibly be confused with the Span type in rustc
2025-08-11Add tracing to resolve-related functionsStypox-1/+5
2025-07-31Add EnteredTraceSpan::or_if_tracing_disabledStypox-4/+5
2025-07-31Add tracing calls to eval_statement/terminatorStypox-3/+18
2025-07-15Add InterpCx::fn_abi_of_instance/_fn_ptr with tracing, shadowing FnAbiOfStypox-1/+0
2025-06-05Update `InterpCx::project_field` to take `FieldIdx`Scott McMurray-1/+1
As suggested by Ralf in 142005.
2025-05-22interpret: do not force_allocate all return placesRalf Jung-1/+1
2025-04-28AsyncDrop implementation using shim codegen of ↵Andrew Zhogin-1/+5
async_drop_in_place::{closure}, scoped async drop added.
2025-03-12minor interpret cleanupsRalf Jung-3/+3
2025-02-10Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptrBastian Kersting-1/+1
The wording unsafe pointer is less common and not mentioned in a lot of places, instead this is usually called a "raw pointer". For the sake of uniformity, we rename this method. This came up during the review of https://github.com/rust-lang/rust/pull/134424.
2025-01-31ValidationMichael Goulet-0/+2
2025-01-31Implement MIR, CTFE, and codegen for unsafe bindersMichael Goulet-0/+5
2025-01-28Represent the raw pointer for a array length check as a new kind of fake borrowMichael Goulet-13/+5
2025-01-27Reapply "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵Michael Goulet-2/+11
r=davidtwco,RalfJung" This reverts commit 122a55bb442bd1995df9cf9b36e6f65ed3ef4a1d.
2025-01-18Revert "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵Rémy Rakic-11/+2
r=davidtwco,RalfJung" This reverts commit b57d93d8b9525fa261404b4cd9c0670eeb1264b8, reversing changes made to 0aeaa5eb22180fdf12a8489e63c4daa18da6f236.
2025-01-18Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"Rémy Rakic-1/+7
This reverts commit e108481f74ff123ad98a63bd107a18d13035b275, reversing changes made to 303e8bd768526a5812bb1776e798e829ddb7d3ca.
2024-12-22Delete `Rvalue::Len`Scott McMurray-7/+1
Everything's moved to `PtrMetadata` instead.
2024-12-13Update compiler/rustc_const_eval/src/interpret/step.rsscottmcm-1/+3
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-12-13Don't retag the `PtrMetadata(&raw const *_n)` in slice indexingScott McMurray-2/+9
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-0/+3
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com> collect drops instead of taking liveness diff apply some suggestions and add explantory notes small fix on the cache let the query recurse through coroutine new suggestion format with extracted variable name fine-tune the drop span and messages bugfix on runtime borrows tweak message wording filter out ecosystem types earlier apply suggestions clippy check lint level at session level further restrict applicability of the lint translate bid into nop for stable mir detect cycle in type structure
2024-11-19`InterpCx` store `TypingEnv` instead of a `ParamEnv`lcnr-2/+1
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-1/+2
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-03compiler: Directly use rustc_abi in const_evalJubilee Young-2/+2
2024-10-01make InterpResult a dedicated type to avoid accidentally discarding the errorRalf Jung-14/+14
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-1/+1
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-1/+1
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-08-06various cleanups based on reviewRalf Jung-36/+33
2024-08-06interpret: refactor function call handling to be better-abstractedRalf Jung-11/+239
2024-08-05interpret: move nullary-op evaluation into operator.rsRalf Jung-35/+8
2024-08-01interpret: simplify pointer arithmetic logicRalf Jung-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-07Refactor & fixup interpreter implementation of tail callsMaybe Waffle-1/+1
2024-06-08offset_of: allow (unstably) taking the offset of slice tail fieldsRalf Jung-1/+4
2024-05-27interpret: get rid of 'mir lifetime everywhereRalf Jung-1/+1
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_const_eval`.Nicholas Nethercote-0/+1
2024-05-21interpret: make overflowing binops just normal binopsRalf Jung-8/+6
2024-05-17Remove `Rvalue::CheckedBinaryOp`Scott McMurray-9/+5
2024-05-13Remove `extern crate rustc_middle` from `rustc_const_eval`.Nicholas Nethercote-0/+1
This requires exporting the interpreter macros so they can be used with `use crate::interpret::*`.
2024-04-21Address PR feedbackScott McMurray-4/+12
2024-04-21Use it in the library, and `InstSimplify` it away in the easy placesScott McMurray-1/+16