aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits/chalk/interner.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits/chalk/interner.rs')
-rw-r--r--crates/hir_ty/src/traits/chalk/interner.rs392
1 files changed, 0 insertions, 392 deletions
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs
deleted file mode 100644
index bd9395b7e..000000000
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ /dev/null
@@ -1,392 +0,0 @@
1//! Implementation of the Chalk `Interner` trait, which allows customizing the
2//! representation of the various objects Chalk deals with (types, goals etc.).
3
4use super::tls;
5use base_db::salsa::InternId;
6use chalk_ir::{GenericArg, Goal, GoalData};
7use hir_def::TypeAliasId;
8use smallvec::SmallVec;
9use std::{fmt, sync::Arc};
10
11#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
12pub struct Interner;
13
14pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
15pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
16pub(crate) type TraitId = chalk_ir::TraitId<Interner>;
17pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
18pub(crate) type AdtId = chalk_ir::AdtId<Interner>;
19pub(crate) type StructDatum = chalk_solve::rust_ir::AdtDatum<Interner>;
20pub(crate) type ImplId = chalk_ir::ImplId<Interner>;
21pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>;
22pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>;
23pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>;
24pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>;
25pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
26pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>;
27pub(crate) type Variances = chalk_ir::Variances<Interner>;
28
29impl chalk_ir::interner::Interner for Interner {
30 type InternedType = Arc<chalk_ir::TyData<Self>>;
31 type InternedLifetime = chalk_ir::LifetimeData<Self>;
32 type InternedConst = Arc<chalk_ir::ConstData<Self>>;
33 type InternedConcreteConst = ();
34 type InternedGenericArg = chalk_ir::GenericArgData<Self>;
35 type InternedGoal = Arc<GoalData<Self>>;
36 type InternedGoals = Vec<Goal<Self>>;
37 type InternedSubstitution = SmallVec<[GenericArg<Self>; 2]>;
38 type InternedProgramClause = Arc<chalk_ir::ProgramClauseData<Self>>;
39 type InternedProgramClauses = Arc<[chalk_ir::ProgramClause<Self>]>;
40 type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
41 type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
42 type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
43 type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
44 type InternedVariances = Arc<[chalk_ir::Variance]>;
45 type DefId = InternId;
46 type InternedAdtId = hir_def::AdtId;
47 type Identifier = TypeAliasId;
48 type FnAbi = ();
49
50 fn debug_adt_id(type_kind_id: AdtId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
51 tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt)))
52 }
53
54 fn debug_trait_id(type_kind_id: TraitId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
55 tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt)))
56 }
57
58 fn debug_assoc_type_id(id: AssocTypeId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
59 tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
60 }
61
62 fn debug_alias(
63 alias: &chalk_ir::AliasTy<Interner>,
64 fmt: &mut fmt::Formatter<'_>,
65 ) -> Option<fmt::Result> {
66 tls::with_current_program(|prog| Some(prog?.debug_alias(alias, fmt)))
67 }
68
69 fn debug_projection_ty(
70 proj: &chalk_ir::ProjectionTy<Interner>,
71 fmt: &mut fmt::Formatter<'_>,
72 ) -> Option<fmt::Result> {
73 tls::with_current_program(|prog| Some(prog?.debug_projection_ty(proj, fmt)))
74 }
75
76 fn debug_opaque_ty(
77 opaque_ty: &chalk_ir::OpaqueTy<Interner>,
78 fmt: &mut fmt::Formatter<'_>,
79 ) -> Option<fmt::Result> {
80 tls::with_current_program(|prog| Some(prog?.debug_opaque_ty(opaque_ty, fmt)))
81 }
82
83 fn debug_opaque_ty_id(
84 opaque_ty_id: chalk_ir::OpaqueTyId<Self>,
85 fmt: &mut fmt::Formatter<'_>,
86 ) -> Option<fmt::Result> {
87 tls::with_current_program(|prog| Some(prog?.debug_opaque_ty_id(opaque_ty_id, fmt)))
88 }
89
90 fn debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
91 tls::with_current_program(|prog| Some(prog?.debug_ty(ty, fmt)))
92 }
93
94 fn debug_lifetime(
95 lifetime: &chalk_ir::Lifetime<Interner>,
96 fmt: &mut fmt::Formatter<'_>,
97 ) -> Option<fmt::Result> {
98 tls::with_current_program(|prog| Some(prog?.debug_lifetime(lifetime, fmt)))
99 }
100
101 fn debug_generic_arg(
102 parameter: &GenericArg<Interner>,
103 fmt: &mut fmt::Formatter<'_>,
104 ) -> Option<fmt::Result> {
105 tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt)))
106 }
107
108 fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
109 tls::with_current_program(|prog| Some(prog?.debug_goal(goal, fmt)))
110 }
111
112 fn debug_goals(
113 goals: &chalk_ir::Goals<Interner>,
114 fmt: &mut fmt::Formatter<'_>,
115 ) -> Option<fmt::Result> {
116 tls::with_current_program(|prog| Some(prog?.debug_goals(goals, fmt)))
117 }
118
119 fn debug_program_clause_implication(
120 pci: &chalk_ir::ProgramClauseImplication<Interner>,
121 fmt: &mut fmt::Formatter<'_>,
122 ) -> Option<fmt::Result> {
123 tls::with_current_program(|prog| Some(prog?.debug_program_clause_implication(pci, fmt)))
124 }
125
126 fn debug_substitution(
127 substitution: &chalk_ir::Substitution<Interner>,
128 fmt: &mut fmt::Formatter<'_>,
129 ) -> Option<fmt::Result> {
130 tls::with_current_program(|prog| Some(prog?.debug_substitution(substitution, fmt)))
131 }
132
133 fn debug_separator_trait_ref(
134 separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>,
135 fmt: &mut fmt::Formatter<'_>,
136 ) -> Option<fmt::Result> {
137 tls::with_current_program(|prog| {
138 Some(prog?.debug_separator_trait_ref(separator_trait_ref, fmt))
139 })
140 }
141
142 fn debug_fn_def_id(
143 fn_def_id: chalk_ir::FnDefId<Self>,
144 fmt: &mut fmt::Formatter<'_>,
145 ) -> Option<fmt::Result> {
146 tls::with_current_program(|prog| Some(prog?.debug_fn_def_id(fn_def_id, fmt)))
147 }
148 fn debug_const(
149 constant: &chalk_ir::Const<Self>,
150 fmt: &mut fmt::Formatter<'_>,
151 ) -> Option<fmt::Result> {
152 tls::with_current_program(|prog| Some(prog?.debug_const(constant, fmt)))
153 }
154 fn debug_variable_kinds(
155 variable_kinds: &chalk_ir::VariableKinds<Self>,
156 fmt: &mut fmt::Formatter<'_>,
157 ) -> Option<fmt::Result> {
158 tls::with_current_program(|prog| Some(prog?.debug_variable_kinds(variable_kinds, fmt)))
159 }
160 fn debug_variable_kinds_with_angles(
161 variable_kinds: &chalk_ir::VariableKinds<Self>,
162 fmt: &mut fmt::Formatter<'_>,
163 ) -> Option<fmt::Result> {
164 tls::with_current_program(|prog| {
165 Some(prog?.debug_variable_kinds_with_angles(variable_kinds, fmt))
166 })
167 }
168 fn debug_canonical_var_kinds(
169 canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>,
170 fmt: &mut fmt::Formatter<'_>,
171 ) -> Option<fmt::Result> {
172 tls::with_current_program(|prog| {
173 Some(prog?.debug_canonical_var_kinds(canonical_var_kinds, fmt))
174 })
175 }
176 fn debug_program_clause(
177 clause: &chalk_ir::ProgramClause<Self>,
178 fmt: &mut fmt::Formatter<'_>,
179 ) -> Option<fmt::Result> {
180 tls::with_current_program(|prog| Some(prog?.debug_program_clause(clause, fmt)))
181 }
182 fn debug_program_clauses(
183 clauses: &chalk_ir::ProgramClauses<Self>,
184 fmt: &mut fmt::Formatter<'_>,
185 ) -> Option<fmt::Result> {
186 tls::with_current_program(|prog| Some(prog?.debug_program_clauses(clauses, fmt)))
187 }
188 fn debug_quantified_where_clauses(
189 clauses: &chalk_ir::QuantifiedWhereClauses<Self>,
190 fmt: &mut fmt::Formatter<'_>,
191 ) -> Option<fmt::Result> {
192 tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt)))
193 }
194
195 fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
196 let flags = kind.compute_flags(self);
197 Arc::new(chalk_ir::TyData { kind, flags })
198 }
199
200 fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> {
201 ty
202 }
203
204 fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime {
205 lifetime
206 }
207
208 fn lifetime_data<'a>(
209 &self,
210 lifetime: &'a Self::InternedLifetime,
211 ) -> &'a chalk_ir::LifetimeData<Self> {
212 lifetime
213 }
214
215 fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
216 Arc::new(constant)
217 }
218
219 fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> {
220 constant
221 }
222
223 fn const_eq(
224 &self,
225 _ty: &Self::InternedType,
226 _c1: &Self::InternedConcreteConst,
227 _c2: &Self::InternedConcreteConst,
228 ) -> bool {
229 true
230 }
231
232 fn intern_generic_arg(
233 &self,
234 parameter: chalk_ir::GenericArgData<Self>,
235 ) -> Self::InternedGenericArg {
236 parameter
237 }
238
239 fn generic_arg_data<'a>(
240 &self,
241 parameter: &'a Self::InternedGenericArg,
242 ) -> &'a chalk_ir::GenericArgData<Self> {
243 parameter
244 }
245
246 fn intern_goal(&self, goal: GoalData<Self>) -> Self::InternedGoal {
247 Arc::new(goal)
248 }
249
250 fn intern_goals<E>(
251 &self,
252 data: impl IntoIterator<Item = Result<Goal<Self>, E>>,
253 ) -> Result<Self::InternedGoals, E> {
254 data.into_iter().collect()
255 }
256
257 fn goal_data<'a>(&self, goal: &'a Self::InternedGoal) -> &'a GoalData<Self> {
258 goal
259 }
260
261 fn goals_data<'a>(&self, goals: &'a Self::InternedGoals) -> &'a [Goal<Interner>] {
262 goals
263 }
264
265 fn intern_substitution<E>(
266 &self,
267 data: impl IntoIterator<Item = Result<GenericArg<Self>, E>>,
268 ) -> Result<Self::InternedSubstitution, E> {
269 data.into_iter().collect()
270 }
271
272 fn substitution_data<'a>(
273 &self,
274 substitution: &'a Self::InternedSubstitution,
275 ) -> &'a [GenericArg<Self>] {
276 substitution
277 }
278
279 fn intern_program_clause(
280 &self,
281 data: chalk_ir::ProgramClauseData<Self>,
282 ) -> Self::InternedProgramClause {
283 Arc::new(data)
284 }
285
286 fn program_clause_data<'a>(
287 &self,
288 clause: &'a Self::InternedProgramClause,
289 ) -> &'a chalk_ir::ProgramClauseData<Self> {
290 clause
291 }
292
293 fn intern_program_clauses<E>(
294 &self,
295 data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>,
296 ) -> Result<Self::InternedProgramClauses, E> {
297 data.into_iter().collect()
298 }
299
300 fn program_clauses_data<'a>(
301 &self,
302 clauses: &'a Self::InternedProgramClauses,
303 ) -> &'a [chalk_ir::ProgramClause<Self>] {
304 &clauses
305 }
306
307 fn intern_quantified_where_clauses<E>(
308 &self,
309 data: impl IntoIterator<Item = Result<chalk_ir::QuantifiedWhereClause<Self>, E>>,
310 ) -> Result<Self::InternedQuantifiedWhereClauses, E> {
311 data.into_iter().collect()
312 }
313
314 fn quantified_where_clauses_data<'a>(
315 &self,
316 clauses: &'a Self::InternedQuantifiedWhereClauses,
317 ) -> &'a [chalk_ir::QuantifiedWhereClause<Self>] {
318 clauses
319 }
320
321 fn intern_generic_arg_kinds<E>(
322 &self,
323 data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>,
324 ) -> Result<Self::InternedVariableKinds, E> {
325 data.into_iter().collect()
326 }
327
328 fn variable_kinds_data<'a>(
329 &self,
330 parameter_kinds: &'a Self::InternedVariableKinds,
331 ) -> &'a [chalk_ir::VariableKind<Self>] {
332 &parameter_kinds
333 }
334
335 fn intern_canonical_var_kinds<E>(
336 &self,
337 data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>,
338 ) -> Result<Self::InternedCanonicalVarKinds, E> {
339 data.into_iter().collect()
340 }
341
342 fn canonical_var_kinds_data<'a>(
343 &self,
344 canonical_var_kinds: &'a Self::InternedCanonicalVarKinds,
345 ) -> &'a [chalk_ir::CanonicalVarKind<Self>] {
346 &canonical_var_kinds
347 }
348
349 fn intern_constraints<E>(
350 &self,
351 data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>,
352 ) -> Result<Self::InternedConstraints, E> {
353 data.into_iter().collect()
354 }
355
356 fn constraints_data<'a>(
357 &self,
358 constraints: &'a Self::InternedConstraints,
359 ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
360 constraints
361 }
362 fn debug_closure_id(
363 _fn_def_id: chalk_ir::ClosureId<Self>,
364 _fmt: &mut fmt::Formatter<'_>,
365 ) -> Option<fmt::Result> {
366 None
367 }
368 fn debug_constraints(
369 _clauses: &chalk_ir::Constraints<Self>,
370 _fmt: &mut fmt::Formatter<'_>,
371 ) -> Option<fmt::Result> {
372 None
373 }
374
375 fn intern_variances<E>(
376 &self,
377 data: impl IntoIterator<Item = Result<chalk_ir::Variance, E>>,
378 ) -> Result<Self::InternedVariances, E> {
379 data.into_iter().collect()
380 }
381
382 fn variances_data<'a>(
383 &self,
384 variances: &'a Self::InternedVariances,
385 ) -> &'a [chalk_ir::Variance] {
386 &variances
387 }
388}
389
390impl chalk_ir::interner::HasInterner for Interner {
391 type Interner = Self;
392}