Skip to content

[TypeRefining] Fix block-nested pops - #9281

Open
tlively wants to merge 1 commit into
mainfrom
type-refining-nested-pop
Open

tlively wants to merge 1 commit into
mainfrom
type-refining-nested-pop

Conversation

@tlively

@tlively tlively commented Oct 20, 2026

Copy link
Copy Markdown
Member

When ReadUpdater replaces trapping or unreachable reads with a sequence block, or when WriteUpdater replaces writes to bottom-type fields with a sequence block, any pop instruction in the wrapped operand becomes nested inside a block. Track when blocks are added in both updaters and call EHUtils::handleBlockNestedPops at the end of the function walk.

When ReadUpdater replaces trapping or unreachable reads with a sequence block, or when WriteUpdater replaces writes to bottom-type fields with a sequence block, any pop instruction in the wrapped operand becomes nested inside a block. Track when blocks are added in both updaters and call EHUtils::handleBlockNestedPops at the end of the function walk.
@tlively
tlively requested a review from a team as a code owner October 20, 2026 02:26
@tlively
tlively requested review from kripken and removed request for a team October 20, 2026 02:26

@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 updates the TypeRefining pass to handle block-nested pops created when updating writes to and reads from refined fields, using EHUtils::handleBlockNestedPops. Feedback on the changes highlights that the addedBlock flag in ReadUpdater is not reset after visiting a function, which can lead to state carry-over and unnecessary processing when the updater is reused across multiple functions. Resetting addedBlock to false inside visitFunction is recommended.

Comment on lines +462 to +466
void visitFunction(Function* func) {
if (addedBlock) {
EHUtils::handleBlockNestedPops(func, *getModule());
}
}

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

In sequential/single-threaded execution mode, the same ReadUpdater instance is reused across all functions in the module. If addedBlock is set to true in one function, it will carry over to all subsequent functions, causing EHUtils::handleBlockNestedPops to be run unnecessarily on them. Resetting addedBlock to false at the end of visitFunction prevents this state carry-over and avoids unnecessary performance overhead.

      void visitFunction(Function* func) {
        if (addedBlock) {
          EHUtils::handleBlockNestedPops(func, *getModule());
          addedBlock = false;
        }
      }

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.

This is not the case because the pass is function-parallel. Every function gets a fresh instance.

This branch has not been deployed

No deployments
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.

1 participant