Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/interner.rs')
| -rw-r--r-- | crates/hir-ty/src/interner.rs | 145 |
1 files changed, 73 insertions, 72 deletions
diff --git a/crates/hir-ty/src/interner.rs b/crates/hir-ty/src/interner.rs index aea7e9762f..89f7d9c4f4 100644 --- a/crates/hir-ty/src/interner.rs +++ b/crates/hir-ty/src/interner.rs @@ -7,7 +7,8 @@ use chalk_ir::{Goal, GoalData}; use hir_def::TypeAliasId; use intern::{impl_internable, Interned}; use smallvec::SmallVec; -use std::{fmt, sync::Arc}; +use std::fmt; +use triomphe::Arc; #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct Interner; @@ -43,7 +44,7 @@ impl_internable!( ); impl chalk_ir::interner::Interner for Interner { - type InternedType = Interned<InternedWrapper<chalk_ir::TyData<Interner>>>; + type InternedType = Interned<InternedWrapper<chalk_ir::TyData<Self>>>; type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>; type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>; type InternedConcreteConst = ConstScalar; @@ -51,8 +52,8 @@ impl chalk_ir::interner::Interner for Interner { type InternedGoal = Arc<GoalData<Self>>; type InternedGoals = Vec<Goal<Self>>; type InternedSubstitution = Interned<InternedWrapper<SmallVec<[GenericArg; 2]>>>; - type InternedProgramClause = chalk_ir::ProgramClauseData<Self>; type InternedProgramClauses = Interned<InternedWrapper<Vec<chalk_ir::ProgramClause<Self>>>>; + type InternedProgramClause = chalk_ir::ProgramClauseData<Self>; type InternedQuantifiedWhereClauses = Interned<InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Self>>>>; type InternedVariableKinds = Interned<InternedWrapper<Vec<chalk_ir::VariableKind<Interner>>>>; @@ -86,6 +87,27 @@ impl chalk_ir::interner::Interner for Interner { tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt))) } + fn debug_opaque_ty_id( + opaque_ty_id: chalk_ir::OpaqueTyId<Self>, + fmt: &mut fmt::Formatter<'_>, + ) -> Option<fmt::Result> { + Some(write!(fmt, "OpaqueTy#{}", opaque_ty_id.0)) + } + + fn debug_fn_def_id( + fn_def_id: chalk_ir::FnDefId<Self>, + fmt: &mut fmt::Formatter<'_>, + ) -> Option<fmt::Result> { + tls::with_current_program(|prog| Some(prog?.debug_fn_def_id(fn_def_id, fmt))) + } + + fn debug_closure_id( + _fn_def_id: chalk_ir::ClosureId<Self>, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option<fmt::Result> { + None + } + fn debug_alias( alias: &chalk_ir::AliasTy<Interner>, fmt: &mut fmt::Formatter<'_>, @@ -113,13 +135,6 @@ impl chalk_ir::interner::Interner for Interner { Some(write!(fmt, "{:?}", opaque_ty.opaque_ty_id)) } - fn debug_opaque_ty_id( - opaque_ty_id: chalk_ir::OpaqueTyId<Self>, - fmt: &mut fmt::Formatter<'_>, - ) -> Option<fmt::Result> { - Some(write!(fmt, "OpaqueTy#{}", opaque_ty_id.0)) - } - fn debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { Some(write!(fmt, "{:?}", ty.data(Interner))) } @@ -131,76 +146,56 @@ impl chalk_ir::interner::Interner for Interner { Some(write!(fmt, "{:?}", lifetime.data(Interner))) } - fn debug_generic_arg( - parameter: &GenericArg, - fmt: &mut fmt::Formatter<'_>, - ) -> Option<fmt::Result> { - Some(write!(fmt, "{:?}", parameter.data(Interner).inner_debug())) - } - - fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { - let goal_data = goal.data(Interner); - Some(write!(fmt, "{goal_data:?}")) - } - - fn debug_goals( - goals: &chalk_ir::Goals<Interner>, - fmt: &mut fmt::Formatter<'_>, - ) -> Option<fmt::Result> { - Some(write!(fmt, "{:?}", goals.debug(Interner))) - } - - fn debug_program_clause_implication( - pci: &chalk_ir::ProgramClauseImplication<Interner>, - fmt: &mut fmt::Formatter<'_>, - ) -> Option<fmt::Result> { - Some(write!(fmt, "{:?}", pci.debug(Interner))) - } - - fn debug_substitution( - substitution: &chalk_ir::Substitution<Interner>, + fn debug_const( + constant: &chalk_ir::Const<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result> { - Some(write!(fmt, "{:?}", substitution.debug(Interner))) + Some(write!(fmt, "{:?}", constant.data(Interner))) } - fn debug_separator_trait_ref( - separator_trait_ref: &chalk_ir::SeparatorTraitRef<'_, Interner>, + fn debug_generic_arg( + parameter: &GenericArg, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result> { - Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner))) + Some(write!(fmt, "{:?}", parameter.data(Interner).inner_debug())) } - fn debug_fn_def_id( - fn_def_id: chalk_ir::FnDefId<Self>, - fmt: &mut fmt::Formatter<'_>, - ) -> Option<fmt::Result> { - tls::with_current_program(|prog| Some(prog?.debug_fn_def_id(fn_def_id, fmt))) - } - fn debug_const( - constant: &chalk_ir::Const<Self>, - fmt: &mut fmt::Formatter<'_>, - ) -> Option<fmt::Result> { - Some(write!(fmt, "{:?}", constant.data(Interner))) - } fn debug_variable_kinds( variable_kinds: &chalk_ir::VariableKinds<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result> { Some(write!(fmt, "{:?}", variable_kinds.as_slice(Interner))) } + fn debug_variable_kinds_with_angles( variable_kinds: &chalk_ir::VariableKinds<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result> { Some(write!(fmt, "{:?}", variable_kinds.inner_debug(Interner))) } + fn debug_canonical_var_kinds( canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result> { Some(write!(fmt, "{:?}", canonical_var_kinds.as_slice(Interner))) } + fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { + let goal_data = goal.data(Interner); + Some(write!(fmt, "{goal_data:?}")) + } + fn debug_goals( + goals: &chalk_ir::Goals<Interner>, + fmt: &mut fmt::Formatter<'_>, + ) -> Option<fmt::Result> { + Some(write!(fmt, "{:?}", goals.debug(Interner))) + } + fn debug_program_clause_implication( + pci: &chalk_ir::ProgramClauseImplication<Interner>, + fmt: &mut fmt::Formatter<'_>, + ) -> Option<fmt::Result> { + Some(write!(fmt, "{:?}", pci.debug(Interner))) + } fn debug_program_clause( clause: &chalk_ir::ProgramClause<Self>, fmt: &mut fmt::Formatter<'_>, @@ -213,6 +208,19 @@ impl chalk_ir::interner::Interner for Interner { ) -> Option<fmt::Result> { Some(write!(fmt, "{:?}", clauses.as_slice(Interner))) } + fn debug_substitution( + substitution: &chalk_ir::Substitution<Interner>, + fmt: &mut fmt::Formatter<'_>, + ) -> Option<fmt::Result> { + Some(write!(fmt, "{:?}", substitution.debug(Interner))) + } + fn debug_separator_trait_ref( + separator_trait_ref: &chalk_ir::SeparatorTraitRef<'_, Interner>, + fmt: &mut fmt::Formatter<'_>, + ) -> Option<fmt::Result> { + Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner))) + } + fn debug_quantified_where_clauses( clauses: &chalk_ir::QuantifiedWhereClauses<Self>, fmt: &mut fmt::Formatter<'_>, @@ -220,6 +228,13 @@ impl chalk_ir::interner::Interner for Interner { Some(write!(fmt, "{:?}", clauses.as_slice(Interner))) } + fn debug_constraints( + _clauses: &chalk_ir::Constraints<Self>, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option<fmt::Result> { + None + } + fn intern_ty(self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType { let flags = kind.compute_flags(self); Interned::new(InternedWrapper(chalk_ir::TyData { kind, flags })) @@ -272,6 +287,10 @@ impl chalk_ir::interner::Interner for Interner { Arc::new(goal) } + fn goal_data(self, goal: &Self::InternedGoal) -> &GoalData<Self> { + goal + } + fn intern_goals<E>( self, data: impl IntoIterator<Item = Result<Goal<Self>, E>>, @@ -279,10 +298,6 @@ impl chalk_ir::interner::Interner for Interner { data.into_iter().collect() } - fn goal_data(self, goal: &Self::InternedGoal) -> &GoalData<Self> { - goal - } - fn goals_data(self, goals: &Self::InternedGoals) -> &[Goal<Interner>] { goals } @@ -367,32 +382,18 @@ impl chalk_ir::interner::Interner for Interner { ) -> &[chalk_ir::CanonicalVarKind<Self>] { canonical_var_kinds } - fn intern_constraints<E>( self, data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>, ) -> Result<Self::InternedConstraints, E> { data.into_iter().collect() } - fn constraints_data( self, constraints: &Self::InternedConstraints, ) -> &[chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] { constraints } - fn debug_closure_id( - _fn_def_id: chalk_ir::ClosureId<Self>, - _fmt: &mut fmt::Formatter<'_>, - ) -> Option<fmt::Result> { - None - } - fn debug_constraints( - _clauses: &chalk_ir::Constraints<Self>, - _fmt: &mut fmt::Formatter<'_>, - ) -> Option<fmt::Result> { - None - } fn intern_variances<E>( self, |