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

Better receiver types for static dispatch. #118

Merged

Conversation

sjrd
Copy link
Collaborator

@sjrd sjrd commented Apr 22, 2024

Based on #116. Only the last 3 commits belong to this PR.

@sjrd sjrd requested a review from tanishiking April 22, 2024 17:06
sjrd added 3 commits April 23, 2024 10:23
The real method body goes to a method used for statically resolved
calls. That method can take the real `this` type as argument.

For table entries, which need to use `(ref any)` as receiver type,
we generate a separate function. That bridge function casts down
the receiver then performs a tail call to the real function.

With this strategy, we do not need to cast down `this` values
every time we use them. Since most calls as statically resolved,
this also means we don't need any cast at all. For dynamically
resolved calls, the overhead should be small thanks to the tail
call.

This change causes a 30% code size regression for fastLink, but
only 6% in fullLink. We should be able to optimize it further by
only emitting bridges for methods that actually appear in at
least one dispatch table.
This surfaced a few places when instantiating new objects where we
need to manipulate non-null values.
@sjrd sjrd force-pushed the better-receiver-type-for-static-dispatch branch from 55388d9 to b256724 Compare April 23, 2024 08:24
@sjrd sjrd marked this pull request as ready for review April 23, 2024 08:25
@sjrd
Copy link
Collaborator Author

sjrd commented Apr 23, 2024

Rebased.

@sjrd
Copy link
Collaborator Author

sjrd commented May 1, 2024

Ping @tanishiking about this one?

@tanishiking
Copy link
Owner

Oops, I'll take a look today. thanks for pinging

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!

fctx.buildAndAddToContext()

if (namespace == IRTrees.MemberNamespace.Public && !isHijackedClass) {
/* Also generate the bridge that is stored in the table entries. In table
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 5128aa5 into tanishiking:main May 1, 2024
1 check passed
@sjrd sjrd deleted the better-receiver-type-for-static-dispatch branch May 1, 2024 07:47
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