Skip to content

sdk: emit bind-macro fault and level conversions as From impls#452

Merged
mfw78 merged 1 commit into
dev/m1from
feat/m3-bind-macro-from-impls
Jul 21, 2026
Merged

sdk: emit bind-macro fault and level conversions as From impls#452
mfw78 merged 1 commit into
dev/m1from
feat/m3-bind-macro-from-impls

Conversation

@mfw78

@mfw78 mfw78 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What

Replaces the bind-macro's convert_fault / sdk_fault_into_wit / convert_level shim functions with From impls (both Fault directions plus Level), 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 From impls, matching the idiom already used for assemble_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

@lgahdl lgahdl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 lgahdl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mfw78
mfw78 force-pushed the feat/m3-intent-body-no-std branch from 446ee89 to 6d89d42 Compare July 21, 2026 07:51
Base automatically changed from feat/m3-intent-body-no-std to dev/m1 July 21, 2026 08:32
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.
@mfw78
mfw78 force-pushed the feat/m3-bind-macro-from-impls branch from eb84355 to b866230 Compare July 21, 2026 08:33
@mfw78
mfw78 merged commit f7778ab into dev/m1 Jul 21, 2026
6 checks passed
@mfw78
mfw78 deleted the feat/m3-bind-macro-from-impls branch July 21, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants