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

Fix static type tests for ancestors of hijacked classes. #93

Merged

Conversation

sjrd
Copy link
Collaborator

@sjrd sjrd commented Apr 11, 2024

This commit fixes the result of x.isInstanceOf[C] where x is a primitive and C is an ancestor of the hijacked class for x.

For jl.Number, which is the only non-Object class that is an ancestor of a hijacked class, we add a special case in the codegen.

For interfaces, we add generic code in their genInstanceTest function, based on their specialInstanceTypes.

This means we have a second place where we need to compute specialInstanceTypes. We move it to the preprocessor, and also use it to generically compute isAncestorOfHijackedClass. This removes the hard-code set that we had before.

Fix #74.
Fix #84.
Fix #92.

@sjrd sjrd requested a review from tanishiking April 11, 2024 12:56
@sjrd sjrd force-pushed the fix-type-tests-for-ancestors-of-hijacked-classes branch from 5a02a15 to 71f17cd Compare April 11, 2024 18:48
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.

I left a minor comment on descriptions, but otherwise LGTM! great work 🎉

if (classInfo.isAncestorOfHijackedClass) {
/* It could be a hijacked class instance that implements this interface.
* Test whether `jsValueType(expr)` is in the `specialInstanceTypes` bitset.
* In other words, return `(1 << jsValueType(expr)) != 0`.
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
* In other words, return `(1 << jsValueType(expr)) != 0`.
* In other words, return `(1 << jsValueType(expr) & specialInstanceTypes) != 0`.

/* It could be a hijacked class instance that implements this interface.
* Test whether `jsValueType(expr)` is in the `specialInstanceTypes` bitset.
* In other words, return `(1 << jsValueType(expr)) != 0`.
*/
Copy link
Owner

Choose a reason for hiding this comment

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

Though it might be a bit duplicated with an explanation at specialInstanceTypes, it would be helpful for me if we can add some example like below here 😅

Suggested change
*/
*
* For example, when the `jsValueType(expr)` is 'string', 'expr.isInstanceOf[j.l.CharSequence]'
* should be `true` because `j.l.String` implements `j.l.CharSequence`, and
* `specialInstanceTypes` for `j.l.CharSequence` contains `1 << jsValueType(j.l.String)`.
*/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a more concrete example. :)

This commit fixes the result of `x.isInstanceOf[C]` where `x` is
a primitive and `C` is an ancestor of the hijacked class for `x`.

For `jl.Number`, which is the only non-`Object` class that is an
ancestor of a hijacked class, we add a special case in the codegen.

For interfaces, we add generic code in their `genInstanceTest`
function, based on their `specialInstanceTypes`.

This means we have a second place where we need to compute
`specialInstanceTypes`. We move it to the preprocessor, and also
use it to generically compute `isAncestorOfHijackedClass`. This
removes the hard-code set that we had before.

Fix tanishiking#74.
Fix tanishiking#84.
Fix tanishiking#92.
@sjrd sjrd force-pushed the fix-type-tests-for-ancestors-of-hijacked-classes branch from 71f17cd to 716d7d4 Compare April 12, 2024 08:03
@sjrd sjrd merged commit 254e6c5 into tanishiking:main Apr 12, 2024
1 check passed
@sjrd sjrd deleted the fix-type-tests-for-ancestors-of-hijacked-classes branch April 12, 2024 08:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants