aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-27 06:51:37 +0000
committerGitHub <[email protected]>2019-11-27 06:51:37 +0000
commitac5ec2adcdfc727f2b33f85a6ca62355b6a130f1 (patch)
tree130858a6312b6313900e2bed2361029f0dbf415d /crates/ra_hir/src/ty
parentd652e1e67f28c9accc9b98f99085e9509f711d33 (diff)
parentaa45561183493f274b78ca6be6b841bbc4b29e0d (diff)
Merge #2424
2424: Crate -> CrateId r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/traits.rs10
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs35
2 files changed, 25 insertions, 20 deletions
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,