4fc65ccb99
`Term::Lam`'s two camelCase JSON tags become kebab-case, matching
the convention every other compound-key tag in the AST schema
already follows. After this iter the canonical JSON has zero
camelCase outliers.
## Schema swap (atomic, Task 2)
- `crates/ailang-core/src/ast.rs:492,494` — two
`#[serde(rename)]` strings: `"paramTypes" → "param-types"`,
`"retType" → "ret-type"`. Rust field names unchanged.
- `crates/ailang-core/src/workspace.rs:1925-1926` — in-source
JSON literal in the `ct1_validator_walks_lam_embedded_types`
test.
- `design/contracts/data-model.md:142-147` — fenced JSON block
in the canonical data-model contract. Honesty-Rule touch-point:
the contract document must describe the actual present-state
schema.
- `examples/test_loop_binder_captured_by_lambda.ail.json` and
`experiments/2026-05-12-cross-model-authoring/master/examples/fn_with_lambda.ail.json`
— the two `.ail.json` fixtures whose canonical-JSON embeds
the renamed tags.
The five files moved together within one task because `Term::Lam`
has no `#[serde(default)]` on `param_tys` / `ret_ty` — a
renamed-away key is a hard deserialise error. Splitting the swap
would have left the workspace untestable mid-step.
## RED → GREEN pin (Tasks 1, 2)
`crates/ailang-core/tests/design_schema_drift.rs` gains
`lam_serialises_with_kebab_keys`: pins that `serde_json::to_value(&Term::Lam{...})`
emits `"param-types"` / `"ret-type"` AND does not emit the old
camelCase keys. Companion: the existing
`design_md_anchors_every_term_variant` test now also asserts the
kebab anchors appear inside `data-model.md`'s `lam` fenced block.
Both confirmed RED on entry, GREEN after Task 2.
## Rustdoc honesty pass (Task 3)
Three pure-prose edits keep production rustdoc consistent with
the new schema vocabulary: `crates/ailang-core/src/ast.rs:8` (the
module-level rename enumeration), `crates/ailang-surface/src/parse.rs:81`
(prose mention of `lam`'s carry), `crates/ailang-check/src/lib.rs:1707`
(InstanceMethod routing helper rustdoc). No compile or test
consequence — Honesty-Rule maintenance.
## Plan-pseudo-vs-reality finding: under-audited hash blast radius
The brainstorm spec audited `crates/ailang-core/tests/hash_pin.rs`
exhaustively (5 pinned modules, zero `(lam ...)` occurrences,
"no hash refresh required"). It missed
`crates/ailang-surface/tests/prelude_module_hash_pin.rs` — a
separate hash-pin file in a different crate that pins `prelude.ail`,
which contains 11 `(lam ...)` forms. The prelude module hash
drifted (`6d0577ff0d4e50ac` → `562a03fc57e7e017`); the implementer
refreshed it with a Honesty-Rule provenance comment matching the
precedent set in commit `26fb345`. Form-A is unchanged — only the
canonical-JSON byte stream differs, which is exactly what the
rename targets. The spec-side learning is: schema-rename
brainstorms must walk *every* test crate for hash-pin files, not
just the home crate of the AST.
## Why this shape, and not the alternatives
- *`params-ty` / `ret-ty` (Rust-field-name vibe)* — rejected. The
AST JSON schema follows its own kebab/single-word convention,
not Rust field names. The other multi-word tag (`reuse-as`) is
kebab; abbreviating `params-ty` mixes singular+plural and has
no precedent.
- *Inline typed params as a sub-tag* (e.g. `params: [{name, type}, ...]`)
— rejected. Stronger semantic locality, but it changes schema
topology rather than tag spelling. Out of scope for a camelCase
correction; would have re-pinned far more than this milestone.
- *Bundle with #27 (arith-rename)* — rejected. #27 carries four
open brainstorm questions (mod vs rem, neg vs sub 0, Num class,
deprecation window) and is structurally a separate milestone.
Each gets one re-pin wave with its own rationale; no churn
saving from bundling.
## Honest call on the feature-acceptance gate
Clause 1 (LLM author naturally uses the new form) is the weakest
of the three. Direct empirical evidence is absent — the 2026-05-21
naming-A/B run measured a different axis. The argument is
indirect: a future LLM author generalises from the rest of the
schema ("compound keys are kebab"), and the two camelCase
outliers are precisely the sites where that generalisation
diverged from reality. Clause 2 (redundancy reduction) and
Clause 3 (no semantic surface touched) are direct.
## Forbidden touches verified untouched
`docs/plans/*.md` historic plans (which embed old tag names in
example JSON), `experiments/2026-05-12-cross-model-authoring/master/spec.md`,
`experiments/.../rendered/*.md`, and `experiments/.../runs/**` —
all left as frozen historical artefacts per Honesty-Rule
analogue (describe state at time of writing, not present state).
Verified via `git diff --name-only HEAD` (Task 4 Step 4).
## Verification
- `cargo test --workspace`: all test groups OK, 0 failed,
2 ignored (pre-existing).
- `cargo test -p ailang-surface --test round_trip`: GREEN
(Form-A unchanged invariant).
- New schema-shape pin and the extended data-model anchor walk:
GREEN after Task 2.
- Negative grep across `crates/`, `examples/`, `design/`,
`runtime/`: the only remaining `paramTypes` / `retType`
occurrences in checked-in code are the load-bearing
negative-assertion strings inside the new pin (intentional —
they are what makes the pin RED-able on regression).
- Stats: `bench/orchestrator-stats/2026-05-21-iter-schema-camelcase-fix.json`
— 4/4 tasks DONE, no re-loops, no review-loops.
closes #30
268 lines
9.8 KiB
Markdown
268 lines
9.8 KiB
Markdown
# Data model
|
|
|
|
## Data model
|
|
|
|
The on-disk JSON-AST is what the toolchain hashes, typechecks, and
|
|
lowers. **This section is the canonical schema.** The Rust types in
|
|
`crates/ailang-core/src/ast.rs` are the in-memory projection of it;
|
|
when the two disagree, this section wins, and the drift test
|
|
`crates/ailang-core/tests/design_schema_drift.rs` fires. Every
|
|
additive field is declared with `skip_serializing_if` so pre-existing
|
|
fixtures keep bit-identical canonical-JSON hashes — that gating
|
|
contract is what makes growing the schema cheap.
|
|
|
|
### Module
|
|
|
|
```jsonc
|
|
{
|
|
"schema": "ailang/v0",
|
|
"name": "<id>",
|
|
"imports": [{ "module": "<id>", "as": "<id>" }],
|
|
"defs": [Def...]
|
|
}
|
|
```
|
|
|
|
### Def
|
|
|
|
`kind ∈ { "fn", "const", "type", "class", "instance" }`. All five
|
|
are real surface forms. Class and type cross-module references
|
|
(canonical-form rule, qualified `<module>.<Class>` /
|
|
`<module>.<TypeName>`) follow the scoping rule in
|
|
[memory model](memory-model.md); the `class`/`instance` schema
|
|
narrative — defaults, superclasses, diagnostics — lives in
|
|
[typeclasses](typeclasses.md). Exported `fn` defs interact with
|
|
[embedding ABI](embedding-abi.md).
|
|
|
|
```jsonc
|
|
// fn (the unit that gets a content hash)
|
|
{ "kind": "fn",
|
|
"name": "<id>",
|
|
"type": Type, // typically Type::Fn, optionally wrapped in Forall
|
|
"params": ["<id>"...], // names bound in body, in type.params order
|
|
"body": Term,
|
|
"doc": "<optional string>",
|
|
"export": "<optional C symbol>", // omitted when absent (hash-stable when omitted); embedding-ABI surface — see prose below
|
|
"suppress": [Suppress...] // omitted when empty
|
|
}
|
|
|
|
// const (top-level value; codegen emits as a global; body must be pure)
|
|
{ "kind": "const",
|
|
"name": "<id>",
|
|
"type": Type,
|
|
"value": Term,
|
|
"doc": "<optional string>"
|
|
}
|
|
|
|
// type (algebraic data type; parameterised)
|
|
{ "kind": "type",
|
|
"name": "<id>",
|
|
"vars": ["<id>"...], // type parameters; omitted when empty (hash-stable when omitted)
|
|
"ctors": [
|
|
{ "name": "<id>", "fields": [Type...] } // nullary ctor: fields = []
|
|
...
|
|
],
|
|
"doc": "<optional string>",
|
|
"drop-iterative": true // opt-in; omitted when false (hash-stable when omitted)
|
|
}
|
|
|
|
// class (typeclass declaration; narrative in contracts/typeclasses.md)
|
|
{ "kind": "class",
|
|
"name": "<id>", // class name (e.g. "Show")
|
|
"param": "<id>", // single class parameter, kind *
|
|
"superclass": null, // or { "class": "<id>", "type": "<param>" } — "class": canonical form (bare for same-module, "<module>.<Class>" for cross-module)
|
|
"methods": [
|
|
{ "name": "<id>",
|
|
"type": Type, // FnSig over the class param
|
|
"default": Term // optional fallback body; null = abstract-required
|
|
}
|
|
...
|
|
],
|
|
"doc": "<optional string>"
|
|
}
|
|
|
|
// instance (typeclass instance; narrative in contracts/typeclasses.md)
|
|
{ "kind": "instance",
|
|
"class": "<id>", // class being instantiated; canonical form (bare for same-module, "<module>.<Class>" for cross-module)
|
|
"type": Type, // concrete type expression (never the class param)
|
|
"methods": [
|
|
{ "name": "<id>", "body": Term }
|
|
...
|
|
],
|
|
"doc": "<optional string>"
|
|
}
|
|
```
|
|
|
|
**`Suppress`** (entry in `FnDef.suppress`):
|
|
|
|
```jsonc
|
|
{ "code": "<diagnostic-code>", // e.g. "over-strict-mode"
|
|
"because": "<author reason>" // must be non-empty;
|
|
// empty/whitespace fires `empty-suppress-reason` (Error)
|
|
}
|
|
```
|
|
|
|
### Term (expression)
|
|
|
|
```jsonc
|
|
{ "t": "lit", "lit": Literal }
|
|
{ "t": "var", "name": "<id>" }
|
|
|
|
// fn application; tail flag triggers musttail under codegen.
|
|
// `tail` is omitted when false (hash-stable when omitted).
|
|
// `args` may be empty: a nullary call is the surface form
|
|
// `(app f)` (resolution of Gitea #12). Read-tolerant: a JSON
|
|
// document omitting the `args` key deserialises to `[]`.
|
|
{ "t": "app", "fn": Term, "args": [Term...], "tail": false }
|
|
|
|
{ "t": "let", "name": "<id>", "value": Term, "body": Term }
|
|
|
|
// Local recursive let. Always fn-shaped. The desugar pass
|
|
// lifts most `letrec` to a synthetic top-level fn; `lift_letrecs`
|
|
// finishes the job after typecheck for the residue that captures
|
|
// let-bound names. Post-codegen, no `letrec` survives.
|
|
{ "t": "letrec",
|
|
"name": "<id>", "type": Type, "params": ["<id>"...],
|
|
"body": Term, "in": Term }
|
|
|
|
{ "t": "if", "cond": Term, "then": Term, "else": Term }
|
|
|
|
// Effect-op invocation. `op` is "<eff>/<op>" (e.g. "io/print_str").
|
|
// `tail` triggers musttail (omitted when false).
|
|
{ "t": "do", "op": "<eff>/<op>", "args": [Term...], "tail": false }
|
|
|
|
// Ctor application. `args` is always emitted on write (including
|
|
// as `"args": []` for niladic ctors); reads tolerate the key being
|
|
// absent and treat it as `[]`. This mirrors the read/write
|
|
// asymmetry on `Term::App.args` (see above).
|
|
{ "t": "ctor", "type": "<id>", "ctor": "<id>", "args": [Term...] }
|
|
|
|
{ "t": "match", "scrutinee": Term, "arms": [Arm...] }
|
|
|
|
// Anonymous fn value; free vars captured from enclosing scope.
|
|
{ "t": "lam",
|
|
"params": ["<id>"...],
|
|
"param-types": [Type...],
|
|
"ret-type": Type,
|
|
"effects": ["<id>"...],
|
|
"body": Term }
|
|
|
|
// Sequencing. Semantically `let _ = lhs in rhs`; lhs must be Unit.
|
|
{ "t": "seq", "lhs": Term, "rhs": Term }
|
|
|
|
// Explicit RC clone. Codegen lowers as
|
|
// `call void @ailang_rc_inc(ptr %v)` before returning %v under `--alloc=rc`.
|
|
{ "t": "clone", "value": Term }
|
|
|
|
// Explicit reuse-as hint. `body` must be allocating
|
|
// (typically `ctor` or `lam`); `source` must be a bare `var`. Codegen
|
|
// lowers as in-place rewrite under `--alloc=rc`.
|
|
{ "t": "reuse-as", "source": Term, "body": Term }
|
|
|
|
// loop: strict iteration block. `binders` declares
|
|
// one or more loop parameters (name, type, init), evaluated in
|
|
// order on loop entry; `body` is in scope of all binders. The
|
|
// loop's value is `body`'s value on the iteration that exits via a
|
|
// non-`recur` branch. Strictly additive (no `skip_serializing_if`;
|
|
// pre-existing fixtures hash bit-identically — none carry the tag).
|
|
// No totality claim — an infinite loop is legal. See
|
|
// `docs/specs/2026-05-17-loop-recur.md`.
|
|
{ "t": "loop",
|
|
"binders": [ { "name": "<id>", "type": Type, "init": Term }, ... ],
|
|
"body": Term }
|
|
|
|
// recur: re-enter the lexically innermost enclosing
|
|
// `loop`, rebinding its binders positionally to `args`. Transfers
|
|
// control (no fall-through); valid only in tail position of its
|
|
// enclosing loop (enforced at typecheck, `recur-not-in-tail-position`).
|
|
{ "t": "recur",
|
|
"args": [ Term, ... ] }
|
|
```
|
|
|
|
In the MVP, `do` is only a direct call to a built-in effect op (no
|
|
handler); the effect system is described in [effects](../models/effects.md).
|
|
A `lam` term constructs an anonymous function value; free
|
|
variables of its body are captured from the enclosing scope.
|
|
|
|
Loop binders are alloca-resident: typecheck binds them in the
|
|
ordinary local scope plus a positional `loop_stack`, and codegen
|
|
lowers them as entry-block allocas. Capturing a `loop` binder into a
|
|
lambda body is rejected at typecheck via
|
|
`CheckError::LoopBinderCapturedByLambda`. See
|
|
`docs/specs/2026-05-17-loop-recur.md`.
|
|
|
|
**`Literal`**:
|
|
|
|
```jsonc
|
|
{ "kind": "int", "value": <i64> }
|
|
{ "kind": "bool", "value": <bool> }
|
|
{ "kind": "str", "value": "<utf-8>" }
|
|
{ "kind": "unit" }
|
|
{ "kind": "float", "bits": "<16-lowercase-hex>" }
|
|
```
|
|
|
|
**`Pattern`** (the `pat` field of an `Arm`; discriminator `p`):
|
|
|
|
```jsonc
|
|
{ "p": "wild" } // _
|
|
{ "p": "var", "name": "<id>" } // x — binds the value
|
|
{ "p": "lit", "lit": Literal }
|
|
{ "p": "ctor", "ctor": "<id>", "fields": [Pattern...] } // fields omitted when empty
|
|
```
|
|
|
|
Patterns are linear: each pattern variable may appear at most once.
|
|
|
|
### Type
|
|
|
|
The `Type::Con.name` canonical-form rule (bare for same-module /
|
|
primitives, qualified `<module>.<TypeName>` for cross-module) lives
|
|
in [memory model](memory-model.md); `Type::Fn`'s parameter-mode
|
|
metadata is defined and gated there as well.
|
|
|
|
```jsonc
|
|
// Type-constructor application. `args` omitted when empty
|
|
// (hash-stable when omitted, for non-parameterised cases like Int, Bool, ...).
|
|
{ "k": "con", "name": "<id>", "args": [Type...] } // "name": canonical form (bare for same-module / primitives, "<module>.<TypeName>" for cross-module)
|
|
|
|
// Function type. paramModes/retMode are metadata on Type::Fn —
|
|
// they are NOT separate Type variants, so every existing match-arm
|
|
// in the typechecker (unify, occurs, apply) keeps working.
|
|
// `paramModes` omitted when every entry is "implicit"; `retMode`
|
|
// omitted when "implicit" (hash-stable when omitted). Full mode
|
|
// contract lives in contracts/memory-model.md.
|
|
{ "k": "fn",
|
|
"params": [Type...],
|
|
"paramModes": [ParamMode...],
|
|
"ret": Type,
|
|
"retMode": ParamMode,
|
|
"effects": ["<id>"...] }
|
|
|
|
{ "k": "var", "name": "<id>" }
|
|
|
|
// Top-level polymorphism only. `constraints` carries class
|
|
// constraints (narrative in contracts/typeclasses.md); omitted when
|
|
// empty (hash-stable when omitted).
|
|
{ "k": "forall",
|
|
"vars": ["<id>"...],
|
|
"constraints": [{ "class": "<id>", "type": "<id>" }, ...], // "class": canonical form (bare for same-module, "<module>.<Class>" for cross-module)
|
|
"body": Type }
|
|
```
|
|
|
|
**`ParamMode`** (full contract in
|
|
[memory model](memory-model.md)):
|
|
|
|
```
|
|
"implicit" — unannotated / back-compat. Treated as `own` by the typechecker.
|
|
"own" — (own T) — caller transfers ownership; callee consumes.
|
|
"borrow" — (borrow T) — caller retains ownership; callee may not consume.
|
|
```
|
|
|
|
`implicit ≡ own` semantically; the distinction exists so existing
|
|
unannotated fixtures continue to serialize without the mode wrapper and keep their
|
|
canonical-JSON hash. The full mode contract (codegen consequences,
|
|
the over-strict-mode lint, the `Suppress` mechanism) lives in
|
|
[memory model](memory-model.md); the four language-design
|
|
preconditions that make RC sound live in
|
|
[language constraints](language-constraints.md).
|
|
|
|
Ratified by: `crates/ailang-core/tests/design_schema_drift.rs`.
|