pchickey opened PR #5397 from pch/component_bindgen_error_types
to main
:
This was gotten working over in wit-bindgen, and I ported it to the wasmtime repo since the generator moved.
My earlier failed experiment of a "HostError<T>" has been deleted, and bindgen macro users can now opt in to a special
trappable_error_type
which should work exactly how wiggle's trappable errors work.I couldn't port the rust-guest dependent tests from wit-bindgen into this repo so currently I am stuck struggling to replace them with wat.
pchickey updated PR #5397 from pch/component_bindgen_error_types
to main
.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Oh I thought the
Error<T>
was going to work which would avoid this result-of-result, but could you explain a bit more why it didn't work out?
pchickey submitted PR review.
pchickey created PR review comment:
I just don't have any tests that actually use the functionality in yet.
We can't use
Result<f64, Error<()>>
in this case because Error<T> requires T impl std::error::Error. Additionally, all of this PR only supports substituting named types, and doesn't support substituting primitive types.
pchickey edited PR review comment.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Ah ok makes sense. I'm worried about the ergonomics of this, though. Are you thinking we'd special-case
-> result<T, rich-error>
in WIT to have aResult<T, E>
return value here? For degenerate cases like-> result<T>
with no error or primitive errors I'm fine with doing whatever.
pchickey updated PR #5397 from pch/component_bindgen_error_types
to main
.
pchickey updated PR #5397 from pch/component_bindgen_error_types
to main
.
pchickey updated PR #5397 from pch/component_bindgen_error_types
to main
.
pchickey updated PR #5397 from pch/component_bindgen_error_types
to main
.
pchickey updated PR #5397 from pch/component_bindgen_error_types
to main
.
pchickey has marked PR #5397 as ready for review.
pchickey submitted PR review.
pchickey created PR review comment:
I put the tests in below that show we can special case a
interface i { ... result<t, e> }
toResult<T, TrappableE>
when the user invokes the macro withtrappable_error_types: { i::e: TrappableE, ... }
pchickey edited PR #5397 from pch/component_bindgen_error_types
to main
:
This was gotten working over in wit-bindgen, and I ported it to the wasmtime repo since the generator moved.
My earlier failed experiment of a "HostError<T>" has been deleted, and bindgen macro users can now opt in to a special
trappable_error_type
which should work exactly how wiggle's trappable errors work.When the user provides the macro argument
trappable_error_type: { i::e: TrappableE }
the code generator looks in wit interfaces named
i
for a wit type namede
, it will generate a typestruct TrappableE
whichimpl Error
andimpl From<E> for TrappableE
. In any functions that returnresult<t, e>
, it generates the return typeResult<T, TrappableE>
, rather than the much less idiomaticResult<Result<T, E>, anyhow::Error>
.I introduced new tests in
tests/all/component-model/bindgen/results.rs
that show this functionality in use.
alexcrichton created PR review comment:
Oh all this clap stuff is a holdover from copying over from the wit-bindgen repository, I think all of it can be removed since
clap
isn't even a dependency in this repo.
alexcrichton submitted PR review.
alexcrichton submitted PR review.
pchickey updated PR #5397 from pch/component_bindgen_error_types
to main
.
pchickey submitted PR review.
pchickey created PR review comment:
Oh! I didn't even think to look. Deleted.
pchickey has enabled auto merge for PR #5397.
pchickey merged PR #5397.
Last updated: Dec 23 2024 at 12:05 UTC