C Extension API

Extension registration

Bundle native components and select them through a sealed context.

Declare a bundle of native components, register it in a context, then select those components explicitly when loading policies and creating sessions. The Extension registration guide executes a document-access frontend, filter and planner in one sealed context.

Handle: context_t

C · handleSince v0.2.0
context_t

#include <maelys/datalog_extension.h>

typedef struct maelys_datalog_context maelys_datalog_context_t;
Reference-counted catalog of native components, populated on one thread and immutable after sealing.

Creation

context_create()

C · functionSince v0.2.0
context_create()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_create(
maelys_datalog_context_t **out_context
);
Create a separate component catalog that can be populated and then sealed.
Outputs

Written on success.

out_contextmaelys_datalog_context_t **out
Receives the caller-owned reference to a new mutable context. Release it with context_free after its callers no longer need it.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with a new mutable context containing the standard filters, Datalog frontend and reference backend. It does not inherit legacy process-global extension registrations; register the additional components before sealing.

Example
maelys_datalog_context_t *created = NULL;
maelys_datalog_status_t status = maelys_datalog_context_create(&created);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("context created: %s\n", created ? "yes" : "no");
check_status(maelys_datalog_context_free(created));
status: ok
context created: yes

Functions

backend_reference()

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

#include <maelys/datalog_extension.h>

const maelys_datalog_backend_t *
maelys_datalog_backend_reference(
void
);
Borrow the built-in snapshot backend descriptor for direct selection or a native bundle.
Return value

const maelys_datalog_backend_t *

Returns a borrowed pointer to the built-in ABI 5 descriptor. Do not free it; the callback code is provided by the loaded SDK.

Example
const maelys_datalog_backend_t *backend = maelys_datalog_backend_reference();
printf("reference available: %s\n", backend ? "yes" : "no");
if (!backend) exit(EXIT_FAILURE);
reference available: yes

backend_reference_v6()

C · functionSince v0.14.0
backend_reference_v6()

#include <maelys/datalog_extension.h>

const maelys_datalog_backend_v6_t *
maelys_datalog_backend_reference_v6(
void
);
Borrow the built-in resource-aware backend descriptor for ABI 6 selection.
Return value

const maelys_datalog_backend_v6_t *

Returns a borrowed pointer to the built-in ABI 6 descriptor. It is a different descriptor type from ABI 5; do not cast between them or free this pointer.

Example
const maelys_datalog_backend_v6_t *backend = maelys_datalog_backend_reference_v6();
printf("reference available: %s\n", backend ? "yes" : "no");
if (!backend) exit(EXIT_FAILURE);
reference available: yes

context_backend_v6_count()

C · functionSince v0.14.0
context_backend_v6_count()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_backend_v6_count(
const maelys_datalog_context_t *context,
size_t *out_count
);
Count the ABI 6 backends in one context catalog.
Arguments
contextconst maelys_datalog_context_t *handleread
Live context whose catalog is used by this operation. Build and register on one thread before sealing; loading and backend selection require the sealed catalog.
Outputs

Written on success.

out_countsize_t *out
Receives the number of entries in the requested context catalog.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with the separate ABI 6 backend count. Invalid context or output pointers return INVALID_ARGUMENT.

Example
size_t count = 0;
maelys_datalog_status_t status = maelys_datalog_context_backend_v6_count(context, &count);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("registered ABI 6 backends: %zu\n", count);
status: ok
registered ABI 6 backends: 0

context_backend_v6_info()

C · functionSince v0.14.0
context_backend_v6_info()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_backend_v6_info(
const maelys_datalog_context_t *context,
size_t index,
maelys_datalog_component_info_t *out_info
);
Read the name and semantic identity of one ABI 6 backend in a context.
Arguments
contextconst maelys_datalog_context_t *handleread
Live context whose catalog is used by this operation. Build and register on one thread before sealing; loading and backend selection require the sealed catalog.
indexsize_tin
Zero-based component index below the count returned for this same context and catalog.
Outputs

Written on success.

out_infomaelys_datalog_component_info_t *out
Receives the component’s name and semantic identity, borrowed from the context; no callback pointers are exposed.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with the ABI 6 backend identity borrowed from the context. An index outside context_backend_v6_count returns NOT_FOUND; invalid context or output pointers return INVALID_ARGUMENT.

Example
maelys_datalog_backend_v6_t named_backend = *maelys_datalog_backend_reference_v6();
named_backend.name = "documents_v6";
named_backend.semantic_id = "example.document-reference.v6";
const maelys_datalog_extension_v2_t bundle_v2 = {
    .abi_version = MAELYS_DATALOG_EXTENSION_V2_ABI_VERSION,
    .struct_size = sizeof(bundle_v2),
    .name = "resource_backend", .semantic_id = "example.resource-backend-bundle.v1",
    .backends_v6 = &named_backend, .backend_v6_count = 1
};
check_status(maelys_datalog_context_register_v2(context, &bundle_v2));
maelys_datalog_component_info_t info;
maelys_datalog_status_t status = maelys_datalog_context_backend_v6_info(context, 0, &info);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("backend: %s\n", info.name);
status: ok
backend: documents_v6

context_component_count()

