aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs26
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 e55cc1e55..d85a86c0a 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::{
36 TraitLoc, TypeAliasLoc, UnionLoc, 36 TraitLoc, TypeAliasLoc, UnionLoc,
37}; 37};
38 38
39const GLOB_RECURSION_LIMIT: usize = 100;
40const EXPANSION_DEPTH_LIMIT: usize = 128;
41const FIXED_POINT_LIMIT: usize = 8192;
42
39pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 43pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
40 let crate_graph = db.crate_graph(); 44 let crate_graph = db.crate_graph();
41 45
@@ -217,7 +221,7 @@ impl DefCollector<'_> {
217 ReachedFixedPoint::Yes => break, 221 ReachedFixedPoint::Yes => break,
218 ReachedFixedPoint::No => i += 1, 222 ReachedFixedPoint::No => i += 1,
219 } 223 }
220 if i == 10000 { 224 if i == FIXED_POINT_LIMIT {
221 log::error!("name resolution is stuck"); 225 log::error!("name resolution is stuck");
222 break; 226 break;
223 } 227 }
@@ -573,6 +577,7 @@ impl DefCollector<'_> {
573 vis: Visibility, 577 vis: Visibility,
574 import_type: ImportType, 578 import_type: ImportType,
575 ) { 579 ) {
580 self.db.check_canceled();
576 self.update_recursive(module_id, resolutions, vis, import_type, 0) 581 self.update_recursive(module_id, resolutions, vis, import_type, 0)
577 } 582 }
578 583
@@ -586,7 +591,7 @@ impl DefCollector<'_> {
586 import_type: ImportType, 591 import_type: ImportType,
587 depth: usize, 592 depth: usize,
588 ) { 593 ) {
589 if depth > 100 { 594 if depth > GLOB_RECURSION_LIMIT {
590 // prevent stack overflows (but this shouldn't be possible) 595 // prevent stack overflows (but this shouldn't be possible)
591 panic!("infinite recursion in glob imports!"); 596 panic!("infinite recursion in glob imports!");
592 } 597 }
@@ -609,14 +614,15 @@ impl DefCollector<'_> {
609 .get(&module_id) 614 .get(&module_id)
610 .into_iter() 615 .into_iter()
611 .flat_map(|v| v.iter()) 616 .flat_map(|v| v.iter())
617 .filter(|(glob_importing_module, _)| {
618 // we know all resolutions have the same visibility (`vis`), so we
619 // just need to check that once
620 vis.is_visible_from_def_map(&self.def_map, *glob_importing_module)
621 })
612 .cloned() 622 .cloned()
613 .collect::<Vec<_>>(); 623 .collect::<Vec<_>>();
624
614 for (glob_importing_module, glob_import_vis) in glob_imports { 625 for (glob_importing_module, glob_import_vis) in glob_imports {
615 // we know all resolutions have the same visibility (`vis`), so we
616 // just need to check that once
617 if !vis.is_visible_from_def_map(&self.def_map, glob_importing_module) {
618 continue;
619 }
620 self.update_recursive( 626 self.update_recursive(
621 glob_importing_module, 627 glob_importing_module,
622 resolutions, 628 resolutions,
@@ -677,10 +683,6 @@ impl DefCollector<'_> {
677 self.unexpanded_attribute_macros = attribute_macros; 683 self.unexpanded_attribute_macros = attribute_macros;
678 684
679 for (module_id, macro_call_id, depth) in resolved { 685 for (module_id, macro_call_id, depth) in resolved {
680 if depth > 1024 {
681 log::debug!("Max macro expansion depth reached");
682 continue;
683 }
684 self.collect_macro_expansion(module_id, macro_call_id, depth); 686 self.collect_macro_expansion(module_id, macro_call_id, depth);
685 } 687 }
686 688
@@ -717,7 +719,7 @@ impl DefCollector<'_> {
717 macro_call_id: MacroCallId, 719 macro_call_id: MacroCallId,
718 depth: usize, 720 depth: usize,
719 ) { 721 ) {
720 if depth > 100 { 722 if depth > EXPANSION_DEPTH_LIMIT {
721 mark::hit!(macro_expansion_overflow); 723 mark::hit!(macro_expansion_overflow);
722 log::warn!("macro expansion is too deep"); 724 log::warn!("macro expansion is too deep");
723 return; 725 return;