Skip to content

Instantly share code, notes, and snippets.

@kripken
Last active July 17, 2022 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kripken/cef8914b195191d5adde70549fce3c66 to your computer and use it in GitHub Desktop.
Save kripken/cef8914b195191d5adde70549fce3c66 to your computer and use it in GitHub Desktop.

Example of Wasm GC non-nullable variations on the "defer" option

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)
  )
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment