Skip to content

Generated code cleanup + Optional field setters - #1

Merged
rooooooooob merged 4 commits into
masterfrom
optional-field-setters
Apr 9, 2020
Merged

Generated code cleanup + Optional field setters#1
rooooooooob merged 4 commits into
masterfrom
optional-field-setters

Conversation

@rooooooooob

Copy link
Copy Markdown
Contributor

Codegen cleanup:

Generated code should be more readable now, as we try harder to generate useful field names.
We also no longer store field such as

pub struct Foo {
    group: groups::Foo,
}

to now be

pub struct Foo(groups::Foo);

and likewise for the binary data wrappers.

In the future we could remove the groups module and have everything as a part of the root structs. They were an abstraction that was thought would help earlier on, especially if plain groups were represented as both array/map. But now the code generation process is changed and the generation of the exposed wrapper + the inner group data is more coupled rather than being a separate process, so it makes less sense. This would make no difference for the wasm API, but for expanding upon the generated library from rust it would be you'd just do self.x instead of self.0.x or self.0.x.0, etc.

The subset of shelley.cddl we support also was renamed to provide more field names

Optional field setters:

Before we only generated a way to set mandatory fields as part of the constructor, but now optional ones generate setters (the ctor defaults them to None) to actually use them.

Instead of defaulting to `index_n` for the `nth` field when there is no
specified name, we now try harder to generate field names using other
information like the type of the field so for example if we have:
`foo = [keyhash, scripthash, scripthash]`
we will generate something like:
```rust
struct Foo {
    keyhash: Keyhash,
    scripthash: Scripthash,
    scripthash2: Scripthash,
}
```
which also applies to constructors/setters or anywhere else the fields
would be referred to.

Array support is handled too so `bar = [0, [input]]` would be:
```rust
struct Bar {
    inputs: Inputs,
}
```
since the 0 isn't stored as we only need it for serialization
@rooooooooob
rooooooooob merged commit b818955 into master Apr 9, 2020
@rooooooooob
rooooooooob deleted the optional-field-setters branch April 9, 2020 04:48
SebastienGllmt added a commit that referenced this pull request Jul 2, 2026
known-red #1 (passthrough alias to a named map typedef -> dangling `MapU64To…`
wasm type, E0425) is not shallowly fixable. Records the investigation so it
isn't re-attempted:

The named map has a dual representation — a transparent `pub type Mp = BTreeMap`
typedef AND a wasm wrapper struct. Inlining the map in the alias base_type is
load-bearing for rust/newtype/struct-field serialization, but it drops the
wrapper name the wasm side needs. Keeping a `Rust(Mp)` reference instead greens
array-element + map-value but regresses collmap__newtype-inner (E0599
BTreeMap::serialize) and breaks struct-field/map-key — a single shared base_type
can't serve both crates (arrays work only because they're transparent on both).
The real fix is the wrapper-logic unification the handoff flags as out-of-scope,
or a wasm-only alias-emission path resolving a Map base_type to its Table
wrapper.

Keeps the 5 passthrumap__* cells skip-listed with a pointer to the ROADMAP
finding; no code change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: c797e9b0-113a-41f4-851d-8c35cd522549
SebastienGllmt added a commit that referenced this pull request Jul 2, 2026
…hook scope, extension guard, axis records

A fresh-context finding-by-finding verification of audit run #1's
remediation ledger against HEAD (88 findings: 78 VERIFIED with 12 gates
executed green and 10 mutations red — including the run's CRITICAL
verify.ts harness-failure guard and the canonical key-sort flip — 8
PARTIAL, 2 MISSING; full evidence in draft/test-setup-2/91) left a
narrow tail, all closed here:

- ArrayOptFields irregular-decode loop (tests/core/tests.rs) was
  assert-free (`let _ = ...unwrap()`): decode-accepts proved nothing.
  Now anchors every field per iteration to what the hand-built bytes
  encode (incl. c: nint -10 stored as magnitude 9; e compared by bytes —
  no PartialEq in the default profile).

- The robustness catalogs' panic silencer was a process-global no-op
  hook: any UNRELATED test failing concurrently during the window lost
  its panic diagnostics. Replaced with a thread-id-filtered hook that
  delegates other threads' panics to the previously-installed hook
  (with_thread_silenced_panics, shared by both catalog tests).

