Skip to content
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

WebAssembly.Memory "index: u32/u64" constructor parameter #39

Merged
merged 5 commits into from
Aug 4, 2023

Conversation

dakenf
Copy link
Contributor

@dakenf dakenf commented Jul 13, 2023

Currently spec does not allow creating 64 bit memory from JS code, so there is no way to create a shared memory instance with more than 65,536 pages.

I propose to add an optional parameter that would create a 64 bit memory instance without those limits.

@sbc100
Copy link
Member

sbc100 commented Jul 26, 2023

Sounds like index: "u64" is what folks suggested in #24. Any reason not to go with that?

@dakenf
Copy link
Contributor Author

dakenf commented Jul 26, 2023

No, it's even better than my proposal. Will update the PR

@dakenf dakenf changed the title WebAssembly.Memory "memory64: bool" constructor parameter WebAssembly.Memory "index: u32/u64" constructor parameter Jul 26, 2023
@dakenf
Copy link
Contributor Author

dakenf commented Aug 1, 2023

I've fixed V8 to work with 64bit memory and threads. Except changes in WebAssembly.Memory there was also an issue with compiler that prevented passing i64.const to memory.fill and memory.init. I think I will clean up the code and make a PR in next few days. Can we get this reviewed and merged? I'm glad to make any changes to get it done

@backes
Copy link
Member

backes commented Aug 3, 2023

It looks like your CL to add Memory index type support in the JS API to V8 is your first contribution to V8 (https://crrev.com/c/4742982).
Or did you use another mail address before?

Anyway, we should land this PR before adding support in V8. Can you also add spec tests for the new parameter please?

@dakenf
Copy link
Contributor Author

dakenf commented Aug 3, 2023

It was my first contribution, will add the tests today

@dakenf
Copy link
Contributor Author

dakenf commented Aug 3, 2023

I've added JS tests. There were memory64 tests in test/core/bulk64._wast but they are disabled because the interpreter does not support memory.copy, fill and init operations. And as it's written in ocaml, i don't think i can add these op support in a reasonable time

const argument = { "initial": 1, "index": "u64" };
const memory = new WebAssembly.Memory(argument);
assert_Memory(memory, { "size": 1 });
assert_equals(memory.type().index, "u64");
Copy link
Member

Choose a reason for hiding this comment

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

This seems to depend on the js-types proposal: https://github.com/WebAssembly/js-types/blob/main/proposals/js-types/Overview.md . Is that intentional? I guess we should probably not depend on that as it is not complete yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. It's a WebAssembly.Memory method that returns "memory type" object:

var memory = new WebAssembly.Memory({ initial: 1, index: "u64"})
memory.type()

{minimum: 1, shared: false, index: 'u64'}

Copy link
Contributor Author

@dakenf dakenf Aug 3, 2023

Choose a reason for hiding this comment

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

Well, you are right. It's a part of the proposal. Should i remove these tests then? I guess i can keep "Unknown memory index" and just test that it creates something with different "index" arguments

Copy link
Member

Choose a reason for hiding this comment

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

I guess so yes, is there any other way to verify the type I wonder?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we could detect the presence of the type() method at runtime and leave a comment about how this depends on js-types proposal.

Also, I wonder if you could include the index check in assert_Memory so this could be a single line:

 assert_Memory(memory, { "size": 1, "index": "u64" });

Copy link
Member

Choose a reason for hiding this comment

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

You can check the index type by importing the memory as memory32 or memory64 and check which of those works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess so yes, is there any other way to verify the type I wonder?

Compile a small wasm test with 64bit memory.init, embed it into JS as UInt8Array and try running with that memory. But it looks like an overkill. WebAssembly.Memory does not export any other info to JS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's also a slight problem with checking type() as i did not think it's part of another proposal and updated V8 code to include the "index" field. So to include that, js-types proposal should be updated

Copy link
Member

Choose a reason for hiding this comment

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

I guess it will be part of whichever proposal lands first.

@dakenf
Copy link
Contributor Author

dakenf commented Aug 3, 2023

I went with the easy way, checked presence of type() method and updated assert_Memory to check the index value

Copy link
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM

}, "Shared memory with u32 index constructor");

test(() => {
const argument = { "initial": 1, "maximum": 2, "index": "u64", shared: true };
Copy link
Member

Choose a reason for hiding this comment

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

I think shared: true also comes from a spec that has yet to land (https://github.com/WebAssembly/threads) so I don't think we should test that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@sbc100 sbc100 merged commit 7cfa894 into WebAssembly:main Aug 4, 2023
@sbc100 sbc100 mentioned this pull request Aug 4, 2023
@sbc100
Copy link
Member

sbc100 commented Aug 23, 2023

Oh wait, I think we should have gone with i64/i32 here. This would be consistent with the JS types proposal (see https://github.com/WebAssembly/js-types/blob/main/proposals/js-types/Overview.md) and also with what spidermonkey apparently implement: #24 (comment)

@sbc100
Copy link
Member

sbc100 commented Aug 23, 2023

Sorry to flip flop on this.. I know I suggested 'u64' back in #39 (comment) but I think I was wrong.

@dakenf
Copy link
Contributor Author

dakenf commented Aug 24, 2023

Yeah, why not. I think i'm the only one who's using it right now so it won't hurt anyone. Will make a new changeset to V8

@backes backes mentioned this pull request Jun 5, 2024
backes added a commit to backes/wasm-spec-memory64 that referenced this pull request Jun 5, 2024
Similar to WebAssembly.Memory (WebAssembly#39), the WebAssembly.Table constructor
also needs an `index` argument.
sbc100 pushed a commit that referenced this pull request Jun 5, 2024
Similar to WebAssembly.Memory (#39), the WebAssembly.Table constructor
also needs an `index` argument.
bvisness pushed a commit to bvisness/memory64 that referenced this pull request Aug 1, 2024
Similar to WebAssembly.Memory (WebAssembly#39), the WebAssembly.Table constructor
also needs an `index` argument.
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