On this page

ADR-0323: First-Class Typed Holes (todo(...)) and tenon holes Manifest

Context

When coding agents or developers build non-trivial Tenon programs top-down, they need to scaffold function signatures, types, and control flow before implementing every branch. Previously, writing a placeholder required fabricating a dummy value of the exact expected type ("", 0, ok(unit), struct literals), which pollutes typechecking, hides unfinished work, and forces agents to re-read whole files to track remaining stubs.

Decision

  1. Contextual todo(...) Expression (ExprKind::Todo(Option<Box<String>>)):

    • Parse todo() and todo("reason") as ExprKind::Todo(...) whenever the identifier todo is immediately followed by (.
    • Because todo is contextual, existing bindings named todo (e.g. let todo = 1) continue to parse as ExprKind::Name.
    • Support full round-trip representation in canonical forms ((todo) / (todo "reason")), compact encoding (D~ / D+<len>:<msg>), compact decoding, and ordinary expansion (todo() / todo("reason")).
  2. Typechecking & Hole Recording:

    • ExprKind::Todo diverges (Flow::exits()), so it unifies with any expected type T (in return positions, let initializers, if/match arms, and call arguments) without triggering E0306 ("function can reach its end").
    • During typechecking, every hole records a TypedHole in Types.holes containing its expr_id, span, enclosing fn_name, optional message, resolved expected_type, and deterministic in-scope local (name, ty) bindings (BTreeMap-ordered).
  3. Dual-Backend Runtime Parity:

    • Core IR gains StmtKind::Trap { kind: TrapReason, message: StrId, pos: Pos }.
    • Lowering emits StmtKind::Trap with TrapReason::Todo and message "todo: <reason>" (or "todo").
    • Both the reference interpreter (TrapKind::Todo, exit code 101) and C backend (trt_trap("todo: ...", TN_FILE, line, col), exit code 101) trap deterministically if a hole is executed at runtime.
  4. Release Build Gate (E1265) and tenon holes [path] [--json]:

    • Development workflows (tenon check, tenon build --dev, tenon run, tenon interp, tenon test) permit typed holes so incomplete programs can be typechecked and partially executed.
    • Release builds (tenon build --release / default release tenon build) fail closed with E1265 for every remaining typed hole.
    • tenon holes [path] [--json] emits a deterministic manifest ("schema": "tenon-holes-1") sorted by (file, line, col, fn_name) containing id, file, line, col, fn_name, item_hash, message, expected_type, and in_scope ([{name, ty}]).

Consequences