From 58e338a72996edc4b29f4fdada9d5b33c54ad608 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Mon, 13 Jul 2020 22:03:26 +0200 Subject: Print chalk programs in debug output --- crates/hir_ty/src/traits.rs | 9 +++++++-- crates/hir_ty/src/traits/chalk.rs | 22 ++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index 255323717..6a012cd6a 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use base_db::CrateId; use chalk_ir::cast::Cast; -use chalk_solve::Solver; +use chalk_solve::{logging_db::LoggingRustIrDatabase, Solver}; use hir_def::{lang_item::LangItemTarget, TraitId}; use crate::{db::HirDatabase, DebruijnIndex, Substs}; @@ -152,6 +152,9 @@ fn solve( goal: &chalk_ir::UCanonical>>, ) -> Option> { let context = ChalkContext { db, krate }; + + let logging_db = LoggingRustIrDatabase::new(context); + log::debug!("solve goal: {:?}", goal); let mut solver = create_chalk_solver(); @@ -167,7 +170,7 @@ fn solve( remaining > 0 }; let mut solve = || { - let solution = solver.solve_limited(&context, goal, should_continue); + let solution = solver.solve_limited(&logging_db, goal, should_continue); log::debug!("solve({:?}) => {:?}", goal, solution); solution }; @@ -176,6 +179,8 @@ fn solve( let solution = if is_chalk_debug() { chalk::tls::set_current_program(db, solve) } else { solve() }; + log::debug!("chalk program:\n{}", logging_db); + solution } diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index b33653417..08c2c9a3e 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -240,20 +240,22 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { Substs::empty().to_chalk(self.db) } - fn trait_name(&self, _trait_id: chalk_ir::TraitId) -> String { - unimplemented!() + fn trait_name(&self, trait_id: chalk_ir::TraitId) -> String { + let id = from_chalk(self.db, trait_id); + self.db.trait_data(id).name.to_string() } - fn adt_name(&self, _struct_id: chalk_ir::AdtId) -> String { - unimplemented!() + // FIXME: lookup names + fn adt_name(&self, struct_id: chalk_ir::AdtId) -> String { + format!("Adt_{:?}", struct_id.0).replace("TypeCtorId(", "").replace(")", "") } - fn assoc_type_name(&self, _assoc_ty_id: chalk_ir::AssocTypeId) -> String { - unimplemented!() + fn assoc_type_name(&self, assoc_ty_id: chalk_ir::AssocTypeId) -> String { + format!("Assoc_{}", assoc_ty_id.0) } - fn opaque_type_name(&self, _opaque_ty_id: chalk_ir::OpaqueTyId) -> String { - unimplemented!() + fn opaque_type_name(&self, opaque_ty_id: chalk_ir::OpaqueTyId) -> String { + format!("Opaque_{}", opaque_ty_id.0) } - fn fn_def_name(&self, _fn_def_id: chalk_ir::FnDefId) -> String { - unimplemented!() + fn fn_def_name(&self, fn_def_id: chalk_ir::FnDefId) -> String { + format!("fn_{}", fn_def_id.0) } } -- cgit v1.2.3 From 10c33275b0c571a27e5858645984611fc5b162bf Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Sun, 26 Jul 2020 12:27:25 +0200 Subject: Only use logging db if CHALK_DEBUG is active --- crates/hir_ty/src/traits.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index 6a012cd6a..4932eac45 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs @@ -152,9 +152,6 @@ fn solve( goal: &chalk_ir::UCanonical>>, ) -> Option> { let context = ChalkContext { db, krate }; - - let logging_db = LoggingRustIrDatabase::new(context); - log::debug!("solve goal: {:?}", goal); let mut solver = create_chalk_solver(); @@ -169,17 +166,23 @@ fn solve( } remaining > 0 }; - let mut solve = || { - let solution = solver.solve_limited(&logging_db, goal, should_continue); - log::debug!("solve({:?}) => {:?}", goal, solution); - solution + + let solution = if is_chalk_debug() { + let logging_db = LoggingRustIrDatabase::new(context); + let solve = || { + let solution = solver.solve_limited(&logging_db, goal, should_continue); + log::debug!("chalk program:\n{}", logging_db); + solution + }; + + // don't set the TLS for Chalk unless Chalk debugging is active, to make + // extra sure we only use it for debugging + chalk::tls::set_current_program(db, solve) + } else { + solver.solve_limited(&context, goal, should_continue) }; - // 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!("chalk program:\n{}", logging_db); + log::debug!("solve({:?}) => {:?}", goal, solution); solution } -- cgit v1.2.3 From 36052ce1a1c19379d67600b49d42f2e09e0450a7 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Sun, 26 Jul 2020 13:06:11 +0200 Subject: Lookup adt names --- crates/hir_ty/src/traits/chalk.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 08c2c9a3e..17c83b6a4 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -246,7 +246,8 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { } // FIXME: lookup names fn adt_name(&self, struct_id: chalk_ir::AdtId) -> String { - format!("Adt_{:?}", struct_id.0).replace("TypeCtorId(", "").replace(")", "") + let datum = self.db.struct_datum(self.krate, struct_id); + format!("{:?}", datum.name(&Interner)) } fn assoc_type_name(&self, assoc_ty_id: chalk_ir::AssocTypeId) -> String { format!("Assoc_{}", assoc_ty_id.0) -- cgit v1.2.3 From de282ddd869f78fc8324f2333204b10e93939d83 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Fri, 14 Aug 2020 14:47:06 +0200 Subject: Only print chalk programs with CHALK_PRINT --- crates/hir_ty/src/traits.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index 4932eac45..1c3abb18f 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs @@ -167,21 +167,22 @@ fn solve( remaining > 0 }; - let solution = if is_chalk_debug() { - let logging_db = LoggingRustIrDatabase::new(context); - let 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); solution - }; - - // don't set the TLS for Chalk unless Chalk debugging is active, to make - // extra sure we only use it for debugging - chalk::tls::set_current_program(db, solve) - } else { - solver.solve_limited(&context, goal, should_continue) + } else { + solver.solve_limited(&context, goal, should_continue) + } }; + // 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 @@ -191,6 +192,10 @@ fn is_chalk_debug() -> bool { std::env::var("CHALK_DEBUG").is_ok() } +fn is_chalk_print() -> bool { + std::env::var("CHALK_PRINT").is_ok() +} + fn solution_from_chalk( db: &dyn HirDatabase, solution: chalk_solve::Solution, -- cgit v1.2.3