diff --git a/compiler/test/__snapshots__/basic_functionality.1d2ec323.0.snapshot b/compiler/test/__snapshots__/basic_functionality.1d2ec323.0.snapshot index f918444785..a3c871c418 100644 --- a/compiler/test/__snapshots__/basic_functionality.1d2ec323.0.snapshot +++ b/compiler/test/__snapshots__/basic_functionality.1d2ec323.0.snapshot @@ -1,11 +1,10 @@ basic functionality › comp22 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -16,6 +15,7 @@ basic functionality › comp22 (import \"GRAIN$MODULE$runtime/gc\" \"malloc\" (func $wimport_GRAIN$MODULE$runtime/gc_malloc (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"isnt\" (func $gimport_pervasives_isnt (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) @@ -45,7 +45,7 @@ basic functionality › comp22 (local.get $0) (i32.const 3) ) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (local.get $0) @@ -56,27 +56,22 @@ basic functionality › comp22 ) ) ) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -113,15 +108,13 @@ basic functionality › comp22 ) ) ) - (local.set $1 + (local.set $3 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -131,9 +124,6 @@ basic functionality › comp22 (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -150,24 +140,24 @@ basic functionality › comp22 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) + (local.get $2) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) + (local.get $3) ) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $2) ) ) (drop @@ -179,7 +169,7 @@ basic functionality › comp22 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $3) ) ) (local.get $4) diff --git a/compiler/test/__snapshots__/basic_functionality.3c2ba165.0.snapshot b/compiler/test/__snapshots__/basic_functionality.3c2ba165.0.snapshot index 00e757d5b1..afafd4be12 100644 --- a/compiler/test/__snapshots__/basic_functionality.3c2ba165.0.snapshot +++ b/compiler/test/__snapshots__/basic_functionality.3c2ba165.0.snapshot @@ -1,11 +1,10 @@ basic functionality › comp20 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -14,6 +13,7 @@ basic functionality › comp20 (import \"GRAIN$MODULE$pervasives\" \"GRAIN$EXPORT$isnt\" (global $gimport_pervasives_isnt (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"isnt\" (func $gimport_pervasives_isnt (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) @@ -29,21 +29,16 @@ basic functionality › comp20 (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -55,21 +50,16 @@ basic functionality › comp20 (local.set $1 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $0) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -81,21 +71,16 @@ basic functionality › comp20 (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $2) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -107,21 +92,16 @@ basic functionality › comp20 (local.set $3 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $3 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $2) ) - (i32.load offset=8 - (local.get $3) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) diff --git a/compiler/test/__snapshots__/basic_functionality.52ca8e0e.0.snapshot b/compiler/test/__snapshots__/basic_functionality.52ca8e0e.0.snapshot index eb942acf97..01323b3d8d 100644 --- a/compiler/test/__snapshots__/basic_functionality.52ca8e0e.0.snapshot +++ b/compiler/test/__snapshots__/basic_functionality.52ca8e0e.0.snapshot @@ -1,11 +1,9 @@ basic functionality › func_shadow (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $i32_=>_i32 (func (param i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -17,51 +15,55 @@ basic functionality › func_shadow (import \"GRAIN$MODULE$pervasives\" \"print\" (func $gimport_pervasives_print (param i32 i32) (result i32))) (global $global_1 (mut i32) (i32.const 0)) (global $global_0 (mut i32) (i32.const 0)) - (global $global_3 i32 (i32.const 2)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131 $foo_1133) + (global $global_3 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_3)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (result i32) + (func $_gmain (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) + (local $2 i32) (i32.store - (local.tee $1 + (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) (i32.const 16) ) ) - (i32.const 1) + (i32.const 6) ) (i32.store offset=4 - (local.get $1) - (i32.const 3) + (local.get $0) + (i32.const 1) ) - (i64.store offset=8 - (local.get $1) - (i64.const 7496034) + (i32.store offset=8 + (local.get $0) + (i32.const -1) ) - (local.set $1 + (i32.store offset=12 + (local.get $0) + (i32.const 0) + ) + (global.set $global_0 (tuple.extract 0 (tuple.make - (local.get $1) - (local.get $1) + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (global.get $global_0) + ) ) ) ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.set $1 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_0) ) ) - (local.get $1) - ) - (func $foo_1133 (; has Stack IR ;) (param $0 i32) (result i32) - (local $1 i32) (i32.store - (local.tee $1 + (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) (i32.const 16) @@ -70,72 +72,26 @@ basic functionality › func_shadow (i32.const 1) ) (i32.store offset=4 - (local.get $1) + (local.get $0) (i32.const 3) ) (i64.store offset=8 - (local.get $1) - (i64.const 8020322) - ) - (local.set $1 - (tuple.extract 0 - (tuple.make - (local.get $1) - (local.get $1) - ) - ) + (local.get $0) + (i64.const 7496034) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (local.get $1) - ) - (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (local $1 i32) - (local $2 i32) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 1) - ) - (i32.store offset=8 - (local.get $0) - (global.get $wimport__grainEnv_relocBase) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 0) - ) - (global.set $global_0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (global.get $global_0) - ) - ) + (local.get $1) ) ) (local.set $1 (tuple.extract 0 (tuple.make - (call $foo_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_0) + (tuple.extract 0 + (tuple.make + (local.get $0) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -172,10 +128,7 @@ basic functionality › func_shadow ) (i32.store offset=8 (local.get $0) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 1) - ) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -192,13 +145,42 @@ basic functionality › func_shadow ) ) ) + (local.set $2 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_1) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 1) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i64.store offset=8 + (local.get $0) + (i64.const 8020322) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $2) + ) + ) (local.set $0 (tuple.extract 0 (tuple.make - (call $foo_1133 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_1) + (tuple.extract 0 + (tuple.make + (local.get $0) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef diff --git a/compiler/test/__snapshots__/basic_functionality.61c58118.0.snapshot b/compiler/test/__snapshots__/basic_functionality.61c58118.0.snapshot index b011fd51a0..f4787e45a3 100644 --- a/compiler/test/__snapshots__/basic_functionality.61c58118.0.snapshot +++ b/compiler/test/__snapshots__/basic_functionality.61c58118.0.snapshot @@ -1,11 +1,9 @@ basic functionality › block_no_expression (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $i32_=>_i32 (func (param i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -14,21 +12,11 @@ basic functionality › block_no_expression (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $f_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $f_1131 (; has Stack IR ;) (param $0 i32) (result i32) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (i32.const 1879048190) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) (i32.store @@ -46,7 +34,7 @@ basic functionality › block_no_expression ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -63,12 +51,19 @@ basic functionality › block_no_expression ) ) ) - (call $f_1131 + (local.set $0 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $0) + ) + ) + (i32.const 1879048190) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/basic_functionality.711a4824.0.snapshot b/compiler/test/__snapshots__/basic_functionality.711a4824.0.snapshot index 01c5a8fcbe..70c113feb0 100644 --- a/compiler/test/__snapshots__/basic_functionality.711a4824.0.snapshot +++ b/compiler/test/__snapshots__/basic_functionality.711a4824.0.snapshot @@ -1,11 +1,9 @@ basic functionality › pattern_match_unsafe_wasm (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $i32_=>_i32 (func (param i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -16,73 +14,11 @@ basic functionality › pattern_match_unsafe_wasm (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"print\" (func $gimport_pervasives_print (param i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 2)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $test_1131 $foo_1132) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $test_1131 (; has Stack IR ;) (param $0 i32) (result i32) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $0) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 1) - ) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 0) - ) - (drop - (call $foo_1132 - (local.tee $0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (i32.const 0) - ) - ) - ) - (i32.const 0) - ) - ) - (drop - (call $foo_1132 - (local.get $0) - (i32.const 1) - ) - ) - (drop - (call $foo_1132 - (local.get $0) - (i32.const 5) - ) - ) - (drop - (call $foo_1132 - (local.get $0) - (i32.const 8) - ) - ) - (call $foo_1132 - (local.get $0) - (i32.const 42) - ) - ) (func $foo_1132 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) (block $switch.31_outer (result i32) (drop @@ -305,7 +241,7 @@ basic functionality › pattern_match_unsafe_wasm ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -322,12 +258,68 @@ basic functionality › pattern_match_unsafe_wasm ) ) ) - (call $test_1131 + (drop (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (i32.const -1) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 0) + ) + (drop + (call $foo_1132 + (local.tee $0 + (tuple.extract 0 + (tuple.make + (local.get $0) + (i32.const 0) + ) + ) + ) + (i32.const 0) + ) + ) + (drop + (call $foo_1132 + (local.get $0) + (i32.const 1) + ) + ) + (drop + (call $foo_1132 + (local.get $0) + (i32.const 5) + ) + ) + (drop + (call $foo_1132 + (local.get $0) + (i32.const 8) + ) + ) + (call $foo_1132 + (local.get $0) + (i32.const 42) + ) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/basic_functionality.9379df0d.0.snapshot b/compiler/test/__snapshots__/basic_functionality.9379df0d.0.snapshot index 6ad0251222..002540459b 100644 --- a/compiler/test/__snapshots__/basic_functionality.9379df0d.0.snapshot +++ b/compiler/test/__snapshots__/basic_functionality.9379df0d.0.snapshot @@ -1,11 +1,10 @@ basic functionality › comp21 (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -15,6 +14,7 @@ basic functionality › comp21 (import \"GRAIN$MODULE$runtime/gc\" \"malloc\" (func $wimport_GRAIN$MODULE$runtime/gc_malloc (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -43,7 +43,7 @@ basic functionality › comp21 (local.get $0) (i32.const 3) ) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (local.get $0) @@ -54,27 +54,22 @@ basic functionality › comp21 ) ) ) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -111,15 +106,13 @@ basic functionality › comp21 ) ) ) - (local.set $1 + (local.set $3 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -129,9 +122,6 @@ basic functionality › comp21 (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -146,11 +136,11 @@ basic functionality › comp21 (i32.eq (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) + (local.get $2) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) + (local.get $3) ) ) (i32.const 31) @@ -161,13 +151,13 @@ basic functionality › comp21 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $2) ) ) (drop @@ -179,7 +169,7 @@ basic functionality › comp21 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $3) ) ) (local.get $4) diff --git a/compiler/test/__snapshots__/basic_functionality.f58be537.0.snapshot b/compiler/test/__snapshots__/basic_functionality.f58be537.0.snapshot index 1e908633a4..e799b390ce 100644 --- a/compiler/test/__snapshots__/basic_functionality.f58be537.0.snapshot +++ b/compiler/test/__snapshots__/basic_functionality.f58be537.0.snapshot @@ -1,11 +1,10 @@ basic functionality › comp19 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -13,6 +12,7 @@ basic functionality › comp19 (import \"GRAIN$MODULE$pervasives\" \"GRAIN$EXPORT$[...]\" (global $gimport_pervasives_[...] (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -27,21 +27,16 @@ basic functionality › comp19 (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -53,21 +48,16 @@ basic functionality › comp19 (local.set $1 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $0) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -79,21 +69,16 @@ basic functionality › comp19 (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $2) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -105,21 +90,16 @@ basic functionality › comp19 (local.set $3 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $3 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $2) ) - (i32.load offset=8 - (local.get $3) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) diff --git a/compiler/test/__snapshots__/basic_functionality.fe88cb04.0.snapshot b/compiler/test/__snapshots__/basic_functionality.fe88cb04.0.snapshot index 257d817246..dd6f9aa49b 100644 --- a/compiler/test/__snapshots__/basic_functionality.fe88cb04.0.snapshot +++ b/compiler/test/__snapshots__/basic_functionality.fe88cb04.0.snapshot @@ -1,7 +1,7 @@ basic functionality › func_shadow_and_indirect_call (module - (type $i32_=>_i32 (func (param i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) @@ -19,48 +19,13 @@ basic functionality › func_shadow_and_indirect_call (global $global_2 (mut i32) (i32.const 0)) (global $global_1 (mut i32) (i32.const 0)) (global $global_0 (mut i32) (i32.const 0)) - (global $global_5 i32 (i32.const 4)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131 $foo_1133 $foo_1135 $func_1148) + (global $global_5 i32 (i32.const 1)) + (elem $elem (global.get $wimport__grainEnv_relocBase) $func_1148) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_5)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (result i32) - (local $1 i32) - (i32.store - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 1) - ) - (i32.store offset=4 - (local.get $1) - (i32.const 3) - ) - (i64.store offset=8 - (local.get $1) - (i64.const 7496034) - ) - (local.set $1 - (tuple.extract 0 - (tuple.make - (local.get $1) - (local.get $1) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (local.get $1) - ) - (func $foo_1133 (; has Stack IR ;) (param $0 i32) (result i32) + (func $func_1148 (; has Stack IR ;) (param $0 i32) (result i32) (local $1 i32) (i32.store (local.tee $1 @@ -77,7 +42,7 @@ basic functionality › func_shadow_and_indirect_call ) (i64.store offset=8 (local.get $1) - (i64.const 8020322) + (i64.const 7894385) ) (local.set $1 (tuple.extract 0 @@ -95,10 +60,13 @@ basic functionality › func_shadow_and_indirect_call ) (local.get $1) ) - (func $foo_1135 (; has Stack IR ;) (param $0 i32) (result i32) + (func $_gmain (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) + (local $2 i32) + (local $3 i32) (i32.store - (local.tee $1 + (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) (i32.const 16) @@ -107,40 +75,36 @@ basic functionality › func_shadow_and_indirect_call (i32.const 6) ) (i32.store offset=4 - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.store offset=8 - (local.get $1) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 3) - ) + (local.get $0) + (i32.const -1) ) (i32.store offset=12 - (local.get $1) + (local.get $0) (i32.const 0) ) - (local.set $1 + (global.set $global_0 (tuple.extract 0 (tuple.make - (local.get $1) - (local.get $1) + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (global.get $global_0) + ) ) ) ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.set $1 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_0) ) ) - (local.get $1) - ) - (func $func_1148 (; has Stack IR ;) (param $0 i32) (result i32) - (local $1 i32) (i32.store - (local.tee $1 + (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) (i32.const 16) @@ -149,73 +113,26 @@ basic functionality › func_shadow_and_indirect_call (i32.const 1) ) (i32.store offset=4 - (local.get $1) + (local.get $0) (i32.const 3) ) (i64.store offset=8 - (local.get $1) - (i64.const 7894385) - ) - (local.set $1 - (tuple.extract 0 - (tuple.make - (local.get $1) - (local.get $1) - ) - ) + (local.get $0) + (i64.const 7496034) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (local.get $1) - ) - (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 1) - ) - (i32.store offset=8 - (local.get $0) - (global.get $wimport__grainEnv_relocBase) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 0) - ) - (global.set $global_0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (global.get $global_0) - ) - ) + (local.get $1) ) ) (local.set $1 (tuple.extract 0 (tuple.make - (call $foo_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_0) + (tuple.extract 0 + (tuple.make + (local.get $0) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -252,10 +169,7 @@ basic functionality › func_shadow_and_indirect_call ) (i32.store offset=8 (local.get $0) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 1) - ) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -272,13 +186,42 @@ basic functionality › func_shadow_and_indirect_call ) ) ) + (local.set $2 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_1) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 1) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i64.store offset=8 + (local.get $0) + (i64.const 8020322) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $2) + ) + ) (local.set $2 (tuple.extract 0 (tuple.make - (call $foo_1133 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_1) + (tuple.extract 0 + (tuple.make + (local.get $0) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -315,10 +258,7 @@ basic functionality › func_shadow_and_indirect_call ) (i32.store offset=8 (local.get $0) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 2) - ) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -335,13 +275,46 @@ basic functionality › func_shadow_and_indirect_call ) ) ) + (local.set $3 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_2) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 1) + ) + (i32.store offset=8 + (local.get $0) + (global.get $wimport__grainEnv_relocBase) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 0) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $3) + ) + ) (global.set $global_3 (tuple.extract 0 (tuple.make - (call $foo_1135 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_2) + (tuple.extract 0 + (tuple.make + (local.get $0) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef diff --git a/compiler/test/__snapshots__/enums.aa34084a.0.snapshot b/compiler/test/__snapshots__/enums.aa34084a.0.snapshot index 0b5cf4fec8..1f1f01d9d9 100644 --- a/compiler/test/__snapshots__/enums.aa34084a.0.snapshot +++ b/compiler/test/__snapshots__/enums.aa34084a.0.snapshot @@ -4,7 +4,6 @@ enums › adt_trailing (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"_grainEnv\" \"moduleRuntimeId\" (global $wimport__grainEnv_moduleRuntimeId i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) @@ -15,64 +14,13 @@ enums › adt_trailing (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_1 (mut i32) (i32.const 0)) (global $global_0 (mut i32) (i32.const 0)) - (global $global_3 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $Cheese_1132) + (global $global_3 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"GRAIN$EXPORT$Pepperoni\" (global $global_1)) (export \"GRAIN$EXPORT$Cheese\" (global $global_0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_3)) - (func $Cheese_1132 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (i32.store - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 24) - ) - ) - (i32.const 2) - ) - (i32.store offset=4 - (local.get $2) - (i32.shl - (global.get $wimport__grainEnv_moduleRuntimeId) - (i32.const 1) - ) - ) - (i32.store offset=8 - (local.get $2) - (i32.const 2263) - ) - (i32.store offset=12 - (local.get $2) - (i32.const 1) - ) - (i32.store offset=16 - (local.get $2) - (i32.const 1) - ) - (i32.store offset=20 - (local.get $2) - (local.get $1) - ) - (local.set $1 - (tuple.extract 0 - (tuple.make - (local.get $2) - (local.get $2) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (local.get $1) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) (i32.store @@ -156,7 +104,7 @@ enums › adt_trailing ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) diff --git a/compiler/test/__snapshots__/enums.ae26523b.0.snapshot b/compiler/test/__snapshots__/enums.ae26523b.0.snapshot index edb9f018a3..ed41a01798 100644 --- a/compiler/test/__snapshots__/enums.ae26523b.0.snapshot +++ b/compiler/test/__snapshots__/enums.ae26523b.0.snapshot @@ -5,7 +5,6 @@ enums › enum_recursive_data_definition (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"_grainEnv\" \"moduleRuntimeId\" (global $wimport__grainEnv_moduleRuntimeId i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) @@ -21,8 +20,7 @@ enums › enum_recursive_data_definition (global $global_4 (mut i32) (i32.const 0)) (global $global_1 (mut i32) (i32.const 0)) (global $global_2 (mut i32) (i32.const 0)) - (global $global_6 i32 (i32.const 2)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $Node_1134 $Cons_1136) + (global $global_6 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"GRAIN$EXPORT$Cons\" (global $global_3)) (export \"GRAIN$EXPORT$Empty\" (global $global_0)) @@ -324,7 +322,7 @@ enums › enum_recursive_data_definition ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -392,10 +390,7 @@ enums › enum_recursive_data_definition ) (i32.store offset=8 (local.get $0) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 1) - ) + (i32.const -1) ) (i32.store offset=12 (local.get $0) diff --git a/compiler/test/__snapshots__/exceptions.a68ae348.0.snapshot b/compiler/test/__snapshots__/exceptions.a68ae348.0.snapshot index 03aa94fa0e..f1714272c9 100644 --- a/compiler/test/__snapshots__/exceptions.a68ae348.0.snapshot +++ b/compiler/test/__snapshots__/exceptions.a68ae348.0.snapshot @@ -5,7 +5,6 @@ exceptions › exception_4 (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"_grainEnv\" \"moduleRuntimeId\" (global $wimport__grainEnv_moduleRuntimeId i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) @@ -16,9 +15,9 @@ exceptions › exception_4 (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_1 (mut i32) (i32.const 0)) (global $global_0 (mut i32) (i32.const 0)) - (global $global_3 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $Foo_1131) + (global $global_3 i32 (i32.const 0)) (export \"memory\" (memory $0)) + (export \"Foo\" (func $Foo_1131)) (export \"GRAIN$EXPORT$Bar\" (global $global_1)) (export \"GRAIN$EXPORT$Foo\" (global $global_0)) (export \"_gmain\" (func $_gmain)) @@ -166,7 +165,7 @@ exceptions › exception_4 ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -232,5 +231,5 @@ exceptions › exception_4 (call $_gmain) ) ) - ;; custom section \"cmi\", size 1093 + ;; custom section \"cmi\", size 1254 ) diff --git a/compiler/test/__snapshots__/exceptions.ccac3e71.0.snapshot b/compiler/test/__snapshots__/exceptions.ccac3e71.0.snapshot index eef2976ff5..0fc5e45519 100644 --- a/compiler/test/__snapshots__/exceptions.ccac3e71.0.snapshot +++ b/compiler/test/__snapshots__/exceptions.ccac3e71.0.snapshot @@ -120,5 +120,5 @@ exceptions › exception_2 (call $_gmain) ) ) - ;; custom section \"cmi\", size 566 + ;; custom section \"cmi\", size 620 ) diff --git a/compiler/test/__snapshots__/exports.a2013f43.0.snapshot b/compiler/test/__snapshots__/exports.a2013f43.0.snapshot index fa9bd955b5..ad5b8e534b 100644 --- a/compiler/test/__snapshots__/exports.a2013f43.0.snapshot +++ b/compiler/test/__snapshots__/exports.a2013f43.0.snapshot @@ -5,15 +5,13 @@ exports › let_rec_export (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"malloc\" (func $wimport_GRAIN$MODULE$runtime/gc_malloc (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"foo\" (func $foo_1131)) (export \"GRAIN$EXPORT$foo\" (global $global_0)) @@ -46,7 +44,7 @@ exports › let_rec_export ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) diff --git a/compiler/test/__snapshots__/functions.06134c8a.0.snapshot b/compiler/test/__snapshots__/functions.06134c8a.0.snapshot index 37c2e71d0f..ccd4238f89 100644 --- a/compiler/test/__snapshots__/functions.06134c8a.0.snapshot +++ b/compiler/test/__snapshots__/functions.06134c8a.0.snapshot @@ -1,11 +1,9 @@ functions › dup_func (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $i32_=>_i32 (func (param i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -14,21 +12,11 @@ functions › dup_func (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1135) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $foo_1135 (; has Stack IR ;) (param $0 i32) (result i32) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (i32.const 19) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) (i32.store @@ -46,7 +34,7 @@ functions › dup_func ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -63,12 +51,19 @@ functions › dup_func ) ) ) - (call $foo_1135 + (local.set $0 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $0) + ) + ) + (i32.const 19) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.14922a92.0.snapshot b/compiler/test/__snapshots__/functions.14922a92.0.snapshot index c4431c786e..50897a292d 100644 --- a/compiler/test/__snapshots__/functions.14922a92.0.snapshot +++ b/compiler/test/__snapshots__/functions.14922a92.0.snapshot @@ -5,7 +5,6 @@ functions › shorthand_4 (type $none_=>_none (func)) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -16,48 +15,14 @@ functions › shorthand_4 (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local.set $2 - (tuple.extract 0 - (tuple.make - (call $gimport_pervasives_+ - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_+) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (i32.const 7) - ) - (i32.const 0) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (local.get $2) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) + (local $1 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -73,7 +38,7 @@ functions › shorthand_4 ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -90,13 +55,43 @@ functions › shorthand_4 ) ) ) - (call $foo_1131 + (local.set $0 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) - (i32.const 3) ) + (local.set $1 + (tuple.extract 0 + (tuple.make + (call $gimport_pervasives_+ + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_+) + ) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 3) + ) + (i32.const 7) + ) + (i32.const 0) + ) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $0) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 3) + ) + ) + (local.get $1) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.1be5ecd5.0.snapshot b/compiler/test/__snapshots__/functions.1be5ecd5.0.snapshot index 88ac6d4286..983cee6587 100644 --- a/compiler/test/__snapshots__/functions.1be5ecd5.0.snapshot +++ b/compiler/test/__snapshots__/functions.1be5ecd5.0.snapshot @@ -4,7 +4,6 @@ functions › shorthand_1 (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -13,41 +12,14 @@ functions › shorthand_1 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local.set $2 - (tuple.extract 0 - (tuple.make - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (i32.const 0) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (local.get $2) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) + (local $1 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -63,7 +35,7 @@ functions › shorthand_1 ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -80,13 +52,36 @@ functions › shorthand_1 ) ) ) - (call $foo_1131 + (local.set $0 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) - (i32.const 3) ) + (local.set $1 + (tuple.extract 0 + (tuple.make + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 3) + ) + (i32.const 0) + ) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $0) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 3) + ) + ) + (local.get $1) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.23afd9c9.0.snapshot b/compiler/test/__snapshots__/functions.23afd9c9.0.snapshot index c284862190..193e891486 100644 --- a/compiler/test/__snapshots__/functions.23afd9c9.0.snapshot +++ b/compiler/test/__snapshots__/functions.23afd9c9.0.snapshot @@ -1,11 +1,10 @@ functions › lam_destructure_5 (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -15,13 +14,15 @@ functions › lam_destructure_5 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) - (global $global_1 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $lam_lambda_1136) + (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) - (func $lam_lambda_1136 (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $_gmain (; has Stack IR ;) (result i32) + (local $0 i32) + (local $1 i32) + (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -36,7 +37,128 @@ functions › lam_destructure_5 (local $14 i32) (local $15 i32) (local $16 i32) - (local.set $3 + (local $17 i32) + (local $18 i32) + (local $19 i32) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=8 + (local.get $0) + (i32.const -1) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 0) + ) + (local.set $7 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 20) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 5) + ) + (i32.store offset=16 + (local.get $0) + (i32.const 7) + ) + (local.set $8 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 9) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 11) + ) + (local.set $9 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (local.set $18 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $7) + ) + ) + (local.set $0 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $8) + ) + ) + (local.set $6 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $9) + ) + ) + (local.set $1 (tuple.extract 0 (tuple.make (i32.const 0) @@ -47,7 +169,7 @@ functions › lam_destructure_5 ) ) ) - (local.set $4 + (local.set $2 (tuple.extract 0 (tuple.make (i32.const 0) @@ -58,7 +180,7 @@ functions › lam_destructure_5 ) ) ) - (local.set $5 + (local.set $3 (tuple.extract 0 (tuple.make (i32.const 0) @@ -69,13 +191,13 @@ functions › lam_destructure_5 ) ) ) - (local.set $8 + (local.set $10 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -85,13 +207,13 @@ functions › lam_destructure_5 ) ) ) - (local.set $9 + (local.set $11 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -101,13 +223,13 @@ functions › lam_destructure_5 ) ) ) - (local.set $10 + (local.set $12 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=16 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -121,16 +243,16 @@ functions › lam_destructure_5 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $5 + (local.set $3 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $10) + (local.get $12) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $5) + (local.get $3) ) ) ) @@ -143,16 +265,16 @@ functions › lam_destructure_5 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $4 + (local.set $2 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $9) + (local.get $11) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $2) ) ) ) @@ -165,16 +287,16 @@ functions › lam_destructure_5 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $3 + (local.set $1 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $8) + (local.get $10) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $1) ) ) ) @@ -183,7 +305,7 @@ functions › lam_destructure_5 ) ) ) - (local.set $6 + (local.set $4 (tuple.extract 0 (tuple.make (i32.const 0) @@ -194,7 +316,7 @@ functions › lam_destructure_5 ) ) ) - (local.set $7 + (local.set $5 (tuple.extract 0 (tuple.make (i32.const 0) @@ -205,13 +327,13 @@ functions › lam_destructure_5 ) ) ) - (local.set $11 + (local.set $13 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $2) + (local.get $6) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -221,13 +343,13 @@ functions › lam_destructure_5 ) ) ) - (local.set $12 + (local.set $14 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $2) + (local.get $6) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -241,16 +363,16 @@ functions › lam_destructure_5 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $7 + (local.set $5 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $12) + (local.get $14) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $7) + (local.get $5) ) ) ) @@ -263,16 +385,16 @@ functions › lam_destructure_5 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $6 + (local.set $4 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $11) + (local.get $13) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $6) + (local.get $4) ) ) ) @@ -281,7 +403,7 @@ functions › lam_destructure_5 ) ) ) - (local.set $13 + (local.set $15 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -291,11 +413,11 @@ functions › lam_destructure_5 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $4) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -305,7 +427,7 @@ functions › lam_destructure_5 ) ) ) - (local.set $14 + (local.set $16 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -315,11 +437,11 @@ functions › lam_destructure_5 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $13) + (local.get $15) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $5) + (local.get $3) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -329,7 +451,7 @@ functions › lam_destructure_5 ) ) ) - (local.set $15 + (local.set $17 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -339,11 +461,11 @@ functions › lam_destructure_5 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $14) + (local.get $16) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $6) + (local.get $4) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -353,7 +475,7 @@ functions › lam_destructure_5 ) ) ) - (local.set $16 + (local.set $19 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -363,11 +485,11 @@ functions › lam_destructure_5 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $15) + (local.get $17) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $7) + (local.get $5) ) ) (i32.const 0) @@ -377,241 +499,121 @@ functions › lam_destructure_5 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $18) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $0) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $6) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $1) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $2) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $5) + (local.get $3) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $8) + (local.get $10) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $9) + (local.get $11) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $10) + (local.get $12) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $6) + (local.get $4) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $7) + (local.get $5) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $11) + (local.get $13) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $12) + (local.get $14) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $13) + (local.get $15) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $14) + (local.get $16) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $15) - ) - ) - (local.get $16) - ) - (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) + (local.get $17) ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=8 - (local.get $0) - (global.get $wimport__grainEnv_relocBase) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 0) - ) - (local.set $1 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 20) - ) - ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 5) - ) - (i32.store offset=16 - (local.get $0) - (i32.const 7) - ) - (local.set $2 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 9) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 11) ) (local.set $0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (local.set $3 - (call $lam_lambda_1136 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) - ) + (local.get $19) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $7) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $8) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $9) ) ) - (local.get $3) + (local.get $0) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.28e0f2b3.0.snapshot b/compiler/test/__snapshots__/functions.28e0f2b3.0.snapshot index 09899d902b..f1ee7df895 100644 --- a/compiler/test/__snapshots__/functions.28e0f2b3.0.snapshot +++ b/compiler/test/__snapshots__/functions.28e0f2b3.0.snapshot @@ -4,7 +4,6 @@ functions › lambda_pat_any (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -13,30 +12,15 @@ functions › lambda_pat_any (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $x_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $x_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (i32.const 11) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) (local $1 i32) + (local $2 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -52,7 +36,7 @@ functions › lambda_pat_any ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -98,17 +82,32 @@ functions › lambda_pat_any ) ) (local.set $1 - (call $x_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_0) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_0) ) ) + (local.set $2 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $0) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $1) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $2) + ) + ) + (local.set $1 + (i32.const 11) + ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) diff --git a/compiler/test/__snapshots__/functions.49ccab54.0.snapshot b/compiler/test/__snapshots__/functions.49ccab54.0.snapshot index 1cfb1a2f5f..29a247f855 100644 --- a/compiler/test/__snapshots__/functions.49ccab54.0.snapshot +++ b/compiler/test/__snapshots__/functions.49ccab54.0.snapshot @@ -16,67 +16,12 @@ functions › curried_func (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 2)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $add_1131 $func_1141) + (global $global_2 i32 (i32.const 1)) + (elem $elem (global.get $wimport__grainEnv_relocBase) $func_1141) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $add_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (i32.store - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 20) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $2) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $2) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 1) - ) - ) - (i32.store offset=12 - (local.get $2) - (i32.const 1) - ) - (i32.store offset=16 - (local.get $2) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - ) - (local.set $2 - (tuple.extract 0 - (tuple.make - (local.get $2) - (local.get $2) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (local.get $2) - ) (func $func_1141 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local.set $2 @@ -134,7 +79,7 @@ functions › curried_func ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -151,15 +96,60 @@ functions › curried_func ) ) ) + (local.set $1 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_0) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 20) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (global.get $wimport__grainEnv_relocBase) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 1) + ) + (i32.store offset=16 + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 5) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $1) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 5) + ) + ) (local.set $0 (tuple.extract 0 (tuple.make - (call $add_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_0) + (tuple.extract 0 + (tuple.make + (local.get $0) + (local.get $0) ) - (i32.const 5) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) diff --git a/compiler/test/__snapshots__/functions.6eacded0.0.snapshot b/compiler/test/__snapshots__/functions.6eacded0.0.snapshot index 846c63ddb2..4329880c07 100644 --- a/compiler/test/__snapshots__/functions.6eacded0.0.snapshot +++ b/compiler/test/__snapshots__/functions.6eacded0.0.snapshot @@ -22,69 +22,14 @@ functions › func_recursive_closure (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) (global $global_1 (mut i32) (i32.const 0)) (global $global_0 (mut i32) (i32.const 0)) - (global $global_3 i32 (i32.const 5)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $makeAdder_1131 $truc_1134 $func_1165 $foo_1135 $bar_1138) + (global $global_3 i32 (i32.const 1)) + (elem $elem (global.get $wimport__grainEnv_relocBase) $func_1165) (export \"memory\" (memory $0)) (export \"truc\" (func $truc_1134)) (export \"GRAIN$EXPORT$truc\" (global $global_1)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_3)) - (func $makeAdder_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (i32.store - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 20) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $2) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $2) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 2) - ) - ) - (i32.store offset=12 - (local.get $2) - (i32.const 1) - ) - (i32.store offset=16 - (local.get $2) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - ) - (local.set $2 - (tuple.extract 0 - (tuple.make - (local.get $2) - (local.get $2) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (local.get $2) - ) (func $truc_1134 (; has Stack IR ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) @@ -103,10 +48,7 @@ functions › func_recursive_closure ) (i32.store offset=8 (local.get $1) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 3) - ) + (i32.const -1) ) (i32.store offset=12 (local.get $1) @@ -195,15 +137,63 @@ functions › func_recursive_closure (local $3 i32) (local $4 i32) (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) (local.set $3 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_0) + ) + ) + (i32.store + (local.tee $2 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 20) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $2) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $2) + (global.get $wimport__grainEnv_relocBase) + ) + (i32.store offset=12 + (local.get $2) + (i32.const 1) + ) + (i32.store offset=16 + (local.get $2) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 3) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $3) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 3) + ) + ) + (local.set $5 (tuple.extract 0 (tuple.make - (call $makeAdder_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_0) + (tuple.extract 0 + (tuple.make + (local.get $2) + (local.get $2) ) - (i32.const 3) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -227,10 +217,7 @@ functions › func_recursive_closure ) (i32.store offset=8 (local.get $2) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 4) - ) + (i32.const -1) ) (i32.store offset=12 (local.get $2) @@ -257,10 +244,10 @@ functions › func_recursive_closure (local.get $2) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) + (local.get $5) ) ) - (local.set $5 + (local.set $3 (tuple.extract 0 (tuple.make (if (result i32) @@ -294,15 +281,105 @@ functions › func_recursive_closure ) (i32.const 31) ) - (call $bar_1138 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (block (result i32) + (local.set $3 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $2) + ) ) - (i32.const 3) + (local.set $6 + (tuple.extract 0 + (tuple.make + (call $foo_1135 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.load offset=16 + (local.get $3) + ) + ) + (i32.const 1) + ) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (local.set $7 + (tuple.extract 0 + (tuple.make + (call_indirect (type $i32_i32_=>_i32) + (local.tee $4 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.load offset=20 + (local.get $3) + ) + ) + ) + (i32.const 3) + (i32.load offset=8 + (local.get $4) + ) + ) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (local.set $4 + (tuple.extract 0 + (tuple.make + (call $gimport_pervasives_+ + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_+) + ) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $6) + ) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $7) + ) + ) + (local.get $4) + ) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $3) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 3) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $6) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $7) + ) + ) + (local.get $4) ) (block (result i32) - (local.set $4 + (local.set $8 (tuple.extract 0 (tuple.make (call $gimport_pervasives_- @@ -330,7 +407,7 @@ functions › func_recursive_closure ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $4) + (local.get $8) ) ) ) @@ -355,7 +432,7 @@ functions › func_recursive_closure (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $5) ) ) (drop @@ -367,104 +444,10 @@ functions › func_recursive_closure (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $8) ) ) - (local.get $5) - ) - (func $bar_1138 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local.set $3 - (tuple.extract 0 - (tuple.make - (call $foo_1135 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (i32.load offset=16 - (local.get $0) - ) - ) - (i32.const 1) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (local.set $4 - (tuple.extract 0 - (tuple.make - (call_indirect (type $i32_i32_=>_i32) - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (i32.load offset=20 - (local.get $0) - ) - ) - ) - (i32.const 3) - (i32.load offset=8 - (local.get $2) - ) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (local.set $2 - (tuple.extract 0 - (tuple.make - (call $gimport_pervasives_+ - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_+) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $4) - ) - ) - (local.get $2) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) - ) - ) - (local.get $2) + (local.get $3) ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) @@ -483,7 +466,7 @@ functions › func_recursive_closure ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -515,10 +498,7 @@ functions › func_recursive_closure ) (i32.store offset=8 (local.get $0) - (i32.add - (global.get $wimport__grainEnv_relocBase) - (i32.const 1) - ) + (i32.const -1) ) (i32.store offset=12 (local.get $0) diff --git a/compiler/test/__snapshots__/functions.7a8986a5.0.snapshot b/compiler/test/__snapshots__/functions.7a8986a5.0.snapshot index 95a2fe53f2..305789b4b9 100644 --- a/compiler/test/__snapshots__/functions.7a8986a5.0.snapshot +++ b/compiler/test/__snapshots__/functions.7a8986a5.0.snapshot @@ -4,7 +4,6 @@ functions › app_1 (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -12,42 +11,15 @@ functions › app_1 (import \"GRAIN$MODULE$runtime/gc\" \"malloc\" (func $wimport_GRAIN$MODULE$runtime/gc_malloc (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) - (global $global_1 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $lam_lambda_1132) + (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) - (func $lam_lambda_1132 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local.set $2 - (tuple.extract 0 - (tuple.make - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (i32.const 0) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (local.get $2) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) (local $1 i32) + (local $2 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -63,7 +35,7 @@ functions › app_1 ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -81,14 +53,37 @@ functions › app_1 ) ) (local.set $1 - (call $lam_lambda_1132 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $0) + ) + ) + (local.set $2 + (tuple.extract 0 + (tuple.make + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 3) + ) + (i32.const 0) ) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $1) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (i32.const 3) ) ) + (local.set $1 + (local.get $2) + ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) diff --git a/compiler/test/__snapshots__/functions.84b6e84b.0.snapshot b/compiler/test/__snapshots__/functions.84b6e84b.0.snapshot index 64ee57f026..5fae7795db 100644 --- a/compiler/test/__snapshots__/functions.84b6e84b.0.snapshot +++ b/compiler/test/__snapshots__/functions.84b6e84b.0.snapshot @@ -4,7 +4,6 @@ functions › shorthand_3 (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -13,41 +12,14 @@ functions › shorthand_3 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local.set $2 - (tuple.extract 0 - (tuple.make - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (i32.const 0) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (local.get $2) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) + (local $1 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -63,7 +35,7 @@ functions › shorthand_3 ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -80,13 +52,36 @@ functions › shorthand_3 ) ) ) - (call $foo_1131 + (local.set $0 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) - (i32.const 3) ) + (local.set $1 + (tuple.extract 0 + (tuple.make + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 3) + ) + (i32.const 0) + ) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $0) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 3) + ) + ) + (local.get $1) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.8baf471f.0.snapshot b/compiler/test/__snapshots__/functions.8baf471f.0.snapshot index 7381537d7c..d5b051be48 100644 --- a/compiler/test/__snapshots__/functions.8baf471f.0.snapshot +++ b/compiler/test/__snapshots__/functions.8baf471f.0.snapshot @@ -5,7 +5,6 @@ functions › lam_destructure_3 (type $none_=>_none (func)) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -15,13 +14,14 @@ functions › lam_destructure_3 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) - (global $global_1 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $lam_lambda_1134) + (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) - (func $lam_lambda_1134 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $_gmain (; has Stack IR ;) (result i32) + (local $0 i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -30,7 +30,89 @@ functions › lam_destructure_3 (local $7 i32) (local $8 i32) (local $9 i32) - (local.set $2 + (local $10 i32) + (local $11 i32) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (i32.const -1) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 0) + ) + (local.set $4 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 20) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 5) + ) + (i32.store offset=16 + (local.get $0) + (i32.const 7) + ) + (local.set $5 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (local.set $10 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $4) + ) + ) + (local.set $0 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $5) + ) + ) + (local.set $1 (tuple.extract 0 (tuple.make (i32.const 0) @@ -41,7 +123,7 @@ functions › lam_destructure_3 ) ) ) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make (i32.const 0) @@ -52,7 +134,7 @@ functions › lam_destructure_3 ) ) ) - (local.set $4 + (local.set $3 (tuple.extract 0 (tuple.make (i32.const 0) @@ -63,13 +145,13 @@ functions › lam_destructure_3 ) ) ) - (local.set $5 + (local.set $6 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -79,13 +161,13 @@ functions › lam_destructure_3 ) ) ) - (local.set $6 + (local.set $7 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -95,13 +177,13 @@ functions › lam_destructure_3 ) ) ) - (local.set $7 + (local.set $8 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=16 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -115,16 +197,16 @@ functions › lam_destructure_3 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $4 + (local.set $3 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $7) + (local.get $8) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $3) ) ) ) @@ -137,16 +219,16 @@ functions › lam_destructure_3 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $6) + (local.get $7) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $2) ) ) ) @@ -159,16 +241,16 @@ functions › lam_destructure_3 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $5) + (local.get $6) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) ) @@ -177,7 +259,7 @@ functions › lam_destructure_3 ) ) ) - (local.set $8 + (local.set $9 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -187,11 +269,11 @@ functions › lam_destructure_3 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -201,7 +283,7 @@ functions › lam_destructure_3 ) ) ) - (local.set $9 + (local.set $11 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -211,11 +293,11 @@ functions › lam_destructure_3 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $8) + (local.get $9) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $4) + (local.get $3) ) ) (i32.const 0) @@ -225,37 +307,31 @@ functions › lam_destructure_3 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $10) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $0) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $1) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $2) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $5) + (local.get $3) ) ) (drop @@ -276,105 +352,28 @@ functions › lam_destructure_3 (local.get $8) ) ) - (local.get $9) - ) - (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (local $1 i32) - (local $2 i32) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $0) - (global.get $wimport__grainEnv_relocBase) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 0) - ) - (local.set $1 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 20) - ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $9) ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 5) - ) - (i32.store offset=16 - (local.get $0) - (i32.const 7) ) (local.set $0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (local.set $2 - (call $lam_lambda_1134 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) - ) + (local.get $11) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $4) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $5) ) ) - (local.get $2) + (local.get $0) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.9223245d.0.snapshot b/compiler/test/__snapshots__/functions.9223245d.0.snapshot index ce2d6f7018..2c944fbe12 100644 --- a/compiler/test/__snapshots__/functions.9223245d.0.snapshot +++ b/compiler/test/__snapshots__/functions.9223245d.0.snapshot @@ -5,7 +5,6 @@ functions › lam_destructure_7 (type $none_=>_none (func)) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -15,13 +14,14 @@ functions › lam_destructure_7 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) - (global $global_1 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $lam_lambda_1135) + (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) - (func $lam_lambda_1135 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $_gmain (; has Stack IR ;) (result i32) + (local $0 i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -34,7 +34,125 @@ functions › lam_destructure_7 (local $11 i32) (local $12 i32) (local $13 i32) - (local.set $2 + (local $14 i32) + (local $15 i32) + (local $16 i32) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (i32.const -1) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 0) + ) + (local.set $6 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 7) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 9) + ) + (local.set $7 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 20) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 5) + ) + (i32.store offset=16 + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $7) + ) + ) + (local.set $8 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (local.set $15 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $6) + ) + ) + (local.set $0 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $8) + ) + ) + (local.set $1 (tuple.extract 0 (tuple.make (i32.const 0) @@ -45,7 +163,7 @@ functions › lam_destructure_7 ) ) ) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make (i32.const 0) @@ -56,7 +174,7 @@ functions › lam_destructure_7 ) ) ) - (local.set $4 + (local.set $3 (tuple.extract 0 (tuple.make (i32.const 0) @@ -67,7 +185,7 @@ functions › lam_destructure_7 ) ) ) - (local.set $5 + (local.set $4 (tuple.extract 0 (tuple.make (i32.const 0) @@ -78,13 +196,13 @@ functions › lam_destructure_7 ) ) ) - (local.set $7 + (local.set $9 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -94,13 +212,13 @@ functions › lam_destructure_7 ) ) ) - (local.set $8 + (local.set $10 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -110,13 +228,13 @@ functions › lam_destructure_7 ) ) ) - (local.set $6 + (local.set $5 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=16 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -126,13 +244,13 @@ functions › lam_destructure_7 ) ) ) - (local.set $9 + (local.set $11 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $6) + (local.get $5) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -142,13 +260,13 @@ functions › lam_destructure_7 ) ) ) - (local.set $10 + (local.set $12 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $6) + (local.get $5) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -162,16 +280,16 @@ functions › lam_destructure_7 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $7) + (local.get $9) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) ) @@ -184,16 +302,16 @@ functions › lam_destructure_7 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $8) + (local.get $10) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $2) ) ) ) @@ -206,16 +324,16 @@ functions › lam_destructure_7 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $5 + (local.set $4 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $10) + (local.get $12) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $5) + (local.get $4) ) ) ) @@ -228,16 +346,16 @@ functions › lam_destructure_7 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $4 + (local.set $3 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $9) + (local.get $11) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $3) ) ) ) @@ -246,7 +364,7 @@ functions › lam_destructure_7 ) ) ) - (local.set $11 + (local.set $13 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -256,11 +374,11 @@ functions › lam_destructure_7 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -270,7 +388,7 @@ functions › lam_destructure_7 ) ) ) - (local.set $12 + (local.set $14 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -280,11 +398,11 @@ functions › lam_destructure_7 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $11) + (local.get $13) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $4) + (local.get $3) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -294,7 +412,7 @@ functions › lam_destructure_7 ) ) ) - (local.set $13 + (local.set $16 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -304,11 +422,11 @@ functions › lam_destructure_7 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $12) + (local.get $14) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $5) + (local.get $4) ) ) (i32.const 0) @@ -318,222 +436,103 @@ functions › lam_destructure_7 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $15) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $0) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $2) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $3) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $5) + (local.get $4) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $7) + (local.get $9) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $8) + (local.get $10) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $6) + (local.get $5) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $9) + (local.get $11) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $10) + (local.get $12) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $11) + (local.get $13) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $12) - ) - ) - (local.get $13) - ) - (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $0) - (global.get $wimport__grainEnv_relocBase) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 0) - ) - (local.set $1 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 7) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 9) - ) - (local.set $2 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 20) - ) - ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 5) - ) - (i32.store offset=16 - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $14) ) ) (local.set $0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (local.set $3 - (call $lam_lambda_1135 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) - ) + (local.get $16) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $6) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $7) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $8) ) ) - (local.get $3) + (local.get $0) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.9fd69835.0.snapshot b/compiler/test/__snapshots__/functions.9fd69835.0.snapshot index 6973e2245d..501d47f45d 100644 --- a/compiler/test/__snapshots__/functions.9fd69835.0.snapshot +++ b/compiler/test/__snapshots__/functions.9fd69835.0.snapshot @@ -5,7 +5,6 @@ functions › shorthand_2 (type $none_=>_none (func)) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -16,48 +15,14 @@ functions › shorthand_2 (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local.set $2 - (tuple.extract 0 - (tuple.make - (call $gimport_pervasives_+ - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_+) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (i32.const 7) - ) - (i32.const 0) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (local.get $2) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) + (local $1 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -73,7 +38,7 @@ functions › shorthand_2 ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -90,13 +55,43 @@ functions › shorthand_2 ) ) ) - (call $foo_1131 + (local.set $0 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) - (i32.const 3) ) + (local.set $1 + (tuple.extract 0 + (tuple.make + (call $gimport_pervasives_+ + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_+) + ) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 3) + ) + (i32.const 7) + ) + (i32.const 0) + ) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $0) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 3) + ) + ) + (local.get $1) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.b37949b2.0.snapshot b/compiler/test/__snapshots__/functions.b37949b2.0.snapshot index c6441415a4..5642703938 100644 --- a/compiler/test/__snapshots__/functions.b37949b2.0.snapshot +++ b/compiler/test/__snapshots__/functions.b37949b2.0.snapshot @@ -5,7 +5,6 @@ functions › lam_destructure_4 (type $none_=>_none (func)) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -16,13 +15,14 @@ functions › lam_destructure_4 (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $_gmain (; has Stack IR ;) (result i32) + (local $0 i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -31,7 +31,88 @@ functions › lam_destructure_4 (local $7 i32) (local $8 i32) (local $9 i32) - (local.set $2 + (local $10 i32) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (i32.const -1) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 0) + ) + (global.set $global_0 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (global.get $global_0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 20) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 5) + ) + (i32.store offset=16 + (local.get $0) + (i32.const 7) + ) + (local.set $4 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (local.set $9 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_0) + ) + ) + (local.set $0 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $4) + ) + ) + (local.set $1 (tuple.extract 0 (tuple.make (i32.const 0) @@ -42,7 +123,7 @@ functions › lam_destructure_4 ) ) ) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make (i32.const 0) @@ -53,7 +134,7 @@ functions › lam_destructure_4 ) ) ) - (local.set $4 + (local.set $3 (tuple.extract 0 (tuple.make (i32.const 0) @@ -70,7 +151,7 @@ functions › lam_destructure_4 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -86,7 +167,7 @@ functions › lam_destructure_4 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -102,7 +183,7 @@ functions › lam_destructure_4 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=16 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -116,7 +197,7 @@ functions › lam_destructure_4 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $4 + (local.set $3 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef @@ -125,7 +206,7 @@ functions › lam_destructure_4 ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $3) ) ) ) @@ -138,7 +219,7 @@ functions › lam_destructure_4 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef @@ -147,7 +228,7 @@ functions › lam_destructure_4 ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $2) ) ) ) @@ -160,7 +241,7 @@ functions › lam_destructure_4 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef @@ -169,7 +250,7 @@ functions › lam_destructure_4 ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) ) @@ -188,11 +269,11 @@ functions › lam_destructure_4 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -202,7 +283,7 @@ functions › lam_destructure_4 ) ) ) - (local.set $9 + (local.set $10 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -216,7 +297,7 @@ functions › lam_destructure_4 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $4) + (local.get $3) ) ) (i32.const 0) @@ -226,31 +307,31 @@ functions › lam_destructure_4 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $9) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $0) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $2) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $3) ) ) (drop @@ -277,98 +358,16 @@ functions › lam_destructure_4 (local.get $8) ) ) - (local.get $9) - ) - (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (local $1 i32) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $0) - (global.get $wimport__grainEnv_relocBase) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 0) - ) - (global.set $global_0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (global.get $global_0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 20) - ) - ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 5) - ) - (i32.store offset=16 - (local.get $0) - (i32.const 7) - ) (local.set $0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (local.set $1 - (call $foo_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_0) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) - ) + (local.get $10) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $4) ) ) - (local.get $1) + (local.get $0) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.b3a8d88b.0.snapshot b/compiler/test/__snapshots__/functions.b3a8d88b.0.snapshot index 08d19e6cc1..c2b9c768f4 100644 --- a/compiler/test/__snapshots__/functions.b3a8d88b.0.snapshot +++ b/compiler/test/__snapshots__/functions.b3a8d88b.0.snapshot @@ -5,7 +5,6 @@ functions › lam_destructure_8 (type $none_=>_none (func)) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -16,13 +15,14 @@ functions › lam_destructure_8 (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $_gmain (; has Stack IR ;) (result i32) + (local $0 i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -35,7 +35,124 @@ functions › lam_destructure_8 (local $11 i32) (local $12 i32) (local $13 i32) - (local.set $2 + (local $14 i32) + (local $15 i32) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (i32.const -1) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 0) + ) + (global.set $global_0 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (global.get $global_0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 7) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 9) + ) + (local.set $6 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 20) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 5) + ) + (i32.store offset=16 + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $6) + ) + ) + (local.set $7 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (local.set $14 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_0) + ) + ) + (local.set $0 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $7) + ) + ) + (local.set $1 (tuple.extract 0 (tuple.make (i32.const 0) @@ -46,7 +163,7 @@ functions › lam_destructure_8 ) ) ) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make (i32.const 0) @@ -57,7 +174,7 @@ functions › lam_destructure_8 ) ) ) - (local.set $4 + (local.set $3 (tuple.extract 0 (tuple.make (i32.const 0) @@ -68,7 +185,7 @@ functions › lam_destructure_8 ) ) ) - (local.set $5 + (local.set $4 (tuple.extract 0 (tuple.make (i32.const 0) @@ -79,13 +196,13 @@ functions › lam_destructure_8 ) ) ) - (local.set $7 + (local.set $8 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -95,13 +212,13 @@ functions › lam_destructure_8 ) ) ) - (local.set $8 + (local.set $9 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -111,13 +228,13 @@ functions › lam_destructure_8 ) ) ) - (local.set $6 + (local.set $5 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=16 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -127,13 +244,13 @@ functions › lam_destructure_8 ) ) ) - (local.set $9 + (local.set $10 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $6) + (local.get $5) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -143,13 +260,13 @@ functions › lam_destructure_8 ) ) ) - (local.set $10 + (local.set $11 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $6) + (local.get $5) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -163,16 +280,16 @@ functions › lam_destructure_8 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $7) + (local.get $8) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) ) @@ -185,16 +302,16 @@ functions › lam_destructure_8 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $3 + (local.set $2 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $8) + (local.get $9) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $2) ) ) ) @@ -207,16 +324,16 @@ functions › lam_destructure_8 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $5 + (local.set $4 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $10) + (local.get $11) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $5) + (local.get $4) ) ) ) @@ -229,16 +346,16 @@ functions › lam_destructure_8 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $4 + (local.set $3 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $9) + (local.get $10) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $3) ) ) ) @@ -247,7 +364,7 @@ functions › lam_destructure_8 ) ) ) - (local.set $11 + (local.set $12 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -257,11 +374,11 @@ functions › lam_destructure_8 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -271,7 +388,7 @@ functions › lam_destructure_8 ) ) ) - (local.set $12 + (local.set $13 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -281,11 +398,11 @@ functions › lam_destructure_8 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $11) + (local.get $12) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $4) + (local.get $3) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -295,7 +412,7 @@ functions › lam_destructure_8 ) ) ) - (local.set $13 + (local.set $15 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -305,11 +422,11 @@ functions › lam_destructure_8 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $12) + (local.get $13) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $5) + (local.get $4) ) ) (i32.const 0) @@ -319,43 +436,37 @@ functions › lam_destructure_8 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $14) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $0) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $1) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $2) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $5) + (local.get $3) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $7) + (local.get $4) ) ) (drop @@ -367,13 +478,13 @@ functions › lam_destructure_8 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $6) + (local.get $9) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $9) + (local.get $5) ) ) (drop @@ -394,140 +505,28 @@ functions › lam_destructure_8 (local.get $12) ) ) - (local.get $13) - ) - (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (local $1 i32) - (local $2 i32) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $0) - (global.get $wimport__grainEnv_relocBase) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 0) - ) - (global.set $global_0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (global.get $global_0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 7) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 9) - ) - (local.set $1 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 20) - ) - ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 5) - ) - (i32.store offset=16 - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $13) ) ) (local.set $0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (local.set $2 - (call $foo_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_0) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) - ) + (local.get $15) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $6) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $7) ) ) - (local.get $2) + (local.get $0) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.b632a2ab.0.snapshot b/compiler/test/__snapshots__/functions.b632a2ab.0.snapshot index f3732fb2f7..ec6d0226a4 100644 --- a/compiler/test/__snapshots__/functions.b632a2ab.0.snapshot +++ b/compiler/test/__snapshots__/functions.b632a2ab.0.snapshot @@ -4,7 +4,6 @@ functions › lam_destructure_1 (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -12,31 +11,16 @@ functions › lam_destructure_1 (import \"GRAIN$MODULE$runtime/gc\" \"malloc\" (func $wimport_GRAIN$MODULE$runtime/gc_malloc (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) - (global $global_1 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $lam_lambda_1131) + (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) - (func $lam_lambda_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (i32.const 11) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) + (local $3 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -52,13 +36,13 @@ functions › lam_destructure_1 ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) (i32.const 0) ) - (local.set $1 + (local.set $2 (tuple.extract 0 (tuple.make (local.get $0) @@ -97,16 +81,16 @@ functions › lam_destructure_1 ) ) ) - (local.set $2 - (call $lam_lambda_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) + (local.set $1 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $2) + ) + ) + (local.set $3 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $0) ) ) (drop @@ -115,13 +99,28 @@ functions › lam_destructure_1 (local.get $1) ) ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $3) + ) + ) + (local.set $1 + (i32.const 11) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $2) + ) + ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (local.get $0) ) ) - (local.get $2) + (local.get $1) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.c6e8a9aa.0.snapshot b/compiler/test/__snapshots__/functions.c6e8a9aa.0.snapshot index cd1bb1d970..8249cf4ad7 100644 --- a/compiler/test/__snapshots__/functions.c6e8a9aa.0.snapshot +++ b/compiler/test/__snapshots__/functions.c6e8a9aa.0.snapshot @@ -4,7 +4,6 @@ functions › lam_destructure_2 (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -13,30 +12,15 @@ functions › lam_destructure_2 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (i32.const 11) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) (local $1 i32) + (local $2 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -52,7 +36,7 @@ functions › lam_destructure_2 ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -98,17 +82,32 @@ functions › lam_destructure_2 ) ) (local.set $1 - (call $foo_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_0) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_0) ) ) + (local.set $2 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $0) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $1) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $2) + ) + ) + (local.set $1 + (i32.const 11) + ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) diff --git a/compiler/test/__snapshots__/functions.e6c6212b.0.snapshot b/compiler/test/__snapshots__/functions.e6c6212b.0.snapshot index b0c75942d7..3ee6d05332 100644 --- a/compiler/test/__snapshots__/functions.e6c6212b.0.snapshot +++ b/compiler/test/__snapshots__/functions.e6c6212b.0.snapshot @@ -1,11 +1,10 @@ functions › fn_trailing_comma (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -16,57 +15,14 @@ functions › fn_trailing_comma (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $testFn_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $testFn_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - (local.set $3 - (tuple.extract 0 - (tuple.make - (call $gimport_pervasives_+ - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_+) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) - ) - ) - (i32.const 0) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) - ) - ) - (local.get $3) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) + (local $1 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -82,7 +38,7 @@ functions › fn_trailing_comma ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -99,14 +55,52 @@ functions › fn_trailing_comma ) ) ) - (call $testFn_1131 + (local.set $0 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) - (i32.const 5) - (i32.const 7) ) + (local.set $1 + (tuple.extract 0 + (tuple.make + (call $gimport_pervasives_+ + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_+) + ) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 5) + ) + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 7) + ) + ) + (i32.const 0) + ) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $0) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 5) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 7) + ) + ) + (local.get $1) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/functions.f400bb7b.0.snapshot b/compiler/test/__snapshots__/functions.f400bb7b.0.snapshot index 7e3b87332b..74d30e81ed 100644 --- a/compiler/test/__snapshots__/functions.f400bb7b.0.snapshot +++ b/compiler/test/__snapshots__/functions.f400bb7b.0.snapshot @@ -1,11 +1,10 @@ functions › lam_destructure_6 (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -16,13 +15,15 @@ functions › lam_destructure_6 (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $foo_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $foo_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $_gmain (; has Stack IR ;) (result i32) + (local $0 i32) + (local $1 i32) + (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -37,7 +38,127 @@ functions › lam_destructure_6 (local $14 i32) (local $15 i32) (local $16 i32) - (local.set $3 + (local $17 i32) + (local $18 i32) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 6) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=8 + (local.get $0) + (i32.const -1) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 0) + ) + (global.set $global_0 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (global.get $global_0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 20) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 3) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 5) + ) + (i32.store offset=16 + (local.get $0) + (i32.const 7) + ) + (local.set $7 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (i32.store + (local.tee $0 + (call $wimport_GRAIN$MODULE$runtime/gc_malloc + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) + (i32.const 16) + ) + ) + (i32.const 7) + ) + (i32.store offset=4 + (local.get $0) + (i32.const 2) + ) + (i32.store offset=8 + (local.get $0) + (i32.const 9) + ) + (i32.store offset=12 + (local.get $0) + (i32.const 11) + ) + (local.set $8 + (tuple.extract 0 + (tuple.make + (local.get $0) + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 0) + ) + ) + ) + ) + (local.set $17 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $global_0) + ) + ) + (local.set $0 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $7) + ) + ) + (local.set $6 + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (local.get $8) + ) + ) + (local.set $1 (tuple.extract 0 (tuple.make (i32.const 0) @@ -48,7 +169,7 @@ functions › lam_destructure_6 ) ) ) - (local.set $4 + (local.set $2 (tuple.extract 0 (tuple.make (i32.const 0) @@ -59,7 +180,7 @@ functions › lam_destructure_6 ) ) ) - (local.set $5 + (local.set $3 (tuple.extract 0 (tuple.make (i32.const 0) @@ -70,13 +191,13 @@ functions › lam_destructure_6 ) ) ) - (local.set $8 + (local.set $9 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -86,13 +207,13 @@ functions › lam_destructure_6 ) ) ) - (local.set $9 + (local.set $10 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -102,13 +223,13 @@ functions › lam_destructure_6 ) ) ) - (local.set $10 + (local.set $11 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=16 - (local.get $1) + (local.get $0) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -122,16 +243,16 @@ functions › lam_destructure_6 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $5 + (local.set $3 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $10) + (local.get $11) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $5) + (local.get $3) ) ) ) @@ -144,16 +265,16 @@ functions › lam_destructure_6 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $4 + (local.set $2 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $9) + (local.get $10) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $2) ) ) ) @@ -166,16 +287,16 @@ functions › lam_destructure_6 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $3 + (local.set $1 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $8) + (local.get $9) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $1) ) ) ) @@ -184,7 +305,7 @@ functions › lam_destructure_6 ) ) ) - (local.set $6 + (local.set $4 (tuple.extract 0 (tuple.make (i32.const 0) @@ -195,7 +316,7 @@ functions › lam_destructure_6 ) ) ) - (local.set $7 + (local.set $5 (tuple.extract 0 (tuple.make (i32.const 0) @@ -206,13 +327,13 @@ functions › lam_destructure_6 ) ) ) - (local.set $11 + (local.set $12 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=8 - (local.get $2) + (local.get $6) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -222,13 +343,13 @@ functions › lam_destructure_6 ) ) ) - (local.set $12 + (local.set $13 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=12 - (local.get $2) + (local.get $6) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -242,16 +363,16 @@ functions › lam_destructure_6 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $7 + (local.set $5 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $12) + (local.get $13) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $7) + (local.get $5) ) ) ) @@ -264,16 +385,16 @@ functions › lam_destructure_6 (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) (block (result i32) - (local.set $6 + (local.set $4 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $11) + (local.get $12) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $6) + (local.get $4) ) ) ) @@ -282,7 +403,7 @@ functions › lam_destructure_6 ) ) ) - (local.set $13 + (local.set $14 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -292,11 +413,11 @@ functions › lam_destructure_6 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $3) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $4) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -306,7 +427,7 @@ functions › lam_destructure_6 ) ) ) - (local.set $14 + (local.set $15 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -316,11 +437,11 @@ functions › lam_destructure_6 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $13) + (local.get $14) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $5) + (local.get $3) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -330,7 +451,7 @@ functions › lam_destructure_6 ) ) ) - (local.set $15 + (local.set $16 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -340,11 +461,11 @@ functions › lam_destructure_6 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $14) + (local.get $15) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $6) + (local.get $4) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -354,7 +475,7 @@ functions › lam_destructure_6 ) ) ) - (local.set $16 + (local.set $18 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -364,11 +485,11 @@ functions › lam_destructure_6 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $15) + (local.get $16) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $7) + (local.get $5) ) ) (i32.const 0) @@ -378,43 +499,37 @@ functions › lam_destructure_6 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $17) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $0) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $3) + (local.get $6) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $4) + (local.get $1) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $5) + (local.get $2) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $8) + (local.get $3) ) ) (drop @@ -432,19 +547,19 @@ functions › lam_destructure_6 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $6) + (local.get $11) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $7) + (local.get $4) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $11) + (local.get $5) ) ) (drop @@ -471,141 +586,28 @@ functions › lam_destructure_6 (local.get $15) ) ) - (local.get $16) - ) - (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (local $1 i32) - (local $2 i32) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) - ) - (i32.const 6) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=8 - (local.get $0) - (global.get $wimport__grainEnv_relocBase) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 0) - ) - (global.set $global_0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (global.get $global_0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 20) - ) - ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 3) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 5) - ) - (i32.store offset=16 - (local.get $0) - (i32.const 7) - ) - (local.set $1 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (i32.store - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_malloc - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc) - (i32.const 16) - ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $16) ) - (i32.const 7) - ) - (i32.store offset=4 - (local.get $0) - (i32.const 2) - ) - (i32.store offset=8 - (local.get $0) - (i32.const 9) - ) - (i32.store offset=12 - (local.get $0) - (i32.const 11) ) (local.set $0 - (tuple.extract 0 - (tuple.make - (local.get $0) - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (i32.const 0) - ) - ) - ) - ) - (local.set $2 - (call $foo_1131 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $global_0) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) - ) + (local.get $18) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $7) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $8) ) ) - (local.get $2) + (local.get $0) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/imports.0706ac31.0.snapshot b/compiler/test/__snapshots__/imports.0706ac31.0.snapshot index 9f71d22f2a..2f727b83b4 100644 --- a/compiler/test/__snapshots__/imports.0706ac31.0.snapshot +++ b/compiler/test/__snapshots__/imports.0706ac31.0.snapshot @@ -1,38 +1,32 @@ imports › import_all_constructor (module (type $none_=>_i32 (func (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_none (func)) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Empty\" (global $gimport_tlists_Empty (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Cons\" (global $gimport_tlists_Cons (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$tlists\" \"Cons\" (func $gimport_tlists_Cons (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_tlists_Cons) - ) + (call $gimport_tlists_Cons + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_tlists_Cons) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_tlists_Empty) ) - (i32.load offset=8 - (local.get $0) - ) ) ) (func $_start (; has Stack IR ;) diff --git a/compiler/test/__snapshots__/imports.2f957040.0.snapshot b/compiler/test/__snapshots__/imports.2f957040.0.snapshot index 74c30225a5..bae884886e 100644 --- a/compiler/test/__snapshots__/imports.2f957040.0.snapshot +++ b/compiler/test/__snapshots__/imports.2f957040.0.snapshot @@ -2,10 +2,9 @@ imports › import_alias_multiple_constructor (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -14,6 +13,7 @@ imports › import_alias_multiple_constructor (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$sum\" (global $gimport_tlists_sum (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$tlists\" \"Cons\" (func $gimport_tlists_Cons (param i32 i32 i32) (result i32))) (import \"GRAIN$MODULE$tlists\" \"sum\" (func $gimport_tlists_sum (param i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) @@ -26,21 +26,16 @@ imports › import_alias_multiple_constructor (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_tlists_Cons) - ) + (call $gimport_tlists_Cons + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_tlists_Cons) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_tlists_Empty) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) diff --git a/compiler/test/__snapshots__/imports.7fc65fd4.0.snapshot b/compiler/test/__snapshots__/imports.7fc65fd4.0.snapshot index bd638724eb..f127c88a74 100644 --- a/compiler/test/__snapshots__/imports.7fc65fd4.0.snapshot +++ b/compiler/test/__snapshots__/imports.7fc65fd4.0.snapshot @@ -1,38 +1,32 @@ imports › import_some_constructor (module (type $none_=>_i32 (func (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_none (func)) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Empty\" (global $gimport_tlists_Empty (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Cons\" (global $gimport_tlists_Cons (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$tlists\" \"Cons\" (func $gimport_tlists_Cons (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_tlists_Cons) - ) + (call $gimport_tlists_Cons + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_tlists_Cons) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_tlists_Empty) ) - (i32.load offset=8 - (local.get $0) - ) ) ) (func $_start (; has Stack IR ;) diff --git a/compiler/test/__snapshots__/imports.a3a21ec1.0.snapshot b/compiler/test/__snapshots__/imports.a3a21ec1.0.snapshot index 51ed83f6a2..e2af87ec36 100644 --- a/compiler/test/__snapshots__/imports.a3a21ec1.0.snapshot +++ b/compiler/test/__snapshots__/imports.a3a21ec1.0.snapshot @@ -1,38 +1,32 @@ imports › import_same_module_unify2 (module (type $none_=>_i32 (func (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_none (func)) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Empty\" (global $gimport_tlists_Empty (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Cons\" (global $gimport_tlists_Cons (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$tlists\" \"Cons\" (func $gimport_tlists_Cons (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_tlists_Cons) - ) + (call $gimport_tlists_Cons + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_tlists_Cons) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_tlists_Empty) ) - (i32.load offset=8 - (local.get $0) - ) ) ) (func $_start (; has Stack IR ;) diff --git a/compiler/test/__snapshots__/imports.c06afb4d.0.snapshot b/compiler/test/__snapshots__/imports.c06afb4d.0.snapshot index 71e103b440..7418774767 100644 --- a/compiler/test/__snapshots__/imports.c06afb4d.0.snapshot +++ b/compiler/test/__snapshots__/imports.c06afb4d.0.snapshot @@ -1,38 +1,32 @@ imports › import_same_module_unify (module (type $none_=>_i32 (func (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_none (func)) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Empty\" (global $gimport_tlists_Empty (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Cons\" (global $gimport_tlists_Cons (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$tlists\" \"Cons\" (func $gimport_tlists_Cons (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_tlists_Cons) - ) + (call $gimport_tlists_Cons + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_tlists_Cons) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_tlists_Empty) ) - (i32.load offset=8 - (local.get $0) - ) ) ) (func $_start (; has Stack IR ;) diff --git a/compiler/test/__snapshots__/imports.f36bd08d.0.snapshot b/compiler/test/__snapshots__/imports.f36bd08d.0.snapshot index 24e08693e9..f3ffd97500 100644 --- a/compiler/test/__snapshots__/imports.f36bd08d.0.snapshot +++ b/compiler/test/__snapshots__/imports.f36bd08d.0.snapshot @@ -1,30 +1,27 @@ imports › import_muliple_modules (module (type $none_=>_i32 (func (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_none (func)) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Empty\" (global $gimport_tlists_Empty (mut i32))) (import \"GRAIN$MODULE$exportStar\" \"GRAIN$EXPORT$x\" (global $gimport_exportStar_x (mut i32))) (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$Cons\" (global $gimport_tlists_Cons (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$tlists\" \"Cons\" (func $gimport_tlists_Cons (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_1)) (func $_gmain (; has Stack IR ;) (result i32) - (local $0 i32) - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_tlists_Cons) - ) + (call $gimport_tlists_Cons + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_tlists_Cons) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -34,9 +31,6 @@ imports › import_muliple_modules (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_tlists_Empty) ) - (i32.load offset=8 - (local.get $0) - ) ) ) (func $_start (; has Stack IR ;) diff --git a/compiler/test/__snapshots__/imports.f4cfe044.0.snapshot b/compiler/test/__snapshots__/imports.f4cfe044.0.snapshot index 4676d2623d..5aab1be55f 100644 --- a/compiler/test/__snapshots__/imports.f4cfe044.0.snapshot +++ b/compiler/test/__snapshots__/imports.f4cfe044.0.snapshot @@ -2,10 +2,9 @@ imports › import_some_mixed (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -14,6 +13,7 @@ imports › import_some_mixed (import \"GRAIN$MODULE$tlists\" \"GRAIN$EXPORT$sum\" (global $gimport_tlists_sum (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$tlists\" \"Cons\" (func $gimport_tlists_Cons (param i32 i32 i32) (result i32))) (import \"GRAIN$MODULE$tlists\" \"sum\" (func $gimport_tlists_sum (param i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) @@ -26,21 +26,16 @@ imports › import_some_mixed (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_tlists_Cons) - ) + (call $gimport_tlists_Cons + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_tlists_Cons) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_tlists_Empty) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) diff --git a/compiler/test/__snapshots__/lists.884ce894.0.snapshot b/compiler/test/__snapshots__/lists.884ce894.0.snapshot index ba8a9b7112..1677492b78 100644 --- a/compiler/test/__snapshots__/lists.884ce894.0.snapshot +++ b/compiler/test/__snapshots__/lists.884ce894.0.snapshot @@ -1,11 +1,10 @@ lists › list_spread (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -13,6 +12,7 @@ lists › list_spread (import \"GRAIN$MODULE$pervasives\" \"GRAIN$EXPORT$[...]\" (global $gimport_pervasives_[...] (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) @@ -23,24 +23,19 @@ lists › list_spread (local $0 i32) (local $1 i32) (local $2 i32) - (local.set $1 + (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 9) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -52,19 +47,14 @@ lists › list_spread (global.set $global_0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 7) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (i32.load offset=8 (local.get $0) ) ) @@ -75,24 +65,19 @@ lists › list_spread ) ) ) - (local.set $0 + (local.set $1 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -102,33 +87,28 @@ lists › list_spread ) ) (local.set $2 - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $0) - ) - (i32.load offset=8 - (local.get $2) + (local.get $1) ) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $0) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $1) ) ) (local.get $2) diff --git a/compiler/test/__snapshots__/lists.d9fd46fb.0.snapshot b/compiler/test/__snapshots__/lists.d9fd46fb.0.snapshot index e786fc041c..f3b0799901 100644 --- a/compiler/test/__snapshots__/lists.d9fd46fb.0.snapshot +++ b/compiler/test/__snapshots__/lists.d9fd46fb.0.snapshot @@ -1,11 +1,10 @@ lists › list1_trailing_space (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -13,6 +12,7 @@ lists › list1_trailing_space (import \"GRAIN$MODULE$pervasives\" \"GRAIN$EXPORT$[...]\" (global $gimport_pervasives_[...] (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -25,21 +25,16 @@ lists › list1_trailing_space (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 7) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -51,21 +46,16 @@ lists › list1_trailing_space (local.set $1 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $0) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -75,21 +65,16 @@ lists › list1_trailing_space ) ) (local.set $2 - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $1) ) - (i32.load offset=8 - (local.get $2) - ) ) ) (drop diff --git a/compiler/test/__snapshots__/lists.e5378351.0.snapshot b/compiler/test/__snapshots__/lists.e5378351.0.snapshot index f3eec36507..d0ca0685fb 100644 --- a/compiler/test/__snapshots__/lists.e5378351.0.snapshot +++ b/compiler/test/__snapshots__/lists.e5378351.0.snapshot @@ -1,11 +1,10 @@ lists › list1_trailing (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -13,6 +12,7 @@ lists › list1_trailing (import \"GRAIN$MODULE$pervasives\" \"GRAIN$EXPORT$[...]\" (global $gimport_pervasives_[...] (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -25,21 +25,16 @@ lists › list1_trailing (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 7) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -51,21 +46,16 @@ lists › list1_trailing (local.set $1 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $0) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -75,21 +65,16 @@ lists › list1_trailing ) ) (local.set $2 - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $1) ) - (i32.load offset=8 - (local.get $2) - ) ) ) (drop diff --git a/compiler/test/__snapshots__/optimizations.d72b00c6.0.snapshot b/compiler/test/__snapshots__/optimizations.d72b00c6.0.snapshot index b53ec96463..8fd85ccc98 100644 --- a/compiler/test/__snapshots__/optimizations.d72b00c6.0.snapshot +++ b/compiler/test/__snapshots__/optimizations.d72b00c6.0.snapshot @@ -1,11 +1,9 @@ optimizations › trs1 (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -14,47 +12,14 @@ optimizations › trs1 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (global $global_0 (mut i32) (i32.const 0)) - (global $global_2 i32 (i32.const 1)) - (elem $elem (global.get $wimport__grainEnv_relocBase) $f1_1131) + (global $global_2 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) (export \"_start\" (func $_start)) (export \"GRAIN$TABLE_SIZE\" (global $global_2)) - (func $f1_1131 (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - (local.set $3 - (tuple.extract 0 - (tuple.make - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) - ) - (i32.const 0) - ) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) - ) - ) - (drop - (call $wimport_GRAIN$MODULE$runtime/gc_decRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) - ) - ) - (local.get $3) - ) (func $_gmain (; has Stack IR ;) (result i32) (local $0 i32) + (local $1 i32) (i32.store (local.tee $0 (call $wimport_GRAIN$MODULE$runtime/gc_malloc @@ -70,7 +35,7 @@ optimizations › trs1 ) (i32.store offset=8 (local.get $0) - (global.get $wimport__grainEnv_relocBase) + (i32.const -1) ) (i32.store offset=12 (local.get $0) @@ -87,14 +52,42 @@ optimizations › trs1 ) ) ) - (call $f1_1131 + (local.set $0 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $global_0) ) - (i32.const 3) - (i32.const 5) ) + (local.set $1 + (tuple.extract 0 + (tuple.make + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (i32.const 3) + ) + (i32.const 0) + ) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (local.get $0) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 3) + ) + ) + (drop + (call $wimport_GRAIN$MODULE$runtime/gc_decRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) + (i32.const 5) + ) + ) + (local.get $1) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/pattern_matching.05b60a1e.0.snapshot b/compiler/test/__snapshots__/pattern_matching.05b60a1e.0.snapshot index 0e21d564ae..fea9f1adc5 100644 --- a/compiler/test/__snapshots__/pattern_matching.05b60a1e.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.05b60a1e.0.snapshot @@ -2,10 +2,9 @@ pattern matching › adt_match_deep (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"_grainEnv\" \"moduleRuntimeId\" (global $wimport__grainEnv_moduleRuntimeId i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) @@ -16,6 +15,7 @@ pattern matching › adt_match_deep (import \"GRAIN$MODULE$runtime/gc\" \"malloc\" (func $wimport_GRAIN$MODULE$runtime/gc_malloc (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -120,12 +120,10 @@ pattern matching › adt_match_deep (local.set $1 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -135,9 +133,6 @@ pattern matching › adt_match_deep (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -158,14 +153,14 @@ pattern matching › adt_match_deep ) ) (local.set $2 - (block $switch.28_outer (result i32) + (block $switch.27_outer (result i32) (drop - (block $switch.28_branch_1 (result i32) + (block $switch.27_branch_1 (result i32) (drop - (block $switch.28_branch_2 (result i32) + (block $switch.27_branch_2 (result i32) (drop - (block $switch.28_default (result i32) - (br_table $switch.28_branch_1 $switch.28_branch_2 $switch.28_default + (block $switch.27_default (result i32) + (br_table $switch.27_branch_1 $switch.27_branch_2 $switch.27_default (i32.const 0) (i32.shr_s (if (result i32) @@ -269,7 +264,7 @@ pattern matching › adt_match_deep (unreachable) ) ) - (br $switch.28_outer + (br $switch.27_outer (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $0) diff --git a/compiler/test/__snapshots__/pattern_matching.0ad4ac05.0.snapshot b/compiler/test/__snapshots__/pattern_matching.0ad4ac05.0.snapshot index ab2c91d7b3..4ff17b5852 100644 --- a/compiler/test/__snapshots__/pattern_matching.0ad4ac05.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.0ad4ac05.0.snapshot @@ -5,7 +5,6 @@ pattern matching › tuple_match_deep4 (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -17,6 +16,7 @@ pattern matching › tuple_match_deep4 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -47,21 +47,16 @@ pattern matching › tuple_match_deep4 (local.set $18 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -232,20 +227,20 @@ pattern matching › tuple_match_deep4 ) ) (local.set $2 - (block $switch.91_outer (result i32) + (block $switch.90_outer (result i32) (drop - (block $switch.91_branch_1 (result i32) + (block $switch.90_branch_1 (result i32) (drop - (block $switch.91_branch_2 (result i32) + (block $switch.90_branch_2 (result i32) (drop - (block $switch.91_branch_3 (result i32) + (block $switch.90_branch_3 (result i32) (drop - (block $switch.91_branch_4 (result i32) + (block $switch.90_branch_4 (result i32) (drop - (block $switch.91_branch_5 (result i32) + (block $switch.90_branch_5 (result i32) (drop - (block $switch.91_default (result i32) - (br_table $switch.91_branch_1 $switch.91_branch_2 $switch.91_branch_3 $switch.91_branch_4 $switch.91_branch_5 $switch.91_default + (block $switch.90_default (result i32) + (br_table $switch.90_branch_1 $switch.90_branch_2 $switch.90_branch_3 $switch.90_branch_4 $switch.90_branch_5 $switch.90_default (i32.const 0) (i32.shr_s (if (result i32) @@ -725,7 +720,7 @@ pattern matching › tuple_match_deep4 (unreachable) ) ) - (br $switch.91_outer + (br $switch.90_outer (i32.const 1999) ) ) @@ -778,7 +773,7 @@ pattern matching › tuple_match_deep4 ) ) ) - (br $switch.91_outer + (br $switch.90_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -820,7 +815,7 @@ pattern matching › tuple_match_deep4 ) ) ) - (br $switch.91_outer + (br $switch.90_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -838,7 +833,7 @@ pattern matching › tuple_match_deep4 ) ) ) - (br $switch.91_outer + (br $switch.90_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) diff --git a/compiler/test/__snapshots__/pattern_matching.0bb6923e.0.snapshot b/compiler/test/__snapshots__/pattern_matching.0bb6923e.0.snapshot index 1ac32b3fd8..817538a58d 100644 --- a/compiler/test/__snapshots__/pattern_matching.0bb6923e.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.0bb6923e.0.snapshot @@ -1,11 +1,10 @@ pattern matching › adt_match_4 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -15,6 +14,7 @@ pattern matching › adt_match_4 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -40,21 +40,16 @@ pattern matching › adt_match_4 (local.set $12 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 13) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -66,21 +61,16 @@ pattern matching › adt_match_4 (local.set $13 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $12) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -89,24 +79,19 @@ pattern matching › adt_match_4 ) ) ) - (local.set $0 + (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 9) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $13) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -181,21 +166,21 @@ pattern matching › adt_match_4 ) ) ) - (local.set $1 - (block $switch.78_outer (result i32) + (local.set $0 + (block $switch.75_outer (result i32) (drop - (block $switch.78_branch_1 (result i32) + (block $switch.75_branch_1 (result i32) (drop - (block $switch.78_branch_2 (result i32) + (block $switch.75_branch_2 (result i32) (drop - (block $switch.78_branch_3 (result i32) + (block $switch.75_branch_3 (result i32) (drop - (block $switch.78_branch_4 (result i32) + (block $switch.75_branch_4 (result i32) (drop - (block $switch.78_branch_5 (result i32) + (block $switch.75_branch_5 (result i32) (drop - (block $switch.78_default (result i32) - (br_table $switch.78_branch_1 $switch.78_branch_2 $switch.78_branch_3 $switch.78_branch_4 $switch.78_branch_5 $switch.78_default + (block $switch.75_default (result i32) + (br_table $switch.75_branch_1 $switch.75_branch_2 $switch.75_branch_3 $switch.75_branch_4 $switch.75_branch_5 $switch.75_default (i32.const 0) (i32.shr_s (if (result i32) @@ -203,9 +188,9 @@ pattern matching › adt_match_4 (i32.or (i32.shl (i32.eq - (local.tee $1 + (local.tee $0 (i32.load offset=12 - (local.get $0) + (local.get $2) ) ) (i32.const 3) @@ -217,13 +202,13 @@ pattern matching › adt_match_4 (i32.const 31) ) (block (result i32) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=20 - (local.get $0) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -238,7 +223,7 @@ pattern matching › adt_match_4 (i32.or (i32.shl (i32.eq - (local.tee $1 + (local.tee $0 (i32.load offset=12 (local.tee $9 (tuple.extract 0 @@ -246,7 +231,7 @@ pattern matching › adt_match_4 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=24 - (local.get $0) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -288,7 +273,7 @@ pattern matching › adt_match_4 (i32.or (i32.shl (i32.eq - (local.tee $1 + (local.tee $0 (i32.load offset=12 (local.tee $11 (tuple.extract 0 @@ -374,7 +359,7 @@ pattern matching › adt_match_4 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -441,7 +426,7 @@ pattern matching › adt_match_4 (i32.or (i32.shl (i32.eq - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.const 31) @@ -460,7 +445,7 @@ pattern matching › adt_match_4 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -506,7 +491,7 @@ pattern matching › adt_match_4 (i32.or (i32.shl (i32.eq - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.const 31) @@ -525,7 +510,7 @@ pattern matching › adt_match_4 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -549,7 +534,7 @@ pattern matching › adt_match_4 (i32.or (i32.shl (i32.eq - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.const 31) @@ -570,12 +555,12 @@ pattern matching › adt_match_4 (unreachable) ) ) - (br $switch.78_outer + (br $switch.75_outer (i32.const 1999) ) ) ) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -594,12 +579,12 @@ pattern matching › adt_match_4 ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) ) ) - (br $switch.78_outer + (br $switch.75_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -607,7 +592,7 @@ pattern matching › adt_match_4 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -617,7 +602,7 @@ pattern matching › adt_match_4 ) ) ) - (br $switch.78_outer + (br $switch.75_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -635,7 +620,7 @@ pattern matching › adt_match_4 ) ) ) - (br $switch.78_outer + (br $switch.75_outer (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $3) @@ -661,7 +646,7 @@ pattern matching › adt_match_4 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $2) ) ) (drop @@ -703,7 +688,7 @@ pattern matching › adt_match_4 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) (drop @@ -736,7 +721,7 @@ pattern matching › adt_match_4 (local.get $15) ) ) - (local.get $1) + (local.get $0) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/pattern_matching.5b6ff2d3.0.snapshot b/compiler/test/__snapshots__/pattern_matching.5b6ff2d3.0.snapshot index 9cde58b115..52c1bee5dc 100644 --- a/compiler/test/__snapshots__/pattern_matching.5b6ff2d3.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.5b6ff2d3.0.snapshot @@ -5,7 +5,6 @@ pattern matching › alias_match_5 (type $none_=>_none (func)) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -15,6 +14,7 @@ pattern matching › alias_match_5 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/equal\" \"equal\" (func $wimport_GRAIN$MODULE$runtime/equal_equal (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"Some\" (func $gimport_pervasives_Some (param i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -29,17 +29,12 @@ pattern matching › alias_match_5 (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_Some) - ) + (call $gimport_pervasives_Some + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_Some) ) (i32.const 11) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -71,16 +66,16 @@ pattern matching › alias_match_5 ) ) (local.set $4 - (block $switch.38_outer (result i32) + (block $switch.37_outer (result i32) (drop - (block $switch.38_branch_1 (result i32) + (block $switch.37_branch_1 (result i32) (drop - (block $switch.38_branch_2 (result i32) + (block $switch.37_branch_2 (result i32) (drop - (block $switch.38_branch_3 (result i32) + (block $switch.37_branch_3 (result i32) (drop - (block $switch.38_default (result i32) - (br_table $switch.38_branch_1 $switch.38_branch_2 $switch.38_branch_3 $switch.38_default + (block $switch.37_default (result i32) + (br_table $switch.37_branch_1 $switch.37_branch_2 $switch.37_branch_3 $switch.37_default (i32.const 0) (i32.shr_s (if (result i32) @@ -293,7 +288,7 @@ pattern matching › alias_match_5 (unreachable) ) ) - (br $switch.38_outer + (br $switch.37_outer (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_None) @@ -301,7 +296,7 @@ pattern matching › alias_match_5 ) ) ) - (br $switch.38_outer + (br $switch.37_outer (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $2) diff --git a/compiler/test/__snapshots__/pattern_matching.702ed9b0.0.snapshot b/compiler/test/__snapshots__/pattern_matching.702ed9b0.0.snapshot index 7f4edb4cb5..bc7ed7f9fa 100644 --- a/compiler/test/__snapshots__/pattern_matching.702ed9b0.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.702ed9b0.0.snapshot @@ -1,11 +1,10 @@ pattern matching › tuple_match_deep6 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -17,6 +16,7 @@ pattern matching › tuple_match_deep6 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -49,21 +49,16 @@ pattern matching › tuple_match_deep6 (local.set $18 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 13) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -75,21 +70,16 @@ pattern matching › tuple_match_deep6 (local.set $19 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $18) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -101,21 +91,16 @@ pattern matching › tuple_match_deep6 (local.set $20 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 9) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $19) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -286,20 +271,20 @@ pattern matching › tuple_match_deep6 ) ) (local.set $2 - (block $switch.97_outer (result i32) + (block $switch.94_outer (result i32) (drop - (block $switch.97_branch_1 (result i32) + (block $switch.94_branch_1 (result i32) (drop - (block $switch.97_branch_2 (result i32) + (block $switch.94_branch_2 (result i32) (drop - (block $switch.97_branch_3 (result i32) + (block $switch.94_branch_3 (result i32) (drop - (block $switch.97_branch_4 (result i32) + (block $switch.94_branch_4 (result i32) (drop - (block $switch.97_branch_5 (result i32) + (block $switch.94_branch_5 (result i32) (drop - (block $switch.97_default (result i32) - (br_table $switch.97_branch_1 $switch.97_branch_2 $switch.97_branch_3 $switch.97_branch_4 $switch.97_branch_5 $switch.97_default + (block $switch.94_default (result i32) + (br_table $switch.94_branch_1 $switch.94_branch_2 $switch.94_branch_3 $switch.94_branch_4 $switch.94_branch_5 $switch.94_default (i32.const 0) (i32.shr_s (if (result i32) @@ -779,7 +764,7 @@ pattern matching › tuple_match_deep6 (unreachable) ) ) - (br $switch.97_outer + (br $switch.94_outer (i32.const 1999) ) ) @@ -832,7 +817,7 @@ pattern matching › tuple_match_deep6 ) ) ) - (br $switch.97_outer + (br $switch.94_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -874,7 +859,7 @@ pattern matching › tuple_match_deep6 ) ) ) - (br $switch.97_outer + (br $switch.94_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -892,7 +877,7 @@ pattern matching › tuple_match_deep6 ) ) ) - (br $switch.97_outer + (br $switch.94_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) diff --git a/compiler/test/__snapshots__/pattern_matching.b1b060ad.0.snapshot b/compiler/test/__snapshots__/pattern_matching.b1b060ad.0.snapshot index 4462980e8d..4b17b98050 100644 --- a/compiler/test/__snapshots__/pattern_matching.b1b060ad.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.b1b060ad.0.snapshot @@ -1,11 +1,10 @@ pattern matching › adt_match_2 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -15,6 +14,7 @@ pattern matching › adt_match_2 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -38,21 +38,16 @@ pattern matching › adt_match_2 (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $2) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -128,20 +123,20 @@ pattern matching › adt_match_2 ) ) (local.set $0 - (block $switch.72_outer (result i32) + (block $switch.71_outer (result i32) (drop - (block $switch.72_branch_1 (result i32) + (block $switch.71_branch_1 (result i32) (drop - (block $switch.72_branch_2 (result i32) + (block $switch.71_branch_2 (result i32) (drop - (block $switch.72_branch_3 (result i32) + (block $switch.71_branch_3 (result i32) (drop - (block $switch.72_branch_4 (result i32) + (block $switch.71_branch_4 (result i32) (drop - (block $switch.72_branch_5 (result i32) + (block $switch.71_branch_5 (result i32) (drop - (block $switch.72_default (result i32) - (br_table $switch.72_branch_1 $switch.72_branch_2 $switch.72_branch_3 $switch.72_branch_4 $switch.72_branch_5 $switch.72_default + (block $switch.71_default (result i32) + (br_table $switch.71_branch_1 $switch.71_branch_2 $switch.71_branch_3 $switch.71_branch_4 $switch.71_branch_5 $switch.71_default (i32.const 0) (i32.shr_s (if (result i32) @@ -516,7 +511,7 @@ pattern matching › adt_match_2 (unreachable) ) ) - (br $switch.72_outer + (br $switch.71_outer (i32.const 1999) ) ) @@ -545,7 +540,7 @@ pattern matching › adt_match_2 ) ) ) - (br $switch.72_outer + (br $switch.71_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -563,7 +558,7 @@ pattern matching › adt_match_2 ) ) ) - (br $switch.72_outer + (br $switch.71_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -581,7 +576,7 @@ pattern matching › adt_match_2 ) ) ) - (br $switch.72_outer + (br $switch.71_outer (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $3) diff --git a/compiler/test/__snapshots__/pattern_matching.c91eac29.0.snapshot b/compiler/test/__snapshots__/pattern_matching.c91eac29.0.snapshot index 451a5c418f..87b41f7d2e 100644 --- a/compiler/test/__snapshots__/pattern_matching.c91eac29.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.c91eac29.0.snapshot @@ -1,11 +1,10 @@ pattern matching › adt_match_3 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -15,6 +14,7 @@ pattern matching › adt_match_3 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -39,21 +39,16 @@ pattern matching › adt_match_3 (local.set $12 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -62,24 +57,19 @@ pattern matching › adt_match_3 ) ) ) - (local.set $0 + (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 9) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $12) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -154,21 +144,21 @@ pattern matching › adt_match_3 ) ) ) - (local.set $1 - (block $switch.75_outer (result i32) + (local.set $0 + (block $switch.73_outer (result i32) (drop - (block $switch.75_branch_1 (result i32) + (block $switch.73_branch_1 (result i32) (drop - (block $switch.75_branch_2 (result i32) + (block $switch.73_branch_2 (result i32) (drop - (block $switch.75_branch_3 (result i32) + (block $switch.73_branch_3 (result i32) (drop - (block $switch.75_branch_4 (result i32) + (block $switch.73_branch_4 (result i32) (drop - (block $switch.75_branch_5 (result i32) + (block $switch.73_branch_5 (result i32) (drop - (block $switch.75_default (result i32) - (br_table $switch.75_branch_1 $switch.75_branch_2 $switch.75_branch_3 $switch.75_branch_4 $switch.75_branch_5 $switch.75_default + (block $switch.73_default (result i32) + (br_table $switch.73_branch_1 $switch.73_branch_2 $switch.73_branch_3 $switch.73_branch_4 $switch.73_branch_5 $switch.73_default (i32.const 0) (i32.shr_s (if (result i32) @@ -176,9 +166,9 @@ pattern matching › adt_match_3 (i32.or (i32.shl (i32.eq - (local.tee $1 + (local.tee $0 (i32.load offset=12 - (local.get $0) + (local.get $2) ) ) (i32.const 3) @@ -190,13 +180,13 @@ pattern matching › adt_match_3 (i32.const 31) ) (block (result i32) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=20 - (local.get $0) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -211,7 +201,7 @@ pattern matching › adt_match_3 (i32.or (i32.shl (i32.eq - (local.tee $1 + (local.tee $0 (i32.load offset=12 (local.tee $9 (tuple.extract 0 @@ -219,7 +209,7 @@ pattern matching › adt_match_3 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=24 - (local.get $0) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -261,7 +251,7 @@ pattern matching › adt_match_3 (i32.or (i32.shl (i32.eq - (local.tee $1 + (local.tee $0 (i32.load offset=12 (local.tee $11 (tuple.extract 0 @@ -347,7 +337,7 @@ pattern matching › adt_match_3 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -414,7 +404,7 @@ pattern matching › adt_match_3 (i32.or (i32.shl (i32.eq - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.const 31) @@ -433,7 +423,7 @@ pattern matching › adt_match_3 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -479,7 +469,7 @@ pattern matching › adt_match_3 (i32.or (i32.shl (i32.eq - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.const 31) @@ -498,7 +488,7 @@ pattern matching › adt_match_3 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -522,7 +512,7 @@ pattern matching › adt_match_3 (i32.or (i32.shl (i32.eq - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.const 31) @@ -543,12 +533,12 @@ pattern matching › adt_match_3 (unreachable) ) ) - (br $switch.75_outer + (br $switch.73_outer (i32.const 1999) ) ) ) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -567,12 +557,12 @@ pattern matching › adt_match_3 ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) ) ) - (br $switch.75_outer + (br $switch.73_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -580,7 +570,7 @@ pattern matching › adt_match_3 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -590,7 +580,7 @@ pattern matching › adt_match_3 ) ) ) - (br $switch.75_outer + (br $switch.73_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -608,7 +598,7 @@ pattern matching › adt_match_3 ) ) ) - (br $switch.75_outer + (br $switch.73_outer (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $3) @@ -628,7 +618,7 @@ pattern matching › adt_match_3 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $2) ) ) (drop @@ -670,7 +660,7 @@ pattern matching › adt_match_3 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) (drop @@ -703,7 +693,7 @@ pattern matching › adt_match_3 (local.get $14) ) ) - (local.get $1) + (local.get $0) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/pattern_matching.c9582b6d.0.snapshot b/compiler/test/__snapshots__/pattern_matching.c9582b6d.0.snapshot index 3c818cf4c6..9b0bac2547 100644 --- a/compiler/test/__snapshots__/pattern_matching.c9582b6d.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.c9582b6d.0.snapshot @@ -5,7 +5,6 @@ pattern matching › alias_match_4 (type $none_=>_none (func)) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -14,6 +13,7 @@ pattern matching › alias_match_4 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/equal\" \"equal\" (func $wimport_GRAIN$MODULE$runtime/equal_equal (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"Some\" (func $gimport_pervasives_Some (param i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -27,17 +27,12 @@ pattern matching › alias_match_4 (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_Some) - ) + (call $gimport_pervasives_Some + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_Some) ) (i32.const 11) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -58,16 +53,16 @@ pattern matching › alias_match_4 ) ) (local.set $3 - (block $switch.30_outer (result i32) + (block $switch.29_outer (result i32) (drop - (block $switch.30_branch_1 (result i32) + (block $switch.29_branch_1 (result i32) (drop - (block $switch.30_branch_2 (result i32) + (block $switch.29_branch_2 (result i32) (drop - (block $switch.30_branch_3 (result i32) + (block $switch.29_branch_3 (result i32) (drop - (block $switch.30_default (result i32) - (br_table $switch.30_branch_1 $switch.30_branch_2 $switch.30_branch_3 $switch.30_default + (block $switch.29_default (result i32) + (br_table $switch.29_branch_1 $switch.29_branch_2 $switch.29_branch_3 $switch.29_default (i32.const 0) (i32.shr_s (if (result i32) @@ -215,12 +210,12 @@ pattern matching › alias_match_4 (unreachable) ) ) - (br $switch.30_outer + (br $switch.29_outer (i32.const 13) ) ) ) - (br $switch.30_outer + (br $switch.29_outer (i32.const 11) ) ) diff --git a/compiler/test/__snapshots__/pattern_matching.d048ece0.0.snapshot b/compiler/test/__snapshots__/pattern_matching.d048ece0.0.snapshot index f0a270d4ee..30e003ccc1 100644 --- a/compiler/test/__snapshots__/pattern_matching.d048ece0.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.d048ece0.0.snapshot @@ -1,11 +1,10 @@ pattern matching › adt_match_5 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -15,6 +14,7 @@ pattern matching › adt_match_5 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -41,21 +41,16 @@ pattern matching › adt_match_5 (local.set $12 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 15) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -67,21 +62,16 @@ pattern matching › adt_match_5 (local.set $13 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 13) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $12) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -93,21 +83,16 @@ pattern matching › adt_match_5 (local.set $14 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $13) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -116,24 +101,19 @@ pattern matching › adt_match_5 ) ) ) - (local.set $0 + (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 9) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $14) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -208,21 +188,21 @@ pattern matching › adt_match_5 ) ) ) - (local.set $1 - (block $switch.81_outer (result i32) + (local.set $0 + (block $switch.77_outer (result i32) (drop - (block $switch.81_branch_1 (result i32) + (block $switch.77_branch_1 (result i32) (drop - (block $switch.81_branch_2 (result i32) + (block $switch.77_branch_2 (result i32) (drop - (block $switch.81_branch_3 (result i32) + (block $switch.77_branch_3 (result i32) (drop - (block $switch.81_branch_4 (result i32) + (block $switch.77_branch_4 (result i32) (drop - (block $switch.81_branch_5 (result i32) + (block $switch.77_branch_5 (result i32) (drop - (block $switch.81_default (result i32) - (br_table $switch.81_branch_1 $switch.81_branch_2 $switch.81_branch_3 $switch.81_branch_4 $switch.81_branch_5 $switch.81_default + (block $switch.77_default (result i32) + (br_table $switch.77_branch_1 $switch.77_branch_2 $switch.77_branch_3 $switch.77_branch_4 $switch.77_branch_5 $switch.77_default (i32.const 0) (i32.shr_s (if (result i32) @@ -230,9 +210,9 @@ pattern matching › adt_match_5 (i32.or (i32.shl (i32.eq - (local.tee $1 + (local.tee $0 (i32.load offset=12 - (local.get $0) + (local.get $2) ) ) (i32.const 3) @@ -244,13 +224,13 @@ pattern matching › adt_match_5 (i32.const 31) ) (block (result i32) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=20 - (local.get $0) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -265,7 +245,7 @@ pattern matching › adt_match_5 (i32.or (i32.shl (i32.eq - (local.tee $1 + (local.tee $0 (i32.load offset=12 (local.tee $9 (tuple.extract 0 @@ -273,7 +253,7 @@ pattern matching › adt_match_5 (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=24 - (local.get $0) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -315,7 +295,7 @@ pattern matching › adt_match_5 (i32.or (i32.shl (i32.eq - (local.tee $1 + (local.tee $0 (i32.load offset=12 (local.tee $11 (tuple.extract 0 @@ -401,7 +381,7 @@ pattern matching › adt_match_5 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -468,7 +448,7 @@ pattern matching › adt_match_5 (i32.or (i32.shl (i32.eq - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.const 31) @@ -487,7 +467,7 @@ pattern matching › adt_match_5 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -533,7 +513,7 @@ pattern matching › adt_match_5 (i32.or (i32.shl (i32.eq - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.const 31) @@ -552,7 +532,7 @@ pattern matching › adt_match_5 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -576,7 +556,7 @@ pattern matching › adt_match_5 (i32.or (i32.shl (i32.eq - (local.get $1) + (local.get $0) (i32.const 1) ) (i32.const 31) @@ -597,12 +577,12 @@ pattern matching › adt_match_5 (unreachable) ) ) - (br $switch.81_outer + (br $switch.77_outer (i32.const 1999) ) ) ) - (local.set $2 + (local.set $1 (tuple.extract 0 (tuple.make (call $gimport_pervasives_+ @@ -621,12 +601,12 @@ pattern matching › adt_match_5 ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) ) ) - (br $switch.81_outer + (br $switch.77_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -634,7 +614,7 @@ pattern matching › adt_match_5 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $2) + (local.get $1) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -644,7 +624,7 @@ pattern matching › adt_match_5 ) ) ) - (br $switch.81_outer + (br $switch.77_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -662,7 +642,7 @@ pattern matching › adt_match_5 ) ) ) - (br $switch.81_outer + (br $switch.77_outer (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $3) @@ -694,7 +674,7 @@ pattern matching › adt_match_5 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $2) ) ) (drop @@ -736,7 +716,7 @@ pattern matching › adt_match_5 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $2) + (local.get $1) ) ) (drop @@ -769,7 +749,7 @@ pattern matching › adt_match_5 (local.get $16) ) ) - (local.get $1) + (local.get $0) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/pattern_matching.e41ad64e.0.snapshot b/compiler/test/__snapshots__/pattern_matching.e41ad64e.0.snapshot index dcd7cea9fe..f09b32fc3f 100644 --- a/compiler/test/__snapshots__/pattern_matching.e41ad64e.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.e41ad64e.0.snapshot @@ -1,11 +1,10 @@ pattern matching › tuple_match_deep5 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -17,6 +16,7 @@ pattern matching › tuple_match_deep5 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -48,21 +48,16 @@ pattern matching › tuple_match_deep5 (local.set $18 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -74,21 +69,16 @@ pattern matching › tuple_match_deep5 (local.set $19 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 9) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $18) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -259,20 +249,20 @@ pattern matching › tuple_match_deep5 ) ) (local.set $2 - (block $switch.94_outer (result i32) + (block $switch.92_outer (result i32) (drop - (block $switch.94_branch_1 (result i32) + (block $switch.92_branch_1 (result i32) (drop - (block $switch.94_branch_2 (result i32) + (block $switch.92_branch_2 (result i32) (drop - (block $switch.94_branch_3 (result i32) + (block $switch.92_branch_3 (result i32) (drop - (block $switch.94_branch_4 (result i32) + (block $switch.92_branch_4 (result i32) (drop - (block $switch.94_branch_5 (result i32) + (block $switch.92_branch_5 (result i32) (drop - (block $switch.94_default (result i32) - (br_table $switch.94_branch_1 $switch.94_branch_2 $switch.94_branch_3 $switch.94_branch_4 $switch.94_branch_5 $switch.94_default + (block $switch.92_default (result i32) + (br_table $switch.92_branch_1 $switch.92_branch_2 $switch.92_branch_3 $switch.92_branch_4 $switch.92_branch_5 $switch.92_default (i32.const 0) (i32.shr_s (if (result i32) @@ -752,7 +742,7 @@ pattern matching › tuple_match_deep5 (unreachable) ) ) - (br $switch.94_outer + (br $switch.92_outer (i32.const 1999) ) ) @@ -805,7 +795,7 @@ pattern matching › tuple_match_deep5 ) ) ) - (br $switch.94_outer + (br $switch.92_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -847,7 +837,7 @@ pattern matching › tuple_match_deep5 ) ) ) - (br $switch.94_outer + (br $switch.92_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -865,7 +855,7 @@ pattern matching › tuple_match_deep5 ) ) ) - (br $switch.94_outer + (br $switch.92_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) diff --git a/compiler/test/__snapshots__/pattern_matching.f0c08ea4.0.snapshot b/compiler/test/__snapshots__/pattern_matching.f0c08ea4.0.snapshot index d0a595b796..ffa5e1dfb2 100644 --- a/compiler/test/__snapshots__/pattern_matching.f0c08ea4.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.f0c08ea4.0.snapshot @@ -1,11 +1,10 @@ pattern matching › tuple_match_deep7 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) @@ -17,6 +16,7 @@ pattern matching › tuple_match_deep7 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"+\" (func $gimport_pervasives_+ (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -50,21 +50,16 @@ pattern matching › tuple_match_deep7 (local.set $18 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 15) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -76,21 +71,16 @@ pattern matching › tuple_match_deep7 (local.set $19 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 13) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $18) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -102,21 +92,16 @@ pattern matching › tuple_match_deep7 (local.set $20 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $19) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -128,21 +113,16 @@ pattern matching › tuple_match_deep7 (local.set $21 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 9) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $20) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -313,20 +293,20 @@ pattern matching › tuple_match_deep7 ) ) (local.set $2 - (block $switch.100_outer (result i32) + (block $switch.96_outer (result i32) (drop - (block $switch.100_branch_1 (result i32) + (block $switch.96_branch_1 (result i32) (drop - (block $switch.100_branch_2 (result i32) + (block $switch.96_branch_2 (result i32) (drop - (block $switch.100_branch_3 (result i32) + (block $switch.96_branch_3 (result i32) (drop - (block $switch.100_branch_4 (result i32) + (block $switch.96_branch_4 (result i32) (drop - (block $switch.100_branch_5 (result i32) + (block $switch.96_branch_5 (result i32) (drop - (block $switch.100_default (result i32) - (br_table $switch.100_branch_1 $switch.100_branch_2 $switch.100_branch_3 $switch.100_branch_4 $switch.100_branch_5 $switch.100_default + (block $switch.96_default (result i32) + (br_table $switch.96_branch_1 $switch.96_branch_2 $switch.96_branch_3 $switch.96_branch_4 $switch.96_branch_5 $switch.96_default (i32.const 0) (i32.shr_s (if (result i32) @@ -806,7 +786,7 @@ pattern matching › tuple_match_deep7 (unreachable) ) ) - (br $switch.100_outer + (br $switch.96_outer (i32.const 1999) ) ) @@ -859,7 +839,7 @@ pattern matching › tuple_match_deep7 ) ) ) - (br $switch.100_outer + (br $switch.96_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -901,7 +881,7 @@ pattern matching › tuple_match_deep7 ) ) ) - (br $switch.100_outer + (br $switch.96_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) @@ -919,7 +899,7 @@ pattern matching › tuple_match_deep7 ) ) ) - (br $switch.100_outer + (br $switch.96_outer (call $gimport_pervasives_+ (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) diff --git a/compiler/test/__snapshots__/pattern_matching.f25e0163.0.snapshot b/compiler/test/__snapshots__/pattern_matching.f25e0163.0.snapshot index 683810ca22..41ce0f4744 100644 --- a/compiler/test/__snapshots__/pattern_matching.f25e0163.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.f25e0163.0.snapshot @@ -2,10 +2,9 @@ pattern matching › or_match_3 (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -13,6 +12,7 @@ pattern matching › or_match_3 (import \"GRAIN$MODULE$pervasives\" \"GRAIN$EXPORT$[...]\" (global $gimport_pervasives_[...] (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -30,21 +30,16 @@ pattern matching › or_match_3 (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 11) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -65,14 +60,14 @@ pattern matching › or_match_3 ) ) (local.set $1 - (block $switch.53_outer (result i32) + (block $switch.52_outer (result i32) (drop - (block $switch.53_branch_1 (result i32) + (block $switch.52_branch_1 (result i32) (drop - (block $switch.53_branch_2 (result i32) + (block $switch.52_branch_2 (result i32) (drop - (block $switch.53_default (result i32) - (br_table $switch.53_branch_1 $switch.53_branch_2 $switch.53_default + (block $switch.52_default (result i32) + (br_table $switch.52_branch_1 $switch.52_branch_2 $switch.52_default (i32.const 0) (i32.shr_s (if (result i32) @@ -345,7 +340,7 @@ pattern matching › or_match_3 (unreachable) ) ) - (br $switch.53_outer + (br $switch.52_outer (i32.const 2147483646) ) ) diff --git a/compiler/test/__snapshots__/pattern_matching.f6c9c89c.0.snapshot b/compiler/test/__snapshots__/pattern_matching.f6c9c89c.0.snapshot index 22ab8e3aaa..b44a619e0f 100644 --- a/compiler/test/__snapshots__/pattern_matching.f6c9c89c.0.snapshot +++ b/compiler/test/__snapshots__/pattern_matching.f6c9c89c.0.snapshot @@ -5,7 +5,6 @@ pattern matching › or_match_2 (type $none_=>_none (func)) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -14,6 +13,7 @@ pattern matching › or_match_2 (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/equal\" \"equal\" (func $wimport_GRAIN$MODULE$runtime/equal_equal (param i32 i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"Some\" (func $gimport_pervasives_Some (param i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -23,17 +23,17 @@ pattern matching › or_match_2 (local $0 i32) (local $1 i32) (local $2 i32) - (local.set $2 - (block $switch.30_outer (result i32) + (local.set $1 + (block $switch.29_outer (result i32) (drop - (block $switch.30_branch_1 (result i32) + (block $switch.29_branch_1 (result i32) (drop - (block $switch.30_branch_2 (result i32) + (block $switch.29_branch_2 (result i32) (drop - (block $switch.30_branch_3 (result i32) + (block $switch.29_branch_3 (result i32) (drop - (block $switch.30_default (result i32) - (br_table $switch.30_branch_1 $switch.30_branch_2 $switch.30_branch_3 $switch.30_default + (block $switch.29_default (result i32) + (br_table $switch.29_branch_1 $switch.29_branch_2 $switch.29_branch_3 $switch.29_default (i32.const 0) (i32.shr_s (if (result i32) @@ -41,22 +41,17 @@ pattern matching › or_match_2 (i32.or (i32.shl (i32.eq - (local.tee $2 + (local.tee $1 (i32.load offset=12 - (local.tee $0 + (local.tee $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_Some) - ) + (call $gimport_pervasives_Some + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_Some) ) (i32.const 11) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -81,7 +76,7 @@ pattern matching › or_match_2 (i32.or (i32.shl (i32.eq - (local.get $2) + (local.get $1) (i32.const 1) ) (i32.const 31) @@ -91,13 +86,13 @@ pattern matching › or_match_2 (i32.const 31) ) (block (result i32) - (local.set $1 + (local.set $0 (tuple.extract 0 (tuple.make (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (i32.load offset=20 - (local.get $0) + (local.get $2) ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef @@ -116,7 +111,7 @@ pattern matching › or_match_2 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) + (local.get $0) ) (i32.const 7) ) @@ -132,7 +127,7 @@ pattern matching › or_match_2 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) + (local.get $0) ) (i32.const 9) ) @@ -150,7 +145,7 @@ pattern matching › or_match_2 ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (local.get $1) + (local.get $0) ) (i32.const 11) ) @@ -171,12 +166,12 @@ pattern matching › or_match_2 (unreachable) ) ) - (br $switch.30_outer + (br $switch.29_outer (i32.const 2147483646) ) ) ) - (br $switch.30_outer + (br $switch.29_outer (i32.const -2) ) ) @@ -187,16 +182,16 @@ pattern matching › or_match_2 (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $0) + (local.get $2) ) ) (drop (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) - (local.get $1) + (local.get $0) ) ) - (local.get $2) + (local.get $1) ) (func $_start (; has Stack IR ;) (drop diff --git a/compiler/test/__snapshots__/records.60c0a141.0.snapshot b/compiler/test/__snapshots__/records.60c0a141.0.snapshot index 70c2887f9e..59387867d3 100644 --- a/compiler/test/__snapshots__/records.60c0a141.0.snapshot +++ b/compiler/test/__snapshots__/records.60c0a141.0.snapshot @@ -4,7 +4,6 @@ records › record_recursive_data_definition (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"_grainEnv\" \"moduleRuntimeId\" (global $wimport__grainEnv_moduleRuntimeId i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$malloc (mut i32))) @@ -15,6 +14,7 @@ records › record_recursive_data_definition (import \"GRAIN$MODULE$runtime/gc\" \"malloc\" (func $wimport_GRAIN$MODULE$runtime/gc_malloc (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"Some\" (func $gimport_pervasives_Some (param i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -174,20 +174,15 @@ records › record_recursive_data_definition (local.set $1 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_Some) - ) + (call $gimport_pervasives_Some + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_Some) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $0) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -216,20 +211,15 @@ records › record_recursive_data_definition (local.set $3 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_=>_i32) - (local.tee $3 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_Some) - ) + (call $gimport_pervasives_Some + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_Some) ) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $2) ) - (i32.load offset=8 - (local.get $3) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) diff --git a/compiler/test/__snapshots__/stdlib.37483d2d.0.snapshot b/compiler/test/__snapshots__/stdlib.37483d2d.0.snapshot index 9ae2925753..5c8a4c3228 100644 --- a/compiler/test/__snapshots__/stdlib.37483d2d.0.snapshot +++ b/compiler/test/__snapshots__/stdlib.37483d2d.0.snapshot @@ -1,11 +1,10 @@ stdlib › stdlib_cons (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -13,6 +12,7 @@ stdlib › stdlib_cons (import \"GRAIN$MODULE$pervasives\" \"GRAIN$EXPORT$[...]\" (global $gimport_pervasives_[...] (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) (export \"_gmain\" (func $_gmain)) @@ -25,21 +25,16 @@ stdlib › stdlib_cons (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 7) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -51,21 +46,16 @@ stdlib › stdlib_cons (local.set $1 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $0) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -75,21 +65,16 @@ stdlib › stdlib_cons ) ) (local.set $2 - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $1) ) - (i32.load offset=8 - (local.get $2) - ) ) ) (drop diff --git a/compiler/test/__snapshots__/stdlib.8300ad7c.0.snapshot b/compiler/test/__snapshots__/stdlib.8300ad7c.0.snapshot index 1fa79296a2..ea7ea985a6 100644 --- a/compiler/test/__snapshots__/stdlib.8300ad7c.0.snapshot +++ b/compiler/test/__snapshots__/stdlib.8300ad7c.0.snapshot @@ -1,11 +1,10 @@ stdlib › stdlib_equal_3 (module - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_none (func)) (import \"_grainEnv\" \"mem\" (memory $0 0)) - (import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref)) (import \"_grainEnv\" \"relocBase\" (global $wimport__grainEnv_relocBase i32)) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$incRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$decRef\" (global $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef (mut i32))) @@ -14,6 +13,7 @@ stdlib › stdlib_equal_3 (import \"GRAIN$MODULE$pervasives\" \"GRAIN$EXPORT$==\" (global $gimport_pervasives_== (mut i32))) (import \"GRAIN$MODULE$runtime/gc\" \"incRef\" (func $wimport_GRAIN$MODULE$runtime/gc_incRef (param i32 i32) (result i32))) (import \"GRAIN$MODULE$runtime/gc\" \"decRef\" (func $wimport_GRAIN$MODULE$runtime/gc_decRef (param i32 i32) (result i32))) + (import \"GRAIN$MODULE$pervasives\" \"[...]\" (func $gimport_pervasives_[...] (param i32 i32 i32) (result i32))) (import \"GRAIN$MODULE$pervasives\" \"==\" (func $gimport_pervasives_== (param i32 i32 i32) (result i32))) (global $global_1 i32 (i32.const 0)) (export \"memory\" (memory $0)) @@ -31,21 +31,16 @@ stdlib › stdlib_equal_3 (local.set $0 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $0 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 7) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $0) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -57,21 +52,16 @@ stdlib › stdlib_equal_3 (local.set $1 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $1 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $0) ) - (i32.load offset=8 - (local.get $1) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -83,21 +73,16 @@ stdlib › stdlib_equal_3 (local.set $2 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $2 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $1) ) - (i32.load offset=8 - (local.get $2) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -109,21 +94,16 @@ stdlib › stdlib_equal_3 (local.set $3 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $3 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 7) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (global.get $gimport_pervasives_[]) ) - (i32.load offset=8 - (local.get $3) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -135,21 +115,16 @@ stdlib › stdlib_equal_3 (local.set $4 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $4 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 5) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $3) ) - (i32.load offset=8 - (local.get $4) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef) @@ -161,21 +136,16 @@ stdlib › stdlib_equal_3 (local.set $5 (tuple.extract 0 (tuple.make - (call_indirect (type $i32_i32_i32_=>_i32) - (local.tee $5 - (call $wimport_GRAIN$MODULE$runtime/gc_incRef - (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) - (global.get $gimport_pervasives_[...]) - ) + (call $gimport_pervasives_[...] + (call $wimport_GRAIN$MODULE$runtime/gc_incRef + (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) + (global.get $gimport_pervasives_[...]) ) (i32.const 3) (call $wimport_GRAIN$MODULE$runtime/gc_incRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$incRef) (local.get $4) ) - (i32.load offset=8 - (local.get $5) - ) ) (call $wimport_GRAIN$MODULE$runtime/gc_decRef (global.get $wimport_GRAIN$MODULE$runtime/gc_GRAIN$EXPORT$decRef)