Add a pass to relax nullabilities of definitions
Maintainers usually reply within 1 day
@stevenfontanella is already working on this.
Since Nov 5, 2026.
Assessment
This issue has not been assessed yet.
Description
As a form of generalization, we can make all definitions nullable (e.g. globals, locals, function params, struct fields, arrays, tags), and insert ref.as_non_null as needed for cases that can't be relaxed (e.g. imported/exported functions, public structs). This transformation is valid since it only introduces ref.as_non_nulls that are no-ops.
The benefits of this are:
- When --traps-never-happen is enabled, it allows us to remove the majority of ref.as_non_null instructions with --strip-refining-casts
- It exposes more opportunities for locals to share a declaration group
- It also exposes more opportunities for type merging by causing more function and struct types to be identical
TypeGeneralizing (which is WIP) may also relax nullability, however it would never 'overgeneralize' and allow something to be nullable that would require inserting ref.as_non_null. So this pass may still be useful even alongside TypeGeneralizing.
In a prototype of this pass, I found that this pass reduces the size of a Google Wasm binary by ~3 percent (both in gzipped and uncompressed size).
Implementation plan:
- RelaxNullability for locals and params (#9349)
- Relax function bodies when params can't otherwise be relaxed (e.g. exported functions or referenced functions that may escape) (#9380)
- Relax private functions even if they may be called indirectly (#9389)
- Relax private struct/array fields
- Handle multi-value returns
- Double-check if relaxing return values is worth it
- Consider relaxing
binaryen.js.calledfunctions when --traps-never-happen
- Dominant language
- WebAssembly
- Stars
- 8.7k
- Forks
- 913
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 92
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from WebAssembly/binaryen
-
DAE2 crashes on call.without.effects with a non ref.func expressionPossibly taken @stevenfontanella claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
WebAssembly/binaryen#9404 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
WebAssembly/binaryen#9135 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 76/100
WebAssembly/binaryen#9018 · 3 comments ·
Maintainers usually reply within 1 day
-
Remove `call.without.effects` intrinsicPossibly taken @stevenfontanella claimed this 2 days ago. Open
WebAssembly/binaryen#9399 · 1 assignee ·
Maintainers usually reply within 1 day
-
Inlining: --inline-max-combined-binary-size is not enforced when several functions are inlined into one caller in the same iterationPossibly taken @kripken claimed this 6 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 58/100
WebAssembly/binaryen#9384 · 1 assignee ·
Maintainers usually reply within 1 day