Skip to content

Add Utility Trait to Convert from u32 to usize#310

Merged
florianhartung merged 3 commits intomainfrom
dev/u32-to-usize-helper
Feb 18, 2026
Merged

Add Utility Trait to Convert from u32 to usize#310
florianhartung merged 3 commits intomainfrom
dev/u32-to-usize-helper

Conversation

@florianhartung
Copy link
Copy Markdown
Collaborator

Because Wasm uses u32s for indexing and Rust uses usizes, we have to convert a lot of u32s to usizes.

In Rust it is generally not recommended to use the as keyword to cast between numerical types, because they might result in unexpected errors, imprecision or other unexpected sign extension behaviors. Normally, the From/Into traits should be used instead. However Rust does not provide a From<u32> for usize implementation.

Therefore, this PR adds a new utility trait to convert from a u32 to a usize.

While we might want to support targets with a 16 bit pointer width in the future, this is a small and easy solution for now.

Checks

  • Using Nix
    • Ran nix fmt
    • Ran nix flake check '.?submodules=1'
  • Using Rust tooling
    • Ran cargo fmt
    • Ran cargo test
    • Ran cargo check
    • Ran cargo build
    • Ran cargo doc

@florianhartung florianhartung force-pushed the dev/u32-to-usize-helper branch 2 times, most recently from c60d87a to 918e333 Compare January 19, 2026 16:15
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 78.48837% with 37 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/validation/code.rs 26.82% 0 Missing and 30 partials ⚠️
src/execution/store/mod.rs 71.42% 2 Missing ⚠️
src/validation/read_constant_expression.rs 0.00% 0 Missing and 2 partials ⚠️
src/core/reader/types/mod.rs 50.00% 0 Missing and 1 partial ⚠️
src/validation/data.rs 0.00% 0 Missing and 1 partial ⚠️
src/validation/mod.rs 66.66% 0 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
src/core/reader/section_header.rs 96.29% <100.00%> (ø)
src/core/reader/types/element.rs 87.61% <100.00%> (ø)
src/core/reader/types/export.rs 40.00% <100.00%> (ø)
src/core/reader/types/import.rs 90.32% <100.00%> (ø)
src/core/reader/types/values.rs 73.83% <100.00%> (ø)
src/core/rw_spinlock.rs 90.76% <100.00%> (ø)
src/core/utils.rs 100.00% <100.00%> (ø)
src/execution/const_interpreter_loop.rs 76.25% <100.00%> (ø)
src/execution/interpreter_loop.rs 76.32% <100.00%> (+0.04%) ⬆️
src/execution/store/instances.rs 84.90% <100.00%> (ø)
... and 8 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@florianhartung florianhartung force-pushed the dev/u32-to-usize-helper branch from 918e333 to 67c6589 Compare February 13, 2026 13:17
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 13, 2026

PR Preview Action v1.4.7
Preview removed because the pull request was closed.
2026-02-18 14:51 UTC

@florianhartung florianhartung force-pushed the dev/u32-to-usize-helper branch from 67c6589 to c660e7a Compare February 13, 2026 14:00
@florianhartung florianhartung marked this pull request as ready for review February 13, 2026 14:01
@florianhartung florianhartung force-pushed the dev/u32-to-usize-helper branch 4 times, most recently from 90511cb to 3fb67f2 Compare February 13, 2026 14:23
Signed-off-by: Florian Hartung <florian.hartung@dlr.de>
Signed-off-by: Florian Hartung <florian.hartung@dlr.de>
Signed-off-by: Florian Hartung <florian.hartung@dlr.de>
@florianhartung florianhartung added this pull request to the merge queue Feb 18, 2026
Merged via the queue into main with commit ab81ea1 Feb 18, 2026
14 checks passed
@florianhartung florianhartung deleted the dev/u32-to-usize-helper branch February 18, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants