-
Notifications
You must be signed in to change notification settings - Fork 787
Update wasm2asm to generate "almost asm" if grow_memory is used #1340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Do we need a flag here? Perhaps if memory growth is used, we can automatically do this and emit almost asm
?
test/wasm2asm.memory.js
Outdated
} | ||
|
||
return { | ||
memory: Object.create(Object.prototype, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this Object stuff needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because buffer needs to be a getter over the buffer var so we are exporting a living binding and Object.create supports an array of descriptors.
I will refactor to just automatically do it based on the presence of grow_memory and I'll fix the python linting rules. I used Object.create() because it is how you create with descriptors and need the buffer to be a getter so it reflects the replacement when memory grows. I could use the new es2015 shorthand instead |
50d0593
to
ce04f4c
Compare
This would be great to have for Glimmer, where we're targeting wasm but still need asm.js output for older browsers (we still support IE11, for now). |
src/wasm2asm.h
Outdated
@@ -205,11 +205,14 @@ class Wasm2AsmBuilder { | |||
// All our function tables have the same size TODO: optimize? | |||
size_t tableSize; | |||
|
|||
bool almostASM; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initializing this to false
could be done here, in the definition.
src/wasm2asm.h
Outdated
); | ||
} | ||
if (export_->kind == ExternalKind::Memory) { | ||
almostASM = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should depend on the presence of a memory export - maybe I'm missing something?
I think it should happen of growth is used, as I see later in the patch, and also the memory has an initial and a max value; if the max is larger than the initial, then growth is possible (from outside - maybe we don't care about that?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think asm.js exports can be anything other than functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is enforcing the maximum growth important for a first pass? The primary motivation is getting backward compatibility when targeting wasm first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean now, yeah, asm.js doesn't allow exporting the memory. However, I think we should just not export the memory - asm.js always imports (and never exports) the memory, no matter what wasm does, so that is always going to be different.
About enforcing the maximum growth, I agree, we can leave that for later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The export shims the WebAssembly.Memory interface and is also the only way to get the reassigned buffer post memory growth, the imported buffer is only the initial buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks, then I agree we need to export it and disable "use asm".
However, can we not do this if memory growth is disabled? I think it may be common to have a non-memory growth wasm module that exports a memory, and it would be better to not export it so that we can keep "use asm" for speed. But, a downside of that is we do something different depending on memory growth. Perhaps we can issue a warning, and/or have an option to ignore a memory export?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exporting memory allows for memory growth externally, via the grow function even if the module itself doesn't have grow_memory instructions. I will log a message when "almost asm" is triggered with the reason why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm excited for this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this looks great! All ready to merge I think, except for the logging just mentioned, which I don't think I see yet?
If grow_memory, current_memory or export memory is used then generate "almost asm" with memory growth support.
ce04f4c
to
e60dcb9
Compare
Thanks, looks good. Before we merge this, please join the wasm w3c community group https://www.w3.org/community/webassembly/participants |
While I'm sure @krisselden is happy to fill out another form, I'm curious @kripken: is there a reason that contributions to binaryen require joining a community group? |
I don't understand it myself, but it's what the WebAssembly group wanted, and this repo is under that org. It may have something to do with the w3c, @jfbastien knows all the details. |
The CG provides the legal protections for all technical contributions to WebAssembly and its projects. Most notably patent protection: see https://www.w3.org/community/about/agreements/summary/ for an overview and https://www.w3.org/community/about/agreements/cla/ for details. |
Is there some reason that this tool needs to live in this org and be under the W3C IPR policy (as opposed to a standalone repository licensed under Apache2?) Are any of the active contributors to this repository only active because of the fact that the repository is part of what WebAssembly umbrella and protected (specifically) by W3C IPR? |
@wycats sorry for missing this discussion. The title made me mark-as-read. Please consider forking this question to its own thread instead of tacking it onto this one. To answer your question: binaryen was started early in WebAssembly's history when much of the design was in flux, and it definitely provided significant input to what will become the final WebAssembly standard. I was one of the 4 CG chairs at the time, representing Google, and advice from representative companies' standards folks + lawyers, and W3C folks, was that WebAssembly contributions which affect the design must be under the W3C umbrella and contributors who provide significant input must be CG members. Binaryen fit that description and was therefore under the WebAssembly organization. Now that the design has settled more we could reconsider and put binaryen as well as other tools under their own organization. For example, the LLVM work now occurs directly in upstream LLVM. It remains true that significant contributions to the standard must come from CG members, but at this point tooling development doesn't influence the design as much as just get stuff working. If you want to float this idea I recommend filing an issue here, and adding an agenda item for the next CG video call (today's is a bit late, but I'll soon post an agenda for the next meeting, at which point a PR for this can be created). CG video calls are open to all CG members, I suggest this path because it seems like the choice of un-CG-ifying binaryen should be put to CG members. |
Microsoft already has signed a contribution agreement (as a member of the W3C), and we believe we are covered by that signed agreement. So can we submit without signing another agreement? |
ping @jfbastien for that legal question. |
Well, to my understanding that should be more than sufficient. I'll merge this in Monday unless someone objects. Thanks for your work and your patience here @krisselden! |
Emits "almost asm" if grow_memory, current_memory or export memory is used.