Constant-space strategy constspace#

Not in this edition. Every clause in this document is deferred or retired, so nothing here binds a 1.0 implementation. It is kept so that its ids and the references to them resolve.

The constspace strategy capability. A program compiled constspace runs a slab-pool / pre-sized-arena allocator, makes no WCET claim, requires no .dsrt contract, and remains compatible with AOT CompiledCode atoms.

Prefix LCSP.

Paired with:

  • [LDIA] — the use mechanism and extension token surface this extends.

  • [RTCT] — the stricter sibling. realtime ⊃ constspace (every realtime program is also constspace).

  • [RAOT] — the no-CompiledCode-atoms-under-realtime gate does not apply to constspace.

What this is not#

  • Not a WCET claim. Pump time is unbounded under constspace alone; the T_wcet formula (LDTL.7) does not apply.

  • Not a guarantee of zero allocation ever — the engine allocates pools at boot (engine creation, then pool sizing). The guarantee is no allocation on the hot path (assert / pump / fire).

  • Not a replacement for realtime. Use realtime when WCET matters.

  • Not a contract carrier — constspace programs MUST NOT ship a .dsrt file (per [LCSP.4.2]).


The bounded-memory split [LCSP.1]#

Deferred: not binding in this edition.

[LCSP.1.1] constspace is the bounded-memory capability: a slab-pool allocator, a bounded working memory, agenda, token pool, intern table and cache, and no allocation on the hot path ([LCSP.2]).

see also: LCSP.2

[LCSP.1.2] constspace makes no claim about execution time: it carries no WCET bound, no INIT/LIVE lifecycle and no contract file, and it permits AOT code atoms.

[LCSP.1.3] The factoring is strict: realtime ⊃ constspace. Every realtime program is also constspace by construction. A dialect resolver MAY infer constspace from realtime; it MAY also leave the inference to the runtime (treating the flags as independent CapabilityInfo tags). The reference compiler treats them as independent (no auto-promotion) per [LCSP.5.4].


see also: LCSP.5.4

What constspace guarantees [LCSP.2]#

Deferred: not binding in this edition.

[LCSP.2.1] No allocation on the hot path. Assert, pump, and fire operations do not call malloc, calloc, realloc, or any other unbounded allocator. All working memory comes from pools sized at boot.

The guarantee is over those pools. Three paths sit outside it and are qualified where they arise, not here: the string-intern table, which constspace cannot freeze because it has no go_live to freeze at ([LCSP.3.5]); series identity cardinality, which the event trace drives and nothing caps ([LCSP.3.6]); and a String-typed series, whose backing copies every absorbed sample — which is why that one is rejected outright ([LCSP.4.5]).

see also: LCSP.3.5, LCSP.3.6, LCSP.4.5

[LCSP.2.2] Bounded steady-state memory. Total memory consumption after the integrator sizes the pools is a function of the supplied caps (WM, agenda, token pool, intern, intern bytes, cache keys + bytes) and the DSC's schema/rule structure. No runtime growth. The cache is engine state ([LSTO.4.7]); it joins the slab budget like the other pools, so a bounded-memory program bounds it too. Its caps come from the integrator's boot-time pool sizing, like the other caps ([LCSP.3.4]).

see also: LCSP.3.4, LSTO.4.7

[LCSP.2.3] Pool exhaustion is observable. When a pool fills:

  • An assert returns a non-OK status to the caller.

  • A pump-time pool exhaustion (e.g., agenda full mid-firing) drops the affected firing and surfaces a warning through the log callback. The engine does not crash or undefined-behave on pool exhaustion.

[LCSP.2.4] AOT is permitted. CompiledCode atoms targeting the host architecture load and execute under constspace. The AOT gate that forbids CompiledCode atoms under realtime (RAOT) is keyed on the realtime capability specifically, not on the underlying allocator mode.


What constspace does NOT guarantee [LCSP.3]#

Deferred: not binding in this edition.

[LCSP.3.1] No WCET claim. Pump time is unbounded; expression evaluation depth, RHS action sequence length, and series-backend behaviour are not WCET-bounded under constspace alone. Programs needing a per-pump time bound must use realtime.

[LCSP.3.2] No per-node capacity contract. realtime reads per-node capacities from .dsrt ([[contract.node]] blocks); constspace does not. All nodes draw from the integrator's global pool budgets.

[LCSP.3.3] No LIVE-state lifecycle. The INIT → LIVE lifecycle and go_live precondition apply only to realtime. A constspace engine pumps as soon as schemas and rules are loaded.

[LCSP.3.4] No .dsrt file. A constspace compile MUST NOT emit a RealtimeContract atom (per [LCSP.4.2]), and the runtime MUST reject a DSC carrying both constspace and a RealtimeContract atom (per [LCSP.6.4]).


see also: LCSP.4.2, LCSP.6.4

[LCSP.3.5] No intern-table lock. constspace does not freeze the string-intern table, and does not inherit the freeze realtime gets ([RTCT.12.4]). The lock is not a policy constspace declines — it has nowhere to attach. Freezing needs a phase boundary after which no new string may appear, and that boundary is go_live, which a constspace-only engine never calls ([LCSP.6.5]).

What follows, stated plainly because it qualifies [LCSP.2.1]: a novel string arriving as a slot value on an asserted fact interns at pump time, and interning a string not already in the table may grow it. So "no allocation on the hot path" holds for the pools [LCSP.2.1] names, and does not hold for the intern table when the event trace carries strings the DSC never saw.

An author who needs the stronger property takes realtime, where go_live supplies the boundary and interning returns DS_ERR_OOM rather than growing. A deployment that stays on constspace bounds its string vocabulary by what it asserts — which is an integrator obligation, not something the compiler checks.

[LNLS.3.2] is unaffected and still applies: it is a compile-time check on strings a rule produces (an interpolated string), which is a different population from strings a fact carries in.

see also: LCSP.2.1, LCSP.6.5, LNLS.3.2, RTCT.12.4

[LCSP.3.6] No bound on series identity cardinality. A series declared by: an identity slot keeps per-identity state, and the engine creates that state on first sight of an identity — at pump time. An event trace carrying an unbounded number of distinct identities grows the series registry without bound. constspace does not cap this and does not fail on it.

The integrator bounds it, by bounding what it asserts. This is the same division as [LCSP.3.5] and the same as [LCSP.7], where the integrator sizes the pools: constspace bounds the structures it declares, and the event trace is not one of them.

see also: LCSP.3.5, LCSP.7

Compile-time obligations [LCSP.4]#

Deferred: not binding in this edition.

[LCSP.4.1] Validation subset. The compiler runs the same bounded-memory validation pass as realtime on constspace programs. This covers the LNLS.3 subset that gates against unbounded allocation:

  • LNLS.3.2 — novel strings a rule PRODUCES (an interpolated string). Note this does not lock the intern table under constspace, which has no phase boundary to lock at ([LCSP.3.5]); strings arriving on asserted facts are a different population and are not gated.

  • LNLS.3.5 — sketch backends (v1 ships none)

  • LNLS.3.7 — regex without capacity

  • LNLS.3.8 — string ordering in cross-pattern position

  • LNLS.3.9 — JSON_PATH (unbounded allocation)

  • LNLS.3.11 — series scan without a sample cap

The same constraints apply for the same reason: each violates "steady-state allocation is zero" if permitted at pump time. The reference compiler reuses _check_realtime for constspace.

This subset is not the whole of the constspace check. linear_scan: false excludes features for their algorithmic shape, and the overlap with bounded memory is real but partial: an obligation that is purely about allocation has no LNLS.3 clause to correspond to, because a per-sample copy is O(1) and linear_scan: false has no objection to it. [LCSP.4.5] is such an obligation, and a validator that runs only the list above misses it.

see also: LCSP.3.5, LCSP.4.5, LNLS.3, LNLS.3.11, LNLS.3.2, LNLS.3.5, LNLS.3.7, LNLS.3.8, LNLS.3.9

[LCSP.4.2] No RealtimeContract. The compiler MUST NOT emit a RealtimeContract atom for a constspace-only program (no realtime). The RealtimeContract contract is WCET-specific; emitting it under constspace is a category error.

[LCSP.4.3] CapabilityInfo tag. The compiler emits constspace in the CapabilityInfo atom's active_extensions list whenever the resolved dialect selects constspace. realtime and constspace MAY both appear when the resolved dialect selects both.

[LCSP.4.4] AOT compatibility. The AOT pipeline (RAOT) emits CompiledCode atoms for constspace programs subject to the existing per-architecture toolchain availability. The AOT gate checks for realtime specifically.


[LCSP.4.5] String-typed series are rejected. A series declared over a String-typed slot, on any backing that stores raw sample values, is a compile error under constspace (DS_VALIDATE_RT_STRING_SERIES).

The reason is the absorb path, not the window. A value-storing backing owns its samples and copies each one on absorb, so a String element type allocates per absorbed sample, at pump time, for the life of the series — and frees on eviction. That is a steady-state allocation, which is the one thing constspace guarantees against ([LCSP.2]).

Which backings store values is the load-bearing part. They are SeriesBackendRingBuffer, SeriesBackendFifoDeque and SeriesBackendReservoir, and those are exactly the backings a String-typed slot can reach: per [LSER.17.2] the only aggregations applicable to String are count, count_distinct, count_of, contains, first and last; per [LSER.18.1] those route to SeriesBackendWelfordEwma / SeriesBackendRingBuffer / SeriesBackendReservoir and SeriesBackendWelfordEwma / SeriesBackendFifoDeque, with the exact sliding set and table forms carried on SeriesBackendRingBuffer. SeriesBackendWelfordEwma holds running accumulators rather than samples, so it does not copy.

