| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Cek.Pykinos.Store
Description
Separates unboxed cell phase tags, memoized normal-form DAG pointers (NfAddr),
and auxiliary 32-bit integers from boxed payload pointers to minimize GC scanning.
Structure-of-Arrays (SoA) Memory Layout
In traditional pointer-heavy graph reduction engines, every lazy evaluation cell (thunk or indirection) is a heap closure containing an info pointer, mutable fields, and payload pointers. As the heap grows, garbage collection pause times degrade proportionally with the total number of cells.
SoAStore eliminates per-cell heap headers by grouping cells into 4096-cell
contiguous memory chunks (StoreChunk):
scUnboxed: A 36,864-byte unboxedMutableByteArrayholding raw bytes and integers in three segregated contiguous lanes:- Lane 0 (Bytes 0..4095): 4096 x 1-byte
CellTagvalues. - Lane 1 (Bytes 4096..20479): 4096 x 4-byte
Int32memoized normal-form DAG addresses. - Lane 2 (Bytes 20480..36863): 4096 x 4-byte
Int32auxiliary integers (literals, symbols). scPtrA: A 4096-slotSmallMutableArrayholding primary boxed payload pointers.scPtrB: A 4096-slotSmallMutableArrayholding secondary boxed payload pointers.
Cell Lifecycle Transitions
Cells progress through strict evaluation phases tracked in Lane 0:
CT_Thunk: Unevaluated closure(term, env)stored acrossscPtrAandscPtrB.CT_Blackhole: Currently under active evaluation. Cycles trigger runtime errors.CT_WLit: Integer / word literal stored unboxed in Lane 2 with zero heap allocations.CT_WBinder: Evaluated lambda or function abstraction.CT_WRecord: Evaluated record with internedSchemaId.CT_WNeu: Neutral application or variable spine pending normalization.
Synopsis
- newtype CellTag = CellTag {
- unCellTag :: Word8
- pattern CT_Thunk :: CellTag
- pattern CT_Blackhole :: CellTag
- pattern CT_WLit :: CellTag
- pattern CT_WBinder :: CellTag
- pattern CT_WRecord :: CellTag
- pattern CT_WNeu :: CellTag
- pattern CT_Unbound :: CellTag
- data StoreChunk s = StoreChunk {
- scUnboxed :: !(MutableByteArray s)
- scPtrA :: !(SmallMutableArray s (Any :: Type))
- scPtrB :: !(SmallMutableArray s (Any :: Type))
- data SoAStore s = SoAStore {
- ssChunks :: !(SmallMutableArray s (StoreChunk s))
- ssState :: !(MutableByteArray s)
- newSoAStore :: ST s (SoAStore s)
- acquireSlot :: SoAStore s -> ST s (Int32, StoreChunk s, Int)
- allocThunkSoA :: SoAStore s -> a -> b -> ST s Int32
- allocWLitSoA :: SoAStore s -> Int32 -> ST s Int32
- allocWNeuSoA :: SoAStore s -> Int32 -> ST s Int32
- readCellPhaseSoA :: SoAStore s -> Int32 -> ST s (CellTag, Int32, StoreChunk s, Int)
- readMemoNfSoA :: SoAStore s -> Int32 -> ST s Int32
- writeMemoNfSoA :: SoAStore s -> Int32 -> Int32 -> ST s ()
Cell Phase Tags
1-byte cell phase opcode stored in Lane 0 of StoreChunk.
pattern CT_Blackhole :: CellTag Source #
In-progress evaluation sentinel; detects infinite recursion loops.
pattern CT_WBinder :: CellTag Source #
Evaluated lambda abstraction or binder closure.
pattern CT_WRecord :: CellTag Source #
Evaluated flat record mapped by a SchemaId.
pattern CT_Unbound :: CellTag Source #
Unbound / unallocated cell slot marker.
Store Arena Structures
data StoreChunk s Source #
A 4096-cell Structure-of-Arrays Store chunk.
Layout of the 36,864-byte scUnboxed MutableByteArray:
* Bytes [ 0 .. 4095]: Lane 0 — 4096 x Word8 CellTag (1 byte per cell)
* Bytes [ 4096 .. 20479]: Lane 1 — 4096 x Int32 Memoized NfAddr (4 bytes per cell)
* Bytes [20480 .. 36863]: Lane 2 — 4096 x Int32 AuxInt (4 bytes per cell)
Constructors
| StoreChunk | |
Fields
| |
Chunked SoA Store arena supporting up to 4,194,304 cells across 1024 chunks.
Constructors
| SoAStore | |
Fields
| |
Store Allocation and Initialization
newSoAStore :: ST s (SoAStore s) Source #
Create a new SoAStore with chunk 0 pre-allocated.
acquireSlot :: SoAStore s -> ST s (Int32, StoreChunk s, Int) Source #
Acquire the next monotonic cell Int32 address, allocating a new chunk on boundary crossings.
Returns the global address, the enclosing StoreChunk, and the local intra-chunk slot index (0..4095).
allocThunkSoA :: SoAStore s -> a -> b -> ST s Int32 Source #
Allocate a lazy thunk (term, env) cell in the Store.
Initializes the cell phase to CT_Thunk and saves the term and environment pointers.
allocWLitSoA :: SoAStore s -> Int32 -> ST s Int32 Source #
Allocate an unboxed integer literal cell with zero pointer writes.
Stores the value directly in Lane 2 of scUnboxed, completely bypassing the GC write barrier.
allocWNeuSoA :: SoAStore s -> Int32 -> ST s Int32 Source #
Allocate a fresh neutral binder symbol WNeu sym [] in the Store.
Records the symbol ID in Lane 2 and initializes an empty elimination spine.
Cell Phase and Memoization Accessors
readCellPhaseSoA :: SoAStore s -> Int32 -> ST s (CellTag, Int32, StoreChunk s, Int) Source #
Read the unboxed CellTag, AuxInt, StoreChunk, and slot offset for addr.
readMemoNfSoA :: SoAStore s -> Int32 -> ST s Int32 Source #
Check in O(1) whether addr already has a memoized normal-form DAG pointer (NfAddr >= 0).
writeMemoNfSoA :: SoAStore s -> Int32 -> Int32 -> ST s () Source #
Record a memoized normal-form DAG pointer nfAddr for cell addr.