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.rs393
1 files changed, 0 insertions, 393 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 94e94a26d..000000000
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ /dev/null
@@ -1,393 +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>) -> Arc<chalk_ir::TyData<Self>> {
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 Arc<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> {
201 ty
202 }
203
204 fn intern_lifetime(
205 &self,
206 lifetime: chalk_ir::LifetimeData<Self>,
207 ) -> chalk_ir::LifetimeData<Self> {
208 lifetime
209 }
210
211 fn lifetime_data<'a>(
212 &self,
213 lifetime: &'a chalk_ir::LifetimeData<Self>,
214 ) -> &'a chalk_ir::LifetimeData<Self> {
215 lifetime
216 }
217
218 fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Arc<chalk_ir::ConstData<Self>> {
219 Arc::new(constant)
220 }
221
222 fn const_data<'a>(
223 &self,
224 constant: &'a Arc<chalk_ir::ConstData<Self>>,
225 ) -> &'a chalk_ir::ConstData<Self> {
226 constant
227 }
228
229 fn const_eq(&self, _ty: &Arc<chalk_ir::TyData<Self>>, _c1: &(), _c2: &()) -> bool {
230 true
231 }
232
233 fn intern_generic_arg(
234 &self,
235 parameter: chalk_ir::GenericArgData<Self>,
236 ) -> chalk_ir::GenericArgData<Self> {
237 parameter
238 }
239
240 fn generic_arg_data<'a>(
241 &self,
242 parameter: &'a chalk_ir::GenericArgData<Self>,
243 ) -> &'a chalk_ir::GenericArgData<Self> {
244 parameter
245 }
246
247 fn intern_goal(&self, goal: GoalData<Self>) -> Arc<GoalData<Self>> {
248 Arc::new(goal)
249 }
250
251 fn intern_goals<E>(
252 &self,
253 data: impl IntoIterator<Item = Result<Goal<Self>, E>>,
254 ) -> Result<Self::InternedGoals, E> {
255 data.into_iter().collect()
256 }
257
258 fn goal_data<'a>(&self, goal: &'a Arc<GoalData<Self>>) -> &'a GoalData<Self> {
259 goal
260 }
261
262 fn goals_data<'a>(&self, goals: &'a Vec<Goal<Interner>>) -> &'a [Goal<Interner>] {
263 goals
264 }
265
266 fn intern_substitution<E>(
267 &self,
268 data: impl IntoIterator<Item = Result<GenericArg<Self>, E>>,
269 ) -> Result<Self::InternedSubstitution, E> {
270 data.into_iter().collect()
271 }
272
273 fn substitution_data<'a>(
274 &self,
275 substitution: &'a Self::InternedSubstitution,
276 ) -> &'a [GenericArg<Self>] {
277 substitution
278 }
279
280 fn intern_program_clause(
281 &self,
282 data: chalk_ir::ProgramClauseData<Self>,
283 ) -> Arc<chalk_ir::ProgramClauseData<Self>> {
284 Arc::new(data)
285 }
286
287 fn program_clause_data<'a>(
288 &self,
289 clause: &'a Arc<chalk_ir::ProgramClauseData<Self>>,
290 ) -> &'a chalk_ir::ProgramClauseData<Self> {
291 clause
292 }
293
294 fn intern_program_clauses<E>(
295 &self,
296 data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>,
297 ) -> Result<Arc<[chalk_ir::ProgramClause<Self>]>, E> {
298 data.into_iter().collect()
299 }
300
301 fn program_clauses_data<'a>(
302 &self,
303 clauses: &'a Arc<[chalk_ir::ProgramClause<Self>]>,
304 ) -> &'a [chalk_ir::ProgramClause<Self>] {
305 &clauses
306 }
307
308 fn intern_quantified_where_clauses<E>(
309 &self,
310 data: impl IntoIterator<Item = Result<chalk_ir::QuantifiedWhereClause<Self>, E>>,
311 ) -> Result<Self::InternedQuantifiedWhereClauses, E> {
312 data.into_iter().collect()
313 }
314
315 fn quantified_where_clauses_data<'a>(
316 &self,
317 clauses: &'a Self::InternedQuantifiedWhereClauses,
318 ) -> &'a [chalk_ir::QuantifiedWhereClause<Self>] {
319 clauses
320 }
321
322 fn intern_generic_arg_kinds<E>(
323 &self,
324 data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>,
325 ) -> Result<Self::InternedVariableKinds, E> {
326 data.into_iter().collect()
327 }
328
329 fn variable_kinds_data<'a>(
330 &self,
331 parameter_kinds: &'a Self::InternedVariableKinds,
332 ) -> &'a [chalk_ir::VariableKind<Self>] {
333 &parameter_kinds
334 }
335
336 fn intern_canonical_var_kinds<E>(
337 &self,
338 data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>,
339 ) -> Result<Self::InternedCanonicalVarKinds, E> {
340 data.into_iter().collect()
341 }
342
343 fn canonical_var_kinds_data<'a>(
344 &self,
345 canonical_var_kinds: &'a Self::InternedCanonicalVarKinds,
346 ) -> &'a [chalk_ir::CanonicalVarKind<Self>] {
347 &canonical_var_kinds
348 }
349
350 fn intern_constraints<E>(
351 &self,
352 data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>,
353 ) -> Result<Self::InternedConstraints, E> {
354 data.into_iter().collect()
355 }
356
357 fn constraints_data<'a>(
358 &self,
359 constraints: &'a Self::InternedConstraints,
360 ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
361 constraints
362 }
363 fn debug_closure_id(
364 _fn_def_id: chalk_ir::ClosureId<Self>,
365 _fmt: &mut fmt::Formatter<'_>,
366 ) -> Option<fmt::Result> {
367 None
368 }
369 fn debug_constraints(
370 _clauses: &chalk_ir::Constraints<Self>,
371 _fmt: &mut fmt::Formatter<'_>,
372 ) -> Option<fmt::Result> {
373 None
374 }
375
376 fn intern_variances<E>(
377 &self,
378 data: impl IntoIterator<Item = Result<chalk_ir::Variance, E>>,
379 ) -> Result<Self::InternedVariances, E> {
380 data.into_iter().collect()
381 }
382
383 fn variances_data<'a>(
384 &self,
385 variances: &'a Self::InternedVariances,
386 ) -> &'a [chalk_ir::Variance] {
387 &variances
388 }
389}
390
391impl chalk_ir::interner::HasInterner for Interner {
392 type Interner = Self;
393}