-
Notifications
You must be signed in to change notification settings - Fork 3
Implement monomorphic Array #16
Conversation
I don't think #15 enters into play here. I hope we can keep arrays entirely inside Wasm. |
07ac844
to
9235493
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.
Looks good overall. Some minor suggestions.
// case IRTrees.IsInstanceOf(pos) => | ||
// case IRTrees.JSLinkingInfo(pos) => | ||
// case IRTrees.Select(tpe) => | ||
// case IRTrees.Return(pos) => | ||
// case IRTrees.While(pos) => | ||
// case IRTrees.LoadJSConstructor(pos) => |
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.
These shouldn't reappear. We did implement them.
case t: IRTrees.Throw => | ||
instrs += UNREACHABLE // Implement Exception Handling (Throwable doesn't compile yet) | ||
IRTypes.NothingType |
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.
Undo the case t: IRTrees.Throw =>
since #17 used null.toString()
to achieve the same thing?
Or put it in genThrow(t)
to keep the shape of this pattern match?
) | ||
|
||
def genWithDimensions(typeRef: IRTypes.ArrayTypeRef, lengths: List[IRTrees.Tree]): Unit = { | ||
val elemTy = extractArrayElemType(t.typeRef) |
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 line is inside the recursive genWithDimensions
but it refers to t
which is captured from the enclosing genNewArray
. That's suspicious. Was it meant to be the following instead?
val elemTy = extractArrayElemType(t.typeRef) | |
val elemTy = extractArrayElemType(typeRef) |
val irElemTy = extractArrayElemType(t.typeRef) | ||
val wasmElemTy = TypeTransformer.transformType(irElemTy)(ctx) | ||
val arrTyName = Names.WasmTypeName.WasmArrayTypeName(t.tpe) | ||
ctx.addArrayType( | ||
WasmArrayType( | ||
arrTyName, | ||
WasmStructField(Names.WasmFieldName.arrayField, wasmElemTy, isMutable = true) | ||
) | ||
) |
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.
These 9 lines are copy-pasted between here (genArrayValue
) and genNewArray
. Consider factoring them directly inside a method of ctx
, for example
def getArrayTypeName(typeRef: IRTypes.ArrayTypeRef): WasmArrayTypeName = ...
genWithDimensions( | ||
IRTypes.ArrayTypeRef(typeRef.base, typeRef.dimensions - 1), | ||
lengths.tail | ||
) |
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.
IIUC, this will create a unique nested array and use it for all the elements of the outer array. In other words, it will compile
new Array[Array[Int]](2, 2)
into something equivalent to
val inner = new Array[Int](2)
val outer = Array(inner, inner)
But it is supposed to create a different instance of the inner array for each slot of the outer array.
I don't think it is possible to do this without a generic recursive helper, which we don't have enough infrastructure for at the moment.
I suggest focusing on the case where lengths.size == 1
for now, and leave a ???
for this case. It is rather rare, so we should be able to make a lot of code work without that support.
typeRef.base match { | ||
case IRTypes.ClassRef(className) => ClassType(className) | ||
case IRTypes.PrimRef(tpe) => tpe | ||
} |
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.
typeRef.base match { | |
case IRTypes.ClassRef(className) => ClassType(className) | |
case IRTypes.PrimRef(tpe) => tpe | |
} | |
ctx.inferTypeFromTypeRef(typeRef.base) |
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, excellent :)
Better to work based on #15 forjs.Iterable
...Implement fundamental monomorphic array
Array.ofDim
because of https://github.com/scala-js/scala-js/blob/8dd02c784818d6d3d4a18ebf53cc0797212ef12e/javalib/src/main/scala/java/lang/Integer.scala#L56java.lang.Object
(?) can we box it inscala.Array
likechar
andlong
?