Skip to content

Commit 30da169

Browse files
committed
Stabilize wasm32 memory-related intrinsics
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!
1 parent 5facdde commit 30da169

File tree

3 files changed

+34
-42
lines changed

3 files changed

+34
-42
lines changed

coresimd/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ pub mod arch {
9090
/// See the [module documentation](../index.html) for more details.
9191
#[cfg(any(target_arch = "wasm32", dox))]
9292
#[doc(cfg(target_arch = "wasm32"))]
93-
#[unstable(feature = "stdsimd", issue = "27731")]
93+
#[stable(feature = "simd_wasm32", since = "1.33.0")]
9494
pub mod wasm32 {
95+
#[stable(feature = "simd_wasm32", since = "1.33.0")]
9596
pub use coresimd::wasm32::*;
9697
}
9798

coresimd/wasm32/memory.rs

+29-20
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,52 @@ extern "C" {
1313
/// Corresponding intrinsic to wasm's [`memory.size` instruction][instr]
1414
///
1515
/// This function, when called, will return the current memory size in units of
16-
/// pages.
16+
/// pages. The current WebAssembly page size is 65536 bytes (64 KB).
1717
///
1818
/// The argument `mem` is the numerical index of which memory to return the
19-
/// size of. Note that currently wasm only supports one memory, so specifying
20-
/// a nonzero value will likely result in a runtime validation error of the
21-
/// wasm module.
19+
/// size of. Note that currently the WebAssembly specification only supports one
20+
/// memory, so it is required that zero is passed in. The argument is present to
21+
/// be forward-compatible with future WebAssembly revisions. If a nonzero
22+
/// argument is passed to this function it will currently unconditionally abort.
2223
///
23-
/// [instr]: https://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
24+
/// [instr]: http://webassembly.github.io/spec/core/exec/instructions.html#exec-memory-size
2425
#[inline]
2526
#[cfg_attr(test, assert_instr("memory.size", mem = 0))]
2627
#[rustc_args_required_const(0)]
27-
pub unsafe fn size(mem: i32) -> i32 {
28-
if mem != 0 {
29-
::intrinsics::abort();
28+
#[stable(feature = "simd_wasm32", since = "1.33.0")]
29+
pub fn memory_size(mem: u32) -> usize {
30+
unsafe {
31+
if mem != 0 {
32+
::intrinsics::abort();
33+
}
34+
llvm_memory_size(0) as usize
3035
}
31-
llvm_memory_size(0)
3236
}
3337

3438
/// Corresponding intrinsic to wasm's [`memory.grow` instruction][instr]
3539
///
3640
/// This function, when called, will attempt to grow the default linear memory
37-
/// by the specified `delta` of pages. If memory is successfully grown then the
38-
/// previous size of memory, in pages, is returned. If memory cannot be grown
39-
/// then -1 is returned.
41+
/// by the specified `delta` of pages. The current WebAssembly page size is
42+
/// 65536 bytes (64 KB). If memory is successfully grown then the previous size
43+
/// of memory, in pages, is returned. If memory cannot be grown then
44+
/// `usize::max_value()` is returned.
4045
///
4146
/// The argument `mem` is the numerical index of which memory to return the
42-
/// size of. Note that currently wasm only supports one memory, so specifying
43-
/// a nonzero value will likely result in a runtime validation error of the
44-
/// wasm module.
47+
/// size of. Note that currently the WebAssembly specification only supports one
48+
/// memory, so it is required that zero is passed in. The argument is present to
49+
/// be forward-compatible with future WebAssembly revisions. If a nonzero
50+
/// argument is passed to this function it will currently unconditionally abort.
4551
///
46-
/// [instr]: https://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
52+
/// [instr]: http://webassembly.github.io/spec/core/exec/instructions.html#exec-memory-grow
4753
#[inline]
4854
#[cfg_attr(test, assert_instr("memory.grow", mem = 0))]
4955
#[rustc_args_required_const(0)]
50-
pub unsafe fn grow(mem: i32, delta: i32) -> i32 {
51-
if mem != 0 {
52-
::intrinsics::abort();
56+
#[stable(feature = "simd_wasm32", since = "1.33.0")]
57+
pub fn memory_grow(mem: u32, delta: usize) -> usize {
58+
unsafe {
59+
if mem != 0 {
60+
::intrinsics::abort();
61+
}
62+
llvm_memory_grow(0, delta as i32) as isize as usize
5363
}
54-
llvm_memory_grow(0, delta)
5564
}

coresimd/wasm32/mod.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,10 @@ use stdsimd_test::assert_instr;
1616
#[cfg(test)]
1717
use wasm_bindgen_test::wasm_bindgen_test;
1818

19-
#[inline]
20-
#[cfg_attr(test, assert_instr("memory.size"))]
21-
#[rustc_deprecated(reason = "renamed to memory::size", since = "1.30.0")]
22-
#[unstable(feature = "stdsimd", issue = "27731")]
23-
#[allow(deprecated)]
24-
#[doc(hidden)]
25-
pub unsafe fn current_memory() -> i32 {
26-
memory::size(0)
27-
}
28-
29-
#[inline]
30-
#[cfg_attr(test, assert_instr("memory.grow"))]
31-
#[rustc_deprecated(reason = "renamed to memory::grow", since = "1.30.0")]
32-
#[unstable(feature = "stdsimd", issue = "27731")]
33-
#[allow(deprecated)]
34-
#[doc(hidden)]
35-
pub unsafe fn grow_memory(delta: i32) -> i32 {
36-
memory::grow(0, delta)
37-
}
38-
3919
pub mod atomic;
40-
pub mod memory;
20+
21+
mod memory;
22+
pub use self::memory::*;
4123

4224
/// Generates the trap instruction `UNREACHABLE`
4325
#[cfg_attr(test, assert_instr(unreachable))]

0 commit comments

Comments
 (0)