Skip to content

Conversation

@sbc100
Copy link
Member

@sbc100 sbc100 commented Nov 5, 2020

This change is required for emscripten-core/emscripten#12323

@sbc100 sbc100 force-pushed the exported_memory branch 3 times, most recently from 6277f12 to 5333969 Compare November 6, 2020 07:07
@sbc100 sbc100 requested a review from kripken November 6, 2020 07:08
@sbc100
Copy link
Member Author

sbc100 commented Nov 7, 2020

I think this good to land now.

src/wasm2js.h Outdated
ast->push_back(
ValueBuilder::makeBinary(ValueBuilder::makeName("bufferView"),
SET,
ValueBuilder::makeName(HEAPU8)));
Copy link
Member

Choose a reason for hiding this comment

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

this creation of bufferView looks unconditional - whenever there is a memory at all. why is another one needed elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not a creation of anything but an assignment to the outer scoped bufferView

But you are right I think it needs to be conditional in the same way that bufferView itself is conditionally declared in the outer scope.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see, I was misreading it, sorry.


var memasmFunc = new ArrayBuffer(1507328);
var bufferView = new Uint8Array(memasmFunc);
var bufferView;
Copy link
Member

Choose a reason for hiding this comment

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

can we not remove this bufferView entirely, and just use HEAP8 which is guaranteed to exist?

Copy link
Member Author

Choose a reason for hiding this comment

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

See my TODO: We should probably just share a single HEAPU8 var. above.

I was thinking that could be a followup. Keeping this change slightly more limited.

Copy link
Member

Choose a reason for hiding this comment

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

This does make it harder to review, though, see the comment above with unconditional - it looks like the current PR is not emitting bufferView properly, but I may be missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we start to share HEAPU8 with the containing scope is that going to interfere with the emscripten-side that also defines a HEAPU8 itself? I mean that should always point to the same thing anyway so maybe its fine?

Copy link
Member Author

@sbc100 sbc100 Nov 10, 2020

Choose a reason for hiding this comment

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

Yes it looks like the wasm2js output shares a scope with the rest of emscripten, but asmFunc currently creates it own function-local versions of HEAP8, etc. This means that in emscripten output there are two copies of all these views today.

We should possibly merge those two (i.e. have the output HEAP8 be the same as the inner HEAP8), but I'd rather not worry about that as part of this change.

The asmFunc now sets the extern `bufferView` variable
as well as its own internal views.
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

This is fairly confusing (not because of you, but because the wasm2js output is complex with the different modes) but reading the outputs I've convinced myself it is correct.

@sbc100 sbc100 merged commit 32171f1 into master Nov 11, 2020
@sbc100 sbc100 deleted the exported_memory branch November 11, 2020 02:06
sbc100 added a commit to emscripten-core/emscripten that referenced this pull request Nov 11, 2020
This captures some minor code size win from (I belive)
WebAssembly/binaryen#3323
sbc100 added a commit to emscripten-core/emscripten that referenced this pull request Nov 12, 2020
Now that wasm2js supports memories defined on the wasm side
this seems to just work.

See: WebAssembly/binaryen#3323
sbc100 added a commit to emscripten-core/emscripten that referenced this pull request Nov 12, 2020
This captures some minor code size win from (I belive)
WebAssembly/binaryen#3323
sbc100 added a commit to emscripten-core/emscripten that referenced this pull request Nov 12, 2020
sbc100 added a commit to emscripten-core/emscripten that referenced this pull request Nov 12, 2020
Now that wasm2js supports memories defined on the wasm side
this seems to just work.

See: WebAssembly/binaryen#3323
sbc100 added a commit to emscripten-core/emscripten that referenced this pull request Nov 13, 2020
Now that wasm2js supports memories defined on the wasm side
this seems to just work.

See: WebAssembly/binaryen#3323
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.

3 participants