C · functionSince v0.2.0
context_component_count()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_component_count(
const maelys_datalog_context_t *context,
maelys_datalog_extension_kind_t kind,
size_t *out_count
);
Count the components of one kind in a context; the backend kind selects ABI 5.
Arguments
contextconst maelys_datalog_context_t *handleread
Live context whose catalog is used by this operation. Build and register on one thread before sealing; loading and backend selection require the sealed catalog.
kindmaelys_datalog_extension_kind_tin
Catalog selector from extension_kind_t: frontend, ABI 5 backend, planner or filter. ABI 6 backends use their separate count/info functions.
Outputs

Written on success.

out_countsize_t *out
Receives the number of entries in the requested context catalog.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with the number of components in the requested catalog, including its built-ins. Invalid arguments or an unknown kind return INVALID_ARGUMENT. Use context_backend_v6_count for the separate ABI 6 backend catalog.

Example
size_t count = 0;
maelys_datalog_status_t status = maelys_datalog_context_component_count(
    context, MAELYS_DATALOG_EXTENSION_FRONTEND, &count);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("frontends: %zu\n", count);

context_component_info()

C · functionSince v0.2.0
context_component_info()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_component_info(
const maelys_datalog_context_t *context,
maelys_datalog_extension_kind_t kind,
size_t index,
maelys_datalog_component_info_t *out_info
);
Read the name and semantic identity of one component in a context.
Arguments
contextconst maelys_datalog_context_t *handleread
Live context whose catalog is used by this operation. Build and register on one thread before sealing; loading and backend selection require the sealed catalog.
kindmaelys_datalog_extension_kind_tin
Catalog selector from extension_kind_t: frontend, ABI 5 backend, planner or filter. ABI 6 backends use their separate count/info functions.
indexsize_tin
Zero-based component index below the count returned for this same context and catalog.
Outputs

Written on success.

out_infomaelys_datalog_component_info_t *out
Receives the component’s name and semantic identity, borrowed from the context; no callback pointers are exposed.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with metadata borrowed from the live context, not executable callback pointers. An index outside the count for the same kind returns NOT_FOUND; invalid arguments or an unknown kind return INVALID_ARGUMENT.

Example
size_t count = 0;
check_status(maelys_datalog_context_component_count(context, MAELYS_DATALOG_EXTENSION_FRONTEND, &count));
if (count == 0) exit(EXIT_FAILURE);
maelys_datalog_component_info_t info;
maelys_datalog_status_t status = maelys_datalog_context_component_info(
    context, MAELYS_DATALOG_EXTENSION_FRONTEND, 0, &info);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("frontend: %s\n", info.name);
status: ok
frontend: datalog

context_load_inline()

C · functionSince v0.2.0
context_load_inline()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_load_inline(
maelys_datalog_context_t *context,
const char *frontend_name,
const char *domain,
const char *policy_id,
const char *source,
size_t source_length,
maelys_datalog_policy_t **out_policy,
maelys_datalog_diagnostic_t *out_diagnostic
);
Load inline policy source with an explicitly selected frontend from a sealed context.
Arguments
contextmaelys_datalog_context_t *handlemodified
Sealed component catalog to resolve the selected frontend, filters and planner. The newly loaded policy retains a reference to this context.
frontend_nameconst char *in
Frontend name in this sealed context, or NULL for the built-in Datalog frontend. An unknown non-NULL name is an error.
domainconst char *in
Process-registered domain name used to validate the frontend’s predicates and records; contexts isolate components, not domain registration.
policy_idconst char *in
Application-chosen identity for the inline policy being loaded.
sourceconst char *in
Policy source bytes borrowed only for this load and its lowering callback.
source_lengthsize_tin
Number of source bytes to read, excluding a terminating NUL when the source is a C string.
Outputs

Written on success.

out_policymaelys_datalog_policy_t **out
Receives the loaded policy handle on success. Close it with policy_free; sessions can subsequently retain their own compiled state.

out_diagnostic: optional diagnostic details on failure; pass NULL when not needed.

Return status

maelys_datalog_status_t — OK on success.

Returns OK with a policy lowered by the selected frontend and accepted by core validation. The context must be sealed. A missing frontend fails instead of using another grammar; invalid source, domain or program records are reported through the status and diagnostic.

Example
check_status(maelys_datalog_context_seal(context, NULL));
maelys_datalog_policy_t *loaded = NULL;
maelys_datalog_status_t status = maelys_datalog_context_load_inline(context, NULL,
    "registration_cards", "context-policy", policy_source, strlen(policy_source), &loaded, &diagnostic);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
check_status(maelys_datalog_policy_free(loaded));

context_register()

C · functionSince v0.2.0
context_register()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_register(
maelys_datalog_context_t *context,
const maelys_datalog_extension_t *extension
);
Atomically copy a native bundle’s frontend, ABI 5 backend, filter and planner declarations into a mutable context.
Arguments
contextmaelys_datalog_context_t *handlemodified
Unsealed context whose mutable catalogs receive this bundle atomically. Register on the same thread that builds the context.
extensionconst maelys_datalog_extension_t *in
extension_t (registration ABI 1) bundle descriptor and its declared component arrays. Registration copies identities and descriptors atomically, invokes no callback and loads no library. Keep native callback code loaded while a retained owner can use it.
Return status

maelys_datalog_status_t — OK on success.

Returns OK only after the whole bundle has been copied into the catalog; no callback is executed. A sealed context returns INVALID_STATE. Invalid descriptors return INVALID_ARGUMENT, exhausted catalog capacity returns PAYLOAD_TOO_LARGE, and duplicate identities are rejected without publishing a partial bundle.

Example
maelys_datalog_status_t status = maelys_datalog_context_register(context, &document_components);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);

context_register_v2()

C · functionSince v0.14.0
context_register_v2()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_register_v2(
maelys_datalog_context_t *context,
const maelys_datalog_extension_v2_t *extension
);
Atomically register a bundle that can contain separate ABI 5 and ABI 6 backend arrays.
Arguments
contextmaelys_datalog_context_t *handlemodified
Unsealed context whose mutable catalogs receive this bundle atomically. Register on the same thread that builds the context.
extensionconst maelys_datalog_extension_v2_t *in
extension_v2_t (registration ABI 2) bundle descriptor and its declared component arrays. Registration copies identities and descriptors atomically, invokes no callback and loads no library. Keep native callback code loaded while a retained owner can use it.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after atomically copying the bundle. A sealed context returns INVALID_STATE, an unsupported registration ABI returns UNSUPPORTED, and an incomplete descriptor, invalid component or exhausted capacity fails without partially updating the catalog. Each backend array uses its exact public base type.

Example
maelys_datalog_backend_v6_t named_backend = *maelys_datalog_backend_reference_v6();
named_backend.name = "documents_v6";
named_backend.semantic_id = "example.document-reference.v6";
const maelys_datalog_extension_v2_t bundle_v2 = {
    .abi_version = MAELYS_DATALOG_EXTENSION_V2_ABI_VERSION,
    .struct_size = sizeof(bundle_v2),
    .name = "resource_backend", .semantic_id = "example.resource-backend-bundle.v1",
    .backends_v6 = &named_backend, .backend_v6_count = 1
};
maelys_datalog_status_t status = maelys_datalog_context_register_v2(context, &bundle_v2);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);

context_seal()

C · functionSince v0.2.0
context_seal()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_seal(
maelys_datalog_context_t *context,
const char *planner_name
);
Make a context catalog immutable and choose its rule-body planner.
Arguments
contextmaelys_datalog_context_t *handlemodified
Unsealed context to finalize with the selected planner. Success freezes its catalogs for shared read access.
planner_nameconst char *in
Registered planner name, or NULL to select the reference heuristic. The selected planner is fixed when the context is sealed.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after choosing the reference planner for NULL, or the registered planner with the given name, and sealing the catalog. An unknown selection fails; component names are explicit choices rather than fallback hints.

Example
maelys_datalog_status_t status = maelys_datalog_context_seal(context, NULL);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);

context_session_create()

C · functionSince v0.2.0
context_session_create()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_session_create(
maelys_datalog_context_t *context,
const maelys_datalog_policy_t *policy,
size_t policy_index,
const char *backend_name,
uint64_t required_capabilities,
uint64_t work_limit,
maelys_datalog_session_t **out_session
);
Create a session with an explicitly selected ABI 5 backend from the policy’s context.
Arguments
contextmaelys_datalog_context_t *handlemodified
Sealed catalog used to select this session’s ABI 5 backend. The created session retains its context reference.
policyconst maelys_datalog_policy_t *in
Live loaded policy supplying the compiled policy selected by policy_index.
policy_indexsize_tin
Zero-based index within the loaded policy set; use zero for the single-policy inline example.
backend_nameconst char *in
Backend name in the selected sealed context, or NULL for that backend catalog’s reference provider. An unknown non-NULL name is an error.
required_capabilitiesuint64_tin
Additional capability bits required of the chosen backend, in addition to the compiled policy’s requirements.
work_limituint64_tin
Backend work budget; zero selects the default 1,048,576 units. A nonzero value requires WORK_LIMIT support; these units do not measure elapsed time.
Outputs

Written on success.

out_sessionmaelys_datalog_session_t **out
Receives the new session handle on success. Release its live results and explanations before session_free.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with a session that retains the policy’s context. The context must be sealed and must be the one used to compile the policy. An unknown backend, unsupported capability, invalid policy index or failed backend preparation returns an error instead of falling back. This convenience call supplies no backend state buffer.

Example
check_status(maelys_datalog_context_seal(context, NULL));
maelys_datalog_policy_t *context_policy = NULL;
check_status(maelys_datalog_context_load_inline(context, NULL, "registration_cards", "context-policy",
    policy_source, strlen(policy_source), &context_policy, &diagnostic));
maelys_datalog_session_t *created = NULL;
maelys_datalog_status_t status = maelys_datalog_context_session_create(
    context, context_policy, 0, NULL, 0, 0, &created);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
check_status(maelys_datalog_session_free(created));
check_status(maelys_datalog_policy_free(context_policy));

frontend_datalog()

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

#include <maelys/datalog_extension.h>

const maelys_datalog_frontend_t *
maelys_datalog_frontend_datalog(
void
);
Borrow the built-in Datalog frontend descriptor for an explicitly selected load.
Return value

const maelys_datalog_frontend_t *

Returns a borrowed pointer to the built-in Datalog frontend descriptor. Do not free it or retain callback arguments supplied during a load.

Example
const maelys_datalog_frontend_t *frontend = maelys_datalog_frontend_datalog();
if (!frontend) exit(EXIT_FAILURE);
printf("frontend: %s\n", frontend->name);

Release

context_free()

