Add tracing in Miri for tcx.layout_of
calls
#142721
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is meant for Miri, but requires a few changes in
rustc
code, hence why it's here. It adds tracing capabilities to thelayout_of
function intcx
by overriding thelayout_of
query (underlocal_providers
) with a wrapper that opens a tracing span and then calls the actuallayout_of
. To make this possible, I had to makerustc_ty_utils::layout::layout_of
public. I added an assert to ensure theproviders.layout_of
value I am replacing is actuallyrustc_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 makinglayout_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 ofproviders.layout_of
. Using a global variable would work but would rely onunsafe
or onMutex
es, so I wanted to avoid it.This PR also adds a tracing call in
instantiate_from_frame_and_normalize_erasing_regions
.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.jsonAnother 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 (sinceLayoutCx::new()
is used everywhere and referenced directly), and in any case it seems likespanned_layout_of()
just callstcx.layout_of()
anyway. For completeness' sake, here is tracing output for when a tracing call is added tospanned_layout_of()
: trace-1750340887920584.jsonNote: this PR is not ready yet as it requires rust-lang/miri#4406 to disable the changes in the Miri code when "tracing" is disabled. I will also add more comments then, if you think my approach is ok.
r? @RalfJung