Skip to content

Commit eb301b8

Browse files
committed
Adding in support for unstable APIs
1 parent ac9724a commit eb301b8

File tree

112 files changed

+5755
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+5755
-101
lines changed

crates/backend/src/ast.rs

-9
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ pub struct Export {
5757
/// Whether or not this function should be flagged as the wasm start
5858
/// function.
5959
pub start: bool,
60-
/// Whether the API is unstable. This is only used internally.
61-
pub unstable_api: bool,
6260
}
6361

6462
/// The 3 types variations of `self`.
@@ -79,7 +77,6 @@ pub struct Import {
7977
pub module: ImportModule,
8078
pub js_namespace: Option<Ident>,
8179
pub kind: ImportKind,
82-
pub unstable_api: bool,
8380
}
8481

8582
#[cfg_attr(feature = "extra-traits", derive(Debug))]
@@ -135,7 +132,6 @@ pub struct ImportFunction {
135132
pub kind: ImportFunctionKind,
136133
pub shim: Ident,
137134
pub doc_comment: Option<String>,
138-
pub unstable_api: bool,
139135
}
140136

141137
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
@@ -192,7 +188,6 @@ pub struct ImportType {
192188
pub js_name: String,
193189
pub attrs: Vec<syn::Attribute>,
194190
pub typescript_name: Option<String>,
195-
pub unstable_api: bool,
196191
pub doc_comment: Option<String>,
197192
pub instanceof_shim: String,
198193
pub is_type_of: Option<syn::Expr>,
@@ -213,8 +208,6 @@ pub struct ImportEnum {
213208
pub variant_values: Vec<String>,
214209
/// Attributes to apply to the Rust enum
215210
pub rust_attrs: Vec<syn::Attribute>,
216-
/// Whether the enum is part of an unstable WebIDL
217-
pub unstable_api: bool,
218211
}
219212

220213
#[cfg_attr(feature = "extra-traits", derive(Debug))]
@@ -250,7 +243,6 @@ pub struct StructField {
250243
pub getter: Ident,
251244
pub setter: Ident,
252245
pub comments: Vec<String>,
253-
pub unstable_api: bool,
254246
}
255247

256248
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
@@ -260,7 +252,6 @@ pub struct Enum {
260252
pub variants: Vec<Variant>,
261253
pub comments: Vec<String>,
262254
pub hole: u32,
263-
pub unstable_api: bool,
264255
}
265256

266257
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]

crates/backend/src/codegen.rs

