Skip to content

Commit

Permalink
Rollup merge of #96697 - oli-obk:trace_queries, r=michaelwoerister
Browse files Browse the repository at this point in the history
Enable tracing for all queries

This allows you to log everything within a specific query, e.g.

```
env RUSTC_LOG=[mir_borrowck]
```

dumping all borrowck queries may be a bit verbose, so you can also restrict it to just an item of your choice:

```
env RUSTC_LOG=[mir_borrowck{key=\.\*name_of_item\.\*}]
```

the regex `.*` in the key name are because the key is a debug printed DefId, so you'd get all kinds of things like hashes in there. The tracing logs will show you the key, so you can restrict it further if you want.
  • Loading branch information
JohnTitor authored May 5, 2022
2 parents e3ada27 + 0d5a738 commit ade1232
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4245,6 +4245,7 @@ dependencies = [
"rustc_serialize",
"rustc_session",
"rustc_span",
"tracing",
]

[[package]]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_query_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rustc_query_system = { path = "../rustc_query_system" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
tracing = "0.1"

[features]
rustc_use_parallel_compiler = ["rustc-rayon-core", "rustc_query_system/rustc_use_parallel_compiler"]
3 changes: 3 additions & 0 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ macro_rules! define_queries {

fn force_from_dep_node(tcx: TyCtxt<'_>, dep_node: DepNode) -> bool {
if let Some(key) = recover(tcx, dep_node) {
#[cfg(debug_assertions)]
let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered();
let tcx = QueryCtxt::from_tcx(tcx);
force_query::<queries::$name<'_>, _>(tcx, key, dep_node);
true
Expand Down Expand Up @@ -532,6 +534,7 @@ macro_rules! define_queries_struct {

$($(#[$attr])*
#[inline(always)]
#[tracing::instrument(level = "trace", skip(self, tcx))]
fn $name(
&'tcx self,
tcx: TyCtxt<$tcx>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ where
}
}

#[derive(Debug)]
pub enum QueryMode {
Get,
Ensure,
Expand All @@ -697,7 +698,6 @@ where
None
};

debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
let (result, dep_node_index) = try_execute_query(
tcx,
Q::query_state(tcx),
Expand Down

0 comments on commit ade1232

Please sign in to comment.