Skip to content

Commit 8ce6fea

Browse files
committed
Remove identity impls for ToChalk
1 parent a163554 commit 8ce6fea

File tree

4 files changed

+21
-215
lines changed

4 files changed

+21
-215
lines changed

crates/hir_ty/src/lower.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,7 @@ pub(crate) fn trait_environment_query(
950950
traits_in_scope
951951
.push((tr.self_type_parameter(&Interner).clone(), tr.hir_trait_id()));
952952
}
953-
let program_clause: chalk_ir::ProgramClause<Interner> =
954-
pred.clone().to_chalk(db).cast(&Interner);
953+
let program_clause: chalk_ir::ProgramClause<Interner> = pred.clone().cast(&Interner);
955954
clauses.push(program_clause.into_from_env_clause(&Interner));
956955
}
957956
}
@@ -974,7 +973,7 @@ pub(crate) fn trait_environment_query(
974973
let substs = TyBuilder::type_params_subst(db, trait_id);
975974
let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs };
976975
let pred = WhereClause::Implemented(trait_ref);
977-
let program_clause: chalk_ir::ProgramClause<Interner> = pred.to_chalk(db).cast(&Interner);
976+
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(&Interner);
978977
clauses.push(program_clause.into_from_env_clause(&Interner));
979978
}
980979

crates/hir_ty/src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub(crate) fn trait_solve_query(
9696
}
9797
}
9898

99-
let canonical = goal.to_chalk(db).cast(&Interner);
99+
let canonical = goal.cast(&Interner);
100100

101101
// We currently don't deal with universes (I think / hope they're not yet
102102
// relevant for our use cases?)

crates/hir_ty/src/traits/chalk.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
8686
debug!("impls_for_trait {:?}", trait_id);
8787
let trait_: hir_def::TraitId = from_chalk(self.db, trait_id);
8888

89-
let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone());
89+
let ty: Ty = parameters[0].assert_ty_ref(&Interner).clone();
9090

9191
fn binder_kind(
9292
ty: &Ty,
@@ -187,15 +187,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
187187
let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders();
188188
let data = &datas.impl_traits[idx as usize];
189189
let bound = OpaqueTyDatumBound {
190-
bounds: make_binders(
191-
data.bounds
192-
.skip_binders()
193-
.iter()
194-
.cloned()
195-
.map(|b| b.to_chalk(self.db))
196-
.collect(),
197-
1,
198-
),
190+
bounds: make_binders(data.bounds.skip_binders().iter().cloned().collect(), 1),
199191
where_clauses: make_binders(vec![], 0),
200192
};
201193
chalk_ir::Binders::new(binders, bound)
@@ -246,8 +238,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
246238
let bound = OpaqueTyDatumBound {
247239
bounds: make_binders(
248240
vec![
249-
crate::wrap_empty_binders(impl_bound).to_chalk(self.db),
250-
crate::wrap_empty_binders(proj_bound).to_chalk(self.db),
241+
crate::wrap_empty_binders(impl_bound),
242+
crate::wrap_empty_binders(proj_bound),
251243
],
252244
1,
253245
),
@@ -272,7 +264,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
272264

273265
fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> {
274266
// FIXME: actually provide the hidden type; it is relevant for auto traits
275-
TyKind::Error.intern(&Interner).to_chalk(self.db)
267+
TyKind::Error.intern(&Interner)
276268
}
277269

278270
fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool {
@@ -293,12 +285,11 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
293285
_closure_id: chalk_ir::ClosureId<Interner>,
294286
substs: &chalk_ir::Substitution<Interner>,
295287
) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> {
296-
let sig_ty: Ty =
297-
from_chalk(self.db, substs.at(&Interner, 0).assert_ty_ref(&Interner).clone());
288+
let sig_ty = substs.at(&Interner, 0).assert_ty_ref(&Interner).clone();
298289
let sig = &sig_ty.callable_sig(self.db).expect("first closure param should be fn ptr");
299290
let io = rust_ir::FnDefInputsAndOutputDatum {
300-
argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(self.db)).collect(),
301-
return_type: sig.ret().clone().to_chalk(self.db),
291+
argument_types: sig.params().iter().cloned().collect(),
292+
return_type: sig.ret().clone(),
302293
};
303294
make_binders(io.shifted_in(&Interner), 0)
304295
}
@@ -307,15 +298,15 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
307298
_closure_id: chalk_ir::ClosureId<Interner>,
308299
_substs: &chalk_ir::Substitution<Interner>,
309300
) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> {
310-
let ty = TyBuilder::unit().to_chalk(self.db);
301+
let ty = TyBuilder::unit();
311302
make_binders(ty, 0)
312303
}
313304
fn closure_fn_substitution(
314305
&self,
315306
_closure_id: chalk_ir::ClosureId<Interner>,
316307
_substs: &chalk_ir::Substitution<Interner>,
317308
) -> chalk_ir::Substitution<Interner> {
318-
Substitution::empty(&Interner).to_chalk(self.db)
309+
Substitution::empty(&Interner)
319310
}
320311

