Skip to content

Commit c78a55f

Browse files
committed
docs: register-file model — SoA as LE registers, OGAR class as ISA descriptor
New section added to three-tier model doc. Mental model: SoA columns are CPU-style LE registers (fixed offset, fixed width, no schema in the row). OGAR class is the instruction-set descriptor and DTO store for active record (label + schema + tools + codegen templates). Three sub-sections: - SoA columns = LE registers: byte-offset table, SoaEnvelope as ABI doc, ColumnDescriptor as register descriptor, MultiLaneColumn as load/store unit. - OGAR class = ISA descriptor + active record: label-inheritance via HHTL, schema stored once per class (never in rows), tools inherited from class hierarchy (prefix ancestry = class ancestry), active record = class wrapping a register bank slice. - Askama/Jinja codegen = masked selection from class DTO: Class<Template> is a compile-time field projection over the class schema — one select mask, zero new types, zero runtime dispatch. Every DTO is a derived view of an OGAR class; independent DTO structs = schema drift. Lookup table: CPU register file vs SoA mailbox (register bank / ABI doc / load-store / ISA / calling convention / object code / active register state). https://claude.ai/code/session_0147hSzjmWZDuy2MSQNrhEK5
1 parent 1eed37a commit c78a55f

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

docs/architecture/soa-three-tier-model.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,120 @@ out pending resolution. **Do not fall back to crates.io surrealdb.**
154154
the O(1) lookup is the sole path.
155155
6. surrealdb requires the AdaWorldAPI fork with `kv-lance`. Never fall back to
156156
crates.io. BLOCKED(C) until fork coordinates are provided.
157+
158+
---
159+
160+
## Register-file model — SoA as LE bytecode registers, OGAR class as instruction-set descriptor
161+
162+
This is the load-bearing mental model. Read it before touching the SoA layout,
163+
the class hierarchy, or any codegen template.
164+
165+
### SoA columns = LE registers
166+
167+
The `MailboxSoA<N>` columns are CPU-style registers: fixed width, fixed byte
168+
offset, little-endian, indexed by position. There is no schema in the row.
169+
The row is a register bank.
170+
171+
```
172+
Byte offset Width Column LE kind
173+
────────── ───── ────── ───────
174+
0 4·N energy[N] f32 × N
175+
4N N plasticity[N] u8 × N
176+
5N 4·N last_active_cycle[N] u32 × N
177+
9N 8·N edges[N] u64 × N (CausalEdge64 LE)
178+
17N N qualia[N] u8 × N (QualiaI4_16D packed)
179+
18N 2·N meta[N] u16 × N (MetaWord LE)
180+
20N 2·N entity_type[N] u16 × N
181+
22N 4 mailbox_id u32
182+
22N+4 4 current_cycle u32
183+
... ... (scalars follow)
184+
```
185+
186+
The `SoaEnvelope` trait is the register-file descriptor: it names each
187+
register's byte offset, width, and LE element kind — exactly what a CPU ABI
188+
document does. `ColumnDescriptor` is one register descriptor. `verify_layout()`
189+
is the ABI conformance check.
190+
191+
`MultiLaneColumn` in ndarray is the load/store unit: it iterates the LE bytes
192+
of one typed register into SIMD lanes. Nothing above this level cares about
193+
byte order — it is resolved at the `from_le_bytes` boundary inside the lane
194+
iterator.
195+
196+
### OGAR class = instruction-set descriptor + DTO store for active record
197+
198+
The OGAR class does NOT live in the register. It describes what the register
199+
means. A class is:
200+
201+
- **Label** — the OGIT identity string (`"ogit-op/WorkPackage"`), the
202+
human-readable name, and the full label-inheritance chain up the HHTL trie.
203+
- **Schema** — the field set: which fields exist, what types they are, which
204+
are required vs optional. Stored once per class in `OntologyRegistry`
205+
(`MappingRow`); never duplicated into SoA rows.
206+
- **Tools** — the methods / adapters that operate on the register. These are
207+
inherited from the class hierarchy (HHTL prefix ancestry = class ancestry).
208+
A subclass inherits all parent tools without restating them.
209+
- **Codegen templates** — Askama/Jinja `Class<Template>` views (see below).
210+
- **Active record** — the class instance wraps a slice of the register bank
211+
and provides the domain API. Methods come from the class hierarchy; data
212+
comes from the register slice. The active record is the class speaking about
213+
one register bank row, not a separate struct.
214+
215+
```
216+
mailbox address ──HHTL O(1)──► OGAR Class
217+
218+
┌────────┼────────────┐
219+
▼ ▼ ▼
220+
label schema tools
221+
(string) (fields) (inherited methods)
222+
│ │ │
223+
└────────┼─────────────┘
224+
225+
active record instance
226+
(class + register bank slice)
227+
no new fields; register IS the data
228+
```
229+
230+
### Askama/Jinja codegen = masked selection from the class DTO
231+
232+
A `Class<Template>` is not a new type. It is a **masked selection** over the
233+
class DTO: the template declares which fields it reads, the codegen emits only
234+
those fields as strongly-typed Rust from the class schema, and the result is a
235+
zero-overhead view — one `select` mask over one class, compiled to a concrete
236+
struct by the Askama/Jinja template engine.
237+
238+
```
239+
OGAR Class { field_a, field_b, field_c, tool_x, tool_y, template_T }
240+
241+
▼ Class<TemplateFoo> mask = { field_a, tool_x }
242+
243+
codegen (Askama/Jinja)
244+
245+
246+
struct FooDto { field_a: TypeA } // only selected fields
247+
impl FooTool for FooDto { ... } // only selected tools
248+
```
249+
250+
The template is a compile-time projection. No runtime dispatch. No new
251+
inheritance hierarchy. The mask is the whole mechanism — the class already
252+
owns the full schema; the template carves the slice it needs.
253+
254+
This makes every DTO in the system a **derived view of an OGAR class**, never
255+
an independent schema. A session that proposes a new DTO struct without a
256+
corresponding OGAR class entry is creating schema drift.
257+
258+
### Why this is the correct mental model
259+
260+
| CPU register file | SoA mailbox |
261+
|---|---|
262+
| Register bank | `MailboxSoA<N>` columns |
263+
| Register descriptor (ABI doc) | `SoaEnvelope` + `ColumnDescriptor` |
264+
| Load/store unit (MOV instruction) | `MultiLaneColumn` SIMD iterator |
265+
| Instruction-set definition | OGAR class (label + schema + tools) |
266+
| Subroutine calling convention | HHTL inheritance (prefix = class ancestry) |
267+
| Object code (compiled binary) | Askama/Jinja codegen from `Class<Template>` |
268+
| Active register state | register bank slice wrapped by active record |
269+
270+
The SoA is dumb. It holds bytes. The class makes the bytes meaningful.
271+
The template makes the class usable without the full schema in scope.
272+
Nothing in the register knows about the class; nothing in the class knows
273+
about which register it describes at runtime — the address is the link.

0 commit comments

Comments
 (0)