diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-04 20:23:54 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-04 20:41:12 +0200 |
commit | 363af42e5fc6d84f2048dc61b863ee1292abf91e (patch) | |
tree | 503b6160c2e87b405479bbfc8bde1504f3059d9b | |
parent | 318a842241fccef0184c69e31a7d08306799c6c6 (diff) | |
download | rebel-363af42e5fc6d84f2048dc61b863ee1292abf91e.tar rebel-363af42e5fc6d84f2048dc61b863ee1292abf91e.zip |
rebel-parse, rebel-lang: switch to rustc-hash
-rw-r--r-- | Cargo.lock | 8 | ||||
-rw-r--r-- | crates/rebel-lang/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/rebel-lang/src/scope.rs | 23 | ||||
-rw-r--r-- | crates/rebel-lang/src/typing.rs | 15 | ||||
-rw-r--r-- | crates/rebel-lang/src/value.rs | 8 | ||||
-rw-r--r-- | crates/rebel-parse/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/rebel-parse/src/ast/expr.rs | 5 |
7 files changed, 32 insertions, 29 deletions
@@ -812,6 +812,7 @@ dependencies = [ "rebel-common", "rebel-parse", "reedline", + "rustc-hash", ] [[package]] @@ -823,6 +824,7 @@ dependencies = [ "peg", "phf", "rebel-common", + "rustc-hash", ] [[package]] @@ -900,6 +902,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30b661b2f27137bdbc16f00eda72866a92bb28af1753ffbd56744fb6e2e9cd8e" [[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] name = "rustix" version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/crates/rebel-lang/Cargo.toml b/crates/rebel-lang/Cargo.toml index b1cb07b..a0a04a6 100644 --- a/crates/rebel-lang/Cargo.toml +++ b/crates/rebel-lang/Cargo.toml @@ -12,6 +12,7 @@ rebel-common = { path = "../rebel-common" } rebel-parse = { path = "../rebel-parse" } enum-kinds = "0.5.1" +rustc-hash = "1.1.0" [dev-dependencies] clap = { version = "4.0.0", features = ["derive"] } diff --git a/crates/rebel-lang/src/scope.rs b/crates/rebel-lang/src/scope.rs index 81bc6e1..c0c2ebd 100644 --- a/crates/rebel-lang/src/scope.rs +++ b/crates/rebel-lang/src/scope.rs @@ -1,10 +1,7 @@ -use std::{ - collections::{HashMap, HashSet}, - mem, - rc::Rc, -}; +use std::{mem, rc::Rc}; use rebel_parse::ast::{self, pat}; +use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ func::Func, @@ -12,15 +9,15 @@ use crate::{ Error, Result, }; -pub type MethodMap = HashMap<TypeFamily, HashMap<&'static str, Func>>; +pub type MethodMap = FxHashMap<TypeFamily, FxHashMap<&'static str, Func>>; #[derive(Debug, Clone)] pub struct Scope<T> { pub defs: Module<T>, - pub initialized: Rc<HashSet<String>>, + pub initialized: Rc<FxHashSet<String>>, pub methods: Rc<MethodMap>, pub parent: Option<Box<Scope<T>>>, - pub upvalue_initialized: HashSet<String>, + pub upvalue_initialized: FxHashSet<String>, } impl<T> Default for Scope<T> { @@ -30,7 +27,7 @@ impl<T> Default for Scope<T> { initialized: Rc::default(), methods: Rc::default(), parent: None, - upvalue_initialized: HashSet::new(), + upvalue_initialized: FxHashSet::default(), }; // Type "prelude" @@ -67,7 +64,7 @@ impl<T> Scope<T> { } } - pub fn scoped<F, R>(self: &mut Box<Self>, f: F) -> (R, HashSet<String>) + pub fn scoped<F, R>(self: &mut Box<Self>, f: F) -> (R, FxHashSet<String>) where F: FnOnce(&mut Box<Self>) -> R, { @@ -76,7 +73,7 @@ impl<T> Scope<T> { initialized: self.initialized.clone(), methods: self.methods.clone(), parent: None, - upvalue_initialized: HashSet::new(), + upvalue_initialized: FxHashSet::default(), }); let scope = mem::replace(self, child); self.parent = Some(scope); @@ -177,9 +174,9 @@ pub fn is_wildcard_destr_pat(pat: &pat::DestrPat) -> bool { #[derive(Debug)] pub struct Module<T> { - pub values: HashMap<String, Rc<T>>, + pub values: FxHashMap<String, Rc<T>>, pub typ: Option<Rc<Type>>, - pub children: Rc<HashMap<String, Module<T>>>, + pub children: Rc<FxHashMap<String, Module<T>>>, } impl<T> Module<T> { diff --git a/crates/rebel-lang/src/typing.rs b/crates/rebel-lang/src/typing.rs index 6c5ba81..ea2096a 100644 --- a/crates/rebel-lang/src/typing.rs +++ b/crates/rebel-lang/src/typing.rs @@ -1,12 +1,9 @@ -use std::{ - collections::{HashMap, HashSet}, - fmt::Display, - rc::Rc, -}; +use std::{fmt::Display, rc::Rc}; use enum_kinds::EnumKind; use rebel_parse::ast::{self, expr, pat, typ}; +use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ func::FuncType, @@ -49,7 +46,7 @@ pub enum Type { Str, Tuple(Vec<Type>), Array(Box<Type>), - Struct(HashMap<String, Type>), + Struct(FxHashMap<String, Type>), Fn(Box<FuncType>), } @@ -366,7 +363,7 @@ impl<'scope> Context<'scope> { }) } - fn type_scope(&mut self, stmts: &[ast::BlockStmt]) -> Result<(Type, HashSet<String>)> { + fn type_scope(&mut self, stmts: &[ast::BlockStmt]) -> Result<(Type, FxHashSet<String>)> { let (ret, upvalues) = self.scoped(|ctx| { let mut ret = Type::Unit; for stmt in stmts { @@ -391,7 +388,7 @@ impl<'scope> Context<'scope> { let (mut ret, mut common_upvalues) = if let Some(block) = else_block { self.type_scope(&block.0)? } else { - (Type::Unit, HashSet::new()) + (Type::Unit, FxHashSet::default()) }; for (cond, block) in if_blocks { @@ -540,7 +537,7 @@ impl<'scope> Context<'scope> { Ok(inferred_type) } - fn scoped<F, R>(&mut self, f: F) -> (R, HashSet<String>) + fn scoped<F, R>(&mut self, f: F) -> (R, FxHashSet<String>) where F: FnOnce(&mut Context) -> R, { diff --git a/crates/rebel-lang/src/value.rs b/crates/rebel-lang/src/value.rs index 97a6f8b..da1ce4b 100644 --- a/crates/rebel-lang/src/value.rs +++ b/crates/rebel-lang/src/value.rs @@ -1,11 +1,11 @@ use std::{ cell::RefCell, - collections::{HashMap, HashSet}, fmt::{Display, Write}, iter, }; use rebel_parse::ast::{self, expr, pat}; +use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ func::{Func, FuncDef}, @@ -26,7 +26,7 @@ pub enum Value { Str(String), Tuple(Vec<Value>), Array(Vec<Value>), - Struct(HashMap<String, Value>), + Struct(FxHashMap<String, Value>), Fn(Box<Func>), } @@ -310,7 +310,7 @@ impl<'scope> Context<'scope> { }) } - fn eval_scope(&mut self, stmts: &[ast::BlockStmt]) -> Result<(Value, HashSet<String>)> { + fn eval_scope(&mut self, stmts: &[ast::BlockStmt]) -> Result<(Value, FxHashSet<String>)> { let (ret, upvalues) = self.scoped(|ctx| { let mut ret = Value::Unit; for stmt in stmts { @@ -434,7 +434,7 @@ impl<'scope> Context<'scope> { Ok(value) } - fn scoped<F, R>(&mut self, f: F) -> (R, HashSet<String>) + fn scoped<F, R>(&mut self, f: F) -> (R, FxHashSet<String>) where F: FnOnce(&mut Context) -> R, { diff --git a/crates/rebel-parse/Cargo.toml b/crates/rebel-parse/Cargo.toml index 7159976..95d2acd 100644 --- a/crates/rebel-parse/Cargo.toml +++ b/crates/rebel-parse/Cargo.toml @@ -11,6 +11,7 @@ edition = "2021" peg = "0.8.3" phf = { version = "0.11.2", features = ["macros"] } rebel-common = { path = "../rebel-common" } +rustc-hash = "1.1.0" [dev-dependencies] clap = { version = "4.0.0", features = ["derive"] } diff --git a/crates/rebel-parse/src/ast/expr.rs b/crates/rebel-parse/src/ast/expr.rs index 3994296..341b8ad 100644 --- a/crates/rebel-parse/src/ast/expr.rs +++ b/crates/rebel-parse/src/ast/expr.rs @@ -1,7 +1,6 @@ -use std::collections::HashSet; - use super::{Block, DestrPat, Ident, Path, ValidationError}; use crate::token; +use rustc_hash::FxHashSet; pub use token::StrKind; @@ -226,7 +225,7 @@ impl<'a> Literal<'a> { Ok(()) } Literal::Struct(entries) => { - let mut fields = HashSet::new(); + let mut fields = FxHashSet::default(); for StructField { name, value } in entries { if !fields.insert(name) { return Err(ValidationError::DuplicateKey); |