-
Notifications
You must be signed in to change notification settings - Fork 39
Added support for Tuples #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: hkmc2
Are you sure you want to change the base?
Conversation
LPTK
left a comment
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.
Neat! This looks well done to me. WDYT @Derppening?
| label = N, | ||
| children = Seq(assignInstr, rstBlk), | ||
| resultTypes = rstBlk.resultTypes.map: ty => | ||
| Result(if ty is UnreachableType then RefType.anyref else ty.asValType_!) |
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.
What is this UnreachableType special case for?
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
Derppening
left a comment
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.
Apart from some fields that appear to be better located in Ctx than WatBuilder, the rest looks good to me.
Please do add documentation where possible, including private members.
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Instructions.scala
Outdated
Show resolved
Hide resolved
| private case class TupleArrayInfo(arrayType: TypeIdx, elemType: Type, mutable: Bool) | ||
| private var mutTupleArrayInfo: Opt[TupleArrayInfo] = N | ||
| private var tupleArrayInfo: Opt[TupleArrayInfo] = N |
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.
I don't really understand why this is necessary. Can't we just lookup/cache the Wasm type for tuples from the module?
And, since we assume that all tuples have anyrefs as their element type, why do we need to store elemType and mutable?
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.
I think mutable is needed because we do differentiate mutable and immutable tuples (see the tests).
Also, it doesn't hurt to store elemType. We may later generalize support for more precisely-typed arrays.
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.
I guess I wasn't being clear here - What I meant is why is mutTupleArrayInfo and tupleArrayInfo necessary and stored as separate fields? It appears to me that what we may want is a lookup table for intrinsic types (e.g. Unit, Tuple and mutable Tuple) to lookup its corresponding Wasm type.
While mutTupleArrayInfo and tupleArrayInfo is probably good enough when tuples are stored as anyref arrays as they are now, if (and when) we generalize support for more precisely-typed arrays, these fields probably wouldn't suffice.
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.
Ok now I look up intrinsic types from MutMap declared in Ctx
| val mutInfo = tupleArray(true) | ||
| val immInfo = tupleArray(false) | ||
| val tupleIsMutable = ref.test(tupleExpr, RefType(mutInfo.arrayType, nullable = true)) | ||
| val mutableBranch = | ||
| val tupleRef = ref.cast(tupleExpr, RefType(mutInfo.arrayType, nullable = false)) | ||
| array.get(mutInfo.arrayType, tupleRef, idxBuilder(tupleRef), mutInfo.elemType) | ||
| val immutableBranch = | ||
| val tupleRef = ref.cast(tupleExpr, RefType(immInfo.arrayType, nullable = false)) | ||
| array.get(immInfo.arrayType, tupleRef, idxBuilder(tupleRef), immInfo.elemType) |
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.
I thought we established that array.get can be used on both mutable and immutable arrays. Is there any reason why this is necessary?
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.
I need to first cast to use array.get. I think that we can't cast immutable tuple to the mutable tuple type or vice versa.
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.
But can't we just use array.get on both mutable and immutable arrays in Wasm?
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.
Yes but before using array.get we need to cast expressions
| resultTypes = Seq(Result(mutInfo.elemType.asValType_!)) | ||
| ) | ||
|
|
||
| private def tupleIndexBuilder( |
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.
Nit: buildTupleIndex - This is an operation, not a class/factory.
No description provided.