Skip to content

Update SIMD support - #1553

Merged
binji merged 5 commits into
WebAssembly:masterfrom
silvanshade:update-simd
Oct 26, 2020
Merged

binji merged 5 commits into
WebAssembly:masterfrom
silvanshade:update-simd

Conversation

@silvanshade

Copy link
Copy Markdown
Contributor

This PR updates SIMD support corresponding to changes in the WebAssembly/simd proposal repo from the following PRs:

WebAssembly/simd#321
WebAssembly/simd#322
WebAssembly/simd#341
WebAssembly/simd#344

This should not be merged until WebAssembly/testsuite#32 is merged since it needs the updated testsuite using the new syntax for the SIMD tests.

For the moment I have pointed the third_party/testsuite to my local branch which has the recent changes from WebAssembly/simd merged.

Note that in the PR I referenced for the WebAssembly/testsuite there will be additional (probably minor) breakage from recent changes in other proposal repos but I didn't include fixes for all of those here since I wanted this PR to focus on SIMD.

@silvanshade

Copy link
Copy Markdown
Contributor Author

I've updated the PR now that WebAssembly/testsuite has been synchronized with the WebAssembly/simd repo upstream.

All of the simd tests are still passing but one of the new (unrelated) tests pulled in from WebAssembly/spec does not pass and I'm not sure how to fix it.

The test is this one which was added from WebAssembly/spec#1213.

@aardappel

Copy link
Copy Markdown
Contributor

Looks like the func.wast test is still failing.. I was actually looking at that earlier, but no idea what the problem is.

Is this the root cause? out/test/spec/func.wast:448: expected module to be malformed: "out/test/spec/func/func.3.wat" ? Seems some quote modules where added.

@aardappel
aardappel requested a review from sbc100 October 2, 2020 23:35
@silvanshade

silvanshade commented Oct 3, 2020 •

Copy link
Copy Markdown
Contributor Author

Is this the root cause? out/test/spec/func.wast:448: expected module to be malformed: "out/test/spec/func/func.3.wat" ? Seems some quote modules where added.

@aardappel Yes, that's the one I wasn't sure how to fix either.

It's related to this issue: WebAssembly/spec#1213.

There's a similar test above it that doesn't use the quoted module (here) and that one does fail (correctly).

The problem seemingly has to do with the fact that the type index (here) is out of range and should trigger the malformed error for the quoted module, but doesn't.

Probably there is some sort of validation that has to happen when processing the quoted module to catch this but I don't understand enough about the internals of wabt to know how to fix it.

@aardappel

Copy link
Copy Markdown
Contributor

@rossberg (and @binji if around) any guidance what the new test in WebAssembly/spec#1213 is supposed to do? Both myself and @darinmorrison so far have failed to fix it in WABT (see error above).

@rossberg

rossberg commented Oct 5, 2020

Copy link
Copy Markdown
Member

@aardappel, can you be more specific? There is more than one test there.

@rossberg

rossberg commented Oct 5, 2020

Copy link
Copy Markdown
Member

Ah, sorry, didn't read up-thread. Let me look.

@rossberg

rossberg commented Oct 5, 2020

Copy link
Copy Markdown
Member

Okay, so the difference between this test and the preceding one is that the function also lists a parameter explicitly. This is a form of syntactic sugar in the text format alone, that has no correspondence in the binary format, and thus the AST. Consequently, it has to be desugared in the parser. But desugaring it requires knowing the actual type. So in order to do that, the parser (not just the validator) has to know and access the type definition for type 2 in this case, which doesn't exist. Since it's the parser failing this time, it produces malformed, not invalid.

It is rather annoying, but I'm not sure what the alternative could be, given that we have this sugar. What does wabt produce for this test atm?

@silvanshade

silvanshade commented Oct 5, 2020 •

Copy link
Copy Markdown
Contributor Author

What does wabt produce for this test atm?

@rossberg Currently wabt doesn't produce any error on the second test with the quoted module.

Okay, so the difference between this test and the preceding one is that the function also lists a parameter explicitly. This is a form of syntactic sugar in the text format alone, that has no correspondence in the binary format, and thus the AST. Consequently, it has to be desugared in the parser.

Alright, I think that makes sense.

I know almost nothing about the internals of wabt. This was my first PR, just intended to fix the SIMD tests for some other tools that use wabt downstream.

However, I think there may be something more fundamental going wrong with how wabt is handling the test because even if you remove the parameter (below) so that the quoted module is like the first test, it still gives no error:

(assert_invalid
  (module quote
    "(func $f (result f64) (f64.const 0))"  ;; adds implicit type definition
    "(func $g (param i32))"                 ;; reuses explicit type definition
    "(func $h (result f64) (f64.const 1))"  ;; reuses implicit type definition
    "(type $t (func (param i32)))"

    "(func (type 2))"  ;; does not exist
  )
  "unknown type"
)

