Skip to content

feat: handshake codegen — IR_HASH + connect / serve helpers - #6

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

feat: handshake codegen — IR_HASH + connect / serve helpers#6
Kinflou merged 1 commit into
mainfrom
feat/handshake-codegen

Conversation

@Kinflou

@Kinflou Kinflou commented Sep 1, 2026

Copy link
Copy Markdown
Member

The codegen half of runtime#8. A schema with a protocol now also emits:

pub const IR_HASH: u64 = 0x…;   // fingerprint of this file's frozen IR

impl<T: Transport, W: WireFormat> ChatClient<T, W> {
    pub fn connect(transport: T, format: W) -> Result<Self, RuntimeError> {
        let hs = Handshake::new(IR_HASH, format.name(), FRAMING_DATAGRAM, 0);
        Ok(Self(Client::connect(transport, format, hs)?))
    }
}

impl<S: Chat> ChatDispatcher<S> {
    pub fn serve<T: Transport, W: WireFormat>(self, transport: &mut T, format: W)
    -> Result<(), RuntimeError> {
        let hs = Handshake::new(IR_HASH, format.name(), FRAMING_DATAGRAM, 0);
        Server::new(self, format).serve_handshaked(transport, hs)
    }
}

ChatClient::new / a bare Server::serve still work for "misaligned mode".

IR_HASH is FNV-1a over the frozen units' Debug form — deterministic per generator version; a generator bump changes it, which is correct (different codegen ⇒ different handshake identity). A canonical cross-language hash from core's CAS, threaded through GenRequest, is the eventual form (noted in the code). Only emitted when the schema has a protocol.

Bumps the generated crate's comline-runtime pin to the handshake rev.

Tests

tests/generate.rsIR_HASH + both helpers for a protocol; no IR_HASH / comline_runtime for a protocol-less schema (8 string tests). tests/compiles.rs builds a protocol crate against comline-runtime, so the helpers compile too. Clippy clean.

Follow-up

A cli PR: switch the end-to-end test's driver to ChatClient::connect / ChatDispatcher::serve so the handshake runs through the real pipeline.

For a schema with a `protocol`, the generated `.rs` now carries:

- `pub const IR_HASH: u64` — a deterministic fingerprint of the schema's
  frozen units (FNV-1a over their Debug form). Stable per generator
  version; a generator bump changes it, which is correct. A canonical
  cross-language hash from core's CAS (threaded through GenRequest) is the
  eventual form — noted in the code.
- `<Proto>Client::connect(transport, format) -> Result<Self, RuntimeError>`
  — wraps `Client::connect` with `Handshake::new(IR_HASH, format.name(),
  FRAMING_DATAGRAM, 0)`.
- `<Proto>Dispatcher::serve(self, transport, format)` — builds a `Server`
  and calls `serve_handshaked` with the same handshake.

`<Proto>Client::new` / a bare `Server::serve` still work for "misaligned
mode". Bumps the generated crate's comline-runtime pin to the rev with
the handshake (runtime#8).

tests/generate.rs: the IR_HASH const + both helpers are emitted for a
protocol, and neither IR_HASH nor any comline_runtime reference appears
for a protocol-less schema. tests/compiles.rs already builds a protocol
crate against comline-runtime, so it now covers the helpers too.
@Kinflou
Kinflou merged commit a0ade3b into main Sep 1, 2026
2 checks passed
@Kinflou
Kinflou deleted the feat/handshake-codegen branch September 1, 2026 19:12
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