StableHLOParse — the token skeleton of an SHlo term round-trips #
StableHLO.Basic states what each SHlo graph denotes: its *_faithful theorems equate den of a node or
graph with a named ℝ function (fwdGraph_faithful : den (fwdGraph W b x) = mnistLinear W b x, …).
This file is about the other side, the encoding the printer works from:
Raw— the skeleton of anSHlograph (opcodes, shapes, leaf SSA names; theℝoperand values and the shape index erased).skel : SHlo n → Raw— extract that skeleton.toToks : Raw → List Tok— the postorder token serializationprettyprints from (children before parent).parse : List Tok → Option Raw— a stack reconstructor.parse_toToks/roundtrip—parse (toToks (skel a)) = some (skel a), by structural induction.
Scope: the round trip is a statement about toToks, not about the text. Which operands each op's
emitted line reads, in what order, with what types, is decided by emitTok (in
StableHLO/Pretty.lean) and is trusted, together with the per-op lexical syntax, the per-op
StableHLO semantics, the lowering, and float32 ≈ ℝ.
Skeleton round trip. The postorder token encoding of the skeleton of any SHlo
term is invertible: parse (toToks (skel a)) = some (skel a). It is a statement about
toToks, not about the text: which operands each op's emitted line reads, in what order,
and with what types is decided by emitTok and remains trusted along with the lexical
syntax.