Program Semantic Graph (PSG)
- Program Semantic Graph (PSG) is a unified, typed, and annotated semantic representation built after parsing and typechecking, capturing crucial computational properties.
- It integrates dimensional type inference, deterministic memory management, and escape analysis to drive representation selection and downstream compilation decisions.
- The PSG preserves rich metadata that guides multi-stage lowering, ensuring semantic preservation and efficient code generation across targets.
The Program Semantic Graph (PSG) is the central semantic representation in the Fidelity compilation framework: a typed, annotated graph built after parsing and typechecking, but before MLIR lowering, in which compilation-relevant properties are attached to program computations rather than erased as front-end artifacts. In the Fidelity/Clef pipeline, Clef source passes through the Composer frontend to the PSG, then to the Program Hypergraph (PHG), MLIR, and finally backends such as LLVM, CIRCT, and MLIR-AIE. Within this role, the PSG unifies Dimensional Type System (DTS) information, Deterministic Memory Management (DMM), escape analysis, representation selection, and target reachability as properties of a single graph (Haynes, 17 Mar 2026, Haynes, 18 Mar 2026).
1. Definition and compiler placement
The PSG is the compiler’s unified semantic representation of a program after type and dimensional inference. It is not MLIR itself, and it is not a plain control-flow graph. Rather, it is a semantic graph overlay over what will eventually become a control-flow or SSA IR, with rich metadata attached to nodes and edges. In the Fidelity presentation, the pipeline is explicitly layered as typed AST to PSG to MLIR to target dialects and machine code; in the Clef/Composer presentation, the PSG is the first rich semantic IR, preceding the PHG generalization (Haynes, 17 Mar 2026, Haynes, 18 Mar 2026).
This placement determines its function. Dimensional annotations persist through multi-stage MLIR lowering as compilation metadata, and the same graph also carries coeffects for allocation strategy, lifetime, target capability, and representation choice. MLIR emission is downstream of these decisions: the enriched PSG is traversed via a zipper, and code generation observes annotations already computed during PSG elaboration and saturation rather than recomputing them during lowering (Haynes, 17 Mar 2026).
A defining feature of the PSG is that numeric representation selection and deterministic memory management are treated as coeffect properties of one semantic object. The abstract formulation in the Fidelity work states the dependency chain directly: dimensional inference determines value ranges; value ranges determine representation selection; representation selection determines word width and memory footprint; and memory footprint, combined with escape classification, determines allocation strategy and cross-target transfer fidelity (Haynes, 17 Mar 2026).
2. Graph structure, annotations, and saturation
In its original form, the PSG is a directed graph
where vertices are computation or value nodes and edges are binary relations representing dependencies. At a high level, nodes are typed, dimension-annotated, and coeffect-annotated computation values, while edges are binary dependencies carrying semantic tags relevant to compilation (Haynes, 18 Mar 2026).
Each vertex carries a type annotation , a dimension vector , a coeffect annotation , and activation or lifecycle information. The Clef/PHG account formulates elaboration with the activation lattice
while the Fidelity account also describes a persistent three-state node view of Live, Latent, and Fresh. Live nodes are elaborated, saturated, and active; Latent nodes are elaborated and saturated but inactive; Fresh nodes are parsed but not elaborated (Haynes, 17 Mar 2026, Haynes, 18 Mar 2026).
Edges are likewise annotated. The papers describe dependency kind, control-like dependency, coeffect dependency, reachability bitvectors over configured targets, and additional compilation-relevant properties such as escape or aliasing and memory lifetimes as edge attributes. The result is a binary semantic graph whose edge set carries substantially more than raw dataflow (Haynes, 18 Mar 2026).
The PSG is not merely a static graph. It is elaborated by repeatedly applying inference rules until a fixpoint is reached. Types, dimensions, coeffects, and lifetimes propagate along edges; saturation terminates because the graph is finite and the activation relation is monotone. This saturation process resolves DTS constraints, resolves memory and escape constraints, and annotates nodes and edges with enough information for lowering and representation selection (Haynes, 18 Mar 2026).
3. DTS and DMM as graph semantics
The PSG is the point at which the Dimensional Type System and Deterministic Memory Management become concrete in the IR. DTS treats physical dimensions as elements of a finitely generated abelian group, essentially with componentwise addition. A value has
with multiplication corresponding to addition of exponents and division corresponding to subtraction. In the PSG, nodes carry dimensional vectors , and operations induce constraints over these vectors (Haynes, 17 Mar 2026, Haynes, 18 Mar 2026).
Typical constraints are attached directly to graph structure. For multiplication,
0
and for addition,
1
These constraints are gathered from edges and solved as linear constraints over 2, using linear algebra or SMT over QF_LIA; inconsistency produces a design-time error (Haynes, 18 Mar 2026).
DMM is formalized as a coeffect discipline on the same graph. Nodes carry coeffects describing resource needs such as arena scope, stack eligibility, and aliasing constraints. Edges encode dataflow and lifetime dependencies, enabling escape checking, stack-versus-arena or heap decisions, and prediction of total memory usage per function or actor. The Fidelity formulation classifies value lifetimes into four escape categories and maps them to verified allocation strategies (Haynes, 17 Mar 2026, Haynes, 18 Mar 2026).
| EscapeKind | Allocation strategy | Lifetime bound |
|---|---|---|
| StackScoped | Stack (memref.alloca) |
Lexical scope |
| ClosureCapture(3) | Arena (closure environment) | Lifetime of closure 4 |
| ReturnEscape | Arena (caller scope) | Caller scope |
| ByRefEscape | Arena (param origin scope) | Origin of ref |
The lifetime lattice is ordered as
5
with promotion defined by the maximum lifetime required by uses. This gives the PSG a dual role: it is simultaneously the site of dimensional inference and of lifetime or placement inference, rather than a representation in which these concerns are split across unrelated analyses (Haynes, 17 Mar 2026).
4. Derived compilation decisions and design-time views
Because DTS and DMM inhabit the same graph, the PSG supports a chained derivation of downstream compilation decisions. The papers describe the sequence explicitly: dimensional inference yields value ranges; value ranges drive representation selection; representation choice fixes word width and memory footprint; and footprint, combined with escape classification, determines allocation strategy, cache behavior, and transfer fidelity (Haynes, 17 Mar 2026).
Representation selection is formulated per target as
6
where 7 is the set of supported numeric representations. The selected representation, dynamic range, error properties, and resulting footprint are attached to PSG nodes as annotations consumed later by MLIR emission (Haynes, 17 Mar 2026).
This organization underlies the papers’ notion of design-time semantic preservation. The PSG is preserved as the long-lived semantic object in the compiler and language server, so dimensional resolutions, escape diagnostics, allocation strategies, cache locality estimates, cross-target representation choices, and transfer fidelity can be shown directly as views over the compilation graph. The Clef/PHG paper further states that, as code is written, the PSG is built, the PHG is derived, constraints are solved, and violations appear as editor diagnostics via a continuously running compiler exposed as the language server Lattice (Haynes, 17 Mar 2026, Haynes, 18 Mar 2026).
The same mechanism extends to auto-differentiation in the Fidelity account. The dimensional algebra is stated to be closed under the chain rule, forward-mode gradient computation has a coeffect signature of no activation tape and 8 auxiliary memory per layer, and quire accumulation can be represented as another coeffected resource in the graph (Haynes, 17 Mar 2026).
5. Adequacy and structural limits of the binary PSG
The original PSG is described as adequate for scalar and tensor computations. Its binary edge model is sufficient when operations can be understood as relations among operands and results pairwise, and this is precisely the setting in which DTS and DMM were first developed (Haynes, 18 Mar 2026).
The same papers also identify the point at which this adequacy fails. Two classes of problems are structurally ill-served by strictly binary edges: tile co-location and routing constraints in spatial dataflow architectures, and geometric algebra computations involving graded multi-way relations. A tile placement constraint is not a constraint between two nodes but over a set of nodes that must reside on the same tile or within the same column. Likewise, operations such as the join of three points to form a plane or the intersection of multiple planes are semantically indivisible multi-input relations (Haynes, 18 Mar 2026).
The geometric-algebra example is especially sharp. In projective geometric algebra, a face may be expressed as
9
A binary PSG forces this into a sequence such as 0 followed by 1, thereby creating an intermediate line 2 that may have no independent geometric role in the algorithm. The PHG paper characterizes such nodes as artifacts of the binary IR rather than of the domain, and also notes their possible contribution to extra floating-point error (Haynes, 18 Mar 2026).
This limitation is structural rather than incidental. The PHG is introduced precisely as the minimal generalization of the PSG that promotes binary edges to hyperedges of arbitrary arity while preserving the rest of the annotation scheme. In that sense, the PSG remains foundational: understanding its binary model is presented as the prerequisite for understanding why hyperedges are needed (Haynes, 18 Mar 2026).
6. Generalization, related graph formalisms, and acronym scope
The Program Hypergraph is defined as a strict superset of the PSG: every valid PSG is a valid PHG in which all source sets have cardinality 3, and no existing PSG property is lost. This makes the PSG the original binary semantic IR of the Fidelity framework, and the PHG its principled extension for multi-way geometric, topological, and spatial constraints (Haynes, 18 Mar 2026).
A plausible implication is that the PSG belongs to a broader family of semantically enriched program graphs, but with a distinct emphasis on coeffect integration. Program dependence graphs have been given operational semantics and determinism criteria in the context of CFG equivalence (Ito, 2018). Hierarchical abstract syntax graphs treat programs as graph structures on which execution is defined by graph rewriting (Ghica, 2021). ProGraML uses a directed attributed multigraph over IR instructions, values, and calls for graph-based learning of classical analyses (Cummins et al., 2020). The Fidelity PSG differs in making dimensional typing, representation selection, escape analysis, allocation strategy, and target reachability cohabit one persistent semantic object (Haynes, 17 Mar 2026).
The acronym PSG is also overloaded in the arXiv literature. In "Path-aware Siamese Graph neural network for link prediction," PSG denotes a link-prediction architecture and not a program-analysis representation (Lv et al., 2022). In "Software Language Comprehension using a Program-Derived Semantics Graph," PSG refers to a multi-tiered semantics graph for software comprehension rather than the Fidelity semantic IR (Iyer et al., 2020). Within the Fidelity and Clef papers, however, Program Semantic Graph has a specific compiler-theoretic meaning: a binary, typed, annotated semantic graph that makes dimensions and memory first-class in compilation and serves as the semantic substrate from which later hypergraph-based compilation is derived (Haynes, 17 Mar 2026, Haynes, 18 Mar 2026).