Skip to content

[subtype-exprs] Fix shared constraints on unreachable RefEqs - #9279

Open
tlively wants to merge 1 commit into
mainfrom
subtype-exprs-ref-eq-shared
Open

tlively wants to merge 1 commit into
mainfrom
subtype-exprs-ref-eq-shared

Conversation

@tlively

@tlively tlively commented Oct 19, 2026

Copy link
Copy Markdown
Member

SubtypingDiscoverer::visitRefEq checked curr->type != Type::unreachable and read only curr->left->type to determine whether its operands must be subtypes of shared or unshared eqref. When one operand of a RefEq is unreachable and the other operand is a shared reference, curr->type is Type::unreachable, causing visitRefEq to constrain the shared operand to unshared eqref and trip the Type::isSubType(curr->type, type) assertion in TranslateToFuzzReader::mutate.

Check both operands of RefEq for shared reference types when determining the eqref shareability constraint. Add unit tests as well as new assertions that allow an Unsbutyping regression test to catch the problem.

SubtypingDiscoverer::visitRefEq checked curr->type != Type::unreachable and read only curr->left->type to determine whether its operands must be subtypes of shared or unshared eqref. When one operand of a RefEq is unreachable and the other operand is a shared reference, curr->type is Type::unreachable, causing visitRefEq to constrain the shared operand to unshared eqref and trip the Type::isSubType(curr->type, type) assertion in TranslateToFuzzReader::mutate.

Check both operands of RefEq for shared reference types when determining the eqref shareability constraint. Add unit tests as well as new assertions that allow an Unsbutyping regression test to catch the problem.
@tlively
tlively requested a review from a team as a code owner October 19, 2026 18:53
@tlively
tlively requested review from stevenfontanella and removed request for a team October 19, 2026 18:53

@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 fixes an issue where a ref.eq expression with an unreachable operand and a shared reference operand did not correctly constrain its operands to shared eqref. The fix updates visitRefEq in subtype-exprs.h to check both operands for shareability, adds assertions to Unsubtyping.cpp to verify subtype relationships, and introduces both a gtest and a lit regression test to cover this scenario. As there are no review comments, I have no feedback to provide.

@tlively

tlively commented Oct 19, 2026

Copy link
Copy Markdown
Member Author

Unfortunately there does not seem to be a way to disable the GCA comments in the event of "I have no feedback to provide."

}

void noteNonFlowSubtype(Expression* sub, Type super) {
assert(Type::isSubType(sub->type, super));

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.

Why are these added? They don't look specific to this pass?

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.

I mean, if these make sense, why not put them in the general utility so they apply to all passes?

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.

They're added because there's no way to add an unsubtyping regression test otherwise. Unsubtyping takes the early return just below this.

Adding the assertions to the general utility makes sense, though. I'll do that.

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.

Oh, the assertions cannot be simply moved to the shared utility because the shared utility is doing CRTP calls out to subtypes for these functions. We could have the CRTP utility call a chokepoint function that does the assertion and then calls the subtype, but that would be a much larger change and doesn't seem worth it to me.

@kripken kripken 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 otherwise

@tlively
tlively requested a review from kripken October 20, 2026 02:41

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.

2 participants