Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Small codegen improvements. #137

Merged
merged 3 commits into from
May 21, 2024

Conversation

sjrd
Copy link
Collaborator

@sjrd sjrd commented May 21, 2024

No description provided.

sjrd added 3 commits May 21, 2024 09:16
We do not need to look at the class' `kind`. The `jsNativeLoadSpec`
is enough.
Previously, we tried to avoid useless casts based on IR subtyping
rules. Now, we do it based on Wasm type equality. Moreover, if we
do need to cast, we only use a direct RefCast, rather than
`unboxOrNull` helpers for hijacked classes.

The new scheme has several advantages:

* It avoids more useless casts. For example, it avoids downcasts to
  interface types when the source type is not an ancestor of a
  hijacked class, since they all translate to `(ref null jl.Object)`.
* The code is much simpler.
* It avoids an expensive IR subtyping test, which would also not
  survive well if we get to make the backend incremental.

As is, some casts can be introduced when they were not necessary
before. However, such cases are rare, and will be truly gone when
we can enable the optimizer.
Previously, we first created the struct with zero's, then assigned
fields from the source one by one.

We now load all the fields from the source onto the stack, then
directly use `struct.new` to allocate the target.

It might not necessarily be more efficient, but it definitely
results is smaller code.
Copy link
Owner

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Comment on lines +1748 to +1749
* rules, there is no pair `(sourceTpe, targetTpe)` for which the Wasm
* types are equal but a valid cast would require a *conversion*.
Copy link
Owner

Choose a reason for hiding this comment

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

👍

@tanishiking tanishiking merged commit 1c51097 into tanishiking:main May 21, 2024
1 check passed
@sjrd sjrd deleted the small-codegen-improvements branch May 21, 2024 12:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants