Make inherent_impls_in_block and trait_impls_in_block infallible

This commit is contained in:
Laurențiu Nicola 2023-04-14 15:56:05 +03:00
parent 96407424de
commit febd5065ad
3 changed files with 22 additions and 27 deletions

View file

@ -139,7 +139,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
} }
}); });
}) })
.filter_map(|block_id| self.db.trait_impls_in_block(block_id)); .map(|block_id| self.db.trait_impls_in_block(block_id));
let id_to_chalk = |id: hir_def::ImplId| id.to_chalk(self.db); let id_to_chalk = |id: hir_def::ImplId| id.to_chalk(self.db);
let mut result = vec![]; let mut result = vec![];
@ -152,7 +152,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
impl_maps.into_iter().chain(block_impls).for_each(&mut f); impl_maps.into_iter().chain(block_impls).for_each(&mut f);
def_blocks def_blocks
.into_iter() .into_iter()
.filter_map(|it| self.db.trait_impls_in_block(it?)) .flatten()
.map(|it| self.db.trait_impls_in_block(it))
.for_each(f); .for_each(f);
} }
fps => { fps => {
@ -165,7 +166,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
impl_maps.into_iter().chain(block_impls).for_each(&mut f); impl_maps.into_iter().chain(block_impls).for_each(&mut f);
def_blocks def_blocks
.into_iter() .into_iter()
.filter_map(|it| self.db.trait_impls_in_block(it?)) .flatten()
.map(|it| self.db.trait_impls_in_block(it))
.for_each(f); .for_each(f);
} }
} }

View file

@ -115,7 +115,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
fn inherent_impls_in_crate(&self, krate: CrateId) -> Arc<InherentImpls>; fn inherent_impls_in_crate(&self, krate: CrateId) -> Arc<InherentImpls>;
#[salsa::invoke(InherentImpls::inherent_impls_in_block_query)] #[salsa::invoke(InherentImpls::inherent_impls_in_block_query)]
fn inherent_impls_in_block(&self, block: BlockId) -> Option<Arc<InherentImpls>>; fn inherent_impls_in_block(&self, block: BlockId) -> Arc<InherentImpls>;
/// Collects all crates in the dependency graph that have impls for the /// Collects all crates in the dependency graph that have impls for the
/// given fingerprint. This is only used for primitive types and types /// given fingerprint. This is only used for primitive types and types
@ -132,7 +132,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
fn trait_impls_in_crate(&self, krate: CrateId) -> Arc<TraitImpls>; fn trait_impls_in_crate(&self, krate: CrateId) -> Arc<TraitImpls>;
#[salsa::invoke(TraitImpls::trait_impls_in_block_query)] #[salsa::invoke(TraitImpls::trait_impls_in_block_query)]
fn trait_impls_in_block(&self, block: BlockId) -> Option<Arc<TraitImpls>>; fn trait_impls_in_block(&self, block: BlockId) -> Arc<TraitImpls>;
#[salsa::invoke(TraitImpls::trait_impls_in_deps_query)] #[salsa::invoke(TraitImpls::trait_impls_in_deps_query)]
fn trait_impls_in_deps(&self, krate: CrateId) -> Arc<TraitImpls>; fn trait_impls_in_deps(&self, krate: CrateId) -> Arc<TraitImpls>;

View file

@ -149,10 +149,7 @@ impl TraitImpls {
Arc::new(impls) Arc::new(impls)
} }
pub(crate) fn trait_impls_in_block_query( pub(crate) fn trait_impls_in_block_query(db: &dyn HirDatabase, block: BlockId) -> Arc<Self> {
db: &dyn HirDatabase,
block: BlockId,
) -> Option<Arc<Self>> {
let _p = profile::span("trait_impls_in_block_query"); let _p = profile::span("trait_impls_in_block_query");
let mut impls = Self { map: FxHashMap::default() }; let mut impls = Self { map: FxHashMap::default() };
@ -160,7 +157,7 @@ impl TraitImpls {
impls.collect_def_map(db, &block_def_map); impls.collect_def_map(db, &block_def_map);
impls.shrink_to_fit(); impls.shrink_to_fit();
Some(Arc::new(impls)) Arc::new(impls)
} }
pub(crate) fn trait_impls_in_deps_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<Self> { pub(crate) fn trait_impls_in_deps_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<Self> {
@ -283,10 +280,7 @@ impl InherentImpls {
Arc::new(impls) Arc::new(impls)
} }
pub(crate) fn inherent_impls_in_block_query( pub(crate) fn inherent_impls_in_block_query(db: &dyn HirDatabase, block: BlockId) -> Arc<Self> {
db: &dyn HirDatabase,
block: BlockId,
) -> Option<Arc<Self>> {
let _p = profile::span("inherent_impls_in_block_query"); let _p = profile::span("inherent_impls_in_block_query");
let mut impls = Self { map: FxHashMap::default(), invalid_impls: Vec::default() }; let mut impls = Self { map: FxHashMap::default(), invalid_impls: Vec::default() };
@ -294,7 +288,7 @@ impl InherentImpls {
impls.collect_def_map(db, &block_def_map); impls.collect_def_map(db, &block_def_map);
impls.shrink_to_fit(); impls.shrink_to_fit();
Some(Arc::new(impls)) Arc::new(impls)
} }
fn shrink_to_fit(&mut self) { fn shrink_to_fit(&mut self) {
@ -1178,18 +1172,17 @@ fn iterate_inherent_methods(
}; };
while let Some(block_id) = block { while let Some(block_id) = block {
if let Some(impls) = db.inherent_impls_in_block(block_id) { let impls = db.inherent_impls_in_block(block_id);
impls_for_self_ty( impls_for_self_ty(
&impls, &impls,
self_ty, self_ty,
table, table,
name, name,
receiver_ty, receiver_ty,
receiver_adjustments.clone(), receiver_adjustments.clone(),
module, module,
callback, callback,
)?; )?;
}
block = db.block_def_map(block_id).parent().and_then(|module| module.containing_block()); block = db.block_def_map(block_id).parent().and_then(|module| module.containing_block());
} }