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.

CODE
#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 boundaryConsequence for applications
Opaque policy, session, and result handlesInternal structures may evolve without requiring source access from consumers.
Explicit status valuesEvery operation reports success or a named fail-closed category.
Explicit ownershipEach successful allocation has one matching *_free operation.
Result-scoped symbol renderingRuntime symbol identifiers are interpreted by the exact result that produced them.
Canonical policy fingerprintsA 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

1. Register domaindomain_register

Declare the closed predicate vocabulary and allowed source atoms.

2. Load policypolicy_load_*

Parse inline policy text or load a manifest into an opaque policy handle.

3. Create sessionsession_create

Prepare one selected policy for repeated runtime fact sets.

4. Solvesession_solve

Submit one bounded fact array and obtain an immutable result.

5. Inspect resultresult_*

Query facts, enumerate a relation, resolve symbols, or render Why-true or Why-false.

6. Release*_free

Free results first, then their session. A policy may be freed after session creation.

Detailed API

Domain

NameSummary
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() functionRegisters 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() macroDeclares a domain when policy source contains no quoted symbolic constants.
DOMAIN_WITH_ATOMS() macroDeclares a domain with an explicit array of allowed policy-source atoms.
EDB() macroDeclares a runtime-input predicate.
EDB_QUERY() macroDeclares a runtime-input predicate that may also be queried.
IDB() macroDeclares a relation derived by policy rules.
IDB_QUERY() macroDeclares a derived relation that may also be queried.
POLICY_FACT() macroDeclares a predicate whose ground facts come from policy source.
POLICY_FACT_QUERY() macroDeclares policy-source facts that may also be queried.

Guides: Registries guide · Full program

Policy

NameSummary
policy_t handleOpaque 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() functionLoads one policy directly from Datalog source text and validates it against a registered domain. This path does not read a manifest.
policy_load_manifest() functionLoads the policies listed in a manifest file, checking their source hashes, domain declarations and public query permissions.
policy_load_manifest_buffer() functionLoad a governed policy set from manifest JSON and source bytes already in memory, without reading policy files.
policy_load_manifest_text() functionLoads 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() functionReads how many policies belong to a loaded set, so the application can choose a valid policy index when creating a session.
policy_id() functionReads 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() functionReads the identity of the complete loaded policy set. Use it to distinguish policy sets, rather than the execution configuration of a session.
policy_free() functionReleases a loaded policy-set handle when the application no longer needs it for creating sessions.
policy_stat_get() functionRead a selected policy's compiled predicate, policy-fact or normalized-rule count without preparing a session.
policy_reads_predicate() functionChecks 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 constantNo optional permissions: require declared policy constants and reject enabled test-only policies.
PUBLIC_ALLOW_TEST_ONLY constantAdmit enabled entries whose manifest mode is test_only.
PUBLIC_ALLOW_UNDECLARED_POLICY_ATOMS constantAdmit policy-local string constants absent from the domain's atoms.
PUBLIC_MAX_POLICY_ATOMS constantPublished maximum number of policy atoms; also reported by the MAX_POLICY_ATOMS runtime limit.
PUBLIC_MAX_POLICY_ATOM_BYTES constantPublished maximum byte length of a policy atom; also reported by the MAX_POLICY_ATOM_BYTES runtime limit.
PUBLIC_FINGERPRINT_BYTES constantRequired caller-owned fingerprint buffer size, including the terminating NUL, as declared by policy_fingerprint.

Guides: Policy guide · Full program

Input EDB

NameSummary
input_edb_t handleOpaque, 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() functionAppends 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() functionAppends 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() functionRemoves 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() functionReads the number of entries currently stored in the input buffer, before any solving or result enumeration.
input_edb_create() functionCreates 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() functionCreates an empty input buffer with explicit fact and text capacities, fixed for its lifetime.
input_edb_free() functionReleases the input buffer. Results already produced from it remain independent of that input storage.
input_edb_init() functionInitializes an empty input buffer inside memory supplied by the application, using the requested fact and text capacities.
input_edb_storage_requirements() functionMeasures 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() functionReads how much of the input buffer’s text storage is occupied by interned strings.
input_edb_view() functionBorrows a view of the stored input facts in insertion order. The view refers to the input buffer rather than copying its contents.
ADD_FACT() macroAdds one typed fact through the input EDB API.
ADD_FACTS() macroAdds one batch through the input EDB API.
BOOL() macroRequests boolean rather than integer conversion for a C expression.
FACT() macroBuilds one borrowed checked descriptor for an atomic batch.
SYMBOL() macroMarks a borrowed C string as a symbol-valued term.

Guides: Runtime EDB guide · Full program

Session