- The extensionless-input fix in api::cddl_paths (README/LICENSE/
  dotfiles in a multifile input dir must be skipped, not parsed) had no
  guard: new unit test directory_input_skips_non_cddl_files,
  mutation-verified red against a removed extension filter.

- The four never-dispositioned architecture axes are now in living docs
  (do-or-decline records, per the "decided, not overlooked" contract):
  MSRV/OS matrix for generated code and example/-plus-docs conformance
  in TESTING_ROADMAP's pending decisions; the decode-side
  reference-codec differential (ciborium/minicbor) folded into the
  decorrelated-conformance-parser bullet; cbor_event version-range
  testing recorded beside the ledgered DoS entry it will collide with.

- The orphan-fixture-dir meta-test deprioritization moved from the
  gitignored draft into "Explicitly not worth it"; corpus_detect.ts's
  blanket approximate-by-design header now names its five audited
  known-approximate cases so they read as decided, not overlooked.

Gates: fmt, clippy (0 warnings), core_no_wasm (anchored loop executes),
robustness suite, the new api unit test, project_corpus.ts PASS.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
SebastienGllmt added a commit that referenced this pull request Aug 2, 2026
…he family checks claims that arrive directly

The loose `<Elem>List` collision family reached its collected plain needs only
through a `[+ …]` shape — as a try_from source, or as a self-named rule — so a
spec with no `[+ …]` anywhere never consulted them. The table-keys member of
that gap was silent rather than loud: `create_and_register_array_type`'s
last-wins registration replaced an authored rule of the structural ident
outright, generation exited 0, and a field of the vanished type serialized as
an array of the key element. The rest are loud, but reach only the generic
duplicate-ident backstop, which reports the ident rather than the claim.

Detector #1 gains a direct-claim leg over every plain use it already collects
(a `*`-occurrence array, a map or table keys() wrapper, a rest row's keys(), a
rest tail), rejecting an incompatible claim in this family's voice; the map
side gains the symmetric leg for its plain map uses and table rules. Because
the swallow deletes its own evidence — once the mint has run, the overwritten
rule is indistinguishable from a rule that was never there —
`create_and_register_array_type` records the incompatible claim at the instant
it overwrites, and the leg reads that record.

A rule that IS `[* elem]` of the same element stays shared: it is that builder,
and the re-mint is byte-identical. That deliberate aliasing is now pinned by a
test and stated in the wasm docs beside the sole-owner table rule it mirrors.

Blast radius, measured by arming the leg before shipping it: zero committed
fixtures flagged (snapshot corpus green), and zero of the 150 rule idents plus
51 `@name`/`@rust_name` overrides across the four CML specs spell a structural
wrapper name. One in-tree re-attribution: the plain `[* bar]` claim moves from
the backstop to the per-kind leg, the same asymmetry-closing move the default
rest-row leg made for `MapKToV`. The backstop keeps a pin of its own on
`@used_as_elem`, whose mint has no RustType for the IR scan to see.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
SebastienGllmt pushed a commit that referenced this pull request Aug 18, 2026
Generated code cleanup + Optional field setters
SebastienGllmt added a commit that referenced this pull request Aug 18, 2026
known-red #1 (passthrough alias to a named map typedef -> dangling `MapU64To…`
wasm type, E0425) is not shallowly fixable. Records the investigation so it
isn't re-attempted:

The named map has a dual representation — a transparent `pub type Mp = BTreeMap`
typedef AND a wasm wrapper struct. Inlining the map in the alias base_type is
load-bearing for rust/newtype/struct-field serialization, but it drops the
wrapper name the wasm side needs. Keeping a `Rust(Mp)` reference instead greens
array-element + map-value but regresses collmap__newtype-inner (E0599
BTreeMap::serialize) and breaks struct-field/map-key — a single shared base_type
can't serve both crates (arrays work only because they're transparent on both).
The real fix is the wrapper-logic unification the handoff flags as out-of-scope,
or a wasm-only alias-emission path resolving a Map base_type to its Table
wrapper.

