diff options
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 26 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 39 |
2 files changed, 40 insertions, 25 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 011bef6f6..541e6082f 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -3,7 +3,7 @@ use std::sync::Arc; | |||
3 | 3 | ||
4 | use log::debug; | 4 | use log::debug; |
5 | 5 | ||
6 | use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg}; | 6 | use chalk_ir::{fold::shift::Shift, CanonicalVarKinds}; |
7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; | 7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; |
8 | 8 | ||
9 | use base_db::{salsa::InternKey, CrateId}; | 9 | use base_db::{salsa::InternKey, CrateId}; |
@@ -22,7 +22,7 @@ use crate::{ | |||
22 | to_assoc_type_id, to_chalk_trait_id, | 22 | to_assoc_type_id, to_chalk_trait_id, |
23 | utils::generics, | 23 | utils::generics, |
24 | AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution, | 24 | AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution, |
25 | TraitRef, Ty, TyKind, WhereClause, | 25 | TraitRef, Ty, TyBuilder, TyKind, WhereClause, |
26 | }; | 26 | }; |
27 | use mapping::{ | 27 | use mapping::{ |
28 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, | 28 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, |
@@ -80,7 +80,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
80 | fn impls_for_trait( | 80 | fn impls_for_trait( |
81 | &self, | 81 | &self, |
82 | trait_id: TraitId, | 82 | trait_id: TraitId, |
83 | parameters: &[GenericArg<Interner>], | 83 | parameters: &[chalk_ir::GenericArg<Interner>], |
84 | binders: &CanonicalVarKinds<Interner>, | 84 | binders: &CanonicalVarKinds<Interner>, |
85 | ) -> Vec<ImplId> { | 85 | ) -> Vec<ImplId> { |
86 | debug!("impls_for_trait {:?}", trait_id); | 86 | debug!("impls_for_trait {:?}", trait_id); |
@@ -92,7 +92,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
92 | ty: &Ty, | 92 | ty: &Ty, |
93 | binders: &CanonicalVarKinds<Interner>, | 93 | binders: &CanonicalVarKinds<Interner>, |
94 | ) -> Option<chalk_ir::TyVariableKind> { | 94 | ) -> Option<chalk_ir::TyVariableKind> { |
95 | if let TyKind::BoundVar(bv) = ty.interned(&Interner) { | 95 | if let TyKind::BoundVar(bv) = ty.kind(&Interner) { |
96 | let binders = binders.as_slice(&Interner); | 96 | let binders = binders.as_slice(&Interner); |
97 | if bv.debruijn == DebruijnIndex::INNERMOST { | 97 | if bv.debruijn == DebruijnIndex::INNERMOST { |
98 | if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind { | 98 | if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind { |
@@ -300,7 +300,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
300 | _closure_id: chalk_ir::ClosureId<Interner>, | 300 | _closure_id: chalk_ir::ClosureId<Interner>, |
301 | _substs: &chalk_ir::Substitution<Interner>, | 301 | _substs: &chalk_ir::Substitution<Interner>, |
302 | ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> { | 302 | ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> { |
303 | let ty = Ty::unit().to_chalk(self.db); | 303 | let ty = TyBuilder::unit().to_chalk(self.db); |
304 | make_binders(ty, 0) | 304 | make_binders(ty, 0) |
305 | } | 305 | } |
306 | fn closure_fn_substitution( | 306 | fn closure_fn_substitution( |
@@ -308,7 +308,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
308 | _closure_id: chalk_ir::ClosureId<Interner>, | 308 | _closure_id: chalk_ir::ClosureId<Interner>, |
309 | _substs: &chalk_ir::Substitution<Interner>, | 309 | _substs: &chalk_ir::Substitution<Interner>, |
310 | ) -> chalk_ir::Substitution<Interner> { | 310 | ) -> chalk_ir::Substitution<Interner> { |
311 | Substitution::empty().to_chalk(self.db) | 311 | Substitution::empty(&Interner).to_chalk(self.db) |
312 | } | 312 | } |
313 | 313 | ||
314 | fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String { | 314 | fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String { |
@@ -387,7 +387,7 @@ pub(crate) fn associated_ty_data_query( | |||
387 | // Lower bounds -- we could/should maybe move this to a separate query in `lower` | 387 | // Lower bounds -- we could/should maybe move this to a separate query in `lower` |
388 | let type_alias_data = db.type_alias_data(type_alias); | 388 | let type_alias_data = db.type_alias_data(type_alias); |
389 | let generic_params = generics(db.upcast(), type_alias.into()); | 389 | let generic_params = generics(db.upcast(), type_alias.into()); |
390 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 390 | let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); |
391 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); | 391 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); |
392 | let ctx = crate::TyLoweringContext::new(db, &resolver) | 392 | let ctx = crate::TyLoweringContext::new(db, &resolver) |
393 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); | 393 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); |
@@ -421,7 +421,7 @@ pub(crate) fn trait_datum_query( | |||
421 | let trait_data = db.trait_data(trait_); | 421 | let trait_data = db.trait_data(trait_); |
422 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); | 422 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); |
423 | let generic_params = generics(db.upcast(), trait_.into()); | 423 | let generic_params = generics(db.upcast(), trait_.into()); |
424 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 424 | let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); |
425 | let flags = rust_ir::TraitFlags { | 425 | let flags = rust_ir::TraitFlags { |
426 | auto: trait_data.is_auto, | 426 | auto: trait_data.is_auto, |
427 | upstream: trait_.lookup(db.upcast()).container.krate() != krate, | 427 | upstream: trait_.lookup(db.upcast()).container.krate() != krate, |
@@ -439,7 +439,7 @@ pub(crate) fn trait_datum_query( | |||
439 | lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); | 439 | lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); |
440 | let trait_datum = TraitDatum { | 440 | let trait_datum = TraitDatum { |
441 | id: trait_id, | 441 | id: trait_id, |
442 | binders: make_binders(trait_datum_bound, bound_vars.len()), | 442 | binders: make_binders(trait_datum_bound, bound_vars.len(&Interner)), |
443 | flags, | 443 | flags, |
444 | associated_ty_ids, | 444 | associated_ty_ids, |
445 | well_known, | 445 | well_known, |
@@ -490,7 +490,7 @@ pub(crate) fn struct_datum_query( | |||
490 | let upstream = adt_id.module(db.upcast()).krate() != krate; | 490 | let upstream = adt_id.module(db.upcast()).krate() != krate; |
491 | let where_clauses = { | 491 | let where_clauses = { |
492 | let generic_params = generics(db.upcast(), adt_id.into()); | 492 | let generic_params = generics(db.upcast(), adt_id.into()); |
493 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 493 | let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); |
494 | convert_where_clauses(db, adt_id.into(), &bound_vars) | 494 | convert_where_clauses(db, adt_id.into(), &bound_vars) |
495 | }; | 495 | }; |
496 | let flags = rust_ir::AdtFlags { | 496 | let flags = rust_ir::AdtFlags { |
@@ -539,7 +539,7 @@ fn impl_def_datum( | |||
539 | let impl_data = db.impl_data(impl_id); | 539 | let impl_data = db.impl_data(impl_id); |
540 | 540 | ||
541 | let generic_params = generics(db.upcast(), impl_id.into()); | 541 | let generic_params = generics(db.upcast(), impl_id.into()); |
542 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 542 | let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); |
543 | let trait_ = trait_ref.hir_trait_id(); | 543 | let trait_ = trait_ref.hir_trait_id(); |
544 | let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate { | 544 | let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate { |
545 | rust_ir::ImplType::Local | 545 | rust_ir::ImplType::Local |
@@ -577,7 +577,7 @@ fn impl_def_datum( | |||
577 | .collect(); | 577 | .collect(); |
578 | debug!("impl_datum: {:?}", impl_datum_bound); | 578 | debug!("impl_datum: {:?}", impl_datum_bound); |
579 | let impl_datum = ImplDatum { | 579 | let impl_datum = ImplDatum { |
580 | binders: make_binders(impl_datum_bound, bound_vars.len()), | 580 | binders: make_binders(impl_datum_bound, bound_vars.len(&Interner)), |
581 | impl_type, | 581 | impl_type, |
582 | polarity, | 582 | polarity, |
583 | associated_ty_value_ids, | 583 | associated_ty_value_ids, |
@@ -629,7 +629,7 @@ pub(crate) fn fn_def_datum_query( | |||
629 | let callable_def: CallableDefId = from_chalk(db, fn_def_id); | 629 | let callable_def: CallableDefId = from_chalk(db, fn_def_id); |
630 | let generic_params = generics(db.upcast(), callable_def.into()); | 630 | let generic_params = generics(db.upcast(), callable_def.into()); |
631 | let sig = db.callable_item_signature(callable_def); | 631 | let sig = db.callable_item_signature(callable_def); |
632 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 632 | let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); |
633 | let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); | 633 | let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); |
634 | let bound = rust_ir::FnDefDatumBound { | 634 | let bound = rust_ir::FnDefDatumBound { |
635 | // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway | 635 | // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index aef6b8a15..452b357e8 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -13,7 +13,7 @@ use crate::{ | |||
13 | db::HirDatabase, | 13 | db::HirDatabase, |
14 | primitive::UintTy, | 14 | primitive::UintTy, |
15 | traits::{Canonical, DomainGoal}, | 15 | traits::{Canonical, DomainGoal}, |
16 | AliasTy, CallableDefId, FnPointer, InEnvironment, OpaqueTy, ProjectionTy, | 16 | AliasTy, CallableDefId, FnPointer, GenericArg, InEnvironment, OpaqueTy, ProjectionTy, |
17 | QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause, | 17 | QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause, |
18 | }; | 18 | }; |
19 | 19 | ||
@@ -137,7 +137,7 @@ impl ToChalk for Ty { | |||
137 | db, | 137 | db, |
138 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), | 138 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), |
139 | ); | 139 | ); |
140 | TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs }) | 140 | TyKind::Function(FnPointer { num_args: (substs.len(&Interner) - 1), sig, substs }) |
141 | } | 141 | } |
142 | chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), | 142 | chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), |
143 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, | 143 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, |
@@ -216,24 +216,39 @@ fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty<Interner> { | |||
216 | chalk_ir::TyKind::Array(arg, const_).intern(&Interner) | 216 | chalk_ir::TyKind::Array(arg, const_).intern(&Interner) |
217 | } | 217 | } |
218 | 218 | ||
219 | impl ToChalk for GenericArg { | ||
220 | type Chalk = chalk_ir::GenericArg<Interner>; | ||
221 | |||
222 | fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk { | ||
223 | match self.interned { | ||
224 | crate::GenericArgData::Ty(ty) => ty.to_chalk(db).cast(&Interner), | ||
225 | } | ||
226 | } | ||
227 | |||
228 | fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self { | ||
229 | match chalk.interned() { | ||
230 | chalk_ir::GenericArgData::Ty(ty) => Ty::from_chalk(db, ty.clone()).cast(&Interner), | ||
231 | chalk_ir::GenericArgData::Lifetime(_) => unimplemented!(), | ||
232 | chalk_ir::GenericArgData::Const(_) => unimplemented!(), | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
219 | impl ToChalk for Substitution { | 237 | impl ToChalk for Substitution { |
220 | type Chalk = chalk_ir::Substitution<Interner>; | 238 | type Chalk = chalk_ir::Substitution<Interner>; |
221 | 239 | ||
222 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { | 240 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { |
223 | chalk_ir::Substitution::from_iter(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) | 241 | chalk_ir::Substitution::from_iter( |
242 | &Interner, | ||
243 | self.iter(&Interner).map(|ty| ty.clone().to_chalk(db)), | ||
244 | ) | ||
224 | } | 245 | } |
225 | 246 | ||
226 | fn from_chalk( | 247 | fn from_chalk( |
227 | db: &dyn HirDatabase, | 248 | db: &dyn HirDatabase, |
228 | parameters: chalk_ir::Substitution<Interner>, | 249 | parameters: chalk_ir::Substitution<Interner>, |
229 | ) -> Substitution { | 250 | ) -> Substitution { |
230 | let tys = parameters | 251 | let tys = parameters.iter(&Interner).map(|p| from_chalk(db, p.clone())).collect(); |
231 | .iter(&Interner) | ||
232 | .map(|p| match p.ty(&Interner) { | ||
233 | Some(ty) => from_chalk(db, ty.clone()), | ||
234 | None => unimplemented!(), | ||
235 | }) | ||
236 | .collect(); | ||
237 | Substitution(tys) | 252 | Substitution(tys) |
238 | } | 253 | } |
239 | } | 254 | } |
@@ -531,7 +546,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
531 | // have the expected self type | 546 | // have the expected self type |
532 | return None; | 547 | return None; |
533 | } | 548 | } |
534 | let args_no_self = trait_ref.substitution[1..] | 549 | let args_no_self = trait_ref.substitution.interned(&Interner)[1..] |
535 | .iter() | 550 | .iter() |
536 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) | 551 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) |
537 | .collect(); | 552 | .collect(); |
@@ -543,7 +558,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
543 | return None; | 558 | return None; |
544 | } | 559 | } |
545 | let trait_ = projection_ty.trait_(db); | 560 | let trait_ = projection_ty.trait_(db); |
546 | let args_no_self = projection_ty.substitution[1..] | 561 | let args_no_self = projection_ty.substitution.interned(&Interner)[1..] |
547 | .iter() | 562 | .iter() |
548 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) | 563 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) |
549 | .collect(); | 564 | .collect(); |