@typesol/cli 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +227 -0
  2. package/README.md +10 -7
  3. package/dist/compiler/analyze.js +443 -12
  4. package/dist/compiler/diagnostics.d.ts +1 -0
  5. package/dist/compiler/diagnostics.js +13 -0
  6. package/dist/compiler/emit/alias.d.ts +44 -0
  7. package/dist/compiler/emit/alias.js +135 -4
  8. package/dist/compiler/emit/base.d.ts +25 -0
  9. package/dist/compiler/emit/base.js +58 -7
  10. package/dist/compiler/emit/calls.d.ts +67 -0
  11. package/dist/compiler/emit/calls.js +521 -46
  12. package/dist/compiler/emit/cpi-core.d.ts +20 -3
  13. package/dist/compiler/emit/cpi-core.js +226 -5
  14. package/dist/compiler/emit/cpi.js +8 -2
  15. package/dist/compiler/emit/expressions.js +38 -7
  16. package/dist/compiler/emit/program.js +30 -1
  17. package/dist/compiler/emit/rbtree.d.ts +7 -0
  18. package/dist/compiler/emit/rbtree.js +142 -0
  19. package/dist/compiler/emit/shared.d.ts +8 -0
  20. package/dist/compiler/emit/shared.js +9 -1
  21. package/dist/compiler/emit/statements.d.ts +27 -1
  22. package/dist/compiler/emit/statements.js +288 -19
  23. package/dist/compiler/emit/storage.d.ts +23 -2
  24. package/dist/compiler/emit/storage.js +100 -56
  25. package/dist/compiler/emit/token.js +2 -2
  26. package/dist/compiler/emit/views.d.ts +60 -0
  27. package/dist/compiler/emit/views.js +523 -0
  28. package/dist/compiler/idl.js +2 -1
  29. package/dist/compiler/model.d.ts +65 -4
  30. package/dist/compiler/model.js +14 -0
  31. package/dist/compiler/toolchain.d.ts +15 -0
  32. package/dist/compiler/toolchain.js +146 -11
  33. package/docs/architecture.md +9 -2
  34. package/docs/case-study-phoenix.md +226 -0
  35. package/docs/language.md +139 -8
  36. package/docs/migrate-from-anchor.md +1 -0
  37. package/docs/runtime.md +1 -1
  38. package/docs/stability.md +21 -2
  39. package/docs/troubleshooting.md +5 -2
  40. package/lib/typesol.d.ts +221 -4
  41. package/llms-full.txt +169 -14
  42. package/llms.txt +1 -1
  43. package/package.json +2 -2
  44. package/runtime/typesol_rt.h +407 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,233 @@ codes, and says so here.
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 0.43.0 — 2026-11-11
10
+
11
+ Phoenix v1 ported in full, Ellipsis Labs' on-chain limit order book and a native program, from the commit a
12
+ reproducible build proves is the mainnet binary, and checked against that binary on 3,575 transactions and a seeded
13
+ random walk over two order books. The compiler gained what it needed: views at run-time offsets (`loadRawAt`,
14
+ `rawArrayAt`), a built-in red-black tree in lib-sokoban 0.3's byte layout (`rbTreeAt`), `Inout<T>` helper parameters,
15
+ byte builders on `FixedVec<u8, N>`, return data and compute-unit logs in native entries, `closeRaw`, Rust 1.14's panic
16
+ lines (`panicsAt`), constant expressions, type aliases and file-local structs. Of the 74 programs of the 0.42.0 sources,
17
+ 68 compile to the same binary as in 0.42.0; Marginfi, multisig, Raydium AMM v4, Raydium CLMM, SPL Stake Pool and
18
+ favorites compile to a different one (the "Faster" entries below).
19
+
20
+ - Examples: showcase/mainnet/phoenix, a port of Phoenix v1 (Ellipsis Labs' on-chain limit order book at PhoeNiXZ8…, a
21
+ native program, all 28 instructions), from the commit a reproducible build proves is the mainnet binary (c16694d,
22
+ relicensed under MIT with its sources unchanged), checked against that binary on 3,575 transactions in five files
23
+ (the original's 50 test functions mapped: 11 covered, 37 added as differential cases, 2 not applicable) and a random
24
+ walk over two order books with a balance oracle, with the same outcomes, log lines, event batches, return data and
25
+ account bytes; 13–61% of the original's compute units (up to 86% at the heap limits, with hundreds of account
26
+ entries or a forwarding program's CPI; a PostOnly order 6,452 against 20,577, a swap of 30 fills 26,344 against
27
+ 61,313, cancelling 512 orders 434,446 against 760,087), 256,360 bytes against 1,344,472. Phoenix's 32 KiB bump heap
28
+ is counted (showcase/mainnet/phoenix/heap.ts): each allocation is charged where the Rust makes it, so a transaction
29
+ that fills the heap (many account entries, a CPI's larger instruction data) aborts at the same allocation, after the
30
+ same log lines and batches; phoenix-limits.test.ts (162 transactions) compares both sides of each boundary, through
31
+ a forwarding caller program where a CPI is needed. What Phoenix formats only when it fails is not charged, the one
32
+ documented difference. A multiple-order packet passed through a CPI is decoded whatever its length, divisions by a
33
+ zero tick size or base lot size panic at Rust's locations, and the clock's timestamp wraps as `as u64`. Its events
34
+ are appended by `pushBorsh` of their literals: in the port, whose batch is an `Inout` parameter, a Reduce event costs
35
+ 47 CU less than the six `pushLE` calls it replaced (one room check instead of six; the 19 against 16 below is a local
36
+ buffer). docs/case-study-phoenix.md.
37
+ - Tests: the Phoenix files keep every compared transaction's compute units and fail unless the port uses fewer on
38
+ every one that succeeds (2,390 of the 3,575) and each compares exactly its expected count; the upstream cases pin
39
+ every refusal to the original's error and message and make the original tests' own assertions on chain. The random
40
+ walk draws its choices and keys from fixed seeds (1, 2 and 3, 300 steps on each market: 1,801 transactions), so a
41
+ seed reproduces it, and requires minimum counts of fills, evictions, expiries and fees decoded from the events. The
42
+ lib-sokoban traces are 21,650 operations (seeds 1–3, five key shapes, capacities 1 to 4096, fill and drain cycles).
43
+ - Language: a top-level integer constant may be an expression over literals and constants declared before it (in its
44
+ file or an imported one): `const EVENT_ROOM = 1280n - 34n`, `const ASKS_AT: u64 = BIDS_AT + 2n * BOOK`, with
45
+ `+ - * / % ** & | ^ << >>`, unary `-` and `~`. It is folded when the program is compiled and inlined like a literal.
46
+ A typed constant is computed in its type, as Rust computes `const X: u64 = …`: every step must fit (`1n - 2n + 5n`
47
+ as a u64 is an error naming the step); division by zero, a negative exponent and a shift past the width are compile
48
+ errors too. Only literals were accepted (test/language/port-syntax.test.ts).
49
+ - Language: a struct that is not exported (`interface Pair { … }`) is its file's own: helpers take, return and change
50
+ it (`Inout<Pair>`), locals hold it, and the IDL leaves it out. It failed with "structs must be exported" and a
51
+ misleading second error about the helper's return type. Used where the IDL describes it (account data, an
52
+ instruction's arguments or result, an event, an exported struct's field, a data enum's variant), it is one error
53
+ naming the use and the fix, `export interface Pair` (test/language/port-syntax.test.ts). A non-exported account group
54
+ is refused as before, with its own message.
55
+ - Language: a read-only native view can be read where it is made: `loadRaw<Header>(market).inner.b`,
56
+ `loadRawAt<Prefix>(market, 576n).tick` and `rbTreeAt<K, V>(…).length` / `.capacity` ("unsupported property access"
57
+ and "bind … to a const first" before). A writable view (`loadRawMut`, `loadRawMutAt`) is still bound first, now
58
+ with the reason: it claims its account once per instruction (test/language/port-syntax.test.ts).
59
+ - Language: a local list may hold 2 KiB of elements, its FixedVec length word aside: `const ids: FixedVec<u32, 512> =
60
+ fixedVec([])` (2,052 bytes, Phoenix's collected order ids) was refused. A frame that then overflows is still reported
61
+ by the frame check, which names the biggest locals; the refusal of a bigger list now gives the element bytes and, on
62
+ a declaration, the `/** @heap */` remedy (test/language/port-syntax.test.ts).
63
+ - Language: comma-separated updates in a `for` loop, `for (let i = 0n, j = n; i < j; i++, j--)`, run in order after
64
+ each pass (`continue` included), and so do comma-separated assignments in its initializer; they were refused ("this
65
+ expression has no effect"). A comma anywhere else still is (test/language/port-syntax.test.ts).
66
+ - Faster: `buf.pushBorsh<DataEnum>({ kind: "Reduce", … })`, a data-enum literal of a fixed-size variant, builds only
67
+ that variant: its fields evaluated in source order into locals, then one room check, the tag and a store of each
68
+ field at its offset (a variant holding a struct or FixedArray: one temporary of exactly its bytes and one copy). It
69
+ zeroed, filled and copied the whole enum (92 bytes for Phoenix's PhoenixMarketEvent), then wrote the tag and the
70
+ variant behind a switch on it: Phoenix's 35-byte Reduce event 54 → 19 CU against 16 for the same bytes by `pushLE`
71
+ (test/language/phx-costs.test.ts, which also checks every field kind's bytes). Changes the generated C of programs
72
+ that push data-enum literals (Phoenix, test/fixtures/byte-builders.ts), whose tests pass unchanged.
73
+ - Faster: a read-only struct, FixedArray or data-enum argument of a helper that also takes accounts is copied at the
74
+ call only when it may be account data (a field of a view or of a loaded account), which the helper's writes could
75
+ change. A struct parameter of a helper that itself takes accounts, an instruction's struct argument and return data
76
+ are now passed in place like the caller's other owned structs (locals, helper results): they arrived as copies and
77
+ no account write reaches them. Phoenix's book helpers now take their MarketShape as a plain struct, where they took
78
+ it as `Inout<T>` only to avoid the copy (test/language/phx-costs.test.ts: 97.6 → 43.3 CU per call of a helper
79
+ passing it on, test/language/helper-copies.test.ts). Changes the generated C of SPL Stake Pool, Marginfi and Raydium
80
+ CLMM (a copy fewer at such calls), whose tests pass unchanged.
81
+ - Faster: the owner check of native account views (`loadRaw` / `loadRawMut`, `loadRawAt`, `rawArrayAt`, `rbTreeAt` and
82
+ their Mut forms) remembers the last account it found this program's, until a CPI or an owner write (`assignOwner`,
83
+ `closeRaw`, `close`) forgets it: the same account passes again with a pointer compare instead of a 32-byte one.
84
+ Phoenix's helpers each view the market again, often in loops that write it, where clang could not drop the
85
+ repeated compare (test/language/phx-costs.test.ts: a view per pass of a writing loop 21 → 15 CU, two views 35 → 21,
86
+ a helper call taking the market 54 → 43). A view after the account changed hands still fails with 3007
87
+ (test/language/owner-cache.test.ts: after assignOwner, closeRaw and a self-CPI that assigns it). Only programs that
88
+ make such views carry the cache (`TS_OWNER_CACHE`, a pointer in TsParams); their generated C changes (SPL Stake
89
+ Pool, Raydium AMM v4, Phoenix and the test fixtures that use views), and their tests pass unchanged.
90
+ - Faster: a RedBlackTree walk (`for (const e of tree)`, `tree.reversed()`) checks each node's index against the
91
+ capacity once, when it steps onto the node, instead of three times, and keeps its stack by pointer: 59 → 40 CU per
92
+ node for a walk summing a field of a 400-order book (test/language/phx-costs.test.ts; 18 CU less per node read-only).
93
+ The same panics at the same points on a damaged tree (an index past the capacity, a cycle filling the stack; both
94
+ now tested). Changes the generated C of programs that walk a tree (Phoenix, test/fixtures/rbtree.ts and
95
+ rbtree-api.ts).
96
+ - New: `tree.removeAt(index)` on a RedBlackTree removes the node at that index (from `addrOf`, or a node's `.index`
97
+ from `min` / `max` / a walk) with exactly the writes `remove(node.key)` makes, without searching the tree a second
98
+ time: Phoenix's cancel finds the order, checks whose it is, then removes it (691 → 547 CU in
99
+ test/language/phx-costs.test.ts). It gives the removed value, or null for index 0 or a node in no tree (a freed one,
100
+ which is left as it is); past the capacity it panics as `nodeAt` does. The lib-sokoban trace replay runs a second
101
+ time with every `remove(key)` as `removeAt(addrOf(key))`, and the bytes after each operation are still the crate's
102
+ (test/verification/rbtree-trace.test.ts).
103
+ - New: room beyond one 4 KiB stack frame. `/** @noinline */` on a helper keeps it a C function of its own, so its
104
+ locals get their own frame instead of the instruction's it would be inlined into (3 to 5 CU per call);
105
+ `/** @heap */` on an instruction's list or struct local keeps it on the heap (one allocation per declaration,
106
+ reused by a loop; 17 to 19 CU). A native port's entry holding a 1,284-byte log buffer could not also build a second
107
+ one, or the order ids after its recorder's last CPI (test/fixtures/frames.ts: 4,672 bytes inlined). The frame-size
108
+ error now lists the biggest locals from clang's frame layout (names and the source line near each; unnamed slots
109
+ with the locals of the helpers inlined there) and names both remedies (test/language/stack-limit.test.ts).
110
+ - Language: plain type aliases, `type Price = u64` (or `Pubkey`, a struct, `FixedVec<u8, 32>`, `Point | null`, another
111
+ alias), replaced by the type they name wherever they are used, so layouts and the IDL are the type's own; exported
112
+ or not, imported from other files (the aliased type keeps its own file's import names). Every `type X = …` was taken
113
+ for a data enum, and a union of named types (`type Event = Fill | Place`) failed with "each variant is an object
114
+ type"; it now says to list the variants as object types or alias one type. Generic aliases and `null` among a data
115
+ enum's variants are refused with what to write instead (test/language/aliases.test.ts).
116
+ - New: `const [address, bump] = findProgramAddressWithBump(seeds, program)`, Rust's `let (address, bump) =
117
+ Pubkey::find_program_address(…)`: the canonical address and its bump from one search, where `findProgramAddress`
118
+ and `findProgramAddressBump` searched twice (453 to 2,118 CU saved in test/language/pda-derivation.test.ts,
119
+ depending on how many bumps the search tries). `[, bump]` keeps only the bump; any other use is a compile error
120
+ showing the form.
121
+ - Language: a read-only `FixedVec<T, N>` (or `Vec<T>`) helper parameter takes the caller's own lists, as the language
122
+ reference said helpers do: a local FixedVec, a FixedVec field of a local struct or of account data, passed as a view
123
+ of its elements by pointer (nothing copied; a list in account data is copied first when the helper also takes
124
+ accounts, as a struct argument is). It was refused ("expected a Vec<u8> instruction argument"), so ports wrote the
125
+ helper with `Inout<T>`. A list with room for more than N elements is refused with the parameter to declare, and a
126
+ list given for an `Inout` parameter of the same call too (test/language/list-params.test.ts).
127
+ - Faster: a local `FixedVec` is set up in about constant compute units. `fixedVec([])` of 1280 bytes zeroed the list
128
+ twice (1,436 CU in test/language/fixedvec-setup.test.ts, now 152 with the rest of the instruction); `fixedVec([15n])`
129
+ also built and copied a temporary (3,216 → 155); a FixedVec field in a struct literal zeroed and copied a temporary,
130
+ doubling the stack (2,571 → 153). The free slots are now zeroed once, by the memset syscall from 128 bytes
131
+ (`ts_memzero_bulk`), and the elements are written in place; `list = fixedVec([…])` still builds in a temporary (its
132
+ elements may read the old list) but zeroes and copies it with the syscalls. The free slots stay zero, since a list's
133
+ whole layout is copied into account data and events. Changes the generated C of programs with local FixedVecs
134
+ (Phoenix, SPL Stake Pool, Marginfi, coral multisig, favorites and seven test fixtures), whose tests pass unchanged.
135
+ - New: `const ERROR_LOG_PREFIX = null` / `const PROGRAM_ERROR_LOG_PREFIX = null`: failures return their error and log
136
+ nothing, as a native program's do when its own checks already logged (Phoenix). `ERROR_LOG_PREFIX = null` covers
137
+ `require(…, MyError.X)` and codes computed at run time, `PROGRAM_ERROR_LOG_PREFIX = null` built-in ProgramErrors
138
+ (`require(…, ProgramError.X)`, `loadBorsh`, views) and `programAt` / `sysvarAt`. With `""` a failure still logged
139
+ "Program log: " plus the message; now it costs 105 to 124 CU less (test/language/quiet-errors.test.ts). Only these
140
+ two constants may be `null`. Programs that do not use it compile to the same C.
141
+ - Language: `Inout<T>` helper parameters, Rust's `&mut T`. `function addEvent(rec: Inout<Recorder>, e: Event): void`
142
+ gets the caller's place itself (a pointer, never a copy) and may change it; the caller sees the writes after the
143
+ call, as JS shares an object passed to a function. `T` is a fixed-size struct, `FixedArray<T, N>` or
144
+ `FixedVec<T, N>` (`push` / `pop` / `clear` included); the argument is a writable place: a local struct or list, a
145
+ `loadBorsh` local, a field of a `Mut<T>` account or of a `loadRawMut` view, a list element, another `Inout`
146
+ parameter. Until now helpers could only change accounts (`Mut<T>`), so ports inlined their mutating helpers (an
147
+ order book's matching engine and event recorder cannot sensibly be inlined). At each call no other argument may
148
+ share storage with an Inout one (two elements of one list count as one place), an element of a Vec or BigVec is
149
+ refused when the call may move it, and a reference into the place read after the call is refused; places that may
150
+ be one account only at run time (two `Dup` accounts, two `loadRawMut` views under `NATIVE_ACCOUNT_WRITES`) are
151
+ compared before the call (2040). Integers, Pubkeys, strings and Options are refused with a hint (JS copies values
152
+ too: return the new one, or keep it in a struct). About the compute units of the same code written inline
153
+ (test/language/inout.test.ts). Writing to a read-only helper parameter now says to declare it `Inout<T>`.
154
+ docs/language.md (`Inout<T>` parameters), docs/stability.md (Experimental; the open edge of helpers taking a
155
+ writable struct that is not an account is settled). Programs that do not use it compile to the same C.
156
+ - New: `loadRawAt<T>(acct, offset)` / `loadRawMutAt<T>(…)`, a native account's struct at a byte offset known at run
157
+ time, and `rawArrayAt<T>(acct, offset, capacity)` / `rawArrayMutAt<T>(…)`, a run-time number of elements in place
158
+ (`get`, `set`, `.length`, `for … of`, the list methods). Bounds checked once when made (ProgramError::AccountDataTooSmall,
159
+ overflow included); owner, writability and claim as `loadRaw` / `loadRawMut`.
160
+ - New: `rbTreeAt<K, V>(acct, offset, capacity, compare?)` / `rbTreeMutAt`, lib-sokoban 0.3's `RedBlackTree<K, V, N>`
161
+ over account bytes, byte for byte (Phoenix's order books and seats): `get`, `insert`, `remove`, `min`, `max`,
162
+ `addrOf`, `nodeAt`, `initialize`, `length`, `capacity`, `for … of` and `reversed()`. A comparator function orders
163
+ the keys (called as `compare(searched, node)`), or Rust's derived order. Replayed against the crate itself with
164
+ identical bytes after every operation: the committed test's 21,650 recorded operations (seeds 1–3, capacities 1 to
165
+ 4096, strides 32, 64 and 144; test/verification/rbtree/regenerate.sh), and, with the previous trace generator, a
166
+ one-off run of 1,020,000 (capacities 1 to 512). sokoban's panics are logged as solana-program up to 1.17 logs a
167
+ panic, with sokoban's messages and locations. Faster than the crate built with cargo-build-sbf at 4,096 entries
168
+ (get 215 CU against 384, insert 595 / 742, remove 355 / 618).
169
+ - Native entries set their own return data and log compute units: `setReturnData(bytes)` (Rust's `set_return_data`,
170
+ from a list of u8: a local `FixedVec<u8, N>`, account data, the instruction data or a slice) in a `@fallback` entry,
171
+ its helpers and void instructions, and `logComputeUnits()` (`sol_log_compute_units`, the runtime's "Program
172
+ consumption: N units remaining"), which were only emitted under `--profile`. An instruction that returns a value
173
+ refuses `setReturnData` (its return value is its return data). Checked against the lines the Phoenix v1 binary
174
+ writes.
175
+ - Native account lifecycle on remaining accounts and `AccountInfo` parameters: `closeRaw(account, receiver)` (Phoenix's
176
+ Tombstone: lamports to the receiver, owner to the System Program, length to 0, in that order and without zeroing the
177
+ data, ending as Phoenix's own Tombstone ends), `assignOwner(account, owner)` (`AccountInfo::assign`), and
178
+ `resizeAccount` on remaining accounts (the 10 KiB growth limit against the size the entrypoint records when the
179
+ instruction starts, as solana_program 1.14 records it). Checked writable, passed once and owned by this program, or
180
+ left to the runtime under `NATIVE_ACCOUNT_WRITES`.
181
+ - Byte builders on `FixedVec<u8, N>` (a local list or one in account data), for byte strings a native program builds by
182
+ hand: `pushLE(x)` (an integer at its width), `pushKey(key)`, `pushBorsh(value)` (Borsh, with the codecs `invoke`,
183
+ events and `storeBorsh` use; object literals take their type, `pushBorsh<Header>({ … })`), `setLE(offset, x)` and
184
+ `truncate(n)`, each bounds-checked (5104) with the length moved only when everything fit. Phoenix's event recorder
185
+ written with them sends the same batches, byte for byte, as the Phoenix binary.
186
+ - Rust panics as solana-program 1.14 to 1.17 leave them: `export const PANIC_STYLE = "solana-1.14"` makes `panic(message,
187
+ location)` log `panicked at '<message>', <location>` and abort ("SBF program panicked"), and `PANIC_ON_OVERFLOW`'s
188
+ panics abort too; `panicsAt(location, expression)` makes the expression's checked arithmetic panic with Rust's
189
+ messages ("attempt to add with overflow", "attempt to divide by zero", …) at the original's location instead of
190
+ failing with 5100 / 5101, in either style. Checked line for line against the Phoenix v1 binary's panics (its
191
+ entrypoint's assertion, and its overflow and remainder checks in initialize.rs and quantities.rs).
192
+ - Fixed: a tree comparator returning an unsigned integer (`function cmp(a: u64, b: u64): u8`) was accepted and could
193
+ never report "less", so every search went one way and the tree was silently out of order. It is a compile error
194
+ naming the type; a comparator returns a signed integer (test/language/rbtree.test.ts).
195
+ - Fixed: two writable views of one account's bytes through `loadRawMutAt`, `rawArrayMutAt` or `rbTreeMutAt` passed as
196
+ two `Inout` arguments under `NATIVE_ACCOUNT_WRITES` were not compared at run time (only `loadRawMut` views were), so
197
+ overlapping places reached the helper. They are compared before the call as `loadRawMut` views are: 2040 when they
198
+ overlap (test/language/inout.test.ts, test/fixtures/inout-views.ts).
199
+ - Fixed: an `Inout` argument was compared at run time only with other `Inout` arguments, so a read-only argument that
200
+ is the same bytes (`h(a.s, b.s)` with two `Dup` accounts that are one, a place of a writable account beside a
201
+ read-only account that is the same, two native views) changed under the helper as it wrote. Every argument passed
202
+ in place is now compared with the `Inout` one when their roots may be one account (2040 when they overlap); calls
203
+ whose arguments cannot alias, and arguments copied for the call, are not compared, so no existing program changed
204
+ (test/language/inout.test.ts, test/fixtures/inout-share.ts).
205
+ - Fixed: a tree node bound any other way than directly (`const e = c ? t.min() : t.max()`, `const v = t.get(k)!`)
206
+ escaped the rule that a reference into a tree is not used after an `insert`; it compiled and could read a reused
207
+ node. It refers to the tree like the direct form (`"e" still refers to t`), and binding one with `let` is refused
208
+ (test/language/rbtree.test.ts).
209
+ - Fixed: a typed constant kept the value folded without its type, so `const T: u8 = ~1n` failed with "-2 does not fit
210
+ in u8" although `~` within a u8 is 254. The value is the one folded in its type, and an untyped constant using it
211
+ gets that value; out-of-range results are still refused (test/language/port-syntax.test.ts).
212
+ - Fixed: a problem with an aliased type (`export type Buf = BigVec<u64>` used as an argument in another file) was
213
+ reported at the alias's declaration, once, instead of where it is used. Each use now gets its own report at the use
214
+ (test/language/aliases.test.ts).
215
+ - Fixed: a view made before `closeRaw` or `resizeAccount` of its account (`const v = t.get(1n)!`, a `rawArrayMutAt`)
216
+ could still be used after it, its bounds checked against the old length, so writes landed past the new end and reads
217
+ were stale. Using one after either, or after a helper that may close or resize an account it is given, is a compile
218
+ error saying to take the view again (test/language/raw-views.test.ts).
219
+ - Fixed: the rule that a `for … of` over a tree may not change its structure was kept per variable, so another view
220
+ of the same tree (`const t2 = rbTreeMutAt(…same account and offset…)`) could remove from it during the walk. It is
221
+ kept per account: no tree view of an account that may be the walked one's may insert, remove or initialize in the
222
+ loop, nor may a helper that takes accounts and makes an `rbTreeMutAt` view be called there
223
+ (test/language/rbtree.test.ts).
224
+ - Language: a reference into a local `FixedVec` (`const e = xs.get(0n)`) read after the element is replaced
225
+ (`xs.set(0n, { … })`, `pop`, `clear`) is refused as one into account data is (`"e" still refers to xs[]`); before, a
226
+ local FixedVec's elements had no storage path and the read compiled, seeing the new value where JS keeps the old
227
+ object (test/language/fixedvec.test.ts). Such messages also name a `@heap` list as the source does (they printed its C
228
+ name).
229
+ - Diagnostics: a node size that is not a multiple of 8 with a scalar value (`rbTreeMutAt<u64, u32>`) says to make the
230
+ value a struct with padding fields, not to add padding to `u32`; the stack-frame report after an overflowing build
231
+ reads clang's remarks without the 1 MiB output limit, which cut them short on large programs
232
+ (test/language/rbtree.test.ts).
233
+ - Programs that use none of the new features above compile to the same C as before; the "Faster" entries name the
234
+ programs whose generated C they change.
235
+
9
236
  ## 0.42.0 — 2026-11-09
10
237
 
11
238
  SPL Stake Pool ported in full, the native program behind most liquid staking tokens, from the tag a reproducible build
package/README.md CHANGED
@@ -185,8 +185,9 @@ If the build refuses something, the error points at the line and, for the usual
185
185
  `typesol port` starts from your program's IDL; [docs/case-study-escrow.md](docs/case-study-escrow.md) follows one
186
186
  program through the port.
187
187
  - Real programs checked against their mainnet binaries: [Showcase](#showcase-ports-checked-against-mainnet), with a
188
- case study each (Marginfi v2 in full: all 124 instructions, the same on 2,081 transactions; Raydium AMM v4, a native
189
- program, down to its log lines).
188
+ case study each (Marginfi v2 in full: all 124 instructions, the same on 2,081 transactions; Phoenix v1, a native
189
+ order book, the same on 3,575 transactions down to its event bytes; Raydium AMM v4, a native program, down to its log
190
+ lines).
190
191
  - To mainnet (wallet, cost, deploy, IDL, verification): [docs/mainnet.md](docs/mainnet.md).
191
192
  - With an AI coding agent: [docs/ai.md](docs/ai.md) (agent rules, [llms.txt](https://typesol.com/llms.txt), the MCP server).
192
193
 
@@ -215,11 +216,12 @@ Runtime failures point back to your source: `Error 6000 Unauthorized (counter.ts
215
216
  | --- | --- |
216
217
  | **Accounts** | `Signer`, `Account<T>`, `Mut<T>`, `Init<T>`, `InitIfNeeded<T>` (PDAs or keypair accounts, with Anchor's `space`; mints, token accounts and associated token accounts), `Zeroed<T>` (up to 10 MiB), optional accounts (`A \| null`), token accounts and mints, `SystemAccount`, programs, sysvars, and account groups (Anchor's composite accounts) |
217
218
  | **Constraints** | `HasOne`, `Seeds` (also from account fields and under another program; `pdaBump` like `ctx.bumps`), `CloseTo`, `Ata`, `Address`, `Owner`, `Executable`. They are checked before the body runs and recorded in the IDL, and take your own error as Anchor's `@ ErrorCode.X` does |
218
- | **Data** | `u8`…`u128`, `i8`…`i128`, `u256` (for computation), `f64` (as its bits, in events and accounts), `boolean`, `Pubkey`, `Hash`, nested structs, `FixedArray`, `FixedString`, `Option`, unit enums, data enums (discriminated unions), `Vec` that resizes its account, `FixedVec` lists anywhere, and Anchor's own byte layout (`@layout borsh`) to take over existing Anchor accounts and to pass, return and emit structs with String / Vec / Option fields as Anchor does |
219
- | **Control flow** | `if`, `for`, `for … of`, `while`, `switch` (with narrowing on data enums), ternaries, `??`, destructuring, helper functions (returning structs too, arrow functions, closures, function arguments, generics, functions chosen at run time), list callbacks (`some`, `find`, `reduce`, …, with `map` / `filter` chains that store nothing) across multiple files |
219
+ | **Data** | `u8`…`u128`, `i8`…`i128`, `u256` (for computation), `f64` (as its bits, in events and accounts), `boolean`, `Pubkey`, `Hash`, nested structs, `FixedArray`, `FixedString`, `Option`, unit enums, data enums (discriminated unions), type aliases (`type Price = u64`), `Vec` that resizes its account, `FixedVec` lists anywhere, and Anchor's own byte layout (`@layout borsh`) to take over existing Anchor accounts and to pass, return and emit structs with String / Vec / Option fields as Anchor does |
220
+ | **Control flow** | `if`, `for`, `for … of`, `while`, `switch` (with narrowing on data enums), ternaries, `??`, destructuring, helper functions (returning structs too, changing the caller's structs and lists through `Inout<T>`, arrow functions, closures, function arguments, generics, functions chosen at run time), list callbacks (`some`, `find`, `reduce`, …, with `map` / `filter` chains that store nothing) across multiple files |
220
221
  | **CPIs** | System, SPL Token, Token-2022 (including extension reads, metadata and token groups), ATA, Memo, Stake, Metaplex Token Metadata, Core, Bubblegum. Generic `invoke` with PDA signing (one or several PDAs per call), return data, and typed bindings generated from any Anchor IDL (`typesol cpi`) |
221
222
  | **Events** | `emit` (log-based) and `emitCpi` (Anchor `emit_cpi!`, through a self-CPI) |
222
223
  | **Crypto & oracles** | `sha256`, `keccak256`, Merkle proofs, Ed25519 and secp256k1 signature checks, Pyth pull oracle, Switchboard feeds and verifiable randomness |
224
+ | **Native programs** | a `@fallback` entry over the raw instruction data and accounts by position, Borsh accounts (`loadBorsh`), views of account bytes in place (also at offsets known only at run time) and lib-sokoban's red-black tree over them, byte builders (`pushLE`, `pushBorsh`, …), return data, `closeRaw`, and Rust's panics and overflow messages at the original's source locations |
223
225
  | **Interfaces** | custom discriminators (`@discriminator`), so a TypeSOL program can be a Token-2022 transfer hook, with extra accounts (ExtraAccountMetaList) |
224
226
 
225
227
  The full reference, with every type, check and built-in, is in [docs/language.md](docs/language.md).
@@ -341,10 +343,10 @@ Details are in [docs/testing.md](docs/testing.md).
341
343
 
342
344
  ### Showcase: ports checked against mainnet
343
345
 
344
- [`showcase/`](showcase) holds programs ported from Anchor and checked against the binaries deployed on mainnet (same
345
- outcomes, account bytes and events; [`showcase/test`](showcase/test)), and the ports of all 46
346
+ [`showcase/`](showcase) holds Anchor and native programs ported and checked against the binaries deployed on mainnet
347
+ (same outcomes, account bytes and events; [`showcase/test`](showcase/test)), and the ports of all 46
346
348
  [solana-developers/program-examples](showcase/program-examples/README.md).
347
- Case studies: [Marginfi v2](docs/case-study-marginfi.md), [SPL Stake Pool](docs/case-study-spl-stake-pool.md), [Raydium AMM v4](docs/case-study-raydium-amm.md), [Raydium CLMM](docs/case-study-raydium-clmm.md),
349
+ Case studies: [Marginfi v2](docs/case-study-marginfi.md), [Phoenix v1](docs/case-study-phoenix.md), [SPL Stake Pool](docs/case-study-spl-stake-pool.md), [Raydium AMM v4](docs/case-study-raydium-amm.md), [Raydium CLMM](docs/case-study-raydium-clmm.md),
348
350
  [Raydium CP-Swap](docs/case-study-raydium-cp-swap.md), [Jito MEV](docs/case-study-jito-mev.md),
349
351
  [coral-xyz/multisig](docs/case-study-multisig.md), [an Anchor escrow](docs/case-study-escrow.md).
350
352
 
@@ -354,6 +356,7 @@ Case studies: [Marginfi v2](docs/case-study-marginfi.md), [SPL Stake Pool](docs/
354
356
  | [`raydium-clmm/`](showcase/mainnet/raydium-clmm) | Raydium CLMM in full: concentrated-liquidity positions as NFTs, swaps and multi-hop routes across tick arrays, limit orders, rewards, dynamic fees, u256 math |
355
357
  | [`jito-mev/`](showcase/mainnet/jito-mev) | Jito's tip payment, tip distribution and priority fee distribution: tips paid out per leader, Merkle-proof claims, epochs and expiry |
356
358
  | [`marginfi/`](showcase/mainnet/marginfi) | Marginfi v2 in full, all 124 instructions: I80F48 fixed-point arithmetic, zero-copy accounts, oracles (Pyth, Switchboard, staked SOL, Scope, venue exchange rates), the risk engine, liquidation and bankruptcy, flash loans, orders, rebalances, and the Solend, Kamino, Drift and JupLend banks |
359
+ | [`phoenix/`](showcase/mainnet/phoenix) | Phoenix v1, Ellipsis Labs' on-chain limit order book and a native program, in full, all 28 instructions: price-time matching over lib-sokoban red-black trees in one market account, every order type, self-trade behaviours, time in force, eviction, cancels, seats and fees, its events as Log self-CPIs byte for byte |
357
360
  | [`spl-stake-pool/`](showcase/mainnet/spl-stake-pool) | SPL Stake Pool in full, all 27 instructions, a native program and the one behind most liquid staking tokens: pools of stake across up to 20,000 validators, SOL and stake deposits and withdrawals, rebalancing over epochs, fees and authorities, token metadata |
358
361
  | [`raydium-amm/`](showcase/mainnet/raydium-amm) | Raydium AMM v4, the original constant-product AMM and a native (non-Anchor) program, in full: pool creation, deposits and withdrawals, the v1 and v2 swaps, P&L and administration, down to its log records and panics |
359
362
  | [`multisig.ts`](showcase/mainnet/multisig/multisig.ts) | coral-xyz/multisig: stored instructions run with `invokeInstruction`, a PDA signing, Anchor's Borsh accounts |