Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use super::complex::{
};
use crate::semantic_db::def::lua_type::type_decl::LuaTypeDeclId;

/// Semantic type structure used for equality, hashing and inference.
/// Shared `Rc` payloads keep their semantic fields immutable; interior hash
/// caches only memoize structural hashes and must not change equality or hash values.
#[derive(Debug, Clone)]
pub enum LuaType {
Unknown,
Expand Down
12 changes: 8 additions & 4 deletions crates/emmylua_code_analysis/src/semantic_model/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ pub(super) struct TypeEvaluationScope<'a> {
}

impl<'a> TypeEvaluationScope<'a> {
pub(super) const MAX_TYPE_VISITS: usize = 1_000_000;
pub(super) const MAX_EVALUATION_DEPTH: usize = 64;

/// Enter a nested evaluation sharing the enclosing query's remaining work.
/// Exhausted work or excessive semantic nesting records an incomplete
/// evaluation before returning `None`; a fresh outer query resets the budget.
pub(super) fn new(cache: &'a LazyCache) -> Option<Self> {
let query = QueryCacheScope::new(cache);
let mut state = cache.borrow_mut();
const MAX_EVALUATION_DEPTH: usize = 64;
if state.evaluation_depth >= MAX_EVALUATION_DEPTH || state.evaluation_exhausted {
if state.evaluation_depth >= Self::MAX_EVALUATION_DEPTH || state.evaluation_exhausted {
state.exhaust_evaluation();
return None;
}
Expand All @@ -110,9 +115,8 @@ impl<'a> TypeEvaluationScope<'a> {
};
}
let mut pending = vec![ty];
const MAX_TYPE_VISITS: usize = 1_000_000;
while let Some(ty) = pending.pop() {
if cache.evaluation_exhausted || cache.evaluation_work >= MAX_TYPE_VISITS {
if cache.evaluation_exhausted || cache.evaluation_work >= Self::MAX_TYPE_VISITS {
cache.exhaust_evaluation();
return false;
}
Expand Down
Loading
Loading