Refactor: Move utils to separate module

Moves `PathTracker` and `UsageInfo` to the `utils` module to improve
code organization.
This commit is contained in:
Michael Schimmel
2026-02-25 20:35:12 +01:00
parent cad0c03973
commit 04f2203900
5 changed files with 179 additions and 175 deletions
+3 -30
View File
@@ -5,12 +5,13 @@ use crate::ast::nodes::Node;
use crate::ast::types::{Purity, Value};
use crate::ast::vm::Closure;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use std::rc::Rc;
use super::substitution_map::{SubstitutionMap, UsageInfo};
use super::substitution_map::SubstitutionMap;
use super::folder::Folder;
use super::inliner::Inliner;
use super::utils::{PathTracker, UsageInfo};
pub struct Optimizer {
pub enabled: bool,
@@ -20,34 +21,6 @@ pub struct Optimizer {
pub lambda_registry: Option<Rc<RefCell<HashMap<GlobalIdx, AnalyzedNode>>>>,
}
struct PathTracker {
inlining_depth: usize,
inlining_stack: HashSet<GlobalIdx>,
identity_stack: HashSet<crate::ast::types::Identity>,
}
impl PathTracker {
fn new() -> Self {
Self {
inlining_depth: 0,
inlining_stack: HashSet::new(),
identity_stack: HashSet::new(),
}
}
fn enter_lambda(&mut self, identity: &crate::ast::types::Identity) -> bool {
if self.identity_stack.contains(identity) {
return false;
}
self.identity_stack.insert(identity.clone());
true
}
fn exit_lambda(&mut self, identity: &crate::ast::types::Identity) {
self.identity_stack.remove(identity);
}
}
impl Optimizer {
pub fn new(enabled: bool) -> Self {
Self {