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
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughRemove 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
8be12df to
1ae5bc9
Compare
ShaharNaveh
left a comment
There was a problem hiding this comment.
Awesome!
ty for looking into it:)
|
Thanks! Could you rebase to to main please? |
1ae5bc9 to
50ba52d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/host_env/src/os.rs`:
- Around line 147-176: On Windows there are two problems: the second
`page_size()` should be `alloc_granularity()` and both functions create an
immutable `SYSTEM_INFO` then pass `&mut info` to `GetSystemInfo()`. Fix by
renaming the second function to `alloc_granularity()` and change the local
binding in both `page_size()` and `alloc_granularity()` to `let mut info =
SYSTEM_INFO::default();`, call `unsafe { GetSystemInfo(&mut info); }`, then
return `info.dwPageSize as _` from `page_size()` and
`info.dwAllocationGranularity as _` from `alloc_granularity()`.
🪄 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: d7716633-5c8a-4e64-aa10-af7c2cb6905a
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (7)
Cargo.tomlcrates/derive-impl/Cargo.tomlcrates/derive-impl/src/compile_bytecode.rscrates/derive-impl/src/lib.rscrates/host_env/src/os.rscrates/stdlib/Cargo.tomlcrates/stdlib/src/mmap.rs
💤 Files with no reviewable changes (3)
- crates/derive-impl/Cargo.toml
- crates/derive-impl/src/lib.rs
- crates/stdlib/Cargo.toml
✅ Files skipped from review due to trivial changes (1)
- crates/derive-impl/src/compile_bytecode.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- Cargo.toml
0bbef59 to
38e1ad3
Compare
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 the unmaintained `winapi-rs`. Both crates are maintained by Microsoft - they're official. Getting the page size is a simple call for both Unix and Windows. 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 a constant that is defined by the spec, so I hard coded it without adding additional dependencies. Finally, I dropped `maplit` which is seven years old and only used in one place. Calling `collect()` with a single item iterator is idiomatic as well as better in this case because Rust can optimize it. `maplit` called `HashMap::insert` which over allocates to amortize future allocs.
38e1ad3 to
482bcf3
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