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

Wasmtime component bindgen: opt-in trappable error types #5397

Merged
merged 10 commits into from
Dec 14, 2022
Merged
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions crates/component-macro/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use proc_macro2::{Span, TokenStream};
use std::path::{Path, PathBuf};
use syn::parse::{Error, Parse, ParseStream, Result};
use syn::punctuated::Punctuated;
use syn::token;
use syn::Token;
use syn::{braced, token, Ident, Token};
use wasmtime_wit_bindgen::Opts;
use wit_parser::World;

Expand Down Expand Up @@ -68,6 +67,7 @@ impl Parse for Config {
}
Opt::Tracing(val) => ret.opts.tracing = val,
Opt::Async(val) => ret.opts.async_ = val,
Opt::TrappableErrorType(val) => ret.opts.trappable_error_type = val,
}
}
} else {
Expand Down Expand Up @@ -99,13 +99,15 @@ mod kw {
syn::custom_keyword!(path);
syn::custom_keyword!(inline);
syn::custom_keyword!(tracing);
syn::custom_keyword!(trappable_error_type);
}

enum Opt {
Path(syn::LitStr),
Inline(Span, World),
Tracing(bool),
Async(bool),
TrappableErrorType(Vec<(String, String, String)>),
}

impl Parse for Opt {
Expand All @@ -130,8 +132,25 @@ impl Parse for Opt {
input.parse::<Token![async]>()?;
input.parse::<Token![:]>()?;
Ok(Opt::Async(input.parse::<syn::LitBool>()?.value))
} else if l.peek(kw::trappable_error_type) {
input.parse::<kw::trappable_error_type>()?;
input.parse::<Token![:]>()?;
let contents;
let _lbrace = braced!(contents in input);
let fields: Punctuated<(String, String, String), Token![,]> =
contents.parse_terminated(trappable_error_field_parse)?;
Ok(Opt::TrappableErrorType(fields.into_iter().collect()))
} else {
Err(l.error())
}
}
}

fn trappable_error_field_parse(input: ParseStream<'_>) -> Result<(String, String, String)> {
let interface = input.parse::<Ident>()?.to_string();
input.parse::<Token![::]>()?;
let type_ = input.parse::<Ident>()?.to_string();
input.parse::<Token![:]>()?;
let rust_type = input.parse::<Ident>()?.to_string();
Ok((interface, type_, rust_type))
}
126 changes: 0 additions & 126 deletions crates/wasmtime/src/component/error.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/wasmtime/src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! probably buggy implementation of the component model.

mod component;
mod error;
mod func;
mod instance;
mod linker;
Expand All @@ -14,7 +13,6 @@ mod store;
pub mod types;
mod values;
pub use self::component::Component;
pub use self::error::{Error, Result};
pub use self::func::{
ComponentNamedList, ComponentType, Func, Lift, Lower, TypedFunc, WasmList, WasmStr,
};
Expand Down
1 change: 1 addition & 0 deletions crates/wit-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ documentation = "https://docs.rs/wasmtime-wit-bindgen/"
edition.workspace = true

[dependencies]
anyhow = { workspace = true }
heck = { workspace = true }
wit-parser = { workspace = true }
Loading