From aa45561183493f274b78ca6be6b841bbc4b29e0d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 27 Nov 2019 09:42:55 +0300 Subject: Crate -> CrateId --- crates/ra_hir/src/db.rs | 14 +++++++------- crates/ra_hir/src/ty.rs | 13 +++++-------- crates/ra_hir/src/ty/traits.rs | 10 +++++----- crates/ra_hir/src/ty/traits/chalk.rs | 35 ++++++++++++++++++++--------------- 4 files changed, 37 insertions(+), 35 deletions(-) (limited to 'crates/ra_hir/src') 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::{ CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, Ty, TyDefId, TypeCtor, ValueTyDefId, }, - Crate, DefWithBody, ImplBlock, + DefWithBody, ImplBlock, }; pub use hir_def::db::{ @@ -71,7 +71,7 @@ pub trait HirDatabase: DefDatabase { /// Mutex and the query does an untracked read internally, to make sure the /// cached state is thrown away when input facts change. #[salsa::invoke(crate::ty::traits::trait_solver_query)] - fn trait_solver(&self, krate: Crate) -> crate::ty::traits::TraitSolver; + fn trait_solver(&self, krate: CrateId) -> crate::ty::traits::TraitSolver; // Interned IDs for Chalk integration #[salsa::interned] @@ -93,35 +93,35 @@ pub trait HirDatabase: DefDatabase { #[salsa::invoke(crate::ty::traits::chalk::trait_datum_query)] fn trait_datum( &self, - krate: Crate, + krate: CrateId, trait_id: chalk_ir::TraitId, ) -> Arc>; #[salsa::invoke(crate::ty::traits::chalk::struct_datum_query)] fn struct_datum( &self, - krate: Crate, + krate: CrateId, struct_id: chalk_ir::StructId, ) -> Arc>; #[salsa::invoke(crate::ty::traits::chalk::impl_datum_query)] fn impl_datum( &self, - krate: Crate, + krate: CrateId, impl_id: chalk_ir::ImplId, ) -> Arc>; #[salsa::invoke(crate::ty::traits::chalk::associated_ty_value_query)] fn associated_ty_value( &self, - krate: Crate, + krate: CrateId, id: chalk_rust_ir::AssociatedTyValueId, ) -> Arc>; #[salsa::invoke(crate::ty::traits::trait_solve_query)] fn trait_solve( &self, - krate: Crate, + krate: CrateId, goal: crate::ty::Canonical>, ) -> Option; } 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::{ GenericDefId, HasModule, Lookup, TraitId, TypeAliasId, }; use hir_expand::name::Name; -use ra_db::{impl_intern_key, salsa}; +use ra_db::{impl_intern_key, salsa, CrateId}; use crate::{ db::HirDatabase, ty::primitive::{FloatTy, IntTy, Uncertain}, util::make_mut_slice, - Crate, }; use display::{HirDisplay, HirFormatter}; @@ -162,7 +161,7 @@ impl TypeCtor { } } - pub fn krate(self, db: &impl HirDatabase) -> Option { + pub fn krate(self, db: &impl HirDatabase) -> Option { match self { TypeCtor::Bool | TypeCtor::Char @@ -178,11 +177,9 @@ impl TypeCtor { | TypeCtor::Tuple { .. } => None, // Closure's krate is irrelevant for coherence I would think? TypeCtor::Closure { .. } => None, - TypeCtor::Adt(adt) => Some(adt.module(db).krate.into()), - TypeCtor::FnDef(callable) => Some(callable.krate(db).into()), - TypeCtor::AssociatedType(type_alias) => { - Some(type_alias.lookup(db).module(db).krate.into()) - } + TypeCtor::Adt(adt) => Some(adt.module(db).krate), + TypeCtor::FnDef(callable) => Some(callable.krate(db)), + TypeCtor::AssociatedType(type_alias) => Some(type_alias.lookup(db).module(db).krate), } } 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}; use ra_prof::profile; use rustc_hash::FxHashSet; -use crate::{db::HirDatabase, Crate, ImplBlock, TypeAlias}; +use crate::{db::HirDatabase, ImplBlock, TypeAlias}; use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; @@ -18,7 +18,7 @@ pub(crate) mod chalk; #[derive(Debug, Clone)] pub struct TraitSolver { - krate: Crate, + krate: CrateId, inner: Arc>>, } @@ -60,12 +60,12 @@ const CHALK_SOLVER_MAX_SIZE: usize = 4; #[derive(Debug, Copy, Clone)] struct ChalkContext<'a, DB> { db: &'a DB, - krate: Crate, + krate: CrateId, } pub(crate) fn trait_solver_query( db: &(impl HirDatabase + salsa::Database), - krate: Crate, + krate: CrateId, ) -> TraitSolver { db.salsa_runtime().report_untracked_read(); // krate parameter is just so we cache a unique solver per crate @@ -176,7 +176,7 @@ impl TypeWalk for ProjectionPredicate { /// Solve a trait goal using Chalk. pub(crate) fn trait_solve_query( db: &impl HirDatabase, - krate: Crate, + krate: CrateId, goal: Canonical>, ) -> Option { 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::{ TypeKindId, TypeName, UniverseIndex, }; use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; +use ra_db::CrateId; use hir_def::{ lang_item::LangItemTarget, AstItemDef, ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, @@ -21,7 +22,7 @@ use crate::{ db::HirDatabase, ty::display::HirDisplay, ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, - Crate, ImplBlock, TypeAlias, + ImplBlock, TypeAlias, }; /// This represents a trait whose name we could not resolve. @@ -448,7 +449,7 @@ where let trait_: TraitId = from_chalk(self.db, trait_id); let mut result: Vec<_> = self .db - .impls_for_trait(self.krate.crate_id, trait_.into()) + .impls_for_trait(self.krate, trait_.into()) .iter() .copied() .map(Impl::ImplBlock) @@ -487,7 +488,7 @@ where &self, id: chalk_rust_ir::AssociatedTyValueId, ) -> Arc> { - self.db.associated_ty_value(self.krate, id) + self.db.associated_ty_value(self.krate.into(), id) } fn custom_clauses(&self) -> Vec> { vec![] @@ -528,7 +529,7 @@ pub(crate) fn associated_ty_data_query( pub(crate) fn trait_datum_query( db: &impl HirDatabase, - krate: Crate, + krate: CrateId, trait_id: chalk_ir::TraitId, ) -> Arc> { debug!("trait_datum {:?}", trait_id); @@ -557,7 +558,7 @@ pub(crate) fn trait_datum_query( let bound_vars = Substs::bound_vars(&generic_params); let flags = chalk_rust_ir::TraitFlags { auto: trait_data.auto, - upstream: trait_.module(db).krate != krate.crate_id, + upstream: trait_.module(db).krate != krate, non_enumerable: true, coinductive: false, // only relevant for Chalk testing // FIXME set these flags correctly @@ -579,7 +580,7 @@ pub(crate) fn trait_datum_query( pub(crate) fn struct_datum_query( db: &impl HirDatabase, - krate: Crate, + krate: CrateId, struct_id: chalk_ir::StructId, ) -> Arc> { debug!("struct_datum {:?}", struct_id); @@ -611,7 +612,7 @@ pub(crate) fn struct_datum_query( pub(crate) fn impl_datum_query( db: &impl HirDatabase, - krate: Crate, + krate: CrateId, impl_id: ImplId, ) -> Arc> { let _p = ra_prof::profile("impl_datum"); @@ -626,7 +627,7 @@ pub(crate) fn impl_datum_query( fn impl_block_datum( db: &impl HirDatabase, - krate: Crate, + krate: CrateId, impl_id: ImplId, impl_block: ImplBlock, ) -> Option>> { @@ -634,7 +635,7 @@ fn impl_block_datum( let bound_vars = Substs::bound_vars(&generic_params); let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); let trait_ = trait_ref.trait_; - let impl_type = if impl_block.krate(db) == krate { + let impl_type = if impl_block.krate(db).crate_id == krate { chalk_rust_ir::ImplType::Local } else { chalk_rust_ir::ImplType::External @@ -698,7 +699,7 @@ fn invalid_impl_datum() -> Arc> { fn closure_fn_trait_impl_datum( db: &impl HirDatabase, - krate: Crate, + krate: CrateId, data: super::ClosureFnTraitImplData, ) -> Option>> { // for some closure |X, Y| -> Z: @@ -755,7 +756,7 @@ fn closure_fn_trait_impl_datum( pub(crate) fn associated_ty_value_query( db: &impl HirDatabase, - krate: Crate, + krate: CrateId, id: chalk_rust_ir::AssociatedTyValueId, ) -> Arc> { let data: AssocTyValue = from_chalk(db, id); @@ -771,7 +772,7 @@ pub(crate) fn associated_ty_value_query( fn type_alias_associated_ty_value( db: &impl HirDatabase, - _krate: Crate, + _krate: CrateId, type_alias: TypeAlias, ) -> Arc> { 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( fn closure_fn_trait_output_assoc_ty_value( db: &impl HirDatabase, - krate: Crate, + krate: CrateId, data: super::ClosureFnTraitImplData, ) -> Arc> { let impl_id = Impl::ClosureFnTraitImpl(data.clone()).to_chalk(db); @@ -831,8 +832,12 @@ fn closure_fn_trait_output_assoc_ty_value( Arc::new(value) } -fn get_fn_trait(db: &impl HirDatabase, krate: Crate, fn_trait: super::FnTrait) -> Option { - let target = db.lang_item(krate.crate_id, fn_trait.lang_item_name().into())?; +fn get_fn_trait( + db: &impl HirDatabase, + krate: CrateId, + fn_trait: super::FnTrait, +) -> Option { + let target = db.lang_item(krate, fn_trait.lang_item_name().into())?; match target { LangItemTarget::TraitId(t) => Some(t), _ => None, -- cgit v1.2.3