Skip to content

WIP Relax nullability for indirectly called functions - #9389

Draft
stevenfontanella wants to merge 1 commit into
mainfrom
relax-nullability-ref
Draft

stevenfontanella wants to merge 1 commit into
mainfrom
relax-nullability-ref

Conversation

@stevenfontanella

@stevenfontanella stevenfontanella commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Part of #9352.

Saves an additional ~5kb compressed size (0.4%) after #9380, bringing the total size savings to ~20kb (1.6%).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Google Antigravity Code Review

I have reviewed the changes in this Pull Request and left inline feedback.

private:
std::unordered_set<HeapType> relaxedTypes;

void modifySignature(HeapType oldType, Signature& sig) override {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[CRITICAL | Confidence: 5/5 | BUG]

modifySignature unconditionally relaxes parameters for all private heap types with HeapTypeKind::Func. In WebAssembly GC, event tags (Tag) also use function signatures (HeapTypeKind::Func), and unexported tags are treated as private heap types by ModuleUtils::collectHeapTypeInfo.

Relaxing an unexported tag's signature causes multiple validation failures and broken semantics:

  1. In modern exception handling (try_table), CodeUpdater in mapTypes preserves nullability on sentTypes. Because tag->params() becomes nullable while TryTable::sentTypes remains non-nullable, FunctionValidator::visitTryTable immediately fails validation with "invalid catch sent type information" (shouldBeEqual(tagType[j], sentType[j])).
  2. try_table catch clauses branch directly to target blocks without an intermediate expression where ref.as_non_null could be inserted. If a target block expects a non-nullable reference, sending a nullable catch payload violates block type subtyping.
  3. In legacy exception handling, a pop expression receiving the tag's payload inside an unrelaxed function (such as an exported function) will produce a nullable value, but InsertRefAsNonNull is never run on unrelaxed functions, causing a type mismatch.
  4. Similarly, compiler intrinsics such as call.without.effects are not marked public in collectHeapTypeInfo, and relaxing their signatures desynchronizes them from target calls in validateCallParamsAndResult.

Notice that (export "tag") had to be added to test/lit/passes/relax-nullability.wast to work around this issue by forcing the tag to be public.

Signatures used by tags (module->tags) and intrinsics should be collected and excluded from signature relaxation.

: GlobalTypeRewriter(wasm, worldMode) {}

std::unordered_set<HeapType> update() {
auto typeMap = rebuildTypes(getSortedTypes(getPrivatePredecessors()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM | Confidence: 5/5 | PERFORMANCE]

update() unconditionally calls rebuildTypes(...) and mapTypes(typeMap) even when no private signatures have relaxable parameters (or when relaxedTypes remains empty).

rebuildTypes merges all private types into a single monolithic recursion group (createRecGroup(0, typeBuilder.size())), re-canonicalizes them, and updates wasm.typeNames. Then mapTypes performs a full AST traversal over every expression across all functions in the module (updater.walkModuleCode(&wasm)). On modules with many private types but no non-nullable signature parameters (or in open-world mode), this results in severe, unnecessary compilation overhead and unneeded rec group merging.

Consider scanning the collected private types beforehand, and skipping rebuildTypes and mapTypes entirely if no private signatures contain non-nullable reference parameters.

@stevenfontanella
stevenfontanella force-pushed the relax-nullability-ref branch 4 times, most recently from f36c918 to 79684f2 Compare November 17, 2026 01:50

This branch has not been deployed

No deployments
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.

1 participant