1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
//! The frontier family's table vocabulary (ADR-0478 Decision 6's
//! allocation half, in the sparse layout): the tables one frontier run
//! reads and writes — the per-touched-node records (the dedup bitmask
//! and the endpoint/candidate marks) and the first-arrival pair ledger
//! carrying each pair's parent — the run's output records those tables'
//! readers consume (the accepted [`Endpoint`] with its [`Arrival`], the
//! reconstructed [`Chain`]), and the allocation ceiling that bounds them
//! ([`FRONTIER_TABLE_BUDGET`], [`within_table_budget`]). Split from the
//! BFS runner (`super::frontier`) by the file-size rule: the runner owns
//! the level loop and the run types (`RunOutcome` and the run it serves,
//! never named here); this module owns the shapes the loop writes and
//! every consumer — the capped emission's halt probe, the re-arrival
//! rule's chain proof, the witness reconstruction — reads.
//!
//! **Sparse, never span-sized.** Every table is sized by the (node,
//! state) pairs the run touched, never by the store's node-id span: the
//! node records live in a [`NodeMap`] (open-addressed, generation-stamped
//! — O(1) reset), the pairs in one ledger vector, and a node's pairs are
//! linked newest-first through the ledger from its record. Nothing is
//! allocated before the first arrival, and no untouched memory is ever
//! written.
use size_of;
use ;
use crateExecGraph;
use crateRelTypes;
use FrontierNfa;
use crateNodeMap;
/// The per-run table-allocation ceiling (ADR-0478 Decision 6's
/// allocation half, the ADR-0395 fixed-constant family): the exact bytes
/// a run's tables hold — [`FrontierTables::heap_bytes`] plus the
/// re-arrival rule's
/// [`RuleBuffers::heap_bytes`](super::rearival::RuleBuffers::heap_bytes)
/// — are checked against it at every level boundary, beside the walk
/// budget, and a run that crosses it declines at run time
/// (`FrontierRunDecline::TableBudget`): its buffered rows are discarded and
/// the clause falls through to the DFS, which has its own caps. Decline
/// over an authored error is deliberate — the family's fail-through
/// direction. The sparse tables allocate nothing up front, so the store's
/// span no longer decides anything; what the ceiling bounds is a run that
/// genuinely touches more pairs than the tables should hold. Sized so
/// every measured class fits with headroom: a run touching every node of
/// a ~10⁶-node store at the workload's 1–3 states sits an order under it.
pub const FRONTIER_TABLE_BUDGET: u64 = 1 << 30;
/// Whether a run's tables, at `bytes` of exact allocation, sit within
/// the ceiling — the BFS runner's level-boundary check. The decline is
/// the DFS fall-through, never an error; the test seam
/// (`frontier_table_budget_override`) pins the decline on a small graph
/// instead of building a run whose tables cross the production constant.
pub
/// How one first arrival happened: over a relationship, or over an
/// epsilon edge (an unrolled bounded quantifier's optional-copy skip —
/// same node, no hop, no rel). The rel-id column (Decision 1: one
/// `RelId` per pair) rides [`Step::Rel`] in place: the traversed rel is
/// exactly what the witness reconstruction needs beside the predecessor
/// pair, and the ledger's entry layout already carried everything else
/// that column requires.
pub
/// The recorded parent of one (node, state) pair's first arrival.
pub
/// The ledger's end-of-chain link: a node record's head, or a pair
/// entry's `next`, holding this names no further pair. The largest
/// ledger index a record's packed head word can carry
/// ([`NodeRecord::link`]): the table ceiling bounds the ledger orders
/// below it.
const NO_PAIR: u32 = - 1;
/// The record's endpoint-mark bit in the packed head word.
const ENDPOINT_MARK: u32 = 1 << 30;
/// The ledger's next pair index at length `len`, or `None` at the index
/// ceiling — the packing reserves every index at and above
/// [`NO_PAIR`] (the mark bits), so the last indexable pair is
/// `NO_PAIR - 1` and a longer ledger declines instead of indexing.
/// The record's candidate-mark bit in the packed head word.
const CANDIDATE_MARK: u32 = 1 << 31;
/// One touched node's record: the run's every per-node fact, in one
/// place — the dedup bitmask, the two marks, and the head of the node's
/// pair chain through the ledger. The record table is the run's one
/// "which nodes did this run touch" structure. Twelve bytes of data,
/// sixteen with the `u64`'s alignment padding, so a map slot is 32
/// (stamp 4, padding 4, key 8, record 16): the head index and the two marks
/// share one word ([`NO_PAIR`] bounds the index below the mark bits) —
/// the slot's size is the BFS's cache footprint per touched node.
/// One first arrival's answer ([`FrontierTables::arrive`]): whether the
/// pair is new, and whether its node was already an accepted endpoint
/// before this arrival — the BFS runner's two per-arrival reads, in one
/// record lookup.
pub
/// The run's table ceiling, crossed at an arrival: the pair was
/// recorded nowhere (no mark, no cell, no ledger entry), and the caller
/// folds the fact into the run's table-budget decline — the per-arrival
/// backstop that keeps both the byte budget and the packing's index
/// space a decline at every granularity, never a panic and never an
/// unbounded allocation. The level-boundary check usually fires first.
pub ;
/// One ledger entry: a first-arrival (node, state) pair, its parent
/// (`None` exactly for the seed pair — every chain's terminator), and
/// the link to the same node's previous pair.
/// The first-arrival parent table of one frontier run, as its readers
/// hold it: per touched (node, state) pair, the predecessor pair and the
/// step kind. A pair has an entry exactly when it is marked seen (the
/// dedup set and the ledger are written together); the one entry
/// without a parent is the run's seed pair — the chain walk's
/// terminator. A borrowed view over the run's owned [`FrontierTables`] —
/// the halt probe, the re-arrival rule's chain proof, and the witness
/// reconstruction read this shape, never a second copy of the ledger.
pub
/// The frontier family's per-clause table set (ADR-0478 Decision 6's
/// allocation half, sparse): created once per engaged clause and
/// recycled across the clause's seeds. Nothing is allocated up front —
/// the node records and the ledger grow with the pairs a run touches —
/// and the per-seed reset ([`Self::begin_seed`]) is O(1): the record
/// map's generation bump and the ledger's length reset. A recycled set
/// keeps its capacity (the largest seed's footprint so far), never a
/// span-sized one.
///
/// The write surface is the method set alone: the BFS runner
/// (`super::frontier`) records first arrivals and marks endpoints and
/// candidates through [`Self::begin_seed`], [`Self::arrive`], and the
/// mark methods beside them; every other consumer reads through the
/// views ([`Self::parents`], the run's endpoint list).
///
/// One run at a time holds the set: the runner's BFS
/// ([`run_with_halt`](super::frontier::run_with_halt)) takes it whole
/// (the clause's pool left empty for the run's duration) and carries it
/// inside a served outcome's run; the caller hands it back through the
/// run's own `reclaim` (in `super::frontier`) once the run's consumers
/// are done. A run that errors out or declines drops its
/// taken set — its clause is aborting or falling through, the pool with
/// it, so an emptied pool is never reused as if it carried a clause's
/// tables.
pub
/// One accepted endpoint, in arrival order — the reconstruction's input.
/// `state` is the arrival state of the accepting transition (a final
/// state epsilon-reachable behind it adds no hops and no nodes, so the
/// node sequence is settled at the rel arrival), `hops` the observed
/// arrival's hop count (in `[min_hops, max_hops]` for observed
/// in-bounds admissions; below `min_hops` for a below-min candidate the
/// rule's search admitted — the observed arrival, the proven trail's
/// own arrival recorded nowhere), and `arrival` how the accepting
/// arrival happened. The arrival rides here, not in [`Parents`]: an
/// accept-on-arrival re-reach of an already-visited pair finds that
/// slot holding the pair's *earlier* first arrival — the recorded
/// arrival's own step is recoverable only here.
pub
/// An endpoint's accepting arrival: the zero-length walk (the seed,
/// `min_hops == 0` — no rel, no predecessor), or one accepting
/// transition over `rel` from the pair `(node, state)` — the pair and
/// the rel are one fact, carried together.
pub
/// One reconstructed witness chain, seed-first: the node sequence and
/// the rel sequence of a complete accepting run. The chain-replay
/// form ([`frontier_emit`](super::frontier_emit)'s per-endpoint
/// reconstruction) and the re-arrival rule's searches
/// ([`rearival`](super::rearival)'s witness returns) agree on this one
/// shape — the emission binds rows from either source through the same
/// reader.
pub
/// One transition's expansion inputs, resolved once per run: the
/// transition's index into the NFA's table and its type filter in the
/// interned domain (LABS-801). The compiler left ids; the names beside
/// them are the write overlay's arm (`RelTypes::matches_name`) and come
/// from the interner's own `Arc<str>` units — a clone is a refcount, never
/// a copy, and the per-pair walk compares ids. One canonical resolver: the
/// re-arrival rule's search ([`super::rearival`]) walks the same table,
/// never a second copy.
pub
/// The per-state expansion table: every transition indexed by its from
/// state, its interned type ids carried as the resolved filter the
/// adjacency walk reads (LABS-801) — built once per run, never per pair.
pub
/// The test seam's table set for one standalone run — fresh tables for
/// the automaton. The production rider creates one set per engaged
/// clause and recycles it across its seeds; a test driving a single run
/// directly needs the one-shot spelling (the reuse itself is pinned by
/// the dedicated recycling tests, never assumed here).
pub