Skip to content

Commit ab14138

Browse files
Rollup merge of #142721 - Stypox:tracing-layout-of, r=RalfJung
Add tracing to `InterpCx::layout_of()` This PR adds tracing calls to `instantiate_from_frame_and_normalize_erasing_regions` and to `InterpCx::layout_of()`. The latter is done by shadowing `LayoutOf`'s trait method with an inherent method on `InterpCx`. <details><summary>Previous attempt by overriding the `layout_of` query (includes downloadable `.diff` patch)</summary> This PR is meant for Miri, but requires a few changes in `rustc` code, hence why it's here. It adds tracing capabilities to the `layout_of` function in `tcx` by overriding the `layout_of` query (under `local_providers`) with a wrapper that opens a tracing span and then calls the actual `layout_of`. To make this possible, I had to make `rustc_ty_utils::layout::layout_of` public. I added an assert to ensure the `providers.layout_of` value I am replacing is actually `rustc_ty_utils::layout::layout_of`, just in case. I also considered taking the previous value in `providers.layout_of` and calling that one instead, to avoid making `layout_of` public. But then the closure would not be castable to a function pointer anymore (`providers.layout_of` is a function pointer), because it would depend on the local variable storing the previous value of `providers.layout_of`. Using a global variable would work but would rely on `unsafe` or on `Mutex`es, so I wanted to avoid it. Here is some tracing output when Miri is run on `src/tools/miri/tests/pass/hello.rs`, visualizable in https://ui.perfetto.dev: [trace-1750338860374637.json](https://github.com/user-attachments/files/20820392/trace-1750338860374637.json) Another place where I could have added tracing calls is to the `rustc_middle::ty::layout::LayoutCx` struct / `spanned_layout_of()` function, however there is no simple way to disable the tracing calls with compile-time boolean constants there (since `LayoutCx::new()` is used everywhere and referenced directly), and in any case it seems like `spanned_layout_of()` just calls `tcx.layout_of()` anyway. For completeness' sake, here is tracing output for when a tracing call is added to `spanned_layout_of()`: [trace-1750340887920584.json](https://github.com/user-attachments/files/20820609/trace-1750340887920584.json) Patch to override `layout_of` query: [tracing-layout_of-query-override.diff.txt](https://github.com/user-attachments/files/20944497/tracing-layout_of-query-override.diff.txt) </details> **Note: obtaining tracing output depends on #4406, but this PR is standalone and can be merged without waiting for #4406 r? `@RalfJung`
2 parents f568c0e + a6b7dfc commit ab14138

File tree

12 files changed

+1
-12
lines changed

12 files changed

+1
-12
lines changed

src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_abi::ExternAbi;
1111
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1212
use rustc_hir::def::Namespace;
1313
use rustc_hir::def_id::DefId;
14-
use rustc_middle::ty::layout::{LayoutCx, LayoutOf};
14+
use rustc_middle::ty::layout::LayoutCx;
1515
use rustc_middle::ty::{self, Ty, TyCtxt};
1616
use rustc_session::config::EntryFnType;
1717

src/intrinsics/simd.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use rand::Rng;
33
use rustc_abi::{Endian, HasDataLayout};
44
use rustc_apfloat::{Float, Round};
55
use rustc_middle::ty::FloatTy;
6-
use rustc_middle::ty::layout::LayoutOf;
76
use rustc_middle::{mir, ty};
87
use rustc_span::{Symbol, sym};
98

src/shims/backtrace.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_abi::{CanonAbi, FieldIdx, Size};
2-
use rustc_middle::ty::layout::LayoutOf as _;
32
use rustc_middle::ty::{self, Instance, Ty};
43
use rustc_span::{BytePos, Loc, Symbol, hygiene};
54
use rustc_target::callconv::FnAbi;

src/shims/os_str.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::os::windows::ffi::{OsStrExt, OsStringExt};
77
use std::path::{Path, PathBuf};
88

99
use rustc_middle::ty::Ty;
10-
use rustc_middle::ty::layout::LayoutOf;
1110

1211
use crate::*;
1312

src/shims/unix/env.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_abi::{FieldIdx, Size};
66
use rustc_data_structures::fx::FxHashMap;
77
use rustc_index::IndexVec;
88
use rustc_middle::ty::Ty;
9-
use rustc_middle::ty::layout::LayoutOf;
109

1110
use crate::*;
1211

src/shims/unix/foreign_items.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::str;
33

44
use rustc_abi::{CanonAbi, ExternAbi, Size};
55
use rustc_middle::ty::Ty;
6-
use rustc_middle::ty::layout::LayoutOf;
76
use rustc_span::Symbol;
87
use rustc_target::callconv::FnAbi;
98

src/shims/windows/thread.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_abi::ExternAbi;
2-
use rustc_middle::ty::layout::LayoutOf;
32

43
use self::shims::windows::handle::{EvalContextExt as _, Handle, PseudoHandle};
54
use crate::*;

src/shims/x86/aesni.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_abi::CanonAbi;
22
use rustc_middle::ty::Ty;
3-
use rustc_middle::ty::layout::LayoutOf as _;
43
use rustc_span::Symbol;
54
use rustc_target::callconv::FnAbi;
65

src/shims/x86/avx.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rustc_abi::CanonAbi;
22
use rustc_apfloat::ieee::{Double, Single};
33
use rustc_middle::mir;
44
use rustc_middle::ty::Ty;
5-
use rustc_middle::ty::layout::LayoutOf as _;
65
use rustc_span::Symbol;
76
use rustc_target::callconv::FnAbi;
87

src/shims/x86/avx2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc_abi::CanonAbi;
22
use rustc_middle::mir;
33
use rustc_middle::ty::Ty;
4-
use rustc_middle::ty::layout::LayoutOf as _;
54
use rustc_span::Symbol;
65
use rustc_target::callconv::FnAbi;
76

0 commit comments

Comments
 (0)