Skip to content

0.2 Graph-Based Optimal Reduction Engine and IR #11

Description

@Mathnerd314

Goal: Represent the program as a mathematical function over the P-code machine, serving as the concrete implementation of the semantic core of the Stroscot language interpreter. This defines the "specification" of behavior when combined with the P-code machine. All projections specialize/compile this semantics; they don’t replace it.

Implementation: Execute and transform programs represented as graphs with explicit sharing and duplication control (Lamping-style, linear logic). Supports sea-of-nodes, SSA, traced paths.

Inputs

  • Graph IR: nodes as combinators/primitives; edges for data/control; labels and boxes for sharing/duplication.
    • Flexible/extensible IR: combination of sea-of-node, SSA, traced paths, etc. - lived observation is "IR's don't have to be clean, they can be as messy as you want. they just have to express everything you want to express"
  • Reduction rules (beta-reduction, primitive operations, control constructs).
  • Parsed AST with lexical scopes and imports, poset-style declaration constraints.
  • Optional annotations for CPS/join points.

Processing

  • Maintain bidirectional, locally-nameless graph with named “chunks” for modularity.
  • Use label-based hash-consing to detect/share common subgraphs.
  • Apply linear-logic-style rules (boxes, contraction/weakening) to control duplication and garbage.
  • Support modes: “active” interpreter-style nodes vs. “frozen” compiled representation.
  • Optionally perform local normalization/cleanup (e.g., trivial join simplification, small CSE).

Outputs

  • Reduced graph (normal form or partially reduced with suspended redexes).
  • fully resolved IR with symbol IDs
  • diagnostics for unresolved names or incoherent poset constraints.
  • Metrics: sharing statistics, duplication counts, reduction logs (for profiling).

Key references

  • Optimal reduction & sharing (Lamping, etc.).
  • GHC supercombinators (Peyton Jones)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready for workUnblocked issue, ready for active coding

    Projects

    Status
    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions