Skip to content

feat: generate the RPC shape for a protocol (surface 4.2) - #2

Merged
Kinflou merged 1 commit into
mainfrom
feat/protocol-codegen
Sep 1, 2026
Merged

feat: generate the RPC shape for a protocol (surface 4.2)#2
Kinflou merged 1 commit into
mainfrom
feat/protocol-codegen

Conversation

@Kinflou

@Kinflou Kinflou commented Sep 1, 2026

Copy link
Copy Markdown
Member

code mode now emits, per FrozenUnit::Protocol, everything comline-runtime's surface-4 contract needs — turning the hand-written stand-ins in the runtime's dispatch_roundtrip / client_roundtrip tests into real generator output.

What's emitted

piece shape
params pub struct <Proto><Fn>Params per function that takes args (owned fields)
per-fn error pub enum <Proto><Fn>Error from the function's throws ordinals — resolved against the FrozenUnit::Error units' ordinal (local or a re-exported import, core#47); empty enum when it throws nothing
union pub enum <Proto>Error ∪ every ! in the protocol + From<<Fn>Error> impls
provider pub trait <Proto> — sync, &self, Result<R, <Fn>Error> (schema errors only) + pub const <PROTO>_CALLS: &[&str]
dispatcher <Proto>Dispatcher<S> impl comline_runtime::contract::Dispatch — index jump table → decode params → run handler → frame the ok/err Envelope
client <Proto>Client<T, W> wrapping comline_runtime::client::Client — one method per fn → Result<R, CallError<<Fn>Error>>

FrozenUnit::Error gets struct codegen too now (it was skipped entirely before). lib mode's generated Cargo.toml git-deps comline-runtime when any schema has a protocol.

Deferred (noted in code)

  • Borrowed generated types (<'de>) — params are owned (String / Vec<T>) for now.
  • True one-way_return: None and KindValue::Unit both render -> () (request/response with an empty ack); fire-and-forget is an unbuilt runtime feature.
  • Function.parameters (per-call settings) — not consumed yet.

Tests

tests/compiles.rs — generates a lib crate for a protocol (throwing call, list return, zero-arg call, unit return) and actually cargo builds it against comline-runtime (string assertions can't prove it compiles). Plus expanded string-match coverage in tests/generate.rs. cargo test --workspace green (1 + 5 + doctests).

Follow-up

The generation conformance corpus's protocol golden will need a re-bless once this lands (separate PR — bump its comline-codegen-rust rev, CONFORMANCE_BLESS=1).

`code` mode now emits, per FrozenUnit::Protocol, everything the runtime's
surface-4 contract needs -- turning the hand-written stand-ins in
comline-runtime's dispatch_roundtrip / client_roundtrip tests into real
generator output:

- one params struct per function that takes args (<Proto><Fn>Params)
- one schema-only error enum per function from its `throws` ordinals
  (<Proto><Fn>Error; empty when it throws nothing), resolved against the
  FrozenUnit::Error units' `ordinal` -- local or a re-exported import
- a per-protocol union <Proto>Error + From<<Fn>Error> impls
- the provider trait `pub trait <Proto>` (sync, schema errors only) plus
  `pub const <PROTO>_CALLS: &[&str]`
- <Proto>Dispatcher<S> impl comline_runtime::contract::Dispatch -- an index
  jump table, decode params, run the handler, frame the ok/err Envelope
- <Proto>Client<T, W> wrapping comline_runtime::client::Client -- one method
  per function returning Result<R, CallError<<Fn>Error>>

FrozenUnit::Error also gets struct codegen now (it was skipped entirely).
KindValue::Unit and a no-return function both render `-> ()` for now
(true one-way / fire-and-forget is a runtime feature, not built yet).
Params are owned (String / Vec<T>); borrowed `<'de>` generated types are a
follow-up. `Function.parameters` (per-call settings) not consumed yet.

lib mode's generated Cargo.toml git-deps comline-runtime when any schema
has a protocol.

tests/compiles.rs generates a lib crate for a protocol (throwing call,
list return, zero-arg call, unit return) and `cargo build`s it against
comline-runtime -- string assertions can't prove it compiles. Plus
expanded string-match coverage in tests/generate.rs.
@Kinflou
Kinflou merged commit 7a9914d into main Sep 1, 2026
2 checks passed
@Kinflou
Kinflou deleted the feat/protocol-codegen branch September 1, 2026 17:09
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.

1 participant