Refactor: Use root_purity instead of global_purity
This commit refactors the purity analysis from using a `HashMap<GlobalIdx, Purity>` to a `Vec<Purity>` indexed by `GlobalIdx.0`. This change simplifies the data structure and makes purity lookups more efficient. The `Binder`'s `globals` field has also been removed as it was not being used.
This commit is contained in:
@@ -6,7 +6,7 @@ use std::collections::{HashMap, HashSet};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Analyzer<'a> {
|
||||
global_purity: &'a HashMap<GlobalIdx, Purity>,
|
||||
root_purity: &'a [Purity],
|
||||
/// Stack of currently visiting lambdas to detect direct recursion.
|
||||
lambda_stack: Vec<crate::ast::types::Identity>,
|
||||
/// Map of global index to its Lambda identity if known.
|
||||
@@ -18,10 +18,10 @@ pub struct Analyzer<'a> {
|
||||
impl<'a> Analyzer<'a> {
|
||||
pub fn analyze(
|
||||
node: &TypedNode,
|
||||
global_purity: &'a HashMap<GlobalIdx, Purity>,
|
||||
root_purity: &'a [Purity],
|
||||
) -> AnalyzedNode {
|
||||
let mut analyzer = Self {
|
||||
global_purity,
|
||||
root_purity,
|
||||
lambda_stack: Vec::new(),
|
||||
globals_to_lambdas: HashMap::new(),
|
||||
recursive_identities: HashSet::new(),
|
||||
@@ -70,7 +70,7 @@ impl<'a> Analyzer<'a> {
|
||||
BoundKind::Get { addr, name } => {
|
||||
let p = match addr {
|
||||
Address::Global(idx) => {
|
||||
self.global_purity.get(idx).cloned().unwrap_or(Purity::Pure)
|
||||
self.root_purity.get(idx.0 as usize).cloned().unwrap_or(Purity::Pure)
|
||||
}
|
||||
_ => Purity::Pure,
|
||||
};
|
||||
@@ -206,8 +206,8 @@ impl<'a> Analyzer<'a> {
|
||||
..
|
||||
} = &callee.kind
|
||||
{
|
||||
self.global_purity
|
||||
.get(idx)
|
||||
self.root_purity
|
||||
.get(idx.0 as usize)
|
||||
.cloned()
|
||||
.unwrap_or(Purity::Impure)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user