Use rustix/windows-sys for page size; drop maplit & page_size#7876
Use rustix/windows-sys for page size; drop maplit & page_size#7876joshuamegnauth54 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughRemoves the ChangesDependency Simplification and Platform Abstraction
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/stdlib/src/mmap.rs (1)
198-228: 💤 Low valueConsider extracting the common GetSystemInfo pattern.
Both Windows implementations create a
SYSTEM_INFO, callGetSystemInfo, and return a field cast tousize. This pattern could be extracted to reduce duplication.♻️ Optional refactor
+#[cfg(windows)] +fn get_system_info() -> SYSTEM_INFO { + let mut info = SYSTEM_INFO::default(); + unsafe { + GetSystemInfo(&mut info); + } + info +} + #[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 _ + get_system_info().dwPageSize as _ } #[cfg(windows)] #[pyattr(name = "ALLOCATIONGRANULARITY", once)] fn granularity(_vm: &VirtualMachine) -> usize { - let mut info = SYSTEM_INFO::default(); - unsafe { - GetSystemInfo(&mut info); - } - info.dwAllocationGranularity as _ + get_system_info().dwAllocationGranularity as _ }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/stdlib/src/mmap.rs` around lines 198 - 228, Extract the duplicated GetSystemInfo pattern into a small helper (e.g., a fn get_system_info() -> SYSTEM_INFO) and use it from both Windows functions to avoid repeating allocation and unsafe block: replace the body of page_size and the windows granularity with calls to this helper and return the appropriate fields (info.dwPageSize and info.dwAllocationGranularity) cast to usize; keep function names page_size and granularity and ensure the helper encapsulates the unsafe GetSystemInfo call and SYSTEM_INFO::default() initialization.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/stdlib/src/mmap.rs`:
- Around line 192-196: The page_size implementation is wrong because
core::arch::wasm32::memory_size(0) returns the current memory page count, not
the fixed page size; change the wasm32 page_size (annotated with #[pyattr(name =
"PAGESIZE", once)] fn page_size) to return the constant WebAssembly page size
65_536 (64 KiB) instead of calling memory_size, and ensure any related symbol
that exposes ALLOCATIONGRANULARITY on wasm32 uses the same 65_536 constant (you
can introduce a WASM_PAGE_SIZE const and return that from page_size and
allocation_granularity).
---
Nitpick comments:
In `@crates/stdlib/src/mmap.rs`:
- Around line 198-228: Extract the duplicated GetSystemInfo pattern into a small
helper (e.g., a fn get_system_info() -> SYSTEM_INFO) and use it from both
Windows functions to avoid repeating allocation and unsafe block: replace the
body of page_size and the windows granularity with calls to this helper and
return the appropriate fields (info.dwPageSize and info.dwAllocationGranularity)
cast to usize; keep function names page_size and granularity and ensure the
helper encapsulates the unsafe GetSystemInfo call and SYSTEM_INFO::default()
initialization.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 359f66fd-62d0-4fe6-9403-f86513e280b7
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (6)
Cargo.tomlcrates/derive-impl/Cargo.tomlcrates/derive-impl/src/compile_bytecode.rscrates/derive-impl/src/lib.rscrates/stdlib/Cargo.tomlcrates/stdlib/src/mmap.rs
💤 Files with no reviewable changes (2)
- crates/derive-impl/Cargo.toml
- crates/derive-impl/src/lib.rs
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.
8be12df to
1ae5bc9
Compare
The
page_sizecrate is a simple libc wrapper for Unix and useswinapi-rsfor Windows.windows-sysandwindows-rsare the modern alternatives forwinapi-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_sizecrate did not support. Rust has a built-in API for wasm32's page size, so I didn't add any new dependencies.Finally, I dropped
maplitwhich is seven years old and only used in one place. Usingcollect()with a single item iterator is better in this case because Rust can optimize it.maplistcalledHashMap::insertwhich would over allocate to amortize future allocs.Summary by CodeRabbit