Dsxir.Program.Source behaviour (dsxir v0.2.0)

Copy Markdown

Abstracts over a %Dsxir.Program{}'s structural origin.

Static use Dsxir.Module programs are wrapped via Dsxir.Program.Source.Module. Runtime, data-authored programs plug into the same behaviour. The dispatcher and optimizer talk only to this behaviour, never to the underlying struct.

Summary

Callbacks

Execute the program. Returning nil delegates to the host program's forward/2 (used by Source.Module); returning a tuple short-circuits with the produced prediction (used by Source.RuntimeProgram).

Stable identity tuple used for hashing, display, and persistence.

Enumerate predictor sites eligible for optimizer demo writes.

Return the normalized predictor declarations exposed by src.

Persist state for predictor name on the source. Stateless sources (such as Source.Module) intentionally return the source unchanged — this is not a stub.

Return the signature for predictor name on src.

Return the JSON-safe blob written into the v2 artifact source slot.

Functions

Dispatch execute/4 to the impl module backing src.

Dispatch identity/1 to the impl module backing src.

Dispatch optimizable_sites/1 to the impl module backing src.

Dispatch predictors/1 to the impl module backing src.

Dispatch put_predictor_state/3 to the impl module backing src.

Dispatch signature_for/2 to the impl module backing src.

Dispatch to_artifact_blob/1 to the impl module backing src.

Types

identity()

@type identity() :: {:module, module(), nil} | {:runtime, String.t(), <<_::256>>}

t()

@type t() :: struct()

Callbacks

execute(t, t, map, keyword)

@callback execute(t(), Dsxir.Program.t(), map(), keyword()) ::
  {Dsxir.Program.t(), Dsxir.Prediction.t()}
  | {Dsxir.Program.t(), {:partial, Dsxir.Prediction.t()}}
  | nil

Execute the program. Returning nil delegates to the host program's forward/2 (used by Source.Module); returning a tuple short-circuits with the produced prediction (used by Source.RuntimeProgram).

identity(t)

@callback identity(t()) :: identity()

Stable identity tuple used for hashing, display, and persistence.

optimizable_sites(t)

@callback optimizable_sites(t()) :: [Dsxir.Program.OptimizableSite.t()]

Enumerate predictor sites eligible for optimizer demo writes.

predictors(t)

@callback predictors(t()) :: [Dsxir.Program.PredictorDecl.t()]

Return the normalized predictor declarations exposed by src.

put_predictor_state(t, atom, t)

@callback put_predictor_state(t(), atom(), Dsxir.Program.State.t()) :: t()

Persist state for predictor name on the source. Stateless sources (such as Source.Module) intentionally return the source unchanged — this is not a stub.

signature_for(t, atom)

@callback signature_for(t(), atom()) :: module() | Dsxir.Signature.Compiled.t()

Return the signature for predictor name on src.

to_artifact_blob(t)

@callback to_artifact_blob(t()) :: term()

Return the JSON-safe blob written into the v2 artifact source slot.

Functions

execute(src, prog, inputs, opts \\ [])

@spec execute(t(), Dsxir.Program.t(), map(), keyword()) ::
  {Dsxir.Program.t(), Dsxir.Prediction.t()}
  | {Dsxir.Program.t(), {:partial, Dsxir.Prediction.t()}}
  | nil

Dispatch execute/4 to the impl module backing src.

identity(src)

@spec identity(t()) :: identity()

Dispatch identity/1 to the impl module backing src.

optimizable_sites(src)

@spec optimizable_sites(t()) :: [Dsxir.Program.OptimizableSite.t()]

Dispatch optimizable_sites/1 to the impl module backing src.

predictors(src)

@spec predictors(t()) :: [Dsxir.Program.PredictorDecl.t()]

Dispatch predictors/1 to the impl module backing src.

put_predictor_state(src, name, state)

@spec put_predictor_state(t(), atom(), Dsxir.Program.State.t()) :: t()

Dispatch put_predictor_state/3 to the impl module backing src.

signature_for(src, name)

@spec signature_for(t(), atom()) :: module() | Dsxir.Signature.Compiled.t()

Dispatch signature_for/2 to the impl module backing src.

to_artifact_blob(src)

@spec to_artifact_blob(t()) :: term()

Dispatch to_artifact_blob/1 to the impl module backing src.