321312
fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String {
@@ -410,7 +401,7 @@ pub(crate) fn associated_ty_data_query(
410401
let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars);
411402
let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses };
412403
let datum = AssociatedTyDatum {
413-
trait_id: trait_.to_chalk(db),
404+
trait_id: to_chalk_trait_id(trait_),
414405
id,
415406
name: type_alias,
416407
binders: make_binders(bound_data, generic_params.len()),
@@ -563,7 +554,6 @@ fn impl_def_datum(
563554
trait_ref.display(db),
564555
where_clauses
565556
);
566-
let trait_ref = trait_ref.to_chalk(db);
567557

568558
let polarity = if negative { rust_ir::Polarity::Negative } else { rust_ir::Polarity::Positive };
569559

@@ -624,7 +614,7 @@ fn type_alias_associated_ty_value(
624614
.associated_type_by_name(&type_alias_data.name)
625615
.expect("assoc ty value should not exist"); // validated when building the impl data as well
626616
let (ty, binders) = db.ty(type_alias.into()).into_value_and_skipped_binders();
627-
let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) };
617+
let value_bound = rust_ir::AssociatedTyValueBound { ty };
628618
let value = rust_ir::AssociatedTyValue {
629619
impl_id: impl_id.to_chalk(db),
630620
associated_ty_id: to_assoc_type_id(assoc_ty),
@@ -647,8 +637,8 @@ pub(crate) fn fn_def_datum_query(
647637
// Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway
648638
inputs_and_output: make_binders(
649639
rust_ir::FnDefInputsAndOutputDatum {
650-
argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(),
651-
return_type: sig.ret().clone().to_chalk(db),
640+
argument_types: sig.params().iter().cloned().collect(),
641+
return_type: sig.ret().clone(),
652642
}
653643
.shifted_in(&Interner),
654644
0,

crates/hir_ty/src/traits/chalk/mapping.rs

Lines changed: 4 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,6 @@ use crate::{
1818
use super::interner::*;
1919
use super::*;
2020

21-
impl ToChalk for Ty {
22-
type Chalk = chalk_ir::Ty<Interner>;
23-
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
24-
self
25-
}
26-
fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
27-
chalk
28-
}
29-
}
30-
31-
impl ToChalk for GenericArg {
32-
type Chalk = chalk_ir::GenericArg<Interner>;
33-
34-
fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
35-
self
36-
}
37-
38-
fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
39-
chalk
40-
}
41-
}
42-
43-
impl ToChalk for Substitution {
44-
type Chalk = chalk_ir::Substitution<Interner>;
45-
46-
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> {
47-
self
48-
}
49-
50-
fn from_chalk(
51-
db: &dyn HirDatabase,
52-
parameters: chalk_ir::Substitution<Interner>,
53-
) -> Substitution {
54-
parameters
55-
}
56-
}
57-
58-
impl ToChalk for TraitRef {
59-
type Chalk = chalk_ir::TraitRef<Interner>;
60-
61-
fn to_chalk(self: TraitRef, db: &dyn HirDatabase) -> chalk_ir::TraitRef<Interner> {
62-
self
63-
}
64-
65-
fn from_chalk(db: &dyn HirDatabase, trait_ref: chalk_ir::TraitRef<Interner>) -> Self {
66-
trait_ref
67-
}
68-
}
69-
7021
impl ToChalk for hir_def::TraitId {
7122
type Chalk = TraitId;
7223

@@ -120,140 +71,6 @@ impl ToChalk for TypeAliasAsValue {
12071
}
12172
}
12273

