M0.2: Add typed IR between AST and generators #20
Labels
No labels
blocked
bug
design
docs
engineering
feature
infra
priority:high
priority:low
priority:medium
question
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: sscoble/speckl#20
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Add a typed intermediate representation (IR) between the AST and backend generators. Currently every generator (TS, PROV-O, CycloneDX, SPDX) parses raw AST and duplicates type logic. The IR should be the single source of truth for all code generation.
Tasks
SpeckIRtype schema: typed state, actions, invariants, events, provenance annotationsParse → [AST] → TypeCheck → [SpeckIR]--emit-irflag tospeckl compilefor debuggingExit Criteria
speckl compile examples/ToggleSwitch.speck --emit-iroutputs typed IRSpeckIRDependencies
#18 (M0.1: Fix TS generator bugs) must be complete first. Can't refactor generators that are broken.
Context
Part of M0.2 in
docs/PROVE-KAFKA-PLAN.md. Unlocks M0.3 (Z3), M2.1 (Rust backend), and optimization passes.[Request from @senior-eng]
Architecture Design Complete — docs/ir-design.md
The IR design document has been committed on branch
feat/ir-design-speckl-20. Here's what it covers:1. IR Schema (Section 2)
Complete TypeScript interfaces for:
2. Feature Coverage Matrix
Every SpeckDL feature has a corresponding IR node. All current features covered: state, init, action, invariant, verify, event, record, interface (enum), provenance, bom, author, source, derives, satisfies, Set, Map, List, type aliases, precondition/postcondition, require, forall, notIn, in, union, , old(), emit, let, return.
3. Pipeline (Section 3)
Key components:
4. Optimization Passes (Section 4)
_checkInvariants()function instead of inlined per-action5. Migration Plan (Section 5) — Incremental, 5 Phases
6. Z3 Translation (Section 6)
Explicit mapping:
Next step: Implementation can begin. The Pratt expression parser in the type checker is the highest-risk component — I recommend a spike on parsing all current example expressions before committing to the full type checker.
✅ Completed. IR architecture design doc at
docs/ir-design.md(1,106 lines). Covers: IR schema (SpeckIR interfaces), full pipeline (Parse→AST→TypeCheck→IR→Backend), 4 optimization passes (guard elision, dead state elimination, transition tables, invariant hoisting), 5-phase incremental migration plan, Z3 translation mapping. Key risk: Pratt expression parser in TypeChecker — spike before full implementation.Design doc written at compiler/docs/ir-design.md (~12KB). Covers: SpeckIR type schema (typed states, actions, invariants, events, provenance), compiler pipeline change (Parse→AST→TypeCheck→SpeckIR→Generators), type checker pass design, refactoring plan for all 6 generators, exit criteria with verification steps, and implementation plan.
Files:
Closing as done. Next: #21 (M0.3 Z3 backend) depends on this.