Skip to content

Fix Flatten on br_table with a more refined value - #9319

Closed
kripken wants to merge 3 commits into
WebAssembly:mainfrom
kripken:flatten.switch
Closed

kripken wants to merge 3 commits into
WebAssembly:mainfrom
kripken:flatten.switch

Conversation

@kripken

@kripken kripken commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

We assumed its value's type was identical to the type of the
thing we branch to, but the target may be less refined. Just
make getTempForBreakTarget always compute the right
thing.

@kripken
kripken requested a review from a team as a code owner October 28, 2026 22:25
@kripken
kripken requested review from stevenfontanella and removed request for a team October 28, 2026 22:25

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request simplifies the getTempForBreakTarget helper in the Flatten pass by removing its redundant Type parameter and instead resolving the target block's type internally via findBreakTarget. It also adds a test case to verify correct handling of subtyping with br_table. The review feedback suggests optimizing the type comparison check in Flatten.cpp by querying the local variable's type directly from the function instead of performing a redundant AST traversal with findBreakTarget.

Comment thread src/passes/Flatten.cpp
// second 'flowing out' local in case two block's types are
// different.
if (type != blockType) {
if (type != findBreakTarget(br->name)->type) {

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

Instead of calling findBreakTarget(br->name)->type again, which performs a redundant AST traversal up the parent stack, you can query the type of the local variable temp directly from the function using getFunction()->getLocalType(temp). Since temp was just retrieved or allocated using getTempForBreakTarget(br->name), its local type is guaranteed to match the target block's type.

Suggested change
if (type != findBreakTarget(br->name)->type) {
if (type != getFunction()->getLocalType(temp)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That is true, but more complicated (harder to refactor, in particular), and would require a comment.

@tlively

tlively commented Oct 28, 2026

Copy link
Copy Markdown
Member

Looks like a dup of #9312

@kripken kripken closed this Oct 28, 2026
@kripken
kripken deleted the flatten.switch branch October 28, 2026 23:38
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.

2 participants