WASM: Support moving subtrees
Context
For discussion in the SCORU WASM crew. This MR solves the "swap issue" where things move around in the tree.
Here's an example of how the new encoding works for a scenario where two vectors swap places in the tree.
Start with a tree (T1):
T1:
- foo
- 0 : A
- 1 : B
- 2 : C
- bar
- 0 : X
- 1 : Y
Run a decode step to decode the tree into a record {foo : vector; bar : vector}
Note that this does not read any values from the tree.
v1 = { tree: T1/foo; produce_value = read_from T1/foo; values = {}; }
v1 = { tree: T1/bar; produce_value = read_from T1/bar; values = {}; }
value1 = {foo = v1; bar = v2}
Now flip v1
and v2
:
value2 = { foo = V2; bar = V1}
Encode the new value given the old tree T1
:
- Remove
foo
fromT1
- Add the tree from vector
v2
tofoo
- Add the loaded bindings from
v2
tofoo
- Remove
bar
fromT1
- Add the tree of vector
v1
tobar
- Add the loaded bindings from
v1
tobar
The new tree T2
now has the shape:
T2:
- foo
- 0
- 1
- bar
- 0
- 1
- 2
Manually testing the MR
CI.
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rst
for the protocol and the environment,CHANGES.rst
at the root of the repository for everything else). -
Select suitable reviewers using the Reviewers
field below. -
Select as Assignee
the next person who should take action on that MR
Edited by Thomas Letan