diff --git a/src/ast/compiler/type_checker.rs b/src/ast/compiler/type_checker.rs index 106cfee..63239ff 100644 --- a/src/ast/compiler/type_checker.rs +++ b/src/ast/compiler/type_checker.rs @@ -1,13 +1,14 @@ use crate::ast::compiler::bound_nodes::{Address, BoundKind, Node, TypedNode}; use crate::ast::diagnostics::Diagnostics; use crate::ast::types::StaticType; +use std::collections::HashMap; use std::rc::Rc; /// Manages the types of locals and upvalues during a single type-checking pass. struct TypeContext<'a> { _parent: Option<&'a TypeContext<'a>>, /// Maps slot index -> Inferred Type - slots: Vec, + slots: HashMap, /// Types of captured variables (passed from outer scope) upvalue_types: Vec, /// Access to root types for unified resolution @@ -18,14 +19,14 @@ struct TypeContext<'a> { impl<'a> TypeContext<'a> { fn new( - slot_count: u32, + _slot_count: u32, upvalue_types: Vec, root_types: &'a std::cell::RefCell>, parent: Option<&'a TypeContext<'a>>, ) -> Self { Self { _parent: parent, - slots: vec![StaticType::Any; slot_count as usize], + slots: HashMap::new(), upvalue_types, root_types, current_params_ty: None, @@ -36,7 +37,7 @@ impl<'a> TypeContext<'a> { match addr { Address::Local(slot) => self .slots - .get(slot.0 as usize) + .get(&slot.0) .cloned() .unwrap_or(StaticType::Any), Address::Global(idx) => self @@ -56,9 +57,7 @@ impl<'a> TypeContext<'a> { fn set_type(&mut self, addr: Address, ty: StaticType) { match addr { Address::Local(slot) => { - if let Some(entry) = self.slots.get_mut(slot.0 as usize) { - *entry = ty; - } + self.slots.insert(slot.0, ty); } Address::Global(idx) => { let mut rt = self.root_types.borrow_mut();