Just to be clear, should the above give an invalid error? (Not malformed since it doesn't involve the desugaring?)

@rossberg

rossberg commented Oct 6, 2020

Copy link
Copy Markdown
Member

Yes, that should be invalid, just like the preceding test.

@aardappel

Copy link
Copy Markdown
Contributor

@darinmorrison any progress on fixing that last issue?

@silvanshade

Copy link
Copy Markdown
Contributor Author

@aardappel Unfortunately I don't really know how to fix that test. I think this will need some input from @binji or @sbc100 or some other maintainer who is more familiar with the internals of wabt.

@aardappel

Copy link
Copy Markdown
Contributor

Ok, I will have another look.

@aardappel

Copy link
Copy Markdown
Contributor

Ok, in CheckFuncTypeVarMatchesExplicit try adding this to the if (func_type) check:

    } else {
      errors->emplace_back(ErrorLevel::Error, loc, "type index out of range");
      result = Result::Error;

That made func.wast pass for me, and didn't seem to break any other tests.

@silvanshade

Copy link
Copy Markdown
Contributor Author

@aardappel Do you mean like this?

Result CheckFuncTypeVarMatchesExplicit(const Location& loc,
                                       const Module& module,
                                       const FuncDeclaration& decl,
                                       Errors* errors) {
  Result result = Result::Ok;
  if (decl.has_func_type) {
    const FuncType* func_type = module.GetFuncType(decl.type_var);
    if (func_type) {
      result |=
          CheckTypes(loc, decl.sig.result_types, func_type->sig.result_types,
                     "function", "result", errors);
      result |=
          CheckTypes(loc, decl.sig.param_types, func_type->sig.param_types,
                     "function", "argument", errors);
    } else {
      errors->emplace_back(ErrorLevel::Error, loc, "type index out of range");
      result = Result::Error;
    }
  }
  return result;
}

Maybe I'm missing something but when I re-run cmake --build out --target run-tests after that change, I get several new failing cases:

**** FAILED ******************************************************************
- test/spec/bulk-memory-operations/imports.txt
    /home/dwm/development/WebAssembly/wabt/out/wast2json out/test/spec/bulk-memory-operations/imports.wast -o out/test/spec/bulk-memory-operations/imports/imports.json --enable-bulk-memory
- test/spec/call_indirect.txt
    /home/dwm/development/WebAssembly/wabt/out/wast2json out/test/spec/call_indirect.wast -o out/test/spec/call_indirect/call_indirect.json
- test/spec/func.txt
    /home/dwm/development/WebAssembly/wabt/out/wast2json out/test/spec/func.wast -o out/test/spec/func/func.json
- test/spec/func_ptrs.txt
    /home/dwm/development/WebAssembly/wabt/out/wast2json out/test/spec/func_ptrs.wast -o out/test/spec/func_ptrs/func_ptrs.json
- test/spec/imports.txt
    /home/dwm/development/WebAssembly/wabt/out/wast2json out/test/spec/imports.wast -o out/test/spec/imports/imports.json
- test/spec/reference-types/call_indirect.txt
    /home/dwm/development/WebAssembly/wabt/out/wast2json out/test/spec/reference-types/call_indirect.wast -o out/test/spec/reference-types/call_indirect/call_indirect.json --enable-reference-types
- test/spec/reference-types/imports.txt
    /home/dwm/development/WebAssembly/wabt/out/wast2json out/test/spec/reference-types/imports.wast -o out/test/spec/reference-types/imports/imports.json --enable-reference-types
- test/wasm2c/spec/call_indirect.txt
    /usr/bin/python3 /home/dwm/development/WebAssembly/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec/call_indirect.txt --bindir=/home/dwm/development/WebAssembly/wabt/out --no-error-cmdline -o out/test/wasm2c/spec/call_indirect
- test/wasm2c/spec/func_ptrs.txt
    /usr/bin/python3 /home/dwm/development/WebAssembly/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec/func_ptrs.wast --bindir=/home/dwm/development/WebAssembly/wabt/out --no-error-cmdline -o out/test/wasm2c/spec/func_ptrs
- test/wasm2c/spec/func.txt
    /usr/bin/python3 /home/dwm/development/WebAssembly/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec/func.txt --bindir=/home/dwm/development/WebAssembly/wabt/out --no-error-cmdline -o out/test/wasm2c/spec/func
- test/wasm2c/spec/imports.txt
    /usr/bin/python3 /home/dwm/development/WebAssembly/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec/imports.wast --bindir=/home/dwm/development/WebAssembly/wabt/out --no-error-cmdline -o out/test/wasm2c/spec/imports
FAILED: CMakeFiles/run-tests 

For comparison, before the change (just with this current PR), this is the output I get:

**** FAILED ******************************************************************
- test/spec/func.txt
    /home/dwm/development/WebAssembly/wabt/out/spectest-interp out/test/spec/func/func.json
FAILED: CMakeFiles/run-tests 

Was there maybe another change that needed to be included?

@aardappel

Copy link
Copy Markdown
Contributor

Did you run run-tests.py -r to update outputs?

@silvanshade

Copy link
Copy Markdown
Contributor Author

Did you run run-tests.py -r to update outputs?

@aardappel Yes, I did try that with individual tests but I'm still getting errors.

Running run-tests.py -r produces the following:

**** FAILED ******************************************************************
- test/spec/bulk-memory-operations/imports.txt
    /home/dwm/development/WebAssembly/wabt/bin/wast2json out/test/spec/bulk-memory-operations/imports.wast -o out/test/spec/bulk-memory-operations/imports/imports.json --enable-bulk-memory
- test/spec/call_indirect.txt
    /home/dwm/development/WebAssembly/wabt/bin/wast2json out/test/spec/call_indirect.wast -o out/test/spec/call_indirect/call_indirect.json
- test/spec/func.txt
    /home/dwm/development/WebAssembly/wabt/bin/wast2json out/test/spec/func.wast -o out/test/spec/func/func.json
- test/spec/func_ptrs.txt
    /home/dwm/development/WebAssembly/wabt/bin/wast2json out/test/spec/func_ptrs.wast -o out/test/spec/func_ptrs/func_ptrs.json
- test/spec/imports.txt
    /home/dwm/development/WebAssembly/wabt/bin/wast2json out/test/spec/imports.wast -o out/test/spec/imports/imports.json
- test/spec/reference-types/call_indirect.txt
    /home/dwm/development/WebAssembly/wabt/bin/wast2json out/test/spec/reference-types/call_indirect.wast -o out/test/spec/reference-types/call_indirect/call_indirect.json --enable-reference-types
- test/spec/reference-types/imports.txt
    /home/dwm/development/WebAssembly/wabt/bin/wast2json out/test/spec/reference-types/imports.wast -o out/test/spec/reference-types/imports/imports.json --enable-reference-types
- test/wasm2c/spec/call_indirect.txt
    /usr/bin/python3 /home/dwm/development/WebAssembly/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec/call_indirect.txt --bindir=/home/dwm/development/WebAssembly/wabt/bin --no-error-cmdline -o out/test/wasm2c/spec/call_indirect
- test/wasm2c/spec/func.txt
    /usr/bin/python3 /home/dwm/development/WebAssembly/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec/func.txt --bindir=/home/dwm/development/WebAssembly/wabt/bin --no-error-cmdline -o out/test/wasm2c/spec/func
- test/wasm2c/spec/func_ptrs.txt
    /usr/bin/python3 /home/dwm/development/WebAssembly/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec/func_ptrs.wast --bindir=/home/dwm/development/WebAssembly/wabt/bin --no-error-cmdline -o out/test/wasm2c/spec/func_ptrs
- test/wasm2c/spec/imports.txt
    /usr/bin/python3 /home/dwm/development/WebAssembly/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec/imports.wast --bindir=/home/dwm/development/WebAssembly/wabt/bin --no-error-cmdline -o out/test/wasm2c/spec/imports

If you were able to get it to work (with the tests passing on CI), can you make your branch available? From that, I could just cherry-pick the commit into this PR.

@aardappel

Copy link
Copy Markdown
Contributor

weird, I don't get those errors, instead I get some remaining SIMD errors I haven't solved yet.. I may make a PR later and we can compare

@aardappel

Copy link
Copy Markdown
Contributor

Ok, my changes are here, and indeed also create these new wasm2c problems.. apparently because these don't run on Windows:
#1560

It may be easiest to wait until @binji is back rather than try to debug this further

@binji

binji commented Oct 21, 2020

Copy link
Copy Markdown
Member

Sorry for the long delay on resolving this. Is func.wast the only issue? If so, probably the easiest thing to do is change the expectation for that test to failure, and we can file a bug and resolve it separately.

It looks like other than this problem, the rest of the PR is relatively straightforward.

@silvanshade

Copy link
Copy Markdown
Contributor Author

@binji Yes, it's just the one test in func.wast. I think I can update the PR to expect that test to fail. Will take a look at that soon.

@silvanshade

Copy link
Copy Markdown
Contributor Author

@binji this should be good to go now I think.

@binji binji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for doing this! lgtm

@binji
binji merged commit 30af7af into WebAssembly:master Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants