Skip to content

Add TRACING_ENABLED to Machine and add enter_trace_span!() #140972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2025

Conversation

Stypox
Copy link
Contributor

@Stypox Stypox commented May 13, 2025

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:

let _guard = enter_trace_span!(M, "eval_statement", "{:?}", stmt);

r? @RalfJung

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 13, 2025

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@Stypox Stypox force-pushed the machine-tracing-flag branch from af8f491 to 7261a79 Compare May 13, 2025 16:39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a new module for that -- please just put this into the existing util module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and force-pushed

@RalfJung
Copy link
Member

@rustbot author

Given how simple this PR is, feel free to just amend and force-push, so that we avoid another round-trip for a final squash.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 20, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Stypox Stypox force-pushed the machine-tracing-flag branch from 7261a79 to 28db348 Compare May 20, 2025 15:29
@RalfJung
Copy link
Member

Please remember to
@rustbot ready
:)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 20, 2025
@RalfJung
Copy link
Member

LGTM, thanks!
@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 20, 2025

📌 Commit 28db348 has been approved by RalfJung

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 20, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 20, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#140972 (Add TRACING_ENABLED to Machine and add enter_trace_span!())
 - rust-lang#141282 (`core_float_math`: Move functions to `math` module)
 - rust-lang#141288 (Get rid of unnecessary `BufDisplay` abstraction)
 - rust-lang#141289 (use `Self` alias in self types rather than manually substituting it)
 - rust-lang#141291 (link tracking issue in explicit-extern-abis.md)
 - rust-lang#141294 (triagebot: ping me if rustdoc js is modified)
 - rust-lang#141303 (Fix pagetoc inactive color in rustc book)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 221d6c7 into rust-lang:master May 21, 2025
6 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 21, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 21, 2025
Rollup merge of rust-lang#140972 - Stypox:machine-tracing-flag, r=RalfJung

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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants