ExDatalog.Capabilities (ExDatalog v0.2.0)

Copy Markdown View Source

Capability metadata for storage backends and constraint sets.

Capabilities enable engines and tooling to reason about what a given configuration supports — portable constraints, indexed lookup, provenance, etc. — without runtime introspection of implementation details.

Fields

FieldDefaultDescription
storage_type:mapStorage backend type (:map, :ets, :external)
indexed_lookupfalseSupports indexed (hash) lookups
concurrent_readsfalseSafe for concurrent read access
arithmetic_constraintstrueSupports arithmetic constraints
comparison_constraintstrueSupports comparison constraints
type_predicatestrueSupports type-check predicates
string_predicatestrueSupports string predicates
provenancetrueSupports derivation provenance
external_executionfalseReserved for Z3, Soufflé, etc.

Merging

merge/2 combines two capability structs using AND semantics: a field is true only if both inputs are true. The storage_type field takes the left operand's value.

iex> cap1 = %ExDatalog.Capabilities{indexed_lookup: true, concurrent_reads: false}
iex> cap2 = %ExDatalog.Capabilities{indexed_lookup: false, concurrent_reads: true}
iex> merged = ExDatalog.Capabilities.merge(cap1, cap2)
iex> merged.indexed_lookup
false
iex> merged.concurrent_reads
false
iex> merged.arithmetic_constraints
true

Satisfying requirements

satisfies?/2 checks whether a capability struct meets a set of requirements. A requirement is a keyword list of boolean fields that must all be true in the capability struct.

iex> caps = %ExDatalog.Capabilities{arithmetic_constraints: true, indexed_lookup: true}
iex> ExDatalog.Capabilities.satisfies?(caps, arithmetic_constraints: true, indexed_lookup: true)
true
iex> ExDatalog.Capabilities.satisfies?(caps, arithmetic_constraints: true, concurrent_reads: true)
false

Summary

Functions

Returns the default capabilities struct.

Queries a backend's capabilities by calling its capabilities/1 callback.

Merges two capability structs using AND semantics.

Checks whether a capability struct satisfies a set of requirements.

Types

storage_type()

@type storage_type() :: :map | :ets | :external

t()

@type t() :: %ExDatalog.Capabilities{
  arithmetic_constraints: boolean(),
  comparison_constraints: boolean(),
  concurrent_reads: boolean(),
  external_execution: boolean(),
  indexed_lookup: boolean(),
  provenance: boolean(),
  storage_type: storage_type(),
  string_predicates: boolean(),
  type_predicates: boolean()
}

Functions

default()

Returns the default capabilities struct.

Represents the baseline capability set for the Map backend: arithmetic, comparison, type-check, and string predicates, provenance, but no indexed lookup, concurrent reads, or external execution.

Examples

iex> cap = ExDatalog.Capabilities.default()
iex> cap.arithmetic_constraints
true
iex> cap.indexed_lookup
false

from_backend(arg)

@spec from_backend({atom(), term()}) :: t()

Queries a backend's capabilities by calling its capabilities/1 callback.

Returns the capabilities reported by the storage backend for the given state.

Examples

iex> state = ExDatalog.Storage.Map.init(%{"rel" => %{arity: 2, types: [:integer, :string]}})
iex> caps = ExDatalog.Capabilities.from_backend({ExDatalog.Storage.Map, state})
iex> caps.storage_type
:map
iex> caps.arithmetic_constraints
true

merge(left, right)

@spec merge(t(), t()) :: t()

Merges two capability structs using AND semantics.

For each boolean field, the result is true only if both inputs are true. The storage_type field takes the left operand's value.

Examples

iex> cap1 = %ExDatalog.Capabilities{indexed_lookup: true, concurrent_reads: false}
iex> cap2 = %ExDatalog.Capabilities{indexed_lookup: false, concurrent_reads: true}
iex> merged = ExDatalog.Capabilities.merge(cap1, cap2)
iex> merged.indexed_lookup
false
iex> merged.concurrent_reads
false
iex> merged.arithmetic_constraints
true

satisfies?(caps, requirements)

@spec satisfies?(
  t(),
  keyword()
) :: boolean()

Checks whether a capability struct satisfies a set of requirements.

requirements is a keyword list of boolean fields that must all be true in the capability struct. Returns true if every requirement is met, false otherwise.

Examples

iex> caps = %ExDatalog.Capabilities{arithmetic_constraints: true, indexed_lookup: true}
iex> ExDatalog.Capabilities.satisfies?(caps, arithmetic_constraints: true, indexed_lookup: true)
true
iex> ExDatalog.Capabilities.satisfies?(caps, arithmetic_constraints: true, concurrent_reads: true)
false
iex> ExDatalog.Capabilities.satisfies?(caps, [])
true