Skip to content

Conversation

@FetBoba
Copy link

@FetBoba FetBoba commented Jan 1, 2026

No description provided.

Copy link
Contributor

@LPTK LPTK left a 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_!)
Copy link
Contributor

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?

@LPTK LPTK requested a review from Derppening January 1, 2026 16:40
Copy link

@Derppening Derppening left a 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.

Comment on lines 40 to 42
private case class TupleArrayInfo(arrayType: TypeIdx, elemType: Type, mutable: Bool)
private var mutTupleArrayInfo: Opt[TupleArrayInfo] = N
private var tupleArrayInfo: Opt[TupleArrayInfo] = N

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?

Copy link
Contributor

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.

Copy link

@Derppening Derppening Jan 2, 2026

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.

Copy link
Author

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

Comment on lines 82 to 90
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)

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?

Copy link
Author

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.

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?

Copy link
Author

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(

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants