Pattern for (or possibility of) tuple.set ? #7448
-
Hello! As far as I've been able to figure, if I have a variable that's a tuple type, the only way I could update a single part of the tuple is to remake the entire thing with the single member adjusted (I use the JS wrapper currently). Is there any possibility of e.g. a tuple.set instruction in the future to update a single member of a tuple? Or is there already a better pattern to accomplish this that I'm just not familiar with / is this discouraged in general for some reason? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The problem with tuples and tuple instructions is that they don't exist in the underlying WebAssembly, so Binaryen's binary writer has to do a complicated lowering involving scratch locals to emit them. Because of this complexity, there's a high bar for adding new tuple instructions. The best reason for adding a new tuple instruction would be if it allowed us to emit better WebAssembly for common patterns. I'm assuming that An alternative would be a In general we don't want to incentivize using tuples by adding a bunch of complexity to make them easier to use. Binaryen can't optimize tuples very well, so it's best to use them only when absolutely necessary. |
Beta Was this translation helpful? Give feedback.
The problem with tuples and tuple instructions is that they don't exist in the underlying WebAssembly, so Binaryen's binary writer has to do a complicated lowering involving scratch locals to emit them. Because of this complexity, there's a high bar for adding new tuple instructions. The best reason for adding a new tuple instruction would be if it allowed us to emit better WebAssembly for common patterns.
I'm assuming that
tuple.set
would take an immediate index, a tuple operand, and the replacement value, and would return the modified tuple. The higher the replaced index is, the better the code generated fromtuple.set
would be compared to reconstructing the whole tuple, but when replac…