Skip to content

[DAE2] Refinalize when changing types - #9290

Merged
tlively merged 3 commits into
mainfrom
dae2-refinalize
Oct 26, 2026
Merged

tlively merged 3 commits into
mainfrom
dae2-refinalize

Conversation

@tlively

@tlively tlively commented Oct 21, 2026

Copy link
Copy Markdown
Member

When DAE2 removes unused values, replacing an expression (such as a drop of a concrete block containing an unreachable child) with its kept children can change the expression's type from none to unreachable. Track when a replacement in Optimizer becomes unreachable and run ReFinalize in parallel on affected functions at the end of DAE2::optimize() after global type rewriting.

When `DAE2` removes unused values, replacing an expression (such as a `drop` of a concrete block containing an `unreachable` child) with its kept children can change the expression's type from `none` to `unreachable`. Track when a replacement in `Optimizer` becomes `unreachable` and run `ReFinalize` in parallel on affected functions at the end of `DAE2::optimize()` after global type rewriting.
@tlively
tlively requested a review from a team as a code owner October 21, 2026 01:35
@tlively
tlively requested review from aheejin and removed request for a team October 21, 2026 01:35

@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 introduces a refinalization step in the Dead Argument Elimination (DAE2) pass to handle cases where removing unused expression results introduces new unreachability, requiring enclosing expressions to be refinalized. It adds a refinalize flag to FunctionInfo and runs a custom Refinalizer pass after global type rewriting to ensure correct type propagation for instructions like call_ref and ref.func. Test cases have been added to verify this behavior. There are no review comments, so I have no additional feedback to provide.

@aheejin aheejin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM % comments

Comment thread src/passes/DeadArgumentElimination2.cpp Outdated
Comment on lines 36 to 37

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We seem to do results analysis now?

@tlively tlively Oct 26, 2026 •

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.

Yes, since #8903. I'll update the comment.

Comment on lines +421 to +422
;; Refinalizing must happen after global type rewriting so that the ref.func
;; gets the final rewritten subtype rather than a temporary scratch type.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to elaborate what "scratch type" here is and why it is necessary. (Grepping the codebase with "scratch type" doesn't yield anything.
(Gemini told me it was this

// Replace the function's type with a new type using only the kept
// parameters and result. This ensures that newly added locals get the
// right indices. Preserve sharedness in case this becomes the permanent
// new type (when GC is disabled, see below).
Signature sig(Type(keptParams),
funcInfo->resultUsage ? func->getResults() : Type::none);

But it would have been nice if could be read without Gemini's help when you don't have a detailed knowledge about the pass)

Also it would be nice if the comment describes what goes wrong if refinalizing doesn't happen at the end in this test.

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.

Updated the comment with a pointer to the code that creates this temporary type. (Explaining all the rationale for that would be too much for the test, I think). Also added an explanation of what would go wrong if we didn't refinalize at the right time.

@tlively
tlively enabled auto-merge (squash) October 26, 2026 21:48
@tlively
tlively merged commit 37186b1 into main Oct 26, 2026
16 of 17 checks passed
@tlively
tlively deleted the dae2-refinalize branch October 26, 2026 22:15
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