Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syntax.Identity

The identities a Prism source file carries, and the two of them a published artifact is enough to compute.

Source identity is the exact bytes, comments and formatting included: the digest the compiler embeds in every syntax artifact. Surface identity is the canonical semantic surface tree with every source position erased, so a comment or layout edit leaves it fixed while a change of syntactic form moves it. Core identity is the elaborated subject and is deliberately not computable here: it needs resolution and elaboration, which no syntax artifact carries.

The negative directions are the essential ones. Equal Core identity does not imply equal surface or source identity, since distinct spellings elaborate to one subject. Equal source bytes do not imply equal Core identity either, because the same text means different things under a different set of imported modules. Nothing here may be read as a claim about behavior.

Functions and Values

source_identity

source_identity : (Syntax.Source.SourceFile) -> String

The source identity of an artifact: the digest of its exact bytes.

source_identity(SourceFile { digest = "9f86d0", text = "fn main() = ()" })
9f86d0

surface_identity

surface_identity : (Syntax.Codec.SurfaceDoc) -> Result(String, Json.JsonError)

The surface identity of a decoded surface document: the canonical rendering of its schema tag and item tree with every span erased.

Two documents share a surface identity exactly when they are the same tree of the same schema, whatever text produced them. The identity is computed by re-encoding the document and stripping positions from the result, so it inherits the encoder’s canonical layout rather than introducing a second one; an encoding that cannot be read back is reported, never silently accepted.