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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
use String;
use Vec;
use crateCountingFlags;
use crate;
use crateLineContent;
use crate;
/// A compiled container (knot, stitch, gather, or anonymous flow block).
/// Name + mode of one declared parameter of a container (T1c,
/// `docs/t1c-spec.md` §6). See [`ContainerDef::params`].
/// Metadata for a single interpolation slot in a template line.
/// Source location of a line in the original `.ink` file.
/// One entry in a container's line table.
/// A locale line entry — content + optional audio, no source metadata.
/// A per-scope locale line table.
/// Complete locale overlay data from a `.inkl` file.
/// Per-scope line table, stored separately from [`ContainerDef`] for
/// locale overlay swapping (`.inkl`).
///
/// All containers within a lexical scope (knot, stitch, or root) share one
/// `ScopeLineTable`. `EmitLine(idx)` indices are scope-relative.
/// One line-variant group (stage 1 of the shared-alternatives track,
/// issue #3273): the record that ties `dims.iter().product()` consecutive
/// [`LineEntry`]s in a scope's line table back to ONE authored source line
/// whose inline alternatives were enumerated at recognition time.
///
/// The entries themselves are ordinary whole-line entries — each with its
/// own `source_hash` and its own `audio_ref`, which is the point: VO is
/// associated per *rendered* line, and a translator sees whole lines. This
/// record exists so intl export and audio tooling can group them, and so
/// codegen's combo switch and the table agree on the layout.
///
/// Layout contract: variant `(i, j, …)` — one branch index per authored
/// alternative, in source order — lives at
/// `base + i * dims[1..].product() + j * dims[2..].product() + …`
/// (row-major, first alternative varies slowest). `dims` is never empty
/// and every dim is ≥ 1.
/// A global variable definition.
/// A list (enum-like set) definition.
/// A `STRUCT` shape definition (TM-4, `docs/typed-mode-spec.md` §6;
/// `StructShapes` section, `docs/format-spec.md` tag `0x0C`).
///
/// Closed shape: `fields` is the ordered set of declared field names — the
/// same order [`crate::value::Value::Record`]'s flat field vector follows,
/// and the order `RecordNew`/static `RecordGet`/`RecordSet` offsets index
/// into.
/// One old→new `DefinitionId` rename record (M-3, `docs/modules-spec.md`
/// §5): the compiler emits one of these per `#@was(old_name)` directive —
/// on a module, one entry per definition the renamed module currently
/// owns; on a single definition, one entry for it. Rehydration
/// (`brink-runtime`'s `load_state`) consults the table **only on the miss
/// path**: a saved fn token, divert value, or visit-count key that the
/// current program doesn't recognize is looked up here before being
/// treated as genuinely gone.
/// The capability-parameter slot carried by every call atom in a factored
/// effect row (T2-3, `docs/effects-spec.md` §11; ruled 2026-07-14,
/// `docs/t1d-spec.md` §7).
///
/// v1 populates every atom as [`CapabilityParam::Any`] — component-granular,
/// the whole capability unrefined. Path-granular refinement (#826) and the
/// instance-resolving handle parameter are later narrowing rungs; their
/// discriminants are reserved (the strict reader rejects them until a section
/// version graduates them), the same reservation discipline the projection
/// range segment follows.
/// A single call atom in an effect row's direct part (`docs/effects-spec.md`
/// §2/§11): the name of an `EXTERNAL` binding (a call-kind), plus its
/// [capability-parameter slot](CapabilityParam) and a **reserved
/// handle-parameter slot**.
///
/// The handle-parameter slot (`docs/t1d-spec.md` §7) is where a
/// handle-parameterized atom (`Transform(@argN)`) will record which minted
/// handle bounds the capability; v1 leaves it `None` (the reserved wire byte is
/// `0`). Possession-bounded capabilities are the tier-2 security model — out of
/// scope for this slice, but the slot ships now so the row encoding need not
/// change to carry it later.
/// The direct part of a factored effect row (`docs/effects-spec.md` §7/§11):
/// the atoms a definition (and everything it statically calls) may perform,
/// independent of any dispatch-cell narrowing. Mirrors the analyzer's flat
/// `EffectRow`, lowered to wire vocabulary (cells as [`DefinitionId`]s, call
/// kinds as [`CallAtom`]s).
///
/// Sets are stored as vectors already sorted/deduplicated by the producer so
/// the encoding is deterministic (the analyzer sources them from `BTreeSet`s).
/// A per-dispatch entry in a factored effect row (`docs/effects-spec.md` §7):
/// the row a call through a dispatch `cell` contributes, whether that dispatch
/// is runtime-**narrowable** (its cell is not in the entry's own write set),
/// and the **static fallback** row used when narrowing does not apply.
///
/// v1 emits none of these (call-through-value is inferred as opaque, folded
/// into the direct part) — but the encoding ships the structure now, because a
/// flat row structurally forecloses the §7 narrowing the host will do at
/// schedule-commit. The reader round-trips a populated dispatch list so writer
/// and reader stay paired (the #742 lesson).
/// One entry in the `EffectRows` `DefinitionId → row` table (T2-3,
/// `docs/effects-spec.md` §11, `docs/format-v4-rfc.md` §2 `EffectRows`
/// reservation): a factored effect row for one definition.
///
/// Every knot/stitch ships one — the per-container row is the host's
/// resume-scheduling estimate (`docs/effects-spec.md` §12.1: a flow resumes
/// from wherever it parked). The row is additive metadata; the runtime does
/// not consume it yet (`sleep`/narrowing are the future clients), so a story
/// carrying rows is byte-identical in behavior to one without.
/// The name-keyed **frame shape** for one `await` site
/// (`docs/flow-suspension-spec.md` §4/§11): the static description of which
/// locals cross the park at that site, so the runtime knows what to
/// spill on park and restore on wake.
///
/// Emitted into the `FrameShapes` [`StoryData`](crate::StoryData) section
/// (`.inkb` tag `0x10`,
/// `.inkt` `(frame_shapes …)`). The shape is **name-keyed** — the runtime
/// spills/restores crossing locals by name, riding the same rehydration
/// machinery as `#@was`/saves (spec §7), so a frame survives recompiles
/// without instruction offsets (spec §2/§3).
///
/// **Reserved-through-fence**: the FS-3c compiler slice lands this section's
/// encoding (writer + reader + round-trips) but does not yet *emit* a
/// non-empty table — the E052 `await` lowering fence keeps `await` from
/// producing any `StoryData`. First emission rides the continuation-splitting
/// codegen when the fence drops (FS-3r), the same reserved-then-materialized
/// discipline `StructShapes` followed. `frame_shapes` is therefore empty for
/// every story compiled today (and for all converter output).
/// A single list item definition.
/// An address pointing to a specific byte offset within a container.
///
/// Addresses are used for divert targets, visit tracking, and any definition
/// that maps to a position within a container. A "primary" address has
/// `byte_offset == 0` and the same `id` as its `container_id`, functioning
/// like the old `Container` tag. Intra-container addresses have non-zero
/// offsets and distinct IDs.
/// Maps a qualified author path (e.g. `knot`, `knot.stitch`, `knot.label`,
/// `knot.stitch.label`) to the [`DefinitionId`] it addresses.
///
/// This is the source of truth for path → address lookup
/// ([`Program::find_address`](../../brink_runtime/struct.Program.html#method.find_address)):
/// the linker resolves each `target` through its address map. The compiler
/// emits one entry per scope container (knot/stitch) and per author-labeled
/// gather/choice. `path` indexes the name table; `target` is the addressed
/// container/label id.
/// Compute a stable hash of source text — FNV-1a, 64-bit, over the UTF-8
/// bytes.
///
/// **Part of the wire contract** (`docs/format-spec.md`), not an
/// implementation detail. Hashes produced here are written into artifacts
/// ([`LineEntry::source_hash`] for the intl regeneration workflow;
/// [`DebugFileEntry::source_hash`] for the debugger's staleness check,
/// issue #3261) and compared later — potentially by a different binary, a
/// different toolchain, or a `no_std` build. So the algorithm is specified
/// and identical on every path, and must not change without treating it as
/// a format change.
///
/// This is why it is no longer `std`'s `DefaultHasher`: Rust documents that
/// hasher's algorithm as unspecified and subject to change between
/// releases, and the `no_std` fallback it used to sit beside was explicitly
/// not bit-identical to it. Both were fine while nothing compared hashes
/// across builds. Recording a hash in an artifact makes that exactly what
/// happens, and a silent algorithm change would make every comparison
/// report "changed" forever, with no obvious cause.
///
/// FNV-1a is a **change detector, not a proof**: it is not collision
/// resistant and is not a security primitive. A collision means changed
/// text is reported as unchanged — for the intl workflow, a line missed for
/// retranslation; for the debugger, a stale source accepted as fresh, which
/// is no worse than the silent wrong answer the check exists to replace.
/// An externally-bound function definition.
// ── DebugInfo (D6, `docs/debugger-spec.md` §2) ──────────────────────────────
/// `flags` bit 0: this entry marks a recommended stop location / the start
/// of a statement (`docs/debugger-spec.md` §2.1's DWARF-`is_stmt` design).
/// v1 sets this on every entry (statement-level rows only); a later
/// expression-level entry arrives with this bit unset, additively — no
/// version bump, no reader change.
pub const DEBUG_FLAG_IS_STMT: u8 = 0b0000_0001;
/// `flags` bit 1: this entry's own `bytecode_offset` is the prologue-end
/// landing point for a breakpoint set on the enclosing container
/// (`docs/debugger-spec.md` §2.4) — past any leading parameter-binding
/// `DeclareTemp`s / choice-output prologue bytes. At most one entry per
/// container carries this bit.
pub const DEBUG_FLAG_PROLOGUE_END: u8 = 0b0000_0010;
/// Bits 2–7 of `flags` are reserved. Per `docs/debugger-spec.md` §2.2's
/// explicit, ruled departure from this format's default strict-rejection
/// posture, a `DebugInfo` reader **must ignore** any reserved bit it does
/// not recognize rather than reject the entry — this constant exists so
/// callers can mask deliberately (e.g. a round-trip test asserting v1 never
/// sets a reserved bit) without hand-writing the mask twice.
pub const DEBUG_FLAG_RESERVED_MASK: u8 = !;
/// Which frontend parsed a `DebugInfo` file-table entry's file
/// (`docs/debugger-spec.md` §2.3) — `KindToken::raw` is frontend-private
/// (two independent `ProvenanceResolver` numberings), so a reader must know
/// which resolver applies before interpreting an entry's `kind_token`.
/// Recorded once per file (not per entry) since surface is a property of
/// where the code came from, constant for every entry pointing at that
/// file.
/// One entry in the `DebugInfo` section's section-local file table
/// (`docs/debugger-spec.md` §2.3). Index 0 is always the reserved synthetic
/// sentinel (§2.5) — `surface = Synthetic`, `path = ""` — real files start
/// at index 1. Paths are project-root-relative (`root_relative_key`), not
/// process-cwd-relative or absolute.
/// One row in a container's `DebugInfo` entry table
/// (`docs/debugger-spec.md` §2.2): maps a bytecode offset (within that
/// container's own bytecode) to the source range it was lowered from.
/// Entries for one container are sorted ascending by `bytecode_offset` so a
/// reader can floor-lookup via binary search.
/// One row in a container's `DebugInfo` locals table
/// (`docs/debugger-spec.md` §3): a VM temp slot's declared name, and
/// optionally the source range it was declared at (for slot-reuse
/// disambiguation). **D7's payload** (`docs/debugger-spec.md` §3, issue
/// #3185) — D6 emits the structural framing (an empty `locals` per
/// container) but does not populate real entries; the wire shape ships now
/// so D7 adds data without a layout change.
/// One container's `DebugInfo` table (`docs/debugger-spec.md` §2.2): the
/// `DebugInfo` section's Nth `DebugContainerTable` describes the container
/// at `StoryData::containers[N]` — addressed by the same `container_idx`
/// the runtime's `ContainerPosition` uses, lockstep with the `Containers`
/// section, no `DefinitionId` lookup needed on the read path.
/// The `DebugInfo` section (`docs/debugger-spec.md` §2, `.inkb` tag
/// `0x11`): bytecode-offset → source-range map, plus the section-local file
/// table it's keyed against. Carried on [`crate::StoryData::debug_info`] as
/// `Option` — `None` when not requested (dev/studio compiles and an
/// explicit CLI debug flag opt in; release export never does, §1.2 ship
/// policy) — distinct from the other "always present, possibly empty"
/// section types, because presence here tracks *whether debug info was
/// requested*, not merely whether any entry was produced.