Repository navigation
Closed
Feature
7 / 77 of 7 issues completed
Copy link
Description
Summary
Replace the runtime reflection + lazy Touch() archetype/component registry build with a Roslyn source generator driven by a [ModuleInitializer] registration barrier. Breaking change to engine startup internals; taken now (pre-alpha, no back-compat obligation).
- Design:
claude/design/Ecs/SourceGeneratedRegistry/(README + 01–04 — 04 is authoritative). - Isolated POC:
scratchpad/reggenpoc/— all mechanics green (real incremental generator, module-init barrier, collectible-ALC unload/R1, AOT-clean generated path).
Why — one change, three value streams
- Reliability (this Epic): fixes the ~33%/run flaky-test race — concurrent
InitializeArchetypeson the unsynchronized process-globalArchetypeRegistry(IndexOutOfRangeExceptioninRebuildEntityMapsFromPersistedData+ a false "cascade diamond"). The CLR module initializer is a run-once, thread-safe registration barrier that kills the race by construction. - Durability (LOG-06): the logical WAL wire carries the order-dependent dense
ComponentTypeId; a crash→reopen with shifted registration order can silently mis-map post-checkpoint records → data loss. Fixed by wiring(routingId, slot)— both durable. - AOT (Native AOT readiness for Typhon.Engine #409): delivers Native AOT readiness for Typhon.Engine #409 acceptance-criteria §1 — source-generate component registration, killing blocker B2 (
MakeGenericType/ActivatorforComponentCollection<T>) + the schema-reflection cluster. - Pluggability (new capability): an engine-assigned per-DB archetype routing id lets two mutually-unaware assemblies compose into one database collision-free — the basis for a plugin/marketplace model.
Model (settled)
- Zero author-set ids. Archetype identity = CLR type name (or optional
[Archetype("Name")]); component identity =[Component("Name")](existing). EntityId= 48-bit per-archetypeEntityKey+ 16-bit per-DB archetype routing id (routing id monotonic, persisted inArchetypeR1, embedded inEntityId;NextEntityKeyis already per-archetype).- In-memory dense component handle unchanged on the hot path (O(1)
_typeIdToSlot). GetMetadata(ushort)moves from global-static to a per-engineMetaByRouting[].
Phases → Tasks
The 6 phases from 04 §9 are tracked as sub-issues below (each independently testable; Phase 1–2 fix the flakiness and LOG-06 before any codegen).
Relations
- Parent: Reliability & Robustness #412 (Reliability & Robustness).
- Relates Native AOT readiness for Typhon.Engine #409 (Native AOT readiness) — this Feature delivers Native AOT readiness for Typhon.Engine #409 acceptance-criteria §1; tick those boxes on completion.
Sub-issues
Collapse Sub-issuesSub-issues
Loading 7 sub-issues
Activity
nockawa commentedon Jul 18, 2026
Accepted implementation plan (whole feature, one branch, one PR)
Branch:
feature/514-source-generated-registry· Spec:claude/design/Ecs/SourceGeneratedRegistry/04-solution-design.md(authoritative)Decisions taken (ratified by design
04)Idfrom[Archetype(Id=N)]; routing id engine-assigned. Ripples to every[Archetype(400..)]declaration.Touch()/RunClassConstructorstartup calls (~230 sites), not no-op shims.[Archetype("Name")]override.Acceptance criteria by phase (completion = all met)
Phase 1 — EntityId 48/16 + per-DB routing id (§2/§6/§7.1)
EntityKey(48)|routingId(16)round-trips; inline shift sites routed throughEntityId.ArchetypeR1.RoutingId(ushort) persisted; engine-assigned per-DB monotonic/dense.MetaByRouting[];GetMetadata(ushort)moved off global static (~32 sites).MaxArchetypeIdsizing coupling).Phase 2 — WAL wire
(routingId, slot)(§7.2; LOG-06/WR-01)ComponentTypeId(Slot + CollectionDelta).(routingId, slot)directly;_typeIdToSlotoff replay path.Phase 3 — Registrar API + registration lock (§4)
ArchetypeRegistry.Registrarsingle registration path, lock-guarded, atomic catalog build.Phase 4 — Generator: per-component reflection-free builders (§3; #409 §1)
[Component]-drivenCreateComponentBuilder().WithField<T>(...)emission; offsets one-timeMarshal.OffsetOf.CreateFromAccessoroff the build path.MonitoringDemo,ARPG.Shell,Workbench.Tests; shipped viaGenerators.Consumer.Phase 5 — Per-archetype records +
[ModuleInitializer]barrier (§3/§5)ArchetypePrebuiltrecords + module-init registrar.Touch()deleted (~230 sites); Workbench →RunModuleConstructorpost-ALC-load.EntityLink<CollectibleArch>leak.Phase 6 —
Type→delegatedispatch (B2) + cascade diagnostic + AOT lock-in (§3.2/§8)MakeGenericType/ActivatorforComponentCollection<T>(B2 gone).TPHxxxx).<IsAotCompatible>true</IsAotCompatible>; correctoverview/04-data.md. Ticks Native AOT readiness for Typhon.Engine #409 §1.Verification
Per-AC affected tests → full Engine suite at each phase boundary → scripted ≥25× parallel-suite race proof → shifted-order WAL oracle → full-solution build incl. generator. Mandatory self-review +
/reviewbefore done.#514 migrate consumer smoke test off removed RegisterArchetype / [Arc…
#514 [no-ut] map Schema.Definition / Generators / Profiler in docs-af…
#514 Source-generated archetype & component registry (PR #530)
#672 Zero the slot location when a revision-chain walk finds nothing
Opening a database in the Workbench must not add components to it
#1044 The first alpha is 1.0.0-alpha.1: the 1.0 line being finished, …
#1044 #1045 #1034 The first alpha, 1.0.0-alpha.1: four NuGet packages…