Repository navigation
WIP Relax nullability for indirectly called functions - #9389
stevenfontanella wants to merge 1 commit into
Conversation
| private: | ||
| std::unordered_set<HeapType> relaxedTypes; | ||
|
|
||
| void modifySignature(HeapType oldType, Signature& sig) override { |
There was a problem hiding this comment.
[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:
- In modern exception handling (
try_table),CodeUpdaterinmapTypespreserves nullability onsentTypes. Becausetag->params()becomes nullable whileTryTable::sentTypesremains non-nullable,FunctionValidator::visitTryTableimmediately fails validation with"invalid catch sent type information"(shouldBeEqual(tagType[j], sentType[j])). try_tablecatch clauses branch directly to target blocks without an intermediate expression whereref.as_non_nullcould be inserted. If a target block expects a non-nullable reference, sending a nullable catch payload violates block type subtyping.- In legacy exception handling, a
popexpression receiving the tag's payload inside an unrelaxed function (such as an exported function) will produce a nullable value, butInsertRefAsNonNullis never run on unrelaxed functions, causing a type mismatch. - Similarly, compiler intrinsics such as
call.without.effectsare not marked public incollectHeapTypeInfo, and relaxing their signatures desynchronizes them from target calls invalidateCallParamsAndResult.
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())); |
There was a problem hiding this comment.
[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.
092ee1a to
90356d5
Compare
f36c918 to
79684f2
Compare
79684f2 to
094e040
Compare
Part of #9352.
Saves an additional ~5kb compressed size (0.4%) after #9380, bringing the total size savings to ~20kb (1.6%).