Imagine this source code:
func foo() {
var ref: A = ..some non-null result..;
bar(ref, ref);
}
In defer
we would write that as following:
(func $foo
(local $ref (ref null $A))
(local.set $ref
(..some non-null result..)
)
(call $bar
(ref.as_non_null
(local.get $ref)
)
(ref.as_non_null
(local.get $ref)
)
)
)
With local.get_or_trap
that would be:
(func $foo
(local $ref (ref null $A))
(local.set $ref
(..some non-null result..)
)
(call $bar
(local.get_or_trap $ref) ;; only these two
(local.get_or_trap $ref) ;; lines change
)
)
And with non-nullable locals (local.get_or_trap+NNL
) that would be:
(func $foo
(local $ref (ref $A)) ;; only this line changes
(local.set $ref
(..some non-null result..)
)
(call $bar
(local.get_or_trap $ref)
(local.get_or_trap $ref)
)
)