diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/wasm-bindgen-backend | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/wasm-bindgen-backend')
-rw-r--r-- | vendor/wasm-bindgen-backend/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/wasm-bindgen-backend/Cargo.toml | 4 | ||||
-rw-r--r-- | vendor/wasm-bindgen-backend/src/ast.rs | 19 | ||||
-rw-r--r-- | vendor/wasm-bindgen-backend/src/codegen.rs | 183 | ||||
-rw-r--r-- | vendor/wasm-bindgen-backend/src/encode.rs | 17 |
5 files changed, 168 insertions, 57 deletions
diff --git a/vendor/wasm-bindgen-backend/.cargo-checksum.json b/vendor/wasm-bindgen-backend/.cargo-checksum.json index 128e39aa8..a20730dd7 100644 --- a/vendor/wasm-bindgen-backend/.cargo-checksum.json +++ b/vendor/wasm-bindgen-backend/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"d4e0f6a5a01e3c7c45270cb76caff12797dfd67fcd73feba5d4ba482e22f3d32","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","src/ast.rs":"4104b5f98d551721556ad85e58d595263dc46ec039abddcf8bddb4344bb9fd45","src/codegen.rs":"3452cbb8990d555091c50f82aa71c33f3b6706b9275a65e10612b9a0d1fb04eb","src/encode.rs":"173285fc270e7f75ac8b11b8be8db215b39bd2ee2d738c7364fa08975d7f2669","src/error.rs":"ecb3e0a2abdce0c9c5bb8a68c0e001a328ed85608bcf4ccb9215088d1f81a9c2","src/lib.rs":"14ade320b537315ec4c575f9f3c7a35ff4e9385114c4c26a35b2ee270a897cb4","src/util.rs":"0e6705dcd8836e01d520e229edc6dbe375ec01ea39e410bd743395416b807f7c"},"package":"4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"}
\ No newline at end of file +{"files":{"Cargo.toml":"71b8be6734c563f974ba5b4760ee5ad268e63668aa7b8dac3b59fa2e61067cae","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","src/ast.rs":"90d8a3740c3c25c49274b2ed85ad4b501809ee5a0bc94b72ee1b06082be23042","src/codegen.rs":"7ea293663ffc6f4b69f655edf27515cdf5a582855ffe98df6e041bfc6c551f51","src/encode.rs":"4977f7f13f7e8fb9ac5dfd854b3062962f426bf0ad1435249e3ace0cd6a477ec","src/error.rs":"ecb3e0a2abdce0c9c5bb8a68c0e001a328ed85608bcf4ccb9215088d1f81a9c2","src/lib.rs":"14ade320b537315ec4c575f9f3c7a35ff4e9385114c4c26a35b2ee270a897cb4","src/util.rs":"0e6705dcd8836e01d520e229edc6dbe375ec01ea39e410bd743395416b807f7c"},"package":"95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"}
\ No newline at end of file diff --git a/vendor/wasm-bindgen-backend/Cargo.toml b/vendor/wasm-bindgen-backend/Cargo.toml index 8e6547ca8..7ed453bc7 100644 --- a/vendor/wasm-bindgen-backend/Cargo.toml +++ b/vendor/wasm-bindgen-backend/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2018" name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" authors = ["The wasm-bindgen Developers"] description = """ Backend code generation of the wasm-bindgen tool @@ -42,7 +42,7 @@ version = "1.0" features = ["full"] [dependencies.wasm-bindgen-shared] -version = "=0.2.83" +version = "=0.2.84" [features] extra-traits = ["syn/extra-traits"] diff --git a/vendor/wasm-bindgen-backend/src/ast.rs b/vendor/wasm-bindgen-backend/src/ast.rs index 7703e2570..064e01377 100644 --- a/vendor/wasm-bindgen-backend/src/ast.rs +++ b/vendor/wasm-bindgen-backend/src/ast.rs @@ -2,7 +2,7 @@ //! with all the added metadata necessary to generate WASM bindings //! for it. -use crate::Diagnostic; +use crate::{util::ShortHash, Diagnostic}; use proc_macro2::{Ident, Span}; use std::hash::{Hash, Hasher}; use wasm_bindgen_shared as shared; @@ -16,6 +16,8 @@ pub struct Program { pub exports: Vec<Export>, /// js -> rust interfaces pub imports: Vec<Import>, + /// linked-to modules + pub linked_modules: Vec<ImportModule>, /// rust enums pub enums: Vec<Enum>, /// rust structs @@ -36,8 +38,23 @@ impl Program { && self.typescript_custom_sections.is_empty() && self.inline_js.is_empty() } + + /// Name of the link function for a specific linked module + pub fn link_function_name(&self, idx: usize) -> String { + let hash = match &self.linked_modules[idx] { + ImportModule::Inline(idx, _) => ShortHash((1, &self.inline_js[*idx])).to_string(), + other => ShortHash((0, other)).to_string(), + }; + format!("__wbindgen_link_{}", hash) + } } +/// An abstract syntax tree representing a link to a module in Rust. +/// In contrast to Program, LinkToModule must expand to an expression. +/// linked_modules of the inner Program must contain exactly one element +/// whose link is produced by the expression. +pub struct LinkToModule(pub Program); + /// A rust to js interface. Allows interaction with rust objects/functions /// from javascript. #[cfg_attr(feature = "extra-traits", derive(Debug))] diff --git a/vendor/wasm-bindgen-backend/src/codegen.rs b/vendor/wasm-bindgen-backend/src/codegen.rs index 5be0fad33..e2d57f433 100644 --- a/vendor/wasm-bindgen-backend/src/codegen.rs +++ b/vendor/wasm-bindgen-backend/src/codegen.rs @@ -1,6 +1,5 @@ use crate::ast; use crate::encode; -use crate::util::ShortHash; use crate::Diagnostic; use once_cell::sync::Lazy; use proc_macro2::{Ident, Literal, Span, TokenStream}; @@ -130,6 +129,29 @@ impl TryToTokens for ast::Program { } } +impl TryToTokens for ast::LinkToModule { + fn try_to_tokens(&self, tokens: &mut TokenStream) -> Result<(), Diagnostic> { + let mut program = TokenStream::new(); + self.0.try_to_tokens(&mut program)?; + let link_function_name = self.0.link_function_name(0); + let name = Ident::new(&link_function_name, Span::call_site()); + let abi_ret = quote! { <std::string::String as wasm_bindgen::convert::FromWasmAbi>::Abi }; + let extern_fn = extern_fn(&name, &[], &[], &[], abi_ret); + (quote! { + { + #program + #extern_fn + + unsafe { + <std::string::String as wasm_bindgen::convert::FromWasmAbi>::from_abi(#name()) + } + } + }) + .to_tokens(tokens); + Ok(()) + } +} + impl ToTokens for ast::Struct { fn to_tokens(&self, tokens: &mut TokenStream) { let name = &self.rust_name; @@ -138,7 +160,6 @@ impl ToTokens for ast::Struct { let name_chars = name_str.chars().map(|c| c as u32); let new_fn = Ident::new(&shared::new_function(&name_str), Span::call_site()); let free_fn = Ident::new(&shared::free_function(&name_str), Span::call_site()); - let free_fn_const = Ident::new(&format!("{}__const", free_fn), free_fn.span()); (quote! { #[automatically_derived] impl wasm_bindgen::describe::WasmDescribe for #name { @@ -211,11 +232,11 @@ impl ToTokens for ast::Struct { #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[automatically_derived] - const #free_fn_const: () = { + const _: () = { #[no_mangle] #[doc(hidden)] pub unsafe extern "C" fn #free_fn(ptr: u32) { - drop(<#name as wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr)); + let _ = <#name as wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr); //implicit `drop()` } }; @@ -244,6 +265,16 @@ impl ToTokens for ast::Struct { } #[automatically_derived] + impl wasm_bindgen::convert::LongRefFromWasmAbi for #name { + type Abi = u32; + type Anchor = wasm_bindgen::__rt::Ref<'static, #name>; + + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + <Self as wasm_bindgen::convert::RefFromWasmAbi>::ref_from_abi(js) + } + } + + #[automatically_derived] impl wasm_bindgen::convert::OptionIntoWasmAbi for #name { #[inline] fn none() -> Self::Abi { 0 } @@ -284,11 +315,9 @@ impl ToTokens for ast::StructField { quote! {} }; - let getter_const = Ident::new(&format!("{}__const", getter), getter.span()); - (quote! { #[automatically_derived] - const #getter_const: () = { + const _: () = { #[cfg_attr(all(target_arch = "wasm32", not(target_os = "emscripten")), no_mangle)] #[doc(hidden)] pub unsafe extern "C" fn #getter(js: u32) @@ -322,12 +351,10 @@ impl ToTokens for ast::StructField { return; } - let setter_const = Ident::new(&format!("{}__const", setter), setter.span()); - (quote! { #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[automatically_derived] - const #setter_const: () = { + const _: () = { #[no_mangle] #[doc(hidden)] pub unsafe extern "C" fn #setter( @@ -405,7 +432,7 @@ impl TryToTokens for ast::Export { let mut argtys = Vec::new(); for (i, arg) in self.function.arguments.iter().enumerate() { - argtys.push(&arg.ty); + argtys.push(&*arg.ty); let i = i + offset; let ident = Ident::new(&format!("arg{}", i), Span::call_site()); let ty = &arg.ty; @@ -427,16 +454,31 @@ impl TryToTokens for ast::Export { }); } syn::Type::Reference(syn::TypeReference { elem, .. }) => { - args.push(quote! { - #ident: <#elem as wasm_bindgen::convert::RefFromWasmAbi>::Abi - }); - arg_conversions.push(quote! { - let #ident = unsafe { - <#elem as wasm_bindgen::convert::RefFromWasmAbi> - ::ref_from_abi(#ident) - }; - let #ident = &*#ident; - }); + if self.function.r#async { + args.push(quote! { + #ident: <#elem as wasm_bindgen::convert::LongRefFromWasmAbi>::Abi + }); + arg_conversions.push(quote! { + let #ident = unsafe { + <#elem as wasm_bindgen::convert::LongRefFromWasmAbi> + ::long_ref_from_abi(#ident) + }; + let #ident = <<#elem as wasm_bindgen::convert::LongRefFromWasmAbi> + ::Anchor as core::borrow::Borrow<#elem>> + ::borrow(&#ident); + }); + } else { + args.push(quote! { + #ident: <#elem as wasm_bindgen::convert::RefFromWasmAbi>::Abi + }); + arg_conversions.push(quote! { + let #ident = unsafe { + <#elem as wasm_bindgen::convert::RefFromWasmAbi> + ::ref_from_abi(#ident) + }; + let #ident = &*#ident; + }); + } } _ => { args.push(quote! { @@ -531,11 +573,9 @@ impl TryToTokens for ast::Export { quote! {} }; - let generated_name_const = - Ident::new(&format!("{}__const", generated_name), generated_name.span()); (quote! { #[automatically_derived] - const #generated_name_const: () = { + const _: () = { #(#attrs)* #[cfg_attr( all(target_arch = "wasm32", not(target_os = "emscripten")), @@ -551,6 +591,22 @@ impl TryToTokens for ast::Export { }) .to_tokens(into); + let describe_args: TokenStream = argtys + .iter() + .map(|ty| match ty { + syn::Type::Reference(reference) + if self.function.r#async && reference.mutability.is_none() => + { + let inner = &reference.elem; + quote! { + inform(LONGREF); + <#inner as WasmDescribe>::describe(); + } + } + _ => quote! { <#ty as WasmDescribe>::describe(); }, + }) + .collect(); + // In addition to generating the shim function above which is what // our generated JS will invoke, we *also* generate a "descriptor" // shim. This descriptor shim uses the `WasmDescribe` trait to @@ -574,7 +630,7 @@ impl TryToTokens for ast::Export { inform(FUNCTION); inform(0); inform(#nargs); - #(<#argtys as WasmDescribe>::describe();)* + #describe_args #describe_ret }, attrs: attrs.clone(), @@ -607,8 +663,6 @@ impl ToTokens for ast::ImportType { None => "", Some(comment) => comment, }; - let const_name = format!("__wbg_generated_const_{}", rust_name); - let const_name = Ident::new(&const_name, Span::call_site()); let instanceof_shim = Ident::new(&self.instanceof_shim, Span::call_site()); let internal_obj = match self.extends.first() { @@ -657,10 +711,10 @@ impl ToTokens for ast::ImportType { } #[automatically_derived] - const #const_name: () = { + const _: () = { use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; - use wasm_bindgen::convert::RefFromWasmAbi; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; use wasm_bindgen::describe::WasmDescribe; use wasm_bindgen::{JsValue, JsCast, JsObject}; use wasm_bindgen::__rt::core; @@ -732,6 +786,17 @@ impl ToTokens for ast::ImportType { } } + impl LongRefFromWasmAbi for #rust_name { + type Abi = <JsValue as LongRefFromWasmAbi>::Abi; + type Anchor = #rust_name; + + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = <JsValue as LongRefFromWasmAbi>::long_ref_from_abi(js); + #rust_name { obj: tmp.into() } + } + } + // TODO: remove this on the next major version impl From<JsValue> for #rust_name { #[inline] @@ -1076,8 +1141,8 @@ impl TryToTokens for ast::ImportFunction { let import_name = &self.shim; let attrs = &self.function.rust_attrs; let arguments = &arguments; - let abi_arguments = &abi_arguments; - let abi_argument_names = &abi_argument_names; + let abi_arguments = &abi_arguments[..]; + let abi_argument_names = &abi_argument_names[..]; let doc_comment = &self.doc_comment; let me = if is_method { @@ -1102,23 +1167,13 @@ impl TryToTokens for ast::ImportFunction { // like rustc itself doesn't do great in that regard so let's just do // the best we can in the meantime. let extern_fn = respan( - quote! { - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] - #(#attrs)* - #[link(wasm_import_module = "__wbindgen_placeholder__")] - extern "C" { - fn #import_name(#(#abi_arguments),*) -> #abi_ret; - } - - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] - unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret { - #( - drop(#abi_argument_names); - )* - panic!("cannot call wasm-bindgen imported functions on \ - non-wasm targets"); - } - }, + extern_fn( + import_name, + attrs, + abi_arguments, + abi_argument_names, + abi_ret, + ), &self.rust_name, ); @@ -1336,16 +1391,12 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> { } let name = Ident::new(&format!("__wbindgen_describe_{}", ident), ident.span()); - let const_name = Ident::new( - &format!("__wbindgen_const_describe_{}", ident), - ident.span(), - ); let inner = &self.inner; let attrs = &self.attrs; (quote! { #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[automatically_derived] - const #const_name: () = { + const _: () = { #(#attrs)* #[no_mangle] #[doc(hidden)] @@ -1361,6 +1412,32 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> { } } +fn extern_fn( + import_name: &Ident, + attrs: &[syn::Attribute], + abi_arguments: &[TokenStream], + abi_argument_names: &[Ident], + abi_ret: TokenStream, +) -> TokenStream { + quote! { + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #(#attrs)* + #[link(wasm_import_module = "__wbindgen_placeholder__")] + extern "C" { + fn #import_name(#(#abi_arguments),*) -> #abi_ret; + } + + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret { + #( + drop(#abi_argument_names); + )* + panic!("cannot call wasm-bindgen imported functions on \ + non-wasm targets"); + } + } +} + /// Converts `span` into a stream of tokens, and attempts to ensure that `input` /// has all the appropriate span information so errors in it point to `span`. fn respan(input: TokenStream, span: &dyn ToTokens) -> TokenStream { diff --git a/vendor/wasm-bindgen-backend/src/encode.rs b/vendor/wasm-bindgen-backend/src/encode.rs index 41d3c8b77..254d0e885 100644 --- a/vendor/wasm-bindgen-backend/src/encode.rs +++ b/vendor/wasm-bindgen-backend/src/encode.rs @@ -146,6 +146,12 @@ fn shared_program<'a>( .iter() .map(|x| -> &'a str { &x }) .collect(), + linked_modules: prog + .linked_modules + .iter() + .enumerate() + .map(|(i, a)| shared_linked_module(&prog.link_function_name(i), a, intern)) + .collect::<Result<Vec<_>, _>>()?, local_modules: intern .files .borrow() @@ -249,6 +255,17 @@ fn shared_import<'a>(i: &'a ast::Import, intern: &'a Interner) -> Result<Import< }) } +fn shared_linked_module<'a>( + name: &str, + i: &'a ast::ImportModule, + intern: &'a Interner, +) -> Result<LinkedModule<'a>, Diagnostic> { + Ok(LinkedModule { + module: shared_module(i, intern)?, + link_function_name: intern.intern_str(name), + }) +} + fn shared_module<'a>( m: &'a ast::ImportModule, intern: &'a Interner, |