Skip to content

Declare records with one kiwi_records! row per definition - #7

Merged
dannote merged 1 commit into
masterfrom
records-macro
Oct 26, 2026
Merged

dannote merged 1 commit into
masterfrom
records-macro

Conversation

@dannote

@dannote dannote commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

The records feature used to write the schema out twice. The definition table took one struct field per line, about 6 lines per schema field, and the `kiwi_record_definitions` and `kiwi_records` constants repeated the same ids and values.

The record runtime template now defines a `kiwi_records!` macro, and the generator emits one call to it, with one row per definition and one line per field or enum value:

```rust
kiwi_records! {
MessageType MESSAGE_TYPE 0 0 "MessageType" "Elixir.Figler.Schema.MessageType" [] [
JOIN_START 0 "join_start";
...
];
...
}
```

The call expands to the same `KIWI_RECORD_DEFINITIONS` table and the same constant modules, so code using them doesn't change.

With Figma's schema, Figler's `generated.rs` drops from about 1.7 MB to 1.06 MB, together with Figler's own attribute-chain change. Both `mix ci` here and Figler's `mix ci` pass, apart from Figler's package tests, which can't build a Hex package while dependencies are local paths. The native records crate in the tests builds and round-trips data through the new macro.

Summary by CodeRabbit

  • Changed
    • Generated Rust for Figma schemas is approximately 630 KB smaller.
    • Record definitions, fields, enum variants, and associated constants continue to be generated, with each definition represented as a row in the record declaration.

The definition table and both constant modules wrote the schema out
twice more, the table one struct field per line. The record runtime now
defines kiwi_records!, which expands a row per definition, its fields and
enum values one per line, into the same table and constants.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a1e5fabb-0909-44b7-a79d-00842a69742c
Commits

Reviewing files that changed from the base of the PR and between c603ebb and e15f79a.

Files selected for processing: 3
  • CHANGELOG.md
  • codegen/kiwi_codec/rustler_generator/records.ex
  • codegen/kiwi_codec/rustler_generator/templates/records.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The record generator now emits each schema definition as a row in a kiwi_records! invocation. The macro expands those rows into the definition table, public constants, and record structs. The changelog reports a 630 KB reduction in generated Rust for Figma’s schema.

Changes: Record generation

Layer / File(s) Summary
Expand record schema rows
codegen/kiwi_codec/rustler_generator/templates/records.rs
The new kiwi_records! macro builds the definition table, definition-index constants, field and enum constants, and record structs from schema rows.
Emit schema rows
codegen/kiwi_codec/rustler_generator/records.ex, CHANGELOG.md
fragments/2 now emits a kiwi_records! row for each definition and removes the previous table and constant generators. The changelog records the output change and the reported Figma schema size reduction.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

Merge Risk: Minimal · up to e15f7

The change appears mergeable after normal checks; no concrete issue requiring a fix has been established.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: record generation now uses one kiwi_records! row per definition.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dannote
dannote merged commit 8379add into master Oct 26, 2026
5 checks passed
@dannote dannote mentioned this pull request Oct 26, 2026
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