Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,22 @@ here.**
and the crate resolves a project the way the other ports do: the `.metaobjects/config.json`
reader, the four source kinds, directory discovery (symlinks followed, `_pending` skipped), the
`iam` and `ai` library sources embedded in the crate, and the naming strategies, pluralizers and
collection-name collision check. It passes `yaml-conformance` 15 of 19, and the
collection-name collision check. It passes `yaml-conformance` 18 of 19, and the
`source-resolution-conformance` and `naming-conformance` corpora in full. Nothing is published.

- **Cross-port stage benchmark and Rust port documentation.** `scripts/bench-load/stages.py` runs
every port (TypeScript, Python, C#, Java, Kotlin, Rust) over the same model, stage by stage: load
and validate, a no-change generation run, a full generation and a one-entity-edit regeneration,
each as the median of N runs with peak memory, into one `report.json` and one Markdown table. It
never gates on a number. The Rust generation stages read "not available yet" until `cargo meta gen`
exists and are picked up on their own once it does. `--project <path> --out <dir>` runs it on a
private project, copies the metadata, and refuses an output inside the repository. `load_bench`
gained `--dir` and `--json`, `gen-model.py` gained `--unique-names`, and Java has a warm-load
driver. New page `docs/ports/rust.md` says what the preview Rust port does and does not do, how
to build and test it, and the planned `cargo meta` command; the crates.io name `cargo-meta` is
held by an unrelated crate, so the CLI crate will publish under another name that installs a
`cargo-meta` binary (a plan, not a promise). Nothing is published.

### Changed

- **Release policy: vocabulary is versioned by feature, not by kind (ADR-0035 Amendment 5).** Adding
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ first-week wedge plan — and `meta init` picks up from there.
- Already have a codebase? → Have your coding agent run the
[fit assessment](#try-it-on-your-repo--nothing-to-install) — read-only, no
install; it finds the drift already in your git history.
- New here? Pick your language → [`docs/ports/`](docs/ports/) (TS / Java / Kotlin / C# / Python).
- New here? Pick your language → [`docs/ports/`](docs/ports/) (TS / Java / Kotlin / C# / Python; Rust is in [preview](docs/ports/rust.md)).
- Want the metamodel feature reference? → [`docs/features/`](docs/features/).
- Want the documentation index? → [`docs/README.md`](docs/README.md).
- Want the design rationale? → [`spec/`](spec/) + [`docs/superpowers/specs/`](docs/superpowers/specs/).
Expand All @@ -169,6 +169,7 @@ first-week wedge plan — and `meta init` picks up from there.
| Kotlin | **Maven Central `8.2.0`** — codegen tier on top of Java: 17 generators (entity, Exposed table, names, relations, repository, output-parser, output-prompt, render-helper, extractor, filter-allowlist, validator, Spring config, storedProc, Spring controller, requirement-tests, api-docs, report-export); 24 / 24 persistence-conformance | [`docs/ports/kotlin.md`](docs/ports/kotlin.md) | [`server/java/codegen-kotlin/`](server/java/codegen-kotlin/) · [`server/java/metadata-ktx/`](server/java/metadata-ktx/) |
| C# | **NuGet `1.2.0`** — loader + conformance + EF Core codegen + render engine + `dotnet meta` CLI all shipped | [`docs/ports/csharp.md`](docs/ports/csharp.md) | [`server/csharp/`](server/csharp/) |
| Python | **PyPI `1.2.0`** — loader + conformance + render + entity-model codegen + ObjectManager runtime shipped; schema migrations are TS-owned (ADR-0015) | [`docs/ports/python.md`](docs/ports/python.md) | [`server/python/`](server/python/) |
| Rust | **Preview, unpublished** — loader (JSON + YAML), project and source resolution, naming and all 40 validation passes; 526 / 526 metamodel conformance. No codegen and no `cargo meta` yet (ADR-0065) | [`docs/ports/rust.md`](docs/ports/rust.md) | [`server/rust/`](server/rust/) |

## Capability matrix

Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ docs/
├── java.md
├── kotlin.md
├── csharp.md
└── python.md
├── python.md
└── rust.md # the Rust port, in preview: loader and validation only, no codegen yet
```

If this list and `ls docs/features/` ever disagree, trust the directory listing —
Expand Down
3 changes: 2 additions & 1 deletion docs/features/language-differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ here changes in the same pull request.
- [CLI architecture](cli.md): which commands each port's own CLI carries.
- [Migrations and drift](migrations-and-drift.md): the schema workflow every port uses.
- The port pages: [TypeScript](../ports/typescript.md), [C#](../ports/csharp.md),
[Java](../ports/java.md), [Kotlin](../ports/kotlin.md), [Python](../ports/python.md).
[Java](../ports/java.md), [Kotlin](../ports/kotlin.md), [Python](../ports/python.md); the
Rust port is in preview and not in this comparison yet: [Rust](../ports/rust.md).
145 changes: 145 additions & 0 deletions docs/ports/rust.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Rust port (preview)

The Rust port is **in preview** ([ADR-0065](../../spec/decisions/ADR-0065-rust-is-the-sixth-port.md)).
It reads a project, validates it and serializes it, and it is held to the same shared conformance
corpora as the other five ports. It does not generate code yet, and **nothing is published**: there
is no crate on crates.io, so there is nothing to `cargo add`. You work from a checkout of this
repository.

This page says what runs today, what does not exist yet, and how to build and test it. For the
decisions behind the port (why Rust, the layout, the preview rules), read the ADR.

## What works today

One crate, `metaobjects`, in the Cargo workspace at `server/rust/`:

| Area | What it does |
|---|---|
| Loading | Reads canonical JSON and sigil-free authoring YAML ([ADR-0006](../../spec/decisions/ADR-0006-ai-first-yaml-authoring.md)): packages, children, subtypes, attributes, `extends` and references, with a line and column on every error from a YAML file. |
| Project resolution | Reads `.metaobjects/config.json` and resolves sources the way every port does: the four source kinds, directory discovery (symlinks followed, `_pending` skipped), and the `iam` and `ai` library sources, which are embedded in the crate so a library resolves with no file on disk. See [Metadata sources](../features/metadata-sources.md). |
| Naming | The naming strategies, the pluralizers and the collection-name collision check ([ADR-0058](../../spec/decisions/ADR-0058-one-physical-naming-setting.md)). |
| Registry | The type registry and the built-in providers. It is strict and sealed after bootstrap, with the same `ERR_*` codes as the other ports. |
| Validation | All 40 validation passes the TypeScript loader runs, in the same order. The ordered list is `PASSES` in `server/rust/metaobjects/src/validate/mod.rs`. |
| Serializer | The canonical serializer. A tree it loads serializes to the same bytes the other ports write. |
| Frozen tree | The loader freezes the tree when it finishes. A frozen tree memoizes its resolved reads (effective children, attributes and array-ness), so many readers can share one. |
| Timings | Every load records how long each phase and each validation pass took (`LoadResult::timings`). |

### Conformance

The port runs five shared corpora. A fixture that fails and is not on the port's ledger prints a
warning and does not fail the `rust` lane while the port is in preview; a fixture that passed and
regresses still fails it, because each ledger records how many fixtures must pass (`minPassing`) and
may only shrink.

| Corpus | Rust today |
|---|---|
| `registry-conformance` | byte-identical manifest |
| `conformance` (the metamodel corpus) | **526 of 526**, and the ledger is empty |
| `yaml-conformance` | 18 of 19. The one on the ledger, `yaml-ref-root-escape`, waits for the root-level `::` reference rules of [ADR-0059](../../spec/decisions/ADR-0059-references-resolve-once-after-the-tree.md), which are reference resolution, not a validation pass. |
| `source-resolution-conformance` | all 28 cases |
| `naming-conformance` | all of it |

Rust is not yet a column in the [per-corpus table](../CONFORMANCE.md#per-corpus-totals); it joins
when the port leaves preview. The other corpora (render, persistence, API contract, codegen compile)
need code the port does not have yet.

### Load benchmark

`load_bench` (a Cargo example) times loading a 20-times model built in memory from the public
conformance fitness model, per load phase and per validation pass, with the peak memory of the
process. Its invocations, the baseline options and the committed baseline are documented in
[`scripts/bench-load/README.md`](../../scripts/bench-load/README.md#rust-load_bench).

[`scripts/bench-load/`](../../scripts/bench-load/README.md) runs this same model through every port,
stage by stage (load and validate, a no-change generation run, a full generation, a one-entity-edit
regeneration, peak memory), so a port's speed can be tracked per feature next to the others.

## What does not exist yet

- **Code generation.** There is no Rust generator, no `meta gen` equivalent and no `eject`. The port
loads and checks metadata; it does not write code.
- **The `cargo meta` command.** It is planned, not built. ADR-0065 names it: a Cargo subcommand (a
`cargo-meta` binary), the way the other build-tool-hosted ports spell theirs (`dotnet meta`,
`mvn metaobjects:...`). A bare `meta` stays the Node schema CLI.
- **Drift checks.** There is no `verify` for Rust yet, so nothing compares generated Rust to the model.
- **The service tier.** No `ObjectManager`, no persistence drivers and no web adapters.
- **Templates and prompts.** No render engine, no payload value objects and no output parser.
- **Publication.** The crate sets `publish = false`. There is no crates.io release, no version policy
beyond ADR-0065 (the port starts on its own `0.x` line when it publishes, and joins the lockstep
numbers only when it leaves preview), and `Cargo.toml` is not a stable interface.

**A note on the name `cargo-meta`.** The crates.io name `cargo-meta` is held by an unrelated crate. The
plan is to publish the CLI crate under another name that installs a `cargo-meta` binary, so the command
you type is still `cargo meta`. That is a plan, not a promise: the crate name is not chosen, and
nothing is reserved.

The schema stays where it is for every port: migrations and database checks run in the Node `meta`
tool ([ADR-0015](../../spec/decisions/ADR-0015-single-shared-migrate-engine.md);
[What differs by language](../features/language-differences.md)).

## Build and test

You need `rustup`. The workspace pins its toolchain in `server/rust/rust-toolchain.toml` (1.94.1, with
`rustfmt` and `clippy`), so `cargo` picks it up on its own.

```bash
cd server/rust
cargo build
cargo test --locked # the corpora and the unit tests, about a second once built
cargo fmt --all --check
cargo clippy --locked --all-targets -- -D warnings
```

The repository's one pre-PR script runs the same steps, plus the `load_bench` table (printed, never
gated on a number):

```bash
scripts/ci-local.sh --only rust
```

A change under `server/rust/` selects the `rust` lane in `scripts/ci-local.sh --affected`, the PR checks
and the local CI. Raise the pinned toolchain deliberately, in its own commit.

Use the crate from a checkout, as a path dependency:

```toml
[dependencies]
metaobjects = { path = "<repo-root>/server/rust/metaobjects" }
```

```rust
use metaobjects::collection::resolve_collection;
use metaobjects::loader::Loader;
use metaobjects::naming::NamingRegistry;
use metaobjects::providers::default_registry;

let registry = default_registry()?;
let collection = resolve_collection(project_dir, None, &NamingRegistry::builtin())?;
let (sources, read_errors) = collection.read_sources();
let result = Loader::new(&registry).load_sources(&sources);
assert!(read_errors.is_empty() && result.errors.is_empty());
```

The API is a preview and will change; read `server/rust/metaobjects/tests/project_load.rs` for a
working call.

## A worked codegen exercise: `examples/tasks-axi-rust/`

[`examples/tasks-axi-rust/`](../../examples/tasks-axi-rust/README.md) is the nearest thing to a Rust
code generator today, and it is an experiment, not a product. It reimplements the read path of an
agent-facing task tracker as a small Rust binary and **generates the Rust for its rows, enums, error
codes, argument parser, help text and dispatcher from a MetaObjects model**, with an owned TypeScript
generator (ADR-0034). The real tool is the oracle: for every implemented command and flag the two print
the same bytes and exit with the same code.

It changes nothing in MetaObjects. Its committed generated crate is the set of golden outputs a
Rust-native generator would have to reproduce, and its README records what the model had to carry. Read
its README, not this page, for what it does and does not do.

## See also

- [ADR-0065: Rust is the sixth port](../../spec/decisions/ADR-0065-rust-is-the-sixth-port.md)
- [Conformance coverage](../CONFORMANCE.md): the corpora, and Rust's standing in them.
- [What differs by language](../features/language-differences.md)
- The other port pages: [TypeScript](typescript.md), [C#](csharp.md), [Java](java.md),
[Kotlin](kotlin.md), [Python](python.md).
59 changes: 57 additions & 2 deletions scripts/bench-load/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Warm-load benchmark
# Cross-port benchmarks: load and generation

Measures how long each loader takes to load a model that is N times the size of the
This README owns the usage of every benchmark in this directory and of the Rust `load_bench`
example. Two tools: `run.sh` (warm load across model sizes) and `stages.py` (every stage, every
port).

## Warm load by model size

`run.sh` measures how long each loader takes to load a model that is N times the size of the
persistence-conformance "fitness" model, so growth with model size is visible (a quadratic
lookup shows up as a 20x model costing far more than 20x the 1x model).

Expand All @@ -20,6 +26,55 @@ scripts/bench-load/run.sh [--sizes "1 5 10 20"] [--loads 7] [--ports "typescript
- `--canonical-dir` also writes each port's canonical serialization of the largest model, so two
runs can be compared byte for byte (`cmp`) to show a change did not alter the loaded tree.

## Every port, stage by stage

```
python3 scripts/bench-load/stages.py [--runs 5] [--copies 20] [--ports "typescript python csharp java kotlin rust"]
[--out <dir>]
python3 scripts/bench-load/stages.py --project <path> --out <dir-outside-the-repo> [--metadata-dir metaobjects]
```

`stages.py` times four stages per port on the same model: `load` (warm load and validate),
`gen-noop` (the generation command with nothing changed), `gen-full` (from clean output) and
`gen-edit` (after one entity gains a field), each the median of `--runs` runs with the peak
resident set. It writes `report.json` and `report.md` to `--out` and never gates on a number. A
stage a port cannot run prints "not available" with the reason: the Rust generation stages read
that way until `cargo meta gen` exists, and run on their own once it does (set
`MO_BENCH_RUST_META` to use a command that is not on `PATH`, `MO_BENCH_RUST_GEN_ARGS` for its
flags). Each port generates with its own CLI and one reference generator, so a generation row
tracks a port against itself over time more than against the others. Java needs the
`metaobjects-*` artifacts of the repo version in the local Maven repository; Kotlin loads
through the Java loader, so it has generation rows only.

The model is the fitness model repeated `--copies` times with every declaration renamed per copy
(`gen-model.py --unique-names`) so it can be generated as well as loaded.

`--project` measures your own project: its metadata directory and, when present, its
`.metaobjects/config.json` are copied into scratch (the project is never written to), and `--out`
must be outside this repository. Only the model label is anonymized; failure reasons may quote
commands and errors, so a private run stays local and its report is never committed. The TypeScript
and Java load drivers and the Java/Kotlin generation projects pass no `libraries` option, so a
project using libraries fails those columns.

## Rust `load_bench`

The Rust port's load benchmark is a Cargo example, `server/rust/metaobjects/examples/load_bench.rs`.
It loads a 20-times model built in memory from the fitness model, then prints the median time of
each load phase and of each validation pass, and the peak memory of the process.

```
cd server/rust
cargo run --release --example load_bench # 20 copies, 15 iterations, JSON
cargo run --release --example load_bench -- 20 15 yaml # the same model as YAML
cargo run --release --example load_bench -- 20 15 project # the project-reading steps
cargo run --release --example load_bench -- --dir <project> --json # a real project, one JSON line
```

`--write-baseline <file>` records a run and `--baseline <file>` compares against one. A baseline is
a record to read, never a threshold: the committed `server/rust/metaobjects/baselines/load-20x.json`
was recorded on one machine, and a delta between two machines measures the machine. Compare against
a baseline you recorded yourself, before and after a change, on the same machine.

Wall-clock is noisy on a busy machine. Compare the 20x/1x growth ratio, not absolute
milliseconds, and treat the deterministic call-count tests in each port
(`top-level-index` tests) as the regression gate; this tool is for measurement, not CI.
Loading
Loading