NameSummary
session_t handlePrepared policy and bounded solver workspace reused for independent requests. One live result may belong to it at a time.
session_config_t handleOptional requirements and memory choices applied when a session is created. Configuration is not a second policy.
session_config_create() functionCreates a mutable configuration with no additional capability requirement and the default work budget.
session_config_free() functionReleases a configuration after its values have been copied into any created sessions.
session_config_get_required_capabilities() functionReads the capability mask selected in a session configuration.
session_config_get_work_limit() functionReads the cooperative work budget selected in a session configuration.
session_config_set_explanation_storage() functionSelects caller-owned, aligned storage for the session explanation workspace.
session_config_set_explanation_workspace() functionSelects explanation kinds for one session-owned workspace allocated at session creation.
session_config_set_required_capabilities() functionReplaces the capability mask that session creation must satisfy.
session_config_set_work_limit() functionReplaces the optional work budget; zero restores the native default.
session_create() functionPrepares one policy selected by its index for repeated requests. No input facts are supplied and no answer is computed yet.
session_create_configured() functionPrepares one selected policy using an explicit session configuration, including any requested execution and explanation settings.
session_execution_fingerprint() functionReads the combined identity of the selected policy and its execution configuration, for distinguishing how a policy is evaluated.
session_explanation_storage_bound() functionReports a reference session's caller-owned workspace requirement before preparing an explanation.
session_fingerprint() functionReads the policy identity selected by this session, independently of its execution configuration.
session_free() functionReleases a prepared session once its live result has been released.
session_solve() functionEvaluates the selected policy against a fact array supplied by the application, without requiring an input EDB handle.
session_solve_edb() functionEvaluates 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 constantPositive Datalog rules.
CAP_NEGATION constantStratified negation.
CAP_COMPARISONS constantComparison operators.
CAP_ARITHMETIC constantArithmetic expressions.
CAP_FILTERS constantRegistered filters.
CAP_EXPLAIN_TRUE constantExplanations for true facts.
CAP_WORK_LIMIT constantBounded work limit.
CAP_EXPLAIN_FALSE constantExplanations for false facts.
CAP_AGGREGATES constantCount aggregation.
CAP_MIN constantMinimum aggregation.
CAP_MAX constantMaximum aggregation.
CAP_SUM constantSum aggregation.
CAP_LANGUAGE constantLanguage capability mask.
CAP_ALL constantAll public capability bits.

Guides: Solving guide · Full program

Session inputs reference

NameSummary
session_inputs_t handleOpt-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() functionMeasures 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() functionInitializes 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() functionReads the current incarnation and generation used to guard a retained-input update.
session_inputs_replace() functionReplaces 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() functionApplies 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() functionReleases 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 macroInitializes the retained-input options structure to the public contract size and version, with zero capacities and no vocabulary.
INPUT_CONTRACT_VERSION constantVersion of the published input_options_t initialization contract.

Guides: Solving guide

Session resources

NameSummary
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 macroInitializes an elastic request that requires a caller allocator.
ALLOCATION_REQUEST_PREFIX_SIZE constantMinimum readable contract prefix, expressed from the published structure layout.
ALLOCATION_REQUEST_V1_SIZE constantComplete V1 structure size; use the expression rather than a hard-coded platform size.
ALLOCATION_STATS_INIT macroInitializes the size and version of an allocation-statistics output.
ALLOCATION_STATS_PREFIX_SIZE constantMinimum readable contract prefix, expressed from the published structure layout.
ALLOCATION_STATS_V1_SIZE constantComplete V1 structure size; use the expression rather than a hard-coded platform size.
ALLOCATION_STATS_VERSION constantVersion of the elastic allocation-statistics contract.
CALLER_ALLOCATOR_INIT macroInitializes an allocator descriptor with no context or callbacks.
CALLER_ALLOCATOR_PREFIX_SIZE constantMinimum readable contract prefix, expressed from the published structure layout.
CALLER_ALLOCATOR_V1_SIZE constantComplete V1 structure size; use the expression rather than a hard-coded platform size.
CALLER_ALLOCATOR_VERSION constantVersion of the caller-allocator descriptor contract.
CAPACITY_ALL constantMask containing all four capacity-presence bits.
CAPACITY_DERIVED_FACTS constantPresence bit for the complete derived-fact capacity.
CAPACITY_INPUT_FACTS constantPresence bit for the raw input-fact capacity.
CAPACITY_SYMBOLS constantPresence bit for the symbol-dictionary capacity.
CAPACITY_TEXT_BYTES constantPresence bit for the interned-text capacity.
MEMORY_BACKEND_ELASTIC constantSelects backend-elastic execution with caller allocation.
MEMORY_FIXED constantSelects fixed-memory execution.
RESOURCES_INIT macroStarting 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 constantMinimum readable contract prefix, expressed from the published structure layout.
RESOURCES_V1_SIZE constantComplete V1 structure size; use the expression rather than a hard-coded platform size.
RESOURCE_CALLER_ALLOCATOR constantResource-feature bit required for caller allocation.
RESOURCE_CONTRACT_VERSION constantVersion of the resource-request and normalized-resources contract.
RESOURCE_REQUEST_INIT macroStarting 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 constantMinimum readable contract prefix, expressed from the published structure layout.
RESOURCE_REQUEST_V1_SIZE constantComplete V1 structure size; use the expression rather than a hard-coded platform size.
RESOURCE_SESSION_CAPACITIES constantResource-feature bit for explicit session capacities.
RESOURCE_SUPPORTED constantSupported resource-feature mask, including caller allocation.
RESOURCE_SUPPORTED_014 constantHistorical supported-resource mask retained for older compiled consumers.
SESSION_PLAN_INIT macroInitializes the size and version of a session storage plan.
SESSION_PLAN_PREFIX_SIZE constantMinimum readable contract prefix, expressed from the published structure layout.
SESSION_PLAN_V1_SIZE constantComplete V1 structure size; use the expression rather than a hard-coded platform size.
SESSION_PLAN_VERSION constantVersion of the configured-session storage-plan contract.
policy_load_manifest_text_in() functionLoads 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() functionMeasures 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() functionCopies 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() functionReads 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() functionReads the normalized resource capacities of a session. The output reports admitted capacities, not unresolved defaults or presence sentinels.
session_init_configured() functionInitializes 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() functionMeasures 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

