JIT: Fold impossible type tests between unrelated classes - #130805
JIT: Fold impossible type tests between unrelated classes#130805EgorBo wants to merge 2 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bfa09cf3-e00d-4d69-98d1-a03f33c6283e
|
@MihuBot -nuget |
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
| const unsigned fromClassAttribs = info.compCompHnd->getClassAttribs(fromClass); | ||
| if ((fromClassAttribs & nonClassTypeAttribs) == 0) | ||
| { | ||
| castMustFail = |
There was a problem hiding this comment.
I know this is correct... but castMustFail = ... MustNot is so confusing to read 😂
There was a problem hiding this comment.
Changed this to an explicit reverse-cast result check.
There was a problem hiding this comment.
Pull request overview
This PR enhances JIT import-time folding for isinst / castclass by proving certain type tests are statically impossible even when the source type isn’t exact, enabling the JIT to return null for isinst in more cases (notably when both types are ordinary unrelated classes with non-overlapping hierarchies).
Changes:
- Extend
impOptimizeCastClassOrIsInstto detect when no subtype of the source class could ever be an instance of the target class (forisinst). - Gate the new proof to “ordinary classes” (excluding arrays, delegates, generic type variables, interfaces, and value classes) to avoid unsound overlap cases.
- Preserve existing behavior for
castclass(still not optimizing always-throw cases here).
|
@tannergooding it's actually just an AI fix for the issue to check the diffs 🙂 |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bfa09cf3-e00d-4d69-98d1-a03f33c6283e
Fixes #106966