Skip to content

Commit

Permalink
Switch trappable_error_type to take a fully-qualified type path
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed Aug 3, 2023
1 parent fc03e74 commit 5f3308b
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 112 deletions.
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.

27 changes: 11 additions & 16 deletions crates/component-macro/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,9 @@ impl Parse for Opt {
input.parse::<Token![:]>()?;
let contents;
let _lbrace = braced!(contents in input);
let fields: Punctuated<(String, String, String), Token![,]> =
let fields: Punctuated<_, Token![,]> =
contents.parse_terminated(trappable_error_field_parse, Token![,])?;
Ok(Opt::TrappableErrorType(
fields
.into_iter()
.map(|(wit_owner, wit_name, rust_name)| TrappableError {
wit_owner: Some(wit_owner),
wit_name,
rust_name,
})
.collect(),
))
Ok(Opt::TrappableErrorType(Vec::from_iter(fields.into_iter())))
} else if l.peek(kw::interfaces) {
input.parse::<kw::interfaces>()?;
input.parse::<Token![:]>()?;
Expand All @@ -281,7 +272,7 @@ impl Parse for Opt {
}
}

fn trappable_error_field_parse(input: ParseStream<'_>) -> Result<(String, String, String)> {
fn trappable_error_field_parse(input: ParseStream<'_>) -> Result<TrappableError> {
// Accept a Rust identifier or a string literal. This is required
// because not all wit identifiers are Rust identifiers, so we can
// smuggle the invalid ones inside quotes.
Expand All @@ -296,12 +287,16 @@ fn trappable_error_field_parse(input: ParseStream<'_>) -> Result<(String, String
}
}

let interface = ident_or_str(input)?;
let wit_package_path = input.parse::<syn::LitStr>()?.value();
input.parse::<Token![::]>()?;
let type_ = ident_or_str(input)?;
let wit_type_name = ident_or_str(input)?;
input.parse::<Token![:]>()?;
let rust_type = input.parse::<Ident>()?.to_string();
Ok((interface, type_, rust_type))
let rust_type_name = input.parse::<Ident>()?.to_string();
Ok(TrappableError {
wit_package_path,
wit_type_name,
rust_type_name,
})
}

fn with_field_parse(input: ParseStream<'_>) -> Result<(String, String)> {
Expand Down
8 changes: 4 additions & 4 deletions crates/wasi/src/preview2/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ wasmtime::component::bindgen!({
tracing: true,
async: true,
trappable_error_type: {
"filesystem"::"error-code": Error,
"streams"::"stream-error": Error,
"wasi:filesystem/filesystem"::"error-code": Error,
"wasi:io/streams"::"stream-error": Error,
},
with: {
"wasi:filesystem/filesystem": crate::preview2::bindings::filesystem::filesystem,
Expand Down Expand Up @@ -50,8 +50,8 @@ pub mod sync {
tracing: true,
async: false,
trappable_error_type: {
"filesystem"::"error-code": Error,
"streams"::"stream-error": Error,
"wasi:filesystem/filesystem"::"error-code": Error,
"wasi:io/streams"::"stream-error": Error,
},
with: {
"wasi:filesystem/filesystem": crate::preview2::bindings::sync_io::filesystem::filesystem,
Expand Down
12 changes: 6 additions & 6 deletions crates/wasi/src/preview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub mod bindings {
",
tracing: true,
trappable_error_type: {
"streams"::"stream-error": Error,
"filesystem"::"error-code": Error,
"wasi:io/streams"::"stream-error": Error,
"wasi:filesystem/filesystem"::"error-code": Error,
},
with: {
"wasi:clocks/wall-clock": crate::preview2::bindings::clocks::wall_clock,
Expand Down Expand Up @@ -104,8 +104,8 @@ pub mod bindings {
tracing: true,
async: true,
trappable_error_type: {
"streams"::"stream-error": Error,
"filesystem"::"error-code": Error,
"wasi:io/streams"::"stream-error": Error,
"wasi:filesystem/filesystem"::"error-code": Error,
},
with: {
"wasi:clocks/wall-clock": crate::preview2::bindings::clocks::wall_clock,
Expand Down Expand Up @@ -133,8 +133,8 @@ pub mod bindings {
",
tracing: true,
trappable_error_type: {
"filesystem"::"error-code": Error,
"streams"::"stream-error": Error,
"wasi:filesystem/filesystem"::"error-code": Error,
"wasi:io/streams"::"stream-error": Error,
},
with: {
"wasi:clocks/wall-clock": crate::preview2::bindings::clocks::wall_clock,
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 @@ -12,3 +12,4 @@ edition.workspace = true
anyhow = { workspace = true }
heck = { workspace = true }
wit-parser = { workspace = true }
indexmap = { workspace = true }
Loading

0 comments on commit 5f3308b

Please sign in to comment.