[wasm-merge] Handle table initializer referring to imported global - #9167
Merged
Merged
Conversation
Unlike global initializers and element segments (which under GC may refer to preceding module-defined globals), a table initializer expression may only refer to imported globals. Fusing can turn an imported global that a table initializer refers to into a module-defined one, which would make the initializer invalid. When that happens, inline the referenced global's (immutable, constant) value so the initializer remains valid.
kripken
reviewed
Sep 29, 2026
| struct Inliner : public PostWalker<Inliner> { | ||
| bool inlined = false; | ||
| void visitGlobalGet(GlobalGet* curr) { | ||
| auto* global = getModule()->getGlobalOrNull(curr->name); |
Member
There was a problem hiding this comment.
How can the result here be null? I think we can use getGlobal()?
kripken
reviewed
Sep 29, 2026
| // global's initializer refers to another one), so iterate to a fixed point. | ||
| // Globals cannot form cycles, so this terminates. Any global.gets that | ||
| // remain refer to imported globals, which are valid in table initializers. | ||
| while (true) { |
Member
There was a problem hiding this comment.
Please add a second testcase that adds coverage for the looping.
kripken
approved these changes
Oct 1, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Unlike global initializers and element segments (which under GC may refer to preceding module-defined globals), a table initializer expression may only refer to imported globals. Fusing can turn an imported global that a table initializer refers to into a module-defined one, which would make the initializer invalid. When that happens, inline the referenced global's (immutable, constant) value so the initializer remains valid.