From aebcf7b5d4a37a08f2a64f7660b7e3d890476dba Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 9 May 2021 20:05:43 +0200 Subject: Better Debug impl for InternedWrapper --- crates/hir_ty/src/interner.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/hir_ty/src/interner.rs') diff --git a/crates/hir_ty/src/interner.rs b/crates/hir_ty/src/interner.rs index 7b4119747..8e77378ab 100644 --- a/crates/hir_ty/src/interner.rs +++ b/crates/hir_ty/src/interner.rs @@ -15,9 +15,15 @@ use std::{fmt, sync::Arc}; #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct Interner; -#[derive(PartialEq, Eq, Hash, Debug)] +#[derive(PartialEq, Eq, Hash)] pub struct InternedWrapper(T); +impl fmt::Debug for InternedWrapper { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self.0, f) + } +} + impl std::ops::Deref for InternedWrapper { type Target = T; -- cgit v1.2.3 From 29266ada0469440d69fd3f3532121a7e8ff5379d Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 15 May 2021 22:26:55 +0200 Subject: Improve debug printing without TLS --- crates/hir_ty/src/interner.rs | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'crates/hir_ty/src/interner.rs') diff --git a/crates/hir_ty/src/interner.rs b/crates/hir_ty/src/interner.rs index 8e77378ab..29ffdd9b7 100644 --- a/crates/hir_ty/src/interner.rs +++ b/crates/hir_ty/src/interner.rs @@ -107,66 +107,65 @@ impl chalk_ir::interner::Interner for Interner { opaque_ty: &chalk_ir::OpaqueTy, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_opaque_ty(opaque_ty, fmt))) + Some(write!(fmt, "{:?}", opaque_ty.opaque_ty_id)) } fn debug_opaque_ty_id( opaque_ty_id: chalk_ir::OpaqueTyId, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_opaque_ty_id(opaque_ty_id, fmt))) + Some(fmt.debug_struct("OpaqueTyId").field("index", &opaque_ty_id.0).finish()) } fn debug_ty(ty: &chalk_ir::Ty, fmt: &mut fmt::Formatter<'_>) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_ty(ty, fmt))) + Some(write!(fmt, "{:?}", ty.data(&Interner))) } fn debug_lifetime( lifetime: &chalk_ir::Lifetime, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_lifetime(lifetime, fmt))) + Some(write!(fmt, "{:?}", lifetime.data(&Interner))) } fn debug_generic_arg( parameter: &GenericArg, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) + Some(write!(fmt, "{:?}", parameter.data(&Interner).inner_debug())) } fn debug_goal(goal: &Goal, fmt: &mut fmt::Formatter<'_>) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_goal(goal, fmt))) + let goal_data = goal.data(&Interner); + Some(write!(fmt, "{:?}", goal_data)) } fn debug_goals( goals: &chalk_ir::Goals, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_goals(goals, fmt))) + Some(write!(fmt, "{:?}", goals.debug(&Interner))) } fn debug_program_clause_implication( pci: &chalk_ir::ProgramClauseImplication, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_program_clause_implication(pci, fmt))) + Some(write!(fmt, "{:?}", pci.debug(&Interner))) } fn debug_substitution( substitution: &chalk_ir::Substitution, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_substitution(substitution, fmt))) + Some(write!(fmt, "{:?}", substitution.debug(&Interner))) } fn debug_separator_trait_ref( separator_trait_ref: &chalk_ir::SeparatorTraitRef, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| { - Some(prog?.debug_separator_trait_ref(separator_trait_ref, fmt)) - }) + Some(write!(fmt, "{:?}", separator_trait_ref.debug(&Interner))) } fn debug_fn_def_id( @@ -179,47 +178,43 @@ impl chalk_ir::interner::Interner for Interner { constant: &chalk_ir::Const, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_const(constant, fmt))) + Some(write!(fmt, "{:?}", constant.data(&Interner))) } fn debug_variable_kinds( variable_kinds: &chalk_ir::VariableKinds, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_variable_kinds(variable_kinds, fmt))) + Some(write!(fmt, "{:?}", variable_kinds.as_slice(&Interner))) } fn debug_variable_kinds_with_angles( variable_kinds: &chalk_ir::VariableKinds, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| { - Some(prog?.debug_variable_kinds_with_angles(variable_kinds, fmt)) - }) + Some(write!(fmt, "{:?}", variable_kinds.inner_debug(&Interner))) } fn debug_canonical_var_kinds( canonical_var_kinds: &chalk_ir::CanonicalVarKinds, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| { - Some(prog?.debug_canonical_var_kinds(canonical_var_kinds, fmt)) - }) + Some(write!(fmt, "{:?}", canonical_var_kinds.as_slice(&Interner))) } fn debug_program_clause( clause: &chalk_ir::ProgramClause, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_program_clause(clause, fmt))) + Some(write!(fmt, "{:?}", clause.data(&Interner))) } fn debug_program_clauses( clauses: &chalk_ir::ProgramClauses, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_program_clauses(clauses, fmt))) + Some(write!(fmt, "{:?}", clauses.as_slice(&Interner))) } fn debug_quantified_where_clauses( clauses: &chalk_ir::QuantifiedWhereClauses, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt))) + Some(write!(fmt, "{:?}", clauses.as_slice(&Interner))) } fn intern_ty(&self, kind: chalk_ir::TyKind) -> Self::InternedType { -- cgit v1.2.3