Skip to content

WIP rename memory instructions#1652

Open
jayphelps wants to merge 4 commits intoWebAssembly:mainfrom
jayphelps:memory
Open

WIP rename memory instructions#1652
jayphelps wants to merge 4 commits intoWebAssembly:mainfrom
jayphelps:memory

Conversation

@jayphelps
Copy link
Contributor

NOT READY FOR REVIEW

To align with the latest spec we need to rename the memory instructions

  • grow_memory -> memory.grow
  • current_memory -> memory.size

This PR is a very early WIP towards that goal, however as changes to the upstream spec testsuite binaryen uses has changed in other ways as well this PR will likely need to contain other fixes to accommodate. I'll list them as I find them, if any. Numerous spec tests now mix stack/sexprs which binaryen doesn't support so I'm attempting to modify them upstream to be 100% sexprs.


This PR also will eventually unblock #1644 which is also waiting on a spec testsuite update

if (str[7] == 'g') return makeHost(s, HostOp::MemoryGrow);
abort_on(str);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the changes so far are naive find-and-replaces with case sensitivity. I've fixed a few spots where I found that it made things incorrect. e.g. memory.size() vs memory_size() but there might be others.

This was one such spot, where I needed to change the parser itself because it assumed that anything with a dot was i32|i64|f32|f64 operations.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, yeah, that's what I was thinking before I saw this comment.

In general I'd say if the test suite passes we should be good - we have good coverage of this stuff.

@jayphelps
Copy link
Contributor Author

Should we keep support for the old instruction names in wat/wast parsers? FWIW wabt did

@kripken
Copy link
Member

kripken commented Aug 30, 2018

Personally I don't think it's important for us to support the old names - I think wabt is what most people use for reading wat files, so makes more sense there, while here our text parsing isn't spec-compliant for other reasons anyhow.

@kripken
Copy link
Member

kripken commented Aug 30, 2018

About the spec tests, as mentioned in the other PR, I'd be fine to replace the git submodule with just a directory of the files in their current state, then modify them for changes like this. (For the same reason as not supporting the old notation - our text format kind of diverged anyhow; may make sense one day to harmonize them, but really we are focused on the binary format here, and just use spec tests for test purposes.)

@jayphelps
Copy link
Contributor Author

@kripken cool. I had started to go down the road of finding and fixing them but I just keep finding more divergences. What I'm gonna do is comment out the ones that binaryen does not support, with a comment--sound good?

@jayphelps
Copy link
Contributor Author

jayphelps commented Aug 30, 2018

btw I noticed one example in the spec tests where I think mixing AST/stack syntaxes can be ambiguous. This may not be news to everyone else, but I thought it was interesting.

(func (export "as-return-value") (result i32)
  (block (result i32)
    (i32.const 1)
  )
  (return)
)

;; vs.

(func (export "as-return-value")
  (block (result i32)
    (i32.const 1)
  )
  (return)
)

Binaryen parses the first one fine, but it fails validation because in AST form it's an empty return, whereas in parsers that support mixed AST/stack form like wabt, the block's value is used as the return operand but if and only if the function has a result signature expecting one, otherwise it's treated as an empty return ignoring the block value. 🤯If I'm wrong, lmk.

@kripken
Copy link
Member

kripken commented Aug 30, 2018

What I'm gonna do is comment out the ones that binaryen does not support, with a comment--sound good?

Yeah, sounds good.

And yeah, you're right about that example - it's pretty weird I think that in wat format you can write (return) or (call) and it uses operands from before. It's basically there for backwards compatibility due to how wasm used to not be a stack machine. Anyhow, yeah, binaryen parses only pure s-expressions, so it is expected that weird stuff like that will parse differently/wrongly.

@jayphelps
Copy link
Contributor Author

@kripken Made more progress but I can't seem to figure out this latest error. It's not clear where these fail functions come from or why this particular test is failing. I manually ran it and I believe it's returning 31353 instead of the expected 122. I believe these are new tests pulled in from test/spec, but I didn't comment this particular one out because it passed the wasm tests.

Curious if something immediately jumps out at you?

(See Travis or below)

executing:  install/bin/wasm2js /home/travis/build/WebAssembly/binaryen/test/spec/address.wast
executing:  install/bin/wasm2js /home/travis/build/WebAssembly/binaryen/test/spec/address.wast --allow-asserts
skipping ( assert_trap ( invoke 32_good5 ( i32.const 65508 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 8u_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 8s_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 16u_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 16s_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 32_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 8u_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 8s_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 16u_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 16s_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 32_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_malformed ( module quote (memory 1) (func (drop (i32.load offset=4294967296 (i32.const 0)))) ) i32 constant )
skipping ( assert_trap ( invoke 64_good5 ( i32.const 65504 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 8u_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 8s_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 16u_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 16s_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 32u_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 32s_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 64_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 8u_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 8s_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 16u_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 16s_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 32u_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 32s_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 64_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 32_good5 ( i32.const 65525 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 32_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 32_bad ( i32.const 1 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 64_good5 ( i32.const 65511 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 64_bad ( i32.const 0 ) ) out of bounds memory access )
skipping ( assert_trap ( invoke 64_bad ( i32.const 1 ) ) out of bounds memory access )
executing:  /home/travis/.nvm/versions/node/v10.9.0/bin/node --experimental-modules --loader ./scripts/test/node-esm-loader.mjs a.2asm.mjs
(node:45693) ExperimentalWarning: The ESM module loader is experimental.
executing:  /home/travis/.nvm/versions/node/v10.9.0/bin/node --experimental-modules --loader ./scripts/test/node-esm-loader.mjs a.2asm.asserts.mjs
Traceback (most recent call last):
  File "./check.py", line 691, in <module>
    sys.exit(main())
  File "./check.py", line 667, in main
    wasm2js.test_wasm2js()
  File "/home/travis/build/WebAssembly/binaryen/scripts/test/wasm2js.py", line 105, in test_wasm2js
    test_wasm2js_output()
  File "/home/travis/build/WebAssembly/binaryen/scripts/test/wasm2js.py", line 80, in test_wasm2js_output
    out = run_command(cmd, expected_err='', err_ignore='The ESM module loader is experimental')
  File "/home/travis/build/WebAssembly/binaryen/scripts/test/support.py", line 160, in run_command
    raise Exception(('run_command failed (%s)' % code, out + str(err or '')))
Exception: ('run_command failed (1)', '(node:45703) ExperimentalWarning: The ESM module loader is experimental.\nReferenceError: fail15 is not defined\n    at file:///home/travis/build/WebAssembly/binaryen/a.2asm.asserts.mjs:346:17\n    at ModuleJob.run (internal/modules/esm/module_job.js:96:12)\n')
function $14(i) { // 16u_good5
  i = i | 0;
  return HEAPU16[(i + 25 | 0) >> 1] | 0 | 0;
}
// ... etc ...
function check15() {
 return (retasmFunc.$16u_good5(0 | 0) | 0 | 0) == (122 | 0) | 0;
}

if (!check15()) fail15();
(func (export "16u_good5") (param $i i32) (result i64)
  (i64.load16_u offset=25 align=2 (get_local $i))        ;; 122 'z\0'
)
;; ... etc ...
(assert_return (invoke "16u_good5" (i32.const 0)) (i32.const 122))

@kripken
Copy link
Member

kripken commented Sep 4, 2018

Do you see the failure locally too?

In the past I saw an odd failure in those tests that was fixed by upgrading node. But likely unrelated.

It might be best to do a separate PR for "flattening" the spec tests, starting with changing nothing but removing the submodule. Then the PR for renaming memory operations would be a lot smaller (just the actual renaming + a few spec test changes) and we could be sure it isn't something that went wrong with the spec test changes.

@jayphelps
Copy link
Contributor Author

Happens locally too. Saw that other ticket mentioning node 10. I tried various versions of node, including latest.

I’ll make a separate PR for the submodule—it’s already in a separate commit so it’s easy 🤙

Base automatically changed from master to main January 19, 2021 21:59
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.

2 participants