summaryrefslogtreecommitdiff
path: root/test/ctor-eval/gc-array.wast.out
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-02-03 14:23:49 -0800
committerGitHub <noreply@github.com>2022-02-03 22:23:49 +0000
commit880c765ab9a4124f708da57329dcbe07c1ca9fa3 (patch)
tree0b2d7f53b816155253e6fa469ca9e58f8e5c7f56 /test/ctor-eval/gc-array.wast.out
parente6f15747d1e3557cfff87c3149e91e3dbd0ff6c7 (diff)
downloadbinaryen-880c765ab9a4124f708da57329dcbe07c1ca9fa3.tar.gz
binaryen-880c765ab9a4124f708da57329dcbe07c1ca9fa3.tar.bz2
binaryen-880c765ab9a4124f708da57329dcbe07c1ca9fa3.zip
[Wasm GC] [ctor-eval] Evaluate and serialize GC data (#4491)
This ended up simpler than I thought. We can simply emit global and local data as we go, creating globals as necessary to contain GC data, and referring to them using global.get later. That will ensure that data identity works (things referring to the same object in the interpreter will refer to the same object when the wasm is loaded). In more detail, each live GC item is created in a "defining global", a global that is immutable and of the precise type of that data. Then we just read from that location in any place that wants to refer to that data. That is, something like function foo() { var x = Bar(10); var y = Bar(20); var z = x; z.value++; // first object now contains 11 ... } will be evalled into something like var define$0 = Bar(11); // note the ++ has taken effect here var define$1 = Bar(20); function foo() { var x = define$0; var y = define$1; var z = define$0; ... } This PR should handle everything but "cycles", that is, GC data that at runtime ends up forming a loop. Leaving that for later work (not sure how urgent it is to fix).
Diffstat (limited to 'test/ctor-eval/gc-array.wast.out')
-rw-r--r--test/ctor-eval/gc-array.wast.out27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/ctor-eval/gc-array.wast.out b/test/ctor-eval/gc-array.wast.out
new file mode 100644
index 000000000..d78eba852
--- /dev/null
+++ b/test/ctor-eval/gc-array.wast.out
@@ -0,0 +1,27 @@
+(module
+ (type $array (array (mut i32)))
+ (type $none_=>_i32 (func (result i32)))
+ (global $global1 (ref $array) (array.init_static $array
+ (i32.const 10)
+ (i32.const 20)
+ (i32.const 30)
+ (i32.const 40)
+ ))
+ (global $global2 (ref $array) (array.init_static $array
+ (i32.const 42)
+ (i32.const 1337)
+ ))
+ (export "keepalive" (func $1))
+ (func $1 (result i32)
+ (i32.add
+ (array.get $array
+ (global.get $global1)
+ (i32.const 0)
+ )
+ (array.get $array
+ (global.get $global2)
+ (i32.const 0)
+ )
+ )
+ )
+)