@@ -3,7 +3,7 @@ use std::{fmt, sync::Arc};
3
3
4
4
use log:: debug;
5
5
6
- use chalk_ir:: { cast:: Cast , Parameter , PlaceholderIndex , TypeName , UniverseIndex } ;
6
+ use chalk_ir:: { cast:: Cast , GoalData , Parameter , PlaceholderIndex , TypeName , UniverseIndex } ;
7
7
8
8
use hir_def:: { AssocContainerId , AssocItemId , GenericDefId , HasModule , Lookup , TypeAliasId } ;
9
9
use ra_db:: {
@@ -24,6 +24,8 @@ impl chalk_ir::family::TypeFamily for TypeFamily {
24
24
type InternedType = Box < chalk_ir:: TyData < Self > > ;
25
25
type InternedLifetime = chalk_ir:: LifetimeData < Self > ;
26
26
type InternedParameter = chalk_ir:: ParameterData < Self > ;
27
+ type InternedGoal = Arc < GoalData < Self > > ;
28
+ type InternedSubstitution = Vec < Parameter < Self > > ;
27
29
type DefId = InternId ;
28
30
29
31
// FIXME: implement these
@@ -78,6 +80,24 @@ impl chalk_ir::family::TypeFamily for TypeFamily {
78
80
fn parameter_data ( parameter : & chalk_ir:: ParameterData < Self > ) -> & chalk_ir:: ParameterData < Self > {
79
81
parameter
80
82
}
83
+
84
+ fn intern_goal ( goal : GoalData < Self > ) -> Arc < GoalData < Self > > {
85
+ Arc :: new ( goal)
86
+ }
87
+
88
+ fn goal_data ( goal : & Arc < GoalData < Self > > ) -> & GoalData < Self > {
89
+ goal
90
+ }
91
+
92
+ fn intern_substitution < E > (
93
+ data : impl IntoIterator < Item = Result < Parameter < Self > , E > > ,
94
+ ) -> Result < Vec < Parameter < Self > > , E > {
95
+ data. into_iter ( ) . collect ( )
96
+ }
97
+
98
+ fn substitution_data ( substitution : & Vec < Parameter < Self > > ) -> & [ Parameter < Self > ] {
99
+ substitution
100
+ }
81
101
}
82
102
83
103
impl chalk_ir:: family:: HasTypeFamily for TypeFamily {
@@ -114,13 +134,13 @@ impl ToChalk for Ty {
114
134
match self {
115
135
Ty :: Apply ( apply_ty) => {
116
136
let name = apply_ty. ctor . to_chalk ( db) ;
117
- let parameters = apply_ty. parameters . to_chalk ( db) ;
118
- chalk_ir:: ApplicationTy { name, parameters } . cast ( ) . intern ( )
137
+ let substitution = apply_ty. parameters . to_chalk ( db) ;
138
+ chalk_ir:: ApplicationTy { name, substitution } . cast ( ) . intern ( )
119
139
}
120
140
Ty :: Projection ( proj_ty) => {
121
141
let associated_ty_id = proj_ty. associated_ty . to_chalk ( db) ;
122
- let parameters = proj_ty. parameters . to_chalk ( db) ;
123
- chalk_ir:: ProjectionTy { associated_ty_id, parameters } . cast ( ) . intern ( )
142
+ let substitution = proj_ty. parameters . to_chalk ( db) ;
143
+ chalk_ir:: ProjectionTy { associated_ty_id, substitution } . cast ( ) . intern ( )
124
144
}
125
145
Ty :: Param { idx, .. } => {
126
146
PlaceholderIndex { ui : UniverseIndex :: ROOT , idx : idx as usize }
@@ -135,23 +155,14 @@ impl ToChalk for Ty {
135
155
. cloned ( )
136
156
. map ( |p| p. to_chalk ( db) )
137
157
. collect ( ) ;
138
- let bounded_ty = chalk_ir:: BoundedTy { bounds : make_binders ( where_clauses, 1 ) } ;
158
+ let bounded_ty = chalk_ir:: DynTy { bounds : make_binders ( where_clauses, 1 ) } ;
139
159
chalk_ir:: TyData :: Dyn ( bounded_ty) . intern ( )
140
160
}
141
- Ty :: Opaque ( predicates) => {
142
- let where_clauses = predicates
143
- . iter ( )
144
- . filter ( |p| !p. is_error ( ) )
145
- . cloned ( )
146
- . map ( |p| p. to_chalk ( db) )
147
- . collect ( ) ;
148
- let bounded_ty = chalk_ir:: BoundedTy { bounds : make_binders ( where_clauses, 1 ) } ;
149
- chalk_ir:: TyData :: Opaque ( bounded_ty) . intern ( )
150
- }
161
+ Ty :: Opaque ( _predicates) => unimplemented ! ( ) ,
151
162
Ty :: Unknown => {
152
- let parameters = Vec :: new ( ) ;
163
+ let substitution = chalk_ir :: Substitution :: empty ( ) ;
153
164
let name = TypeName :: Error ;
154
- chalk_ir:: ApplicationTy { name, parameters } . cast ( ) . intern ( )
165
+ chalk_ir:: ApplicationTy { name, substitution } . cast ( ) . intern ( )
155
166
}
156
167
}
157
168
}
@@ -161,7 +172,7 @@ impl ToChalk for Ty {
161
172
TypeName :: Error => Ty :: Unknown ,
162
173
_ => {
163
174
let ctor = from_chalk ( db, apply_ty. name ) ;
164
- let parameters = from_chalk ( db, apply_ty. parameters ) ;
175
+ let parameters = from_chalk ( db, apply_ty. substitution ) ;
165
176
Ty :: Apply ( ApplicationTy { ctor, parameters } )
166
177
}
167
178
} ,
@@ -171,10 +182,10 @@ impl ToChalk for Ty {
171
182
}
172
183
chalk_ir:: TyData :: Projection ( proj) => {
173
184
let associated_ty = from_chalk ( db, proj. associated_ty_id ) ;
174
- let parameters = from_chalk ( db, proj. parameters ) ;
185
+ let parameters = from_chalk ( db, proj. substitution ) ;
175
186
Ty :: Projection ( ProjectionTy { associated_ty, parameters } )
176
187
}
177
- chalk_ir:: TyData :: ForAll ( _) => unimplemented ! ( ) ,
188
+ chalk_ir:: TyData :: Function ( _) => unimplemented ! ( ) ,
178
189
chalk_ir:: TyData :: BoundVar ( idx) => Ty :: Bound ( idx as u32 ) ,
179
190
chalk_ir:: TyData :: InferenceVar ( _iv) => Ty :: Unknown ,
180
191
chalk_ir:: TyData :: Dyn ( where_clauses) => {
@@ -183,27 +194,18 @@ impl ToChalk for Ty {
183
194
where_clauses. bounds . value . into_iter ( ) . map ( |c| from_chalk ( db, c) ) . collect ( ) ;
184
195
Ty :: Dyn ( predicates)
185
196
}
186
- chalk_ir:: TyData :: Opaque ( where_clauses) => {
187
- assert_eq ! ( where_clauses. bounds. binders. len( ) , 1 ) ;
188
- let predicates =
189
- where_clauses. bounds . value . into_iter ( ) . map ( |c| from_chalk ( db, c) ) . collect ( ) ;
190
- Ty :: Opaque ( predicates)
191
- }
192
197
}
193
198
}
194
199
}
195
200
196
201
impl ToChalk for Substs {
197
- type Chalk = Vec < chalk_ir:: Parameter < TypeFamily > > ;
202
+ type Chalk = chalk_ir:: Substitution < TypeFamily > ;
198
203
199
- fn to_chalk ( self , db : & impl HirDatabase ) -> Vec < Parameter < TypeFamily > > {
200
- self . iter ( ) . map ( |ty| ty. clone ( ) . to_chalk ( db) . cast ( ) ) . collect ( )
204
+ fn to_chalk ( self , db : & impl HirDatabase ) -> chalk_ir :: Substitution < TypeFamily > {
205
+ chalk_ir :: Substitution :: from ( self . iter ( ) . map ( |ty| ty. clone ( ) . to_chalk ( db) ) )
201
206
}
202
207
203
- fn from_chalk (
204
- db : & impl HirDatabase ,
205
- parameters : Vec < chalk_ir:: Parameter < TypeFamily > > ,
206
- ) -> Substs {
208
+ fn from_chalk ( db : & impl HirDatabase , parameters : chalk_ir:: Substitution < TypeFamily > ) -> Substs {
207
209
let tys = parameters
208
210
. into_iter ( )
209
211
. map ( |p| match p. ty ( ) {
@@ -220,13 +222,13 @@ impl ToChalk for TraitRef {
220
222
221
223
fn to_chalk ( self : TraitRef , db : & impl HirDatabase ) -> chalk_ir:: TraitRef < TypeFamily > {
222
224
let trait_id = self . trait_ . to_chalk ( db) ;
223
- let parameters = self . substs . to_chalk ( db) ;
224
- chalk_ir:: TraitRef { trait_id, parameters }
225
+ let substitution = self . substs . to_chalk ( db) ;
226
+ chalk_ir:: TraitRef { trait_id, substitution }
225
227
}
226
228
227
229
fn from_chalk ( db : & impl HirDatabase , trait_ref : chalk_ir:: TraitRef < TypeFamily > ) -> Self {
228
230
let trait_ = from_chalk ( db, trait_ref. trait_id ) ;
229
- let substs = from_chalk ( db, trait_ref. parameters ) ;
231
+ let substs = from_chalk ( db, trait_ref. substitution ) ;
230
232
TraitRef { trait_, substs }
231
233
}
232
234
}
@@ -350,7 +352,7 @@ impl ToChalk for ProjectionTy {
350
352
fn to_chalk ( self , db : & impl HirDatabase ) -> chalk_ir:: ProjectionTy < TypeFamily > {
351
353
chalk_ir:: ProjectionTy {
352
354
associated_ty_id : self . associated_ty . to_chalk ( db) ,
353
- parameters : self . parameters . to_chalk ( db) ,
355
+ substitution : self . parameters . to_chalk ( db) ,
354
356
}
355
357
}
356
358
@@ -360,7 +362,7 @@ impl ToChalk for ProjectionTy {
360
362
) -> ProjectionTy {
361
363
ProjectionTy {
362
364
associated_ty : from_chalk ( db, projection_ty. associated_ty_id ) ,
363
- parameters : from_chalk ( db, projection_ty. parameters ) ,
365
+ parameters : from_chalk ( db, projection_ty. substitution ) ,
364
366
}
365
367
}
366
368
}
0 commit comments