Use ahash in the compiler

This commit is contained in:
Noah 2020-12-19 15:26:41 -06:00
parent 64fa9ccba9
commit a0790d4906
5 changed files with 14 additions and 10 deletions

View file

@ -16,6 +16,7 @@ num-complex = { version = "0.3", features = ["serde"] }
num-traits = "0.2" num-traits = "0.2"
log = "0.4" log = "0.4"
arrayvec = "0.5" arrayvec = "0.5"
ahash = "0.6"
[dev-dependencies] [dev-dependencies]
rustpython-parser = { path = "../parser" } rustpython-parser = { path = "../parser" }

View file

@ -9,7 +9,7 @@ use crate::error::{CompileError, CompileErrorType};
use crate::ir::{self, CodeInfo}; use crate::ir::{self, CodeInfo};
pub use crate::mode::Mode; pub use crate::mode::Mode;
use crate::symboltable::{make_symbol_table, statements_to_symbol_table, SymbolScope, SymbolTable}; use crate::symboltable::{make_symbol_table, statements_to_symbol_table, SymbolScope, SymbolTable};
use indexmap::IndexSet; use crate::IndexSet;
use itertools::Itertools; use itertools::Itertools;
use num_complex::Complex64; use num_complex::Complex64;
use num_traits::ToPrimitive; use num_traits::ToPrimitive;
@ -140,10 +140,10 @@ impl Compiler {
blocks: vec![ir::Block::default()], blocks: vec![ir::Block::default()],
current_block: bytecode::Label(0), current_block: bytecode::Label(0),
constants: Vec::new(), constants: Vec::new(),
name_cache: IndexSet::new(), name_cache: IndexSet::default(),
varname_cache: IndexSet::new(), varname_cache: IndexSet::default(),
cellvar_cache: IndexSet::new(), cellvar_cache: IndexSet::default(),
freevar_cache: IndexSet::new(), freevar_cache: IndexSet::default(),
}; };
Compiler { Compiler {
code_stack: vec![module_code], code_stack: vec![module_code],
@ -217,8 +217,8 @@ impl Compiler {
blocks: vec![ir::Block::default()], blocks: vec![ir::Block::default()],
current_block: bytecode::Label(0), current_block: bytecode::Label(0),
constants: Vec::new(), constants: Vec::new(),
name_cache: IndexSet::new(), name_cache: IndexSet::default(),
varname_cache: IndexSet::new(), varname_cache: IndexSet::default(),
cellvar_cache, cellvar_cache,
freevar_cache, freevar_cache,
}; };

View file

@ -1,4 +1,4 @@
use indexmap::IndexSet; use crate::IndexSet;
use rustpython_bytecode::{CodeFlags, CodeObject, ConstantData, Instruction, Label, Location}; use rustpython_bytecode::{CodeFlags, CodeObject, ConstantData, Instruction, Label, Location};
pub type BlockIdx = Label; pub type BlockIdx = Label;

View file

@ -5,6 +5,9 @@
#[macro_use] #[macro_use]
extern crate log; extern crate log;
type IndexMap<K, V> = indexmap::IndexMap<K, V, ahash::RandomState>;
type IndexSet<T> = indexmap::IndexSet<T, ahash::RandomState>;
pub mod compile; pub mod compile;
pub mod error; pub mod error;
pub mod ir; pub mod ir;

View file

@ -8,7 +8,7 @@ Inspirational file: https://github.com/python/cpython/blob/master/Python/symtabl
*/ */
use crate::error::{CompileError, CompileErrorType}; use crate::error::{CompileError, CompileErrorType};
use indexmap::map::IndexMap; use crate::IndexMap;
use rustpython_ast::{self as ast, Location}; use rustpython_ast::{self as ast, Location};
use std::fmt; use std::fmt;
@ -58,7 +58,7 @@ impl SymbolTable {
typ, typ,
line_number, line_number,
is_nested, is_nested,
symbols: IndexMap::new(), symbols: IndexMap::default(),
sub_tables: vec![], sub_tables: vec![],
} }
} }