Skip to content

Commit 268d9a1

Browse files
Rollup merge of #143968 - Stypox:tracing-FnAbiOf, r=RalfJung
Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr` This PR adds tracing to the `InterpCx::fn_abi_of_instance`/`::fn_abi_of_fn_ptr` functions by shadowing `FnAbiOf`'s trait methods with inherent methods on `InterpCx`, like done in rust-lang/rust#142721. The reason why I am targeting these two functions is because they are used for Miri interpretation, and they make a `layout_of` query down the line without passing through the `layout_of` that was traced in rust-lang/rust#142721. There are other places where `layout_of` is called without being traced (see the analysis below), but that's because the `Machine` used there is not `MiriMachine` but rather `CompileTimeMachine` which does not implement `enter_trace_span()`. But after discussing with ```````@RalfJung``````` we agreed that the const-eval part should not be traced together with Miri, that's why I am ignoring the other places where `layout_of` is called. r? ```````@RalfJung``````` <details><summary>Analysis of the places where <code>layout_of</code> is called</summary> I did some analysis for rust-lang/rust#142721 (comment), and these are all the places where the query `tcx.layout_of` is called (directly or indirectly) outside of a traced `InterpCx::layout_of` while a program is being interpreted by Miri: ``` adjust_for_rust_scalar at ./compiler/rustc_ty_utils/src/abi.rs:302:35 {closure#2} at ./compiler/rustc_ty_utils/src/abi.rs:522:25 eval_body_using_ecx<> at ./compiler/rustc_const_eval/src/const_eval/eval_queries.rs:49:22 {closure#1}<> at ./compiler/rustc_const_eval/src/interpret/operand.rs:851:76 {closure#0}<> at ./compiler/rustc_const_eval/src/interpret/stack.rs:612:18 size_and_align at ./compiler/rustc_middle/src/mir/interpret/mod.rs:387:38 ``` I got these by: - patching rustc with this patch that adds a span to the `layout_of` query which prints the backtrace: [layout_of_other_places.diff.txt](https://github.com/user-attachments/files/21235523/layout_of_other_places.diff.txt) - adding this to my bootstrap.toml to have debug symbols inside the Miri binary: `rust.debuginfo-level = "line-tables-only"` and also `build.tool.miri.features = ["tracing"]` - obtaining a trace file with `MIRI_TRACING=1 ./x.py run miri --stage 1 --warnings warn --args src/tools/miri/tests/pass/hello.rs` (note: maybe using a file different than "src/tools/miri/tests/pass/hello.rs" would lead to more places where layout_of is called?) - running this query in Perfetto to select all `layout_of` spans that have as a direct parent a span named "frame" (as opposed to the parent being `InterpCx::layout_of`) and extract their backtrace: `select args.string_value from slice left join args on slice.arg_set_id = args.id where slice.name = "tcx.layout_of" and slice.parent_id in (select slice2.id from slice as slice2 where slice2.name = "frame") group by args.string_value` - exporting the data as `.tsv` and processing that file through this Python script. It finds the first path in the backtraces where "layout" isn't mentioned, which imo is a good heuristic to not consider `layout_of` wrappers/friends as call places, but rather go down the backtrace until an actual call place is reached. [layout_of_other_places.py.txt](https://github.com/user-attachments/files/21235529/layout_of_other_places.py.txt) </details>
2 parents 6d7a905 + 65685e8 commit 268d9a1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_index::IndexVec;
1313
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1414
use rustc_middle::middle::dependency_format::Linkage;
1515
use rustc_middle::middle::exported_symbols::ExportedSymbol;
16-
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, MaybeResult, TyAndLayout};
16+
use rustc_middle::ty::layout::{LayoutOf, MaybeResult, TyAndLayout};
1717
use rustc_middle::ty::{self, Binder, FloatTy, FnSig, IntTy, Ty, TyCtxt, UintTy};
1818
use rustc_session::config::CrateType;
1919
use rustc_span::{Span, Symbol};

0 commit comments

Comments
 (0)