Skip to content

Commit

Permalink
Disable enabling reference types by default with the bundler target (#…
Browse files Browse the repository at this point in the history
…4235)

Update reference files to Rust v1.82.
  • Loading branch information
daxpedda authored Oct 31, 2024
1 parent 2f2ac1a commit 04d508b
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 158 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
* Optimized ABI performance for `Option<{i32,u32,isize,usize,f32,*const T,*mut T}>`.
[#4183](https://github.com/rustwasm/wasm-bindgen/pull/4183)

* Reference type proposal transformations are not applied by default when detecting it in the Wasm module for the bundler target because currently `webpack` doesn't support it.
[#4235](https://github.com/rustwasm/wasm-bindgen/pull/4235)

### Fixed

* Fixed methods with `self: &Self` consuming the object.
Expand Down
5 changes: 4 additions & 1 deletion crates/cli-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ impl Bindgen {
};

// Enable reference type transformations if the module is already using it.
if let Ok(true) = wasm_bindgen_wasm_conventions::target_feature(&module, "reference-types")
// Currently `webpack` does not support reference types.
if !matches!(self.mode, OutputMode::Bundler { .. })
&& wasm_bindgen_wasm_conventions::target_feature(&module, "reference-types").ok()
== Some(true)
{
self.externref = true;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/reference/add.wat
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
(export "memory" (memory 0))
(export "add_u32" (func $add_u32))
(export "add_i32" (func $add_i32))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/anyref-empty.wat
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
(export "memory" (memory 0))
(export "__wbindgen_export_0" (table 0))
(export "__wbindgen_start" (func 0))
(@custom "target_features" (after export) "\03+\0fmutable-globals+\08sign-ext+\0freference-types")
(@custom "target_features" (after export) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

22 changes: 3 additions & 19 deletions crates/cli/tests/reference/anyref-import-catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,16 @@ function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}

let cachedDataViewMemory0 = null;

function getDataViewMemory0() {
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
}
return cachedDataViewMemory0;
}

function takeFromExternrefTable0(idx) {
const value = wasm.__wbindgen_export_2.get(idx);
wasm.__externref_table_dealloc(idx);
return value;
}

export function exported() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.exported(retptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
if (r1) {
throw takeFromExternrefTable0(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
const ret = wasm.exported();
if (ret[1]) {
throw takeFromExternrefTable0(ret[0]);
}
}

Expand Down
18 changes: 8 additions & 10 deletions crates/cli/tests/reference/anyref-import-catch.wat
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
(module $reference_test.wasm
(type (;0;) (func))
(type (;1;) (func (result i32)))
(type (;2;) (func (param i32)))
(type (;3;) (func (param i32) (result i32)))
(type (;2;) (func (result i32 i32)))
(type (;3;) (func (param i32)))
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
(func $exported (;1;) (type 2) (param i32))
(func $__externref_table_dealloc (;2;) (type 2) (param i32))
(func $__externref_table_alloc (;3;) (type 1) (result i32))
(func $__wbindgen_exn_store (;4;) (type 2) (param i32))
(func $__wbindgen_add_to_stack_pointer (;5;) (type 3) (param i32) (result i32))
(func $__externref_table_dealloc (;1;) (type 3) (param i32))
(func $__externref_table_alloc (;2;) (type 1) (result i32))
(func $__wbindgen_exn_store (;3;) (type 3) (param i32))
(func $"exported multivalue shim" (;4;) (type 2) (result i32 i32))
(table (;0;) 128 externref)
(memory (;0;) 17)
(export "memory" (memory 0))
(export "exported" (func $exported))
(export "exported" (func $"exported multivalue shim"))
(export "__wbindgen_exn_store" (func $__wbindgen_exn_store))
(export "__externref_table_alloc" (func $__externref_table_alloc))
(export "__wbindgen_export_2" (table 0))
(export "__wbindgen_add_to_stack_pointer" (func $__wbindgen_add_to_stack_pointer))
(export "__externref_table_dealloc" (func $__externref_table_dealloc))
(export "__wbindgen_start" (func 0))
(@custom "target_features" (after code) "\03+\0fmutable-globals+\08sign-ext+\0freference-types")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/anyref-nop.wat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
(export "foo" (func $foo))
(export "__wbindgen_export_0" (table 0))
(export "__wbindgen_start" (func 0))
(@custom "target_features" (after code) "\03+\0fmutable-globals+\08sign-ext+\0freference-types")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/builder.wat
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
(export "memory" (memory 0))
(export "__wbg_classbuilder_free" (func $__wbg_classbuilder_free))
(export "classbuilder_builder" (func $classbuilder_builder))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/constructor.wat
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
(export "memory" (memory 0))
(export "__wbg_classconstructor_free" (func $__wbg_classconstructor_free))
(export "classconstructor_new" (func $classconstructor_new))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/empty.wat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module $reference_test.wasm
(memory (;0;) 16)
(export "memory" (memory 0))
(@custom "target_features" (after export) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after export) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/enums.wat
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
(export "option_enum_echo" (func $option_enum_echo))
(export "get_name" (func $get_name))
(export "option_string_enum_echo" (func $option_string_enum_echo))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

48 changes: 9 additions & 39 deletions crates/cli/tests/reference/getter-setter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}

let cachedDataViewMemory0 = null;

function getDataViewMemory0() {
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
}
return cachedDataViewMemory0;
}

function isLikeNone(x) {
return x === undefined || x === null;
}
Expand Down Expand Up @@ -129,61 +120,40 @@ export class Foo {
* @returns {number | undefined}
*/
get y() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.__wbg_get_foo_y(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
return r0 === 0 ? undefined : r1 >>> 0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
const ret = wasm.__wbg_get_foo_y(this.__wbg_ptr);
return ret === 0x100000001 ? undefined : ret;
}
/**
* @param {number | undefined} [arg0]
*/
set y(arg0) {
wasm.__wbg_set_foo_y(this.__wbg_ptr, !isLikeNone(arg0), isLikeNone(arg0) ? 0 : arg0);
wasm.__wbg_set_foo_y(this.__wbg_ptr, isLikeNone(arg0) ? 0x100000001 : (arg0) >>> 0);
}
/**
* @returns {number | undefined}
*/
get z() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.foo_z(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
return r0 === 0 ? undefined : r1 >>> 0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
const ret = wasm.foo_z(this.__wbg_ptr);
return ret === 0x100000001 ? undefined : ret;
}
/**
* @param {number | undefined} [z]
*/
set z(z) {
wasm.foo_set_z(this.__wbg_ptr, !isLikeNone(z), isLikeNone(z) ? 0 : z);
wasm.foo_set_z(this.__wbg_ptr, isLikeNone(z) ? 0x100000001 : (z) >>> 0);
}
/**
* @returns {number | undefined}
*/
get lone_getter() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.foo_lone_getter(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
return r0 === 0 ? undefined : r1 >>> 0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
const ret = wasm.foo_lone_getter(this.__wbg_ptr);
return ret === 0x100000001 ? undefined : ret;
}
/**
* @param {number | undefined} [value]
*/
set lone_setter(value) {
wasm.foo_set_lone_setter(this.__wbg_ptr, !isLikeNone(value), isLikeNone(value) ? 0 : value);
wasm.foo_set_lone_setter(this.__wbg_ptr, isLikeNone(value) ? 0x100000001 : (value) >>> 0);
}
/**
* You will only read numbers.
Expand Down
38 changes: 19 additions & 19 deletions crates/cli/tests/reference/getter-setter.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(type (;2;) (func (param i32) (result i32)))
(type (;3;) (func (param i32 i32)))
(type (;4;) (func (param i32 i32) (result i32)))
(type (;5;) (func (param i32 i32 i32)))
(type (;6;) (func (param i32 i32 i32 i32) (result i32)))
(func $__wbindgen_realloc (;0;) (type 6) (param i32 i32 i32 i32) (result i32))
(func $__wbindgen_malloc (;1;) (type 4) (param i32 i32) (result i32))
(func $__wbg_set_foo_y (;2;) (type 5) (param i32 i32 i32))
(func $__wbg_get_foo_y (;3;) (type 3) (param i32 i32))
(func $foo_z (;4;) (type 3) (param i32 i32))
(func $foo_lone_getter (;5;) (type 3) (param i32 i32))
(func $foo_set_weird (;6;) (type 5) (param i32 i32 i32))
(func $foo_set_z (;7;) (type 5) (param i32 i32 i32))
(func $foo_set_lone_setter (;8;) (type 5) (param i32 i32 i32))
(func $__wbg_get_foo_x (;9;) (type 2) (param i32) (result i32))
(func $__wbg_set_foo_x (;10;) (type 3) (param i32 i32))
(type (;3;) (func (param i32) (result f64)))
(type (;4;) (func (param i32 i32)))
(type (;5;) (func (param i32 i32) (result i32)))
(type (;6;) (func (param i32 i32 i32)))
(type (;7;) (func (param i32 i32 i32 i32) (result i32)))
(type (;8;) (func (param i32 f64)))
(func $__wbindgen_realloc (;0;) (type 7) (param i32 i32 i32 i32) (result i32))
(func $__wbindgen_malloc (;1;) (type 5) (param i32 i32) (result i32))
(func $foo_set_weird (;2;) (type 6) (param i32 i32 i32))
(func $__wbg_set_foo_y (;3;) (type 8) (param i32 f64))
(func $__wbg_get_foo_y (;4;) (type 3) (param i32) (result f64))
(func $__wbg_get_foo_x (;5;) (type 2) (param i32) (result i32))
(func $foo_set_z (;6;) (type 8) (param i32 f64))
(func $foo_set_lone_setter (;7;) (type 8) (param i32 f64))
(func $foo_z (;8;) (type 3) (param i32) (result f64))
(func $foo_lone_getter (;9;) (type 3) (param i32) (result f64))
(func $__wbg_set_foo_x (;10;) (type 4) (param i32 i32))
(func $foo_weird (;11;) (type 2) (param i32) (result i32))
(func $foo_x_static (;12;) (type 0) (result i32))
(func $__wbg_foo_free (;13;) (type 3) (param i32 i32))
(func $__wbg_foo_free (;13;) (type 4) (param i32 i32))
(func $foo_set_x_static (;14;) (type 1) (param i32))
(func $__wbindgen_add_to_stack_pointer (;15;) (type 2) (param i32) (result i32))
(memory (;0;) 17)
(export "memory" (memory 0))
(export "__wbg_foo_free" (func $__wbg_foo_free))
Expand All @@ -37,9 +38,8 @@
(export "foo_set_weird" (func $foo_set_weird))
(export "foo_x_static" (func $foo_x_static))
(export "foo_set_x_static" (func $foo_set_x_static))
(export "__wbindgen_add_to_stack_pointer" (func $__wbindgen_add_to_stack_pointer))
(export "__wbindgen_malloc" (func $__wbindgen_malloc))
(export "__wbindgen_realloc" (func $__wbindgen_realloc))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

22 changes: 3 additions & 19 deletions crates/cli/tests/reference/import-catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ function handleError(f, args) {
}
}

let cachedDataViewMemory0 = null;

function getDataViewMemory0() {
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
}
return cachedDataViewMemory0;
}

function getObject(idx) { return heap[idx]; }

function dropObject(idx) {
Expand All @@ -51,16 +42,9 @@ function takeObject(idx) {
}

export function exported() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.exported(retptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
const ret = wasm.exported();
if (ret[1]) {
throw takeObject(ret[0]);
}
}

Expand Down
14 changes: 6 additions & 8 deletions crates/cli/tests/reference/import-catch.wat
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
(module $reference_test.wasm
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32) (result i32)))
(func $exported (;0;) (type 0) (param i32))
(func $__wbindgen_exn_store (;1;) (type 0) (param i32))
(func $__wbindgen_add_to_stack_pointer (;2;) (type 1) (param i32) (result i32))
(type (;0;) (func (result i32 i32)))
(type (;1;) (func (param i32)))
(func $__wbindgen_exn_store (;0;) (type 1) (param i32))
(func $"exported multivalue shim" (;1;) (type 0) (result i32 i32))
(memory (;0;) 17)
(export "memory" (memory 0))
(export "exported" (func $exported))
(export "exported" (func $"exported multivalue shim"))
(export "__wbindgen_exn_store" (func $__wbindgen_exn_store))
(export "__wbindgen_add_to_stack_pointer" (func $__wbindgen_add_to_stack_pointer))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/nop.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
(memory (;0;) 17)
(export "memory" (memory 0))
(export "nop" (func $nop))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/pointers.wat
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
(export "memory" (memory 0))
(export "const_pointer" (func $const_pointer))
(export "mut_pointer" (func $mut_pointer))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/raw.wat
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
(export "__wbg_test_free" (func $__wbg_test_free))
(export "test_test1" (func $test_test1))
(export "test_test2" (func $test_test2))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

Loading

0 comments on commit 04d508b

Please sign in to comment.