sdk: emit bind-macro fault and level conversions as From impls#452
Conversation
lgahdl
left a comment
There was a problem hiding this comment.
Worth flagging before the code review: PR #358 (still open, unmerged) already closes the same issue (#264) with a very similar approach — converting the same shim functions in the same two files (crates/nexum-sdk/src/wit_bindgen_macro.rs, crates/shepherd-sdk/src/wit_bindgen_macro.rs) to From impls. Worth closing one of the two to avoid duplicate work and a merge conflict once either lands — probably whichever hasn't been rebased onto the current Videre train, since this one is stacked on feat/m3-intent-body-no-std and #358 predates the train entirely.
On the code itself: this is clean. Both From impls are a faithful 1:1 copy of the old functions' logic (including the #[non_exhaustive] wildcard arm and the five-tier Level if/else chain — no branch dropped), the orphan-rule reasoning holds since wit_bindgen::generate! makes the wit Fault type crate-local at each macro-expansion site, and all 6 changed module call sites resolve ?/.map_err(Into::into) to the same target type the old explicit calls produced. One tiny doc nit: docs/05-sdk-design.md's updated snippet relies on ?'s implicit From conversion without naming the From impl in scope, unlike tutorial-first-module.md's equivalent update which does call it out explicitly — a one-line note there would keep the two docs consistent.
lgahdl
left a comment
There was a problem hiding this comment.
Re-posting as an inline comment (my earlier review body-only comment didn't render in the diff view).
|
|
||
| /// Generate `WitBindgenHost` + the `*Host` trait impls + the error / | ||
| /// level converters for the selected capabilities. See module docs. | ||
| /// level `From` impls for the selected capabilities. See module docs. |
There was a problem hiding this comment.
Worth flagging before the code review: PR #358 (still open, unmerged) already closes the same issue (#264) with a very similar approach — converting the same shim functions in the same two files (crates/nexum-sdk/src/wit_bindgen_macro.rs, crates/shepherd-sdk/src/wit_bindgen_macro.rs) to From impls. Worth closing one of the two to avoid duplicate work and a merge conflict once either lands — probably whichever hasn't been rebased onto the current Videre train, since this one is stacked on feat/m3-intent-body-no-std and #358 predates the train entirely.
On the code itself: this is clean. Both From impls are a faithful 1:1 copy of the old functions' logic (including the #[non_exhaustive] wildcard arm and the five-tier Level if/else chain — no branch dropped), the orphan-rule reasoning holds since wit_bindgen::generate! makes the wit Fault type crate-local at each macro-expansion site, and all 6 changed module call sites resolve ?/.map_err(Into::into) to the same target type the old explicit calls produced. One tiny doc nit: docs/05-sdk-design.md's updated snippet relies on ?'s implicit From conversion without naming the From impl in scope, unlike tutorial-first-module.md's equivalent update which does call it out explicitly — a one-line note there would keep the two docs consistent.
There was a problem hiding this comment.
Thanks - two threads here.
Duplicate: closed #358, the develop-based PR that predates the train, as superseded by this one. #264 will close when this lands. Kept this PR since it is the version rebased onto the Videre train, as you suggested.
Doc nit: the two docs differ by audience on purpose. tutorial-first-module.md names the From impls because it teaches the reader the conversion; docs/05-sdk-design.md's snippet stays terser and lets ? speak for itself, in keeping with the terse-docs convention for the design docs. Leaving 05-sdk-design.md as-is, but happy to add the one-line note if you would rather they match verbatim.
446ee89 to
6d89d42
Compare
Replace the convert_fault / sdk_fault_into_wit / convert_level shim functions with From impls emitted by the macro (orphan-legal in the per-cdylib expansion), so module glue converts via ? and Into. No behaviour change.
eb84355 to
b866230
Compare
What
Replaces the bind-macro's
convert_fault/sdk_fault_into_wit/convert_levelshim functions withFromimpls (bothFaultdirections plusLevel), emitted per-cdylib so the orphan rule is satisfied. Updates every module call site from.map_err(convert_fault)/.map_err(sdk_fault_into_wit)to?/.map_err(Into::into), plus the two SDK-design docs.Why
Verb-named pure infallible conversions should be
Fromimpls, matching the idiom already used forassemble_log/project_chain_log. No behaviour change.Testing
None run in this PR; relies on the stacked train's gate.
AI Assistance
Generated with Claude Code.
Closes #264