diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-15 13:54:04 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-15 13:54:04 +0000 |
| commit | e0ef6d5c093ceaa64f4e3d3f7a616e0c19f6bef5 (patch) | |
| tree | 19a00b2f7c8be828452a6857cd28038da64057c2 | |
| parent | fbdc3c78494dfd2127638feb1de2ebd157667d6d (diff) | |
| parent | 4c08fc9be3f7b79e3040a154aa97c29c97ee5a49 (diff) | |
| download | rust-e0ef6d5c093ceaa64f4e3d3f7a616e0c19f6bef5.tar.gz rust-e0ef6d5c093ceaa64f4e3d3f7a616e0c19f6bef5.zip | |
Merge #5394
5394: Add missing cancellation point r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
| -rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index e55cc1e55be..d85a86c0a3e 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -36,6 +36,10 @@ use crate::{ TraitLoc, TypeAliasLoc, UnionLoc, }; +const GLOB_RECURSION_LIMIT: usize = 100; +const EXPANSION_DEPTH_LIMIT: usize = 128; +const FIXED_POINT_LIMIT: usize = 8192; + pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { let crate_graph = db.crate_graph(); @@ -217,7 +221,7 @@ impl DefCollector<'_> { ReachedFixedPoint::Yes => break, ReachedFixedPoint::No => i += 1, } - if i == 10000 { + if i == FIXED_POINT_LIMIT { log::error!("name resolution is stuck"); break; } @@ -573,6 +577,7 @@ impl DefCollector<'_> { vis: Visibility, import_type: ImportType, ) { + self.db.check_canceled(); self.update_recursive(module_id, resolutions, vis, import_type, 0) } @@ -586,7 +591,7 @@ impl DefCollector<'_> { import_type: ImportType, depth: usize, ) { - if depth > 100 { + if depth > GLOB_RECURSION_LIMIT { // prevent stack overflows (but this shouldn't be possible) panic!("infinite recursion in glob imports!"); } @@ -609,14 +614,15 @@ impl DefCollector<'_> { .get(&module_id) .into_iter() .flat_map(|v| v.iter()) + .filter(|(glob_importing_module, _)| { + // we know all resolutions have the same visibility (`vis`), so we + // just need to check that once + vis.is_visible_from_def_map(&self.def_map, *glob_importing_module) + }) .cloned() .collect::<Vec<_>>(); + for (glob_importing_module, glob_import_vis) in glob_imports { - // we know all resolutions have the same visibility (`vis`), so we - // just need to check that once - if !vis.is_visible_from_def_map(&self.def_map, glob_importing_module) { - continue; - } self.update_recursive( glob_importing_module, resolutions, @@ -677,10 +683,6 @@ impl DefCollector<'_> { self.unexpanded_attribute_macros = attribute_macros; for (module_id, macro_call_id, depth) in resolved { - if depth > 1024 { - log::debug!("Max macro expansion depth reached"); - continue; - } self.collect_macro_expansion(module_id, macro_call_id, depth); } @@ -717,7 +719,7 @@ impl DefCollector<'_> { macro_call_id: MacroCallId, depth: usize, ) { - if depth > 100 { + if depth > EXPANSION_DEPTH_LIMIT { mark::hit!(macro_expansion_overflow); log::warn!("macro expansion is too deep"); return; |
