2.5 KiB
2.5 KiB
AST Contract and Root Model Decision
Status: Accepted
Date: 2026-03-05
Related Agenda: docs/pbs/agendas/archive/11.1. AST Workshop 1 - AST Contract and Root Model.md
Context
PBS introduced 11. AST Specification.md as the language-specific AST layer between parser output and frontend lowering to IRBackend.
The open question was whether AST should be standardized by one mandatory implementation model (for example one Java class hierarchy) or by observable contract obligations.
Decision
PBS adopts an obligations-first AST contract.
The specification standardizes required observable AST behavior and invariants, not one mandatory in-memory representation.
The following are required:
- one AST root per source file;
- deterministic child ordering consistent with source order;
- mandatory source attribution (
file,start,end) on nodes consumed by diagnostics or lowering; - explicit declaration/statement/expression node families for the supported v1 source slice;
- deterministic rejection for unsupported forms, without permissive synthetic AST that hides rejection.
Invariants
- AST conformance is implementation-language agnostic.
- Missing required attribution on mandatory nodes is non-conformant.
- Parser recovery may produce partial AST, but structural integrity must remain valid for continued diagnostics.
- Lowering and diagnostics are allowed to depend on the required AST invariants above.
Explicit Non-Decisions
- This decision does not freeze one parser architecture.
- This decision does not define full static-semantics rules.
- This decision does not define
IRBackend -> IRVMlowering. - This decision does not define runtime/bytecode/verifier policies.
Spec Impact
docs/pbs/specs/11. AST Specification.mdmust encode the obligations-first contract and invariants.docs/pbs/specs/12. Diagnostics Specification.mdremains the authority for diagnostic identity/phase/attribution payload rules consumed by AST-facing diagnostics.docs/pbs/specs/13. Lowering IRBackend Specification.mdmay assume the mandatory AST invariants as lowering preconditions.
Validation Notes
At minimum, Gate U evidence (per docs/general/specs/13. Conformance Test Specification.md) should include:
- valid AST shape fixtures for representative declarations/statements/expressions;
- deterministic syntax rejection fixtures with stable diagnostics;
- attribution checks (
file/start/end) on nodes required by diagnostics and lowering.