Skip to content

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

Closed

Description

@codefromthecrypt

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?

Activity

  1. codefromthecrypt commented on Feb 10, 2022

    @codefromthecrypt
    ContributorAuthor

    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.

  2. codefromthecrypt commented on Feb 10, 2022

    @codefromthecrypt
    ContributorAuthor

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

  3. codefromthecrypt commented on Feb 10, 2022

    @codefromthecrypt
    ContributorAuthor

    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.

  4. added a commit that references this issue on Feb 10, 2022
    9fa87ea
  5. codefromthecrypt commented on Feb 10, 2022

    @codefromthecrypt
    ContributorAuthor

    #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..

  6. added a commit that references this issue on Feb 14, 2022
    f58b501
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions