Skip to content

Refactor Host expression to MemorySize and MemoryGrow#3137

Merged
dcodeIO merged 3 commits into
WebAssembly:masterfrom
dcodeIO:host-refactor
Sep 17, 2020
Merged

Refactor Host expression to MemorySize and MemoryGrow#3137
dcodeIO merged 3 commits into
WebAssembly:masterfrom
dcodeIO:host-refactor

Conversation

@dcodeIO

@dcodeIO dcodeIO commented Sep 16, 2020

Copy link
Copy Markdown
Contributor

The complexity of the Host expression in the C and JS APIs has bugged me for quite a while, and in #3130 (comment) I was reminded of it, so I thought I may as well just refactor it to get it out of the way. Now aligns well with other memory instructions, passes can optimize memory.size away if unused, and the APIs are much simpler.

Comment thread src/ir/effects.h
@dcodeIO

dcodeIO commented Sep 16, 2020

Copy link
Copy Markdown
Contributor Author
Invocations so far:
   FuzzExec: 26917
   CompareVMs: 7320
   CheckDeterminism: 2327
   Wasm2JS: 6618
   Asyncify: 6903

ITERATION: 31718

@tlively tlively 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.

Thanks for doing this :)

Comment thread src/ir/effects.h

@tlively tlively 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.

Can you add readsMemory to memory.grow as well? It technically does a read-modify-write operation on the memory size in the successful case and just a read operation on the memory size in the failure case.

@dcodeIO

dcodeIO commented Sep 17, 2020

Copy link
Copy Markdown
Contributor Author
Invocations so far:
   FuzzExec: 12727
   CompareVMs: 3544
   CheckDeterminism: 1045
   Wasm2JS: 3104
   Asyncify: 3340

ITERATION: 15019

@dcodeIO dcodeIO merged commit 2841edd into WebAssembly:master Sep 17, 2020
@aardappel

Copy link
Copy Markdown
Contributor

This caused a ton of conflicts in #3130.. given that this was just a nice to have refactor, that could have waited.

@dcodeIO

dcodeIO commented Sep 17, 2020

Copy link
Copy Markdown
Contributor Author

Oh, sorry, I actually thought this would help to tackle the Host related issues. If you want, I can take a look at merging it into your PR?

@aardappel

Copy link
Copy Markdown
Contributor

I've already made all the changes.
It does not change the issue I mentioned in that PR, we still need to find a way to pass the current memory index type to those finalize calls.

@dcodeIO

dcodeIO commented Sep 17, 2020

Copy link
Copy Markdown
Contributor Author

Would it be possible to pass it upon construction of the respective expression and keep it as a field, like in the builder?

@aardappel

Copy link
Copy Markdown
Contributor

That would be fine with me.. @kripken does that sound acceptable? I guess the total number of memory.size / memory.grow ops will never affect total memory usage :)

@tlively

tlively commented Sep 17, 2020

Copy link
Copy Markdown
Member

I would add it as an argument to the finalize calls and force everyone that explicitly calls finalize on those expressions to supply it. That way it just has to be a field passed in the Builder or ReFinalize or ReFinalizeNode constructors.

@kripken

kripken commented Sep 17, 2020

Copy link
Copy Markdown
Member

Given these are rare nodes, memory isn't an issue, yeah. So it could be either way. I think I agree with @tlively that passing it to finalize makes sense (avoids duplicating info that could get stale).

@aardappel

Copy link
Copy Markdown
Contributor

@tlively that's what we had so far, but it was problematic, since finalize is called from sites that don't have the current memory/module already available.

@tlively

tlively commented Sep 17, 2020

Copy link
Copy Markdown
Member

@aardappel can you share a link to such a site in your PR?

@aardappel

Copy link
Copy Markdown
Contributor

@tlively it's in one of the comments on the PR #3130:

Ok, changed the way Host::finalize works and is called to satisfy the tests, but it is very broken. What really needs to happen is for it to use the current pointer size, which depends on the current memory/module, which is not accessible from most of these functions calling finalize. We could stick an is64 bool in the visitors calling this function, e.g. BinaryenExpressionFinalize would need to take a module argument, changing the JS API etc.

But I've already changed it to work the way @dcodeIO suggested.

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.

4 participants