ADR-0323:
First-Class Typed Holes (todo(...)) and
tenon holes Manifest
- Status: Accepted
- Date: 2026-11-28
- Plan: M30.2
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
Contextual
todo(...)Expression (ExprKind::Todo(Option<Box<String>>)):- Parse
todo()andtodo("reason")asExprKind::Todo(...)whenever the identifiertodois immediately followed by(. - Because
todois contextual, existing bindings namedtodo(e.g.let todo = 1) continue to parse asExprKind::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")).
- Parse
Typechecking & Hole Recording:
ExprKind::Tododiverges (Flow::exits()), so it unifies with any expected typeT(in return positions,letinitializers,if/matcharms, and call arguments) without triggeringE0306("function can reach its end").- During typechecking, every hole records a
TypedHoleinTypes.holescontaining itsexpr_id,span, enclosingfn_name, optionalmessage, resolvedexpected_type, and deterministic in-scope local(name, ty)bindings (BTreeMap-ordered).
Dual-Backend Runtime Parity:
- Core IR gains
StmtKind::Trap { kind: TrapReason, message: StrId, pos: Pos }. - Lowering emits
StmtKind::TrapwithTrapReason::Todoand message"todo: <reason>"(or"todo"). - Both the reference interpreter (
TrapKind::Todo, exit code101) and C backend (trt_trap("todo: ...", TN_FILE, line, col), exit code101) trap deterministically if a hole is executed at runtime.
- Core IR gains
Release Build Gate (
E1265) andtenon 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 releasetenon build) fail closed withE1265for every remaining typed hole. tenon holes [path] [--json]emits a deterministic manifest ("schema": "tenon-holes-1") sorted by(file, line, col, fn_name)containingid,file,line,col,fn_name,item_hash,message,expected_type, andin_scope([{name, ty}]).
- Development workflows (
Consequences
- Coding agents can scaffold full program skeletons, verify all
types with
tenon check, querytenon holes --jsonto pick the next hole with its exact expected type and in-scope locals, and rely onE1265to guarantee no hole ships in a release binary. size_of::<Expr>()stays strictly within its11 * size_of::<usize>()budget becauseOption<Box<String>>is one pointer word.