Print chalk programs in debug output

This commit is contained in:
Wilco Kusee 2020-07-13 22:03:26 +02:00
parent f1f73649a6
commit 58e338a729
2 changed files with 19 additions and 12 deletions

View File

@ -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<chalk_ir::InEnvironment<chalk_ir::Goal<Interner>>>,
) -> Option<chalk_solve::Solution<Interner>> {
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
}

View File

@ -240,20 +240,22 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
Substs::empty().to_chalk(self.db)
}
fn trait_name(&self, _trait_id: chalk_ir::TraitId<Interner>) -> String {
unimplemented!()
fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> 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<Interner>) -> String {
unimplemented!()
// FIXME: lookup names
fn adt_name(&self, struct_id: chalk_ir::AdtId<Interner>) -> String {
format!("Adt_{:?}", struct_id.0).replace("TypeCtorId(", "").replace(")", "")
}
fn assoc_type_name(&self, _assoc_ty_id: chalk_ir::AssocTypeId<Interner>) -> String {
unimplemented!()
fn assoc_type_name(&self, assoc_ty_id: chalk_ir::AssocTypeId<Interner>) -> String {
format!("Assoc_{}", assoc_ty_id.0)
}
fn opaque_type_name(&self, _opaque_ty_id: chalk_ir::OpaqueTyId<Interner>) -> String {
unimplemented!()
fn opaque_type_name(&self, opaque_ty_id: chalk_ir::OpaqueTyId<Interner>) -> String {
format!("Opaque_{}", opaque_ty_id.0)
}
fn fn_def_name(&self, _fn_def_id: chalk_ir::FnDefId<Interner>) -> String {
unimplemented!()
fn fn_def_name(&self, fn_def_id: chalk_ir::FnDefId<Interner>) -> String {
format!("fn_{}", fn_def_id.0)
}
}