2
2
//! representation of the various objects Chalk deals with (types, goals etc.).
3
3
4
4
use super :: tls;
5
+ use crate :: GenericArg ;
5
6
use base_db:: salsa:: InternId ;
6
- use chalk_ir:: { GenericArg , Goal , GoalData } ;
7
- use hir_def:: TypeAliasId ;
7
+ use chalk_ir:: { Goal , GoalData } ;
8
+ use hir_def:: {
9
+ intern:: { impl_internable, InternStorage , Internable , Interned } ,
10
+ TypeAliasId ,
11
+ } ;
8
12
use smallvec:: SmallVec ;
9
13
use std:: { fmt, sync:: Arc } ;
10
14
@@ -26,22 +30,47 @@ pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
26
30
pub ( crate ) type OpaqueTyDatum = chalk_solve:: rust_ir:: OpaqueTyDatum < Interner > ;
27
31
pub ( crate ) type Variances = chalk_ir:: Variances < Interner > ;
28
32
33
+ #[ derive( PartialEq , Eq , Hash , Debug ) ]
34
+ pub struct InternedWrapper < T > ( T ) ;
35
+
36
+ impl < T > std:: ops:: Deref for InternedWrapper < T > {
37
+ type Target = T ;
38
+
39
+ fn deref ( & self ) -> & Self :: Target {
40
+ & self . 0
41
+ }
42
+ }
43
+
44
+ impl_internable ! (
45
+ InternedWrapper <Vec <chalk_ir:: VariableKind <Interner >>>,
46
+ InternedWrapper <SmallVec <[ GenericArg ; 2 ] >>,
47
+ InternedWrapper <chalk_ir:: TyData <Interner >>,
48
+ InternedWrapper <chalk_ir:: LifetimeData <Interner >>,
49
+ InternedWrapper <chalk_ir:: ConstData <Interner >>,
50
+ InternedWrapper <Vec <chalk_ir:: CanonicalVarKind <Interner >>>,
51
+ InternedWrapper <Vec <chalk_ir:: ProgramClause <Interner >>>,
52
+ InternedWrapper <Vec <chalk_ir:: QuantifiedWhereClause <Interner >>>,
53
+ InternedWrapper <Vec <chalk_ir:: Variance >>,
54
+ ) ;
55
+
29
56
impl 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 > > ;
57
+ type InternedType = Interned < InternedWrapper < chalk_ir:: TyData < Interner > > > ;
58
+ type InternedLifetime = Interned < InternedWrapper < chalk_ir:: LifetimeData < Self > > > ;
59
+ type InternedConst = Interned < InternedWrapper < chalk_ir:: ConstData < Self > > > ;
33
60
type InternedConcreteConst = ( ) ;
34
61
type InternedGenericArg = chalk_ir:: GenericArgData < Self > ;
35
62
type InternedGoal = Arc < GoalData < Self > > ;
36
63
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 > > ;
64
+ type InternedSubstitution = Interned < InternedWrapper < SmallVec < [ GenericArg ; 2 ] > > > ;
65
+ type InternedProgramClause = chalk_ir:: ProgramClauseData < Self > ;
66
+ type InternedProgramClauses = Interned < InternedWrapper < Vec < chalk_ir:: ProgramClause < Self > > > > ;
67
+ type InternedQuantifiedWhereClauses =
68
+ Interned < InternedWrapper < Vec < chalk_ir:: QuantifiedWhereClause < Self > > > > ;
69
+ type InternedVariableKinds = Interned < InternedWrapper < Vec < chalk_ir:: VariableKind < Interner > > > > ;
70
+ type InternedCanonicalVarKinds =
71
+ Interned < InternedWrapper < Vec < chalk_ir:: CanonicalVarKind < Self > > > > ;
43
72
type InternedConstraints = Vec < chalk_ir:: InEnvironment < chalk_ir:: Constraint < Self > > > ;
44
- type InternedVariances = Arc < [ chalk_ir:: Variance ] > ;
73
+ type InternedVariances = Interned < InternedWrapper < Vec < chalk_ir:: Variance > > > ;
45
74
type DefId = InternId ;
46
75
type InternedAdtId = hir_def:: AdtId ;
47
76
type Identifier = TypeAliasId ;
@@ -99,7 +128,7 @@ impl chalk_ir::interner::Interner for Interner {
99
128
}
100
129
101
130
fn debug_generic_arg (
102
- parameter : & GenericArg < Interner > ,
131
+ parameter : & GenericArg ,
103
132
fmt : & mut fmt:: Formatter < ' _ > ,
104
133
) -> Option < fmt:: Result > {
105
134
tls:: with_current_program ( |prog| Some ( prog?. debug_generic_arg ( parameter, fmt) ) )
@@ -194,30 +223,30 @@ impl chalk_ir::interner::Interner for Interner {
194
223
195
224
fn intern_ty ( & self , kind : chalk_ir:: TyKind < Self > ) -> Self :: InternedType {
196
225
let flags = kind. compute_flags ( self ) ;
197
- Arc :: new ( chalk_ir:: TyData { kind, flags } )
226
+ Interned :: new ( InternedWrapper ( chalk_ir:: TyData { kind, flags } ) )
198
227
}
199
228
200
229
fn ty_data < ' a > ( & self , ty : & ' a Self :: InternedType ) -> & ' a chalk_ir:: TyData < Self > {
201
- ty
230
+ & ty . 0
202
231
}
203
232
204
233
fn intern_lifetime ( & self , lifetime : chalk_ir:: LifetimeData < Self > ) -> Self :: InternedLifetime {
205
- lifetime
234
+ Interned :: new ( InternedWrapper ( lifetime) )
206
235
}
207
236
208
237
fn lifetime_data < ' a > (
209
238
& self ,
210
239
lifetime : & ' a Self :: InternedLifetime ,
211
240
) -> & ' a chalk_ir:: LifetimeData < Self > {
212
- lifetime
241
+ & lifetime. 0
213
242
}
214
243
215
244
fn intern_const ( & self , constant : chalk_ir:: ConstData < Self > ) -> Self :: InternedConst {
216
- Arc :: new ( constant)
245
+ Interned :: new ( InternedWrapper ( constant) )
217
246
}
218
247
219
248
fn const_data < ' a > ( & self , constant : & ' a Self :: InternedConst ) -> & ' a chalk_ir:: ConstData < Self > {
220
- constant
249
+ & constant. 0
221
250
}
222
251
223
252
fn const_eq (
@@ -264,23 +293,23 @@ impl chalk_ir::interner::Interner for Interner {
264
293
265
294
fn intern_substitution < E > (
266
295
& self ,
267
- data : impl IntoIterator < Item = Result < GenericArg < Self > , E > > ,
296
+ data : impl IntoIterator < Item = Result < GenericArg , E > > ,
268
297
) -> Result < Self :: InternedSubstitution , E > {
269
- data. into_iter ( ) . collect ( )
298
+ Ok ( Interned :: new ( InternedWrapper ( data. into_iter ( ) . collect :: < Result < _ , _ > > ( ) ? ) ) )
270
299
}
271
300
272
301
fn substitution_data < ' a > (
273
302
& self ,
274
303
substitution : & ' a Self :: InternedSubstitution ,
275
- ) -> & ' a [ GenericArg < Self > ] {
276
- substitution
304
+ ) -> & ' a [ GenericArg ] {
305
+ & substitution. as_ref ( ) . 0
277
306
}
278
307
279
308
fn intern_program_clause (
280
309
& self ,
281
310
data : chalk_ir:: ProgramClauseData < Self > ,
282
311
) -> Self :: InternedProgramClause {
283
- Arc :: new ( data)
312
+ data
284
313
}
285
314
286
315
fn program_clause_data < ' a > (
@@ -294,7 +323,7 @@ impl chalk_ir::interner::Interner for Interner {
294
323
& self ,
295
324
data : impl IntoIterator < Item = Result < chalk_ir:: ProgramClause < Self > , E > > ,
296
325
) -> Result < Self :: InternedProgramClauses , E > {
297
- data. into_iter ( ) . collect ( )
326
+ Ok ( Interned :: new ( InternedWrapper ( data. into_iter ( ) . collect :: < Result < _ , _ > > ( ) ? ) ) )
298
327
}
299
328
300
329
fn program_clauses_data < ' a > (
@@ -308,7 +337,7 @@ impl chalk_ir::interner::Interner for Interner {
308
337
& self ,
309
338
data : impl IntoIterator < Item = Result < chalk_ir:: QuantifiedWhereClause < Self > , E > > ,
310
339
) -> Result < Self :: InternedQuantifiedWhereClauses , E > {
311
- data. into_iter ( ) . collect ( )
340
+ Ok ( Interned :: new ( InternedWrapper ( data. into_iter ( ) . collect :: < Result < _ , _ > > ( ) ? ) ) )
312
341
}
313
342
314
343
fn quantified_where_clauses_data < ' a > (
@@ -322,21 +351,21 @@ impl chalk_ir::interner::Interner for Interner {
322
351
& self ,
323
352
data : impl IntoIterator < Item = Result < chalk_ir:: VariableKind < Self > , E > > ,
324
353
) -> Result < Self :: InternedVariableKinds , E > {
325
- data. into_iter ( ) . collect ( )
354
+ Ok ( Interned :: new ( InternedWrapper ( data. into_iter ( ) . collect :: < Result < _ , _ > > ( ) ? ) ) )
326
355
}
327
356
328
357
fn variable_kinds_data < ' a > (
329
358
& self ,
330
359
parameter_kinds : & ' a Self :: InternedVariableKinds ,
331
360
) -> & ' a [ chalk_ir:: VariableKind < Self > ] {
332
- & parameter_kinds
361
+ & parameter_kinds. as_ref ( ) . 0
333
362
}
334
363
335
364
fn intern_canonical_var_kinds < E > (
336
365
& self ,
337
366
data : impl IntoIterator < Item = Result < chalk_ir:: CanonicalVarKind < Self > , E > > ,
338
367
) -> Result < Self :: InternedCanonicalVarKinds , E > {
339
- data. into_iter ( ) . collect ( )
368
+ Ok ( Interned :: new ( InternedWrapper ( data. into_iter ( ) . collect :: < Result < _ , _ > > ( ) ? ) ) )
340
369
}
341
370
342
371
fn canonical_var_kinds_data < ' a > (
@@ -376,7 +405,7 @@ impl chalk_ir::interner::Interner for Interner {
376
405
& self ,
377
406
data : impl IntoIterator < Item = Result < chalk_ir:: Variance , E > > ,
378
407
) -> Result < Self :: InternedVariances , E > {
379
- data. into_iter ( ) . collect ( )
408
+ Ok ( Interned :: new ( InternedWrapper ( data. into_iter ( ) . collect :: < Result < _ , _ > > ( ) ? ) ) )
380
409
}
381
410
382
411
fn variances_data < ' a > (
0 commit comments