The obligation is on the property, and an implementation that checks a fixed list satisfies it only while the list is complete.

This is a distinct axis from [LNLS.3.11] / DS_VALIDATE_RT_SERIES_UNBOUNDED, which bound the sample count. A String series with a perfectly bounded window still allocates once per sample, so a capacity bound does not rescue it and the two checks do not subsume each other.

The same allocation occurs under realtime, which carries the constant-space concern as one of its three ([LCSP.1.1]) and states the zero-steady-state-allocation obligation at [RTCT.12.4]; the rejection applies there for the same reason, and is where the diagnostic's name comes from.

see also: LCSP.1.1, LCSP.2, LNLS.3.11, LSER.17.2, LSER.18.1, RTCT.12.4

Dialect mechanics [LCSP.5]#

Deferred: not binding in this edition.

[LCSP.5.1] constspace is a strategy capability of [LCAP.1], set like any other: by a program's dialect, or by a line of its use block ([LDIA.2.1]). The built-in realtime dialect sets it true ([LDIA.9.3]).

see also: LCAP.1, LDIA.2.1, LDIA.9.3

[LCSP.5.2] Chip-adapter baseline choice. Each chip adapter picks its own implied baseline ([LDIA.3.3.1]). The recommended choice for MCU targets is:

  • implied_extensions: [constspace] when bounded memory is the primary need (most embedded telemetry / control use cases).

  • implied_extensions: [realtime] when hard WCET is mandatory (safety-critical / hard real-time control loops).

Adapters MAY offer both as opt-in tokens.

see also: LDIA.3.3.1

[LCSP.5.3] realtime IMPLIES constspace semantically. The reference compiler does not auto-add constspace to active extensions when realtime is present; runtimes treat the flags as independent CapabilityInfo tags and rely on the fact that the allocator mode is identical between the two.

[LCSP.5.4] A program declaring both realtime and constspace explicitly is valid (realtime is the binding choice for WCET-related decisions; constspace is a no-op alongside it).


Runtime contract [LCSP.6]#

Deferred: not binding in this edition.

[LCSP.6.1] CapabilityInfo. The loader reads constspace from the CapabilityInfo atom's enabled list ([RDSC.16.2.2]); a true setting selects the pooled strategy ([LCSP.6.2]).

see also: LCSP.6.2, RDSC.16.2.2

[LCSP.6.2] Lazy pool init. When the artefact has constspace: true, the loader arms the pooled strategy. The integrator's pool-sizing call supplies the capacities and initialises the pools (slab pools, pre-sized arenas), identical to the realtime allocator path. The sizing call supplies capacities only; it never selects the strategy ([NLFC.10.3]).

see also: NLFC.10.3

[LCSP.6.3] No RealtimeContract requirement. Unlike realtime, a constspace DSC does not require a RealtimeContract atom. The end-of-load gate ([RTCT.6.5]) MUST check the realtime setting specifically, not constspace.

see also: RTCT.6.5

[LCSP.6.4] RealtimeContract prohibition. A DSC with realtime: false that carries a RealtimeContract atom is malformed, whatever its constspace setting; the loader returns DS_ERR_CONTRACT_INVALID.

[LCSP.6.5] LIVE enforcement skipped. All LIVE-state checks — the pump_wcet_ns cap and per-pump WCET ([RTCT.12]), and the RT violation codes ([NERR.18]) — apply only under realtime: true. An engine with constspace: true and realtime: false does not transition through the INIT/LIVE lifecycle and never raises a LIVE-state violation.

see also: NERR.18, RTCT.12

[LCSP.6.6] Pool-exhaustion semantics. When a pool fills under constspace:

  • assert returns DS_ERR_OOM (or the existing pool-full code) to the caller. The caller chooses what to do (retry, drop, log).

  • A pump-time pool exhaustion drops the affected firing and emits a warning through the log callback, naming the pool that filled. The pump returns normally; the engine does not abort.


Integration: integrator sizes the pools [LCSP.7]#

Deferred: not binding in this edition.

[LCSP.7.1] Pool capacities come from the build, not from the DSC or a sidecar file. The integrator chooses sizes appropriate to the device's memory budget and supplies them through the runtime's pool-sizing entry points — working-memory cap first, then the remaining bounded pools (agenda cap, intern cap, and so on) as each lands.

[LCSP.7.2] On ESP-IDF targets, these are typically wired through Kconfig (CONFIG_DS_WM_MAX_FACTS, CONFIG_DS_ASSERT_QUEUE_DEPTH, etc.) and applied in the chip adapter's *_init shim. On Pico / bare-metal targets, the integrator passes the values into the adapter context struct.

[LCSP.7.3] An engine whose artefact has constspace: true runs only under the pooled strategy ([RDSC.16.2.1]). If the integrator has not sized the pools, the engine must refuse to assert or pump, with DS_ERR_STATE, rather than run with the ordinary algorithms: nothing switches the strategy off implicitly.

see also: RDSC.16.2.1