Skip to content

[PrincipalType] Finish and fix join and compose edge cases - #9301

Merged
tlively merged 1 commit into
mainfrom
principal-types-fixes
Oct 29, 2026
Merged

tlively merged 1 commit into
mainfrom
principal-types-fixes

Conversation

@tlively

@tlively tlively commented Oct 23, 2026

Copy link
Copy Markdown
Member

Default-initialize PrincipalType::unreachable so the Signature constructor does not leave it uninitialized, and grow AssignmentClasses sets up to max(i, *other) before looking up classes.getRoot(*other).

Implement the remaining join cases for VarNullability, VarExactness, VarSharedness, VarHeapType (including mixed abstract/defined heap types and defined heap types with basic LUBs), and VarRef/Type, as well as erasing leading unreachable elements at the bottom of results in PrincipalType::compose.

Default-initialize PrincipalType::unreachable so the Signature constructor does not leave it uninitialized, and grow AssignmentClasses sets up to max(i, *other) before looking up classes.getRoot(*other).

Implement the remaining join cases for VarNullability, VarExactness, VarSharedness, VarHeapType (including mixed abstract/defined heap types and defined heap types with basic LUBs), and VarRef/Type, as well as erasing leading unreachable elements at the bottom of results in PrincipalType::compose.
@tlively
tlively requested a review from a team as a code owner October 23, 2026 21:31
@tlively
tlively requested review from aheejin and kripken and removed request for a team October 23, 2026 21:31

@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 implements support for joining abstract and defined heap types, refactors nullability, exactness, and sharedness join operations, and improves the handling of unreachable types during principal type composition. It also adds comprehensive unit tests to verify these changes. As there are no review comments, I have no feedback to provide.

@tlively

tlively commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Here is the plan:

  1. Finish implementing composition of principal types (this PR)
  2. Fix bugs in child-typer.h and use it as part of PrincipalType::fromExpression
    1. At this point, progress on Outlining will be unblocked
  3. Add a ConcreteChildTyper utility that computes the upper bounds on the types of children from an upper bound on the type of the parent.
    1. For efficiency, this will not actually use PrincipalType because the forward principal types property lets us do this kind of analysis without having to worry about any kind of polymorphism.
    2. There will be a test-only pass that checks that ConcreteChildTyper and an analysis using PrincipalType give the same results. We will run this in the fuzzer.
  4. Use ConcreteChildTyper in TypeGeneralizing, StripRefiningCasts, etc.

@tlively

tlively commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

@stevenfontanella, maybe you want to review this :)

Comment thread src/ir/principal-type.cpp
value = other;
return true;
}
if (std::get_if<Index>(&value) || std::get_if<Index>(&other)) {

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.

nit: use std::holds_alternative since we're not using the pointer

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 guess a lot of other code here uses get_if this way. Fine to keep as-is

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.

Yeah, there was a weird historical thing where we could use std::get_if but not most other variant functions because ancient mac system libraries were missing implementations for them. So we have way more uses of std::get_if than you would otherwise expect. This is possibly something we could clean up at some point.

@tlively
tlively merged commit f321a13 into main Oct 29, 2026
16 of 17 checks passed
@tlively
tlively deleted the principal-types-fixes branch October 29, 2026 21:24
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