Keeps the 5 passthrumap__* cells skip-listed with a pointer to the ROADMAP
finding; no code change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: c797e9b0-113a-41f4-851d-8c35cd522549
SebastienGllmt added a commit that referenced this pull request Aug 18, 2026
…hook scope, extension guard, axis records

A fresh-context finding-by-finding verification of audit run #1's
remediation ledger against HEAD (88 findings: 78 VERIFIED with 12 gates
executed green and 10 mutations red — including the run's CRITICAL
verify.ts harness-failure guard and the canonical key-sort flip — 8
PARTIAL, 2 MISSING; full evidence in draft/test-setup-2/91) left a
narrow tail, all closed here:

- ArrayOptFields irregular-decode loop (tests/core/tests.rs) was
  assert-free (`let _ = ...unwrap()`): decode-accepts proved nothing.
  Now anchors every field per iteration to what the hand-built bytes
  encode (incl. c: nint -10 stored as magnitude 9; e compared by bytes —
  no PartialEq in the default profile).

- The robustness catalogs' panic silencer was a process-global no-op
  hook: any UNRELATED test failing concurrently during the window lost
  its panic diagnostics. Replaced with a thread-id-filtered hook that
  delegates other threads' panics to the previously-installed hook
  (with_thread_silenced_panics, shared by both catalog tests).

- The extensionless-input fix in api::cddl_paths (README/LICENSE/
  dotfiles in a multifile input dir must be skipped, not parsed) had no
  guard: new unit test directory_input_skips_non_cddl_files,
  mutation-verified red against a removed extension filter.

- The four never-dispositioned architecture axes are now in living docs
  (do-or-decline records, per the "decided, not overlooked" contract):
  MSRV/OS matrix for generated code and example/-plus-docs conformance
  in TESTING_ROADMAP's pending decisions; the decode-side
  reference-codec differential (ciborium/minicbor) folded into the
  decorrelated-conformance-parser bullet; cbor_event version-range
  testing recorded beside the ledgered DoS entry it will collide with.

- The orphan-fixture-dir meta-test deprioritization moved from the
  gitignored draft into "Explicitly not worth it"; corpus_detect.ts's
  blanket approximate-by-design header now names its five audited
  known-approximate cases so they read as decided, not overlooked.

Gates: fmt, clippy (0 warnings), core_no_wasm (anchored loop executes),
robustness suite, the new api unit test, project_corpus.ts PASS.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
SebastienGllmt added a commit that referenced this pull request Aug 18, 2026
…he family checks claims that arrive directly

The loose `<Elem>List` collision family reached its collected plain needs only
through a `[+ …]` shape — as a try_from source, or as a self-named rule — so a
spec with no `[+ …]` anywhere never consulted them. The table-keys member of
that gap was silent rather than loud: `create_and_register_array_type`'s
last-wins registration replaced an authored rule of the structural ident
outright, generation exited 0, and a field of the vanished type serialized as
an array of the key element. The rest are loud, but reach only the generic
duplicate-ident backstop, which reports the ident rather than the claim.

Detector #1 gains a direct-claim leg over every plain use it already collects
(a `*`-occurrence array, a map or table keys() wrapper, a rest row's keys(), a
rest tail), rejecting an incompatible claim in this family's voice; the map
side gains the symmetric leg for its plain map uses and table rules. Because
the swallow deletes its own evidence — once the mint has run, the overwritten
rule is indistinguishable from a rule that was never there —
`create_and_register_array_type` records the incompatible claim at the instant
it overwrites, and the leg reads that record.

A rule that IS `[* elem]` of the same element stays shared: it is that builder,
and the re-mint is byte-identical. That deliberate aliasing is now pinned by a
test and stated in the wasm docs beside the sole-owner table rule it mirrors.

Blast radius, measured by arming the leg before shipping it: zero committed
fixtures flagged (snapshot corpus green), and zero of the 150 rule idents plus
51 `@name`/`@rust_name` overrides across the four CML specs spell a structural
wrapper name. One in-tree re-attribution: the plain `[* bar]` claim moves from
the backstop to the per-kind leg, the same asymmetry-closing move the default
rest-row leg made for `MapKToV`. The backstop keeps a pin of its own on
`@used_as_elem`, whose mint has no RustType for the IR scan to see.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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