Performance improvements and Memory Leak fixes #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses critical performance issues and memory leaks identified during code review.
1. Tokenizer Optimization & Fix
once_cell::sync::Lazyto compile regexes once statically.TokenStream::nextwhere it would endlessly return_EOFDummytokens becausesent_eof_dummyflag was never updated.2. Closure Memory Leak Fix (Flat Closures)
Environment(scope chain), causing all variables in parent scopes (even unused ones) to remain in memory. This is a common source of leaks in naive interpreter implementations.semantic::captured_variables) that identifies exactly which variables a function uses from its parent scope.Function::new_closurenow creates a detachedVariableScopecontaining only these captured variables, linked directly to the global scope. This allows intermediate stack frames to be garbage collected.3. Closure Initialization Order
getandsetinside auseStatefunction) could not capture each other because they were initialized sequentially.Environment::setup_scopeto execute in two phases:This ensures that when a closure is created, all potential capture targets in the same scope are already declared.
4. Safety
unsafeusage innative_wrap.Verification
bench_tokenizertest which now runs in milliseconds (vs timeout previously).complex_closure.PR created automatically by Jules for task 17035486210205838536 started by @aryan-programmer