Skip to content

[RemoveUnusedBrs] Skip BrOn when descriptor is unreachable - #9268

Merged
tlively merged 1 commit into
mainfrom
remove-unused-brs-unreachable-desc
Oct 16, 2026
Merged

tlively merged 1 commit into
mainfrom
remove-unused-brs-unreachable-desc

Conversation

@tlively

@tlively tlively commented Oct 16, 2026

Copy link
Copy Markdown
Member

In RemoveUnusedBrs::optimizeGC, Optimizer walks and optimizes BrOn expressions bottom-up without running ReFinalize until the walk completes. When an inner BrOn in the desc operand of a BrOnCastDescEq or BrOnCastDescEqFail is optimized into an unconditional branch, curr->desc->type becomes Type::unreachable while curr->type still holds its old reference type. If the outer BrOn then refines curr->castType and calls curr->finalize(), curr->type becomes Type::unreachable, causing maybeCast(curr, oldType) to fail its reference-type assertion. Check curr->desc && curr->desc->type == Type::unreachable in the early return at the start of Optimizer::visitBrOn alongside curr->ref->type == Type::unreachable.

In `RemoveUnusedBrs::optimizeGC`, `Optimizer` walks and optimizes `BrOn` expressions bottom-up without running `ReFinalize` until the walk completes. When an inner `BrOn` in the `desc` operand of a `BrOnCastDescEq` or `BrOnCastDescEqFail` is optimized into an unconditional branch, `curr->desc->type` becomes `Type::unreachable` while `curr->type` still holds its old reference type. If the outer `BrOn` then refines `curr->castType` and calls `curr->finalize()`, `curr->type` becomes `Type::unreachable`, causing `maybeCast(curr, oldType)` to fail its reference-type assertion. Check `curr->desc && curr->desc->type == Type::unreachable` in the early return at the start of `Optimizer::visitBrOn` alongside `curr->ref->type == Type::unreachable`.
@tlively
tlively requested a review from a team as a code owner October 16, 2026 19:09
@tlively
tlively requested review from kripken and removed request for a team October 16, 2026 19:09
@tlively tlively changed the title [RemoveUnusedBrs]: Skip BrOn when descriptor is unreachable [RemoveUnusedBrs] Skip BrOn when descriptor is unreachable Oct 16, 2026
@tlively
tlively merged commit a631c14 into main Oct 16, 2026
16 checks passed
@tlively
tlively deleted the remove-unused-brs-unreachable-desc branch October 16, 2026 20:03
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