C · functionSince v0.2.0
context_free()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_context_free(
maelys_datalog_context_t *context
);
Release the caller’s context reference while existing policies and sessions retain theirs.
Arguments
contextmaelys_datalog_context_t *handlereleased
Caller-owned context reference to release. Policies and sessions retain their own references; do not use this caller handle again after success.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after dropping the caller’s context reference. Already-created policies and sessions retain their own references. No longer use the released caller handle.

Example
maelys_datalog_status_t status = maelys_datalog_context_free(context);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
context = NULL;

Constants

Catalog limits

CONTEXT_MAX_EXTENSIONS

C · constantSince v0.2.0
CONTEXT_MAX_EXTENSIONS
#define MAELYS_DATALOG_CONTEXT_MAX_EXTENSIONS 16u

Maximum number of native bundles registered in one context.

Value

16

CONTEXT_MAX_COMPONENTS

C · constantSince v0.2.0
CONTEXT_MAX_COMPONENTS
#define MAELYS_DATALOG_CONTEXT_MAX_COMPONENTS 16u

Maximum entries in each context frontend, backend or planner catalog; filter capacity is governed separately.

Value

16

Handle: policy_t ↗

Creation

policy_load_frontend()

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

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_policy_load_frontend(
const char *domain,
const char *policy_id,
const char *source,
size_t source_length,
const maelys_datalog_frontend_t *frontend,
maelys_datalog_policy_t **out_policy,
maelys_datalog_diagnostic_t *out_diagnostic
);
Load inline policy source with one frontend descriptor selected directly by the caller.
Arguments
domainconst char *in
Process-registered domain name used to validate the frontend’s predicates and records; contexts isolate components, not domain registration.
policy_idconst char *in
Application-chosen identity for the inline policy being loaded.
sourceconst char *in
Policy source bytes borrowed only for this load and its lowering callback.
source_lengthsize_tin
Number of source bytes to read, excluding a terminating NUL when the source is a C string.
frontendconst maelys_datalog_frontend_t *in
Frontend descriptor selected for this load, with the current program ABI, exact structure size, identities and lowering callback.
Outputs

Written on success.

out_policymaelys_datalog_policy_t **out
Receives the loaded policy handle on success. Close it with policy_free; sessions can subsequently retain their own compiled state.

out_diagnostic: optional diagnostic details on failure; pass NULL when not needed.

Return status

maelys_datalog_status_t — OK on success.

Returns OK with a policy after the selected callback lowers the source and the core validates the resulting records. The selection is local to this load, not a mutable global grammar. Frontends must not retain source or builder pointers or reenter loading; a lowering or validation failure rejects the load.

Example
maelys_datalog_policy_t *loaded = NULL;
maelys_datalog_status_t status = maelys_datalog_policy_load_frontend("registration_cards",
    "selected-frontend", policy_source, strlen(policy_source), maelys_datalog_frontend_datalog(), &loaded, &diagnostic);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
check_status(maelys_datalog_policy_free(loaded));

policy_load_frontend_in()

C · functionSince v0.10.0
policy_load_frontend_in()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_policy_load_frontend_in(
void *storage,
size_t storage_bytes,
const char *domain,
const char *policy_id,
const char *source,
size_t source_length,
const maelys_datalog_frontend_t *frontend,
maelys_datalog_policy_t **out_policy,
maelys_datalog_diagnostic_t *out_diagnostic
);
Load inline policy source through a selected frontend into caller-owned policy storage.
Arguments
storagevoid *in/out
Caller-owned policy arena, correctly aligned and large enough according to policy_storage_requirements; keep it alive until the policy is closed.
storage_bytessize_tin
Available size of the caller-owned policy arena, at least the measured policy storage requirement.
domainconst char *in
Process-registered domain name used to validate the frontend’s predicates and records; contexts isolate components, not domain registration.
policy_idconst char *in
Application-chosen identity for the inline policy being loaded.
sourceconst char *in
Policy source bytes borrowed only for this load and its lowering callback.
source_lengthsize_tin
Number of source bytes to read, excluding a terminating NUL when the source is a C string.
frontendconst maelys_datalog_frontend_t *in
Frontend descriptor selected for this load, with the current program ABI, exact structure size, identities and lowering callback.
Outputs

Written on success.

out_policymaelys_datalog_policy_t **out
Receives the loaded policy handle on success. Close it with policy_free; sessions can subsequently retain their own compiled state.

out_diagnostic: optional diagnostic details on failure; pass NULL when not needed.

Return status

maelys_datalog_status_t — OK on success.

Returns OK with a policy in the supplied arena after frontend lowering and core validation. Measure the arena with policy_storage_requirements and keep it aligned, immovable and alive until policy_free closes the policy; policy_free does not free the arena. Loader and callback allocations remain separate from this caller-owned policy object.

Example
size_t bytes = 0, alignment = 0;
check_status(maelys_datalog_policy_storage_requirements(&bytes, &alignment));
void *arena = allocate_policy_storage(bytes, alignment);
maelys_datalog_policy_t *loaded = NULL;
maelys_datalog_status_t status = maelys_datalog_policy_load_frontend_in(arena, bytes,
    "registration_cards", "caller-owned-policy", policy_source, strlen(policy_source),
    maelys_datalog_frontend_datalog(), &loaded, &diagnostic);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
check_status(maelys_datalog_policy_free(loaded));
free(arena);

Functions

Documented on Rulesets.

  • policy_count() ↗ — Reads how many policies belong to a loaded set, so the application can choose a valid policy index when creating a session.
  • policy_fingerprint() ↗ — Reads the identity of the complete loaded policy set. Use it to distinguish policy sets, rather than the execution configuration of a session.
  • policy_id() ↗ — 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_reads_predicate() ↗ — 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.
  • policy_stat_get() ↗ — Read a selected policy's compiled predicate, policy-fact or normalized-rule count without preparing a session.

Release

Documented on Rulesets.

  • policy_free() ↗ — Releases a loaded policy-set handle when the application no longer needs it for creating sessions.

Handle: session_t ↗

Creation

backend_storage_requirements()

C · functionSince v0.11.0
backend_storage_requirements()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_backend_storage_requirements(
const maelys_datalog_policy_t *policy,
size_t policy_index,
const maelys_datalog_backend_t *backend,
size_t *out_bytes,
size_t *out_alignment
);
Measure the caller-owned backend state storage needed by one policy and backend.
Arguments
policyconst maelys_datalog_policy_t *in
Live loaded policy supplying the compiled policy selected by policy_index.
policy_indexsize_tin
Zero-based index within the loaded policy set; use zero for the single-policy inline example.
backendconst maelys_datalog_backend_t *in
ABI 5 descriptor, or NULL for the reference backend. It must satisfy the selected policy and capability requirements.
Outputs

Written on success.

out_bytessize_t *out
Receives the required size of caller-owned backend state storage, in bytes; zero is valid.
out_alignmentsize_t *out
Receives the required nonzero power-of-two storage alignment.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with deterministic byte and alignment requirements for this policy and backend. It allocates nothing and leaves both outputs unchanged on failure. Zero bytes is valid; alignment is a nonzero power of two. The requirements are checked again at session creation.

Example
size_t bytes = 0, alignment = 0;
maelys_datalog_status_t status = maelys_datalog_backend_storage_requirements(
    policy, 0, maelys_datalog_backend_reference(), &bytes, &alignment);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("external storage required: %s\n", bytes ? "yes" : "no");
printf("alignment valid: %s\n", alignment && !(alignment & (alignment - 1)) ? "yes" : "no");
status: ok
external storage required: no
alignment valid: yes

session_create_ex()

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

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_session_create_ex(
const maelys_datalog_policy_t *policy,
size_t policy_index,
const maelys_datalog_session_options_t *options,
maelys_datalog_session_t **out_session
);
Create a session with a direct ABI 5 backend, minimum capabilities and work budget.
Arguments
policyconst maelys_datalog_policy_t *in
Live loaded policy supplying the compiled policy selected by policy_index.
policy_indexsize_tin
Zero-based index within the loaded policy set; use zero for the single-policy inline example.
optionsconst maelys_datalog_session_options_t *in
ABI 5 session options with abi_version set to BACKEND_ABI_VERSION and struct_size set to sizeof the descriptor. NULL selects ordinary reference defaults.
Outputs

Written on success.

out_sessionmaelys_datalog_session_t **out
Receives the new session handle on success. Release its live results and explanations before session_free.
Return status

maelys_datalog_status_t — OK on success.

Returns OK with a session using the chosen ABI 5 descriptor, or the reference descriptor for a NULL backend or options pointer. Policy-required and caller-required capabilities are checked before preparation; a nonzero work limit additionally requires WORK_LIMIT. The options use BACKEND_ABI_VERSION and their exact structure size. No caller-owned backend buffer is supplied by this convenience call.

Example
const maelys_datalog_session_options_t options = {
    .abi_version = MAELYS_DATALOG_BACKEND_ABI_VERSION,
    .struct_size = sizeof(options), .backend = maelys_datalog_backend_reference(),
    .required_capabilities = MAELYS_DATALOG_CAP_NEGATION, .work_limit = 0
};
maelys_datalog_session_t *created = NULL;
maelys_datalog_status_t status = maelys_datalog_session_create_ex(policy, 0, &options, &created);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
check_status(maelys_datalog_session_free(created));

Functions

Documented on Solving, Session resources.

  • session_execution_fingerprint() ↗ — Reads the combined identity of the selected policy and its execution configuration, for distinguishing how a policy is evaluated.
  • session_fingerprint() ↗ — Reads the policy identity selected by this session, independently of its execution configuration.
  • session_get_allocation_stats() ↗ — 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() ↗ — Reads the normalized resource capacities of a session. The output reports admitted capacities, not unresolved defaults or presence sentinels.
  • session_solve() ↗ — Evaluates the selected policy against a fact array supplied by the application, without requiring an input EDB handle.
  • session_solve_edb() ↗ — 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.

Release

Documented on Solving.

  • session_free() ↗ — Releases a prepared session once its live result has been released.

Handle: session_config_t ↗

Functions

session_config_set_backend()

C · functionSince v0.10.0
session_config_set_backend()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_session_config_set_backend(
maelys_datalog_session_config_t *config,
const maelys_datalog_backend_t *backend
);
Select a direct ABI 5 backend for sessions created from this configuration.
Arguments
configmaelys_datalog_session_config_t *handlemodified
Live session configuration to update. Creating a session consumes the selected configuration values; callback code and borrowed storage must remain valid for their required lifetimes.
backendconst maelys_datalog_backend_t *in
ABI 5 descriptor, or NULL for the reference backend. It must satisfy the selected policy and capability requirements.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after selecting and copying the ABI 5 descriptor and identities. NULL restores ordinary reference configuration. This direct selection clears a context selection; callback code must outlive every session that uses it. Invalid descriptors fail before replacing the configuration.

Example
maelys_datalog_status_t status = maelys_datalog_session_config_set_backend(config, maelys_datalog_backend_reference());
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);

session_config_set_backend_storage()

C · functionSince v0.11.0
session_config_set_backend_storage()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_session_config_set_backend_storage(
maelys_datalog_session_config_t *config,
const maelys_datalog_backend_storage_t *storage
);
Attach caller-owned state storage for the backend selected by this configuration.
Arguments
configmaelys_datalog_session_config_t *handlemodified
Live session configuration to update. Creating a session consumes the selected configuration values; callback code and borrowed storage must remain valid for their required lifetimes.
storageconst maelys_datalog_backend_storage_t *in
Backend storage descriptor containing its structure size, caller-owned buffer, byte count and alignment. NULL clears the attachment; the buffer remains owned by the caller.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after copying the storage descriptor, while borrowing its buffer; NULL clears the attachment. The buffer must be disjoint from other live storage and remain valid through session destruction. Backend or context selection does not clear this attachment. Session creation rejects insufficient size or alignment before calling prepare, without implicit allocation or fallback.

Example
size_t bytes = 0, alignment = 0;
check_status(maelys_datalog_backend_storage_requirements(
    policy, 0, maelys_datalog_backend_reference(), &bytes, &alignment));
void *arena = bytes ? allocate_policy_storage(bytes, alignment) : NULL;
const maelys_datalog_backend_storage_t storage = {
    sizeof(storage), arena, bytes, alignment
};
maelys_datalog_status_t status = maelys_datalog_session_config_set_backend_storage(config, &storage);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
/* Release the configuration before its caller-owned storage. */
check_status(maelys_datalog_session_config_free(config));
config = NULL;
free(arena);

session_config_set_backend_v6()

C · functionSince v0.14.0
session_config_set_backend_v6()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_session_config_set_backend_v6(
maelys_datalog_session_config_t *config,
const maelys_datalog_backend_v6_t *backend
);
Select a direct ABI 6 backend with the resource contract for sessions created from this configuration.
Arguments
configmaelys_datalog_session_config_t *handlemodified
Live session configuration to update. Creating a session consumes the selected configuration values; callback code and borrowed storage must remain valid for their required lifetimes.
backendconst maelys_datalog_backend_v6_t *in
Independent ABI 6 descriptor, such as backend_reference_v6(); do not cast an ABI 5 or ABI 7 descriptor.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after selecting the independent ABI 6 descriptor. Its complete resource-aware descriptor and supported resource features are required; do not cast an ABI 5 or ABI 7 descriptor. An invalid selection fails rather than silently choosing another backend.

Example
maelys_datalog_status_t status = maelys_datalog_session_config_set_backend_v6(config, maelys_datalog_backend_reference_v6());
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);

session_config_set_backend_v7()

C · functionSince v0.16.0
session_config_set_backend_v7()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_session_config_set_backend_v7(
maelys_datalog_session_config_t *config,
const maelys_datalog_backend_v7_t *backend
);
Select a direct ABI 7 retained-input backend, or clear that selection with NULL.
Arguments
configmaelys_datalog_session_config_t *handlemodified
Live session configuration to update. Creating a session consumes the selected configuration values; callback code and borrowed storage must remain valid for their required lifetimes.
backendconst maelys_datalog_backend_v7_t *in
ABI 7 retained-input descriptor, or NULL to restore ordinary reference configuration. There is no ABI 7 context registry in this release.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after copying a valid ABI 7 descriptor and identities; NULL restores ordinary reference configuration. Unsupported ABI versions return UNSUPPORTED; short descriptors or missing callbacks return INVALID_ARGUMENT without modifying the configuration. Before solving, attach retained inputs: ordinary session_solve is refused. v0.26 has no ABI 7 extension registry.

Example
/* NULL clears the retained-input backend selection. */
maelys_datalog_status_t status = maelys_datalog_session_config_set_backend_v7(config, NULL);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);

session_config_set_context()

C · functionSince v0.10.0
session_config_set_context()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_session_config_set_context(
maelys_datalog_session_config_t *config,
maelys_datalog_context_t *context,
const char *backend_name
);
Select a named ABI 5 backend in a sealed context and retain that context in the configuration.
Arguments
configmaelys_datalog_session_config_t *handlemodified
Live session configuration to update. Creating a session consumes the selected configuration values; callback code and borrowed storage must remain valid for their required lifetimes.
contextmaelys_datalog_context_t *in
Sealed catalog retained by this configuration for later ABI 5 backend lookup. The policy used to create a session must have been compiled in this same context.
backend_nameconst char *in
Backend name in the selected sealed context, or NULL for that backend catalog’s reference provider. An unknown non-NULL name is an error.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after retaining the sealed context and selecting its named ABI 5 backend; NULL backend_name selects its reference backend. Policies used with this configuration must have been compiled in that same context. A missing component fails; a later direct backend selection clears this context selection.

Example
check_status(maelys_datalog_context_seal(context, NULL));
maelys_datalog_status_t status = maelys_datalog_session_config_set_context(config, context, NULL);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);

session_config_set_context_backend_v6()

C · functionSince v0.14.0
session_config_set_context_backend_v6()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_session_config_set_context_backend_v6(
maelys_datalog_session_config_t *config,
maelys_datalog_context_t *context,
const char *backend_name
);
Select a named ABI 6 backend in a sealed context for later session creation.
Arguments
configmaelys_datalog_session_config_t *handlemodified
Live session configuration to update. Creating a session consumes the selected configuration values; callback code and borrowed storage must remain valid for their required lifetimes.
contextmaelys_datalog_context_t *in
Sealed catalog retained by this configuration for later ABI 6 backend lookup. The policy used to create a session must have been compiled in this same context.
backend_nameconst char *in
Backend name in the selected sealed context, or NULL for that backend catalog’s reference provider. An unknown non-NULL name is an error.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after retaining the sealed context and selecting the named ABI 6 backend; NULL backend_name selects its ABI 6 reference. The policy must come from the same context, and an unknown name is an error rather than a fallback selection.

Example
maelys_datalog_backend_v6_t named_backend = *maelys_datalog_backend_reference_v6();
named_backend.name = "documents_v6";
named_backend.semantic_id = "example.document-reference.v6";
const maelys_datalog_extension_v2_t bundle_v2 = {
    .abi_version = MAELYS_DATALOG_EXTENSION_V2_ABI_VERSION,
    .struct_size = sizeof(bundle_v2),
    .name = "resource_backend", .semantic_id = "example.resource-backend-bundle.v1",
    .backends_v6 = &named_backend, .backend_v6_count = 1
};
check_status(maelys_datalog_context_register_v2(context, &bundle_v2));
check_status(maelys_datalog_context_seal(context, NULL));
maelys_datalog_status_t status = maelys_datalog_session_config_set_context_backend_v6(
    config, context, named_backend.name);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);

session_config_set_requirements()

C · functionSince v0.10.0
session_config_set_requirements()

#include <maelys/datalog_extension.h>

maelys_datalog_status_t
maelys_datalog_session_config_set_requirements(
maelys_datalog_session_config_t *config,
uint64_t capabilities,
uint64_t work_limit
);
Set the additional required capabilities and backend work budget for session creation.
Arguments
configmaelys_datalog_session_config_t *handlemodified
Live session configuration to update. Creating a session consumes the selected configuration values; callback code and borrowed storage must remain valid for their required lifetimes.
capabilitiesuint64_tin
Additional CAP_* bits required at session creation; unknown bits are rejected.
work_limituint64_tin
Backend work budget; zero selects the default 1,048,576 units. A nonzero value requires WORK_LIMIT support; these units do not measure elapsed time.
Return status

maelys_datalog_status_t — OK on success.

Returns OK after storing the required capability mask and work limit. Unknown capability bits return INVALID_ARGUMENT. These requirements are enforced at session creation; a nonzero work limit also requires WORK_LIMIT support. Work units are backend-specific, not a wall-clock timeout or sandbox.

Example
maelys_datalog_status_t status = maelys_datalog_session_config_set_requirements(
    config, MAELYS_DATALOG_CAP_NEGATION, 0);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);

Release

Documented on Solving.

  • session_config_free() ↗ — Releases a configuration after its values have been copied into any created sessions.

Struct: extension_t

C · structSince v0.2.0
extension_t

#include <maelys/datalog_extension.h>

ABI 1 bundle declaration containing frontends, ABI 5 backends, planners and filters; registration copies the declaration without running callbacks.
Fields
abi_versionuint32_t
Set to MAELYS_DATALOG_EXTENSION_ABI_VERSION for this bundle descriptor; this is separate from every component ABI.
struct_sizesize_t
Set to sizeof this installed descriptor; registration validates its layout.
nameconst char *
Bundle selection name copied by registration.
semantic_idconst char *
Bundle semantic identity copied by registration; use a stable identity for its meaning.
frontendsconst maelys_datalog_frontend_t *
Array of frontend descriptors, or NULL when frontend_count is zero. These components use PROGRAM_ABI_VERSION, independently of the bundle ABI.
frontend_countsize_t
Number of entries in the frontends array.
backendsconst maelys_datalog_backend_t *
Array of ABI 5 backend descriptors, or NULL when backend_count is zero.
backend_countsize_t
Number of entries in the ABI 5 backends array.
plannersconst maelys_datalog_planner_module_t *
Array of native planner descriptors, or NULL when planner_count is zero.
planner_countsize_t
Number of entries in the planners array.
filtersconst maelys_datalog_filter_module_t *
Array of native filter descriptors, or NULL when filter_count is zero.
filter_countsize_t
Number of entries in the filters array.
Typedef
typedef struct {
    uint32_t abi_version;
    size_t struct_size;
    const char *name;
    const char *semantic_id;
    const maelys_datalog_frontend_t *frontends;
    size_t frontend_count;
    const maelys_datalog_backend_t *backends;
    size_t backend_count;
    const maelys_datalog_planner_module_t *planners;
    size_t planner_count;
    const maelys_datalog_filter_module_t *filters;
    size_t filter_count;
} maelys_datalog_extension_t;

Constants

Registration ABI

EXTENSION_ABI_VERSION

C · constantSince v0.2.0
EXTENSION_ABI_VERSION
#define MAELYS_DATALOG_EXTENSION_ABI_VERSION 1u

Registration ABI used by extension_t; component descriptors have their own independent ABI versions.

Value

1

Struct: extension_v2_t

C · structSince v0.14.0
extension_v2_t

#include <maelys/datalog_extension.h>

ABI 2 bundle declaration with independent ABI 5 and ABI 6 backend arrays; other component contracts keep their own ABIs.
Fields
abi_versionuint32_t
Set to MAELYS_DATALOG_EXTENSION_V2_ABI_VERSION for this bundle descriptor; this is separate from every component ABI.
struct_sizesize_t
Set to sizeof this installed descriptor; registration validates its layout.
nameconst char *
Bundle selection name copied by registration.
semantic_idconst char *
Bundle semantic identity copied by registration; use a stable identity for its meaning.
frontendsconst maelys_datalog_frontend_t *
Array of frontend descriptors, or NULL when frontend_count is zero. These components use PROGRAM_ABI_VERSION, independently of the bundle ABI.
frontend_countsize_t
Number of entries in the frontends array.
backends_v5const maelys_datalog_backend_t *
Array with exact maelys_datalog_backend_t strides; do not cast ABI 6 or ABI 7 descriptors into this array.
backend_v5_countsize_t
Number of entries in backends_v5.
backends_v6const maelys_datalog_backend_v6_t *
Array with exact maelys_datalog_backend_v6_t strides; ABI 6 has its own resource-aware descriptor.
backend_v6_countsize_t
Number of entries in backends_v6. This registry does not register ABI 7 backends.
plannersconst maelys_datalog_planner_module_t *
Array of native planner descriptors, or NULL when planner_count is zero.
planner_countsize_t
Number of entries in the planners array.
filtersconst maelys_datalog_filter_module_t *
Array of native filter descriptors, or NULL when filter_count is zero.
filter_countsize_t
Number of entries in the filters array.
Typedef
typedef struct {
    uint32_t abi_version;
    size_t struct_size;
    const char *name;
    const char *semantic_id;
    const maelys_datalog_frontend_t *frontends;
    size_t frontend_count;
    const maelys_datalog_backend_t *backends_v5;
    size_t backend_v5_count;
    const maelys_datalog_backend_v6_t *backends_v6;
    size_t backend_v6_count;
    const maelys_datalog_planner_module_t *planners;
    size_t planner_count;
    const maelys_datalog_filter_module_t *filters;
    size_t filter_count;
} maelys_datalog_extension_v2_t;

Constants

Registration ABI

EXTENSION_V2_ABI_VERSION

C · constantSince v0.14.0
EXTENSION_V2_ABI_VERSION
#define MAELYS_DATALOG_EXTENSION_V2_ABI_VERSION 2u

Registration ABI used by extension_v2_t, including its separate ABI 5 and ABI 6 backend arrays.

Value

2

Enum: extension_kind_t

C · enumSince v0.2.0
extension_kind_t

#include <maelys/datalog_extension.h>

Selects a context component catalog for metadata enumeration.
Members
EXTENSION_FRONTEND1
Select the context’s frontend catalog.
EXTENSION_BACKEND2
Select its ABI 5 backend catalog; ABI 6 backends have separate accessors.
EXTENSION_PLANNER3
Select its join-planner catalog.
EXTENSION_FILTER4
Select its native filter catalog.
Typedef
typedef enum {
    MAELYS_DATALOG_EXTENSION_FRONTEND = 1,
    MAELYS_DATALOG_EXTENSION_BACKEND,
    MAELYS_DATALOG_EXTENSION_PLANNER,
    MAELYS_DATALOG_EXTENSION_FILTER
} maelys_datalog_extension_kind_t;

Struct: component_info_t

C · structSince v0.2.0
component_info_t

#include <maelys/datalog_extension.h>

Borrowed component name and semantic identity returned by a context metadata accessor.
Fields
nameconst char *
Component selection name borrowed from the live context.
semantic_idconst char *
Stable semantic identity borrowed from the live context; this is metadata, not a callback pointer.
Typedef
typedef struct {
    const char *name;
    const char *semantic_id;
} maelys_datalog_component_info_t;

Struct: session_options_t

C · structSince v0.1.0-alpha.4
session_options_t

#include <maelys/datalog_extension.h>

Direct ABI 5 session selection, additional capabilities and cooperative work budget.
Fields
abi_versionuint32_t
Set to MAELYS_DATALOG_BACKEND_ABI_VERSION, as required by session_create_ex; this selects the ABI 5 options contract.
struct_sizesize_t
Set to sizeof(maelys_datalog_session_options_t) for this installed SDK.
backendconst maelys_datalog_backend_t *
Direct ABI 5 descriptor, or NULL for the built-in reference backend. The descriptor is copied; callback code must remain loaded.
required_capabilitiesuint64_t
Additional CAP_* requirements to combine with those computed from the compiled policy.
work_limituint64_t
Zero selects 1,048,576 backend work units; a nonzero value also requires WORK_LIMIT support.
Typedef
typedef struct {
    uint32_t abi_version;
    size_t struct_size;
    const maelys_datalog_backend_t *backend; /* NULL selects the reference. */
    uint64_t required_capabilities;
    /* Zero selects 1,048,576 host work units. Nonzero requires WORK_LIMIT. */
    uint64_t work_limit;
} maelys_datalog_session_options_t;

Usage guides