diff options
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 23 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 38 |
2 files changed, 14 insertions, 47 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 4378a9723..1a2a3a8c7 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -33,13 +33,13 @@ pub(super) mod tls; | |||
33 | mod interner; | 33 | mod interner; |
34 | mod mapping; | 34 | mod mapping; |
35 | 35 | ||
36 | pub(super) trait ToChalk { | 36 | pub(crate) trait ToChalk { |
37 | type Chalk; | 37 | type Chalk; |
38 | fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk; | 38 | fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk; |
39 | fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self; | 39 | fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self; |
40 | } | 40 | } |
41 | 41 | ||
42 | pub(super) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T | 42 | pub(crate) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T |
43 | where | 43 | where |
44 | T: ToChalk<Chalk = ChalkT>, | 44 | T: ToChalk<Chalk = ChalkT>, |
45 | { | 45 | { |
@@ -424,7 +424,7 @@ pub(crate) fn trait_datum_query( | |||
424 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 424 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); |
425 | let flags = rust_ir::TraitFlags { | 425 | let flags = rust_ir::TraitFlags { |
426 | auto: trait_data.auto, | 426 | auto: trait_data.auto, |
427 | upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate() != krate, | 427 | upstream: trait_.lookup(db.upcast()).container.krate() != krate, |
428 | non_enumerable: true, | 428 | non_enumerable: true, |
429 | coinductive: false, // only relevant for Chalk testing | 429 | coinductive: false, // only relevant for Chalk testing |
430 | // FIXME: set these flags correctly | 430 | // FIXME: set these flags correctly |
@@ -487,19 +487,14 @@ pub(crate) fn struct_datum_query( | |||
487 | struct_id: AdtId, | 487 | struct_id: AdtId, |
488 | ) -> Arc<StructDatum> { | 488 | ) -> Arc<StructDatum> { |
489 | debug!("struct_datum {:?}", struct_id); | 489 | debug!("struct_datum {:?}", struct_id); |
490 | let type_ctor = Ty::Adt(struct_id, Substs::empty()); | ||
491 | let chalk_ir::AdtId(adt_id) = struct_id; | 490 | let chalk_ir::AdtId(adt_id) = struct_id; |
492 | debug!("struct {:?} = {:?}", struct_id, type_ctor); | ||
493 | let num_params = generics(db.upcast(), adt_id.into()).len(); | 491 | let num_params = generics(db.upcast(), adt_id.into()).len(); |
494 | let upstream = adt_id.module(db.upcast()).krate() != krate; | 492 | let upstream = adt_id.module(db.upcast()).krate() != krate; |
495 | let where_clauses = type_ctor | 493 | let where_clauses = { |
496 | .as_generic_def() | 494 | let generic_params = generics(db.upcast(), adt_id.into()); |
497 | .map(|generic_def| { | 495 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); |
498 | let generic_params = generics(db.upcast(), generic_def); | 496 | convert_where_clauses(db, adt_id.into(), &bound_vars) |
499 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 497 | }; |
500 | convert_where_clauses(db, generic_def, &bound_vars) | ||
501 | }) | ||
502 | .unwrap_or_else(Vec::new); | ||
503 | let flags = rust_ir::AdtFlags { | 498 | let flags = rust_ir::AdtFlags { |
504 | upstream, | 499 | upstream, |
505 | // FIXME set fundamental and phantom_data flags correctly | 500 | // FIXME set fundamental and phantom_data flags correctly |
@@ -548,7 +543,7 @@ fn impl_def_datum( | |||
548 | let generic_params = generics(db.upcast(), impl_id.into()); | 543 | let generic_params = generics(db.upcast(), impl_id.into()); |
549 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 544 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); |
550 | let trait_ = trait_ref.trait_; | 545 | let trait_ = trait_ref.trait_; |
551 | let impl_type = if impl_id.lookup(db.upcast()).container.module(db.upcast()).krate() == krate { | 546 | let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate { |
552 | rust_ir::ImplType::Local | 547 | rust_ir::ImplType::Local |
553 | } else { | 548 | } else { |
554 | rust_ir::ImplType::External | 549 | rust_ir::ImplType::External |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 3a08b67e9..b0415e8b0 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -17,7 +17,7 @@ use crate::{ | |||
17 | primitive::UintTy, | 17 | primitive::UintTy, |
18 | traits::{Canonical, Obligation}, | 18 | traits::{Canonical, Obligation}, |
19 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, | 19 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, |
20 | OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment, TraitRef, Ty, | 20 | OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | use super::interner::*; | 23 | use super::interner::*; |
@@ -536,31 +536,6 @@ where | |||
536 | } | 536 | } |
537 | } | 537 | } |
538 | 538 | ||
539 | impl ToChalk for Arc<TraitEnvironment> { | ||
540 | type Chalk = chalk_ir::Environment<Interner>; | ||
541 | |||
542 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Environment<Interner> { | ||
543 | let mut clauses = Vec::new(); | ||
544 | for pred in &self.predicates { | ||
545 | if pred.is_error() { | ||
546 | // for env, we just ignore errors | ||
547 | continue; | ||
548 | } | ||
549 | let program_clause: chalk_ir::ProgramClause<Interner> = | ||
550 | pred.clone().to_chalk(db).cast(&Interner); | ||
551 | clauses.push(program_clause.into_from_env_clause(&Interner)); | ||
552 | } | ||
553 | chalk_ir::Environment::new(&Interner).add_clauses(&Interner, clauses) | ||
554 | } | ||
555 | |||
556 | fn from_chalk( | ||
557 | _db: &dyn HirDatabase, | ||
558 | _env: chalk_ir::Environment<Interner>, | ||
559 | ) -> Arc<TraitEnvironment> { | ||
560 | unimplemented!() | ||
561 | } | ||
562 | } | ||
563 | |||
564 | impl<T: ToChalk> ToChalk for InEnvironment<T> | 539 | impl<T: ToChalk> ToChalk for InEnvironment<T> |
565 | where | 540 | where |
566 | T::Chalk: chalk_ir::interner::HasInterner<Interner = Interner>, | 541 | T::Chalk: chalk_ir::interner::HasInterner<Interner = Interner>, |
@@ -569,19 +544,16 @@ where | |||
569 | 544 | ||
570 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> { | 545 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> { |
571 | chalk_ir::InEnvironment { | 546 | chalk_ir::InEnvironment { |
572 | environment: self.environment.to_chalk(db), | 547 | environment: self.environment.env.clone(), |
573 | goal: self.value.to_chalk(db), | 548 | goal: self.value.to_chalk(db), |
574 | } | 549 | } |
575 | } | 550 | } |
576 | 551 | ||
577 | fn from_chalk( | 552 | fn from_chalk( |
578 | db: &dyn HirDatabase, | 553 | _db: &dyn HirDatabase, |
579 | in_env: chalk_ir::InEnvironment<T::Chalk>, | 554 | _in_env: chalk_ir::InEnvironment<T::Chalk>, |
580 | ) -> InEnvironment<T> { | 555 | ) -> InEnvironment<T> { |
581 | InEnvironment { | 556 | unimplemented!() |
582 | environment: from_chalk(db, in_env.environment), | ||
583 | value: from_chalk(db, in_env.goal), | ||
584 | } | ||
585 | } | 557 | } |
586 | } | 558 | } |
587 | 559 | ||