Skip to content

Conversation

@tlively
Copy link
Member

@tlively tlively commented Mar 8, 2025

After calculating the best possible type for a local, LocalSubtyping
then checks to see whether the local can be non-nullable based on
whether all of its gets are dominated by sets. If it cannot be
non-nullable, the new type is adjusted to be nullable. This adjustment
did not previously preserve exactness, causing an assertion that the
optimization improves the type to fail. Fix the adjustment and add a
test.

tlively added 3 commits March 7, 2025 17:26
Update the finalization of all instructions whose types (or sent types)
depend on their operand reference types to handle exact references
correctly. Specifically, update `ref.as_non_null`, `br_on_null`,
`br_on_non_null`, `br_on_cast`, and `br_on_cast_fail`. Also add TODOs on
all instructions that allocate new heap objects to remind us to make
their types exact in the future.
When optimizing a cast to an exact reference to a bottom type,
OptimizeInstructions previously triggered an assertion that expected the
cast type to be inexact. Fix the assertion and surrounding code to be
more robust to the presence of exact reference types and add a test.
After calculating the best possible type for a local, LocalSubtyping
then checks to see whether the local can be non-nullable based on
whether all of its gets are dominated by sets. If it cannot be
non-nullable, the new type is adjusted to be nullable. This adjustment
did not previously preserve exactness, causing an assertion that the
optimization improves the type to fail. Fix the adjustment and add a
test.
@tlively tlively requested a review from kripken March 8, 2025 03:45
if (cannotBeNonNullable.count(i)) {
newType = Type(newType.getHeapType(), Nullable);
newType =
Type(newType.getHeapType(), Nullable, newType.getExactness());
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it makes sense to add getAsNullable() or getWithNullability(nullability)? That would shorten such code, and be forward looking for when we add yet more things aside from shareability, nullability, exactness, etc....

Copy link
Member

Choose a reason for hiding this comment

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

Actually it could be getAs(nullability) which is nice and short.

@kripken
Copy link
Member

kripken commented Mar 10, 2025

I am ok with leaving such refactoring to later, but the more I think about it, while you are making these changes it would be good to do it, and not be any more work?

@tlively
Copy link
Member Author

tlively commented Mar 10, 2025

Yes, I've had the same thought. I was planning to leave such a refactoring to later, but you're right that it would make sense to update the use sites as I fix bugs incrementally. How about we land the current batch of PRs, and then I'll add the new API and update all these fixed use sites to use it. Subsequent bug fix PRs can then use the new API right away.

@kripken
Copy link
Member

kripken commented Mar 10, 2025

Sounds good.

Base automatically changed from optimize-insts-exact to main March 11, 2025 04:39
@tlively tlively merged commit 7d2f80d into main Mar 11, 2025
14 checks passed
@tlively tlively deleted the local-subtypign-exact branch March 11, 2025 04:40
tlively added a commit that referenced this pull request Mar 26, 2025
We decided that Custom Descriptors should introduce exact heap types
rather than exact reference types. Although these new features are very
similar, the APIs we need to change for them are completely different.

One option would have been to keep the existing exact reference type
implementation while additionally implementing exact heap types, but
there are not enough free bits in the type implementation to have both
at once without increasing the alignment of HeapTypeInfo allocations.
Portably increasing the alignment is annoying enough that it's easier to
just eagerly remove exact reference types to free up the bit for use
with exact heap types.

Fully or partially revert the following PRs:

 - #7371
 - #7365
 - #7360
 - #7357
 - #7356
 - #7355
 - #7354
 - #7353
 - #7347
 - #7342
 - #7328

Keep the new `.with(...)` Type APIs and the relevant parts of the type
relations gtest that were introduced as part of the reverted work.
tlively added a commit that referenced this pull request Mar 26, 2025
We decided that Custom Descriptors should introduce exact heap types
rather than exact reference types. Although these new features are very
similar, the APIs we need to change for them are completely different.

One option would have been to keep the existing exact reference type
implementation while additionally implementing exact heap types, but
there are not enough free bits in the type implementation to have both
at once without increasing the alignment of HeapTypeInfo allocations.
Portably increasing the alignment is annoying enough that it's easier to
just eagerly remove exact reference types to free up the bit for use
with exact heap types.

Fully or partially revert the following PRs:

 - #7371
 - #7365
 - #7360
 - #7357
 - #7356
 - #7355
 - #7354
 - #7353
 - #7347
 - #7342
 - #7328

Keep the new `.with(...)` Type APIs and the relevant parts of the type
relations gtest that were introduced as part of the reverted work.
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.

3 participants