Skip to content

Reword 6.6.5.1. Function Abbreviations to be more specific about impact #1418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
codefromthecrypt opened this issue Feb 7, 2022 · 4 comments · Fixed by #1420
Closed

Reword 6.6.5.1. Function Abbreviations to be more specific about impact #1418

codefromthecrypt opened this issue Feb 7, 2022 · 4 comments · Fixed by #1420

Comments

@codefromthecrypt
Copy link
Contributor

codefromthecrypt commented Feb 7, 2022

The WebAssembly 1.0 (MVP) and 1.1 draft both allow repetition and co-mingling of inlined/abbreviated function import and exports.

Screen Shot 2022-02-07 at 8 42 33 AM

The wording "The latter abbreviation can be applied repeatedly, with “…” containing another import or export." is more wide than necessary. The only possible grammar seems (export)* (import)? because the "import", if present, must be present at the end.

For example, the valid combinations besides no inlined import/export

  • only import -> this means the func cannot have a body or locals, it is effectively a different way of writing import func
  • N exports -> this is a module-defined func where N exports point to the current position in the index namespace
  • N exports then import -> this is an imported function re-exported N times

To figure these points out from the spec requires too much thinking, so I think the section can be worded, ya?

@codefromthecrypt
Copy link
Contributor Author

codefromthecrypt commented Feb 10, 2022

Actually, per the grammar, I think it should be possible to have exports after a single import, just not more than one import. However, in practice, both wabt and wasm-tools require an abbreviated import to be last.

Ex. (export)* (import)?: This parses in both wat2wasm and also wasm-tools (both latest)

(module $test
  (func $wasi.args_get (export "wasi/args_get") (import "wasi_snapshot_preview1" "args_get")
    (param $argv i32) (param $argv_buf i32) (result (;errno;) i32))
  (memory (export "memory") 1))

Ex. (export)* (import)? (export)*: This fails on both of the above, but per the description in the spec, I actually think it shouldn't.

(module $test
  (func $wasi.args_get (import "wasi_snapshot_preview1" "args_get") (export "wasi/args_get")
    (param $argv i32) (param $argv_buf i32) (result (;errno;) i32))
  (memory (export "memory") 1))

Presuming no-one has complained, I'm personally ok restricting this to (export)* (import)?, but if it is an oversight, I'd rather implement the full grammar allowed (export)* (import)? (export)*. To know the difference, I'd appreciate some feedback from folks familiar if you don't mind.

@codefromthecrypt
Copy link
Contributor Author

cc @rossberg - spec side
cc @alexcrichton - wasm-tools
cc @sbc100 - wabt

@codefromthecrypt
Copy link
Contributor Author

actually I can see how this can result in the terminal import as the first abbreviation has no trailing ...

So, that means (export)* (import)? (export)* is invalid and (export)* (import)? is valid

Meanwhile, took a while to figure out which may be due to my denseness. hope something in this issue can be of use to make things more obvious or at least obvious faster than it took me!

FWIW if it wrote the same info more straightforwardly, like (export)* (import)? I think I would have gotten this point quicker as the relationship of type use (param)* (result)? wasn't so hard on me and is basically the same.

codefromthecrypt pushed a commit to codefromthecrypt/spec that referenced this issue Feb 10, 2022
…flect impact

While implementing this specification, I became confused as while the
language did say the latter was repeatable, the rest used plural words
for things that cannot repeat. This changes the text to hopefully
prevent future folks from reaching the same misconclusion.

Fixes WebAssembly#1418

Signed-off-by: Adrian Cole <[email protected]>
@codefromthecrypt
Copy link
Contributor Author

codefromthecrypt commented Feb 10, 2022

#1420 is best I can do to clarify this

"The latter abbreviation can be applied repeatedly, with “…” containing another import or export."

^^ this seems to hint that you can do (export) (import) (export) (import) resulting in multiple imports that won't work as there can be at most one and really only exports can repeat.

IOTW, I think even if the grammar can be interpreted correctly as is, it wouldn't hurt to help it become interpreted correctly. Meanwhile, closing this issue to whatever end the WG feels as I've made copious notes on my side regardless..

codefromthecrypt pushed a commit to codefromthecrypt/spec that referenced this issue Feb 14, 2022
…flect impact

While implementing this specification, I became confused as while the
language did say the latter was repeatable, the rest used plural words
for things that cannot repeat. This changes the text to hopefully
prevent future folks from reaching the same misconclusion.

Fixes WebAssembly#1418

Signed-off-by: Adrian Cole <[email protected]>
Co-authored-by: Andreas Rossberg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant