C Extension API

Backends

Implement snapshot, resource-aware and retained-input native solvers with explicit commit and abort.

Implement a native solver with an explicit lifecycle: validate a supported program, stage a complete result, then publish state only when the core commits it. The Backends guide applies the independent ABI 5, ABI 6 and ABI 7 contracts to document-access decisions.

Struct: backend_t

C · structSince v0.1.0-alpha.4
backend_t

#include <maelys/datalog_backend.h>

Snapshot backend descriptor: prepare one session, read its complete canonical inputs, and emit the complete derived result before commit.
Fields
abi_versionuint32_t
Set to MAELYS_DATALOG_BACKEND_ABI_VERSION (ABI 5). This is the fixed-memory snapshot descriptor.
struct_sizesize_t
Readable descriptor size, set to sizeof this exact installed public type.
nameconst char *
Stable nonempty component name copied into the session; callback code must remain loaded until the session and its results are destroyed.
semantic_idconst char *
Stable semantic identity of this implementation, copied with its descriptor; change it when evaluation semantics change.
capabilitiesuint64_t
CAP_* assertions for the semantics this backend implements. Advertise an explanation capability only with all three explanation callbacks and their conformance coverage.
storage_requirementsmaelys_datalog_status_t (*)(const maelys_datalog_program_t *, size_t *, size_t *)Since v0.11.0
Read-only deterministic storage measurement for the compiled program. Write bytes and a nonzero power-of-two alignment no larger than alignof(max_align_t); zero bytes is valid. Do not allocate or reenter the engine.
preparemaelys_datalog_status_t (*)(const maelys_datalog_program_t *, const maelys_datalog_backend_storage_t *, void **)
Prepare session-confined backend state from the live compiled program and supplied caller-owned state buffer. Retain storage->bytes if needed, never the temporary storage descriptor. Return state through out_state; state returned on failure is destroyed too.
solvemaelys_datalog_status_t (*)(void *, const maelys_datalog_fact_t *, size_t, maelys_datalog_backend_output_t *, void **, maelys_datalog_diagnostic_t *)
Stage a candidate from the complete canonical dynamic input snapshot and emit the complete derived IDB, including internal predicates. Keep previously committed state unchanged until commit; return candidate state through out_result_state.
explanation_storage_requirementsmaelys_datalog_status_t (*)(void *, void *, maelys_datalog_explanation_kind_t, size_t *, size_t *)Since v0.4.0
When an explanation capability is advertised, deterministically measure caller-owned scratch for this live result and kind. Size must be positive and alignment valid; do not allocate, acquire resources or reenter the engine.
explanation_preparemaelys_datalog_status_t (*)(void *, void *, maelys_datalog_explanation_kind_t, const char *, const maelys_datalog_value_t *, size_t, void *, size_t, size_t *)Since v0.4.0
Extract the requested explanation once into the supplied scratch and return its exact text length excluding NUL. SIZE_MAX is invalid. No allocation, acquired resources, retained query strings or engine reentry; result state must remain unchanged on failure.
explanation_write_textmaelys_datalog_status_t (*)(void *, void *, maelys_datalog_explanation_kind_t, const void *, char *, size_t)Since v0.4.0
Format only the already prepared scratch, without another search or extraction. The host checks capacity first; successful text is NUL-terminated and exactly the prepared length, without allocation or resource acquisition.
commitvoid (*)(void *, void *)Since v0.11.0
Infallible callback invoked exactly once only after a complete candidate has passed host validation and is installed irrevocably. Publish staged backend state here; allocate nothing and do not reenter the engine. NULL result_state still receives this callback.
destroy_resultvoid (*)(void *, void *)
Destroy a candidate/result state. Before commit this aborts the staged candidate; after commit it releases a result. It is also invoked for state returned by a failed solve; NULL is valid.
destroyvoid (*)(void *)
Release all backend session state, including state returned by a failed prepare. Its program and session-bound allocation service remain valid through this callback; do not reenter the engine.
Typedef
typedef struct maelys_datalog_backend_t {
    uint32_t abi_version;
    size_t struct_size;
    const char *name;
    const char *semantic_id;
    uint64_t capabilities;
    /* Read-only, deterministic for the program, without allocation or reentry.
     * Called once per session creation before prepare (explicit public queries
     * are separate calls). Zero bytes is valid; alignment must be a nonzero
     * power of two <= alignof(max_align_t), even for zero bytes. */
    maelys_datalog_status_t (*storage_requirements)(const maelys_datalog_program_t *program,
                                                   size_t *out_bytes, size_t *out_alignment);
    /* storage is non-NULL and valid for this call only; storage->bytes is the
     * caller's exact pointer. Retain the buffer, not the descriptor pointer.
     * Absent storage is represented by {sizeof(...), NULL, 0, 1}. */
    maelys_datalog_status_t (*prepare)(const maelys_datalog_program_t *program,
                                      const maelys_datalog_backend_storage_t *storage, void **out_state);
    maelys_datalog_status_t (*solve)(void *state,
                                     const maelys_datalog_fact_t *canonical_inputs,
                                     size_t input_count, maelys_datalog_backend_output_t *output,
                                     void **out_result_state, maelys_datalog_diagnostic_t *out_diagnostic);
    /* Caller-owned explanation storage introduced in ABI 3 is retained in ABI 5.
     * The versioned common diagnostic protocol introduced in ABI 4 also remains.
     * All three are required if either EXPLAIN capability is advertised; the
     * host calls only supported kinds. No allocator calls, acquired resources,
     * engine reentry or retained query-string pointers. Result state stays alive
     * until all explanations are released. Scratch belongs in the same storage;
     * bounded automatic locals are allowed. No destroy hook is needed: this
     * storage contains only values and references borrowed from the live result.
     *
     * storage_requirements is read-only and deterministic for (result, kind).
     * Alignment must be a nonzero power of two <= alignof(max_align_t), size > 0.
     * prepare extracts once and returns the EXACT text length excluding NUL;
     * SIZE_MAX is invalid. On failure storage may change, retained state may not.
     * write_text only formats the prepared storage; never extracts/searches again.
     * The host checks capacity first. Successful output is NUL-terminated and
     * exactly the prepared length. All callbacks are trusted and bounded. */
    maelys_datalog_status_t (*explanation_storage_requirements)(
        void *state, void *result_state, maelys_datalog_explanation_kind_t kind,
        size_t *out_bytes, size_t *out_alignment);
    maelys_datalog_status_t (*explanation_prepare)(
        void *state, void *result_state, maelys_datalog_explanation_kind_t kind,
        const char *predicate, const maelys_datalog_value_t *terms, size_t arity,
        void *storage, size_t storage_bytes, size_t *out_text_size);
    maelys_datalog_status_t (*explanation_write_text)(
        void *state, void *result_state, maelys_datalog_explanation_kind_t kind,
        const void *storage, char *out_text, size_t capacity);
    /* Exactly once per accepted result, after host validation/copy/deduplication
     * and installation; for windows, only after publication is irrevocable.
     * Never called for an abandoned candidate (including window init probes).
     * Infallible, no allocation or reentry; precedes every explanation callback.
     * solve must keep previously committed backend state intact until commit.
     * destroy_result without commit means abort; after commit it means release.
     * A NULL result_state is valid and does not suppress either callback. */
    void (*commit)(void *state, void *result_state);
    void (*destroy_result)(void *state, void *result_state);
    void (*destroy)(void *state);
} maelys_datalog_backend_t;

Constants

Snapshot ABI

BACKEND_ABI_VERSION

C · constantSince v0.1.0-alpha.4
BACKEND_ABI_VERSION
#define MAELYS_DATALOG_BACKEND_ABI_VERSION 5u

ABI 5 snapshot descriptor version; fixed resource policy and complete snapshot solving.

Value

5

Struct: backend_v6_t

C · structSince v0.14.0
backend_v6_t

#include <maelys/datalog_backend.h>

Independent resource-aware snapshot backend descriptor; storage measurement and preparation receive the session’s normalized resource contract.
Fields
abi_versionuint32_t
Set to MAELYS_DATALOG_BACKEND_V6_ABI_VERSION (ABI 6); use this independent resource-aware descriptor, never an ABI 5 cast.
struct_sizesize_t
Readable descriptor size, set to sizeof this exact installed public type.
nameconst char *
Stable nonempty component name copied into the session; callback code must remain loaded until the session and its results are destroyed.
semantic_idconst char *
Stable semantic identity of this implementation, copied with its descriptor; change it when evaluation semantics change.
capabilitiesuint64_t
CAP_* assertions for the semantics this backend implements. Advertise an explanation capability only with all three explanation callbacks and their conformance coverage.
resource_featuresuint64_t
Supported RESOURCE_* contract bits. SESSION_CAPACITIES is required; CALLER_ALLOCATOR requires the elastic tail and explicit caller opt-in. Unknown bits are unsupported.
storage_requirementsmaelys_datalog_status_t (*)(const maelys_datalog_program_t *, const maelys_datalog_session_resources_t *, size_t *, size_t *)
Read-only deterministic measurement from the compiled program and normalized resources. Resources and scalar policy are the same as prepare; an elastic tail has allocation=NULL at this stage. Do not allocate or reenter the engine.
preparemaelys_datalog_status_t (*)(const maelys_datalog_program_t *, const maelys_datalog_session_resources_t *, const maelys_datalog_backend_storage_t *, void **)
Prepare session-confined backend state from the program, normalized resources and caller-owned state buffer. For elastic opt-in, read the tail’s session-bound allocation service here; retain the state buffer, not the temporary storage descriptor.
solvemaelys_datalog_status_t (*)(void *, const maelys_datalog_fact_t *, size_t, maelys_datalog_backend_output_t *, void **, maelys_datalog_diagnostic_t *)
Stage a candidate from the complete canonical dynamic input snapshot and emit the complete derived IDB, including internal predicates. Keep previously committed state unchanged until commit; return candidate state through out_result_state.
explanation_storage_requirementsmaelys_datalog_status_t (*)(void *, void *, maelys_datalog_explanation_kind_t, size_t *, size_t *)
When an explanation capability is advertised, deterministically measure caller-owned scratch for this live result and kind. Size must be positive and alignment valid; do not allocate, acquire resources or reenter the engine.
explanation_preparemaelys_datalog_status_t (*)(void *, void *, maelys_datalog_explanation_kind_t, const char *, const maelys_datalog_value_t *, size_t, void *, size_t, size_t *)
Extract the requested explanation once into the supplied scratch and return its exact text length excluding NUL. SIZE_MAX is invalid. No allocation, acquired resources, retained query strings or engine reentry; result state must remain unchanged on failure.
explanation_write_textmaelys_datalog_status_t (*)(void *, void *, maelys_datalog_explanation_kind_t, const void *, char *, size_t)
Format only the already prepared scratch, without another search or extraction. The host checks capacity first; successful text is NUL-terminated and exactly the prepared length, without allocation or resource acquisition.
commitvoid (*)(void *, void *)
Infallible callback invoked exactly once only after a complete candidate has passed host validation and is installed irrevocably. Publish staged backend state here; allocate nothing and do not reenter the engine. NULL result_state still receives this callback.
destroy_resultvoid (*)(void *, void *)
Destroy a candidate/result state. Before commit this aborts the staged candidate; after commit it releases a result. It is also invoked for state returned by a failed solve; NULL is valid.
destroyvoid (*)(void *)
Release all backend session state, including state returned by a failed prepare. Its program and session-bound allocation service remain valid through this callback; do not reenter the engine.
Typedef
typedef struct maelys_datalog_backend_v6_t {
    uint32_t abi_version;
    size_t struct_size;
    const char *name;
    const char *semantic_id;
    uint64_t capabilities;
    uint64_t resource_features;
    maelys_datalog_status_t (*storage_requirements)(
        const maelys_datalog_program_t *program,
        const maelys_datalog_session_resources_t *resources,
        size_t *out_bytes, size_t *out_alignment);
    maelys_datalog_status_t (*prepare)(
        const maelys_datalog_program_t *program,
        const maelys_datalog_session_resources_t *resources,
        const maelys_datalog_backend_storage_t *storage, void **out_state);
    /* Snapshot solve, complete emission, explanation and commit/abort contracts
     * retain their ABI 5 semantics and callback signatures. No delta callback. */
    maelys_datalog_status_t (*solve)(
        void *state, const maelys_datalog_fact_t *canonical_inputs,
        size_t input_count, maelys_datalog_backend_output_t *output,
        void **out_result_state, maelys_datalog_diagnostic_t *out_diagnostic);
    maelys_datalog_status_t (*explanation_storage_requirements)(
        void *state, void *result_state, maelys_datalog_explanation_kind_t kind,
        size_t *out_bytes, size_t *out_alignment);
    maelys_datalog_status_t (*explanation_prepare)(
        void *state, void *result_state, maelys_datalog_explanation_kind_t kind,
        const char *predicate, const maelys_datalog_value_t *terms, size_t arity,
        void *storage, size_t storage_bytes, size_t *out_text_size);
    maelys_datalog_status_t (*explanation_write_text)(
        void *state, void *result_state, maelys_datalog_explanation_kind_t kind,
        const void *storage, char *out_text, size_t capacity);
    void (*commit)(void *state, void *result_state);
    void (*destroy_result)(void *state, void *result_state);
    void (*destroy)(void *state);
} maelys_datalog_backend_v6_t;

Constants

Resource-aware ABI

BACKEND_V6_ABI_VERSION

C · constantSince v0.14.0
BACKEND_V6_ABI_VERSION
#define MAELYS_DATALOG_BACKEND_V6_ABI_VERSION 6u

ABI 6 resource-aware snapshot descriptor version; independent of ABI 5 and ABI 7.

Value

6

BACKEND_V6_SIZE

C · constantSince v0.14.0
BACKEND_V6_SIZE
#define MAELYS_DATALOG_BACKEND_V6_SIZE sizeof(maelys_datalog_backend_v6_t)

Complete required ABI 6 descriptor size; optional compatible tails may follow without inserting callbacks.

Value

sizeof(maelys_datalog_backend_v6_t)platform-dependent

Struct: backend_v7_t

C · structSince v0.16.0
backend_v7_t

#include <maelys/datalog_backend.h>

Independent retained-input backend descriptor; solve receives replacement or delta packets and commits the next input base only with an accepted result.
Fields
abi_versionuint32_t
Set to MAELYS_DATALOG_BACKEND_V7_ABI_VERSION (ABI 7). This retained-input descriptor is independent of ABI 5 and ABI 6.
struct_sizesize_t
Readable descriptor size, set to sizeof this exact installed public type.
nameconst char *
Stable nonempty component name copied into the session; callback code must remain loaded until the session and its results are destroyed.
semantic_idconst char *
Stable semantic identity of this implementation, copied with its descriptor; change it when evaluation semantics change.
capabilitiesuint64_t
CAP_* assertions for the semantics this backend implements. Advertise an explanation capability only with all three explanation callbacks and their conformance coverage.
resource_featuresuint64_t
Supported RESOURCE_* contract bits. SESSION_CAPACITIES is required; CALLER_ALLOCATOR requires the elastic tail and explicit caller opt-in. Unknown bits are unsupported.
storage_requirementsmaelys_datalog_status_t (*)(const maelys_datalog_program_t *, const maelys_datalog_session_resources_t *, size_t *, size_t *)
Read-only deterministic resource-aware storage measurement with ABI 6 semantics. Normalize support before solve; the same resource prefix and scalar policy reach prepare.
preparemaelys_datalog_status_t (*)(const maelys_datalog_program_t *, const maelys_datalog_session_resources_t *, const maelys_datalog_backend_storage_t *, void **)
Prepare session-confined retained-input state with ABI 6 resource/storage semantics. Keep a committed input base and a separate staged candidate; callback-scoped pointers may not be retained.
solvemaelys_datalog_backend_transaction_solve_t
Apply a REPLACE packet’s complete additions, or a DELTA packet’s removals then additions, to staged provider-owned inputs. Check the exact base, emit the complete IDB, and adopt next only in commit. No implicit snapshot fallback; copy every retained value or string.
explanation_storage_requirementsmaelys_datalog_status_t (*)(void *, void *, maelys_datalog_explanation_kind_t, size_t *, size_t *)
When an explanation capability is advertised, deterministically measure caller-owned scratch for this live result and kind. Size must be positive and alignment valid; do not allocate, acquire resources or reenter the engine.
explanation_preparemaelys_datalog_status_t (*)(void *, void *, maelys_datalog_explanation_kind_t, const char *, const maelys_datalog_value_t *, size_t, void *, size_t, size_t *)
Extract the requested explanation once into the supplied scratch and return its exact text length excluding NUL. SIZE_MAX is invalid. No allocation, acquired resources, retained query strings or engine reentry; result state must remain unchanged on failure.
explanation_write_textmaelys_datalog_status_t (*)(void *, void *, maelys_datalog_explanation_kind_t, const void *, char *, size_t)
Format only the already prepared scratch, without another search or extraction. The host checks capacity first; successful text is NUL-terminated and exactly the prepared length, without allocation or resource acquisition.
commitvoid (*)(void *, void *)
Infallible callback invoked exactly once only after a complete candidate has passed host validation and is installed irrevocably. Publish staged backend state here; allocate nothing and do not reenter the engine. NULL result_state still receives this callback.
destroy_resultvoid (*)(void *, void *)
Destroy a candidate/result state. Before commit this aborts the staged candidate; after commit it releases a result. It is also invoked for state returned by a failed solve; NULL is valid.
destroyvoid (*)(void *)
Release all backend session state, including state returned by a failed prepare. Its program and session-bound allocation service remain valid through this callback; do not reenter the engine.
Typedef
typedef struct maelys_datalog_backend_v7_t {
    uint32_t abi_version;
    size_t struct_size;
    const char *name, *semantic_id;
    uint64_t capabilities, resource_features;
    maelys_datalog_status_t (*storage_requirements)(const maelys_datalog_program_t *program,
        const maelys_datalog_session_resources_t *resources, size_t *out_bytes, size_t *out_alignment);
    maelys_datalog_status_t (*prepare)(const maelys_datalog_program_t *program,
        const maelys_datalog_session_resources_t *resources, const maelys_datalog_backend_storage_t *storage, void **out_state);
    maelys_datalog_backend_transaction_solve_t solve;
    maelys_datalog_status_t (*explanation_storage_requirements)(void *state, void *result_state,
        maelys_datalog_explanation_kind_t kind, size_t *out_bytes, size_t *out_alignment);
    maelys_datalog_status_t (*explanation_prepare)(void *state, void *result_state, maelys_datalog_explanation_kind_t kind,
        const char *predicate, const maelys_datalog_value_t *terms, size_t arity, void *storage, size_t storage_bytes, size_t *out_text_size);
    maelys_datalog_status_t (*explanation_write_text)(void *state, void *result_state, maelys_datalog_explanation_kind_t kind,
        const void *storage, char *out_text, size_t capacity);
    void (*commit)(void *state, void *result_state);
    void (*destroy_result)(void *state, void *result_state);
    void (*destroy)(void *state);
} maelys_datalog_backend_v7_t;

Constants

Retained-input ABI

BACKEND_V7_ABI_VERSION

C · constantSince v0.16.0
BACKEND_V7_ABI_VERSION
#define MAELYS_DATALOG_BACKEND_V7_ABI_VERSION 7u

ABI 7 retained-input descriptor version; replacement/delta solving with commit-only base adoption.

Value

7

BACKEND_V7_SIZE

C · constantSince v0.16.0
BACKEND_V7_SIZE
#define MAELYS_DATALOG_BACKEND_V7_SIZE sizeof(maelys_datalog_backend_v7_t)

Complete retained-input ABI 7 descriptor size; this type must never be cast as ABI 5 or ABI 6.

Value

sizeof(maelys_datalog_backend_v7_t)platform-dependent

Handle: backend_output_t

C · handleSince v0.1.0-alpha.4
backend_output_t

#include <maelys/datalog_backend.h>

typedef struct maelys_datalog_backend_output maelys_datalog_backend_output_t;
Callback-scoped destination for derived facts, cooperative work charges and native filter evaluation.

Functions

backend_charge()

C · functionSince v0.1.0-alpha.4
backend_charge()

#include <maelys/datalog_backend.h>

maelys_datalog_status_t
maelys_datalog_backend_charge(
maelys_datalog_backend_output_t *output,
uint64_t units
);
Charge cooperative backend work before executing a bounded unit of solving.
Arguments
outputmaelys_datalog_backend_output_t *handlemodified
Callback-scoped candidate output whose cooperative work budget is charged. A failed charge remains fatal even if the callback ignores its return value.
unitsuint64_tin
Number of backend-specific work units to charge before doing that work. Units compare only within this backend, not across algorithms; charging provides neither a wall-clock deadline nor sandbox isolation.
Return status

maelys_datalog_status_t — OK on success.

Returns OK if the charge is accepted. An exhausted work limit fails the candidate and remains sticky; propagate the returned status without continuing unbounded work.

Example
maelys_datalog_status_t status = maelys_datalog_backend_charge(output, 1);
printf("bounded work charged: %s\n", maelys_datalog_status_name(status));
return status;
bounded work charged: ok

backend_filter()

C · functionSince v0.1.0-alpha.4
backend_filter()

#include <maelys/datalog_backend.h>

maelys_datalog_status_t
maelys_datalog_backend_filter(
maelys_datalog_backend_output_t *output,
const char *name,
const char *semantic_id,
const unsigned char *value,
size_t value_length,
const unsigned char *pattern,
size_t pattern_length,
int *out_matched
);
Evaluate one registered native filter through the current backend output contract.
Arguments
outputmaelys_datalog_backend_output_t *handlemodified
Callback-scoped candidate output used for metering and sticky failure handling during this solve.
nameconst char *in
Exact registered filter name for this policy’s resolved native filter.
semantic_idconst char *in
Exact semantic identity paired with the registered filter name.
valueconst unsigned char *in
Borrowed value bytes to test during this callback.
value_lengthsize_tin
Number of value bytes; do not assume NUL termination.
patternconst unsigned char *in
Borrowed pattern bytes matching a filter pattern declared in the compiled policy.
pattern_lengthsize_tin
Number of pattern bytes; do not assume NUL termination.
Outputs

Written on success.

out_matchedint *out
Receives exactly 0 or 1 on success. Treat a failure as a solve failure, never a negative match.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with a normalized match after the registered filter’s cost check and evaluation. An unknown name/semantic identity returns UNSUPPORTED; a pattern not declared by the compiled program returns INVALID_FIELD. Invalid arguments, exhausted filter quotas, evaluation errors and prior sticky failures reject the candidate. Propagate every failure.

Example
maelys_datalog_status_t status = maelys_datalog_backend_filter(
    output, "ends_with", "string.ends-with.utf8-bytes-v1",
    (const unsigned char *)document, strlen(document),
    (const unsigned char *)".pdf", 4, out_matched);
if (status) return status;
printf("PDF suffix matched: %s\n", *out_matched ? "yes" : "no");
return MAELYS_DATALOG_STATUS_OK;

backend_emit()

C · functionSince v0.1.0-alpha.4
backend_emit()

#include <maelys/datalog_backend.h>

maelys_datalog_status_t
maelys_datalog_backend_emit(
maelys_datalog_backend_output_t *output,
const maelys_datalog_fact_t *fact
);
Copy one derived fact into the candidate result being built by the backend.
Arguments
outputmaelys_datalog_backend_output_t *handlemodified
Callback-scoped candidate output, supplied only to the current solve call. Emission and charging failures remain fatal to this candidate.
factconst maelys_datalog_fact_t *in
Complete derived IDB fact, including an internal non-query predicate when applicable. The core validates, copies and deduplicates it; symbols must already belong to the input/program vocabulary.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after accepting the copied fact. Invalid facts, unknown vocabulary, exhausted capacity or a prior sticky output failure return an error; no partial result is published when solve fails.

Example
maelys_datalog_status_t status = maelys_datalog_backend_emit(output, answer);
printf("derived fact accepted: %s\n", maelys_datalog_status_name(status));
return status;
derived fact accepted: ok

Struct: backend_input_t

C · structSince v0.16.0
backend_input_t

#include <maelys/datalog_backend.h>

Borrowed retained-input transaction packet describing a complete replacement or a removal/addition delta between two input bases.
Fields
struct_sizesize_t
Readable byte count of the transaction packet supplied by the host.
contract_versionuint32_t
Host-supplied MAELYS_DATALOG_BACKEND_INPUT_VERSION; reject an unsupported input contract before using its tail.
kinduint32_t
BACKEND_INPUT_REPLACE for the complete dynamic EDB in additions; BACKEND_INPUT_DELTA for removals followed by additions, with additions winning.
basemaelys_datalog_input_base_t
Committed input identity that the provider must match before applying this packet; the first base is empty at generation zero.
nextmaelys_datalog_input_base_t
Input identity of the candidate transaction; adopt it only in commit after the host has accepted publication.
additionsconst maelys_datalog_backend_input_view_t *
Callback-scoped typed-fact view of the replacement inputs or delta additions. Enumerate only while solve is running; copy retained text and values.
removalsconst maelys_datalog_backend_input_view_t *
Callback-scoped typed-fact view of delta removals. An absent removal is a no-op; never retain the view.
addition_countsize_t
Number of facts available through additions. A NULL view is valid only when this count is zero.
removal_countsize_t
Number of facts available through removals. A NULL view is valid only when this count is zero.
Typedef
typedef struct {
    size_t struct_size;
    uint32_t contract_version, kind;
    maelys_datalog_input_base_t base, next;
    const maelys_datalog_backend_input_view_t *additions, *removals;
    size_t addition_count, removal_count;
} maelys_datalog_backend_input_t;

Constants

Transaction packets

BACKEND_INPUT_VERSION

C · constantSince v0.16.0
BACKEND_INPUT_VERSION
#define MAELYS_DATALOG_BACKEND_INPUT_VERSION 1u

Version of the borrowed retained-input transaction packet.

Value

1

BACKEND_INPUT_REPLACE

C · constantSince v0.16.0
BACKEND_INPUT_REPLACE
#define MAELYS_DATALOG_BACKEND_INPUT_REPLACE 1u

Retained-input packet whose additions contain the complete replacement dynamic EDB.

Value

1

BACKEND_INPUT_DELTA

C · constantSince v0.16.0
BACKEND_INPUT_DELTA
#define MAELYS_DATALOG_BACKEND_INPUT_DELTA 2u

Retained-input packet with removals applied before additions; additions win and absent removals do nothing.

Value

2

Handle: backend_input_view_t

C · handleSince v0.16.0
backend_input_view_t

#include <maelys/datalog_backend.h>

typedef struct maelys_datalog_backend_input_view maelys_datalog_backend_input_view_t;
Callback-scoped view that exports normalized typed input facts one at a time.

Functions

backend_input_at()

C · functionSince v0.16.0
backend_input_at()

#include <maelys/datalog_backend.h>

maelys_datalog_status_t
maelys_datalog_backend_input_at(
const maelys_datalog_backend_input_view_t *view,
size_t index,
maelys_datalog_fact_t *out_fact
);
Read one normalized typed fact from a borrowed retained-input view during solve.
Arguments
viewconst maelys_datalog_backend_input_view_t *handleread
Callback-scoped input view from the current ABI 7 packet. A NULL view is valid only when its packet count is zero.
indexsize_tin
Zero-based index bounded by this view’s packet count; no enumeration order is promised.
Outputs

Written on success.

out_factmaelys_datalog_fact_t *out
Receives one normalized fact on success. Returned strings are borrowed only until solve returns; copy retained values and text into provider-owned storage.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with the exported fact. An out-of-range index returns NOT_FOUND; any failure leaves out_fact unchanged. The call allocates nothing and exposes no internal symbol IDs.

Example
maelys_datalog_status_t status = maelys_datalog_backend_input_at(view, index, out_fact);
printf("borrowed input read: %s\n", maelys_datalog_status_name(status));
return status;
borrowed input read: ok
borrowed input read: ok
borrowed input read: ok

Type: backend_transaction_solve_t

C · typeSince v0.16.0
backend_transaction_solve_t

#include <maelys/datalog_backend.h>

ABI 7 solve callback: stage the input transaction, emit every derived fact and defer all committed-state changes until commit.
Typedef
typedef maelys_datalog_status_t (*maelys_datalog_backend_transaction_solve_t)(
    void *state, const maelys_datalog_backend_input_t *input, maelys_datalog_backend_output_t *output,
    void **out_result_state, maelys_datalog_diagnostic_t *out_diagnostic);

Struct: session_allocation_resources_t

C · structSince v0.19.0
session_allocation_resources_t

#include <maelys/datalog_backend.h>

Elastic extension of normalized session resources: execution byte cap and the host’s session-bound allocation service.
Fields
basemaelys_datalog_session_resources_t
Existing normalized V1 resources at offset zero. Requirements and prepare receive the same normalized prefix and scalar policy.
execution_byte_capsize_t
Execution charge cap selected by the caller’s explicit elastic request; this scalar is available during requirements and prepare.
allocationconst maelys_datalog_allocation_service_t *
NULL during storage_requirements, then the live session-bound allocation service during prepare. Only callers opting into the elastic contract receive this required tail.
Typedef
typedef struct {
    maelys_datalog_session_resources_t base;
    size_t execution_byte_cap;
    const maelys_datalog_allocation_service_t *allocation;
} maelys_datalog_session_allocation_resources_t;

Constants

Elastic resource contract

ALLOCATION_RESOURCES_V1_SIZE

C · constantSince v0.19.0
ALLOCATION_RESOURCES_V1_SIZE
#define MAELYS_DATALOG_ALLOCATION_RESOURCES_V1_SIZE \
    sizeof(maelys_datalog_session_allocation_resources_t)

Complete elastic resource-tail size, including normalized base resources, execution cap and the session-bound service pointer.

Value

sizeof(maelys_datalog_session_allocation_resources_t)platform-dependent

Struct: allocation_service_t

C · structSince v0.19.0
allocation_service_t

#include <maelys/datalog_backend.h>

Session-bound allocation service that accounts for every acquired block and remains alive through the backend’s final destroy callback.
Fields
struct_sizesize_t
Host-supplied readable size of this service descriptor; use only fields covered by its supported contract.
contract_versionuint32_t
Host-supplied MAELYS_DATALOG_ALLOCATION_SERVICE_VERSION.
reserveduint32_t
Reserved service bits; zero in V1.
required_featuresuint64_t
Required allocation-service contract features; zero in V1.
tracking_bytessize_t
Per-block tracking charge K. A request for n bytes aligned to a is charged exactly K + (a - 1) + n, with every sum checked.
maximum_alignmentsize_t
Largest alignment accepted by the service; requests must also use a nonzero power of two.
contextvoid *
Opaque host context passed unchanged to inspect, acquire and release. It is session-bound and remains valid through final backend destruction.
inspectmaelys_datalog_status_t (*)(void *, size_t, size_t, maelys_datalog_allocation_budget_t *)
Read-only budget query for one size/alignment request. Initialize out_budget first; success reports fits as 0 or 1 and the complete charge. Failure preserves every output member and all allocation counters and transaction state.
acquiremaelys_datalog_status_t (*)(void *, size_t, size_t, void **, maelys_datalog_diagnostic_t *)
Acquire a provider-owned block through this session’s host service, writing its pointer to out_block and reporting failure through status/diagnostic. Use this service, never the caller’s raw allocator; account for tracking and alignment overhead.
releasevoid (*)(void *, void *)
Return a block acquired from this same session service exactly once. Do not use the service for another session or reentrantly.
Typedef
typedef struct {
    size_t struct_size;
    uint32_t contract_version;
    uint32_t reserved; /* zero */
    uint64_t required_features; /* zero in V1 */
    size_t tracking_bytes;
    size_t maximum_alignment;
    void *context;
    maelys_datalog_status_t (*inspect)(
        void *context, size_t bytes, size_t alignment,
        maelys_datalog_allocation_budget_t *out_budget);
    maelys_datalog_status_t (*acquire)(
        void *context, size_t bytes, size_t alignment,
        void **out_block, maelys_datalog_diagnostic_t *out_diagnostic);
    void (*release)(void *context, void *block);
} maelys_datalog_allocation_service_t;

Constants

Service contract

ALLOCATION_SERVICE_VERSION

C · constantSince v0.19.0
ALLOCATION_SERVICE_VERSION
#define MAELYS_DATALOG_ALLOCATION_SERVICE_VERSION 1u

Version of the host’s session-bound allocation-service contract.

Value

1

ALLOCATION_SERVICE_PREFIX_SIZE

C · constantSince v0.19.0
ALLOCATION_SERVICE_PREFIX_SIZE
#define MAELYS_DATALOG_ALLOCATION_SERVICE_PREFIX_SIZE \
    (offsetof(maelys_datalog_allocation_service_t, required_features) + sizeof(uint64_t))

Minimum readable allocation-service prefix, expressed from the installed public structure layout.

Value

(offsetof(maelys_datalog_allocation_service_t, required_features) + sizeof(uint64_t))platform-dependent

ALLOCATION_SERVICE_V1_SIZE

C · constantSince v0.19.0
ALLOCATION_SERVICE_V1_SIZE
#define MAELYS_DATALOG_ALLOCATION_SERVICE_V1_SIZE \
    sizeof(maelys_datalog_allocation_service_t)

Complete V1 allocation-service descriptor size; use its source expression rather than a fixed byte count.

Value

sizeof(maelys_datalog_allocation_service_t)platform-dependent

Struct: allocation_budget_t

C · structSince v0.19.0
allocation_budget_t

#include <maelys/datalog_backend.h>

