Update various types to use their own definitions

This commit refactors several modules to use the defined types from
`ast::types` and `ast::nodes` directly, rather than using fully
qualified paths. This improves code readability and reduces redundancy.

Specifically, the following changes were made:

- In `analyzer.rs`, `crate::ast::types::Identity` and
  `crate::ast::types::Purity` are now used directly.
- In `binder.rs`, `crate::ast::types::NodeIdentity`,
  `crate::ast::types::SourceLocation`,
  `crate::ast::types::RecordLayout`, and `crate::ast::types::Value` are
  now used directly.
- In `macros.rs`, types like `Address`, `VirtualId`, `NodeIdentity`,
  `SourceLocation`, `StaticType`, and `Purity` are now used directly.
- In `optimizer/engine.rs`, `Address<VirtualId>` is now used directly.
- In `type_checker.rs`, `BoundPhase`, `Signature`, `Keyword`, and
  `RecordLayout` are now used directly.
- In `environment.rs`, `CompilerScope`, `LocalInfo`, `CapturePass`,
  `AnalyzedPhase`, `NativeFunction`, and `Closure` are now used
  directly.
- In `nodes.rs`, `RecordLayout`, `Keyword`, `Purity`, and `StaticType`
  are now used directly.
- In `parser.rs`, `SourceLocation` and `NodeIdentity` are now used
  directly.
- In `rtl/math.rs`, `NativeFunction`, `Purity`, `Signature`,
  `StaticType`, `Value`, `RefCell`, and `Rc` are now used directly.
- In `rtl/streams.rs`, `ScalarValue`, `SeriesMember`, `Object`,
  `PipeFn`, `Value`, `VM`, `RingBuffer`, `RecordSeries`, `SeriesView`,
  `build_map_stream`, and `build_pipeline_node` are now used directly.
- In `rtl/type_registry.rs`, `RecordLayout`, `Keyword`, `Purity`,
  `Signature`, `StaticType`, and `Value` are now used directly.
- In `vm.rs`, `RecordSeries`, `SeriesView`, `build_map_stream`,
  `build_pipeline_node`, `StreamNode`, `Object`, and `PipeFn` are now
  used directly.
