Refactor: Move utils to separate module
Moves `PathTracker` and `UsageInfo` to the `utils` module to improve code organization.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user