Files
aji/docs/design/open-questions.md
T
dev 222c0c884c Fix two toolchain defects found by the M checkpoint
A. Interpreter memory grew with the number of executed steps (one arena,
never reclaimed): block and call arguments, frames, frame storage, value
copies, place paths, channel buffers and per-step scratch now live in a
collectable execution heap. Between instructions, past a threshold, the
live state is copied into a fresh heap (sharing preserved) and the old one
released. Long-lived state (module, world, authority, task, channel and
region tables, the result) stays in the caller's arena. The guarded value
of a mutex is a separate cell (no interior pointers). Nothing observable
changes: fuel, schedule, PRNG, values, traps and run records are the same.
- test: five loop shapes x 100k/1M/4M iterations, measured with the
  interpreter's own heap counters: live state after a collection does not
  grow with the iteration count; the heap stays under a fixed bound
- conformance --collect-every-step: the second run of every run test
  collects before every instruction; records must be byte-identical
  (passes, also with --stress 20)

B. A void function whose body ends in an if/if-else/match/block/void call
lowered to `ret %` (malformed AIR, reported as E0001): it now lowers to
`ret`. Seven fall-through tests (six failed before).

Also: files_opened counts reads by relative path and file name; P6A-11
(malformed generated AIR as an internal compiler diagnostic) and Q-023
(ref of a whole array as an argument) recorded.
2026-10-05 15:34:12 +03:00

163 lines
14 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Open Questions
Non-normative log of gaps and ambiguities in the draft spec. Each entry names the phase that is blocked until it is answered. Close an entry by changing the spec (or accepting an RFC) and recording the resolution here; do not delete entries.
Status values: `open`, `resolved`.
| ID | Status | Blocks | Question |
|---|---|---|---|
| Q-001 | resolved | P0 | Text AIR grammar |
| Q-002 | open | P0 | Instruction contract tables |
| Q-003 | resolved | P0 | Diagnostic codes for parse errors |
| Q-004 | resolved | P0 | Observable trap semantics |
| Q-005 | resolved | P0 | Verifier resource budget values |
| Q-006 | resolved | P0 | Target description for `usize` and layout in the interpreter |
| Q-007 | resolved | P0 | Integer edge cases besides overflow |
| Q-008 | resolved | P0 | How `hello` writes output before capabilities exist |
| Q-009 | resolved | P1 | Borrow lifetimes in AIR |
| Q-010 | resolved | P1 | Region generation checks: static, dynamic, or both |
| Q-011 | resolved | P2 | Effect hierarchy and discharge |
| Q-012 | resolved | P2 | Capability representation and host instantiation |
| Q-013 | resolved | P3 | Deterministic `select` rule and scheduler seed |
| Q-014 | resolved | P3 | `Send`/`Share` derivation for aggregates holding capabilities |
| Q-015 | open | P5 | Operational weak-memory model for the interpreter |
| Q-016 | open | P0 | Floating-point determinism |
| Q-017 | open | P5 | Replay file format |
| Q-018 | resolved | P2 | Runtime diagnostics (traps) vs verifier diagnostics |
| Q-019 | resolved | P3 | Non-terminating programs in test tooling |
| Q-020 | resolved | P2 | Size bound for SSA array values |
## Q-001 — Text AIR grammar
Spec 07 shows illustrative AIR but no grammar. Undecided: comment syntax; constant spelling (`const.u64 0`?); type suffix convention on opcodes (`add.checked.u64` vs typed operands); module header and version/feature-bit declaration (spec 00 §5 requires them); how types, structs and enums are declared; canonical whitespace for the serializer.
Proposed home: `docs/reference/air-text.ebnf` plus normative text in spec 07.
**Resolved (P0-1):** `docs/reference/air-text.ebnf` and spec 07 §8. Comments use `;`; opcodes carry the type suffix (`add.checked.u64`, `const.u64 5`); the module header is four lines (`module`, `air`, `lang`, `features`).
## Q-002 — Instruction contract tables
Spec 07 §4 and RFC 0004 require per-opcode contracts (operands, results, ownership/borrow transition, memory set, sync, effects, capabilities, traps, transfer function, interpreter behavior). None are written. Each phase must write the contracts for the opcodes it introduces before implementing them.
Proposed home: a normative `docs/spec/07-air.md` appendix or `docs/spec/air/` per instruction family.
**Partially resolved (P0-3):** format-version-0 instructions are specified in spec 07a. Stays open for the instructions of later phases.
## Q-003 — Diagnostic codes for parse errors
The registry has no codes for malformed AIR text. Options: a new `E0xxx` range for syntax, or `E50xx` under AIR/verifier.
**Resolved (P0-1):** new range `E0xxx` (E0001–E0006) for text and module errors. Undefined values and unknown block labels use the semantic codes `E5001` and `E5002`.
## Q-004 — Observable trap semantics
Spec 01 §6 defines a trap as termination "according to runtime policy". The interpreter needs: trap kinds (overflow, assert, bounds, explicit, …), how a trap is reported (exit status, structured record), and whether the trap location is observable.
**Resolved (P0-2):** spec 01 §6. Traps terminate the program and produce a record with a stable `T0xxx` code, function, block and instruction index.
## Q-005 — Verifier resource budget values
Spec 08 §7 says budgets are "configured/spec-defined". A user-configurable budget would let a flag change which programs are accepted, which conflicts with "no compiler flags that change language semantics". Proposal: fixed spec-defined budgets per profile, reported in `E5101`.
**Resolved (P0-2):** fixed, non-configurable limits in spec 08 §7.
## Q-006 — Target description in the interpreter
`usize`/`isize` match the target pointer width (spec 02 §1) and struct layout is implementation-defined (spec 02 §7). For determinism the interpreter must run against an explicit target description. Undecided: format, default, and whether it is part of the AIR module (spec 00 §5 "optional target requirements").
**Resolved (P0-2):** spec 09 §9. Target description with `pointer_bits`; the interpreter defaults to `air64`. `usize`/`isize` are never `widen` operands, so verification is target-independent.
## Q-007 — Integer edge cases besides overflow
Unspecified: division and remainder by zero; signed `MIN / -1`; shift amounts ≥ bit width; signed right shift; casts between widths and signedness (spec 01 §2 forbids implicit conversion but explicit cast semantics are absent).
**Resolved (P0-2):** spec 02 §2.1 and spec 07a.
## Q-008 — `hello` before capabilities
Phase 0's exit criterion runs AIR `hello`, but `io.stdout_write` needs `cap<io.write>` (Phase 2). Options: bring a minimal `io.write` capability and intrinsic into Phase 0, or define Phase 0 `hello` as a function whose return value the test harness checks.
**Resolved (P0-2):** Phase 0 `hello` is a `@main` that returns a value which `aji run` reports (spec 07a "Run result"). A `hello` that writes to stdout moves to P2-11, after slices (P1) and capabilities (P2).
## Q-009 — Borrow lifetimes in AIR
Spec 03 §4 shows `'a` lifetimes in source; AIR has `borrow.ref`/`borrow.end` but no notation for lifetime relationships across function signatures. Undecided: explicit lifetime parameters in AIR signatures vs scope-based borrows only.
**Resolved (RFC 0005):** second-class borrows; returns use `from %param`; explicit `borrow.end` with path linearity (spec 07 §8.8, spec 08 §11).
## Q-010 — Region generation checks
Spec 03 §8.1 allows removing generation checks "when statically proven unnecessary", implying a dynamic check otherwise; `E2104` implies static rejection. Undecided: which cases are static errors, which compile to runtime checks, and what the runtime failure is.
**Resolved (owner decision, RFC 0005):** static checks only; no runtime generation checks in safe code (spec 03 §8.1). Specified in detail with `regions` in Phase 2.
## Q-011 — Effect hierarchy and discharge
Spec 05 §2 lists effects such as `atomic` and `atomic.weak`, `io.write` and `fs.write`. Undecided: whether effects form a hierarchy (does `atomic` cover `atomic.weak`?), and what a "verifier-recognized boundary" that discharges an effect is.
**Resolved (RFC 0006):** effects are flat atoms from a closed registry; no implication and no discharge in format 0; function pointer types must carry effect sets (spec 05 §9).
## Q-012 — Capability representation and host instantiation
Binary AIR has a `CAPABILITY_TABLE` (spec 07 §6). Undecided: how capabilities appear in text AIR, how an entry point declares the capabilities it needs, how the host/interpreter grants them, and how narrowing (spec 05 §4) is expressed.
**Resolved (RFC 0006):** `cap<K>` is an opaque, copyable reference to a shared host authority object; it enters only as a named `@main` parameter bound by `--grant name=kind[:scope]`; `cap.narrow` is the only, fallible, transformation; failed instantiation is `not_instantiated` (exit 6) (spec 05 §10).
## Q-013 — Deterministic `select` and scheduler seed
Spec 04 §14 and spec 11 §6 require a stable rule in deterministic mode but do not define it. Also undecided: scheduler seed format and which choice points are recorded.
**Resolved (RFC 0012, spec 04 §39):** ready arms chosen by a draw from the schedule generator (not textual order); task choices and arm choices share one stream and one `choices` count. The schedule seed was settled by RFC 0011.
## Q-014 — `Send`/`Share` for aggregates holding capabilities
Spec 02 §6 derives properties structurally; spec 05 §5 says capability types define their own transfer rules. Undecided: the derivation for a struct mixing ordinary fields with `Local` or move-only capabilities.
**Resolved (RFC 0011):** `Send`/`Share` are structural; every capability kind is `Send` and `Share`, so an aggregate holding capabilities is `Send`/`Share` exactly when its other members are (spec 04 §35).
## Q-015 — Operational weak-memory model
The SB litmus test requires the interpreter not to forbid `r1=0, r2=0` under relaxed ordering. Undecided: which executable model to use (store buffers, a promising-style semantics, or an axiomatic checker over recorded executions) and how much of C11's model to adopt.
## Q-016 — Floating-point determinism
`f32`/`f64` exist (spec 02 §1) with no rules on NaN payloads, fused operations, rounding mode or denormals. Deterministic replay requires these to be fixed.
## Q-017 — Replay file format
Spec 11 §4 mentions `.ajr` files without a format or compatibility rule.
## Q-018 — Runtime diagnostics
The error registry covers verifier/compiler errors. Traps and runtime check failures (bounds, generation, overflow) need stable machine-readable records too, either in the same registry (e.g. `R` codes) or a separate one.
**Resolved (P0-2):** traps share the registry in a separate `T0xxx` range (`docs/reference/error-codes.md`).
## Q-019 — Non-terminating programs in test tooling
A program may legitimately loop forever, so the language cannot bound execution. The conformance runner and `ajid` still need a way to stop a run without making the outcome depend on wall-clock time. Options: a deterministic step budget that is a tooling parameter (reported as "budget exhausted", never as a language trap), or explicit `fuel:` in test headers. Must be decided before scheduler stress tests (P3), which multiply run counts.
**Resolved:** deterministic instruction fuel (spec 11 §7). Wall-clock time is never used to determine semantic test termination. Fuel exhaustion is an execution-runner outcome (`limit_exceeded`, CLI exit code 5), not an Aji trap.
## Q-020 — Size bound for SSA array values
Frame storage is bounded (`max_local_frame`, spec 08 §11.5), but an SSA value of type `array<T, N>` (for example from `array.splat`) is bounded only by `N ≤ 2^32`. A module can therefore ask the interpreter for gigabytes in one instruction, and the outcome then depends on host memory. Options: apply the same accounted-size limit to every type in the module (E5101), or a separate `max_value_bytes`. Needs an owner decision; changing it later would turn accepted modules into rejected ones, so it should be settled before format 0 is released.
**Resolved (owner decision, DD-015):** `max_value_size` = 1 048 576 bytes bounds the accounted size of every materializable type in a module (spec 08 §7.1); `max_local_frame` stays a separate limit. Both are normative, deterministic, independent of host memory and reported as `E5101`. Accounted sizes use checked arithmetic; overflow is `E5101`. Total allocation is a Phase 2 concern (allocation capabilities and runtime limits).
## Q-021 — `@main` parameter names that are `.aji` keywords
Parameter names are preserved by lowering and are the binding points for grants (spec 15 §2). An AIR program whose `@main` has a parameter named after a `.aji` keyword (`%in` in `tests/conformance/phase2/run/echo_stdin.air`) has no source equivalent with the same instantiation contract, so a grant `in=io.read` cannot target a `.aji` program. Options: accept the restriction (keywords are not parameter names; AIR programs meant to have a source twin avoid them), or a raw-identifier spelling for this position. Not urgent; noted when the source/AIR equivalence test for `echo_stdin` had to drop its `equivalent:` reference.
**Resolved (owner decision):** no language change. For runtime grants the source parameter name is what matters, not identity with a hand-written AIR program: the source program names the parameter `input` and is run with `--grant input=…`, and that AIR test simply has no `equivalent:` twin. Escaped identifiers (`` `in` ``) are deferred until there is a real need, because they grow the grammar for a rare case.
## Q-022 — Byte strings dominate the source/AIR size metric
A byte string lowers to one `local.zero`, then a borrow, index, store and end per non-zero byte, because format 0 has no byte-array constant. In the Layer 6 programs this makes up most of the AIR (`hello`: `mechanical_air_eliminated` 0.94). The metric then measures a representation cost of format 0 more than the mechanics an agent would otherwise write. Options for P6A-9: report the metric both with and without byte-string materialization, or count each byte string as one AIR construct. A byte-array constant in AIR would be a format change (spec 07 §8.7) and is out of scope for 6A.
**Resolved (owner decision):** report both. `mechanical_air_eliminated_raw` counts all AIR actually generated and stays the main engineering metric. `mechanical_air_eliminated_normalized` counts each byte-string materialization as one logical constant operation, under one fixed rule for every program (spec 15 §11).
## Q-023 — `ref` of a whole array passed to a `ref<[T; N]>` parameter
In `.aji` a borrow of a whole array written as an argument (`f(ref a)`, `a: [u64; 4]`) is always lowered as a slice (`slice<u64>`), so a function declared with a parameter `ref<[u64; 4]>` cannot be called with `ref a` (`E7005`). Spec 15 §5 says that binding a borrow of a whole array (`ref r = a;`) gives a slice. It does not say what an argument borrow gives, so the frontend's choice is not specified. Options: the argument borrow follows the parameter type (array borrow for `ref<[T; N]>`, slice for `slice<T>`), which is a small amount of inference from a known signature; or keep slices only and state it in spec 15. Found while writing the interpreter memory test; not urgent.