Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 17 additions & 4 deletions crates/hir_ty/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -166,23 +166,36 @@ fn solve(
}
remaining > 0
};

let mut solve = || {
let solution = solver.solve_limited(&context, goal, should_continue);
log::debug!("solve({:?}) => {:?}", goal, solution);
solution
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
} 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
}

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<Interner>,
Expand Down
23 changes: 13 additions & 10 deletions crates/hir_ty/src/traits/chalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,23 @@ 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 {
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<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)
}
}

Expand Down