Skip to content

Commit 25c7c72

Browse files
committed
Revert bundler target specific default transformations webpack now supports the reference type proposal.
1 parent 50c7504 commit 25c7c72

36 files changed

+450
-257
lines changed

CHANGELOG.md

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

40-
* 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.
41-
[#4235](https://github.com/rustwasm/wasm-bindgen/pull/4235)
42-
4340
* Deprecate `--reference-types` in favor of automatic target feature detection.
4441
[#4237](https://github.com/rustwasm/wasm-bindgen/pull/4237)
4542

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
@@ -110,6 +110,17 @@ export const Ordering = Object.freeze({
110110

111111
const __wbindgen_enum_ColorName = ["green", "yellow", "red"];
112112

113+
export function __wbindgen_init_externref_table() {
114+
const table = wasm.__wbindgen_export_0;
115+
const offset = table.grow(4);
116+
table.set(0, undefined);
117+
table.set(offset + 0, undefined);
118+
table.set(offset + 1, null);
119+
table.set(offset + 2, true);
120+
table.set(offset + 3, false);
121+
;
122+
};
123+
113124
export function __wbindgen_throw(arg0, arg1) {
114125
throw new Error(getStringFromWasm0(arg0, arg1));
115126
};

crates/cli/tests/reference/enums.wat

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
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))
7-
(func $option_order (;4;) (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+
(func $option_order (;5;) (type 1) (param i32) (result i32))
10+
(table (;0;) 128 externref)
811
(memory (;0;) 17)
912
(export "memory" (memory 0))
1013
(export "enum_echo" (func $enum_echo))
1114
(export "option_enum_echo" (func $option_enum_echo))
1215
(export "get_name" (func $get_name))
1316
(export "option_string_enum_echo" (func $option_string_enum_echo))
1417
(export "option_order" (func $option_order))
18+
(export "__wbindgen_export_0" (table 0))
19+
(export "__wbindgen_start" (func 0))
1520
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
1621
)
1722

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.js

+25-26
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,18 @@ 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

@@ -47,24 +39,16 @@ function getStringFromWasm0(ptr, len) {
4739
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
4840
}
4941

50-
function getObject(idx) { return heap[idx]; }
51-
52-
function dropObject(idx) {
53-
if (idx < 132) return;
54-
heap[idx] = heap_next;
55-
heap_next = idx;
56-
}
57-
58-
function takeObject(idx) {
59-
const ret = getObject(idx);
60-
dropObject(idx);
61-
return ret;
42+
function takeFromExternrefTable0(idx) {
43+
const value = wasm.__wbindgen_export_2.get(idx);
44+
wasm.__externref_table_dealloc(idx);
45+
return value;
6246
}
6347

6448
export function exported() {
6549
const ret = wasm.exported();
6650
if (ret[1]) {
67-
throw takeObject(ret[0]);
51+
throw takeFromExternrefTable0(ret[0]);
6852
}
6953
}
7054

@@ -93,3 +77,18 @@ export function __wbg_write_d258674ff6f0ea8d(arg0, arg1) {
9377
window.document.write(getStringFromWasm0(arg0, arg1));
9478
};
9579

80+
export function __wbindgen_init_externref_table() {
81+
const table = wasm.__wbindgen_export_2;
82+
const offset = table.grow(4);
83+
table.set(0, undefined);
84+
table.set(offset + 0, undefined);
85+
table.set(offset + 1, null);
86+
table.set(offset + 2, true);
87+
table.set(offset + 3, false);
88+
;
89+
};
90+
91+
export function __wbindgen_throw(arg0, arg1) {
92+
throw new Error(getStringFromWasm0(arg0, arg1));
93+
};
94+

0 commit comments

Comments
 (0)