Skip to content

Checking in .bin.wast #119

Open
Open

Description

@titzer

In maintaining https://github.com/titzer/wizard-engine, we made the decision to only parse .wast tests where the modules themselves are in binary, i.e. .bin.wast. This has been very helpful in avoiding both the work and potential incompatibilities with implementing our own parser for the entire text format. To date, Wizard's strategy has been to check out the spec repo and proposal repos, building their respective interpreters, and then generate the .bin.wast.

As it turns out, as proposals either stagnate or get their tests merged into the main spec, their respective repos get stuck with their respective toolchains (to wit, old versions of Ocaml, ocamlbuild, or dune).

I was wondering if there is any appetite for building the spec interpreter for each of the tracked proposals and then also building the .bin.wast outputs of them, and checking them in here automatically as part of the CI.

Activity

  1. alexcrichton commented on Feb 6, 2025

    @alexcrichton
    Contributor

    Personally I like the idea of lowering the barrier to entry to run the tests here, although if CI goes so far as to convert to *.bin.wast I'd say that it might be better to go as far as something like the output of wast2json where it's binaries + json which is, in principle, even easier to parser. That assumes that using your local language's json parser is likely easier than writing an s-expression parser, even if you're just parsing binary modules and not each individual instruction for example.

    To me though there's a lot of downsides in these ideas though. Building the spec interpreter in CI here is probably going to be very nontrivial (especially if each repo needs its own version of ocaml/dune/etc). Running something like wast2json is also nontrivial because it means that some tool (e.g. wast2json itself or some other tool like wasm-tools json-from-wast) has to support proposals before being integrated with this repository, which also isn't great. And there's also the issue of the exact json schema etc etc.

    One strong upside of this repo as-is is that the maintenance burden is quite low. Postprocessing *.wast is going to increase that no matter what and to me it'll be a game of minimizing that cost as much as possible.

  2. dschuff commented on Feb 6, 2025

    @dschuff
    Member

    Agreed that this would be nontrivial. I'll also add thought that something like this would be useful for importing wasm tests into WPT (Web Platform Tests). We currently have automation that uses the interpreter to convert the wast tests into binary and generate HTML/JS tests in the WPT style and import them. This currently works for things that get merged into the main branch but it would be nice to get them from proposals too, and there we'd have the same problem of needing either the interpreter from that branch, or another tool like Binaryen or wasm-tools.

  3. titzer commented on Mar 3, 2026

    @titzer
    Author

    @alexcrichton I think running the reference interpreter to generate .bin.wast in CI isn't too big of a burden, these are the lines in Wizard's CI:

    # Install Opam for specification tests
    sudo apt install -y opam
    opam init
    
    # Install spec test dependencies
    opam install dune
    opam install menhir -y
    opam install ocamlbuild # for older proposals
    # Make dune available in PATH
    eval $(opam config env)
    
    ...
    git clone git clone <repo> --depth 1
    cd <repo>/interpreter
    make
    ...
    <repo>/interpreter <test> -o <test>.bin.wast
    
    
  4. tlively commented on Mar 3, 2026

    @tlively
    Member

    If we can generate .bin.wast without installing multiple versions of OCaml and its packages, I would be in favor of doing so.

  5. rossberg commented on Mar 3, 2026

    @rossberg
    Member

    FWIW, in the spec repo itself it's now just these actions to build the reference interpreter:

          - uses: actions/checkout@v4
          - uses: ocaml/setup-ocaml@v3
            with:
              ocaml-compiler: 5.04.x
          - run: cd interpreter && opam exec make jsdeps wasm
    

    Edit: In your case, deps instead of jsdeps is probably enough.

  6. alexcrichton commented on Mar 3, 2026

    @alexcrichton
    Contributor

    My main worry w.r.t. ocaml is that each proposal might need a different version of ocaml if the spec interpreter ever updates. This is trying to pull together a whole bunch of proposal repos into one repo and they've all got their own version of the spec interpreter and different merge-base's with the main spec. I don't doubt that building one interpreter and getting some deps out isn't too bad, it's more the constellation of spec repos and getting them all to line up. That being said, though, I don't think it's problematic to at least try to generate *.bin.wast for the files we can, even if it can't cover everything. Getting the main body of tests I think would still be a good win.

    Orthogonal to that though, do y'all have thoughs a JSON-style approach? If the goal is to ingest an easier-to-parse form than the raw text format itself then I would suspect that parsing JSON is far easier than parsing *.bin.wast. I don't doubt that parsing *.bin.wast is easier than parsing the tests as-is, but if we're going to far as to make it easier for tools to ingest then this seems worthwhile to consider. I understand the spec interpreter does not have support for this right now, but that's something that seems tractable as I assume ocaml has some form of JSON serializer library to use.

  7. rossberg commented on Mar 3, 2026

    @rossberg
    Member

    I don't think you should ever need multiple versions of ocaml. The max required one should do, it's very backwards compatible.

  8. tlively commented on Mar 4, 2026

    @tlively
    Member

    Assuming that the JSON output would be a new feature built into the reference interpreter, it sounds like we would need to get the reference interpreter built on CI here either way. How about we start with the .bin.wast since the interpreter already supports that, then we can additionally add some JSON dump format once the interpreter supports that as well? I guess the only downside would be having more formats than we need at that point, but if all downstreams prefer the JSON, then we could just remove the .bin.wast.

  9. rossberg commented on Mar 4, 2026

    @rossberg
    Member

    https://seriot.ch/software/parsing_json.html — just sayin', since this thread is replicating the myth of JSON's alleged simplicity and portability.

  10. titzer commented on Mar 22, 2026

    @titzer
    Author

    I generally agree that adding JSON to the mix, even though it is already necessarily supported by web engines, doesn't make things easier for other engines. As it is, .wast is already complete, and (in my view) .bin.wast is a simplification of that format to just assertions and binaries. Even in the Claude era, fielding a (new) JSON parser for this purpose seems like overkill.

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