123-
impl ToChalk for WhereClause {
124-
type Chalk = chalk_ir::WhereClause<Interner>;
125-
126-
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::WhereClause<Interner> {
127-
self
128-
}
129-
130-
fn from_chalk(
131-
db: &dyn HirDatabase,
132-
where_clause: chalk_ir::WhereClause<Interner>,
133-
) -> WhereClause {
134-
where_clause
135-
}
136-
}
137-
138-
impl ToChalk for ProjectionTy {
139-
type Chalk = chalk_ir::ProjectionTy<Interner>;
140-
141-
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
142-
self
143-
}
144-
145-
fn from_chalk(
146-
db: &dyn HirDatabase,
147-
projection_ty: chalk_ir::ProjectionTy<Interner>,
148-
) -> ProjectionTy {
149-
projection_ty
150-
}
151-
}
152-
impl ToChalk for OpaqueTy {
153-
type Chalk = chalk_ir::OpaqueTy<Interner>;
154-
155-
fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
156-
self
157-
}
158-
159-
fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
160-
chalk
161-
}
162-
}
163-
164-
impl ToChalk for AliasTy {
165-
type Chalk = chalk_ir::AliasTy<Interner>;
166-
167-
fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
168-
self
169-
}
170-
171-
fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
172-
chalk
173-
}
174-
}
175-
176-
impl ToChalk for AliasEq {
177-
type Chalk = chalk_ir::AliasEq<Interner>;
178-
179-
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::AliasEq<Interner> {
180-
self
181-
}
182-
183-
fn from_chalk(db: &dyn HirDatabase, alias_eq: chalk_ir::AliasEq<Interner>) -> Self {
184-
alias_eq
185-
}
186-
}
187-
188-
impl ToChalk for DomainGoal {
189-
type Chalk = chalk_ir::DomainGoal<Interner>;
190-
191-
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> {
192-
self
193-
}
194-
195-
fn from_chalk(_db: &dyn HirDatabase, goal: chalk_ir::DomainGoal<Interner>) -> Self {
196-
goal
197-
}
198-
}
199-
200-
impl<T> ToChalk for Canonical<T>
201-
where
202-
T: HasInterner<Interner = Interner>,
203-
{
204-
type Chalk = chalk_ir::Canonical<T>;
205-
206-
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical<T> {
207-
self
208-
}
209-
210-
fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T>) -> Canonical<T> {
211-
canonical
212-
}
213-
}
214-
215-
impl<T: ToChalk> ToChalk for InEnvironment<T>
216-
where
217-
T: HasInterner<Interner = Interner>,
218-
{
219-
type Chalk = chalk_ir::InEnvironment<T>;
220-
221-
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T> {
222-
self
223-
}
224-
225-
fn from_chalk(_db: &dyn HirDatabase, in_env: chalk_ir::InEnvironment<T>) -> InEnvironment<T> {
226-
in_env
227-
}
228-
}
229-
230-
impl<T: ToChalk> ToChalk for crate::Binders<T>
231-
where
232-
T: HasInterner<Interner = Interner>,
233-
{
234-
type Chalk = chalk_ir::Binders<T>;
235-
236-
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T> {
237-
self
238-
}
239-
240-
fn from_chalk(db: &dyn HirDatabase, binders: chalk_ir::Binders<T>) -> crate::Binders<T> {
241-
binders
242-
}
243-
}
244-
245-
impl ToChalk for crate::ConstrainedSubst {
246-
type Chalk = chalk_ir::ConstrainedSubst<Interner>;
247-
248-
fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk {
249-
self
250-
}
251-
252-
fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
253-
chalk
254-
}
255-
}
256-
25774
pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T>
25875
where
25976
T: HasInterner<Interner = Interner>,
@@ -276,7 +93,7 @@ pub(super) fn convert_where_clauses(
27693
let generic_predicates = db.generic_predicates(def);
27794
let mut result = Vec::with_capacity(generic_predicates.len());
27895
for pred in generic_predicates.iter() {
279-
result.push(pred.clone().substitute(&Interner, substs).to_chalk(db));
96+
result.push(pred.clone().substitute(&Interner, substs));
28097
}
28198
result
28299
}
@@ -299,7 +116,7 @@ pub(super) fn generic_predicate_to_inline_bound(
299116
}
300117
let args_no_self = trait_ref.substitution.interned()[1..]
301118
.iter()
302-
.map(|ty| ty.clone().to_chalk(db).cast(&Interner))
119+
.map(|ty| ty.clone().cast(&Interner))
303120
.collect();
304121
let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self };
305122
Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
@@ -311,10 +128,10 @@ pub(super) fn generic_predicate_to_inline_bound(
311128
let trait_ = projection_ty.trait_(db);
312129
let args_no_self = projection_ty.substitution.interned()[1..]
313130
.iter()
314-
.map(|ty| ty.clone().to_chalk(db).cast(&Interner))
131+
.map(|ty| ty.clone().cast(&Interner))
315132
.collect();
316133
let alias_eq_bound = rust_ir::AliasEqBound {
317-
value: ty.clone().to_chalk(db),
134+
value: ty.clone(),
318135
trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
319136
associated_ty_id: projection_ty.associated_ty_id,
320137
parameters: Vec::new(), // FIXME we don't support generic associated types yet

0 commit comments

Comments
 (0)