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

Commit

Permalink
Fix the translation of the type java.lang.Void (BoxedUnitClass).
Browse files Browse the repository at this point in the history
It is a nullable reference of the `undef` struct.
  • Loading branch information
sjrd committed Mar 7, 2024
1 parent 4c71d0d commit 1ccf6ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
9 changes: 6 additions & 3 deletions wasm/src/main/scala/ir2wasm/TypeTransformer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ object TypeTransformer {
t: IRTypes.Type
)(implicit ctx: ReadOnlyWasmContext): List[Types.WasmType] =
t match {
case IRTypes.NoType => Nil
case IRTypes.ClassType(className) if className == IRNames.BoxedUnitClass => Nil
case _ => List(transformType(t))
case IRTypes.NoType => Nil
case _ => List(transformType(t))
}
def transformType(t: IRTypes.Type)(implicit ctx: ReadOnlyWasmContext): Types.WasmType =
t match {
Expand All @@ -64,6 +63,10 @@ object TypeTransformer {
Types.WasmRefNullType(
Types.WasmHeapType.Type(Names.WasmTypeName.WasmStructTypeName.string)
)
case IRNames.BoxedUnitClass =>
Types.WasmRefNullType(
Types.WasmHeapType.Type(Names.WasmTypeName.WasmStructTypeName.undef)
)
case _ =>
if (ctx.getClassInfo(clazz.className).isInterface)
Types.WasmRefNullType(Types.WasmHeapType.ObjectType)
Expand Down
23 changes: 8 additions & 15 deletions wasm/src/main/scala/ir2wasm/WasmExpressionBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -661,22 +661,15 @@ private class WasmExpressionBuilder private (ctx: FunctionTypeWriterWasmContext,
}

private def genVarDef(r: IRTrees.VarDef): IRTypes.Type = {
r.vtpe match {
// val _: Unit = rhs
case ClassType(className) if className == IRNames.BoxedUnitClass =>
genTree(r.rhs, IRTypes.NoType)

case _ =>
val local = WasmLocal(
WasmLocalName.fromIR(r.name.name),
TypeTransformer.transformType(r.vtpe)(ctx),
isParameter = false
)
fctx.locals.define(local)
val local = WasmLocal(
WasmLocalName.fromIR(r.name.name),
TypeTransformer.transformType(r.vtpe)(ctx),
isParameter = false
)
fctx.locals.define(local)

genTree(r.rhs, r.vtpe)
instrs += LOCAL_SET(LocalIdx(local.name))
}
genTree(r.rhs, r.vtpe)
instrs += LOCAL_SET(LocalIdx(local.name))

IRTypes.NoType
}
Expand Down

0 comments on commit 1ccf6ff

Please sign in to comment.