ToolCall.TypeCompiler (ToolCall v0.4.0)

Copy Markdown

Compiles a declaration's ToolCall.TypeExpr values into ToolCall.IR.Type.

The compiler owns local-type expansion, recursive $defs hoisting, provider mapping, and result-type handling; the declaration source has already resolved aliases, current-module references, and when bindings. The builder remains responsible for docs, defaults, parameter names, and overrides.

Summary

Types

context()

@type context() :: map()

prepared()

@type prepared() :: %{context: context(), definitions: map(), cyclic: MapSet.t()}

t()

@type t() :: %{
  context: context(),
  definitions: map(),
  cyclic: MapSet.t(),
  defs: map()
}

Functions

compile_param(state, type_expr)

@spec compile_param(t(), ToolCall.TypeExpr.t()) ::
  {ToolCall.IR.Type.t(), boolean(), t()}

compile_result(state, return_expr)

@spec compile_result(t(), ToolCall.TypeExpr.t()) ::
  {ToolCall.IR.Type.t() | nil, boolean(), t()}

defs(map)

@spec defs(t()) :: map()

new(prepared)

@spec new(prepared()) :: t()

prepare(context)

@spec prepare(context()) :: prepared()

Converts the module's local type definitions once.

The result is shared by every tool in the module; new/1 only resets the per-tool $defs budget.