Skip to content

[DRAFT] Do not rewrite supertypes in AbstractTypeRefining #7720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tlively
Copy link
Member

@tlively tlively commented Jul 14, 2025

Keeping descriptor chains valid while rewriting subtyping is
complicated. Make it simpler to optimize descriptor and described types
by not rewriting supertypes at all in AbstractTypeRefining.

Landing this is blocked on making Unsubtyping more efficient so we can
use it by default as a follow-up to AbstractTypeRefining to avoid
regressions.

tlively added 4 commits July 11, 2025 21:27
The interpreter was returning the wrong value when evaluating a
branching descriptor operand to a descriptor cast. Adding tests for this
fix also exposed a bug where the validator did not allow for unreachable
descriptor operands without also having unreachable ref operands.
Update the cast optimizations in OptimizeInstructions to correctly
optimize ref.cast_desc. The optimizations differ from the optimizations
of normal casts because they have to be careful not to skip any side
effects in the descriptor operand and because type information alone is
not sufficient to prove that a cast will succeed.
We previously hit an assertion failure when accessing the GCData of the
ref literal because i31 literals do not have GCData.
Keeping descriptor chains valid while rewriting subtyping is
complicated. Make it simpler to optimize descriptor and described types
by not rewriting supertypes at all in AbstractTypeRefining.

Landing this is blocked on making Unsubtyping more efficient so we can
use it by default as a follow-up to AbstractTypeRefining to avoid
regressions.
@tlively tlively requested a review from kripken July 14, 2025 16:54
@tlively tlively marked this pull request as draft July 14, 2025 16:56
// supertype, which is not allowed. We could fix this by walking up the
// supertype chain to find a supertype that is not being rewritten, but
// changing subtype relationships and keep descriptor chains valid is
// nontrivial. Instead, avoid changing subtype relationships entirely.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// nontrivial. Instead, avoid changing subtype relationships entirely.
// nontrivial. Instead, avoid changing subtype relationships entirely:
// leave that for Unsubtyping.

// C. But if we rewrote C's supertype, C would declare itself to be its own
// supertype, which is not allowed. We could fix this by walking up the
// supertype chain to find a supertype that is not being rewritten, but
// changing subtype relationships and keep descriptor chains valid is
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// changing subtype relationships and keep descriptor chains valid is
// changing subtype relationships and keeping descriptor chains valid is

}
return super;
// We do not want to update subtype relationships.
return oldType.getDeclaredSuperType();
Copy link
Member

Choose a reason for hiding this comment

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

This is identical to the function being overridden, so it can be removed. We do not need to declare AbstractTypeRefiningTypeMapper at all, I think.

Base automatically changed from fix-cast-desc-i31 to main July 15, 2025 20:10
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