Skip to content

Commit d95052d

Browse files
committed
Revert bundler target specific default transformations webpack now supports the reference type proposal.
1 parent f1d60ab commit d95052d

32 files changed

+392
-224
lines changed

CHANGELOG.md

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
* Optimized ABI performance for `Option<{i32,u32,isize,usize,f32,*const T,*mut T}>`.
2929
[#4183](https://github.com/rustwasm/wasm-bindgen/pull/4183)
3030

31-
* 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.
32-
[#4235](https://github.com/rustwasm/wasm-bindgen/pull/4235)
33-
3431
* Deprecate `--reference-types` in favor of automatic target feature detection.
3532
[#4237](https://github.com/rustwasm/wasm-bindgen/pull/4237)
3633

crates/cli-support/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,7 @@ impl Bindgen {
325325
};
326326

327327
// Enable reference type transformations if the module is already using it.
328-
// Currently `webpack` does not support reference types.
329-
if !matches!(self.mode, OutputMode::Bundler { .. })
330-
&& wasm_bindgen_wasm_conventions::target_feature(&module, "reference-types").ok()
331-
== Some(true)
328+
if let Ok(true) = wasm_bindgen_wasm_conventions::target_feature(&module, "reference-types")
332329
{
333330
self.externref = true;
334331
}

crates/cli/tests/reference/add.js

+11
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ export function add_i32(a, b) {
2323
return ret;
2424
}
2525

26+
export function __wbindgen_init_externref_table() {
27+
const table = wasm.__wbindgen_export_0;
28+
const offset = table.grow(4);
29+
table.set(0, undefined);
30+
table.set(offset + 0, undefined);
31+
table.set(offset + 1, null);
32+
table.set(offset + 2, true);
33+
table.set(offset + 3, false);
34+
;
35+
};
36+

crates/cli/tests/reference/add.wat

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
(module $reference_test.wasm
2-
(type (;0;) (func (param i32 i32) (result i32)))
3-
(func $add_u32 (;0;) (type 0) (param i32 i32) (result i32))
4-
(func $add_i32 (;1;) (type 0) (param i32 i32) (result i32))
2+
(type (;0;) (func))
3+
(type (;1;) (func (param i32 i32) (result i32)))
4+
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
5+
(func $add_u32 (;1;) (type 1) (param i32 i32) (result i32))
6+
(func $add_i32 (;2;) (type 1) (param i32 i32) (result i32))
7+
(table (;0;) 128 externref)
58
(memory (;0;) 17)
69
(export "memory" (memory 0))
710
(export "add_u32" (func $add_u32))
811
(export "add_i32" (func $add_i32))
12+
(export "__wbindgen_export_0" (table 0))
13+
(export "__wbindgen_start" (func 0))
914
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
1015
)
1116

crates/cli/tests/reference/builder.js

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ export class ClassBuilder {
5858
}
5959
}
6060

61+
export function __wbindgen_init_externref_table() {
62+
const table = wasm.__wbindgen_export_0;
63+
const offset = table.grow(4);
64+
table.set(0, undefined);
65+
table.set(offset + 0, undefined);
66+
table.set(offset + 1, null);
67+
table.set(offset + 2, true);
68+
table.set(offset + 3, false);
69+
;
70+
};
71+
6172
export function __wbindgen_throw(arg0, arg1) {
6273
throw new Error(getStringFromWasm0(arg0, arg1));
6374
};
+9-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
(module $reference_test.wasm
2-
(type (;0;) (func (result i32)))
3-
(type (;1;) (func (param i32 i32)))
4-
(func $__wbg_classbuilder_free (;0;) (type 1) (param i32 i32))
5-
(func $classbuilder_builder (;1;) (type 0) (result i32))
2+
(type (;0;) (func))
3+
(type (;1;) (func (result i32)))
4+
(type (;2;) (func (param i32 i32)))
5+
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
6+
(func $__wbg_classbuilder_free (;1;) (type 2) (param i32 i32))
7+
(func $classbuilder_builder (;2;) (type 1) (result i32))
8+
(table (;0;) 128 externref)
69
(memory (;0;) 17)
710
(export "memory" (memory 0))
811
(export "__wbg_classbuilder_free" (func $__wbg_classbuilder_free))
912
(export "classbuilder_builder" (func $classbuilder_builder))
13+
(export "__wbindgen_export_0" (table 0))
14+
(export "__wbindgen_start" (func 0))
1015
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
1116
)
1217

crates/cli/tests/reference/constructor.js

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ export class ClassConstructor {
4949
}
5050
}
5151

52+
export function __wbindgen_init_externref_table() {
53+
const table = wasm.__wbindgen_export_0;
54+
const offset = table.grow(4);
55+
table.set(0, undefined);
56+
table.set(offset + 0, undefined);
57+
table.set(offset + 1, null);
58+
table.set(offset + 2, true);
59+
table.set(offset + 3, false);
60+
;
61+
};
62+
5263
export function __wbindgen_throw(arg0, arg1) {
5364
throw new Error(getStringFromWasm0(arg0, arg1));
5465
};
+9-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
(module $reference_test.wasm
2-
(type (;0;) (func (result i32)))
3-
(type (;1;) (func (param i32 i32)))
4-
(func $__wbg_classconstructor_free (;0;) (type 1) (param i32 i32))
5-
(func $classconstructor_new (;1;) (type 0) (result i32))
2+
(type (;0;) (func))
3+
(type (;1;) (func (result i32)))
4+
(type (;2;) (func (param i32 i32)))
5+
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
6+
(func $__wbg_classconstructor_free (;1;) (type 2) (param i32 i32))
7+
(func $classconstructor_new (;2;) (type 1) (result i32))
8+
(table (;0;) 128 externref)
69
(memory (;0;) 17)
710
(export "memory" (memory 0))
811
(export "__wbg_classconstructor_free" (func $__wbg_classconstructor_free))
912
(export "classconstructor_new" (func $classconstructor_new))
13+
(export "__wbindgen_export_0" (table 0))
14+
(export "__wbindgen_start" (func 0))
1015
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
1116
)
1217

crates/cli/tests/reference/empty.js

+12
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,15 @@ export function __wbg_set_wasm(val) {
33
wasm = val;
44
}
55

6+
7+
export function __wbindgen_init_externref_table() {
8+
const table = wasm.__wbindgen_export_0;
9+
const offset = table.grow(4);
10+
table.set(0, undefined);
11+
table.set(offset + 0, undefined);
12+
table.set(offset + 1, null);
13+
table.set(offset + 2, true);
14+
table.set(offset + 3, false);
15+
;
16+
};
17+

crates/cli/tests/reference/empty.wat

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
(module $reference_test.wasm
2+
(type (;0;) (func))
3+
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
4+
(table (;0;) 128 externref)
25
(memory (;0;) 16)
36
(export "memory" (memory 0))
7+
(export "__wbindgen_export_0" (table 0))
8+
(export "__wbindgen_start" (func 0))
49
(@custom "target_features" (after export) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
510
)
611

crates/cli/tests/reference/enums.js

+11
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ export const ImplicitDiscriminant = Object.freeze({
9292

9393
const __wbindgen_enum_ColorName = ["green", "yellow", "red"];
9494

95+
export function __wbindgen_init_externref_table() {
96+
const table = wasm.__wbindgen_export_0;
97+
const offset = table.grow(4);
98+
table.set(0, undefined);
99+
table.set(offset + 0, undefined);
100+
table.set(offset + 1, null);
101+
table.set(offset + 2, true);
102+
table.set(offset + 3, false);
103+
;
104+
};
105+
95106
export function __wbindgen_throw(arg0, arg1) {
96107
throw new Error(getStringFromWasm0(arg0, arg1));
97108
};

crates/cli/tests/reference/enums.wat

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
(module $reference_test.wasm
2-
(type (;0;) (func (param i32) (result i32)))
3-
(func $enum_echo (;0;) (type 0) (param i32) (result i32))
4-
(func $option_enum_echo (;1;) (type 0) (param i32) (result i32))
5-
(func $get_name (;2;) (type 0) (param i32) (result i32))
6-
(func $option_string_enum_echo (;3;) (type 0) (param i32) (result i32))
2+
(type (;0;) (func))
3+
(type (;1;) (func (param i32) (result i32)))
4+
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
5+
(func $enum_echo (;1;) (type 1) (param i32) (result i32))
6+
(func $option_enum_echo (;2;) (type 1) (param i32) (result i32))
7+
(func $get_name (;3;) (type 1) (param i32) (result i32))
8+
(func $option_string_enum_echo (;4;) (type 1) (param i32) (result i32))
9+
(table (;0;) 128 externref)
710
(memory (;0;) 17)
811
(export "memory" (memory 0))
912
(export "enum_echo" (func $enum_echo))
1013
(export "option_enum_echo" (func $option_enum_echo))
1114
(export "get_name" (func $get_name))
1215
(export "option_string_enum_echo" (func $option_string_enum_echo))
16+
(export "__wbindgen_export_0" (table 0))
17+
(export "__wbindgen_start" (func 0))
1318
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
1419
)
1520

crates/cli/tests/reference/getter-setter.js

+11
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ export class Foo {
191191
}
192192
}
193193

194+
export function __wbindgen_init_externref_table() {
195+
const table = wasm.__wbindgen_export_0;
196+
const offset = table.grow(4);
197+
table.set(0, undefined);
198+
table.set(offset + 0, undefined);
199+
table.set(offset + 1, null);
200+
table.set(offset + 2, true);
201+
table.set(offset + 3, false);
202+
;
203+
};
204+
194205
export function __wbindgen_throw(arg0, arg1) {
195206
throw new Error(getStringFromWasm0(arg0, arg1));
196207
};
+29-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
(module $reference_test.wasm
2-
(type (;0;) (func (result i32)))
3-
(type (;1;) (func (param i32)))
4-
(type (;2;) (func (param i32) (result i32)))
5-
(type (;3;) (func (param i32) (result f64)))
6-
(type (;4;) (func (param i32 i32)))
7-
(type (;5;) (func (param i32 i32) (result i32)))
8-
(type (;6;) (func (param i32 i32 i32)))
9-
(type (;7;) (func (param i32 i32 i32 i32) (result i32)))
10-
(type (;8;) (func (param i32 f64)))
11-
(func $__wbindgen_realloc (;0;) (type 7) (param i32 i32 i32 i32) (result i32))
12-
(func $__wbindgen_malloc (;1;) (type 5) (param i32 i32) (result i32))
13-
(func $foo_set_weird (;2;) (type 6) (param i32 i32 i32))
14-
(func $__wbg_set_foo_y (;3;) (type 8) (param i32 f64))
15-
(func $__wbg_get_foo_y (;4;) (type 3) (param i32) (result f64))
16-
(func $__wbg_get_foo_x (;5;) (type 2) (param i32) (result i32))
17-
(func $foo_set_z (;6;) (type 8) (param i32 f64))
18-
(func $foo_set_lone_setter (;7;) (type 8) (param i32 f64))
19-
(func $foo_z (;8;) (type 3) (param i32) (result f64))
20-
(func $foo_lone_getter (;9;) (type 3) (param i32) (result f64))
21-
(func $__wbg_set_foo_x (;10;) (type 4) (param i32 i32))
22-
(func $foo_weird (;11;) (type 2) (param i32) (result i32))
23-
(func $foo_x_static (;12;) (type 0) (result i32))
24-
(func $__wbg_foo_free (;13;) (type 4) (param i32 i32))
25-
(func $foo_set_x_static (;14;) (type 1) (param i32))
2+
(type (;0;) (func))
3+
(type (;1;) (func (result i32)))
4+
(type (;2;) (func (param i32)))
5+
(type (;3;) (func (param i32) (result i32)))
6+
(type (;4;) (func (param i32) (result f64)))
7+
(type (;5;) (func (param i32 i32)))
8+
(type (;6;) (func (param i32 i32) (result i32)))
9+
(type (;7;) (func (param i32 i32 i32)))
10+
(type (;8;) (func (param i32 i32 i32 i32) (result i32)))
11+
(type (;9;) (func (param i32 f64)))
12+
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
13+
(func $__wbindgen_realloc (;1;) (type 8) (param i32 i32 i32 i32) (result i32))
14+
(func $__wbindgen_malloc (;2;) (type 6) (param i32 i32) (result i32))
15+
(func $foo_set_weird (;3;) (type 7) (param i32 i32 i32))
16+
(func $__wbg_set_foo_y (;4;) (type 9) (param i32 f64))
17+
(func $__wbg_get_foo_y (;5;) (type 4) (param i32) (result f64))
18+
(func $__wbg_get_foo_x (;6;) (type 3) (param i32) (result i32))
19+
(func $foo_set_z (;7;) (type 9) (param i32 f64))
20+
(func $foo_set_lone_setter (;8;) (type 9) (param i32 f64))
21+
(func $foo_z (;9;) (type 4) (param i32) (result f64))
22+
(func $foo_lone_getter (;10;) (type 4) (param i32) (result f64))
23+
(func $__wbg_set_foo_x (;11;) (type 5) (param i32 i32))
24+
(func $foo_weird (;12;) (type 3) (param i32) (result i32))
25+
(func $foo_x_static (;13;) (type 1) (result i32))
26+
(func $__wbg_foo_free (;14;) (type 5) (param i32 i32))
27+
(func $foo_set_x_static (;15;) (type 2) (param i32))
28+
(table (;0;) 128 externref)
2629
(memory (;0;) 17)
2730
(export "memory" (memory 0))
2831
(export "__wbg_foo_free" (func $__wbg_foo_free))
@@ -38,8 +41,10 @@
3841
(export "foo_set_weird" (func $foo_set_weird))
3942
(export "foo_x_static" (func $foo_x_static))
4043
(export "foo_set_x_static" (func $foo_set_x_static))
44+
(export "__wbindgen_export_0" (table 0))
4145
(export "__wbindgen_malloc" (func $__wbindgen_malloc))
4246
(export "__wbindgen_realloc" (func $__wbindgen_realloc))
47+
(export "__wbindgen_start" (func 0))
4348
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
4449
)
4550

crates/cli/tests/reference/import-catch.js

+42-23
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,70 @@ export function __wbg_set_wasm(val) {
44
}
55

66

7-
const heap = new Array(128).fill(undefined);
8-
9-
heap.push(undefined, null, true, false);
10-
11-
let heap_next = heap.length;
12-
13-
function addHeapObject(obj) {
14-
if (heap_next === heap.length) heap.push(heap.length + 1);
15-
const idx = heap_next;
16-
heap_next = heap[idx];
17-
18-
heap[idx] = obj;
7+
function addToExternrefTable0(obj) {
8+
const idx = wasm.__externref_table_alloc();
9+
wasm.__wbindgen_export_2.set(idx, obj);
1910
return idx;
2011
}
2112

2213
function handleError(f, args) {
2314
try {
2415
return f.apply(this, args);
2516
} catch (e) {
26-
wasm.__wbindgen_exn_store(addHeapObject(e));
17+
const idx = addToExternrefTable0(e);
18+
wasm.__wbindgen_exn_store(idx);
2719
}
2820
}
2921

30-
function getObject(idx) { return heap[idx]; }
22+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
23+
24+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
25+
26+
cachedTextDecoder.decode();
3127

32-
function dropObject(idx) {
33-
if (idx < 132) return;
34-
heap[idx] = heap_next;
35-
heap_next = idx;
28+
let cachedUint8ArrayMemory0 = null;
29+
30+
function getUint8ArrayMemory0() {
31+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
32+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
33+
}
34+
return cachedUint8ArrayMemory0;
35+
}
36+
37+
function getStringFromWasm0(ptr, len) {
38+
ptr = ptr >>> 0;
39+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
3640
}
3741

38-
function takeObject(idx) {
39-
const ret = getObject(idx);
40-
dropObject(idx);
41-
return ret;
42+
function takeFromExternrefTable0(idx) {
43+
const value = wasm.__wbindgen_export_2.get(idx);
44+
wasm.__externref_table_dealloc(idx);
45+
return value;
4246
}
4347

4448
export function exported() {
4549
const ret = wasm.exported();
4650
if (ret[1]) {
47-
throw takeObject(ret[0]);
51+
throw takeFromExternrefTable0(ret[0]);
4852
}
4953
}
5054

5155
export function __wbg_foo_95fe1a04017077db() { return handleError(function () {
5256
foo();
5357
}, arguments) };
5458

59+
export function __wbindgen_init_externref_table() {
60+
const table = wasm.__wbindgen_export_2;
61+
const offset = table.grow(4);
62+
table.set(0, undefined);
63+
table.set(offset + 0, undefined);
64+
table.set(offset + 1, null);
65+
table.set(offset + 2, true);
66+
table.set(offset + 3, false);
67+
;
68+
};
69+
70+
export function __wbindgen_throw(arg0, arg1) {
71+
throw new Error(getStringFromWasm0(arg0, arg1));
72+
};
73+

0 commit comments

Comments
 (0)