Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply transformations even if the shim is empty #4366

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
* Error if URL in `<WEBDRIVER>_REMOTE` can't be parsed.
[#4362](https://github.com/rustwasm/wasm-bindgen/pull/4362)

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

--------------------------------------------------------------------------------

## [0.2.99](https://github.com/rustwasm/wasm-bindgen/compare/0.2.98...0.2.99)
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/tests/reference/intrinsic-only.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* tslint:disable */
/* eslint-disable */
export function causes_error(): number;
57 changes: 57 additions & 0 deletions crates/cli/tests/reference/intrinsic-only.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
let wasm;
export function __wbg_set_wasm(val) {
wasm = val;
}


const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachedUint8ArrayMemory0 = null;

function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}

function takeFromExternrefTable0(idx) {
const value = wasm.__wbindgen_export_0.get(idx);
wasm.__externref_table_dealloc(idx);
return value;
}
/**
* @returns {number}
*/
export function causes_error() {
const ret = wasm.causes_error();
if (ret[2]) {
throw takeFromExternrefTable0(ret[1]);
}
return ret[0];
}

export function __wbindgen_init_externref_table() {
const table = wasm.__wbindgen_export_0;
const offset = table.grow(4);
table.set(0, undefined);
table.set(offset + 0, undefined);
table.set(offset + 1, null);
table.set(offset + 2, true);
table.set(offset + 3, false);
;
};

export function __wbindgen_throw(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};

6 changes: 6 additions & 0 deletions crates/cli/tests/reference/intrinsic-only.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn causes_error() -> Result<f64, JsError> {
Ok(1.0)
}
17 changes: 17 additions & 0 deletions crates/cli/tests/reference/intrinsic-only.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(module $reference_test.wasm
(type (;0;) (func))
(type (;1;) (func (result f64 i32 i32)))
(type (;2;) (func (param i32)))
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
(func $__externref_table_dealloc (;1;) (type 2) (param i32))
(func $"causes_error multivalue shim" (;2;) (type 1) (result f64 i32 i32))
(table (;0;) 128 externref)
(memory (;0;) 17)
(export "memory" (memory 0))
(export "causes_error" (func $"causes_error multivalue shim"))
(export "__wbindgen_export_0" (table 0))
(export "__externref_table_dealloc" (func $__externref_table_dealloc))
(export "__wbindgen_start" (func 0))
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

6 changes: 0 additions & 6 deletions crates/externref-xform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,6 @@ impl Transform<'_> {
self.process_elements(module)?;
assert!(self.cx.new_elements.is_empty());

// If we didn't actually transform anything, no need to inject or
// rewrite anything from below.
if self.shims.is_empty() {
return Ok(());
}

// Perform all instruction transformations to rewrite calls between
// functions and make sure everything is still hooked up right.
self.rewrite_calls(module)?;
Expand Down
Loading