Repository navigation
feat(codegen): wasm32 WASI lowering behind off-by-default target-wasi (WASI phase 3b)
#11406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b2a7075
perry-codegen: wasm32 WASI lowering behind `target-wasi` (phase 3b, #…
claude 00f70ad
changelog: 11406 wasm32 WASI lowering
claude f545f6b
fix(scripts): resolve the perry path in wasi_ir_check.sh before cd
claude bb20258
perry-codegen: split large wasm32 modules into codegen units again
claude 0665858
perry-codegen: keep wasm32 on one codegen unit; reject compile failur…
claude 1df577f
scripts: fail the WASI IR check on a compile timeout or signal
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| Perry can emit wasm32 code for the standalone WASI target (`--target wasi`, | ||
| `wasm32-unknown-wasip2`) when the compiler is built with the new, | ||
| off-by-default `target-wasi` cargo feature (phase 3b of #11375, #11378). | ||
| Without the feature nothing compiles differently. With it, only wasm32 WASI | ||
| takes any new path; host IR from a baseline, the default build and a | ||
| `target-wasi` build is otherwise unchanged (125/130 gap modules byte-identical, | ||
| and the rest differ only in an ordering the baseline itself varies). | ||
|
|
||
| - A wasm32-only pass rewrites each runtime declaration to the runtime's real | ||
| signature. Every call whose own type differs goes through an inlined adapter. | ||
| On LP64, codegen's i64-for-pointer convention matches the runtime; on wasm32 | ||
| it would be a link-time signature mismatch at ~1,200 sites. | ||
| - The signatures come from `crates/perry-codegen/src/wasm32/runtime_abi.tsv`. | ||
| `scripts/runtime_abi_check.py --emit-wasm-abi` generates it from the runtime | ||
| source, and `--check-wasm-abi` checks it is current. | ||
| - The shadow-frame push reads the 32-bit `frame_top` on wasm32. | ||
| - Inline shadow-slot stores, the Map entry fast path and inline arena | ||
| allocation take their runtime calls on wasm32. | ||
|
|
||
| `runtime_abi_check.py --ir` verifies emitted wasm32 IR (27,946 runtime calls | ||
| across 54 gap modules, 0 mismatches). `scripts/wasi_ir_check.sh` runs it on | ||
| sample programs in the non-required `wasi-check` workflow's new | ||
| `wasi-codegen` job. Linking a `.wasm` is phase 4 (#11379). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 41434
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 42700
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 41993
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 45624
<inspected_subject>crates/perry-codegen/src/target_layout.rs:114-128</inspected_subject>
Add WASI to the hosted heap-address classification.
The new
wasm32_loweringpath admitswasm32-unknown-wasip2, butheap_addr_lower_bound_inclusivestill assigns non-hosted targets a0x200_0000_0000floor. The WASI runtime makes the same mistake:is_valid_obj_ptrselects that floor fortarget_os = "wasi". wasm32 pointers are 32-bit, so GC allocations cannot reach it.try_read_gc_headerthen rejects every such allocation throughis_plausible_heap_addr.Treat WASI as a low-address target in both layers. Keep the runtime’s
HEAP_MINat0x1000;is_plausible_heap_addralready applies the0x100000handle-band floor. Add a wasm32 WASI address test.Suggested fix
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct: on wasm32 both floors are 2 TiB, above every address a 32-bit heap can have. This is already fixed in the next PR in the stack, #11413 (commit
48127538), with exactly the two changes you suggest:triple.contains("wasi")inheap_addr_lower_bound_inclusive, withwasm32-unknown-wasip2added to its test, andtarget_os = "wasi"in bothis_valid_obj_ptrcfg lists.It belongs there rather than here because the runtime half is only safe together with #11413's link layout. That link places the stack first with 8 MiB (
link/wasi.rs), which keeps every heap address above the0x100000handle band. Without that layout, lowering the runtime floor could let a low heap address pass as a handle. On this PR nothing is linked or run on wasm32: the codegen guards that read this floor all fall through to the runtime slow path when it rejects an address, so the only effect is that inline fast paths are off in IR that nothing executes yet. #11413 is the next PR to land. Leaving this thread open for the maintainer.Generated by Claude Code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@proggeramlug, thanks for the explanation. The 2 TiB floor remains a valid finding for wasm32, but I agree that lowering the runtime floor belongs with#11413’s link layout. This PR does not link or run wasm32 output, so I will leave this thread open for the maintainer as requested. I have not independently verified commit48127538.Is
#11413sufficient to track the fix, or would you like a separate issue?✏️ Learnings added
You are interacting with an AI system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#11413 is sufficient. It's the next PR in this stack, and it lands the floor change together with the stack-first link it depends on. No separate issue is needed.
Generated by Claude Code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@proggeramlug, understood. PR#11413is sufficient to track the floor change and its required stack-first link layout. No separate issue is needed. I’ll leave this finding open in PR#11406for the maintainer.🧠 Learnings used
You are interacting with an AI system.