Skip to content

Generate value nodes; introduce field-type override + hand-written-union skip#95

Merged
lorisleiva merged 1 commit into
mainfrom
loris/spec-gen-value-box-rule
Jun 10, 2026
Merged

Generate value nodes; introduce field-type override + hand-written-union skip#95
lorisleiva merged 1 commit into
mainfrom
loris/spec-gen-value-box-rule

Conversation

@lorisleiva

Copy link
Copy Markdown
Member

This PR brings the value category into the generator: 16 node structs are emitted under codama-nodes/src/generated/value_nodes/, plus the renamed EnumVariantData inline union (enumValuePayload in the spec). Hand-written value_nodes/*.rs files shrink to constructors and #[cfg(test)] mod tests, mirroring the established pattern. Three pieces of generator infrastructure land alongside, each driven by a one-entry config that future PRs can extend or simplify: HAND_WRITTEN_UNIONS skips category unions whose Rust counterpart can't be reproduced mechanically (currently the value category's valueNode, hosted as the hand-written RegisteredValueNode with #[derive(RegisteredNodes)]); FIELD_TYPE_OVERRIDES pins a specific (node, attr) pair to a bespoke Rust type when the spec can't capture it (currently numberValueNode.number \u2192 Number, since the spec says float(f64) but Rust uses a Number enum with a serde(from/into = "JsonNumber") adapter and eight From<uN/iN/fN> impls \u2014 all kept hand-written in number_value_node.rs); and UNION_NAME_OVERRIDES gains an entry for enumValuePayload \u2192 EnumVariantData. The inline-union emit path also now uses the Rust override name (when present) for the on-disk file name, so enumValuePayload lands at enum_variant_data.rs matching its type name. The enum Rust keyword is added to the field-name escape set (enumValueNode.enum \u2192 r#enum). Box rule applies: constantValueNode.{type,value}, mapEntryValueNode.{key,value}, someValueNode.value, structFieldValueNode.value, and enumValueNode.value (as Box<Option<EnumVariantData>>) are all boxed; the corresponding hand-written constructors use Box::new(...) and tests dereference with *.

lorisleiva commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

Merge activity

  • Jun 10, 2:13 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 10, 2:19 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 10, 2:19 PM UTC: @lorisleiva merged this pull request with Graphite.

@lorisleiva lorisleiva changed the base branch from loris/spec-gen-inline-unions-pda-seed to graphite-base/95 June 10, 2026 14:16
@lorisleiva lorisleiva changed the base branch from graphite-base/95 to main June 10, 2026 14:17
…ion skip

This PR brings the `value` category into the generator: 16 node structs are emitted under `codama-nodes/src/generated/value_nodes/`, plus the renamed `EnumVariantData` inline union (`enumValuePayload` in the spec). Hand-written `value_nodes/*.rs` files shrink to constructors and `#[cfg(test)] mod tests`, mirroring the established pattern. Three pieces of generator infrastructure land alongside, each driven by a one-entry config that future PRs can extend or simplify: `HAND_WRITTEN_UNIONS` skips category unions whose Rust counterpart can't be reproduced mechanically (currently the `value` category's `valueNode`, hosted as the hand-written `RegisteredValueNode` with `#[derive(RegisteredNodes)]`); `FIELD_TYPE_OVERRIDES` pins a specific `(node, attr)` pair to a bespoke Rust type when the spec can't capture it (currently `numberValueNode.number \u2192 Number`, since the spec says `float(f64)` but Rust uses a `Number` enum with a `serde(from/into = "JsonNumber")` adapter and eight `From<uN/iN/fN>` impls \u2014 all kept hand-written in `number_value_node.rs`); and `UNION_NAME_OVERRIDES` gains an entry for `enumValuePayload \u2192 EnumVariantData`. The inline-union emit path also now uses the Rust override name (when present) for the on-disk file name, so `enumValuePayload` lands at `enum_variant_data.rs` matching its type name. The `enum` Rust keyword is added to the field-name escape set (`enumValueNode.enum \u2192 r#enum`). Box rule applies: `constantValueNode.{type,value}`, `mapEntryValueNode.{key,value}`, `someValueNode.value`, `structFieldValueNode.value`, and `enumValueNode.value` (as `Box<Option<EnumVariantData>>`) are all boxed; the corresponding hand-written constructors use `Box::new(...)` and tests dereference with `*`.
@lorisleiva lorisleiva force-pushed the loris/spec-gen-value-box-rule branch from 5b769a4 to 7bf6396 Compare June 10, 2026 14:18
@lorisleiva lorisleiva merged commit 8d87575 into main Jun 10, 2026
4 checks passed
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