(func $main/test (type $t1) (param $p0 i32) (param $p1 i32)
...)
(func $main/test|trampoline (export "test") (type $t1) (param $p0 i32) (param $p1 i32)
block $B0
block $B1
block $B2
get_global $g25
i32.const 1
i32.sub
br_table $B1 $B0 $B2
end
unreachable
end
i32.const 0
set_local $p1
end
get_local $p0
get_local $p1
call $main/test)
(func $~setargc (export "_setargc") (type $t2) (param $p0 i32)
get_local $p0
set_global $g25)
The trampoline is generated if a function with optional arguments is called with omitted arguments. It basically wraps up the initializers of optional arguments in a proper context and calls the original function with them. If you always call functions with optional arguments with all arguments provided, no trampolines must be generated.
This reminds me that a few optimizations could be performed there. One is that if default values of omitted arguments are zero anyway, another one is if default values are constants that can be inlined into the call.
Closing this issue for now as it hasn't received any replies recently, so I assume that the optimizations implemented above address it sufficiently. Feel free to reopen if necessary!
Most helpful comment
This reminds me that a few optimizations could be performed there. One is that if default values of omitted arguments are zero anyway, another one is if default values are constants that can be inlined into the call.