aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/db.rs14
-rw-r--r--crates/ra_hir/src/ty.rs13
-rw-r--r--crates/ra_hir/src/ty/traits.rs10
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs35
4 files changed, 37 insertions, 35 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 31b21ca84..17cb63868 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -13,7 +13,7 @@ use crate::{
13 CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, Ty, TyDefId, TypeCtor, 13 CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, Ty, TyDefId, TypeCtor,
14 ValueTyDefId, 14 ValueTyDefId,
15 }, 15 },
16 Crate, DefWithBody, ImplBlock, 16 DefWithBody, ImplBlock,
17}; 17};
18 18
19pub use hir_def::db::{ 19pub use hir_def::db::{
@@ -71,7 +71,7 @@ pub trait HirDatabase: DefDatabase {
71 /// Mutex and the query does an untracked read internally, to make sure the 71 /// Mutex and the query does an untracked read internally, to make sure the
72 /// cached state is thrown away when input facts change. 72 /// cached state is thrown away when input facts change.
73 #[salsa::invoke(crate::ty::traits::trait_solver_query)] 73 #[salsa::invoke(crate::ty::traits::trait_solver_query)]
74 fn trait_solver(&self, krate: Crate) -> crate::ty::traits::TraitSolver; 74 fn trait_solver(&self, krate: CrateId) -> crate::ty::traits::TraitSolver;
75 75
76 // Interned IDs for Chalk integration 76 // Interned IDs for Chalk integration
77 #[salsa::interned] 77 #[salsa::interned]
@@ -93,35 +93,35 @@ pub trait HirDatabase: DefDatabase {
93 #[salsa::invoke(crate::ty::traits::chalk::trait_datum_query)] 93 #[salsa::invoke(crate::ty::traits::chalk::trait_datum_query)]
94 fn trait_datum( 94 fn trait_datum(
95 &self, 95 &self,
96 krate: Crate, 96 krate: CrateId,
97 trait_id: chalk_ir::TraitId, 97 trait_id: chalk_ir::TraitId,
98 ) -> Arc<chalk_rust_ir::TraitDatum<chalk_ir::family::ChalkIr>>; 98 ) -> Arc<chalk_rust_ir::TraitDatum<chalk_ir::family::ChalkIr>>;
99 99
100 #[salsa::invoke(crate::ty::traits::chalk::struct_datum_query)] 100 #[salsa::invoke(crate::ty::traits::chalk::struct_datum_query)]
101 fn struct_datum( 101 fn struct_datum(
102 &self, 102 &self,
103 krate: Crate, 103 krate: CrateId,
104 struct_id: chalk_ir::StructId, 104 struct_id: chalk_ir::StructId,
105 ) -> Arc<chalk_rust_ir::StructDatum<chalk_ir::family::ChalkIr>>; 105 ) -> Arc<chalk_rust_ir::StructDatum<chalk_ir::family::ChalkIr>>;
106 106
107 #[salsa::invoke(crate::ty::traits::chalk::impl_datum_query)] 107 #[salsa::invoke(crate::ty::traits::chalk::impl_datum_query)]
108 fn impl_datum( 108 fn impl_datum(
109 &self, 109 &self,
110 krate: Crate, 110 krate: CrateId,
111 impl_id: chalk_ir::ImplId, 111 impl_id: chalk_ir::ImplId,
112 ) -> Arc<chalk_rust_ir::ImplDatum<chalk_ir::family::ChalkIr>>; 112 ) -> Arc<chalk_rust_ir::ImplDatum<chalk_ir::family::ChalkIr>>;
113 113
114 #[salsa::invoke(crate::ty::traits::chalk::associated_ty_value_query)] 114 #[salsa::invoke(crate::ty::traits::chalk::associated_ty_value_query)]
115 fn associated_ty_value( 115 fn associated_ty_value(
116 &self, 116 &self,
117 krate: Crate, 117 krate: CrateId,
118 id: chalk_rust_ir::AssociatedTyValueId, 118 id: chalk_rust_ir::AssociatedTyValueId,
119 ) -> Arc<chalk_rust_ir::AssociatedTyValue<chalk_ir::family::ChalkIr>>; 119 ) -> Arc<chalk_rust_ir::AssociatedTyValue<chalk_ir::family::ChalkIr>>;
120 120
121 #[salsa::invoke(crate::ty::traits::trait_solve_query)] 121 #[salsa::invoke(crate::ty::traits::trait_solve_query)]
122 fn trait_solve( 122 fn trait_solve(
123 &self, 123 &self,
124 krate: Crate, 124 krate: CrateId,
125 goal: crate::ty::Canonical<crate::ty::InEnvironment<crate::ty::Obligation>>, 125 goal: crate::ty::Canonical<crate::ty::InEnvironment<crate::ty::Obligation>>,
126 ) -> Option<crate::ty::traits::Solution>; 126 ) -> Option<crate::ty::traits::Solution>;
127} 127}
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 791b6064a..a26776b26 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -23,13 +23,12 @@ use hir_def::{
23 GenericDefId, HasModule, Lookup, TraitId, TypeAliasId, 23 GenericDefId, HasModule, Lookup, TraitId, TypeAliasId,
24}; 24};
25use hir_expand::name::Name; 25use hir_expand::name::Name;
26use ra_db::{impl_intern_key, salsa}; 26use ra_db::{impl_intern_key, salsa, CrateId};
27 27
28use crate::{ 28use crate::{
29 db::HirDatabase, 29 db::HirDatabase,
30 ty::primitive::{FloatTy, IntTy, Uncertain}, 30 ty::primitive::{FloatTy, IntTy, Uncertain},
31 util::make_mut_slice, 31 util::make_mut_slice,
32 Crate,
33}; 32};
34use display::{HirDisplay, HirFormatter}; 33use display::{HirDisplay, HirFormatter};
35 34
@@ -162,7 +161,7 @@ impl TypeCtor {
162 } 161 }
163 } 162 }
164 163
165 pub fn krate(self, db: &impl HirDatabase) -> Option<Crate> { 164 pub fn krate(self, db: &impl HirDatabase) -> Option<CrateId> {
166 match self { 165 match self {
167 TypeCtor::Bool 166 TypeCtor::Bool
168 | TypeCtor::Char 167 | TypeCtor::Char
@@ -178,11 +177,9 @@ impl TypeCtor {
178 | TypeCtor::Tuple { .. } => None, 177 | TypeCtor::Tuple { .. } => None,
179 // Closure's krate is irrelevant for coherence I would think? 178 // Closure's krate is irrelevant for coherence I would think?
180 TypeCtor::Closure { .. } => None, 179 TypeCtor::Closure { .. } => None,
181 TypeCtor::Adt(adt) => Some(adt.module(db).krate.into()), 180 TypeCtor::Adt(adt) => Some(adt.module(db).krate),
182 TypeCtor::FnDef(callable) => Some(callable.krate(db).into()), 181 TypeCtor::FnDef(callable) => Some(callable.krate(db)),
183 TypeCtor::AssociatedType(type_alias) => { 182 TypeCtor::AssociatedType(type_alias) => Some(type_alias.lookup(db).module(db).krate),
184 Some(type_alias.lookup(db).module(db).krate.into())
185 }
186 } 183 }
187 } 184 }
188 185
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs
index 637e21e9c..39b489a4c 100644
--- a/crates/ra_hir/src/ty/traits.rs
+++ b/crates/ra_hir/src/ty/traits.rs
@@ -8,7 +8,7 @@ use ra_db::{impl_intern_key, salsa, CrateId};
8use ra_prof::profile; 8use ra_prof::profile;
9use rustc_hash::FxHashSet; 9use rustc_hash::FxHashSet;
10 10
11use crate::{db::HirDatabase, Crate, ImplBlock, TypeAlias}; 11use crate::{db::HirDatabase, ImplBlock, TypeAlias};
12 12
13use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; 13use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk};
14 14
@@ -18,7 +18,7 @@ pub(crate) mod chalk;
18 18
19#[derive(Debug, Clone)] 19#[derive(Debug, Clone)]
20pub struct TraitSolver { 20pub struct TraitSolver {
21 krate: Crate, 21 krate: CrateId,
22 inner: Arc<Mutex<chalk_solve::Solver<ChalkIr>>>, 22 inner: Arc<Mutex<chalk_solve::Solver<ChalkIr>>>,
23} 23}
24 24
@@ -60,12 +60,12 @@ const CHALK_SOLVER_MAX_SIZE: usize = 4;
60#[derive(Debug, Copy, Clone)] 60#[derive(Debug, Copy, Clone)]
61struct ChalkContext<'a, DB> { 61struct ChalkContext<'a, DB> {
62 db: &'a DB, 62 db: &'a DB,
63 krate: Crate, 63 krate: CrateId,
64} 64}
65 65
66pub(crate) fn trait_solver_query( 66pub(crate) fn trait_solver_query(
67 db: &(impl HirDatabase + salsa::Database), 67 db: &(impl HirDatabase + salsa::Database),
68 krate: Crate, 68 krate: CrateId,
69) -> TraitSolver { 69) -> TraitSolver {
70 db.salsa_runtime().report_untracked_read(); 70 db.salsa_runtime().report_untracked_read();
71 // krate parameter is just so we cache a unique solver per crate 71 // krate parameter is just so we cache a unique solver per crate
@@ -176,7 +176,7 @@ impl TypeWalk for ProjectionPredicate {
176/// Solve a trait goal using Chalk. 176/// Solve a trait goal using Chalk.
177pub(crate) fn trait_solve_query( 177pub(crate) fn trait_solve_query(
178 db: &impl HirDatabase, 178 db: &impl HirDatabase,
179 krate: Crate, 179 krate: CrateId,
180 goal: Canonical<InEnvironment<Obligation>>, 180 goal: Canonical<InEnvironment<Obligation>>,
181) -> Option<Solution> { 181) -> Option<Solution> {
182 let _p = profile("trait_solve_query"); 182 let _p = profile("trait_solve_query");
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index d879382a0..49fa95508 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -8,6 +8,7 @@ use chalk_ir::{
8 TypeKindId, TypeName, UniverseIndex, 8 TypeKindId, TypeName, UniverseIndex,
9}; 9};
10use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; 10use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
11use ra_db::CrateId;
11 12
12use hir_def::{ 13use hir_def::{
13 lang_item::LangItemTarget, AstItemDef, ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, 14 lang_item::LangItemTarget, AstItemDef, ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId,
@@ -21,7 +22,7 @@ use crate::{
21 db::HirDatabase, 22 db::HirDatabase,
22 ty::display::HirDisplay, 23 ty::display::HirDisplay,
23 ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, 24 ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk},
24 Crate, ImplBlock, TypeAlias, 25 ImplBlock, TypeAlias,
25}; 26};
26 27
27/// This represents a trait whose name we could not resolve. 28/// This represents a trait whose name we could not resolve.
@@ -448,7 +449,7 @@ where
448 let trait_: TraitId = from_chalk(self.db, trait_id); 449 let trait_: TraitId = from_chalk(self.db, trait_id);
449 let mut result: Vec<_> = self 450 let mut result: Vec<_> = self
450 .db 451 .db
451 .impls_for_trait(self.krate.crate_id, trait_.into()) 452 .impls_for_trait(self.krate, trait_.into())
452 .iter() 453 .iter()
453 .copied() 454 .copied()
454 .map(Impl::ImplBlock) 455 .map(Impl::ImplBlock)
@@ -487,7 +488,7 @@ where
487 &self, 488 &self,
488 id: chalk_rust_ir::AssociatedTyValueId, 489 id: chalk_rust_ir::AssociatedTyValueId,
489 ) -> Arc<AssociatedTyValue<ChalkIr>> { 490 ) -> Arc<AssociatedTyValue<ChalkIr>> {
490 self.db.associated_ty_value(self.krate, id) 491 self.db.associated_ty_value(self.krate.into(), id)
491 } 492 }
492 fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<ChalkIr>> { 493 fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<ChalkIr>> {
493 vec![] 494 vec![]
@@ -528,7 +529,7 @@ pub(crate) fn associated_ty_data_query(
528 529
529pub(crate) fn trait_datum_query( 530pub(crate) fn trait_datum_query(
530 db: &impl HirDatabase, 531 db: &impl HirDatabase,
531 krate: Crate, 532 krate: CrateId,
532 trait_id: chalk_ir::TraitId, 533 trait_id: chalk_ir::TraitId,
533) -> Arc<TraitDatum<ChalkIr>> { 534) -> Arc<TraitDatum<ChalkIr>> {
534 debug!("trait_datum {:?}", trait_id); 535 debug!("trait_datum {:?}", trait_id);
@@ -557,7 +558,7 @@ pub(crate) fn trait_datum_query(
557 let bound_vars = Substs::bound_vars(&generic_params); 558 let bound_vars = Substs::bound_vars(&generic_params);
558 let flags = chalk_rust_ir::TraitFlags { 559 let flags = chalk_rust_ir::TraitFlags {
559 auto: trait_data.auto, 560 auto: trait_data.auto,
560 upstream: trait_.module(db).krate != krate.crate_id, 561 upstream: trait_.module(db).krate != krate,
561 non_enumerable: true, 562 non_enumerable: true,
562 coinductive: false, // only relevant for Chalk testing 563 coinductive: false, // only relevant for Chalk testing
563 // FIXME set these flags correctly 564 // FIXME set these flags correctly
@@ -579,7 +580,7 @@ pub(crate) fn trait_datum_query(
579 580
580pub(crate) fn struct_datum_query( 581pub(crate) fn struct_datum_query(
581 db: &impl HirDatabase, 582 db: &impl HirDatabase,
582 krate: Crate, 583 krate: CrateId,
583 struct_id: chalk_ir::StructId, 584 struct_id: chalk_ir::StructId,
584) -> Arc<StructDatum<ChalkIr>> { 585) -> Arc<StructDatum<ChalkIr>> {
585 debug!("struct_datum {:?}", struct_id); 586 debug!("struct_datum {:?}", struct_id);
@@ -611,7 +612,7 @@ pub(crate) fn struct_datum_query(
611 612
612pub(crate) fn impl_datum_query( 613pub(crate) fn impl_datum_query(
613 db: &impl HirDatabase, 614 db: &impl HirDatabase,
614 krate: Crate, 615 krate: CrateId,
615 impl_id: ImplId, 616 impl_id: ImplId,
616) -> Arc<ImplDatum<ChalkIr>> { 617) -> Arc<ImplDatum<ChalkIr>> {
617 let _p = ra_prof::profile("impl_datum"); 618 let _p = ra_prof::profile("impl_datum");
@@ -626,7 +627,7 @@ pub(crate) fn impl_datum_query(
626 627
627fn impl_block_datum( 628fn impl_block_datum(
628 db: &impl HirDatabase, 629 db: &impl HirDatabase,
629 krate: Crate, 630 krate: CrateId,
630 impl_id: ImplId, 631 impl_id: ImplId,
631 impl_block: ImplBlock, 632 impl_block: ImplBlock,
632) -> Option<Arc<ImplDatum<ChalkIr>>> { 633) -> Option<Arc<ImplDatum<ChalkIr>>> {
@@ -634,7 +635,7 @@ fn impl_block_datum(
634 let bound_vars = Substs::bound_vars(&generic_params); 635 let bound_vars = Substs::bound_vars(&generic_params);
635 let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); 636 let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars);
636 let trait_ = trait_ref.trait_; 637 let trait_ = trait_ref.trait_;
637 let impl_type = if impl_block.krate(db) == krate { 638 let impl_type = if impl_block.krate(db).crate_id == krate {
638 chalk_rust_ir::ImplType::Local 639 chalk_rust_ir::ImplType::Local
639 } else { 640 } else {
640 chalk_rust_ir::ImplType::External 641 chalk_rust_ir::ImplType::External
@@ -698,7 +699,7 @@ fn invalid_impl_datum() -> Arc<ImplDatum<ChalkIr>> {
698 699
699fn closure_fn_trait_impl_datum( 700fn closure_fn_trait_impl_datum(
700 db: &impl HirDatabase, 701 db: &impl HirDatabase,
701 krate: Crate, 702 krate: CrateId,
702 data: super::ClosureFnTraitImplData, 703 data: super::ClosureFnTraitImplData,
703) -> Option<Arc<ImplDatum<ChalkIr>>> { 704) -> Option<Arc<ImplDatum<ChalkIr>>> {
704 // for some closure |X, Y| -> Z: 705 // for some closure |X, Y| -> Z:
@@ -755,7 +756,7 @@ fn closure_fn_trait_impl_datum(
755 756
756pub(crate) fn associated_ty_value_query( 757pub(crate) fn associated_ty_value_query(
757 db: &impl HirDatabase, 758 db: &impl HirDatabase,
758 krate: Crate, 759 krate: CrateId,
759 id: chalk_rust_ir::AssociatedTyValueId, 760 id: chalk_rust_ir::AssociatedTyValueId,
760) -> Arc<chalk_rust_ir::AssociatedTyValue<ChalkIr>> { 761) -> Arc<chalk_rust_ir::AssociatedTyValue<ChalkIr>> {
761 let data: AssocTyValue = from_chalk(db, id); 762 let data: AssocTyValue = from_chalk(db, id);
@@ -771,7 +772,7 @@ pub(crate) fn associated_ty_value_query(
771 772
772fn type_alias_associated_ty_value( 773fn type_alias_associated_ty_value(
773 db: &impl HirDatabase, 774 db: &impl HirDatabase,
774 _krate: Crate, 775 _krate: CrateId,
775 type_alias: TypeAlias, 776 type_alias: TypeAlias,
776) -> Arc<AssociatedTyValue<ChalkIr>> { 777) -> Arc<AssociatedTyValue<ChalkIr>> {
777 let impl_block = type_alias.impl_block(db).expect("assoc ty value should be in impl"); 778 let impl_block = type_alias.impl_block(db).expect("assoc ty value should be in impl");
@@ -798,7 +799,7 @@ fn type_alias_associated_ty_value(
798 799
799fn closure_fn_trait_output_assoc_ty_value( 800fn closure_fn_trait_output_assoc_ty_value(
800 db: &impl HirDatabase, 801 db: &impl HirDatabase,
801 krate: Crate, 802 krate: CrateId,
802 data: super::ClosureFnTraitImplData, 803 data: super::ClosureFnTraitImplData,
803) -> Arc<AssociatedTyValue<ChalkIr>> { 804) -> Arc<AssociatedTyValue<ChalkIr>> {
804 let impl_id = Impl::ClosureFnTraitImpl(data.clone()).to_chalk(db); 805 let impl_id = Impl::ClosureFnTraitImpl(data.clone()).to_chalk(db);
@@ -831,8 +832,12 @@ fn closure_fn_trait_output_assoc_ty_value(
831 Arc::new(value) 832 Arc::new(value)
832} 833}
833 834
834fn get_fn_trait(db: &impl HirDatabase, krate: Crate, fn_trait: super::FnTrait) -> Option<TraitId> { 835fn get_fn_trait(
835 let target = db.lang_item(krate.crate_id, fn_trait.lang_item_name().into())?; 836 db: &impl HirDatabase,
837 krate: CrateId,
838 fn_trait: super::FnTrait,
839) -> Option<TraitId> {
840 let target = db.lang_item(krate, fn_trait.lang_item_name().into())?;
836 match target { 841 match target {
837 LangItemTarget::TraitId(t) => Some(t), 842 LangItemTarget::TraitId(t) => Some(t),
838 _ => None, 843 _ => None,