From 20663a2a8b8960097ee71d9ed66d9227368c93f1 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Wed, 9 Sep 2020 12:55:05 -0400 Subject: Lookup ADT and assoc. type names for chalk debug --- crates/hir_ty/src/traits/chalk.rs | 14 +++++++++----- crates/hir_ty/src/traits/chalk/mapping.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 17c83b6a4..01b5717a3 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -244,13 +244,17 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { let id = from_chalk(self.db, trait_id); self.db.trait_data(id).name.to_string() } - // FIXME: lookup names - fn adt_name(&self, struct_id: chalk_ir::AdtId) -> String { - let datum = self.db.struct_datum(self.krate, struct_id); - format!("{:?}", datum.name(&Interner)) + fn adt_name(&self, adt_id: chalk_ir::AdtId) -> String { + let id = from_chalk(self.db, adt_id); + match id { + hir_def::AdtId::StructId(id) => self.db.struct_data(id).name.to_string(), + hir_def::AdtId::EnumId(id) => self.db.enum_data(id).name.to_string(), + hir_def::AdtId::UnionId(id) => self.db.union_data(id).name.to_string(), + } } fn assoc_type_name(&self, assoc_ty_id: chalk_ir::AssocTypeId) -> String { - format!("Assoc_{}", assoc_ty_id.0) + let id = self.db.associated_ty_data(assoc_ty_id).name; + self.db.type_alias_data(id).name.to_string() } fn opaque_type_name(&self, opaque_ty_id: chalk_ir::OpaqueTyId) -> String { format!("Opaque_{}", opaque_ty_id.0) diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index fe62f3fa7..d6bacba1d 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -464,6 +464,18 @@ impl ToChalk for hir_def::ImplId { } } +impl ToChalk for hir_def::AdtId { + type Chalk = AdtId; + + fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk { + chalk_ir::AdtId(self.into()) + } + + fn from_chalk(_db: &dyn HirDatabase, id: AdtId) -> Self { + id.0 + } +} + impl ToChalk for CallableDefId { type Chalk = FnDefId; -- cgit v1.2.3 From bf0b194fed03d88b1217e921799638cb80bb9df8 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Wed, 9 Sep 2020 12:55:38 -0400 Subject: Tweak interner for chalk --- crates/hir_ty/src/traits/chalk/interner.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index fc0f9c201..eb35db3ff 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs @@ -26,7 +26,7 @@ pub type OpaqueTyId = chalk_ir::OpaqueTyId; pub type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum; impl chalk_ir::interner::Interner for Interner { - type InternedType = Box>; // FIXME use Arc? + type InternedType = Arc>; type InternedLifetime = chalk_ir::LifetimeData; type InternedConst = Arc>; type InternedConcreteConst = (); @@ -34,7 +34,7 @@ impl chalk_ir::interner::Interner for Interner { type InternedGoal = Arc>; type InternedGoals = Vec>; type InternedSubstitution = Vec>; - type InternedProgramClause = chalk_ir::ProgramClauseData; + type InternedProgramClause = Arc>; type InternedProgramClauses = Arc<[chalk_ir::ProgramClause]>; type InternedQuantifiedWhereClauses = Vec>; type InternedVariableKinds = Vec>; @@ -197,11 +197,11 @@ impl chalk_ir::interner::Interner for Interner { tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt))) } - fn intern_ty(&self, ty: chalk_ir::TyData) -> Box> { - Box::new(ty) + fn intern_ty(&self, ty: chalk_ir::TyData) -> Arc> { + Arc::new(ty) } - fn ty_data<'a>(&self, ty: &'a Box>) -> &'a chalk_ir::TyData { + fn ty_data<'a>(&self, ty: &'a Arc>) -> &'a chalk_ir::TyData { ty } @@ -230,7 +230,7 @@ impl chalk_ir::interner::Interner for Interner { constant } - fn const_eq(&self, _ty: &Box>, _c1: &(), _c2: &()) -> bool { + fn const_eq(&self, _ty: &Arc>, _c1: &(), _c2: &()) -> bool { true } @@ -284,13 +284,13 @@ impl chalk_ir::interner::Interner for Interner { fn intern_program_clause( &self, data: chalk_ir::ProgramClauseData, - ) -> chalk_ir::ProgramClauseData { - data + ) -> Arc> { + Arc::new(data) } fn program_clause_data<'a>( &self, - clause: &'a chalk_ir::ProgramClauseData, + clause: &'a Arc>, ) -> &'a chalk_ir::ProgramClauseData { clause } -- cgit v1.2.3