+1-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::ast;
22
use crate::encode;
3-
use crate::util::{self, ShortHash};
3+
use crate::util::ShortHash;
44
use crate::Diagnostic;
55
use proc_macro2::{Ident, Literal, Span, TokenStream};
66
use quote::{quote, ToTokens};
@@ -41,7 +41,6 @@ impl TryToTokens for ast::Program {
4141
for i in self.imports.iter() {
4242
DescribeImport {
4343
kind: &i.kind,
44-
unstable_api: i.unstable_api,
4544
}.to_tokens(tokens);
4645

4746
// If there is a js namespace, check that name isn't a type. If it is,
@@ -298,7 +297,6 @@ impl ToTokens for ast::StructField {
298297
inner: quote! {
299298
<#ty as WasmDescribe>::describe();
300299
},
301-
unstable_api: self.unstable_api,
302300
attrs: vec![],
303301
}
304302
.to_tokens(tokens);
@@ -536,7 +534,6 @@ impl TryToTokens for ast::Export {
536534
#(<#argtys as WasmDescribe>::describe();)*
537535
#describe_ret
538536
},
539-
unstable_api: self.unstable_api,
540537
attrs: attrs.clone(),
541538
}
542539
.to_tokens(into);
@@ -563,7 +560,6 @@ impl ToTokens for ast::ImportType {
563560
let vis = &self.vis;
564561
let rust_name = &self.rust_name;
565562
let attrs = &self.attrs;
566-
let unstable_api_attr = util::maybe_unstable_api_attr(self.unstable_api);
567563
let doc_comment = match &self.doc_comment {
568564
None => "",
569565
Some(comment) => comment,
@@ -612,14 +608,12 @@ impl ToTokens for ast::ImportType {
612608
#[doc = #doc_comment]
613609
#[repr(transparent)]
614610
#[allow(clippy::all)]
615-
#unstable_api_attr
616611
#vis struct #rust_name {
617612
obj: #internal_obj
618613
}
619614

620615
#[allow(bad_style)]
621616
#[allow(clippy::all)]
622-
#unstable_api_attr
623617
const #const_name: () = {
624618
use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi};
625619
use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi};
@@ -770,7 +764,6 @@ impl ToTokens for ast::ImportType {
770764
for superclass in self.extends.iter() {
771765
(quote! {
772766
#[allow(clippy::all)]
773-
#unstable_api_attr
774767
impl From<#rust_name> for #superclass {
775768
#[inline]
776769
fn from(obj: #rust_name) -> #superclass {
@@ -780,7 +773,6 @@ impl ToTokens for ast::ImportType {
780773
}
781774

782775
#[allow(clippy::all)]
783-
#unstable_api_attr
784776
impl AsRef<#superclass> for #rust_name {
785777
#[inline]
786778
fn as_ref(&self) -> &#superclass {
@@ -802,7 +794,6 @@ impl ToTokens for ast::ImportEnum {
802794
let variants = &self.variants;
803795
let variant_strings = &self.variant_values;
804796
let attrs = &self.rust_attrs;
805-
let unstable_api_attr = util::maybe_unstable_api_attr(self.unstable_api);
806797

807798
let mut current_idx: usize = 0;
808799
let variant_indexes: Vec<Literal> = variants
@@ -831,15 +822,13 @@ impl ToTokens for ast::ImportEnum {
831822
#[allow(bad_style)]
832823
#(#attrs)*
833824
#[allow(clippy::all)]
834-
#unstable_api_attr
835825
#vis enum #name {
836826
#(#variants = #variant_indexes_ref,)*
837827
#[doc(hidden)]
838828
__Nonexhaustive,
839829
}
840830

841831
#[allow(clippy::all)]
842-
#unstable_api_attr
843832
impl #name {
844833
#vis fn from_js_value(obj: &wasm_bindgen::JsValue) -> Option<#name> {
845834
obj.as_string().and_then(|obj_str| match obj_str.as_str() {
@@ -850,15 +839,13 @@ impl ToTokens for ast::ImportEnum {
850839
}
851840

852841
#[allow(clippy::all)]
853-
#unstable_api_attr
854842
impl wasm_bindgen::describe::WasmDescribe for #name {
855843
fn describe() {
856844
wasm_bindgen::JsValue::describe()
857845
}
858846
}
859847

860848
#[allow(clippy::all)]
861-
#unstable_api_attr
862849
impl wasm_bindgen::convert::IntoWasmAbi for #name {
863850
type Abi = <wasm_bindgen::JsValue as
864851
wasm_bindgen::convert::IntoWasmAbi>::Abi;
@@ -870,7 +857,6 @@ impl ToTokens for ast::ImportEnum {
870857
}
871858

872859
#[allow(clippy::all)]
873-
#unstable_api_attr
874860
impl wasm_bindgen::convert::FromWasmAbi for #name {
875861
type Abi = <wasm_bindgen::JsValue as
876862
wasm_bindgen::convert::FromWasmAbi>::Abi;
@@ -881,21 +867,18 @@ impl ToTokens for ast::ImportEnum {
881867
}
882868

883869
#[allow(clippy::all)]
884-
#unstable_api_attr
885870
impl wasm_bindgen::convert::OptionIntoWasmAbi for #name {
886871
#[inline]
887872
fn none() -> Self::Abi { Object::none() }
888873
}
889874

890875
#[allow(clippy::all)]
891-
#unstable_api_attr
892876
impl wasm_bindgen::convert::OptionFromWasmAbi for #name {
893877
#[inline]
894878
fn is_none(abi: &Self::Abi) -> bool { Object::is_none(abi) }
895879
}
896880

897881
#[allow(clippy::all)]
898-
#unstable_api_attr
899882
impl From<#name> for wasm_bindgen::JsValue {
900883
fn from(obj: #name) -> wasm_bindgen::JsValue {
901884
match obj {
@@ -1007,7 +990,6 @@ impl TryToTokens for ast::ImportFunction {
1007990
let arguments = &arguments;
1008991
let abi_arguments = &abi_arguments;
1009992
let abi_argument_names = &abi_argument_names;
1010-
let unstable_api_attr = util::maybe_unstable_api_attr(self.unstable_api);
1011993

1012994
let doc_comment = match &self.doc_comment {
1013995
None => "",
@@ -1075,7 +1057,6 @@ impl TryToTokens for ast::ImportFunction {
10751057

10761058
if let Some(class) = class_ty {
10771059
(quote! {
1078-
#unstable_api_attr
10791060
impl #class {
10801061
#invocation
10811062
}
@@ -1092,7 +1073,6 @@ impl TryToTokens for ast::ImportFunction {
10921073
// See comment above in ast::Export for what's going on here.
10931074
struct DescribeImport<'a> {
10941075
kind: &'a ast::ImportKind,
1095-
unstable_api: bool,
10961076
}
10971077

10981078
impl<'a> ToTokens for DescribeImport<'a> {
@@ -1119,7 +1099,6 @@ impl<'a> ToTokens for DescribeImport<'a> {
11191099
#(<#argtys as WasmDescribe>::describe();)*
11201100
#inform_ret
11211101
},
1122-
unstable_api: self.unstable_api,
11231102
attrs: f.function.rust_attrs.clone(),
11241103
}
11251104
.to_tokens(tokens);
@@ -1130,7 +1109,6 @@ impl ToTokens for ast::Enum {
11301109
fn to_tokens(&self, into: &mut TokenStream) {
11311110
let enum_name = &self.name;
11321111
let hole = &self.hole;
1133-
let unstable_api_attr = util::maybe_unstable_api_attr(self.unstable_api);
11341112
let cast_clauses = self.variants.iter().map(|variant| {
11351113
let variant_name = &variant.name;
11361114
quote! {
@@ -1141,7 +1119,6 @@ impl ToTokens for ast::Enum {
11411119
});
11421120
(quote! {
11431121
#[allow(clippy::all)]
1144-
#unstable_api_attr
11451122
impl wasm_bindgen::convert::IntoWasmAbi for #enum_name {
11461123
type Abi = u32;
11471124

@@ -1152,7 +1129,6 @@ impl ToTokens for ast::Enum {
11521129
}
11531130

11541131
#[allow(clippy::all)]
1155-
#unstable_api_attr
11561132
impl wasm_bindgen::convert::FromWasmAbi for #enum_name {
11571133
type Abi = u32;
11581134

@@ -1165,21 +1141,18 @@ impl ToTokens for ast::Enum {
11651141
}
11661142

11671143
#[allow(clippy::all)]
1168-
#unstable_api_attr
11691144
impl wasm_bindgen::convert::OptionFromWasmAbi for #enum_name {
11701145
#[inline]
11711146
fn is_none(val: &u32) -> bool { *val == #hole }
11721147
}
11731148

11741149
#[allow(clippy::all)]
1175-
#unstable_api_attr
11761150
impl wasm_bindgen::convert::OptionIntoWasmAbi for #enum_name {
11771151
#[inline]
11781152
fn none() -> Self::Abi { #hole }
11791153
}
11801154

11811155
#[allow(clippy::all)]
1182-
#unstable_api_attr
11831156
impl wasm_bindgen::describe::WasmDescribe for #enum_name {
11841157
fn describe() {
11851158
use wasm_bindgen::describe::*;
@@ -1230,7 +1203,6 @@ impl ToTokens for ast::ImportStatic {
12301203
inner: quote! {
12311204
<#ty as WasmDescribe>::describe();
12321205
},
1233-
unstable_api: false,
12341206
attrs: vec![],
12351207
}
12361208
.to_tokens(into);
@@ -1242,7 +1214,6 @@ impl ToTokens for ast::ImportStatic {
12421214
struct Descriptor<'a, T> {
12431215
ident: &'a Ident,
12441216
inner: T,
1245-
unstable_api: bool,
12461217
attrs: Vec<syn::Attribute>,
12471218
}
12481219

@@ -1271,7 +1242,6 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
12711242
}
12721243

12731244
let name = Ident::new(&format!("__wbindgen_describe_{}", ident), ident.span());
1274-
let unstable_api_attr = util::maybe_unstable_api_attr(self.unstable_api);
12751245
let inner = &self.inner;
12761246
let attrs = &self.attrs;
12771247
(quote! {
@@ -1281,7 +1251,6 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
12811251
#[doc(hidden)]
12821252
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
12831253
#[allow(clippy::all)]
1284-
#unstable_api_attr
12851254
pub extern "C" fn #name() {
12861255
use wasm_bindgen::describe::*;
12871256
// See definition of `link_mem_intrinsics` for what this is doing

crates/backend/src/encode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ fn shared_export<'a>(
188188
function: shared_function(&export.function, intern),
189189
method_kind,
190190
start: export.start,
191-
unstable_api: export.unstable_api,
192191
})
193192
}
194193

crates/backend/src/util.rs

-19
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,10 @@ pub fn ident_ty(ident: Ident) -> syn::Type {
113113
}
114114

115115
pub fn wrap_import_function(function: ast::ImportFunction) -> ast::Import {
116-
let unstable_api = function.unstable_api;
117116
ast::Import {
118117
module: ast::ImportModule::None,
119118
js_namespace: None,
120119
kind: ast::ImportKind::Function(function),
121-
unstable_api,
122120
}
123121
}
124122

@@ -156,20 +154,3 @@ impl<T: Hash> fmt::Display for ShortHash<T> {
156154
write!(f, "{:016x}", h.finish())
157155
}
158156
}
159-
160-
161-
/// Create syn attribute for `#[cfg(web_sys_unstable_apis)]` and a doc comment.
162-
pub fn unstable_api_attrs() -> proc_macro2::TokenStream {
163-
quote::quote!(
164-
#[cfg(web_sys_unstable_apis)]
165-
#[doc = "\n\n*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as [described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
166-
)
167-
}
168-
169-
pub fn maybe_unstable_api_attr(unstable_api: bool) -> Option<proc_macro2::TokenStream> {
170-
if unstable_api {
171-
Some(unstable_api_attrs())
172-
} else {
173-
None
174-
}
175-
}

0 commit comments

Comments
 (0)