aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/traits/chalk/interner.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/traits/chalk/interner.rs')
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/interner.rs298
1 files changed, 298 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/traits/chalk/interner.rs b/crates/ra_hir_ty/src/traits/chalk/interner.rs
new file mode 100644
index 000000000..032deca75
--- /dev/null
+++ b/crates/ra_hir_ty/src/traits/chalk/interner.rs
@@ -0,0 +1,298 @@
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 chalk_ir::{GenericArg, Goal, GoalData};
6use hir_def::TypeAliasId;
7use ra_db::salsa::InternId;
8use std::{fmt, sync::Arc};
9
10#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
11pub struct Interner;
12
13pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
14pub type AssociatedTyDatum = chalk_rust_ir::AssociatedTyDatum<Interner>;
15pub type TraitId = chalk_ir::TraitId<Interner>;
16pub type TraitDatum = chalk_rust_ir::TraitDatum<Interner>;
17pub type StructId = chalk_ir::AdtId<Interner>;
18pub type StructDatum = chalk_rust_ir::AdtDatum<Interner>;
19pub type ImplId = chalk_ir::ImplId<Interner>;
20pub type ImplDatum = chalk_rust_ir::ImplDatum<Interner>;
21pub type AssociatedTyValueId = chalk_rust_ir::AssociatedTyValueId<Interner>;
22pub type AssociatedTyValue = chalk_rust_ir::AssociatedTyValue<Interner>;
23
24impl chalk_ir::interner::Interner for Interner {
25 type InternedType = Box<chalk_ir::TyData<Self>>; // FIXME use Arc?
26 type InternedLifetime = chalk_ir::LifetimeData<Self>;
27 type InternedConst = Arc<chalk_ir::ConstData<Self>>;
28 type InternedConcreteConst = ();
29 type InternedGenericArg = chalk_ir::GenericArgData<Self>;
30 type InternedGoal = Arc<GoalData<Self>>;
31 type InternedGoals = Vec<Goal<Self>>;
32 type InternedSubstitution = Vec<GenericArg<Self>>;
33 type InternedProgramClause = chalk_ir::ProgramClauseData<Self>;
34 type InternedProgramClauses = Arc<[chalk_ir::ProgramClause<Self>]>;
35 type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
36 type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
37 type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
38 type DefId = InternId;
39 type InternedAdtId = InternId;
40 type Identifier = TypeAliasId;
41
42 fn debug_adt_id(type_kind_id: StructId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
43 tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt)))
44 }
45
46 fn debug_trait_id(type_kind_id: TraitId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
47 tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt)))
48 }
49
50 fn debug_assoc_type_id(id: AssocTypeId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
51 tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
52 }
53
54 fn debug_alias(
55 alias: &chalk_ir::AliasTy<Interner>,
56 fmt: &mut fmt::Formatter<'_>,
57 ) -> Option<fmt::Result> {
58 tls::with_current_program(|prog| Some(prog?.debug_alias(alias, fmt)))
59 }
60
61 fn debug_projection_ty(
62 proj: &chalk_ir::ProjectionTy<Interner>,
63 fmt: &mut fmt::Formatter<'_>,
64 ) -> Option<fmt::Result> {
65 tls::with_current_program(|prog| Some(prog?.debug_projection_ty(proj, fmt)))
66 }
67
68 fn debug_opaque_ty(
69 opaque_ty: &chalk_ir::OpaqueTy<Interner>,
70 fmt: &mut fmt::Formatter<'_>,
71 ) -> Option<fmt::Result> {
72 tls::with_current_program(|prog| Some(prog?.debug_opaque_ty(opaque_ty, fmt)))
73 }
74
75 fn debug_opaque_ty_id(
76 opaque_ty_id: chalk_ir::OpaqueTyId<Self>,
77 fmt: &mut fmt::Formatter<'_>,
78 ) -> Option<fmt::Result> {
79 tls::with_current_program(|prog| Some(prog?.debug_opaque_ty_id(opaque_ty_id, fmt)))
80 }
81
82 fn debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
83 tls::with_current_program(|prog| Some(prog?.debug_ty(ty, fmt)))
84 }
85
86 fn debug_lifetime(
87 lifetime: &chalk_ir::Lifetime<Interner>,
88 fmt: &mut fmt::Formatter<'_>,
89 ) -> Option<fmt::Result> {
90 tls::with_current_program(|prog| Some(prog?.debug_lifetime(lifetime, fmt)))
91 }
92
93 fn debug_generic_arg(
94 parameter: &GenericArg<Interner>,
95 fmt: &mut fmt::Formatter<'_>,
96 ) -> Option<fmt::Result> {
97 tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt)))
98 }
99
100 fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
101 tls::with_current_program(|prog| Some(prog?.debug_goal(goal, fmt)))
102 }
103
104 fn debug_goals(
105 goals: &chalk_ir::Goals<Interner>,
106 fmt: &mut fmt::Formatter<'_>,
107 ) -> Option<fmt::Result> {
108 tls::with_current_program(|prog| Some(prog?.debug_goals(goals, fmt)))
109 }
110
111 fn debug_program_clause_implication(
112 pci: &chalk_ir::ProgramClauseImplication<Interner>,
113 fmt: &mut fmt::Formatter<'_>,
114 ) -> Option<fmt::Result> {
115 tls::with_current_program(|prog| Some(prog?.debug_program_clause_implication(pci, fmt)))
116 }
117
118 fn debug_application_ty(
119 application_ty: &chalk_ir::ApplicationTy<Interner>,
120 fmt: &mut fmt::Formatter<'_>,
121 ) -> Option<fmt::Result> {
122 tls::with_current_program(|prog| Some(prog?.debug_application_ty(application_ty, fmt)))
123 }
124
125 fn debug_substitution(
126 substitution: &chalk_ir::Substitution<Interner>,
127 fmt: &mut fmt::Formatter<'_>,
128 ) -> Option<fmt::Result> {
129 tls::with_current_program(|prog| Some(prog?.debug_substitution(substitution, fmt)))
130 }
131
132 fn debug_separator_trait_ref(
133 separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>,
134 fmt: &mut fmt::Formatter<'_>,
135 ) -> Option<fmt::Result> {
136 tls::with_current_program(|prog| {
137 Some(prog?.debug_separator_trait_ref(separator_trait_ref, fmt))
138 })
139 }
140
141 fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Box<chalk_ir::TyData<Self>> {
142 Box::new(ty)
143 }
144
145 fn ty_data<'a>(&self, ty: &'a Box<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> {
146 ty
147 }
148
149 fn intern_lifetime(
150 &self,
151 lifetime: chalk_ir::LifetimeData<Self>,
152 ) -> chalk_ir::LifetimeData<Self> {
153 lifetime
154 }
155
156 fn lifetime_data<'a>(
157 &self,
158 lifetime: &'a chalk_ir::LifetimeData<Self>,
159 ) -> &'a chalk_ir::LifetimeData<Self> {
160 lifetime
161 }
162
163 fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Arc<chalk_ir::ConstData<Self>> {
164 Arc::new(constant)
165 }
166
167 fn const_data<'a>(
168 &self,
169 constant: &'a Arc<chalk_ir::ConstData<Self>>,
170 ) -> &'a chalk_ir::ConstData<Self> {
171 constant
172 }
173
174 fn const_eq(&self, _ty: &Box<chalk_ir::TyData<Self>>, _c1: &(), _c2: &()) -> bool {
175 true
176 }
177
178 fn intern_generic_arg(
179 &self,
180 parameter: chalk_ir::GenericArgData<Self>,
181 ) -> chalk_ir::GenericArgData<Self> {
182 parameter
183 }
184
185 fn generic_arg_data<'a>(
186 &self,
187 parameter: &'a chalk_ir::GenericArgData<Self>,
188 ) -> &'a chalk_ir::GenericArgData<Self> {
189 parameter
190 }
191
192 fn intern_goal(&self, goal: GoalData<Self>) -> Arc<GoalData<Self>> {
193 Arc::new(goal)
194 }
195
196 fn intern_goals<E>(
197 &self,
198 data: impl IntoIterator<Item = Result<Goal<Self>, E>>,
199 ) -> Result<Self::InternedGoals, E> {
200 data.into_iter().collect()
201 }
202
203 fn goal_data<'a>(&self, goal: &'a Arc<GoalData<Self>>) -> &'a GoalData<Self> {
204 goal
205 }
206
207 fn goals_data<'a>(&self, goals: &'a Vec<Goal<Interner>>) -> &'a [Goal<Interner>] {
208 goals
209 }
210
211 fn intern_substitution<E>(
212 &self,
213 data: impl IntoIterator<Item = Result<GenericArg<Self>, E>>,
214 ) -> Result<Vec<GenericArg<Self>>, E> {
215 data.into_iter().collect()
216 }
217
218 fn substitution_data<'a>(
219 &self,
220 substitution: &'a Vec<GenericArg<Self>>,
221 ) -> &'a [GenericArg<Self>] {
222 substitution
223 }
224
225 fn intern_program_clause(
226 &self,
227 data: chalk_ir::ProgramClauseData<Self>,
228 ) -> chalk_ir::ProgramClauseData<Self> {
229 data
230 }
231
232 fn program_clause_data<'a>(
233 &self,
234 clause: &'a chalk_ir::ProgramClauseData<Self>,
235 ) -> &'a chalk_ir::ProgramClauseData<Self> {
236 clause
237 }
238
239 fn intern_program_clauses<E>(
240 &self,
241 data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>,
242 ) -> Result<Arc<[chalk_ir::ProgramClause<Self>]>, E> {
243 data.into_iter().collect()
244 }
245
246 fn program_clauses_data<'a>(
247 &self,
248 clauses: &'a Arc<[chalk_ir::ProgramClause<Self>]>,
249 ) -> &'a [chalk_ir::ProgramClause<Self>] {
250 &clauses
251 }
252
253 fn intern_quantified_where_clauses<E>(
254 &self,
255 data: impl IntoIterator<Item = Result<chalk_ir::QuantifiedWhereClause<Self>, E>>,
256 ) -> Result<Self::InternedQuantifiedWhereClauses, E> {
257 data.into_iter().collect()
258 }
259
260 fn quantified_where_clauses_data<'a>(
261 &self,
262 clauses: &'a Self::InternedQuantifiedWhereClauses,
263 ) -> &'a [chalk_ir::QuantifiedWhereClause<Self>] {
264 clauses
265 }
266
267 fn intern_generic_arg_kinds<E>(
268 &self,
269 data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>,
270 ) -> Result<Self::InternedVariableKinds, E> {
271 data.into_iter().collect()
272 }
273
274 fn variable_kinds_data<'a>(
275 &self,
276 parameter_kinds: &'a Self::InternedVariableKinds,
277 ) -> &'a [chalk_ir::VariableKind<Self>] {
278 &parameter_kinds
279 }
280
281 fn intern_canonical_var_kinds<E>(
282 &self,
283 data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>,
284 ) -> Result<Self::InternedCanonicalVarKinds, E> {
285 data.into_iter().collect()
286 }
287
288 fn canonical_var_kinds_data<'a>(
289 &self,
290 canonical_var_kinds: &'a Self::InternedCanonicalVarKinds,
291 ) -> &'a [chalk_ir::CanonicalVarKind<Self>] {
292 &canonical_var_kinds
293 }
294}
295
296impl chalk_ir::interner::HasInterner for Interner {
297 type Interner = Self;
298}