Add a pass to relax nullabilities of definitions

Offen
#9,352 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@stevenfontanella arbeitet bereits daran.

Seit 05.11.2026.

  • #9353 von @stevenfontanella — offen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

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 private struct/array fields
  • Relax private functions even if they may be called indirectly
  • Handle multi-value returns
  • Double-check if relaxing return values is worth it
Vorherrschende Sprache
WebAssembly
Sterne
8.7k
Forks
905
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
86

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus WebAssembly/binaryen

Alle Issues in WebAssembly/binaryen

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.