0014. Carry M2 types into the temporary C backend
- Status: Superseded by 0016
- Date: 2026-10-29
- Plan: M2.2, M3.1–M3.3, M5.3
- Review: Compiler and backend; Language semantics
Context
M2 adds four static types and value-producing if
before M3 replaces the AST-to-C path (ADR-0011). The emitter needs
expression types for hoisted temporaries and printing. String
views must preserve embedded NUL bytes.
Decision
Keep the AST plain. The checker returns function signatures and expression types/fallthrough keyed by source spans, consumed by the temporary emitter. Keep separate name-based scope stacks in resolution and types as planned.
Represent str as a pointer/byte-length pair
referencing static literal bytes, passed and returned by value.
Equality compares byte contents; there is no allocation or string
construction. i64, bool and unit retain
the bootstrap integer representation; unit is zero and is not
printable.
Lower if through hoisted temporaries, omitting
assignments on paths that return, break or continue. Its plain
else block uses an expression wrapper. Blocks supply
their final expression's value even with a trailing semicolon;
function bodies still require explicit non-unit returns. Loops
conservatively may finish for return-path analysis. Snapshot local
reads because branches can now assign before a later operand or
argument is evaluated. Source-loop labels preserve break/continue
targets when an inner while's condition contains an if-expression
controlling its enclosing loop.
Alternatives considered
- Build a typed AST or IR now — duplicates M3 work and widens this task.
- Reject non-direct string printing or use C strings — conflicts with retiring E0303 and loses embedded NUL bytes or valid typed string values.
- Rely on inline local reads — a later if-expression could mutate them, violating Harness's left-to-right evaluation order (ADR-0003).
Consequences
All four compile commands share one checked front end. The M1 program goldens keep their output. M3 replaces the span table and duplicated scope walks with IR IDs; M5 supplies constructed strings and their memory model.