Skip to content

Commit 5bf3a51

Browse files
authored
Merge pull request #525 from nathanwhit/tracing
Introduce Tracing into Chalk (Third Time's the Charm)
2 parents 28fcc72 + 9303b01 commit 5bf3a51

36 files changed

+414
-379
lines changed

Cargo.lock

Lines changed: 208 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ rustyline = "6.0.0"
2020
salsa = "0.10.0"
2121
serde = "1.0"
2222
serde_derive = "1.0"
23+
tracing-subscriber = "0.2"
2324

2425
chalk-derive = { version = "0.14.0-dev.0", path = "chalk-derive" }
2526
chalk-engine = { version = "0.14.0-dev.0", path = "chalk-engine" }
@@ -32,3 +33,4 @@ chalk-integration = { version = "0.14.0-dev.0", path = "chalk-integration" }
3233

3334
[dev-dependencies]
3435
pretty_assertions = "0.6.1"
36+
tracing = "0.1"

book/src/contribution_guide.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,27 @@ $ cargo run
4848
Unique; substitution [], lifetime constraints []
4949
```
5050

51-
More logging can be enabled by setting the `CHALK_DEBUG` environment variable. Set `CHALK_DEBUG=1` to see `info!(...)` output, and `CHALK_DEBUG=2` to see `debug!(...)` output as well.
51+
More logging can be enabled by setting the `CHALK_DEBUG` environment variable. Set `CHALK_DEBUG=3` or `CHALK_DEBUG=info` to see `info!(...)` output, and `CHALK_DEBUG=4` or `CHALK_DEBUG=debug` to see `debug!(...)` output as well. In addition, logs may be filtered in a number of ways. The syntax for filtering logs is:
52+
53+
```notrust
54+
target[span{field=value}]=level
55+
```
56+
57+
(Note: all parts of the filter are optional )
58+
59+
In more detail, the filter may consist of:
60+
61+
- A target (location of origin)
62+
- For example setting `CHALK_DEBUG='chalk_solve::infer::unify'` will filter logs to show only output originating from `chalk_solve::infer::unify`.
63+
- A span (name provided to the logging macros, for instance `unify_var_ty` in `debug_span!("unify_var_ty")`)
64+
- For example setting `CHALK_DEBUG='[unify_ty_ty]'` will show only logs where the span contains `unify_ty_ty`.
65+
- A list of fields (variables recorded in the logs), for instance `ty` in `debug!("unify_var_ty", ?ty)` with values optionally specified
66+
- For example setting `CHALK_DEBUG='[{ty}]'` will show only logs which contain a variable `ty`
67+
- Setting `CHALK_DEBUG='[{ty=Bar}]'` will show only logs which contain a variable `ty` with the value `Bar`
68+
- A maximum log level (one of `info`, `debug`, `trace`) which shows logs at or below the given level
69+
70+
More documentation on the syntax and options can be found [here](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#Directives).
71+
5272

5373
## Pull Requests
5474
[pull-requests]: #pull-requests

chalk-engine/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ default = []
1414

1515
[dependencies]
1616
rustc-hash = { version = "1.1.0" }
17+
tracing = "0.1"
1718

1819
chalk-derive = { version = "0.14.0-dev.0", path = "../chalk-derive" }
1920
chalk-ir = { version = "0.14.0-dev.0", path = "../chalk-ir" }

chalk-engine/src/forest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::table::AnswerIndex;
44
use crate::tables::Tables;
55
use crate::{TableIndex, TimeStamp};
66

7-
use chalk_ir::debug;
87
use chalk_ir::interner::Interner;
98
use chalk_ir::{Goal, InEnvironment, Substitution, UCanonical};
9+
use tracing::debug;
1010

1111
pub struct Forest<I: Interner, C: Context<I>> {
1212
pub(crate) tables: Tables<I>,

chalk-engine/src/logic.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use crate::{
1111
};
1212

1313
use chalk_ir::interner::Interner;
14-
use chalk_ir::{debug, debug_heading, info, info_heading};
1514
use chalk_ir::{
1615
Canonical, ConstrainedSubst, DomainGoal, Floundered, Goal, GoalData, InEnvironment, NoSolution,
1716
Substitution, UCanonical, UniverseMap, WhereClause,
1817
};
18+
use tracing::{debug, debug_span, info, instrument};
1919

2020
type RootSearchResult<T> = Result<T, RootSearchFail>;
2121

@@ -179,14 +179,13 @@ impl<I: Interner, C: Context<I>> Forest<I, C> {
179179
/// In terms of the NFTD paper, creating a new table corresponds
180180
/// to the *New Subgoal* step as well as the *Program Clause
181181
/// Resolution* steps.
182+
#[instrument(level = "debug", skip(self, context, infer))]
182183
fn get_or_create_table_for_subgoal(
183184
&mut self,
184185
context: &impl ContextOps<I, C>,
185186
infer: &mut dyn InferenceTable<I, C>,
186187
subgoal: &Literal<I>,
187188
) -> Option<(TableIndex, UniverseMap)> {
188-
debug_heading!("get_or_create_table_for_subgoal(subgoal={:?})", subgoal);
189-
190189
// Subgoal abstraction:
191190
let (ucanonical_subgoal, universe_map) = match subgoal {
192191
Literal::Positive(subgoal) => {
@@ -212,19 +211,18 @@ impl<I: Interner, C: Context<I>> Forest<I, C> {
212211
/// In terms of the NFTD paper, creating a new table corresponds
213212
/// to the *New Subgoal* step as well as the *Program Clause
214213
/// Resolution* steps.
214+
#[instrument(level = "debug", skip(self, context))]
215215
pub(crate) fn get_or_create_table_for_ucanonical_goal(
216216
&mut self,
217217
context: &impl ContextOps<I, C>,
218218
goal: UCanonical<InEnvironment<Goal<I>>>,
219219
) -> TableIndex {
220-
debug_heading!("get_or_create_table_for_ucanonical_goal({:?})", goal);
221-
222220
if let Some(table) = self.tables.index_of(&goal) {
223221
debug!("found existing table {:?}", table);
224222
return table;
225223
}
226224

227-
info_heading!(
225+
info!(
228226
"creating new table {:?} and goal {:#?}",
229227
self.tables.next_index(),
230228
goal
@@ -436,16 +434,12 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
436434
/// This function first attempts to fetch answer that is cached in
437435
/// the table. If none is found, then it will recursively search
438436
/// to find an answer.
437+
#[instrument(level = "info", skip(self))]
439438
fn ensure_root_answer(
440439
&mut self,
441440
initial_table: TableIndex,
442441
initial_answer: AnswerIndex,
443442
) -> RootSearchResult<()> {
444-
info_heading!(
445-
"ensure_answer(table={:?}, answer={:?})",
446-
initial_table,
447-
initial_answer
448-
);
449443
info!(
450444
"table goal = {:#?}",
451445
self.forest.tables[initial_table].table_goal
@@ -1529,11 +1523,13 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
15291523
/// subgoal list and adds it to the strand's floundered subgoal
15301524
/// list.
15311525
fn flounder_subgoal(&self, ex_clause: &mut ExClause<I>, subgoal_index: usize) {
1532-
info_heading!(
1533-
"flounder_subgoal(answer_time={:?}, subgoal={:?})",
1534-
ex_clause.answer_time,
1535-
ex_clause.subgoals[subgoal_index],
1526+
let _s = debug_span!(
1527+
"flounder_subgoal",
1528+
answer_time = ?ex_clause.answer_time,
1529+
subgoal = ?ex_clause.subgoals[subgoal_index],
15361530
);
1531+
let _s = _s.enter();
1532+
15371533
let floundered_time = ex_clause.answer_time;
15381534
let floundered_literal = ex_clause.subgoals.remove(subgoal_index);
15391535
ex_clause.floundered_subgoals.push(FlounderedSubgoal {

chalk-engine/src/simplify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use crate::context::{Context, ContextOps, InferenceTable};
22
use crate::forest::Forest;
33
use crate::{ExClause, Literal, TimeStamp};
44

5-
use chalk_ir::debug;
65
use chalk_ir::interner::Interner;
76
use chalk_ir::{
87
Constraint, DomainGoal, Environment, Fallible, Goal, GoalData, InEnvironment, LifetimeOutlives,
98
QuantifierKind, Substitution, WhereClause,
109
};
10+
use tracing::debug;
1111

1212
impl<I: Interner, C: Context<I>> Forest<I, C> {
1313
/// Simplifies a goal into a series of positive domain goals

chalk-engine/src/table.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::collections::VecDeque;
77
use std::mem;
88

99
use chalk_ir::interner::Interner;
10-
use chalk_ir::{debug, debug_heading, info};
1110
use chalk_ir::{AnswerSubst, Canonical, Goal, InEnvironment, UCanonical};
11+
use tracing::{debug, info, instrument};
1212

1313
pub(crate) struct Table<I: Interner> {
1414
/// The goal this table is trying to solve (also the key to look
@@ -133,10 +133,9 @@ impl<I: Interner> Table<I> {
133133
/// tests trigger this case, and assumptions upstream assume that when
134134
/// `true` is returned here, that a *new* answer was added (instead of an)
135135
/// existing answer replaced.
136+
#[instrument(level = "debug", skip(self))]
136137
pub(super) fn push_answer(&mut self, answer: Answer<I>) -> Option<AnswerIndex> {
137138
assert!(!self.floundered);
138-
139-
debug_heading!("push_answer(answer={:?})", answer);
140139
debug!(
141140
"pre-existing entry: {:?}",
142141
self.answers_hash.get(&answer.subst)

chalk-integration/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ publish = false
1212
[dependencies]
1313
string_cache = "0.8.0"
1414
salsa = "0.10.0"
15+
tracing = "0.1"
1516

1617
chalk-derive = { version = "0.14.0-dev.0", path = "../chalk-derive" }
1718
chalk-engine = { version = "0.14.0-dev.0", path = "../chalk-engine" }

chalk-integration/src/lowering.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use chalk_ir::{
55
self, AdtId, AssocTypeId, BoundVar, ClausePriority, DebruijnIndex, FnDefId, ImplId, OpaqueTyId,
66
QuantifiedWhereClauses, Substitution, ToGenericArg, TraitId, TyKind,
77
};
8-
use chalk_ir::{debug, debug_heading};
98
use chalk_parse::ast::*;
109
use chalk_solve::rust_ir::{
1110
self, Anonymize, AssociatedTyValueId, IntoWhereClauses, OpaqueTyDatum, OpaqueTyDatumBound,
1211
};
1312
use std::collections::{BTreeMap, HashSet};
1413
use std::sync::Arc;
1514
use string_cache::DefaultAtom as Atom;
15+
use tracing::{debug, instrument};
1616

1717
use crate::error::RustIrError;
1818
use crate::program::Program as LoweredProgram;
@@ -1591,14 +1591,13 @@ trait LowerImpl {
15911591
}
15921592

15931593
impl LowerImpl for Impl {
1594+
#[instrument(level = "debug", skip(self, empty_env, associated_ty_value_ids))]
15941595
fn lower_impl(
15951596
&self,
15961597
empty_env: &Env,
15971598
impl_id: ImplId<ChalkIr>,
15981599
associated_ty_value_ids: &AssociatedTyValueIds,
15991600
) -> LowerResult<rust_ir::ImplDatum<ChalkIr>> {
1600-
debug_heading!("LowerImpl::lower_impl(impl_id={:?})", impl_id);
1601-
16021601
let polarity = self.polarity.lower();
16031602
let binders = empty_env.in_binders(self.all_parameters(), |env| {
16041603
let trait_ref = self.trait_ref.lower(env)?;

chalk-ir/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ edition = "2018"
1212
[dependencies]
1313
lazy_static = "1.4.0"
1414
chalk-derive = { version = "0.14.0-dev.0", path = "../chalk-derive" }
15-

chalk-ir/src/debug_macros.rs

Lines changed: 0 additions & 127 deletions
This file was deleted.

chalk-ir/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ pub mod fold;
5151
#[macro_use]
5252
pub mod visit;
5353

54-
#[macro_use]
55-
pub mod debug_macros;
56-
5754
pub mod cast;
5855

5956
pub mod interner;

chalk-solve/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ edition = "2018"
1313
ena = "0.14.0"
1414
itertools = "0.9.0"
1515
petgraph = "0.5.0"
16+
tracing = "0.1"
1617
rustc-hash = { version = "1.0.0" }
1718

1819
chalk-derive = { version = "0.14.0-dev.0", path = "../chalk-derive" }

0 commit comments

Comments
 (0)