Add type aliases for registries

Introduces `GlobalFunctionRegistry` and `GlobalAnalyzedRegistry` type
aliases to clarify the usage of `HashMap`s for storing global functions
and their analyzed versions. This change also refactors the
`LambdaCollector` and `Optimizer` to use these new aliases, improving
code readability and maintainability.
This commit is contained in:
Michael Schimmel
2026-03-03 15:51:47 +01:00
parent a18642fd7b
commit 078b520c37
6 changed files with 94 additions and 82 deletions
+5 -4
View File
@@ -1,15 +1,16 @@
use crate::ast::compiler::bound_nodes::{Address, BoundKind, BoundNode, GlobalIdx};
use std::collections::HashMap;
use std::rc::Rc;
/// A pass that collects all global function definitions (lambdas) into a registry.
/// This allows the Specializer to retrieve the original AST of a function for monomorphization.
pub struct LambdaCollector<'a, T> {
registry: &'a mut HashMap<GlobalIdx, BoundNode<T>>,
registry: &'a mut HashMap<GlobalIdx, Rc<BoundNode<T>>>,
}
impl<'a, T: Clone> LambdaCollector<'a, T> {
/// Performs a full traversal of the AST and populates the provided registry.
pub fn collect(node: &BoundNode<T>, registry: &'a mut HashMap<GlobalIdx, BoundNode<T>>) {
pub fn collect(node: &BoundNode<T>, registry: &'a mut HashMap<GlobalIdx, Rc<BoundNode<T>>>) {
let mut collector = Self { registry };
collector.visit(node);
}
@@ -32,7 +33,7 @@ impl<'a, T: Clone> LambdaCollector<'a, T> {
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, (*current).as_ref().clone());
.insert(*global_index, Rc::new((**current).clone()));
}
}
self.visit(value);
@@ -48,7 +49,7 @@ impl<'a, T: Clone> LambdaCollector<'a, T> {
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, (*current).as_ref().clone());
.insert(*global_index, Rc::new((**current).clone()));
}
}
self.visit(value);