mdn / interactive-examples

Home of the MDN live code editor interactive examples
Creative Commons Zero v1.0 Universal
731 stars 510 forks source link

Add return_call example for WASM #2693

Closed pepelsbey closed 3 weeks ago

pepelsbey commented 10 months ago

Description

Adds example for return_call, tail call version of the call. I took it from the explainer.

But there’s a catch: the playground shows an error when I try to run the code. There might be two reasons for that:

Motivation

To support enabled tail calls in Firefox 121.

Additional details

> Error: parseWat failed:
3:6: error: opcode not allowed: return_call
    (return_call $fac-aux (local.get $x) (i32.const 1))
     ^^^^^^^^^^^
10:10: error: opcode not allowed: return_call
        (return_call $fac-aux
         ^^^^^^^^^^^

Related issues and pull requests

github-actions[bot] commented 10 months ago

It looks like this is your first pull request. 🎉 Thank you for your contribution! One of the project maintainers will triage and assign the pull request for review. We appreciate your patience. To safeguard the health of the project, please take a moment to read our code of conduct.

pepelsbey commented 10 months ago

@eqrion could you please have a look?

pepelsbey commented 10 months ago

@yurydelendik thank you! However, the code still won’t run if pasted into the playground we have on the call page, for example:

> Error: parseWat failed:
3:6: error: opcode not allowed: return_call
    (return_call $fac-aux (local.get $x) (i64.const 1))
     ^^^^^^^^^^^
10:10: error: opcode not allowed: return_call
        (return_call $fac-aux
         ^^^^^^^^^^^

Do you have an idea if it’s the problem with the playground?

yurydelendik commented 10 months ago

Do you have an idea if it’s the problem with the playground?

I have a little insight into how playground works. The WebAssembly engine does not know about WAT and text representation. The transformation to bytecode is happening somewhere else. That something perhaps needs to be updated with new wasm specifications support.

yurydelendik commented 10 months ago

If not mistaken, parseWat is API function from wabt JS library. Is https://github.com/mdn/bob/blob/main/editor/js/editable-wat.ts executed on the main page?

There is a reference to "wabt": "^1.0.29", which is https://github.com/AssemblyScript/wabt.js . The package is not updated for long time and probably missing new specifications.

pepelsbey commented 10 months ago

The package is not updated for long time and probably missing new specifications.

Thank you for investigating! I’ll reach out to platform engineers about this.

fiji-flo commented 1 month ago

once https://github.com/mdn/interactive-examples/pull/2845 landed we can get this out.