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/hir_ty/src') 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