NameSummary
window_t handleRetains the last accepted single-fact events and their current solved snapshot.
group_window_t handleRetains 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 constantReserve 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() functionBorrow the retained raw contributions, including duplicate facts.
group_window_expire() functionExpire all entries whose deadlines are at or before the caller-supplied time.
group_window_expiry_watermark() functionRead the last time committed by an explicit expiration call.
group_window_facts() functionBorrow the sorted unique union of committed event and static facts.
group_window_free() functionRelease the current result and return the borrowed sessions without freeing caller storage.
group_window_groups() functionBorrow retained group metadata and the slices into its contribution view.
group_window_init() functionInitialize a multi-fact window in caller-owned storage and borrow two idle sessions.
group_window_init_configured() functionInitialize a multi-fact window in caller-owned storage and borrow two idle sessions with the selected options.
group_window_push() functionAppend a complete group of facts, expiring the oldest entry when the window is full.
group_window_push_until() functionAppend a complete group of facts and an explicit expiration deadline.
group_window_replace_static() functionReplace all static facts and recompute the result without consuming an event ID.
group_window_result() functionBorrow the latest result; the window retains ownership of its lease.
group_window_state() functionRead committed group, contribution and unique-fact occupancy.
group_window_static_facts() functionBorrow the committed static facts without changing the window.
group_window_storage_requirements() functionMeasure the caller-owned storage for a multi-fact event window.
group_window_storage_requirements_configured() functionMeasure the caller-owned storage for a multi-fact event window with static input or expiration options.
window_events() functionBorrow retained events in arrival order, including their generated occurrence IDs.
window_expire() functionExpire all entries whose deadlines are at or before the caller-supplied time.
window_expiry_watermark() functionRead the last time committed by an explicit expiration call.
window_free() functionRelease the current result and return the borrowed sessions without freeing caller storage.
window_init() functionInitialize a single-fact window in caller-owned storage and borrow two idle sessions.
window_init_configured() functionInitialize a single-fact window in caller-owned storage and borrow two idle sessions with the selected options.
window_push() functionAppend an event with a generated occurrence ID, expiring the oldest entry when the window is full.
window_push_until() functionAppend an event with a generated occurrence ID and an explicit expiration deadline.
window_replace_static() functionReplace all static facts and recompute the result without consuming an event ID.
window_result() functionBorrow the latest result; the window retains ownership of its lease.
window_state() functionRead the retained event count and the next occurrence ID.
window_static_facts() functionBorrow the committed static facts without changing the window.
window_storage_requirements() functionMeasure the caller-owned storage for a single-fact event window.
window_storage_requirements_configured() functionMeasure the caller-owned storage for a single-fact event window with static input or expiration options.
window_text_usage() functionRead the interned text used by committed input and its per-bank capacity.

Guides: Event windows guide

Program

NameSummary
program_t handleBorrowed, 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 constantReports that the SDK provides source-variable name lookup.
IR_MAX_BODY constantMaximum number of literals in a normalized rule body.
IR_MAX_EXPRESSIONS constantMaximum number of expression nodes in a normalized rule.
IR_MAX_VARIABLES constantMaximum number of variables in a normalized rule.
IR_NO_EXPRESSION constantSentinel for a literal with no arithmetic-expression root.
PROGRAM_ABI_VERSION constantVersion of the read-only compiled-program inspection contract.
program_fact() functionRead a normalized static fact by its zero-based index.
program_fingerprint() functionRead the compiled identity of the program into a fixed-size fingerprint buffer.
program_info() functionRead the program identity, declaration counts, limits and required capabilities.
program_predicate() functionRead a predicate descriptor by its zero-based program index.
program_query() functionRead an admitted query descriptor by its zero-based query index.
program_query_count() functionCount the queries admitted by the loaded manifest and query policy.
program_rule() functionRead a normalized rule by its zero-based index.
program_rule_variable_name() functionRead the source spelling of a named variable in a normalized rule.
session_program() functionBorrow the compiled program from a live session for read-only inspection.