Initialized output record for a side-effect-free inspection of the session-bound allocation budget.
Fields
struct_sizesize_t
Readable output size; the ALLOCATION_BUDGET_INIT macro sets the installed V1 size automatically.
contract_versionuint32_t
Allocation-budget contract version, set automatically by ALLOCATION_BUDGET_INIT.
reserveduint32_t
Reserved input bits; keep zero.
required_featuresuint64_t
Required budget-contract features; zero in V1.
cap_bytessize_t
Maximum charge available to this session’s execution allocation service.
current_bytessize_t
Current execution charge, including the session's fixed execution reservation and live service allocations.
remaining_bytessize_t
Unused charge remaining below cap_bytes.
operation_peak_bytessize_t
Largest charge reached in the current operation; inspection does not update this value.
required_chargesize_t
Exact charge for the inspected request, including service tracking and alignment overhead.
fitsuint32_t
Exactly 1 when the inspected request fits the remaining budget, otherwise 0; inspection acquires nothing.
reserved_tailuint32_t
Reserved output tail; zero in V1.
Typedef
typedef struct {
    size_t struct_size;
    uint32_t contract_version;
    uint32_t reserved; /* zero */
    uint64_t required_features; /* zero in V1 */
    size_t cap_bytes;
    size_t current_bytes;
    size_t remaining_bytes;
    size_t operation_peak_bytes;
    size_t required_charge;
    uint32_t fits;
    uint32_t reserved_tail; /* zero */
} maelys_datalog_allocation_budget_t;

Creation

ALLOCATION_BUDGET_INIT

C · macroSince v0.19.0
ALLOCATION_BUDGET_INIT

#include <maelys/datalog_backend.h>

#define MAELYS_DATALOG_ALLOCATION_BUDGET_INIT

Starting value for inspecting a session allocation request: initializes the size and contract version, then clears every output field. Pass the record to allocation_service_t.inspect.

Effect

Sets the installed size and contract version automatically and clears the remaining fields before the service fills them in. An initialized allocation_budget_t output record for allocation_service_t.inspect.

Initial values
FieldInitial valueMeaning
struct_sizeMAELYS_DATALOG_ALLOCATION_BUDGET_V1_SIZEReadable output size; the ALLOCATION_BUDGET_INIT macro sets the installed V1 size automatically.set automatically
contract_versionMAELYS_DATALOG_ALLOCATION_BUDGET_VERSIONAllocation-budget contract version, set automatically by ALLOCATION_BUDGET_INIT.set automatically
reservedUINT32_C(0)Reserved input bits; keep zero.
required_featuresUINT64_C(0)Required budget-contract features; zero in V1.
cap_bytes0Maximum charge available to this session’s execution allocation service.
current_bytes0Current execution charge, including the session's fixed execution reservation and live service allocations.
remaining_bytes0Unused charge remaining below cap_bytes.
operation_peak_bytes0Largest charge reached in the current operation; inspection does not update this value.
required_charge0Exact charge for the inspected request, including service tracking and alignment overhead.
fitsUINT32_C(0)Exactly 1 when the inspected request fits the remaining budget, otherwise 0; inspection acquires nothing.
reserved_tailUINT32_C(0)Reserved output tail; zero in V1.
Expansion
{ MAELYS_DATALOG_ALLOCATION_BUDGET_V1_SIZE,        MAELYS_DATALOG_ALLOCATION_BUDGET_VERSION, UINT32_C(0), UINT64_C(0),        0, 0, 0, 0, 0, UINT32_C(0), UINT32_C(0) }
Example
maelys_datalog_allocation_budget_t budget = MAELYS_DATALOG_ALLOCATION_BUDGET_INIT;
printf("budget version initialized: %s\n",
    budget.contract_version == MAELYS_DATALOG_ALLOCATION_BUDGET_VERSION ? "yes" : "no");
printf("ready for allocation service inspect: %s\n",
    budget.struct_size == sizeof(budget) && budget.reserved == 0 && budget.reserved_tail == 0 ? "yes" : "no");
return MAELYS_DATALOG_STATUS_OK;
budget version initialized: yes
ready for allocation service inspect: yes
Versioning

Initialize with the ALLOCATION_BUDGET_INIT macro; these values identify the structure version and are not set by hand.

Budget contract

ALLOCATION_BUDGET_VERSION

C · constantSince v0.19.0
ALLOCATION_BUDGET_VERSION
#define MAELYS_DATALOG_ALLOCATION_BUDGET_VERSION 1u

Version of the allocation-budget record initialized by ALLOCATION_BUDGET_INIT.

Value

1

ALLOCATION_BUDGET_PREFIX_SIZE

C · constantSince v0.19.0
ALLOCATION_BUDGET_PREFIX_SIZE
#define MAELYS_DATALOG_ALLOCATION_BUDGET_PREFIX_SIZE \
    (offsetof(maelys_datalog_allocation_budget_t, required_features) + sizeof(uint64_t))

Minimum readable allocation-budget prefix, expressed from the installed public structure layout.

Value

(offsetof(maelys_datalog_allocation_budget_t, required_features) + sizeof(uint64_t))platform-dependent

ALLOCATION_BUDGET_V1_SIZE

C · constantSince v0.19.0
ALLOCATION_BUDGET_V1_SIZE
#define MAELYS_DATALOG_ALLOCATION_BUDGET_V1_SIZE \
    sizeof(maelys_datalog_allocation_budget_t)

Complete V1 allocation-budget size; retain the sizeof expression rather than a platform-specific number.

Value

sizeof(maelys_datalog_allocation_budget_t)platform-dependent

Usage guides