Improve link_mem_intrinsics hack

Previously the `link_mem_intrinsics` hack actually had a runtime
overhead by storing a value into a global location, but it turns out we
can actually use a non-inlined function call as part of the *descriptor*
which requires this to be in the final binary, but we'll end up snip'ing
the value at the end.

All in all this should mean that it's not a zero-overhead solution for
linking these intrinsics! The `#[wasm_bindgen]` attribute already has
other problems if the descriptors don't show up, so that's the least of
our issues!
This commit is contained in:
Alex Crichton
2018-09-24 15:39:55 -07:00
parent d10ca579e4
commit b256b98e38
3 changed files with 5 additions and 25 deletions

View File

@ -451,9 +451,6 @@ impl TryToTokens for ast::Export {
#[allow(non_snake_case)]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
pub extern fn #generated_name(#(#args),*) #ret_ty {
// See definition of `link_mem_intrinsics` for what this is doing
::wasm_bindgen::__rt::link_mem_intrinsics();
// Scope all local variables to be destroyed after we call the
// function to ensure that `#convert_ret`, if it panics, doesn't
// leak anything.
@ -887,8 +884,6 @@ impl TryToTokens for ast::ImportFunction {
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[doc = #doc_comment]
#vis fn #rust_name(#me #(#arguments),*) #ret {
// See definition of `link_mem_intrinsics` for what this is doing
::wasm_bindgen::__rt::link_mem_intrinsics();
#[link(wasm_import_module = "__wbindgen_placeholder__")]
extern {
fn #import_name(#(#abi_arguments),*) -> #abi_ret;
@ -1256,6 +1251,8 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
pub extern fn #name() {
use wasm_bindgen::describe::*;
// See definition of `link_mem_intrinsics` for what this is doing
::wasm_bindgen::__rt::link_mem_intrinsics();
#inner
}
}).to_tokens(tokens);