Guides: Program guide

Structured explanations

NameSummary
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() functionRead the query outcome, completeness and record counts of a prepared explanation.
prepared_explanation_obstacle() functionRead one failed rule attempt and its supporting facts and obstacle in a Why-false explanation.
prepared_explanation_premise() functionRead one supporting fact, checked absence, comparison, filter or aggregate in a Why-true proof.
prepared_explanation_step() functionRead one derived fact and the range of premises supporting it in a Why-true proof.
EXPLANATION_NO_STEP constantSentinel indicating that a premise has no supporting derived step.

Guides: Structured explanations guide

Result

NameSummary
result_t handleAnswer to one successful solve. Query and explain it while live, then release it before reusing its session.
prepared_explanation_t handleAn 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() functionEnds the prepared explanation lease so its result and workspace may be reused or released.
prepared_explanation_text_size() functionReads the cached formatted length of a prepared explanation without traversing its proof again.
prepared_explanation_write_text() functionFormats a retained explanation into caller-owned output text without preparing it again.
result_derived_fact_count() functionReads the number of facts derived during this solve, without enumerating them or deriving additional facts.
result_enumerate() functionLists the derived facts of a query-enabled predicate in an existing result, using the supplied output array.
result_explain_false_text() functionProduces 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() functionPrepares, sizes, writes and releases one explanation in caller-owned storage in a single call.
result_explain_true_text() functionProduces 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() functionRenders a Why-true or Why-false explanation into caller-owned text, with optional caller-owned failure diagnostics.
result_explanation_storage_requirements() functionReports the workspace bytes and alignment needed to prepare an explanation from this result.
result_free() functionReleases a result and its result-local data, allowing the session to solve another request once explanation leases have also been released.
result_prepare_explanation() functionPrepares one Why-true or Why-false document in caller-owned storage and leases its result.
result_prepare_explanation_diagnosed() functionPrepares one Why-true or Why-false explanation in caller-owned storage, with optional caller-owned failure diagnostics.
result_query() functionChecks whether one fully specified fact is present in an existing result. It does not solve the policy again.
result_symbol_text() functionLooks 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() macroDeclares suitably aligned caller-owned bytes for prepared explanations.
QUERY() macroQueries a fully specified fact using C11 term conversion.
result_filter_statistics() functionReads the reference solver’s filter statistics for this result. These describe solving work, not a later Why-false explanation search.
PUBLIC_MAX_TERMS constantMaximum number of terms in a public fact or query.

Guides: Querying guide · Full program

Decisions reference

NameSummary
decision_t enum (5 members)Composed outcome of the explicit allow, reduce and deny presence bits.
decision_from_presence() functionCombines 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

NameSummary
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() functionConverts a diagnostic reason code into a readable name, complementing the broader public status.
diagnostic_clear() functionClears details from a previous diagnostic while keeping the object ready for reuse by another API call.
diagnostic_init() functionInitializes diagnostic storage supplied by the application, with the metadata required before passing it to an API call.
diagnostic_initializer() functionConstructs an initialized diagnostic value, including its size and ABI metadata, ready to receive details from an API call.
limit_get() functionReads a selected build capacity from the loaded library so callers can size bounded inputs.
status_name() functionConverts a public status code into a readable name for logs and error messages.
DIAGNOSTIC_INIT macroConstructs an initialized diagnostic value.
limit_name() functionReturns the stable name of a public budget identifier.
DIAGNOSTIC_AGGREGATE constantAggregate field, offending value text and kind, projection index and inclusive numeric bound are populated.
DIAGNOSTIC_ARITY constantExpected and observed arity are populated.
DIAGNOSTIC_CAPACITY constantAttempted count, capacity bound and budget identity are populated.
DIAGNOSTIC_COMPARISON constantComparison outcome, operand kinds and operator are populated.
DIAGNOSTIC_CONTEXT constantDomain and producer context are populated.
DIAGNOSTIC_DEPTH constantObserved and permitted depth are populated.
DIAGNOSTIC_LOCATION constantSource file, line and column are populated.
DIAGNOSTIC_PREDICATE constantPredicate name and arity are populated.
DIAGNOSTIC_RULE constantRule identifier is populated.
DIAGNOSTIC_ABI_VERSION constantABI 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.