From 1ae5bc9081394dca759d26dbac17ee7e23b8290a Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Fri, 15 May 2026 21:05:45 -0400 Subject: [PATCH] rustix/windows-sys for page size; drop maplit The `page_size` crate is a simple libc wrapper for Unix and uses `winapi-rs` for Windows. `windows-sys` and `windows-rs` are the modern alternatives for `winapi-rs`. Both crates are maintained by Microsoft - they're official. Getting the page size for Unix is a simple call. Rustix can do it safely for us. Windows is effectively the same. Besides Unix and Windows, I also added the page size for wasm32 which the `page_size` crate did not support. `wasm32`'s page size is defined by the spec, so I hard coded it without adding new dependencies. Finally, I dropped `maplit` which is seven years old and only used in one place. Using `collect()` with a single item iterator is better in this case because Rust can optimize it. `maplist` called `HashMap::insert` which would over allocate to amortize future allocs. --- Cargo.lock | 8 ---- Cargo.toml | 4 +- crates/derive-impl/Cargo.toml | 1 - crates/derive-impl/src/compile_bytecode.rs | 8 ++-- crates/derive-impl/src/lib.rs | 3 -- crates/stdlib/Cargo.toml | 2 +- crates/stdlib/src/mmap.rs | 45 +++++++++++++++++++--- 7 files changed, 47 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e9b54bb8aa..eae11dbfaec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2114,12 +2114,6 @@ dependencies = [ "quote", ] -[[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" - [[package]] name = "md-5" version = "0.10.6" @@ -3304,7 +3298,6 @@ name = "rustpython-derive-impl" version = "0.5.0" dependencies = [ "itertools 0.14.0", - "maplit", "proc-macro2", "quote", "rustpython-compiler-core", @@ -3505,7 +3498,6 @@ dependencies = [ "openssl", "openssl-probe", "openssl-sys", - "page_size", "parking_lot", "paste", "pbkdf2", diff --git a/Cargo.toml b/Cargo.toml index 80976b1e1c7..02d2647f90e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -235,7 +235,6 @@ mac_address = "1.1.3" malachite-bigint = "0.9.1" malachite-q = "0.9.1" malachite-base = "0.9.1" -maplit = "1.0.2" md-5 = "0.10.1" memchr = "2.8.0" memmap2 = "0.9.10" @@ -250,7 +249,6 @@ openssl = "0.10.79" openssl-sys = "0.9.110" openssl-probe = "0.2.1" optional = "0.5" -page_size = "0.6" parking_lot = "0.12.3" paste = "1.0.15" pbkdf2 = "0.12" @@ -265,7 +263,7 @@ radium = "1.1.1" rand = "0.9" rand_core = { version = "0.9", features = ["os_rng"] } result-like = "0.5.0" -rustix = { version = "1.1", features = ["event", "system"] } +rustix = { version = "1.1", features = ["event", "param", "system"] } rustls = { version = "0.23.39", default-features = false } rustls-native-certs = "0.8" rustls-pemfile = "2.2" diff --git a/crates/derive-impl/Cargo.toml b/crates/derive-impl/Cargo.toml index 383bf229171..7197c51ecfa 100644 --- a/crates/derive-impl/Cargo.toml +++ b/crates/derive-impl/Cargo.toml @@ -16,7 +16,6 @@ rustpython-doc = { workspace = true } itertools = { workspace = true } syn = { workspace = true, features = ["full", "extra-traits"] } -maplit = { workspace = true } proc-macro2 = { workspace = true } quote = { workspace = true } syn-ext = { workspace = true, features = ["full"] } diff --git a/crates/derive-impl/src/compile_bytecode.rs b/crates/derive-impl/src/compile_bytecode.rs index a640d59c577..05197440e69 100644 --- a/crates/derive-impl/src/compile_bytecode.rs +++ b/crates/derive-impl/src/compile_bytecode.rs @@ -83,12 +83,14 @@ impl CompilationSource { CompilationSourceKind::Dir { base, rel_path } => { self.compile_dir(base, &base.join(rel_path), "", mode, compiler) } - _ => Ok(hashmap! { - module_name.to_string() => CompiledModule { + _ => Ok(core::iter::once(( + module_name.to_string(), + CompiledModule { code: self.compile_single(mode, module_name, compiler)?, package: false, }, - }), + )) + .collect()), } } diff --git a/crates/derive-impl/src/lib.rs b/crates/derive-impl/src/lib.rs index 91f606bba1f..3d4b7991511 100644 --- a/crates/derive-impl/src/lib.rs +++ b/crates/derive-impl/src/lib.rs @@ -4,9 +4,6 @@ extern crate proc_macro; -#[macro_use] -extern crate maplit; - #[macro_use] mod error; #[macro_use] diff --git a/crates/stdlib/Cargo.toml b/crates/stdlib/Cargo.toml index 25a4b8c12f2..429db299bca 100644 --- a/crates/stdlib/Cargo.toml +++ b/crates/stdlib/Cargo.toml @@ -110,7 +110,6 @@ rustix = { workspace = true } # mmap + socket dependencies [target.'cfg(not(target_arch = "wasm32"))'.dependencies] memmap2 = { workspace = true } -page_size = { workspace = true } gethostname = { workspace = true } socket2 = { workspace = true, features = ["all"] } dns-lookup = { workspace = true } @@ -159,6 +158,7 @@ features = [ "Win32_System_Console", "Win32_System_IO", "Win32_System_Memory", + "Win32_System_SystemInformation", "Win32_System_Threading" ] diff --git a/crates/stdlib/src/mmap.rs b/crates/stdlib/src/mmap.rs index 9cb84b4efa6..f1b99bef4ea 100644 --- a/crates/stdlib/src/mmap.rs +++ b/crates/stdlib/src/mmap.rs @@ -46,7 +46,10 @@ mod mmap { CreateFileMappingW, FILE_MAP_COPY, FILE_MAP_READ, FILE_MAP_WRITE, FlushViewOfFile, MapViewOfFile, PAGE_READONLY, PAGE_READWRITE, PAGE_WRITECOPY, UnmapViewOfFile, }, - System::Threading::GetCurrentProcess, + System::{ + SystemInformation::{GetSystemInfo, SYSTEM_INFO}, + Threading::GetCurrentProcess, + }, }; #[cfg(unix)] @@ -180,16 +183,48 @@ mod mmap { #[pyattr] const ACCESS_COPY: u32 = AccessMode::Copy as u32; - #[cfg(not(target_arch = "wasm32"))] + #[cfg(unix)] #[pyattr(name = "PAGESIZE", once)] fn page_size(_vm: &VirtualMachine) -> usize { - page_size::get() + rustix::param::page_size() + } + + #[cfg(target_arch = "wasm32")] + #[pyattr(name = "PAGESIZE", once)] + const fn page_size(_vm: &VirtualMachine) -> usize { + 65536 + } + + #[cfg(windows)] + #[pyattr(name = "PAGESIZE", once)] + fn page_size(_vm: &VirtualMachine) -> usize { + let mut info = SYSTEM_INFO::default(); + unsafe { + GetSystemInfo(&mut info); + } + info.dwPageSize as _ } - #[cfg(not(target_arch = "wasm32"))] + #[cfg(unix)] + #[pyattr(name = "ALLOCATIONGRANULARITY", once)] + fn granularity(_vm: &VirtualMachine) -> usize { + rustix::param::page_size() + } + + #[cfg(target_arch = "wasm32")] + #[pyattr(name = "ALLOCATIONGRANULARITY", once)] + const fn granularity(_vm: &VirtualMachine) -> usize { + 65536 + } + + #[cfg(windows)] #[pyattr(name = "ALLOCATIONGRANULARITY", once)] fn granularity(_vm: &VirtualMachine) -> usize { - page_size::get_granularity() + let mut info = SYSTEM_INFO::default(); + unsafe { + GetSystemInfo(&mut info); + } + info.dwAllocationGranularity as _ } #[pyattr(name = "error", once)]