Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1e3cc75

Browse files
committedDec 19, 2024··
Apply transformations even if the shim is empty
1 parent c118dc5 commit 1e3cc75

File tree

6 files changed

+86
-6
lines changed

6 files changed

+86
-6
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
* Error if URL in `<WEBDRIVER>_REMOTE` can't be parsed.
6565
[#4362](https://github.com/rustwasm/wasm-bindgen/pull/4362)
6666

67+
* Internal functions are now removed instead of invalidly imported if they are unused.
68+
[#4366](https://github.com/rustwasm/wasm-bindgen/pull/4366)
69+
6770
--------------------------------------------------------------------------------
6871

6972
## [0.2.99](https://github.com/rustwasm/wasm-bindgen/compare/0.2.98...0.2.99)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
export function causes_error(): number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
let wasm;
2+
export function __wbg_set_wasm(val) {
3+
wasm = val;
4+
}
5+
6+
7+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
8+
9+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
10+
11+
cachedTextDecoder.decode();
12+
13+
let cachedUint8ArrayMemory0 = null;
14+
15+
function getUint8ArrayMemory0() {
16+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
17+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
18+
}
19+
return cachedUint8ArrayMemory0;
20+
}
21+
22+
function getStringFromWasm0(ptr, len) {
23+
ptr = ptr >>> 0;
24+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
25+
}
26+
27+
function takeFromExternrefTable0(idx) {
28+
const value = wasm.__wbindgen_export_0.get(idx);
29+
wasm.__externref_table_dealloc(idx);
30+
return value;
31+
}
32+
/**
33+
* @returns {number}
34+
*/
35+
export function causes_error() {
36+
const ret = wasm.causes_error();
37+
if (ret[2]) {
38+
throw takeFromExternrefTable0(ret[1]);
39+
}
40+
return ret[0];
41+
}
42+
43+
export function __wbindgen_init_externref_table() {
44+
const table = wasm.__wbindgen_export_0;
45+
const offset = table.grow(4);
46+
table.set(0, undefined);
47+
table.set(offset + 0, undefined);
48+
table.set(offset + 1, null);
49+
table.set(offset + 2, true);
50+
table.set(offset + 3, false);
51+
;
52+
};
53+
54+
export function __wbindgen_throw(arg0, arg1) {
55+
throw new Error(getStringFromWasm0(arg0, arg1));
56+
};
57+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use wasm_bindgen::prelude::*;
2+
3+
#[wasm_bindgen]
4+
pub fn causes_error() -> Result<f64, JsError> {
5+
Ok(1.0)
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(module $reference_test.wasm
2+
(type (;0;) (func))
3+
(type (;1;) (func (result f64 i32 i32)))
4+
(type (;2;) (func (param i32)))
5+
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
6+
(func $__externref_table_dealloc (;1;) (type 2) (param i32))
7+
(func $"causes_error multivalue shim" (;2;) (type 1) (result f64 i32 i32))
8+
(table (;0;) 128 externref)
9+
(memory (;0;) 17)
10+
(export "memory" (memory 0))
11+
(export "causes_error" (func $"causes_error multivalue shim"))
12+
(export "__wbindgen_export_0" (table 0))
13+
(export "__externref_table_dealloc" (func $__externref_table_dealloc))
14+
(export "__wbindgen_start" (func 0))
15+
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
16+
)
17+

‎crates/externref-xform/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,6 @@ impl Transform<'_> {
302302
self.process_elements(module)?;
303303
assert!(self.cx.new_elements.is_empty());
304304

305-
// If we didn't actually transform anything, no need to inject or
306-
// rewrite anything from below.
307-
if self.shims.is_empty() {
308-
return Ok(());
309-
}
310-
311305
// Perform all instruction transformations to rewrite calls between
312306
// functions and make sure everything is still hooked up right.
313307
self.rewrite_calls(module)?;

0 commit comments

Comments
 (0)
Please sign in to comment.