Skip to content

Opt: Recognize non-nullabe RT long as subtype of LongType #5189

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

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

gzm0
Copy link
Contributor

@gzm0 gzm0 commented Jun 1, 2025

Discovered while working on #5077. This allows to remove unnecessary unboxes and unlocks more inlining.

Discovered while working on scala-js#5077. This allows to remove unnecessary
unboxes and unlocks more inlining.
@gzm0
Copy link
Contributor Author

gzm0 commented Jun 1, 2025

Full diff on the test suite: https://gist.github.com/gzm0/b6b7b064f0edadbd1b65af827957d9c9 (fast opt).

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 1, 2025

@sjrd, a somewhat related question: With nullability in the IR typesystem, why are non-nullable boxed types not subtypes / equivalent to primitive types?

@gzm0 gzm0 requested a review from sjrd June 1, 2025 11:51
@gzm0
Copy link
Contributor Author

gzm0 commented Jun 1, 2025

It seems, this appears quite often in the diff:

-    var t$1 = $uJ(new $c_RTLong(lo$3, hi$4));
-    var lo$4 = t$1.RTLong__f_lo;
-    var hi$5 = t$1.RTLong__f_hi;

That not only removes an unnecessary unbox but also an unnecessary allocation.

@sjrd
Copy link
Member

sjrd commented Jun 1, 2025

@sjrd, a somewhat related question: With nullability in the IR typesystem, why are non-nullable boxed types not subtypes / equivalent to primitive types?

They may have a different representation. A non-nullable Character is an instance of $Char. A char is a number. The phenomenon is exacerbated in Wasm.

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Nice!

That diff is both satisfying, and scary that we were previously leaving such allocations on the table.

@sjrd sjrd enabled auto-merge June 1, 2025 12:57
@sjrd sjrd merged commit 289a5e1 into scala-js:main Jun 2, 2025
3 checks passed
@gzm0 gzm0 deleted the long-subtype branch June 2, 2025 19:02
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