C API
C API
Integrate Maelys Datalog through its stable opaque C API and explicit ownership model.Stable public consumer API · version 2
The stable C API is the recommended integration surface for new native consumers. Policies, prepared sessions and solve results are opaque handles: application code need not depend on parser, ruleset, symbol-table, EDB or solver layouts. Datalog 0.27.0 uses consumer API 2, frontend/program ABI 2 and diagnostic ABI 1. Native backend descriptors have distinct ABIs 5, 6 and 7; resource and retained-input contracts are opt-in. Recompile existing C/C++ consumers; removed type aliases have no compatibility layer.
#include <maelys/datalog.h>What stable means
The stable boundary covers the declarations in <maelys/datalog.h>, identified
by PUBLIC_API_VERSION. Internal structure layouts are not part
of that contract.
| Guaranteed boundary | Consequence for applications |
|---|---|
| Opaque policy, session, and result handles | Internal structures may evolve without requiring source access from consumers. |
| Explicit status values | Every operation reports success or a named fail-closed category. |
| Explicit ownership | Each successful allocation has one matching *_free operation. |
| Result-scoped symbol rendering | Runtime symbol identifiers are interpreted by the exact result that produced them. |
| Canonical policy fingerprints | A consumer can bind a loaded policy or session to its engine identity. |
The library release version and the public API version are separate concepts. The API version identifies the shape of this facade; the library release identifies a concrete implementation.
For release-by-release changes, see the Changelog.
The lifecycle
domain_registerDeclare the closed predicate vocabulary and allowed source atoms.
policy_load_*Parse inline policy text or load a manifest into an opaque policy handle.
session_createPrepare one selected policy for repeated runtime fact sets.
session_solveSubmit one bounded fact array and obtain an immutable result.
result_*Query facts, enumerate a relation, resolve symbols, or render Why-true or Why-false.
*_freeFree results first, then their session. A policy may be freed after session creation.
Detailed API
Domain
| Name | Summary |
|---|---|
domain_t struct (5 fields) | The domain declaration supplied when registering a policy vocabulary. |
predicate_t struct (3 fields) | One predicate in the domain vocabulary, with a fixed name, arity and set of permissions. |
predicate_flags_t enum (4 members) | Predicate-origin and query-permission bits used when declaring a domain. Combine one origin with QUERY when membership queries are required. |
domain_register() function | Registers a domain: its predicate names, arities, permissions and allowed policy-source atoms. Policies can then be loaded against this vocabulary; registration does not load or evaluate a policy. |
DOMAIN_NO_ATOMS() macro | Declares a domain when policy source contains no quoted symbolic constants. |
DOMAIN_WITH_ATOMS() macro | Declares a domain with an explicit array of allowed policy-source atoms. |
EDB() macro | Declares a runtime-input predicate. |
EDB_QUERY() macro | Declares a runtime-input predicate that may also be queried. |
IDB() macro | Declares a relation derived by policy rules. |
IDB_QUERY() macro | Declares a derived relation that may also be queried. |
POLICY_FACT() macro | Declares a predicate whose ground facts come from policy source. |
POLICY_FACT_QUERY() macro | Declares policy-source facts that may also be queried. |
Guides: Registries guide · Full program
Policy
| Name | Summary |
|---|---|
policy_t handle | Opaque handle owning one loaded policy or a manifest set. Select policies by index through sessions; release the handle with policy_free(). |
policy_bundle_entry_t struct (3 fields) | Pairs a manifest policy ID with caller-supplied source bytes for one buffer load. |
policy_stat_t enum (3 members) | Selects which immutable compiled-program count to read from one loaded policy. |
policy_load_inline() function | Loads one policy directly from Datalog source text and validates it against a registered domain. This path does not read a manifest. |
policy_load_manifest() function | Loads the policies listed in a manifest file, checking their source hashes, domain declarations and public query permissions. |
policy_load_manifest_buffer() function | Load a governed policy set from manifest JSON and source bytes already in memory, without reading policy files. |
policy_load_manifest_text() function | Loads a manifest bundle from memory using the historical text-loading contract. If default_profile is omitted, it defaults to MAELYS-DATALOG-v2; policy_load_manifest_buffer uses the file-loader default, enforce. Source bytes are borrowed only for the call. |
policy_count() function | Reads how many policies belong to a loaded set, so the application can choose a valid policy index when creating a session. |
policy_id() function | Reads the identifier of one enabled policy without preparing a session or allocating storage. The returned string is borrowed from the loaded policy set. |
policy_fingerprint() function | Reads the identity of the complete loaded policy set. Use it to distinguish policy sets, rather than the execution configuration of a session. |
policy_free() function | Releases a loaded policy-set handle when the application no longer needs it for creating sessions. |
policy_stat_get() function | Read a selected policy's compiled predicate, policy-fact or normalized-rule count without preparing a session. |
policy_reads_predicate() function | Checks whether one compiled policy reads a named predicate in a rule body, without preparing a session. Reads include positive and negated atoms and aggregate sources; heads and static facts do not count. |
PUBLIC_ALLOW_NONE constant | No optional permissions: require declared policy constants and reject enabled test-only policies. |
PUBLIC_ALLOW_TEST_ONLY constant | Admit enabled entries whose manifest mode is test_only. |
PUBLIC_ALLOW_UNDECLARED_POLICY_ATOMS constant | Admit policy-local string constants absent from the domain's atoms. |
PUBLIC_MAX_POLICY_ATOMS constant | Published maximum number of policy atoms; also reported by the MAX_POLICY_ATOMS runtime limit. |
PUBLIC_MAX_POLICY_ATOM_BYTES constant | Published maximum byte length of a policy atom; also reported by the MAX_POLICY_ATOM_BYTES runtime limit. |
PUBLIC_FINGERPRINT_BYTES constant | Required caller-owned fingerprint buffer size, including the terminating NUL, as declared by policy_fingerprint. |
Guides: Policy guide · Full program
Input EDB
| Name | Summary |
|---|---|
input_edb_t handle | Opaque, reusable buffer for the complete input facts of one request. Create or initialize it, add facts, solve, then clear it before another request. |
fact_t struct (3 fields) | One input fact: a predicate name, its arity and up to four typed terms. |
value_kind_t enum (3 members) | Tag selecting the symbol, integer or boolean member of a typed input or result term. |
value_t struct (2 fields) | A typed ground value supplied in an input fact, query or explanation request. Symbol inputs carry text rather than a result-owned symbol identifier. |
input_edb_add_fact() function | Appends one typed fact to the input buffer and copies its text values into the buffer’s storage. This call does not evaluate the policy. |
input_edb_add_facts() function | Appends a complete batch of typed facts in one operation. The batch is atomic: if an entry cannot be stored, none of this batch is added. |
input_edb_clear() function | Removes the input entries so the same buffer can hold another request. Clearing input does not release a live result or reset its session. |
input_edb_count() function | Reads the number of entries currently stored in the input buffer, before any solving or result enumeration. |
input_edb_create() function | Creates an empty input buffer using the installed profile’s default capacities. The application fills it with facts before solving a request. |
input_edb_create_with_capacity() function | Creates an empty input buffer with explicit fact and text capacities, fixed for its lifetime. |
input_edb_free() function | Releases the input buffer. Results already produced from it remain independent of that input storage. |
input_edb_init() function | Initializes an empty input buffer inside memory supplied by the application, using the requested fact and text capacities. |
input_edb_storage_requirements() function | Measures the size and alignment needed to initialize an input buffer in application-provided memory. It does not allocate or initialize that memory. |
input_edb_text_usage() function | Reads how much of the input buffer’s text storage is occupied by interned strings. |
input_edb_view() function | Borrows a view of the stored input facts in insertion order. The view refers to the input buffer rather than copying its contents. |
ADD_FACT() macro | Adds one typed fact through the input EDB API. |
ADD_FACTS() macro | Adds one batch through the input EDB API. |
BOOL() macro | Requests boolean rather than integer conversion for a C expression. |
FACT() macro | Builds one borrowed checked descriptor for an atomic batch. |
SYMBOL() macro | Marks a borrowed C string as a symbol-valued term. |
Guides: Runtime EDB guide · Full program
Session
| Name | Summary |
|---|---|
session_t handle | Prepared policy and bounded solver workspace reused for independent requests. One live result may belong to it at a time. |
session_config_t handle | Optional requirements and memory choices applied when a session is created. Configuration is not a second policy. |
session_config_create() function | Creates a mutable configuration with no additional capability requirement and the default work budget. |
session_config_free() function | Releases a configuration after its values have been copied into any created sessions. |
session_config_get_required_capabilities() function | Reads the capability mask selected in a session configuration. |
session_config_get_work_limit() function | Reads the cooperative work budget selected in a session configuration. |
session_config_set_explanation_storage() function | Selects caller-owned, aligned storage for the session explanation workspace. |
session_config_set_explanation_workspace() function | Selects explanation kinds for one session-owned workspace allocated at session creation. |
session_config_set_required_capabilities() function | Replaces the capability mask that session creation must satisfy. |
session_config_set_work_limit() function | Replaces the optional work budget; zero restores the native default. |
session_create() function | Prepares one policy selected by its index for repeated requests. No input facts are supplied and no answer is computed yet. |
session_create_configured() function | Prepares one selected policy using an explicit session configuration, including any requested execution and explanation settings. |
session_execution_fingerprint() function | Reads the combined identity of the selected policy and its execution configuration, for distinguishing how a policy is evaluated. |
session_explanation_storage_bound() function | Reports a reference session's caller-owned workspace requirement before preparing an explanation. |
session_fingerprint() function | Reads the policy identity selected by this session, independently of its execution configuration. |
session_free() function | Releases a prepared session once its live result has been released. |
session_solve() function | Evaluates the selected policy against a fact array supplied by the application, without requiring an input EDB handle. |
session_solve_edb() function | Evaluates the selected policy against all facts in an input EDB. Each call is a complete request snapshot, not an incremental update to the previous result. |
CAP_POSITIVE constant | Positive Datalog rules. |
CAP_NEGATION constant | Stratified negation. |
CAP_COMPARISONS constant | Comparison operators. |
CAP_ARITHMETIC constant | Arithmetic expressions. |
CAP_FILTERS constant | Registered filters. |
CAP_EXPLAIN_TRUE constant | Explanations for true facts. |
CAP_WORK_LIMIT constant | Bounded work limit. |
CAP_EXPLAIN_FALSE constant | Explanations for false facts. |
CAP_AGGREGATES constant | Count aggregation. |
CAP_MIN constant | Minimum aggregation. |
CAP_MAX constant | Maximum aggregation. |
CAP_SUM constant | Sum aggregation. |
CAP_LANGUAGE constant | Language capability mask. |
CAP_ALL constant | All public capability bits. |
Guides: Solving guide · Full program
Session inputs reference
| Name | Summary |
|---|---|
session_inputs_t handle | Opt-in retained dynamic input attached to one session with a fixed symbol vocabulary. Compiled policy facts remain separate. Initialize before the session’s first solve; release every result and prepared explanation before changing or releasing the attachment. |
input_options_t struct (8 fields) | Caller-specified capacities and fixed vocabulary for a retained-input attachment. Initialize with MAELYS_DATALOG_INPUT_OPTIONS_INIT before assigning capacities and symbols. The attachment copies these options and vocabulary. |
input_base_t struct (2 fields) | Incarnation and generation of one retained-input attachment. Pass its current base to replace or apply; even a successful no-op publishes a new base, and an old base never becomes valid for a fresh attachment. |
session_inputs_storage_requirements() function | Measures the aligned caller storage needed to attach fixed-vocabulary retained input to a session. No engine allocation is performed. Query the requirements at runtime rather than hard-coding a platform-dependent size or alignment. |
session_inputs_init() function | Initializes retained dynamic input in caller-owned storage before the session’s first solve. Copies the options and vocabulary, performs no engine allocation and borrows the supplied aligned, nonoverlapping arena for the attachment lifetime. |
session_inputs_base() function | Reads the current incarnation and generation used to guard a retained-input update. |
session_inputs_replace() function | Replaces retained facts against the current base and returns a leased result. Raw record limits apply before deduplication. Unknown replacement symbols are INVALID_FIELD. A successful no-op also publishes a new base; live results or explanations forbid the next update. |
session_inputs_apply() function | Applies an addition/removal batch against the current base and returns a leased result. Raw addition and removal counts are independently bounded before deduplication. Additions win over removals and absent removals are no-ops. Unknown added symbols are INVALID_FIELD; unknown removed symbols denote absent facts after raw validation. |
session_inputs_free() function | Releases an attachment after all results have been released, without freeing caller storage. Session destruction is refused while an attachment remains live. Released storage may be reused with a fresh session; its old base is never valid for another attachment. |
INPUT_OPTIONS_INIT macro | Initializes the retained-input options structure to the public contract size and version, with zero capacities and no vocabulary. |
INPUT_CONTRACT_VERSION constant | Version of the published input_options_t initialization contract. |
Guides: Solving guide
Session resources
| Name | Summary |
|---|---|
session_resource_request_t struct (9 fields) | Selects session memory mode, required resources and optional capacities. Initialize the complete descriptor, then set capacity-mask bits for explicit capacities. An absent capacity uses the loaded profile default; a present zero capacity is an exact quota, not a default sentinel. |
session_resources_t struct (8 fields) | Reports the normalized resource capacities admitted for a session. All four capacities are normalized without presence/default sentinels. Requirements and preparation use the same values. Retain scalar copies rather than borrowed callback-scoped descriptors. |
caller_allocator_t struct (7 fields) | Supplies borrowed allocation callbacks and their context for elastic execution. Context and callback code are borrowed through destruction and the last release, including failed preparation. Keep reserved and required_features zero in V1. |
session_allocation_request_t struct (3 fields) | Extends a resource request with an execution byte cap and caller allocator. Initialize the complete extended request. Its base selects backend-elastic memory and requires caller allocation; older hosts reject this required feature before reading the tail. |
session_allocation_stats_t struct (8 fields) | Reports elastic execution charges and the peak for the current or last operation. Accounting is read-only and does not allocate or call the allocator. A fixed-memory session returns UNSUPPORTED with the output unchanged. Reading is allowed while a result or explanation lease is live, but not reentrantly during an operation. |
session_storage_plan_t struct (13 fields) | Describes the caller-owned arena and external slices required by a configured session. Requirements allocate no prepared state. The first four internal components sum to arena_bytes. External storage contributes only its required slice, counted once; init recomputes the plan rather than trusting stale sizes. |
backend_storage_t struct (4 fields) | Describes borrowed, aligned storage reserved for a backend. The buffer is aligned, immovable and disjoint from all other live storage, inputs and outputs. It lives through session destruction; the host copies the descriptor, never accesses or frees its contents. |
ALLOCATION_REQUEST_INIT macro | Initializes an elastic request that requires a caller allocator. |
ALLOCATION_REQUEST_PREFIX_SIZE constant | Minimum readable contract prefix, expressed from the published structure layout. |
ALLOCATION_REQUEST_V1_SIZE constant | Complete V1 structure size; use the expression rather than a hard-coded platform size. |
ALLOCATION_STATS_INIT macro | Initializes the size and version of an allocation-statistics output. |
ALLOCATION_STATS_PREFIX_SIZE constant | Minimum readable contract prefix, expressed from the published structure layout. |
ALLOCATION_STATS_V1_SIZE constant | Complete V1 structure size; use the expression rather than a hard-coded platform size. |
ALLOCATION_STATS_VERSION constant | Version of the elastic allocation-statistics contract. |
CALLER_ALLOCATOR_INIT macro | Initializes an allocator descriptor with no context or callbacks. |
CALLER_ALLOCATOR_PREFIX_SIZE constant | Minimum readable contract prefix, expressed from the published structure layout. |
CALLER_ALLOCATOR_V1_SIZE constant | Complete V1 structure size; use the expression rather than a hard-coded platform size. |
CALLER_ALLOCATOR_VERSION constant | Version of the caller-allocator descriptor contract. |
CAPACITY_ALL constant | Mask containing all four capacity-presence bits. |
CAPACITY_DERIVED_FACTS constant | Presence bit for the complete derived-fact capacity. |
CAPACITY_INPUT_FACTS constant | Presence bit for the raw input-fact capacity. |
CAPACITY_SYMBOLS constant | Presence bit for the symbol-dictionary capacity. |
CAPACITY_TEXT_BYTES constant | Presence bit for the interned-text capacity. |
MEMORY_BACKEND_ELASTIC constant | Selects backend-elastic execution with caller allocation. |
MEMORY_FIXED constant | Selects fixed-memory execution. |
RESOURCES_INIT macro | Starting value for reading a session's capacities: pass it to session_get_resources(), which fills in the capacities granted to the session. |
RESOURCES_PREFIX_SIZE constant | Minimum readable contract prefix, expressed from the published structure layout. |
RESOURCES_V1_SIZE constant | Complete V1 structure size; use the expression rather than a hard-coded platform size. |
RESOURCE_CALLER_ALLOCATOR constant | Resource-feature bit required for caller allocation. |
RESOURCE_CONTRACT_VERSION constant | Version of the resource-request and normalized-resources contract. |
RESOURCE_REQUEST_INIT macro | Starting value for a capacity request: every field is set so the session uses the profile's default capacities. Change only the capacities you need, then pass the request to session_config_set_resources(). |
RESOURCE_REQUEST_PREFIX_SIZE constant | Minimum readable contract prefix, expressed from the published structure layout. |
RESOURCE_REQUEST_V1_SIZE constant | Complete V1 structure size; use the expression rather than a hard-coded platform size. |
RESOURCE_SESSION_CAPACITIES constant | Resource-feature bit for explicit session capacities. |
RESOURCE_SUPPORTED constant | Supported resource-feature mask, including caller allocation. |
RESOURCE_SUPPORTED_014 constant | Historical supported-resource mask retained for older compiled consumers. |
SESSION_PLAN_INIT macro | Initializes the size and version of a session storage plan. |
SESSION_PLAN_PREFIX_SIZE constant | Minimum readable contract prefix, expressed from the published structure layout. |
SESSION_PLAN_V1_SIZE constant | Complete V1 structure size; use the expression rather than a hard-coded platform size. |
SESSION_PLAN_VERSION constant | Version of the configured-session storage-plan contract. |
policy_load_manifest_text_in() function | Loads a manifest using caller-owned policy storage. The policy object uses caller storage with no heap fallback. JSON parsing, contexts and extension callbacks may still allocate: this is not a whole-loader zero-allocation guarantee. Keep the arena alive until the policy is closed; policy_free closes it without freeing the arena. Failure may overwrite the arena. |
policy_storage_requirements() function | Measures the caller storage needed by a policy handle. Query size and alignment at runtime; both depend on the platform. The fixed-profile policy arena holds up to eight policies. |
session_config_set_resources() function | Copies a resource request into a session configuration. NULL restores defaults. The configuration copies known values and remains unchanged on failure. Policy-dependent normalization and admission occur during planning or creation. |
session_get_allocation_stats() function | Reads elastic allocation accounting without allocating. The reference backend returns UNSUPPORTED for its fixed-memory sessions and leaves the initialized output unchanged. This is not a claim of zero memory use. |
session_get_resources() function | Reads the normalized resource capacities of a session. The output reports admitted capacities, not unresolved defaults or presence sentinels. |
session_init_configured() function | Initializes a configured session in a caller-owned arena. Supply the aligned caller arena allocated to the size and alignment returned by the requirements query. Init recomputes its plan from the policy and configuration. Whole-session initialization rejects ABI 5; the convenience create_configured path retains its legacy ABI 5 default path. |
session_storage_requirements_configured() function | Measures and describes the complete configured session arena. Query requirements at runtime rather than hard-coding platform-dependent sizes or alignment. No prepared state is allocated. Whole-session planning rejects ABI 5 backend selections; no provider is migrated automatically. |
Guides: Session resources guide
Event windows
| Name | Summary |
|---|---|
window_t handle | Retains the last accepted single-fact events and their current solved snapshot. |
group_window_t handle | Retains the last accepted groups of complete facts and their current solved snapshot. |
window_options_t struct (3 fields) | Reserves optional static input and deadline storage when creating either window adapter. |
group_window_capacities_t struct (4 fields) | Sets separate bounds for retained groups, raw contributions, unique facts and text. |
event_group_t struct (3 fields) | Identifies a retained group and its slice of the ordered event contributions. |
group_window_usage_t struct (5 fields) | Reports the committed groups, contributions, unique facts and text use. |
WINDOW_EXPIRATION constant | Reserve per-event or per-group deadline metadata in both caller-owned input banks. Set this flag in window_options_t.flags before initialization to enable explicit expiration. |
group_window_contributions() function | Borrow the retained raw contributions, including duplicate facts. |
group_window_expire() function | Expire all entries whose deadlines are at or before the caller-supplied time. |
group_window_expiry_watermark() function | Read the last time committed by an explicit expiration call. |
group_window_facts() function | Borrow the sorted unique union of committed event and static facts. |
group_window_free() function | Release the current result and return the borrowed sessions without freeing caller storage. |
group_window_groups() function | Borrow retained group metadata and the slices into its contribution view. |
group_window_init() function | Initialize a multi-fact window in caller-owned storage and borrow two idle sessions. |
group_window_init_configured() function | Initialize a multi-fact window in caller-owned storage and borrow two idle sessions with the selected options. |
group_window_push() function | Append a complete group of facts, expiring the oldest entry when the window is full. |
group_window_push_until() function | Append a complete group of facts and an explicit expiration deadline. |
group_window_replace_static() function | Replace all static facts and recompute the result without consuming an event ID. |
group_window_result() function | Borrow the latest result; the window retains ownership of its lease. |
group_window_state() function | Read committed group, contribution and unique-fact occupancy. |
group_window_static_facts() function | Borrow the committed static facts without changing the window. |
group_window_storage_requirements() function | Measure the caller-owned storage for a multi-fact event window. |
group_window_storage_requirements_configured() function | Measure the caller-owned storage for a multi-fact event window with static input or expiration options. |
window_events() function | Borrow retained events in arrival order, including their generated occurrence IDs. |
window_expire() function | Expire all entries whose deadlines are at or before the caller-supplied time. |
window_expiry_watermark() function | Read the last time committed by an explicit expiration call. |
window_free() function | Release the current result and return the borrowed sessions without freeing caller storage. |
window_init() function | Initialize a single-fact window in caller-owned storage and borrow two idle sessions. |
window_init_configured() function | Initialize a single-fact window in caller-owned storage and borrow two idle sessions with the selected options. |
window_push() function | Append an event with a generated occurrence ID, expiring the oldest entry when the window is full. |
window_push_until() function | Append an event with a generated occurrence ID and an explicit expiration deadline. |
window_replace_static() function | Replace all static facts and recompute the result without consuming an event ID. |
window_result() function | Borrow the latest result; the window retains ownership of its lease. |
window_state() function | Read the retained event count and the next occurrence ID. |
window_static_facts() function | Borrow the committed static facts without changing the window. |
window_storage_requirements() function | Measure the caller-owned storage for a single-fact event window. |
window_storage_requirements_configured() function | Measure the caller-owned storage for a single-fact event window with static input or expiration options. |
window_text_usage() function | Read the interned text used by committed input and its per-bank capacity. |
Guides: Event windows guide
Program
| Name | Summary |
|---|---|
program_t handle | Borrowed, read-only view of the compiled program owned by a session. |
program_info_t struct (11 fields) | Identity, counts, limits and capabilities of the compiled program. |
ir_atom_t struct (3 fields) | Predicate name and typed terms in a normalized atom. |
ir_rule_t struct (6 fields) | Normalized rule head, body, arithmetic expressions and source location. |
ir_literal_t struct (13 fields) | One normalized rule-body operation and its active operands. |
ir_expression_t struct (4 fields) | One node of an arithmetic expression in normalized rule order. |
ir_term_t struct (2 fields) | A symbol, integer, Boolean or variable in a normalized program. |
source_location_t struct (2 fields) | One-based source line and column when available. |
ir_literal_kind_t enum (8 members) | The operation represented by a normalized rule-body literal. |
ir_term_kind_t enum (4 members) | The active value of a normalized program term. |
ir_comparison_t enum (6 members) | Comparison operator used by a normalized rule literal. |
ir_expression_kind_t enum (5 members) | Literal, variable or arithmetic operator represented by an expression node. |
HAS_RULE_VARIABLE_NAMES constant | Reports that the SDK provides source-variable name lookup. |
IR_MAX_BODY constant | Maximum number of literals in a normalized rule body. |
IR_MAX_EXPRESSIONS constant | Maximum number of expression nodes in a normalized rule. |
IR_MAX_VARIABLES constant | Maximum number of variables in a normalized rule. |
IR_NO_EXPRESSION constant | Sentinel for a literal with no arithmetic-expression root. |
PROGRAM_ABI_VERSION constant | Version of the read-only compiled-program inspection contract. |
program_fact() function | Read a normalized static fact by its zero-based index. |
program_fingerprint() function | Read the compiled identity of the program into a fixed-size fingerprint buffer. |
program_info() function | Read the program identity, declaration counts, limits and required capabilities. |
program_predicate() function | Read a predicate descriptor by its zero-based program index. |
program_query() function | Read an admitted query descriptor by its zero-based query index. |
program_query_count() function | Count the queries admitted by the loaded manifest and query policy. |
program_rule() function | Read a normalized rule by its zero-based index. |
program_rule_variable_name() function | Read the source spelling of a named variable in a normalized rule. |
session_program() function | Borrow the compiled program from a live session for read-only inspection. |
Guides: Program guide
Structured explanations
| Name | Summary |
|---|---|
explanation_info_t struct (14 fields) | Outcome, completeness and record counts of a prepared Why-true or Why-false explanation. |
explanation_step_view_t struct (4 fields) | A derived fact and the contiguous range of premises supporting its rule application. |
explanation_premise_view_t struct (13 fields) | One Why-true premise, with the operands selected by its kind. |
explanation_support_view_t struct (3 fields) | A fact that supported a body literal before a Why-false rule attempt failed. |
explanation_obstacle_view_t struct (18 fields) | A failed rule attempt, its bound variables and supports, and the obstacle that stopped it. |
explanation_premise_kind_t enum (8 members) | Selects the meaning and active operands of a Why-true premise. |
explanation_origin_t enum (4 members) | Identifies whether a fact comes from policy data, runtime inputs or derived results. |
why_false_status_t enum (3 members) | Distinguishes a complete refusal, a truncated search and an inapplicable Why-false request. |
why_false_summary_t enum (2 members) | Indicates whether the refusal search found any candidate rule. |
why_false_obstacle_kind_t enum (11 members) | Identifies the failed condition recorded for a candidate rule. |
why_false_limit_t enum (5 members) | Bit flags identifying which bounded Why-false searches reached a limit. |
prepared_explanation_info() function | Read the query outcome, completeness and record counts of a prepared explanation. |
prepared_explanation_obstacle() function | Read one failed rule attempt and its supporting facts and obstacle in a Why-false explanation. |
prepared_explanation_premise() function | Read one supporting fact, checked absence, comparison, filter or aggregate in a Why-true proof. |
prepared_explanation_step() function | Read one derived fact and the range of premises supporting it in a Why-true proof. |
EXPLANATION_NO_STEP constant | Sentinel indicating that a premise has no supporting derived step. |
Guides: Structured explanations guide
Result
| Name | Summary |
|---|---|
result_t handle | Answer to one successful solve. Query and explain it while live, then release it before reusing its session. |
prepared_explanation_t handle | An opaque explanation retained in caller-owned aligned storage. It leases its result until prepared_explanation_release() ends the lease; the workspace and result must remain alive throughout. |
fact_view_t struct (2 fields) | Borrowed view of one result fact returned by enumeration. Its symbol IDs belong to the same live result. |
term_view_t struct (2 fields) | A typed term borrowed from an enumerated result fact. Symbol IDs are scoped to that result and must be resolved with result_symbol_text() while it remains alive. |
explanation_kind_t enum (2 members) | Selects Why-true or Why-false when preparing or rendering an explanation. |
filter_statistics_t struct (4 fields) | Filter activity accumulated by a reference-backend solve. |
prepared_explanation_release() function | Ends the prepared explanation lease so its result and workspace may be reused or released. |
prepared_explanation_text_size() function | Reads the cached formatted length of a prepared explanation without traversing its proof again. |
prepared_explanation_write_text() function | Formats a retained explanation into caller-owned output text without preparing it again. |
result_derived_fact_count() function | Reads the number of facts derived during this solve, without enumerating them or deriving additional facts. |
result_enumerate() function | Lists the derived facts of a query-enabled predicate in an existing result, using the supplied output array. |
result_explain_false_text() function | Produces a bounded Why-false document describing obstacles encountered when investigating an absent fact. This is a diagnostic exploration, not an exhaustive proof of every possible obstruction. |
result_explain_text_in() function | Prepares, sizes, writes and releases one explanation in caller-owned storage in a single call. |
result_explain_true_text() function | Produces a bounded Why-true document describing a derivation of the requested fact in this result. It explains the existing answer rather than solving the policy again. |
result_explain_text_diagnosed() function | Renders a Why-true or Why-false explanation into caller-owned text, with optional caller-owned failure diagnostics. |
result_explanation_storage_requirements() function | Reports the workspace bytes and alignment needed to prepare an explanation from this result. |
result_free() function | Releases a result and its result-local data, allowing the session to solve another request once explanation leases have also been released. |
result_prepare_explanation() function | Prepares one Why-true or Why-false document in caller-owned storage and leases its result. |
result_prepare_explanation_diagnosed() function | Prepares one Why-true or Why-false explanation in caller-owned storage, with optional caller-owned failure diagnostics. |
result_query() function | Checks whether one fully specified fact is present in an existing result. It does not solve the policy again. |
result_symbol_text() function | Looks up the string represented by a symbol ID belonging to this result. That ID is not a reusable symbol identifier for another result. |
EXPLANATION_STORAGE() macro | Declares suitably aligned caller-owned bytes for prepared explanations. |
QUERY() macro | Queries a fully specified fact using C11 term conversion. |
result_filter_statistics() function | Reads the reference solver’s filter statistics for this result. These describe solving work, not a later Why-false explanation search. |
PUBLIC_MAX_TERMS constant | Maximum number of terms in a public fact or query. |
Guides: Querying guide · Full program
Decisions reference
| Name | Summary |
|---|---|
decision_t enum (5 members) | Composed outcome of the explicit allow, reduce and deny presence bits. |
decision_from_presence() function | Combines already known query-presence bits into a decision. It does not run a query or evaluate a policy. Deny takes precedence, then reduce, then allow; deny combined with allow or reduce is a conflict, and no presence yields the default deny. |
Guides: Solving guide · Querying guide
Errors reference
| Name | Summary |
|---|---|
status_t enum (15 members) | Machine-readable outcome of a public call. OK is success; other values must never be treated as a negative membership answer. |
diagnostic_t struct (31 fields) | Versioned diagnostic record: owned text plus independent typed detail sections. Initialize before every producer call. |
diag_code_t enum (46 members) | Typed diagnostic reason reported alongside the public status; use diag_code_name() for its stable name. |
diagnostic_source_t enum (3 members) | Identifies the producer of diagnostic details: NONE, policy loading, or solving. |
limit_t enum (26 members) | Identifies a budget dimension rather than its current occupancy. limit_get() reports library-wide ceilings; session-specific dimensions have no global value. Capacity diagnostics report the effective bound at the failure site, including session quotas. |
diag_code_name() function | Converts a diagnostic reason code into a readable name, complementing the broader public status. |
diagnostic_clear() function | Clears details from a previous diagnostic while keeping the object ready for reuse by another API call. |
diagnostic_init() function | Initializes diagnostic storage supplied by the application, with the metadata required before passing it to an API call. |
diagnostic_initializer() function | Constructs an initialized diagnostic value, including its size and ABI metadata, ready to receive details from an API call. |
limit_get() function | Reads a selected build capacity from the loaded library so callers can size bounded inputs. |
status_name() function | Converts a public status code into a readable name for logs and error messages. |
DIAGNOSTIC_INIT macro | Constructs an initialized diagnostic value. |
limit_name() function | Returns the stable name of a public budget identifier. |
DIAGNOSTIC_AGGREGATE constant | Aggregate field, offending value text and kind, projection index and inclusive numeric bound are populated. |
DIAGNOSTIC_ARITY constant | Expected and observed arity are populated. |
DIAGNOSTIC_CAPACITY constant | Attempted count, capacity bound and budget identity are populated. |
DIAGNOSTIC_COMPARISON constant | Comparison outcome, operand kinds and operator are populated. |
DIAGNOSTIC_CONTEXT constant | Domain and producer context are populated. |
DIAGNOSTIC_DEPTH constant | Observed and permitted depth are populated. |
DIAGNOSTIC_LOCATION constant | Source file, line and column are populated. |
DIAGNOSTIC_PREDICATE constant | Predicate name and arity are populated. |
DIAGNOSTIC_RULE constant | Rule identifier is populated. |
DIAGNOSTIC_ABI_VERSION constant | ABI version required when initializing this diagnostic record. |
Guides: Errors guide
For a runnable C example, see the Full program. Additional operations on the same opaque handles are declared in the installed SDK headers: structured explanations in datalog_explanations.h, for example.
Deliberate boundary
The stable header does not expose parser objects, ruleset fields, EDB pools,
symbol-table mutation or solver internals. Supported program views, structured
explanations and extension contracts live in datalog_program.h,
datalog_explanations.h and the other installed SDK headers listed above.
For language semantics, see the Datalog language. For the meaning of the lifecycle stages, see the concept pages on registries, rulesets, runtime EDB, solving, and querying.