gleamunison/run_ref

Run a definition by content hash: the store is the program.

Resolve the dependency closure first, then load it, then execute. A ref whose module is already in the runtime as a genesis builtin needs no store entry, so a stored definition that adds two numbers does not have to carry the definition of +.

Types

pub type FunctionInfo {
  FunctionInfo(
    module: String,
    arity: Int,
    exports: List(#(String, Int)),
  )
}

Constructors

  • FunctionInfo(
      module: String,
      arity: Int,
      exports: List(#(String, Int)),
    )

Values

pub fn arity_of(typ: ast.Type) -> Int

A definition’s declared arity: parameters along the curried function chain. The surface language curries (define (f a b) ...) into nested one-arg lambdas, so fn a b -> ... types as Fn([Int], Fn([Int], Int)): arity is the sum along the chain, not the top-level parameter count. Anything that is not a function is a value, which takes no arguments.

pub const default_branch: String

The branch selected when a caller has no explicit release branch.

pub fn inspect_function_on_branch(
  adapter: storage.StorageAdapter,
  ref: identity.DefinitionRef,
  branch: String,
) -> Result(FunctionInfo, run_error.RunError)

What a stored function is, without calling it: the compiled module, the declared arity, and the export table it actually loaded with. The closure is loaded (dependencies first) because the export table only exists once the module is in the runtime — but '$eval' is never applied, so this is inspection, not execution.

pub fn run_verified_on_branch(
  adapter: storage.StorageAdapter,
  ref: identity.DefinitionRef,
  branch: String,
  args: List(dynamic.Dynamic),
  allow_unverified: Bool,
) -> Result(String, run_error.RunError)

The CLI-facing text form: run through the same authority, then render the resulting term the way the REPL does.

pub fn run_verified_raw_on_branch(
  adapter: storage.StorageAdapter,
  ref: identity.DefinitionRef,
  branch: String,
  args: List(dynamic.Dynamic),
  allow_unverified: Bool,
) -> Result(dynamic.Dynamic, run_error.RunError)

The execution authority: settle existence, check evidence, then execute.

A definition runs only when a verified Test record covers its content hash — the same turnstile publish passes, checked again at the moment of execution because a store can be filled by sync or pkg install long after admission. allow_unverified is the explicit escape hatch for local stores; the caller warns on stderr.

Existence is settled first: an absent definition is absent, not unverified, and a caller reading exit codes must be able to tell the two apart.

✨ Search Document