gleamunison/identity

Types

A content-addressed reference to a definition.

pub type DefinitionRef {
  Ref(hash: Hash)
}

Constructors

Opaque hash type. No access to the inner bytes outside this module.

pub opaque type Hash

Local variable binding using de Bruijn indices.

pub type LocalVar {
  Local(index: Int)
}

Constructors

  • Local(index: Int)

Values

pub fn hash_bytes(contents: BitArray) -> Hash

Compute a SHA-256 hash from arbitrary bytes.

pub fn hash_equal(a: Hash, b: Hash) -> Bool

Compare two hashes for equality.

pub fn hash_from_bytes(contents: BitArray) -> Hash
pub fn hash_to_bytes(h: Hash) -> BitArray
pub fn hash_to_debug_string(h: Hash) -> String

Produce a hex string for display/debugging.

pub fn hash_to_hash_input(h: Hash) -> BitArray

The canonical byte input a hash contributes when another hash is derived over it (structural hashing in codebase). FROZEN: this is the hash’s 64-char lowercase hex text re-encoded as UTF-8 bytes, not the raw 32 digest bytes of hash_to_bytes. Every stored definition ref was derived over these bytes; switching to raw bytes would orphan all stored content. The derivation is documented here, with its owner, so no other module keeps a private copy of it.

pub fn hash_to_short_string(h: Hash) -> String

Produce a short hash prefix for display.

pub fn name_ref(name: String) -> DefinitionRef

The ref a name derives to: the SHA-256 of its UTF-8 bytes. Elaboration wires intra-batch references this way, so every layer that resolves a name to a ref must agree on these bytes - changing the derivation orphans every definition already stored under the old one.

This lives with the other hash authorities rather than in the REPL evaluator, where it grew first and which the read model, the index and the db layer were importing purely to hash a name.

pub fn parse_ref_hex(
  hex: String,
) -> Result(DefinitionRef, String)

Parse an external SHA-256 reference before it reaches storage or transport.

pub fn ref_hex(ref: DefinitionRef) -> String

The canonical external representation of a definition reference.

pub fn runtime_module_name(ref: DefinitionRef) -> String

Runtime module identity: “m_” plus the final eight hash digits.

pub fn short_hash_hex(hex: String) -> String

Shorten an already-rendered hash without reparsing display data.

pub fn short_ref_hex(ref: DefinitionRef) -> String

The canonical short display of a definition reference.

✨ Search Document