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 ++++++------- crates/hir_ty/src/tls.rs | 138 +----------------------------------------- 2 files changed, 21 insertions(+), 158 deletions(-) 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 { diff --git a/crates/hir_ty/src/tls.rs b/crates/hir_ty/src/tls.rs index 87c671a42..708797c47 100644 --- a/crates/hir_ty/src/tls.rs +++ b/crates/hir_ty/src/tls.rs @@ -1,7 +1,7 @@ //! Implementation of Chalk debug helper functions using TLS. -use std::fmt; +use std::fmt::{self, Debug}; -use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; +use chalk_ir::AliasTy; use itertools::Itertools; use crate::{ @@ -53,14 +53,6 @@ impl DebugContext<'_> { write!(fmt, "{}::{}", trait_data.name, type_alias_data.name) } - pub(crate) fn debug_opaque_ty_id( - &self, - opaque_ty_id: chalk_ir::OpaqueTyId, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - fmt.debug_struct("OpaqueTyId").field("index", &opaque_ty_id.0).finish() - } - pub(crate) fn debug_alias( &self, alias_ty: &AliasTy, @@ -68,7 +60,7 @@ impl DebugContext<'_> { ) -> Result<(), fmt::Error> { match alias_ty { AliasTy::Projection(projection_ty) => self.debug_projection_ty(projection_ty, fmt), - AliasTy::Opaque(opaque_ty) => self.debug_opaque_ty(opaque_ty, fmt), + AliasTy::Opaque(opaque_ty) => opaque_ty.fmt(fmt), } } @@ -96,79 +88,6 @@ impl DebugContext<'_> { write!(fmt, ">::{}", type_alias_data.name) } - pub(crate) fn debug_opaque_ty( - &self, - opaque_ty: &chalk_ir::OpaqueTy, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - write!(fmt, "{:?}", opaque_ty.opaque_ty_id) - } - - pub(crate) fn debug_ty( - &self, - ty: &chalk_ir::Ty, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - write!(fmt, "{:?}", ty.data(&Interner)) - } - - pub(crate) fn debug_lifetime( - &self, - lifetime: &Lifetime, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - write!(fmt, "{:?}", lifetime.data(&Interner)) - } - - pub(crate) fn debug_generic_arg( - &self, - parameter: &GenericArg, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - write!(fmt, "{:?}", parameter.data(&Interner).inner_debug()) - } - - pub(crate) fn debug_goal( - &self, - goal: &Goal, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - let goal_data = goal.data(&Interner); - write!(fmt, "{:?}", goal_data) - } - - pub(crate) fn debug_goals( - &self, - goals: &Goals, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - write!(fmt, "{:?}", goals.debug(&Interner)) - } - - pub(crate) fn debug_program_clause_implication( - &self, - pci: &ProgramClauseImplication, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - write!(fmt, "{:?}", pci.debug(&Interner)) - } - - pub(crate) fn debug_substitution( - &self, - substitution: &chalk_ir::Substitution, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - write!(fmt, "{:?}", substitution.debug(&Interner)) - } - - pub(crate) fn debug_separator_trait_ref( - &self, - separator_trait_ref: &chalk_ir::SeparatorTraitRef, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - write!(fmt, "{:?}", separator_trait_ref.debug(&Interner)) - } - pub(crate) fn debug_fn_def_id( &self, fn_def_id: chalk_ir::FnDefId, @@ -190,57 +109,6 @@ impl DebugContext<'_> { } } } - - pub(crate) fn debug_const( - &self, - _constant: &chalk_ir::Const, - fmt: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - write!(fmt, "const") - } - - pub(crate) fn debug_variable_kinds( - &self, - variable_kinds: &chalk_ir::VariableKinds, - fmt: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - write!(fmt, "{:?}", variable_kinds.as_slice(&Interner)) - } - pub(crate) fn debug_variable_kinds_with_angles( - &self, - variable_kinds: &chalk_ir::VariableKinds, - fmt: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - write!(fmt, "{:?}", variable_kinds.inner_debug(&Interner)) - } - pub(crate) fn debug_canonical_var_kinds( - &self, - canonical_var_kinds: &chalk_ir::CanonicalVarKinds, - fmt: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - write!(fmt, "{:?}", canonical_var_kinds.as_slice(&Interner)) - } - pub(crate) fn debug_program_clause( - &self, - clause: &chalk_ir::ProgramClause, - fmt: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - write!(fmt, "{:?}", clause.data(&Interner)) - } - pub(crate) fn debug_program_clauses( - &self, - clauses: &chalk_ir::ProgramClauses, - fmt: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - write!(fmt, "{:?}", clauses.as_slice(&Interner)) - } - pub(crate) fn debug_quantified_where_clauses( - &self, - clauses: &chalk_ir::QuantifiedWhereClauses, - fmt: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - write!(fmt, "{:?}", clauses.as_slice(&Interner)) - } } mod unsafe_tls { -- cgit v1.2.3