From e94b812b3bc59f430bec0de5626776f7ce3f70eb Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 16 Nov 2024 14:22:34 +0100 Subject: [PATCH] removing the regalloc dependency --- Cargo.lock | 40 +-------------------------- lang/Cargo.toml | 9 ++----- lang/src/fs.rs | 8 +++--- lang/src/lib.rs | 51 +++++++++++++++++------------------ lang/src/son/hbvm/regalloc.rs | 4 +-- 5 files changed, 35 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1ffd7c..59b7f1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,12 +38,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - [[package]] name = "anyhow" version = "1.0.89" @@ -235,7 +229,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash 1.1.0", + "rustc-hash", "shlex", "syn", "which", @@ -265,15 +259,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -dependencies = [ - "allocator-api2", -] - [[package]] name = "bytes" version = "1.8.0" @@ -594,9 +579,6 @@ name = "hashbrown" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" -dependencies = [ - "allocator-api2", -] [[package]] name = "hashlink" @@ -619,7 +601,6 @@ dependencies = [ "hbbytecode", "hbvm", "log", - "regalloc2", ] [[package]] @@ -1058,19 +1039,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "regalloc2" -version = "0.10.2" -source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#21c43e3ee182824e92e2b25f1d3c03ed47f9c02b" -dependencies = [ - "allocator-api2", - "bumpalo", - "hashbrown 0.14.5", - "log", - "rustc-hash 2.0.0", - "smallvec", -] - [[package]] name = "regex" version = "1.11.1" @@ -1141,12 +1109,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc-hash" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" - [[package]] name = "rustix" version = "0.38.37" diff --git a/lang/Cargo.toml b/lang/Cargo.toml index 6c7e5e0..9e1741b 100644 --- a/lang/Cargo.toml +++ b/lang/Cargo.toml @@ -12,17 +12,12 @@ name = "fuzz" path = "src/fuzz_main.rs" [dependencies] -hashbrown = { version = "0.15.0", default-features = false, features = ["raw-entry", "allocator-api2"] } hbbytecode = { workspace = true, features = ["disasm"] } hbvm = { workspace = true, features = ["nightly"] } +hashbrown = { version = "0.15.0", default-features = false, features = ["raw-entry"] } log = "0.4.22" -[dependencies.regalloc2] -git = "https://github.com/jakubDoka/regalloc2" -branch = "reuse-allocations" -default-features = false - [features] -default = ["std", "regalloc2/trace-log"] +default = ["std"] std = [] no_log = ["log/max_level_off"] diff --git a/lang/src/fs.rs b/lang/src/fs.rs index 82941a6..85a5cf4 100644 --- a/lang/src/fs.rs +++ b/lang/src/fs.rs @@ -2,7 +2,7 @@ use { crate::{ parser::{Ast, Ctx, FileKind}, son::{self, hbvm::HbvmBackend}, - ty, + ty, FnvBuildHasher, }, alloc::{string::String, vec::Vec}, core::{fmt::Write, num::NonZeroUsize, ops::Deref}, @@ -18,6 +18,8 @@ use { }, }; +type HashMap = hashbrown::HashMap; + pub struct Logger; impl log::Log for Logger { @@ -249,8 +251,8 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result { type Task = (usize, PathBuf); - let seen_modules = Mutex::new(crate::HashMap::::default()); - let seen_embeds = Mutex::new(crate::HashMap::::default()); + let seen_modules = Mutex::new(HashMap::::default()); + let seen_embeds = Mutex::new(HashMap::::default()); let tasks = TaskQueue::::new(extra_threads + 1); let ast = Mutex::new(Vec::>::new()); let embeds = Mutex::new(Vec::>::new()); diff --git a/lang/src/lib.rs b/lang/src/lib.rs index b2ce0e1..e5052d6 100644 --- a/lang/src/lib.rs +++ b/lang/src/lib.rs @@ -1440,32 +1440,6 @@ impl OffsetIter { } } -type HashMap = hashbrown::HashMap; -type FnvBuildHasher = core::hash::BuildHasherDefault; - -struct FnvHasher(u64); - -impl core::hash::Hasher for FnvHasher { - fn finish(&self) -> u64 { - self.0 - } - - fn write(&mut self, bytes: &[u8]) { - self.0 = bytes.iter().fold(self.0, |hash, &byte| { - let mut hash = hash; - hash ^= byte as u64; - hash = hash.wrapping_mul(0x100000001B3); - hash - }); - } -} - -impl Default for FnvHasher { - fn default() -> Self { - Self(0xCBF29CE484222325) - } -} - #[cfg(test)] pub fn run_test( name: &'static str, @@ -1682,3 +1656,28 @@ pub fn quad_sort(mut slice: &mut [T], mut cmp: impl FnMut(&T, &T) -> core::cm } debug_assert!(slice.is_sorted_by(|a, b| cmp(a, b) != core::cmp::Ordering::Greater)); } + +type FnvBuildHasher = core::hash::BuildHasherDefault; + +struct FnvHasher(u64); + +impl core::hash::Hasher for FnvHasher { + fn finish(&self) -> u64 { + self.0 + } + + fn write(&mut self, bytes: &[u8]) { + self.0 = bytes.iter().fold(self.0, |hash, &byte| { + let mut hash = hash; + hash ^= byte as u64; + hash = hash.wrapping_mul(0x100000001B3); + hash + }); + } +} + +impl Default for FnvHasher { + fn default() -> Self { + Self(0xCBF29CE484222325) + } +} diff --git a/lang/src/son/hbvm/regalloc.rs b/lang/src/son/hbvm/regalloc.rs index 832a6ab..8eadb73 100644 --- a/lang/src/son/hbvm/regalloc.rs +++ b/lang/src/son/hbvm/regalloc.rs @@ -9,7 +9,7 @@ use { PLoc, Sig, Types, }, alloc::{borrow::ToOwned, vec::Vec}, - core::{borrow::Borrow, mem, ops::Range}, + core::{mem, ops::Range}, hbbytecode::{self as instrs}, }; @@ -108,7 +108,7 @@ impl HbvmBackend { ); #[cfg(debug_assertions)] debug_assert!( - res.marked.borrow().contains(&(allc, nid)) + res.marked.contains(&(allc, nid)) || nid == allc || nodes.is_hard_zero(allc) || allc == MEM