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

Stabilize wasm32 memory-related intrinsics #613

Merged
merged 1 commit into from
Dec 10, 2018

Conversation

alexcrichton
Copy link
Member

This commit stabilizes the wasm32 memory-related intrinsics, as
specified in rust-lang/rust#56292. The old intrinsics were removed and
the current intrinsics were updated in place, but it's the last breaking
change!

Copy link
Contributor

@gnzlbg gnzlbg left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -47,9 +48,10 @@ pub unsafe fn size(mem: i32) -> i32 {
#[inline]
#[cfg_attr(test, assert_instr("memory.grow", mem = 0))]
#[rustc_args_required_const(0)]
pub unsafe fn grow(mem: i32, delta: i32) -> i32 {
#[stable(feature = "simd_wasm32", since = "1.33.0")]
pub unsafe fn memory_grow(mem: u32, delta: usize) -> isize {
Copy link
Member

Choose a reason for hiding this comment

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

memory.grow conceptually returns the value that memory.size would return after the resize, which suggests that it should be usize rather than isize (with the error value being usize::MAX rather than -1). However, I don't think it'll make a big difference in practice, so I don't feel strongly about it.

Copy link
Contributor

@gnzlbg gnzlbg Dec 10, 2018

Choose a reason for hiding this comment

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

Good point. User programs can use as to go either way anyways, and to me it feels that both approaches have downsides - using isize might mean that negative values might indicate success, while using usize will confuse those trying to use -1 here to catch errors like the spec suggests =/

Using usize here and updating the docs to suggest using usize::MAX feels like the lesser evil.

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds reasonable to me! I've switched to usize and documented the return value on failure. Thanks for the suggestions @sunfishcode!

This commit stabilizes the wasm32 memory-related intrinsics, as
specified in rust-lang/rust#56292. The old intrinsics were removed and
the current intrinsics were updated in place, but it's the last breaking
change!
@alexcrichton alexcrichton merged commit 3c0503d into rust-lang:master Dec 10, 2018
@alexcrichton alexcrichton deleted the wasm32-memory branch December 10, 2018 19:53
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