From 4c08fc9be3f7b79e3040a154aa97c29c97ee5a49 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 15 Jul 2020 15:52:32 +0200 Subject: Cleanup limits --- crates/ra_hir_def/src/nameres/collector.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 6494b653a..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::{ 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; } @@ -587,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!"); } @@ -679,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); } @@ -719,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; -- cgit v1.2.3