grmbl grmbl symbol tables
2 files changed, 24 insertions(+), 7 deletions(-)

M src/hir2/lower.rs
M src/symtbl.rs
M src/hir2/lower.rs +11 -2
@@ 23,6 23,16 @@ impl Idx {
     }
 }
 
+/// See crate::symtbl::UniqueSym.
+///
+/// Rust is a silly language sometimes.
+impl Default for Idx {
+    fn default() -> Self {
+        unreachable!(
+            "can't happen, but we want to be able to default-construct containers containing this"
+        )
+    }
+}
 fn lower_lit(lit: &ast::Literal) -> Literal {
     lit.clone()
 }

          
@@ 679,6 689,7 @@ impl super::visit::Visit for IndexCounte
 #[derive(Default)]
 struct IndexRenamer {
     next_var_idx: usize,
+    symtbl: crate::symtbl::Symtbl<Idx>,
 }
 
 impl super::visit::Visit for IndexRenamer {

          
@@ 970,8 981,6 @@ end
             let ir = lower(&ast);
             let mut ctr = IndexRenamer::default();
             ctr.visit(&ir);
-            assert_eq!(ctr.vars, varcount);
-            assert_eq!(ctr.type_vars, typevarcount);
         }
     }
 }

          
M src/symtbl.rs +13 -5
@@ 29,10 29,18 @@ use crate::*;
 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
 pub struct UniqueSym(pub Sym);
 
+impl Default for UniqueSym {
+    fn default() -> Self {
+        unreachable!(
+            "can't happen, but we want to be able to default-construct containers containing this"
+        )
+    }
+}
+
 #[derive(Clone, Default, Debug)]
-struct ScopeFrame {
-    symbols: BTreeMap<Sym, UniqueSym>,
-    types: BTreeMap<Sym, UniqueSym>,
+struct ScopeFrame<Val> {
+    symbols: BTreeMap<Sym, Val>,
+    types: BTreeMap<Sym, Val>,
 }
 
 /// A shortcut for a cloneable AnyMap

          
@@ 42,8 50,8 @@ type CloneMap = Map<dyn anymap::any::Clo
 /// and manages scope.
 /// Looks ugly, works well.
 #[derive(Debug, Clone)]
-pub struct Symtbl {
-    frames: Rc<RefCell<Vec<ScopeFrame>>>,
+pub struct Symtbl<Val = UniqueSym> {
+    frames: Rc<RefCell<Vec<ScopeFrame<Val>>>>,
     /// A mapping from unique symbol names to whatever
     /// we need to know about them.  It's an AnyMap, so
     /// we can just stuff whatever data we need into it.