- In `utils/tester.rs`, `TypedNode` is now used directly.
This commit is contained in:
2026-03-22 18:30:56 +01:00
parent 1cbc656554
commit 007446a167
13 changed files with 112 additions and 104 deletions
+4 -4
View File
@@ -2,18 +2,18 @@ use crate::ast::nodes::{
Address, AnalyzedNode, GlobalIdx, IdentifierBinding, Node,
NodeKind, NodeMetrics, TypedNode, TypedPhase,
};
use crate::ast::types::Purity;
use crate::ast::types::{Identity, Purity};
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
pub struct Analyzer<'a> {
root_purity: &'a [Purity],
/// Stack of currently visiting lambdas to detect direct recursion.
lambda_stack: Vec<crate::ast::types::Identity>,
lambda_stack: Vec<Identity>,
/// Map of global index to its Lambda identity if known.
globals_to_lambdas: HashMap<GlobalIdx, crate::ast::types::Identity>,
globals_to_lambdas: HashMap<GlobalIdx, Identity>,
/// Set of identities that were found to be recursive.
recursive_identities: HashSet<crate::ast::types::Identity>,
recursive_identities: HashSet<Identity>,
}
impl<'a> Analyzer<'a> {
+5 -5
View File
@@ -4,7 +4,7 @@ use crate::ast::nodes::{
UpvalueIdx, VirtualId,
};
use crate::ast::diagnostics::Diagnostics;
use crate::ast::types::{Identity, Purity, StaticType};
use crate::ast::types::{Identity, NodeIdentity, Purity, RecordLayout, SourceLocation, StaticType, Value};
use std::collections::HashMap;
use std::rc::Rc;
@@ -139,7 +139,7 @@ impl Binder {
fixed_scope_idx,
};
binder.functions.push(FunctionCompiler::new(
crate::ast::types::NodeIdentity::new(crate::ast::types::SourceLocation {
NodeIdentity::new(SourceLocation {
line: 0,
col: 0,
}),
@@ -488,10 +488,10 @@ impl Binder {
let key_node = self.bind(k, ExprContext::Expression, diag);
let val_node = self.bind(v, ExprContext::Expression, diag);
if let NodeKind::Constant(crate::ast::types::Value::Keyword(kw)) =
if let NodeKind::Constant(Value::Keyword(kw)) =
&key_node.kind
{
layout_fields.push((*kw, crate::ast::types::StaticType::Any));
layout_fields.push((*kw, StaticType::Any));
} else {
diag.push_error(
format!(
@@ -504,7 +504,7 @@ impl Binder {
bound_fields.push((Rc::new(key_node), Rc::new(val_node)));
}
let layout = crate::ast::types::RecordLayout::get_or_create(layout_fields);
let layout = RecordLayout::get_or_create(layout_fields);
self.make_node(
node.identity.clone(),
+13 -11
View File
@@ -642,10 +642,12 @@ impl<E: MacroEvaluator> MacroExpander<E> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::nodes::Address;
use crate::ast::compiler::binder::{CompilerScope, LocalInfo};
use crate::ast::compiler::Binder;
use crate::ast::diagnostics::Diagnostics;
use crate::ast::nodes::{Address, VirtualId};
use crate::ast::parser::Parser;
use crate::ast::types::{Object, Value};
use crate::ast::types::{NodeIdentity, Object, Purity, SourceLocation, StaticType, Value};
struct SimpleEvaluator;
impl MacroEvaluator for SimpleEvaluator {
@@ -787,19 +789,19 @@ mod tests {
let mut locals = HashMap::new();
locals.insert(
Symbol::from("*"),
crate::ast::compiler::binder::LocalInfo {
addr: Address::Local(crate::ast::nodes::VirtualId(0)),
identity: crate::ast::types::NodeIdentity::new(crate::ast::types::SourceLocation {
LocalInfo {
addr: Address::Local(VirtualId(0)),
identity: NodeIdentity::new(SourceLocation {
line: 0,
col: 0,
}),
_ty: crate::ast::types::StaticType::Any,
purity: crate::ast::types::Purity::Pure,
_ty: StaticType::Any,
purity: Purity::Pure,
},
);
let initial_scopes = vec![crate::ast::compiler::binder::CompilerScope { locals }];
let initial_scopes = vec![CompilerScope { locals }];
let mut diag = crate::ast::diagnostics::Diagnostics::new();
let mut diag = Diagnostics::new();
// fixed_scope_idx = 0 means scope 0 is frozen (Global)
let result = Binder::bind_root(initial_scopes, 1, 0, &expanded, &mut diag);
assert!(
@@ -824,7 +826,7 @@ mod tests {
let mut expander = MacroExpander::new(MacroRegistry::new(), SimpleEvaluator);
let expanded = expander.expand(syntax).unwrap();
let mut diag = crate::ast::diagnostics::Diagnostics::new();
let mut diag = Diagnostics::new();
let result = Binder::bind_root(vec![], 0, 0, &expanded, &mut diag);
assert!(result.is_ok(), "Hygiene failed: {:?}", result.err());
}
@@ -844,7 +846,7 @@ mod tests {
let mut expander = MacroExpander::new(MacroRegistry::new(), SimpleEvaluator);
let expanded = expander.expand(syntax).unwrap();
let mut diag = crate::ast::diagnostics::Diagnostics::new();
let mut diag = Diagnostics::new();
let result = Binder::bind_root(vec![], 0, 0, &expanded, &mut diag);
assert!(
result.is_ok(),
+2 -2
View File
@@ -1,6 +1,6 @@
use crate::ast::nodes::{
Address, AnalyzedNode, AssignBinding, GlobalAnalyzedRegistry,
IdentifierBinding, LambdaBinding, Node, NodeKind, UpvalueIdx,
IdentifierBinding, LambdaBinding, Node, NodeKind, UpvalueIdx, VirtualId,
};
use crate::ast::types::{Purity, Value};
use crate::ast::vm::Closure;
@@ -756,7 +756,7 @@ impl Optimizer {
}
/// Extracts the address from a Def pattern node (when it's a simple Identifier with Declaration binding).
fn extract_def_addr(pattern: &AnalyzedNode) -> Option<Address<crate::ast::nodes::VirtualId>> {
fn extract_def_addr(pattern: &AnalyzedNode) -> Option<Address<VirtualId>> {
if let NodeKind::Identifier {
binding: IdentifierBinding::Declaration { addr, .. },
..
+10 -9
View File
@@ -1,9 +1,9 @@
use crate::ast::nodes::{
Address, AssignBinding, BoundLike, DefBinding, IdentifierBinding, LambdaBinding, Node,
NodeKind, TypedNode, TypedPhase, VirtualId,
Address, AssignBinding, BoundLike, BoundPhase, DefBinding, IdentifierBinding, LambdaBinding,
Node, NodeKind, TypedNode, TypedPhase, VirtualId,
};
use crate::ast::diagnostics::Diagnostics;
use crate::ast::types::StaticType;
use crate::ast::types::{Keyword, RecordLayout, Signature, StaticType};
use std::collections::HashMap;
use std::rc::Rc;
@@ -84,7 +84,7 @@ impl TypeChecker {
pub fn check(
&self,
node: &Node<crate::ast::nodes::BoundPhase>,
node: &Node<BoundPhase>,
arg_types: &[StaticType],
diag: &mut Diagnostics,
) -> TypedNode {
@@ -134,7 +134,7 @@ impl TypeChecker {
let ret_ty = body_typed.ty.clone();
let final_params_ty = params_typed.ty.clone();
let fn_ty = StaticType::Function(Box::new(crate::ast::types::Signature {
let fn_ty = StaticType::Function(Box::new(Signature {
params: final_params_ty,
ret: ret_ty,
}));
@@ -319,7 +319,7 @@ impl TypeChecker {
StaticType::Record(layout) => layout
.fields
.get(i)
.map(|(_, ty): &(crate::ast::types::Keyword, StaticType)| ty.clone())
.map(|(_, ty): &(Keyword, StaticType)| ty.clone())
.unwrap_or(StaticType::Any),
StaticType::Error => StaticType::Error,
_ => StaticType::Any,
@@ -627,7 +627,7 @@ impl TypeChecker {
let body_typed = self.check_node(body, &mut lambda_ctx, diag);
let ret_ty = body_typed.ty.clone();
let fn_ty = StaticType::Function(Box::new(crate::ast::types::Signature {
let fn_ty = StaticType::Function(Box::new(Signature {
params: params_typed.ty.clone(),
ret: ret_ty,
}));
@@ -780,7 +780,7 @@ impl TypeChecker {
typed_fields.push((Rc::new(kt), Rc::new(vt)));
}
let new_layout = crate::ast::types::RecordLayout::get_or_create(fields_ty);
let new_layout = RecordLayout::get_or_create(fields_ty);
(
NodeKind::Record {
fields: typed_fields,
@@ -841,10 +841,11 @@ impl TypeChecker {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::environment::Environment;
use crate::ast::types::StaticType;
fn check_source(source: &str) -> TypedNode {
let env = crate::ast::environment::Environment::new();
let env = Environment::new();
env.compile(source).into_result().unwrap()
}