mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Improve Chalk debugging
- add panic context for the trait goal if CHALK_DEBUG is set - print the Chalk program even if we're panicking - log goal/solution while TLS is still set
This commit is contained in:
parent
dd8a75b2cf
commit
baeb16e83f
1 changed files with 23 additions and 7 deletions
|
@ -5,6 +5,7 @@ use base_db::CrateId;
|
||||||
use chalk_ir::cast::Cast;
|
use chalk_ir::cast::Cast;
|
||||||
use chalk_solve::{logging_db::LoggingRustIrDatabase, Solver};
|
use chalk_solve::{logging_db::LoggingRustIrDatabase, Solver};
|
||||||
use hir_def::{lang_item::LangItemTarget, TraitId};
|
use hir_def::{lang_item::LangItemTarget, TraitId};
|
||||||
|
use stdx::panic_context;
|
||||||
|
|
||||||
use crate::{db::HirDatabase, DebruijnIndex, Substs};
|
use crate::{db::HirDatabase, DebruijnIndex, Substs};
|
||||||
|
|
||||||
|
@ -168,14 +169,23 @@ fn solve(
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut solve = || {
|
let mut solve = || {
|
||||||
if is_chalk_print() {
|
let _ctx = if is_chalk_debug() || is_chalk_print() {
|
||||||
let logging_db = LoggingRustIrDatabase::new(context);
|
Some(panic_context::enter(format!("solving {:?}", goal)))
|
||||||
let solution = solver.solve_limited(&logging_db, goal, &should_continue);
|
} else {
|
||||||
log::debug!("chalk program:\n{}", logging_db);
|
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
|
solution
|
||||||
} else {
|
} else {
|
||||||
solver.solve_limited(&context, goal, &should_continue)
|
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
|
// don't set the TLS for Chalk unless Chalk debugging is active, to make
|
||||||
|
@ -183,11 +193,17 @@ fn solve(
|
||||||
let solution =
|
let solution =
|
||||||
if is_chalk_debug() { chalk::tls::set_current_program(db, solve) } else { solve() };
|
if is_chalk_debug() { chalk::tls::set_current_program(db, solve) } else { solve() };
|
||||||
|
|
||||||
log::debug!("solve({:?}) => {:?}", goal, solution);
|
|
||||||
|
|
||||||
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 {
|
fn is_chalk_debug() -> bool {
|
||||||
std::env::var("CHALK_DEBUG").is_ok()
|
std::env::var("CHALK_DEBUG").is_ok()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue