Conversation
src/wasm/wasm-binary.cpp
Outdated
| uint32_t flags = hasMaximum ? 1 : 0; | ||
| void WasmBinaryWriter::writeResizableLimits(Address initial, Address maximum, | ||
| bool hasMaximum, bool shared) { | ||
| uint32_t flags = (uint32_t) hasMaximum | (uint32_t) shared << 1; |
There was a problem hiding this comment.
@binji This uses the 2nd bit as the "shared" bit, i.e
0x03 is the flags value for shared. https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#spec-changes says it's 0x11 but I'm wondering if you meant 0b11?
|
What are shared memories? Is this something new in wasm? Where are they supported? |
|
@kripken as specified in the threading proposal https://github.com/WebAssembly/threads |
| // gets a name in the combined function import+defined function space | ||
| Name getFunctionIndexName(Index i); | ||
| void getResizableLimits(Address& initial, Address& max, Address defaultIfNoMax); | ||
| void getResizableLimits(Address& initial, Address& max, bool& shared, Address defaultIfNoMax); |
There was a problem hiding this comment.
why not put it at the end? seems more natural there at first glance, maybe there's something I'm missing?
There was a problem hiding this comment.
The first 3 parameters are out-parameters, and the last one is an in-parameter, so I wanted to keep them together.
src/wasm/wasm-binary.cpp
Outdated
| auto flags = getU32LEB(); | ||
| initial = getU32LEB(); | ||
| bool hasMax = flags & 0x1; | ||
| bool is_shared = flags & 0x2; |
|
Thanks, now I understand the context here. |
auto_update_tests.py
Outdated
| f.close() | ||
| cmd = ['mozjs', 'a.js'] | ||
| out = run_command(cmd, stderr=subprocess.STDOUT) | ||
| open(os.path.join('test', 'binaryen.js', s + '.txt'), 'w').write(out) |
There was a problem hiding this comment.
Should we not be consistently using "with ... open as:" ?
There was a problem hiding this comment.
Yes, we probably should, but it's not common enough in this codebase. I'll fix this instance though since I'm touching it anyway.
| (module | ||
| (memory $0 23 256 shared) | ||
| ) | ||
|
|
There was a problem hiding this comment.
Why do some of these have a trailing newline?
There was a problem hiding this comment.
I think it's because wasm-dis prints an extra newline, whereas wasm-opt --print does not. Should maybe fix that in another PR.
auto_update_tests.py
Outdated
| f.write(open(os.path.join('bin', 'binaryen.js')).read()) | ||
| f.write(open(os.path.join('test', 'binaryen.js', s)).read()) | ||
| f.close() | ||
| cmd = ['mozjs', 'a.js'] |
There was a problem hiding this comment.
Should probably be cmd = [MOZJS, 'a.js']?
There was a problem hiding this comment.
OK, but If I make any more changes to this code I'm going to have to go build mozjs just so I can test it =-O
src/wasm/wasm-binary.cpp
Outdated
| uint32_t flags = hasMaximum ? 1 : 0; | ||
| void WasmBinaryWriter::writeResizableLimits(Address initial, Address maximum, | ||
| bool hasMaximum, bool shared) { | ||
| uint32_t flags = (uint32_t) hasMaximum | (uint32_t) shared << 1; |
There was a problem hiding this comment.
Instead of two bools in the signature, would it make sense to have a MemoryFlags enum?
enum MemoryFlags {
memoryHasMaximum = 1 << 0,
memoryIsShared = 1 << 1
};As it is now we're basically inlining the knowledge of the flag layout, which is probably less obvious in the future.
Failing that a link in a comment to the threads proposal might be good, because otherwise that's implicit knowledge.
There was a problem hiding this comment.
I dunno, the point of having the bools in the signature is to abstract away the encoding details from the caller (as with initial and maximum). But having bits explicit is good; I moved that to BinaryConsts
src/wasm/wasm-binary.cpp
Outdated
| case ExternalKind::Table: { | ||
| o << S32LEB(BinaryConsts::EncodedType::AnyFunc); | ||
| writeResizableLimits(wasm->table.initial, wasm->table.max, wasm->table.max != Table::kMaxSize); | ||
| writeResizableLimits(wasm->table.initial, wasm->table.max, wasm->table.max != Table::kMaxSize, false); |
There was a problem hiding this comment.
Instead of calling naked falses, would defaulting the param to false make sense?
There was a problem hiding this comment.
Hm I actually like the pattern of
writeResizeableLimits(..., .., ..., /*shared=*/false) here.
There was a problem hiding this comment.
That is also pretty reasonable
| cmd = ['mozjs', 'a.js'] | ||
| out = run_command(cmd, stderr=subprocess.STDOUT) | ||
| open(os.path.join('test', 'binaryen.js', s + '.txt'), 'w').write(out) | ||
| with open(os.path.join('test', 'binaryen.js', s + '.txt'), 'w') as o: o.write(out) |
There was a problem hiding this comment.
Nit: o.write(out) on its own line
There was a problem hiding this comment.
Every other instance of with in this file uses this pattern. I think it may have been a compromise between `you should use with instead of just open().write!' and 'but verbosity!'
There was a problem hiding this comment.
Yeah consistency > perfection. Seems fine
For now, just IR, wast, and binary support.