-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
// TODO: investigate what's going on | ||
// Don't know why, but it seems that `this` isn't boxed even if | ||
// t.receiver.tpe = ClassType(ClassName<java.lang.Boolean>), and | ||
// primReceiverType = BooleanType | ||
// This wired patch is required for `(func $f#java.lang.Boolean#compareTo_Ljava.lang.Boolean_R` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this change, validation fails because of the following wasm code
(func $f#java.lang.Boolean#compareTo_Ljava.lang.Boolean_R (type $f.268)
(param $___<this> i32) (param $that anyref) (result anyref)
local.get $___<this>
;; <this> is already unboxed
ref.as_non_null
call $__scalaJSHelpers#uZ
local.get $that
call $f#java.lang.Boolean#compareTo_Ljava.lang.Boolean_I
call $__scalaJSHelpers#bI)
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum that's weird indeed. In the ClassDef
of a hijacked class, the tpe
of This()
trees should always be the primitive. So here I would expect t.receiver.tpe == BooleanType
, and therefore we should enter the first if (t.receiver.tpe == primReceiverType)
.
c25f493
to
6b20614
Compare
Added a `reflectiveProxies` field to `typeData`, this field contains an array of struct with `methodId` of `i32`, and a reference to a reflective proxy function. When the compiler found an Apply to the reflective proxy, we lookup the method to call from the `reflectiveProxies` field in the receiver's `typeData` field, instead of normal table dispatching.
6b20614
to
4549279
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Good stuff.
There's one issue but it is pretty niche. We can fix it later.
@@ -47,6 +47,17 @@ object TypeTransformer { | |||
case _ => List(transformType(t)) | |||
} | |||
|
|||
def transformTypeRef(t: IRTypes.TypeRef)(implicit ctx: ReadOnlyWasmContext): Types.WasmType = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't be correct for ClassRef
s of JS types. We need to use
transformType(ctx.inferTypeFromTypeRef(typeRef))
instead.
Note that this is not a problem in transformType
because a ClassType(someJSType)
is not valid in the first place. But ClassRef(someJSType)
is valid; its corresponding type is AnyType
.
#71
Added a
reflectiveProxies
field totypeData
, this field contains anarray of struct with
methodId
ofi32
, and a reference to areflective proxy function.
When the compiler found an Apply to the reflective proxy, we lookup the
method to call from the
reflectiveProxies
field in the receiver'stypeData
field, instead of normal table dispatching.TODO (maybe in another PR)
java.lang.Object#clone
, it generates a following function, and it fails because a function$f#java.lang.Void#clone_Ljava.lang.Object
doesn't exist.ReflectiveCallTest
)