1 //! Implementation of the Chalk `Interner` trait, which allows customizing the
2 //! representation of the various objects Chalk deals with (types, goals etc.).
3 
4 use crate::{chalk_db, tls, GenericArg};
5 use base_db::salsa::InternId;
6 use chalk_ir::{Goal, GoalData};
7 use hir_def::{
8     intern::{impl_internable, InternStorage, Internable, Interned},
9     type_ref::ConstScalar,
10     TypeAliasId,
11 };
12 use smallvec::SmallVec;
13 use std::{fmt, sync::Arc};
14 
15 #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
16 pub struct Interner;
17 
18 #[derive(PartialEq, Eq, Hash)]
19 pub struct InternedWrapper<T>(T);
20 
21 impl<T: fmt::Debug> fmt::Debug for InternedWrapper<T> {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result22     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23         fmt::Debug::fmt(&self.0, f)
24     }
25 }
26 
27 impl<T> std::ops::Deref for InternedWrapper<T> {
28     type Target = T;
29 
deref(&self) -> &Self::Target30     fn deref(&self) -> &Self::Target {
31         &self.0
32     }
33 }
34 
35 impl_internable!(
36     InternedWrapper<Vec<chalk_ir::VariableKind<Interner>>>,
37     InternedWrapper<SmallVec<[GenericArg; 2]>>,
38     InternedWrapper<chalk_ir::TyData<Interner>>,
39     InternedWrapper<chalk_ir::LifetimeData<Interner>>,
40     InternedWrapper<chalk_ir::ConstData<Interner>>,
41     InternedWrapper<ConstScalar>,
42     InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Interner>>>,
43     InternedWrapper<Vec<chalk_ir::ProgramClause<Interner>>>,
44     InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Interner>>>,
45     InternedWrapper<Vec<chalk_ir::Variance>>,
46 );
47 
48 impl chalk_ir::interner::Interner for Interner {
49     type InternedType = Interned<InternedWrapper<chalk_ir::TyData<Interner>>>;
50     type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>;
51     type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>;
52     type InternedConcreteConst = ConstScalar;
53     type InternedGenericArg = chalk_ir::GenericArgData<Self>;
54     type InternedGoal = Arc<GoalData<Self>>;
55     type InternedGoals = Vec<Goal<Self>>;
56     type InternedSubstitution = Interned<InternedWrapper<SmallVec<[GenericArg; 2]>>>;
57     type InternedProgramClause = chalk_ir::ProgramClauseData<Self>;
58     type InternedProgramClauses = Interned<InternedWrapper<Vec<chalk_ir::ProgramClause<Self>>>>;
59     type InternedQuantifiedWhereClauses =
60         Interned<InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Self>>>>;
61     type InternedVariableKinds = Interned<InternedWrapper<Vec<chalk_ir::VariableKind<Interner>>>>;
62     type InternedCanonicalVarKinds =
63         Interned<InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Self>>>>;
64     type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
65     type InternedVariances = Interned<InternedWrapper<Vec<chalk_ir::Variance>>>;
66     type DefId = InternId;
67     type InternedAdtId = hir_def::AdtId;
68     type Identifier = TypeAliasId;
69     type FnAbi = ();
70 
debug_adt_id( type_kind_id: chalk_db::AdtId, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>71     fn debug_adt_id(
72         type_kind_id: chalk_db::AdtId,
73         fmt: &mut fmt::Formatter<'_>,
74     ) -> Option<fmt::Result> {
75         tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt)))
76     }
77 
debug_trait_id( type_kind_id: chalk_db::TraitId, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>78     fn debug_trait_id(
79         type_kind_id: chalk_db::TraitId,
80         fmt: &mut fmt::Formatter<'_>,
81     ) -> Option<fmt::Result> {
82         tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt)))
83     }
84 
debug_assoc_type_id( id: chalk_db::AssocTypeId, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>85     fn debug_assoc_type_id(
86         id: chalk_db::AssocTypeId,
87         fmt: &mut fmt::Formatter<'_>,
88     ) -> Option<fmt::Result> {
89         tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
90     }
91 
debug_alias( alias: &chalk_ir::AliasTy<Interner>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>92     fn debug_alias(
93         alias: &chalk_ir::AliasTy<Interner>,
94         fmt: &mut fmt::Formatter<'_>,
95     ) -> Option<fmt::Result> {
96         use std::fmt::Debug;
97         match alias {
98             chalk_ir::AliasTy::Projection(projection_ty) => {
99                 Interner::debug_projection_ty(projection_ty, fmt)
100             }
101             chalk_ir::AliasTy::Opaque(opaque_ty) => Some(opaque_ty.fmt(fmt)),
102         }
103     }
104 
debug_projection_ty( proj: &chalk_ir::ProjectionTy<Interner>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>105     fn debug_projection_ty(
106         proj: &chalk_ir::ProjectionTy<Interner>,
107         fmt: &mut fmt::Formatter<'_>,
108     ) -> Option<fmt::Result> {
109         tls::with_current_program(|prog| Some(prog?.debug_projection_ty(proj, fmt)))
110     }
111 
debug_opaque_ty( opaque_ty: &chalk_ir::OpaqueTy<Interner>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>112     fn debug_opaque_ty(
113         opaque_ty: &chalk_ir::OpaqueTy<Interner>,
114         fmt: &mut fmt::Formatter<'_>,
115     ) -> Option<fmt::Result> {
116         Some(write!(fmt, "{:?}", opaque_ty.opaque_ty_id))
117     }
118 
debug_opaque_ty_id( opaque_ty_id: chalk_ir::OpaqueTyId<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>119     fn debug_opaque_ty_id(
120         opaque_ty_id: chalk_ir::OpaqueTyId<Self>,
121         fmt: &mut fmt::Formatter<'_>,
122     ) -> Option<fmt::Result> {
123         Some(write!(fmt, "OpaqueTy#{}", opaque_ty_id.0))
124     }
125 
debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>126     fn debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
127         Some(write!(fmt, "{:?}", ty.data(&Interner)))
128     }
129 
debug_lifetime( lifetime: &chalk_ir::Lifetime<Interner>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>130     fn debug_lifetime(
131         lifetime: &chalk_ir::Lifetime<Interner>,
132         fmt: &mut fmt::Formatter<'_>,
133     ) -> Option<fmt::Result> {
134         Some(write!(fmt, "{:?}", lifetime.data(&Interner)))
135     }
136 
debug_generic_arg( parameter: &GenericArg, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>137     fn debug_generic_arg(
138         parameter: &GenericArg,
139         fmt: &mut fmt::Formatter<'_>,
140     ) -> Option<fmt::Result> {
141         Some(write!(fmt, "{:?}", parameter.data(&Interner).inner_debug()))
142     }
143 
debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>144     fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
145         let goal_data = goal.data(&Interner);
146         Some(write!(fmt, "{:?}", goal_data))
147     }
148 
debug_goals( goals: &chalk_ir::Goals<Interner>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>149     fn debug_goals(
150         goals: &chalk_ir::Goals<Interner>,
151         fmt: &mut fmt::Formatter<'_>,
152     ) -> Option<fmt::Result> {
153         Some(write!(fmt, "{:?}", goals.debug(&Interner)))
154     }
155 
debug_program_clause_implication( pci: &chalk_ir::ProgramClauseImplication<Interner>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>156     fn debug_program_clause_implication(
157         pci: &chalk_ir::ProgramClauseImplication<Interner>,
158         fmt: &mut fmt::Formatter<'_>,
159     ) -> Option<fmt::Result> {
160         Some(write!(fmt, "{:?}", pci.debug(&Interner)))
161     }
162 
debug_substitution( substitution: &chalk_ir::Substitution<Interner>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>163     fn debug_substitution(
164         substitution: &chalk_ir::Substitution<Interner>,
165         fmt: &mut fmt::Formatter<'_>,
166     ) -> Option<fmt::Result> {
167         Some(write!(fmt, "{:?}", substitution.debug(&Interner)))
168     }
169 
debug_separator_trait_ref( separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>170     fn debug_separator_trait_ref(
171         separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>,
172         fmt: &mut fmt::Formatter<'_>,
173     ) -> Option<fmt::Result> {
174         Some(write!(fmt, "{:?}", separator_trait_ref.debug(&Interner)))
175     }
176 
debug_fn_def_id( fn_def_id: chalk_ir::FnDefId<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>177     fn debug_fn_def_id(
178         fn_def_id: chalk_ir::FnDefId<Self>,
179         fmt: &mut fmt::Formatter<'_>,
180     ) -> Option<fmt::Result> {
181         tls::with_current_program(|prog| Some(prog?.debug_fn_def_id(fn_def_id, fmt)))
182     }
debug_const( constant: &chalk_ir::Const<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>183     fn debug_const(
184         constant: &chalk_ir::Const<Self>,
185         fmt: &mut fmt::Formatter<'_>,
186     ) -> Option<fmt::Result> {
187         Some(write!(fmt, "{:?}", constant.data(&Interner)))
188     }
debug_variable_kinds( variable_kinds: &chalk_ir::VariableKinds<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>189     fn debug_variable_kinds(
190         variable_kinds: &chalk_ir::VariableKinds<Self>,
191         fmt: &mut fmt::Formatter<'_>,
192     ) -> Option<fmt::Result> {
193         Some(write!(fmt, "{:?}", variable_kinds.as_slice(&Interner)))
194     }
debug_variable_kinds_with_angles( variable_kinds: &chalk_ir::VariableKinds<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>195     fn debug_variable_kinds_with_angles(
196         variable_kinds: &chalk_ir::VariableKinds<Self>,
197         fmt: &mut fmt::Formatter<'_>,
198     ) -> Option<fmt::Result> {
199         Some(write!(fmt, "{:?}", variable_kinds.inner_debug(&Interner)))
200     }
debug_canonical_var_kinds( canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>201     fn debug_canonical_var_kinds(
202         canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>,
203         fmt: &mut fmt::Formatter<'_>,
204     ) -> Option<fmt::Result> {
205         Some(write!(fmt, "{:?}", canonical_var_kinds.as_slice(&Interner)))
206     }
debug_program_clause( clause: &chalk_ir::ProgramClause<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>207     fn debug_program_clause(
208         clause: &chalk_ir::ProgramClause<Self>,
209         fmt: &mut fmt::Formatter<'_>,
210     ) -> Option<fmt::Result> {
211         Some(write!(fmt, "{:?}", clause.data(&Interner)))
212     }
debug_program_clauses( clauses: &chalk_ir::ProgramClauses<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>213     fn debug_program_clauses(
214         clauses: &chalk_ir::ProgramClauses<Self>,
215         fmt: &mut fmt::Formatter<'_>,
216     ) -> Option<fmt::Result> {
217         Some(write!(fmt, "{:?}", clauses.as_slice(&Interner)))
218     }
debug_quantified_where_clauses( clauses: &chalk_ir::QuantifiedWhereClauses<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>219     fn debug_quantified_where_clauses(
220         clauses: &chalk_ir::QuantifiedWhereClauses<Self>,
221         fmt: &mut fmt::Formatter<'_>,
222     ) -> Option<fmt::Result> {
223         Some(write!(fmt, "{:?}", clauses.as_slice(&Interner)))
224     }
225 
intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType226     fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
227         let flags = kind.compute_flags(self);
228         Interned::new(InternedWrapper(chalk_ir::TyData { kind, flags }))
229     }
230 
ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self>231     fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> {
232         &ty.0
233     }
234 
intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime235     fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime {
236         Interned::new(InternedWrapper(lifetime))
237     }
238 
lifetime_data<'a>( &self, lifetime: &'a Self::InternedLifetime, ) -> &'a chalk_ir::LifetimeData<Self>239     fn lifetime_data<'a>(
240         &self,
241         lifetime: &'a Self::InternedLifetime,
242     ) -> &'a chalk_ir::LifetimeData<Self> {
243         &lifetime.0
244     }
245 
intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst246     fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
247         Interned::new(InternedWrapper(constant))
248     }
249 
const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self>250     fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> {
251         &constant.0
252     }
253 
const_eq( &self, _ty: &Self::InternedType, c1: &Self::InternedConcreteConst, c2: &Self::InternedConcreteConst, ) -> bool254     fn const_eq(
255         &self,
256         _ty: &Self::InternedType,
257         c1: &Self::InternedConcreteConst,
258         c2: &Self::InternedConcreteConst,
259     ) -> bool {
260         match (c1, c2) {
261             (&ConstScalar::Usize(a), &ConstScalar::Usize(b)) => a == b,
262             // we were previously assuming this to be true, I'm not whether true or false on
263             // unknown values is safer.
264             (_, _) => true,
265         }
266     }
267 
intern_generic_arg( &self, parameter: chalk_ir::GenericArgData<Self>, ) -> Self::InternedGenericArg268     fn intern_generic_arg(
269         &self,
270         parameter: chalk_ir::GenericArgData<Self>,
271     ) -> Self::InternedGenericArg {
272         parameter
273     }
274 
generic_arg_data<'a>( &self, parameter: &'a Self::InternedGenericArg, ) -> &'a chalk_ir::GenericArgData<Self>275     fn generic_arg_data<'a>(
276         &self,
277         parameter: &'a Self::InternedGenericArg,
278     ) -> &'a chalk_ir::GenericArgData<Self> {
279         parameter
280     }
281 
intern_goal(&self, goal: GoalData<Self>) -> Self::InternedGoal282     fn intern_goal(&self, goal: GoalData<Self>) -> Self::InternedGoal {
283         Arc::new(goal)
284     }
285 
intern_goals<E>( &self, data: impl IntoIterator<Item = Result<Goal<Self>, E>>, ) -> Result<Self::InternedGoals, E>286     fn intern_goals<E>(
287         &self,
288         data: impl IntoIterator<Item = Result<Goal<Self>, E>>,
289     ) -> Result<Self::InternedGoals, E> {
290         data.into_iter().collect()
291     }
292 
goal_data<'a>(&self, goal: &'a Self::InternedGoal) -> &'a GoalData<Self>293     fn goal_data<'a>(&self, goal: &'a Self::InternedGoal) -> &'a GoalData<Self> {
294         goal
295     }
296 
goals_data<'a>(&self, goals: &'a Self::InternedGoals) -> &'a [Goal<Interner>]297     fn goals_data<'a>(&self, goals: &'a Self::InternedGoals) -> &'a [Goal<Interner>] {
298         goals
299     }
300 
intern_substitution<E>( &self, data: impl IntoIterator<Item = Result<GenericArg, E>>, ) -> Result<Self::InternedSubstitution, E>301     fn intern_substitution<E>(
302         &self,
303         data: impl IntoIterator<Item = Result<GenericArg, E>>,
304     ) -> Result<Self::InternedSubstitution, E> {
305         Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
306     }
307 
substitution_data<'a>( &self, substitution: &'a Self::InternedSubstitution, ) -> &'a [GenericArg]308     fn substitution_data<'a>(
309         &self,
310         substitution: &'a Self::InternedSubstitution,
311     ) -> &'a [GenericArg] {
312         &substitution.as_ref().0
313     }
314 
intern_program_clause( &self, data: chalk_ir::ProgramClauseData<Self>, ) -> Self::InternedProgramClause315     fn intern_program_clause(
316         &self,
317         data: chalk_ir::ProgramClauseData<Self>,
318     ) -> Self::InternedProgramClause {
319         data
320     }
321 
program_clause_data<'a>( &self, clause: &'a Self::InternedProgramClause, ) -> &'a chalk_ir::ProgramClauseData<Self>322     fn program_clause_data<'a>(
323         &self,
324         clause: &'a Self::InternedProgramClause,
325     ) -> &'a chalk_ir::ProgramClauseData<Self> {
326         clause
327     }
328 
intern_program_clauses<E>( &self, data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>, ) -> Result<Self::InternedProgramClauses, E>329     fn intern_program_clauses<E>(
330         &self,
331         data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>,
332     ) -> Result<Self::InternedProgramClauses, E> {
333         Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
334     }
335 
program_clauses_data<'a>( &self, clauses: &'a Self::InternedProgramClauses, ) -> &'a [chalk_ir::ProgramClause<Self>]336     fn program_clauses_data<'a>(
337         &self,
338         clauses: &'a Self::InternedProgramClauses,
339     ) -> &'a [chalk_ir::ProgramClause<Self>] {
340         clauses
341     }
342 
intern_quantified_where_clauses<E>( &self, data: impl IntoIterator<Item = Result<chalk_ir::QuantifiedWhereClause<Self>, E>>, ) -> Result<Self::InternedQuantifiedWhereClauses, E>343     fn intern_quantified_where_clauses<E>(
344         &self,
345         data: impl IntoIterator<Item = Result<chalk_ir::QuantifiedWhereClause<Self>, E>>,
346     ) -> Result<Self::InternedQuantifiedWhereClauses, E> {
347         Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
348     }
349 
quantified_where_clauses_data<'a>( &self, clauses: &'a Self::InternedQuantifiedWhereClauses, ) -> &'a [chalk_ir::QuantifiedWhereClause<Self>]350     fn quantified_where_clauses_data<'a>(
351         &self,
352         clauses: &'a Self::InternedQuantifiedWhereClauses,
353     ) -> &'a [chalk_ir::QuantifiedWhereClause<Self>] {
354         clauses
355     }
356 
intern_generic_arg_kinds<E>( &self, data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>, ) -> Result<Self::InternedVariableKinds, E>357     fn intern_generic_arg_kinds<E>(
358         &self,
359         data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>,
360     ) -> Result<Self::InternedVariableKinds, E> {
361         Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
362     }
363 
variable_kinds_data<'a>( &self, parameter_kinds: &'a Self::InternedVariableKinds, ) -> &'a [chalk_ir::VariableKind<Self>]364     fn variable_kinds_data<'a>(
365         &self,
366         parameter_kinds: &'a Self::InternedVariableKinds,
367     ) -> &'a [chalk_ir::VariableKind<Self>] {
368         &parameter_kinds.as_ref().0
369     }
370 
intern_canonical_var_kinds<E>( &self, data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>, ) -> Result<Self::InternedCanonicalVarKinds, E>371     fn intern_canonical_var_kinds<E>(
372         &self,
373         data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>,
374     ) -> Result<Self::InternedCanonicalVarKinds, E> {
375         Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
376     }
377 
canonical_var_kinds_data<'a>( &self, canonical_var_kinds: &'a Self::InternedCanonicalVarKinds, ) -> &'a [chalk_ir::CanonicalVarKind<Self>]378     fn canonical_var_kinds_data<'a>(
379         &self,
380         canonical_var_kinds: &'a Self::InternedCanonicalVarKinds,
381     ) -> &'a [chalk_ir::CanonicalVarKind<Self>] {
382         canonical_var_kinds
383     }
384 
intern_constraints<E>( &self, data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>, ) -> Result<Self::InternedConstraints, E>385     fn intern_constraints<E>(
386         &self,
387         data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>,
388     ) -> Result<Self::InternedConstraints, E> {
389         data.into_iter().collect()
390     }
391 
constraints_data<'a>( &self, constraints: &'a Self::InternedConstraints, ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>]392     fn constraints_data<'a>(
393         &self,
394         constraints: &'a Self::InternedConstraints,
395     ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
396         constraints
397     }
debug_closure_id( _fn_def_id: chalk_ir::ClosureId<Self>, _fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>398     fn debug_closure_id(
399         _fn_def_id: chalk_ir::ClosureId<Self>,
400         _fmt: &mut fmt::Formatter<'_>,
401     ) -> Option<fmt::Result> {
402         None
403     }
debug_constraints( _clauses: &chalk_ir::Constraints<Self>, _fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>404     fn debug_constraints(
405         _clauses: &chalk_ir::Constraints<Self>,
406         _fmt: &mut fmt::Formatter<'_>,
407     ) -> Option<fmt::Result> {
408         None
409     }
410 
intern_variances<E>( &self, data: impl IntoIterator<Item = Result<chalk_ir::Variance, E>>, ) -> Result<Self::InternedVariances, E>411     fn intern_variances<E>(
412         &self,
413         data: impl IntoIterator<Item = Result<chalk_ir::Variance, E>>,
414     ) -> Result<Self::InternedVariances, E> {
415         Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
416     }
417 
variances_data<'a>( &self, variances: &'a Self::InternedVariances, ) -> &'a [chalk_ir::Variance]418     fn variances_data<'a>(
419         &self,
420         variances: &'a Self::InternedVariances,
421     ) -> &'a [chalk_ir::Variance] {
422         variances
423     }
424 }
425 
426 impl chalk_ir::interner::HasInterner for Interner {
427     type Interner = Self;
428 }
429 
430 #[macro_export]
431 macro_rules! has_interner {
432     ($t:ty) => {
433         impl HasInterner for $t {
434             type Interner = crate::Interner;
435         }
436     };
437 }
438