gleamunison/patch

Named update-propagation patches (Unison’s patch entity, our shape).

A patch is a named, content-addressed set of replacements old-ref → new-ref. Applying it rewrites every definition that references a replaced ref and re-hashes the result: the “rewrite dependents” wave, as data. Iterating to a fixpoint is the cascade.

Types

pub type ApplyResult {
  ApplyResult(patch: Patch, rewritten: List(Rewrite))
}

Constructors

pub type Patch {
  Patch(
    name: String,
    replacements: List(
      #(identity.DefinitionRef, identity.DefinitionRef),
    ),
  )
}

Constructors

pub type Rewrite {
  Rewrite(
    old_ref: identity.DefinitionRef,
    new_ref: identity.DefinitionRef,
    new_def: ast.Definition,
  )
}

Constructors

Values

pub fn apply_to_defs(
  p: Patch,
  defs: List(#(identity.DefinitionRef, ast.Definition)),
) -> ApplyResult

One propagation wave: rewrite every definition that references a replaced ref, re-hash each result. Idempotent for untouched defs.

pub fn dependents(
  defs: List(#(identity.DefinitionRef, ast.Definition)),
  target: identity.DefinitionRef,
) -> List(identity.DefinitionRef)

Which of these definitions reference target?

pub fn hash_of(p: Patch) -> identity.Hash

The patch is itself content-addressed: same replacements, same hash.

pub fn lookup(
  p: Patch,
  ref: identity.DefinitionRef,
) -> Result(identity.DefinitionRef, Nil)
pub fn new(name: String) -> Patch
pub fn rewrite_definition(
  p: Patch,
  def: ast.Definition,
) -> ast.Definition
pub fn rewrite_term(p: Patch, term: ast.Term) -> ast.Term
✨ Search Document