# Defining dialects

The dialect system as an integrator meets it: defining a dialect —
a setting of every capability — for the programs on a given
tier, and wiring that definition into the compiler. What an
integration admits at load is [NLFC.10].

Paired with:

- [LDIA] — language-level contract: what `use` means, grammar,
  compile-time validation.
- [RBND] — how a compiled program's settings are carried and verified.

## What this is not

- Not the language spec. Rule authors read [LDIA].
- Not the capability registry. Authoritative table lives at [LCAP].
- Not a deployment topology guide.

---

(NDLC-1)=
## What a dialect does [NDLC.1]

(NDLC-1-1)=
[NDLC.1.1] A dialect is a named setting of every capability
([LDIA.1.1]). A program names the dialect it starts from in its `use`
directive, and may override single settings in a `use` block
([LDIA.2.1]).

*see also:* [LDIA.1.1](#LDIA-1-1), [LDIA.2.1](#LDIA-2-1)

(NDLC-1-2)=
[NDLC.1.2] The compiler validates every construct a program and its
libraries use against the program's resolved settings. A construct its
settings do not permit is a compile error naming the construct, the
capability, where the setting came from, and a refactor hint
([LDIA.5]). No runtime-on-first-use surprises.

*see also:* [LDIA.5](#LDIA-5)

(NDLC-1-3)=
[NDLC.1.3] Settings restrict **constructs, not the grammar**. The BNF is
the same under every setting. What differs is which constructs are
permitted and how the engine executes them, never what a program computes
([LDET.1.12]).

*see also:* [LDET.1.12](#LDET-1-12)

(NDLC-1-4)=
[NDLC.1.4] Three dialects are built in: `base`, `default` and `realtime`
([LDIA.9]). Running the compiler without a dialect file gives those three.
`realtime` is deferred in this edition, and the compiler refuses a program
that names it ([LDIA.3.2.3]).
Integrators define their own dialects when a tier genuinely lacks a
capability, or when they want the compiler to enforce architectural
boundaries.

---

*see also:* [LDIA.3.2.3](#LDIA-3-2-3), [LDIA.9](#LDIA-9)

(NDLC-2)=
## The dialect YAML file [NDLC.2]

(NDLC-2-1)=
[NDLC.2.1] A dialect is defined in a YAML file whose fields are `name`
and `settings` and no other. The compiler must refuse a file holding any other
top-level key ([NDLC.6.1]): a key nothing reads would claim something no tier
does.

```yaml
# Required. The name programs use in their `use` directive.
name: frame

# Required. A setting for every capability of [LCAP.1], by
# stable name: nothing is derived ([NDLC.2.2]). The deferred
# capabilities ([LCAP.2.10]) must be `false`.
settings:
  realtime: false
  constspace: false
  linear_scan: true
  logical: true
  dynamic_ttl: false
  regex: true
  float: true
  call: true
  publish: true
  cache: true
  cache_delete: true
  nocooldown: true
  series: false
  sampled_slots: false
  persist_on_series: false
  storage_hydrate_facts: false
  storage_hydrate_samples: false
```

*checks:* `alloy`  —  *see also:* [LCAP.1](#LCAP-1), [LCAP.2.10](#LCAP-2-10), [NDLC.2.2](#NDLC-2-2), [NDLC.6.1](#NDLC-6-1)

(NDLC-2-2)=
[NDLC.2.2] **`settings` must set every capability, and the loader
derives nothing.** Its keys must be exactly the capabilities of
[LCAP.1]: a capability left unset is an error, not a default
(`DS_VALIDATE_DIALECT_INCOMPLETE`), and a key naming no capability is
`DS_VALIDATE_DIALECT_UNKNOWN_CAPABILITY`. The settings must satisfy the
fundamental constraints of [LCAP.3.8]
(`DS_VALIDATE_DIALECT_DEPENDENCY`), and must set `realtime` and
`constspace` `false`, which are deferred in this edition
(`DS_VALIDATE_REALTIME_DEFERRED`, [LCAP.2.1.5]).

Defaulting an unset capability would be the silent behaviour this rule
exists to prevent, and the cost is concrete: when a capability is
**added** to the registry, every existing dialect file would take a value
for it by omission, and compiles would keep succeeding while the tier
silently gained or lost a construct. Requiring every key converts that
into a loud failure when the definition is loaded, which is the point.

*checks:* `alloy×8`  —  *see also:* [LCAP.1](#LCAP-1), [LCAP.2.1.5](#LCAP-2-1-5), [LCAP.3.8](#LCAP-3-8)

(NDLC-2-4)=
[NDLC.2.4] A dialect setting `call`, `publish`, `cache` and
`cache_delete` `false` — and with them every capability that depends
on `call` ([LCAP.3.8]) — is valid: it produces a read-only dialect, with
no writes and no calls. `cached(...)` reads still work, because reads are
not gateable ([NDLC.3.1]).

---

*see also:* [LCAP.3.8](#LCAP-3-8), [NDLC.3.1](#NDLC-3-1)

(NDLC-3)=
## The form catalog [NDLC.3]

(NDLC-3-1)=
[NDLC.3.1] The construct capabilities that gate a surface construct, and
when a tier sets each `false`:

| Capability | Language surface | Set `false` when |
|---|---|---|
| `call` | `call <domain>.<method> ...` | tier has no adapter or service connection, or can't absorb call latency |
| `publish` | `publish <Schema> ...` | tier is the topmost (has nowhere to publish to) |
| `cache` | `cache key: k value: v` | rules on this tier must not mutate cache state |
| `cache_delete` | `cache_delete key: k` | rules on this tier must not mutate cache state |
| `nocooldown` | the bare `nocooldown` flag on `call` ([LCRS.8.1]) | tier requires an explicit rate bound on every call |
| `series` | `series ...` declaration plus the aggregation surface ([LFCA.5.1]) | tier has no series subsystem — no backend is registered for the series atoms the artefact would carry |

The capabilities with engine consequences (`realtime`, `constspace`,
`linear_scan`, `logical`, `dynamic_ttl`, `regex`, `float`) are specified in
[LCAP.2]. The storage and samples-plane capabilities are deferred, and every
dialect sets them `false` ([LCAP.2.10]).

`cached(...)` is **not** a capability and is not gateable. The cache is
engine-owned — every engine has one, a read takes no integrator callback,
so there is no tier that lacks it ([LFCA.2.4]); only the two cache write
verbs above are gateable.

*see also:* [LCAP.2](#LCAP-2), [LCAP.2.10](#LCAP-2-10), [LCRS.8.1](#LCRS-8-1), [LFCA.2.4](#LFCA-2-4), [LFCA.5.1](#LFCA-5-1)

(NDLC-3-2)=
[NDLC.3.2] Everything no capability governs — `emit`, `log`, the full
expression grammar, pattern matching, schema declarations,
`within`/`dwell` — is **always available** and cannot be disabled by a
dialect ([LDIA.4.2]).

**Series declarations are not in that list.** A tier can lack a
registered series backend, so `series` and its two companions are
gateable and appear in [NDLC.3.1]; the catalog entry is [LFCA.5].
Gating them is what turns a missing backend into a compile error naming
the construct, instead of a `DS_ERR_BACKEND_NOT_REGISTERED` at artefact
load.


*see also:* [LDIA.4.2](#LDIA-4-2), [LFCA.5](#LFCA-5), [NDLC.3.1](#NDLC-3-1)

(NDLC-3-3)=
[NDLC.3.3] The hydration capabilities (`storage_hydrate_facts`,
`storage_hydrate_samples`) depend on `call` ([LCAP.3.8]). A
dialect with `call: false` must set both `false` as well:
nothing switches them off for it.

---

*Deferred: not binding in this edition.*

*see also:* [LCAP.3.8](#LCAP-3-8)

(NDLC-4)=
## Compiling with a dialect file [NDLC.4]

(NDLC-4-2)=
[NDLC.4.2] `-d` is repeatable, so one compile pass may register any number of
dialects. The grammar admits the repetition but cannot say which options repeat
and which are once-only, so it is stated here.

(NDLC-4-3)=
[NDLC.4.3] When a source file declares `use frame` and the `frame`
dialect was registered via `-d frame.yaml`, the compiler
validates the file against that dialect. An unrecognised
dialect name in a `use` directive is a compile error that
lists the registered dialects.

(NDLC-4-5)=
[NDLC.4.5] The compiled `.dsc` artefact records the program's resolved
settings and the capabilities it requires in its `CapabilityInfo` atom
([RDSC.16.2]), and the dialect's name, for information, in a
`DialectInfo` atom. The binding tuple carries the settings, not the name;
loading artefacts whose settings disagree fails with
`DS_ERR_BND_DIALECT_MISMATCH` (see [NRTM.6]
and [NERR.11]).

---

*see also:* [NERR.11](#NERR-11), [NRTM.6](#NRTM-6), [RDSC.16.2](#RDSC-16-2)

(NDLC-5)=
## Dialect gating diagnostic [NDLC.5]

(NDLC-5-3)=
[NDLC.5.3] Rejecting a construct the program's settings do not permit
([LDIA.3.4.2]) reports `DS_VALIDATE_CAPABILITY_DISABLED`. The diagnostic
names the construct, the capability and where its setting came from, the
source position, and a remedy ([LDIA.5]):

```
error[DS_VALIDATE_CAPABILITY_DISABLED]: 'publish' is not permitted: capability 'publish' is false (dialect 'site')
  at site_rules.ds:14:5
  suggestion: move the rule to a non-topmost tier.
```

The layout is carried here because the corpus has no notation for a compiler
message; when one exists this block moves to it.

*see also:* [LDIA.3.4.2](#LDIA-3-4-2), [LDIA.5](#LDIA-5)

(NDLC-6)=
## Registration errors [NDLC.6]

(NDLC-6-1)=
[NDLC.6.1] The compiler validates dialect YAML files at load time.
Errors surface before any source file is touched:

| Condition | Message prefix |
|---|---|
| A `settings` key naming no capability | `DS_VALIDATE_DIALECT_UNKNOWN_CAPABILITY` ([NDLC.2.2]) |
| A capability absent from `settings` | `DS_VALIDATE_DIALECT_INCOMPLETE` ([NDLC.2.2]) |
| The settings violate a fundamental constraint | `DS_VALIDATE_DIALECT_DEPENDENCY` ([LCAP.3.8]) |
| The settings set `realtime` or `constspace` `true` | `DS_VALIDATE_REALTIME_DEFERRED` ([LCAP.2.1.5]) |
| The settings set a storage or samples-plane capability `true` | `DS_VALIDATE_CAPABILITY_DEFERRED` ([LCAP.2.10]) |
| `name` missing, empty, or not a `NAME` token, so that no `use` directive could name it ([LGRA.3.1]) | `DS_VALIDATE_DIALECT_BAD_NAME` |
| Dialect name already registered | `DS_VALIDATE_DIALECT_DUPLICATE_NAME` |
| YAML syntax error | file path + `YAML parse error` |
| A top-level key other than `name` and `settings` ([NDLC.2.1]) | file path + the line and the key |
| `settings` absent, or not a mapping ([NDLC.2.2]) | file path + `settings must be a mapping` |

The last three are refusals of the file's shape, before any capability is
judged, and carry no `DS_VALIDATE_*` code.

*see also:* [LCAP.2.1.5](#LCAP-2-1-5), [LCAP.2.10](#LCAP-2-10), [LCAP.3.8](#LCAP-3-8), [LGRA.3.1](#LGRA-3-1), [NDLC.2.1](#NDLC-2-1), [NDLC.2.2](#NDLC-2-2)

(NDLC-6-2)=
[NDLC.6.2] Exit code 2 on registration error (same as other usage
errors per [RCLI.3.1]). The error message names the file.

---

*see also:* [RCLI.3.1](#RCLI-3-1)

(NDLC-8)=
## Testing a dialect [NDLC.8]

(NDLC-8-1)=
[NDLC.8.1] An integrator's dialect should be tested before it ships, in
three ways:

1. **Loading.** The definition loads without error ([NDLC.6.1]): every
   capability set, and the fundamental constraints satisfied.
2. **Compiling.** A program using each construct the dialect permits
   compiles; a program using each construct it forbids fails with
   `DS_VALIDATE_CAPABILITY_DISABLED` ([LDIA.3.4.2]).
3. **Running.** A program compiled under the dialect runs correctly on an
   engine configured for the tier, with every permitted construct
   exercised.

The conformance harness runs the first two for every dialect it is given;
the third is the tier implementor's, on the harness's mock-adapter and
event-trace infrastructure.

*see also:* [LDIA.3.4.2](#LDIA-3-4-2), [NDLC.6.1](#NDLC-6-1)

