Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions crates/hir_ty/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use base_db::CrateId;
use chalk_ir::cast::Cast;
use chalk_solve::{logging_db::LoggingRustIrDatabase, Solver};
use hir_def::{lang_item::LangItemTarget, TraitId};
use stdx::panic_context;

use crate::{db::HirDatabase, DebruijnIndex, Substs};

Expand Down Expand Up @@ -168,26 +169,41 @@ fn solve(
};

let mut solve = || {
if is_chalk_print() {
let logging_db = LoggingRustIrDatabase::new(context);
let solution = solver.solve_limited(&logging_db, goal, &should_continue);
log::debug!("chalk program:\n{}", logging_db);
let _ctx = if is_chalk_debug() || is_chalk_print() {
Some(panic_context::enter(format!("solving {:?}", goal)))
} else {
None
};
let solution = if is_chalk_print() {
let logging_db =
LoggingRustIrDatabaseLoggingOnDrop(LoggingRustIrDatabase::new(context));
let solution = solver.solve_limited(&logging_db.0, goal, &should_continue);
solution
} else {
solver.solve_limited(&context, goal, &should_continue)
}
};

log::debug!("solve({:?}) => {:?}", goal, solution);

solution
};

// don't set the TLS for Chalk unless Chalk debugging is active, to make
// extra sure we only use it for debugging
let solution =
if is_chalk_debug() { chalk::tls::set_current_program(db, solve) } else { solve() };

log::debug!("solve({:?}) => {:?}", goal, solution);

solution
}

struct LoggingRustIrDatabaseLoggingOnDrop<'a>(LoggingRustIrDatabase<Interner, ChalkContext<'a>>);

impl<'a> Drop for LoggingRustIrDatabaseLoggingOnDrop<'a> {
fn drop(&mut self) {
eprintln!("chalk program:\n{}", self.0);
}
}

fn is_chalk_debug() -> bool {
std::env::var("CHALK_DEBUG").is_ok()
}
Expand Down