11use std:: fmt:: { self , Display } ;
22
3+ use ahash:: RandomState ;
34use bumpalo:: { Bump , collections:: Vec } ;
4- use hashbrown:: { DefaultHashBuilder , HashMap } ;
5- use indexmap :: { IndexMap , IndexSet } ;
5+ use hashbrown:: HashMap ;
6+ use indexmap_allocator_api :: { IndexMap , IndexSet } ;
67use parser:: Identifier ;
78
89use crate :: ir:: {
@@ -28,7 +29,7 @@ pub struct Interpreter<'a> {
2829 program_counter : usize ,
2930 registers : Registers < ' a > ,
3031 symbols : SymbolTable < ' a > ,
31- consts : Consts ,
32+ consts : Consts < ' a > ,
3233 compat : ExecMode ,
3334}
3435
@@ -37,14 +38,14 @@ pub struct Registers<'a>(Vec<'a, Value>);
3738
3839#[ derive( Debug ) ]
3940pub struct SymbolTable < ' a > {
40- user : IndexMap < Identifier < ' a > , Value > ,
41+ user : IndexMap < Identifier < ' a > , Value , RandomState , & ' a Bump > ,
4142 // separate table for cheap invalidation. It's an arena _visibly shrugs_.
42- records : HashMap < usize , Value , DefaultHashBuilder , & ' a Bump > ,
43+ records : HashMap < usize , Value , RandomState , & ' a Bump > ,
4344 // etc
4445}
4546
4647#[ derive( Debug ) ]
47- pub struct Consts ( pub IndexSet < Value > ) ;
48+ pub struct Consts < ' a > ( pub IndexSet < Value , RandomState , & ' a Bump > ) ;
4849
4950impl < ' a > Interpreter < ' a > {
5051 pub fn new ( compat : ExecMode , code : Code < ' a > ) -> Self {
@@ -63,8 +64,8 @@ impl<'a> Interpreter<'a> {
6364impl < ' a > SymbolTable < ' a > {
6465 pub fn new_in ( arena : & ' a Bump ) -> Self {
6566 Self {
66- user : IndexMap :: new ( ) ,
67- records : HashMap :: new_in ( arena) ,
67+ user : IndexMap :: new_in ( arena ) ,
68+ records : HashMap :: with_hasher_in ( RandomState :: new ( ) , arena) ,
6869 }
6970 }
7071 fn lookup_user_var ( & self , var : NonLocal ) -> & Value {
@@ -88,9 +89,9 @@ impl<'a> SymbolTable<'a> {
8889 }
8990}
9091
91- impl Consts {
92- pub fn new ( ) -> Self {
93- Self ( IndexSet :: with_capacity ( 4 ) )
92+ impl < ' a > Consts < ' a > {
93+ pub fn new_in ( arena : & ' a Bump ) -> Self {
94+ Self ( IndexSet :: with_capacity_in ( 4 , arena ) )
9495 }
9596}
9697
@@ -195,7 +196,7 @@ impl Display for SymbolTable<'_> {
195196 }
196197}
197198
198- impl Display for Consts {
199+ impl Display for Consts < ' _ > {
199200 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
200201 write ! ( f, "Consts:" ) ?;
201202 fmt_list ( f, self . 0 . iter ( ) , |f, i, e| write ! ( f, "mem[{i}] = {e:?}" ) )
0 commit comments