API surfaces

C Stable 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.11.1 uses consumer API 2, frontend/program ABI 2, backend ABI 5 and diagnostic ABI 1. 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 MAELYS_DATALOG_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.

API by responsibility

ResponsibilityOperationsPurpose
Domaindomain_registerInstall the vocabulary used to validate policy source and runtime facts.
Loadingpolicy_load_inline · policy_load_manifestCreate an opaque policy from source bytes or a governed manifest.
Identitypolicy_fingerprint · session_fingerprintRead the canonical policy identity before or after selecting a policy.
Sessionsession_create · session_solvePrepare one policy once and evaluate independent runtime fact sets.
Queriesresult_query · result_enumerateCheck one ground fact or enumerate an already-derived query relation.
Renderingresult_symbol_text · result_explain_true_text · result_explain_false_textResolve result-owned symbols and render Why-true or Why-false text.
Lifetimepolicy_free · session_free · result_freeRelease each opaque object at the end of its documented lifetime.
Input bufferinput_edb_create · input_edb_init · input_edb_add_fact · input_edb_add_facts · session_solve_edbCopy facts into bounded owned storage and solve from it.
Configurationsession_config_create · session_create_configured · session_execution_fingerprintRequire capabilities or a work budget explicitly and read execution identity.
Limitslimit_get · result_derived_fact_countRead loaded-library capacities and distinct derived-fact counts.
Prepared explanationsresult_explanation_storage_requirements · result_prepare_explanation · prepared_explanation_text_size · prepared_explanation_write_text · prepared_explanation_releasePrepare once in caller-owned storage, measure and write repeatedly, then release.
Optional C buildersMAELYS_DATALOG_EDB · MAELYS_DATALOG_IDB_QUERY · MAELYS_DATALOG_ADD_FACTS · MAELYS_DATALOG_QUERYOptional source builders; no additional exported symbols or ABI change.

Reference by topic

Choose the stable C operation by task. Each topic links to its separate explanation of the underlying concept.

For a runnable C example, see the Full program. Additional operations on the same opaque handles—including in-memory manifests, dynamic domain registration and structured explanations—are documented in the C Advanced API.

Deliberate boundary

The stable header does not expose parser objects, ruleset fields, EDB pools, symbol-table mutation or solver internals. Use the C Advanced API for supported extensions on the same opaque handles. Its operations live in a separate installed header.

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.