@typesol/cli 0.44.0 → 0.45.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 (47) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/NOTICE +14 -1
  3. package/README.md +52 -10
  4. package/SECURITY.md +1 -1
  5. package/dist/cli.js +194 -48
  6. package/dist/compiler/emit/alias.d.ts +16 -2
  7. package/dist/compiler/emit/alias.js +62 -4
  8. package/dist/compiler/emit/calls.js +15 -7
  9. package/dist/compiler/emit/cpi-core.d.ts +6 -0
  10. package/dist/compiler/emit/cpi-core.js +18 -5
  11. package/dist/compiler/emit/create.js +19 -11
  12. package/dist/compiler/emit/function.js +5 -5
  13. package/dist/compiler/emit/metaplex.js +17 -4
  14. package/dist/compiler/emit/token.js +64 -39
  15. package/dist/compiler/index.d.ts +51 -1
  16. package/dist/compiler/index.js +17 -2
  17. package/dist/compiler/toolchain.d.ts +23 -0
  18. package/dist/compiler/toolchain.js +128 -8
  19. package/dist/tools/docker.d.ts +183 -0
  20. package/dist/tools/docker.js +442 -0
  21. package/dist/tools/doctor.d.ts +3 -0
  22. package/dist/tools/doctor.js +12 -0
  23. package/dist/workspace.d.ts +2 -1
  24. package/dist/workspace.js +33 -6
  25. package/docker/Dockerfile +163 -0
  26. package/docker/deps/0.43.0.lock.json +1206 -0
  27. package/docker/deps/0.44.0.lock.json +1206 -0
  28. package/docker/deps/0.44.1.lock.json +1206 -0
  29. package/docker/deps/0.45.0.lock.json +1206 -0
  30. package/docs/architecture.md +13 -5
  31. package/docs/audit.md +54 -7
  32. package/docs/cli.md +31 -4
  33. package/docs/errors.md +1 -1
  34. package/docs/language.md +6 -4
  35. package/docs/mainnet.md +86 -6
  36. package/docs/security-model.md +47 -12
  37. package/docs/stability.md +62 -3
  38. package/docs/testing.md +49 -2
  39. package/docs/troubleshooting.md +46 -0
  40. package/llms-full.txt +283 -34
  41. package/package.json +3 -1
  42. package/releases/0.43.0.json +669 -0
  43. package/releases/0.44.0.json +672 -0
  44. package/releases/0.44.1.json +672 -0
  45. package/runtime/LICENSE-compiler-builtins.txt +275 -0
  46. package/runtime/typesol_builtins.c +484 -0
  47. package/runtime/typesol_rt.h +8 -5
@@ -0,0 +1,484 @@
1
+ /*
2
+ * The compiler builtins a TypeSOL program can call, compiled with the program's clang and linked into every program
3
+ * in place of platform-tools' compiler-builtins Rust library. That library is built separately for each platform-tools
4
+ * host package (macOS, Linux arm64, Linux x86_64): the functions have the same instructions in each, but each build
5
+ * splits them into differently numbered archive members, so the linker laid out the ones a program called (128-bit or
6
+ * signed division, which pull in shared helpers) in another order and the program's calls had other offsets. These
7
+ * definitions are compiled from this file by the clang that compiles the program, after the program's object, so the
8
+ * binary depends on the clang and this source only.
9
+ *
10
+ * clang emits a call to these where SBF has no instruction for the operation: 128-bit multiplication, division and
11
+ * variable shifts, and (SBPF v0 and v1) signed 64-bit division. The set is every symbol C integer code can reference,
12
+ * for SBPF v0, v1 and v2 (test/language/builtins.test.ts checks it on every operator of every width).
13
+ *
14
+ * Two kinds of definition:
15
+ * - Division (__udivti3, __umodti3, __divti3, __modti3, __divdi3, __moddi3) in C below, taking the shortest route for
16
+ * the operands' sizes (one 64-bit division when both fit in 64 bits, three for a divisor below 2^32, the 64-bit
17
+ * division for signed 64-bit values, where compiler-builtins divides bit by bit), so they cost no more compute units
18
+ * than compiler-builtins' versions on any input measured, and fewer on most.
19
+ * - Multiplication and shifts (__multi3, __ashlti3, __lshrti3, __ashrti3) as assembly: the instructions
20
+ * compiler-builtins' build of them has for that SBPF version (https://github.com/rust-lang/compiler-builtins,
21
+ * licensed "MIT AND Apache-2.0 WITH LLVM-exception AND (MIT OR Apache-2.0)"; its LICENSE.txt is
22
+ * runtime/LICENSE-compiler-builtins.txt, and NOTICE says what is taken), one for one, so a program that calls only
23
+ * these links to the same bytes and costs the same compute units as before. clang compiles the equivalent C to
24
+ * other register choices, one to four units dearer per shift. The exception is __multi3 on SBPF v1 and v2 (whose
25
+ * stack frames work differently), in C, which costs less there: on v1 a program that calls __multi3 (128-bit or
26
+ * checked 64-bit multiplication) links to other bytes than with compiler-builtins.
27
+ *
28
+ * Rules for the C: no 128-bit multiplication, division or variable shift (each would call one of these functions,
29
+ * itself included); 128-bit values are taken apart into 64-bit halves and put together with constant shifts, which are
30
+ * register moves. Each function has the calling convention clang uses for the libcall (a 128-bit result through a
31
+ * pointer in r1, a 128-bit argument in two registers, the shift amount in one), which is that of its C signature.
32
+ *
33
+ * Division by zero: every division TypeSOL emits checks its divisor first and fails with TS_ERR_DIV_ZERO, so none of
34
+ * these is called with a zero divisor. If one were, it divides by zero with the 64-bit instruction, which the VM stops
35
+ * with its division-by-zero error (compiler-builtins leaves that case undefined).
36
+ */
37
+
38
+ typedef unsigned long long ts_u64;
39
+ typedef long long ts_i64;
40
+ typedef unsigned __int128 ts_u128;
41
+ typedef __int128 ts_i128;
42
+
43
+ #define TS_BUILTIN __attribute__((visibility("hidden")))
44
+ #define TS_LO(x) ((ts_u64)(x))
45
+ #define TS_HI(x) ((ts_u64)((ts_u128)(x) >> 64))
46
+ #define TS_MK(hi, lo) (((ts_u128)(ts_u64)(hi) << 64) | (ts_u64)(lo))
47
+ #define TS_M32 0xffffffffull
48
+
49
+ #if !defined(TS_SBPF_V0) && !defined(TS_SBPF_V1) && !defined(TS_SBPF_V2)
50
+ #error "compile with -DTS_SBPF_V0, -DTS_SBPF_V1 or -DTS_SBPF_V2 (builtinsCflags in src/compiler/toolchain.ts)"
51
+ #endif
52
+
53
+ /* Leading zeros of a nonzero 64-bit value: a binary search (SBF has no count-leading-zeros instruction). */
54
+ static inline __attribute__((always_inline)) ts_u64 ts_clz64(ts_u64 x) {
55
+ ts_u64 n = 0;
56
+ if ((x >> 32) == 0) n += 32, x <<= 32;
57
+ if ((x >> 48) == 0) n += 16, x <<= 16;
58
+ if ((x >> 56) == 0) n += 8, x <<= 8;
59
+ if ((x >> 60) == 0) n += 4, x <<= 4;
60
+ if ((x >> 62) == 0) n += 2, x <<= 2;
61
+ if ((x >> 63) == 0) n += 1;
62
+ return n;
63
+ }
64
+
65
+ /* a * b as 128 bits: SBPF v2's high-half multiply, else from 32-bit halves (the 64-bit multiply keeps the low half). */
66
+ static inline __attribute__((always_inline)) ts_u64 ts_mul_wide(ts_u64 a, ts_u64 b, ts_u64 *hi) {
67
+ #ifdef TS_SBPF_V2
68
+ ts_u128 p = (ts_u128)a * b; /* mul64 and uhmul64: no __multi3 on v2 */
69
+ *hi = TS_HI(p);
70
+ return TS_LO(p);
71
+ #else
72
+ ts_u64 a0 = a & TS_M32, a1 = a >> 32, b0 = b & TS_M32, b1 = b >> 32;
73
+ ts_u64 p00 = a0 * b0, p01 = a0 * b1, p10 = a1 * b0, p11 = a1 * b1;
74
+ ts_u64 mid = (p00 >> 32) + (p01 & TS_M32) + (p10 & TS_M32); /* below 3 * 2^32 */
75
+ *hi = p11 + (p01 >> 32) + (p10 >> 32) + (mid >> 32);
76
+ return (p00 & TS_M32) | (mid << 32);
77
+ #endif
78
+ }
79
+
80
+ /*
81
+ * (u1:u0) / v for u1 < v, v normalized (its top bit set): the quotient (which fits in 64 bits) and the remainder.
82
+ * Knuth's algorithm D on 32-bit digits, as Hacker's Delight's divlu: each quotient digit is estimated from the top two
83
+ * digits by one 64-bit division and corrected at most twice.
84
+ */
85
+ static inline __attribute__((always_inline)) ts_u64 ts_divlu_norm(ts_u64 u1, ts_u64 u0, ts_u64 v, ts_u64 *r) {
86
+ const ts_u64 b = 1ull << 32;
87
+ ts_u64 vn1 = v >> 32, vn0 = v & TS_M32;
88
+ ts_u64 un1 = u0 >> 32, un0 = u0 & TS_M32;
89
+ ts_u64 q1 = u1 / vn1, rhat = u1 - q1 * vn1;
90
+ while (q1 >= b || q1 * vn0 > ((rhat << 32) | un1)) {
91
+ q1 -= 1;
92
+ rhat += vn1;
93
+ if (rhat >= b) break;
94
+ }
95
+ ts_u64 un21 = (u1 << 32) + un1 - q1 * v;
96
+ ts_u64 q0 = un21 / vn1;
97
+ rhat = un21 - q0 * vn1;
98
+ while (q0 >= b || q0 * vn0 > ((rhat << 32) | un0)) {
99
+ q0 -= 1;
100
+ rhat += vn1;
101
+ if (rhat >= b) break;
102
+ }
103
+ *r = (un21 << 32) + un0 - q0 * v;
104
+ return (q1 << 32) | q0;
105
+ }
106
+
107
+ /* a / b and a % b, unsigned 128-bit. A zero b divides by zero with the 64-bit instruction (see the top). */
108
+ static inline __attribute__((always_inline)) ts_u128 ts_udivmod128(ts_u128 a, ts_u128 b, ts_u128 *rem) {
109
+ ts_u64 ah = TS_HI(a), al = TS_LO(a), bh = TS_HI(b), bl = TS_LO(b);
110
+ if (bh == 0) {
111
+ if (ah == 0) {
112
+ /* Both fit in 64 bits: one division. */
113
+ *rem = al % bl;
114
+ return al / bl;
115
+ }
116
+ if ((bl >> 32) == 0) {
117
+ /* A divisor below 2^32: short division, 64 then 32 then 32 bits of the dividend. */
118
+ ts_u64 qh = ah / bl, r = ah % bl;
119
+ ts_u64 mid = (r << 32) | (al >> 32);
120
+ ts_u64 q1 = mid / bl;
121
+ r = mid % bl;
122
+ ts_u64 lo = (r << 32) | (al & TS_M32);
123
+ ts_u64 q0 = lo / bl;
124
+ *rem = lo % bl;
125
+ return TS_MK(qh, (q1 << 32) | q0);
126
+ }
127
+ /* A 64-bit divisor: the high quotient word by one division, the low one from (ah % bl):al. */
128
+ ts_u64 qh = 0, r1 = ah;
129
+ if (ah >= bl) {
130
+ qh = ah / bl;
131
+ r1 = ah % bl;
132
+ }
133
+ ts_u64 s = ts_clz64(bl), r;
134
+ ts_u64 u1 = s ? (r1 << s) | (al >> (64 - s)) : r1;
135
+ ts_u64 q0 = ts_divlu_norm(u1, al << s, bl << s, &r);
136
+ *rem = r >> s;
137
+ return TS_MK(qh, q0);
138
+ }
139
+ /* b >= 2^64, so the quotient fits in 64 bits. */
140
+ if (ah < bh || (ah == bh && al < bl)) {
141
+ *rem = a;
142
+ return 0;
143
+ }
144
+ if ((ah ^ bh) <= (ah & bh)) {
145
+ /* The same top bit (the xor clears it, the and keeps it) and a >= b: the quotient is 1. */
146
+ *rem = TS_MK(ah - bh - (al < bl), al - bl);
147
+ return 1;
148
+ }
149
+ ts_u64 da = ts_clz64(ah), db = ts_clz64(bh), q, r;
150
+ if (db - da < 32) {
151
+ /*
152
+ * The top 64 bits of a over the same bits of b (at least 2^32): the quotient or one more than it, as in
153
+ * compiler-builtins' "two possibility" step. One less never overflows, so it is the start, corrected once.
154
+ */
155
+ ts_u64 sh = 64 - da;
156
+ ts_u64 duo = da ? (ah << da) | (al >> sh) : ah, div = da ? (bh << da) | (bl >> sh) : bh;
157
+ q = duo / div - 1;
158
+ } else {
159
+ /*
160
+ * Hacker's Delight's divu128: the top 64 bits of b (normalized) into a / 2 by Knuth's step, which gives the
161
+ * quotient or one more than it.
162
+ */
163
+ ts_u64 v1 = (bh << db) | (bl >> (64 - db)); /* db >= 32 here */
164
+ ts_u64 q1 = ts_divlu_norm(ah >> 1, (ah << 63) | (al >> 1), v1, &r);
165
+ q = q1 >> (63 - db);
166
+ if (q != 0) q -= 1;
167
+ }
168
+ /* a - q * b (q * b <= a), then one correction. */
169
+ ts_u64 ph, pl = ts_mul_wide(q, bl, &ph);
170
+ ph += q * bh;
171
+ ts_u64 rl = al - pl, rh = ah - ph - (al < pl);
172
+ if (rh > bh || (rh == bh && rl >= bl)) {
173
+ q += 1;
174
+ rh -= bh + (rl < bl);
175
+ rl -= bl;
176
+ }
177
+ *rem = TS_MK(rh, rl);
178
+ return q;
179
+ }
180
+
181
+ TS_BUILTIN ts_u128 __udivti3(ts_u128 a, ts_u128 b) {
182
+ ts_u128 r;
183
+ return ts_udivmod128(a, b, &r);
184
+ }
185
+
186
+ TS_BUILTIN ts_u128 __umodti3(ts_u128 a, ts_u128 b) {
187
+ ts_u128 r;
188
+ ts_udivmod128(a, b, &r);
189
+ return r;
190
+ }
191
+
192
+ /* Signed: the quotient rounds toward zero and the remainder has the dividend's sign, as in C (MIN / -1 wraps to MIN). */
193
+ TS_BUILTIN ts_i128 __divti3(ts_i128 a, ts_i128 b) {
194
+ ts_u128 ua = a < 0 ? (ts_u128)0 - (ts_u128)a : (ts_u128)a, ub = b < 0 ? (ts_u128)0 - (ts_u128)b : (ts_u128)b, r;
195
+ ts_u128 q = ts_udivmod128(ua, ub, &r);
196
+ return (ts_i128)((a < 0) != (b < 0) ? (ts_u128)0 - q : q);
197
+ }
198
+
199
+ TS_BUILTIN ts_i128 __modti3(ts_i128 a, ts_i128 b) {
200
+ ts_u128 ua = a < 0 ? (ts_u128)0 - (ts_u128)a : (ts_u128)a, ub = b < 0 ? (ts_u128)0 - (ts_u128)b : (ts_u128)b, r;
201
+ ts_udivmod128(ua, ub, &r);
202
+ return (ts_i128)(a < 0 ? (ts_u128)0 - r : r);
203
+ }
204
+
205
+ TS_BUILTIN ts_i64 __divdi3(ts_i64 a, ts_i64 b) {
206
+ ts_u64 ua = a < 0 ? 0 - (ts_u64)a : (ts_u64)a, ub = b < 0 ? 0 - (ts_u64)b : (ts_u64)b;
207
+ ts_u64 q = ua / ub;
208
+ return (ts_i64)((a < 0) != (b < 0) ? 0 - q : q);
209
+ }
210
+
211
+ TS_BUILTIN ts_i64 __moddi3(ts_i64 a, ts_i64 b) {
212
+ ts_u64 ua = a < 0 ? 0 - (ts_u64)a : (ts_u64)a, ub = b < 0 ? 0 - (ts_u64)b : (ts_u64)b;
213
+ ts_u64 r = ua % ub;
214
+ return (ts_i64)(a < 0 ? 0 - r : r);
215
+ }
216
+
217
+ /*
218
+ * The assembly. In: r1 the result's address, r2 and r3 the first operand's low and high halves, r4 and r5 the second's
219
+ * (__multi3) or r4 the shift amount, 0 to 127. Out: 16 bytes at r1. r6 to r9 and the stack frame at r10 are the
220
+ * callee's, as in any SBF function.
221
+ */
222
+ #ifdef TS_SBPF_V0
223
+ __asm__(
224
+ ".section .text.__multi3,\"ax\",@progbits\n"
225
+ ".hidden __multi3\n"
226
+ ".globl __multi3\n"
227
+ ".p2align 3\n"
228
+ ".type __multi3,@function\n"
229
+ "__multi3:\n"
230
+ " stxdw [r10 - 16], r3\n"
231
+ " stxdw [r10 - 8], r1\n"
232
+ " mov64 r1, r2\n"
233
+ " lsh64 r1, 32\n"
234
+ " rsh64 r1, 32\n"
235
+ " mov64 r7, r4\n"
236
+ " lsh64 r7, 32\n"
237
+ " rsh64 r7, 32\n"
238
+ " mov64 r6, r2\n"
239
+ " rsh64 r6, 32\n"
240
+ " mov64 r3, r7\n"
241
+ " mul64 r3, r1\n"
242
+ " mul64 r7, r6\n"
243
+ " mov64 r0, r4\n"
244
+ " rsh64 r0, 32\n"
245
+ " mov64 r9, r0\n"
246
+ " mul64 r9, r1\n"
247
+ " mov64 r1, r9\n"
248
+ " add64 r1, r7\n"
249
+ " mov64 r8, 1\n"
250
+ " jlt r1, r9, .Lmulti3_b0\n"
251
+ " mov64 r8, 0\n"
252
+ ".Lmulti3_b0:\n"
253
+ " mov64 r9, r1\n"
254
+ " lsh64 r9, 32\n"
255
+ " mov64 r7, r3\n"
256
+ " add64 r7, r9\n"
257
+ " mov64 r9, 1\n"
258
+ " jlt r7, r3, .Lmulti3_e8\n"
259
+ " mov64 r9, 0\n"
260
+ ".Lmulti3_e8:\n"
261
+ " ldxdw r3, [r10 - 8]\n"
262
+ " stxdw [r3 + 0], r7\n"
263
+ " rsh64 r1, 32\n"
264
+ " lsh64 r8, 32\n"
265
+ " or64 r8, r1\n"
266
+ " ldxdw r1, [r10 - 16]\n"
267
+ " mul64 r4, r1\n"
268
+ " mul64 r5, r2\n"
269
+ " add64 r5, r4\n"
270
+ " mul64 r0, r6\n"
271
+ " add64 r0, r5\n"
272
+ " add64 r0, r8\n"
273
+ " add64 r0, r9\n"
274
+ " stxdw [r3 + 8], r0\n"
275
+ " exit\n"
276
+ ".size __multi3, .-__multi3\n"
277
+ ".text\n");
278
+ #else
279
+ /* The low 128 bits of a * b (SBPF v1 and v2). */
280
+ TS_BUILTIN ts_u128 __multi3(ts_u128 a, ts_u128 b) {
281
+ ts_u64 al = TS_LO(a), bl = TS_LO(b), hi;
282
+ ts_u64 lo = ts_mul_wide(al, bl, &hi);
283
+ return TS_MK(hi + al * TS_HI(b) + TS_HI(a) * bl, lo);
284
+ }
285
+ #endif
286
+
287
+ #if defined(TS_SBPF_V0) || defined(TS_SBPF_V1)
288
+ /* SBPF v0 and v1 (compiler-builtins has the same instructions for both). */
289
+ __asm__(
290
+ ".section .text.__ashlti3,\"ax\",@progbits\n"
291
+ ".hidden __ashlti3\n"
292
+ ".globl __ashlti3\n"
293
+ ".p2align 3\n"
294
+ ".type __ashlti3,@function\n"
295
+ "__ashlti3:\n"
296
+ " mov64 r5, r4\n"
297
+ " and64 r5, 64\n"
298
+ " jne r5, 0, .Lashlti3_70\n"
299
+ " jeq r4, 0, .Lashlti3_90\n"
300
+ " mov64 r5, r4\n"
301
+ " and64 r5, 63\n"
302
+ " lsh64 r3, r5\n"
303
+ " neg64 r4\n"
304
+ " and64 r4, 63\n"
305
+ " mov64 r0, r2\n"
306
+ " rsh64 r0, r4\n"
307
+ " or64 r3, r0\n"
308
+ " lsh64 r2, r5\n"
309
+ " ja .Lashlti3_90\n"
310
+ ".Lashlti3_70:\n"
311
+ " and64 r4, 63\n"
312
+ " mov64 r3, r2\n"
313
+ " lsh64 r3, r4\n"
314
+ " mov64 r2, 0\n"
315
+ ".Lashlti3_90:\n"
316
+ " stxdw [r1 + 0], r2\n"
317
+ " stxdw [r1 + 8], r3\n"
318
+ " exit\n"
319
+ ".size __ashlti3, .-__ashlti3\n"
320
+ ".section .text.__lshrti3,\"ax\",@progbits\n"
321
+ ".hidden __lshrti3\n"
322
+ ".globl __lshrti3\n"
323
+ ".p2align 3\n"
324
+ ".type __lshrti3,@function\n"
325
+ "__lshrti3:\n"
326
+ " mov64 r5, r4\n"
327
+ " and64 r5, 64\n"
328
+ " jne r5, 0, .Llshrti3_78\n"
329
+ " jeq r4, 0, .Llshrti3_98\n"
330
+ " mov64 r5, r4\n"
331
+ " and64 r5, 63\n"
332
+ " rsh64 r2, r5\n"
333
+ " neg64 r4\n"
334
+ " and64 r4, 63\n"
335
+ " mov64 r0, r3\n"
336
+ " lsh64 r0, r4\n"
337
+ " or64 r0, r2\n"
338
+ " rsh64 r3, r5\n"
339
+ " mov64 r2, r0\n"
340
+ " ja .Llshrti3_98\n"
341
+ ".Llshrti3_78:\n"
342
+ " and64 r4, 63\n"
343
+ " rsh64 r3, r4\n"
344
+ " mov64 r2, r3\n"
345
+ " mov64 r3, 0\n"
346
+ ".Llshrti3_98:\n"
347
+ " stxdw [r1 + 0], r2\n"
348
+ " stxdw [r1 + 8], r3\n"
349
+ " exit\n"
350
+ ".size __lshrti3, .-__lshrti3\n"
351
+ ".section .text.__ashrti3,\"ax\",@progbits\n"
352
+ ".hidden __ashrti3\n"
353
+ ".globl __ashrti3\n"
354
+ ".p2align 3\n"
355
+ ".type __ashrti3,@function\n"
356
+ "__ashrti3:\n"
357
+ " mov64 r5, r4\n"
358
+ " and64 r5, 64\n"
359
+ " jne r5, 0, .Lashrti3_70\n"
360
+ " jeq r4, 0, .Lashrti3_98\n"
361
+ " mov64 r5, r4\n"
362
+ " neg64 r5\n"
363
+ " and64 r5, 63\n"
364
+ " mov64 r0, r3\n"
365
+ " lsh64 r0, r5\n"
366
+ " and64 r4, 63\n"
367
+ " rsh64 r2, r4\n"
368
+ " or64 r0, r2\n"
369
+ " mov64 r2, r0\n"
370
+ " ja .Lashrti3_90\n"
371
+ ".Lashrti3_70:\n"
372
+ " and64 r4, 63\n"
373
+ " mov64 r2, r3\n"
374
+ " arsh64 r2, r4\n"
375
+ " mov64 r4, 63\n"
376
+ ".Lashrti3_90:\n"
377
+ " arsh64 r3, r4\n"
378
+ ".Lashrti3_98:\n"
379
+ " stxdw [r1 + 0], r2\n"
380
+ " stxdw [r1 + 8], r3\n"
381
+ " exit\n"
382
+ ".size __ashrti3, .-__ashrti3\n"
383
+ ".text\n");
384
+ #else
385
+ /* SBPF v2: its 32-bit ALU forms (sub32 with immediate 0 is v2's negation). */
386
+ __asm__(
387
+ ".section .text.__ashlti3,\"ax\",@progbits\n"
388
+ ".hidden __ashlti3\n"
389
+ ".globl __ashlti3\n"
390
+ ".p2align 3\n"
391
+ ".type __ashlti3,@function\n"
392
+ "__ashlti3:\n"
393
+ " mov64 r5, r4\n"
394
+ " and32 w5, 64\n"
395
+ " jne r5, 0, .Lashlti3_v2_78\n"
396
+ " mov32 w5, w4\n"
397
+ " jeq r5, 0, .Lashlti3_v2_98\n"
398
+ " mov64 r5, r4\n"
399
+ " and32 w5, 63\n"
400
+ " lsh64 r3, r5\n"
401
+ " sub32 w4, 0\n"
402
+ " and32 w4, 63\n"
403
+ " mov64 r0, r2\n"
404
+ " rsh64 r0, r4\n"
405
+ " or64 r3, r0\n"
406
+ " lsh64 r2, r5\n"
407
+ " ja .Lashlti3_v2_98\n"
408
+ ".Lashlti3_v2_78:\n"
409
+ " and32 w4, 63\n"
410
+ " mov64 r3, r2\n"
411
+ " lsh64 r3, r4\n"
412
+ " mov64 r2, 0\n"
413
+ ".Lashlti3_v2_98:\n"
414
+ " stxdw [r1 + 0], r2\n"
415
+ " stxdw [r1 + 8], r3\n"
416
+ " exit\n"
417
+ ".size __ashlti3, .-__ashlti3\n"
418
+ ".section .text.__lshrti3,\"ax\",@progbits\n"
419
+ ".hidden __lshrti3\n"
420
+ ".globl __lshrti3\n"
421
+ ".p2align 3\n"
422
+ ".type __lshrti3,@function\n"
423
+ "__lshrti3:\n"
424
+ " mov64 r5, r4\n"
425
+ " and32 w5, 64\n"
426
+ " jne r5, 0, .Llshrti3_v2_80\n"
427
+ " mov32 w5, w4\n"
428
+ " jeq r5, 0, .Llshrti3_v2_a0\n"
429
+ " mov64 r5, r4\n"
430
+ " and32 w5, 63\n"
431
+ " rsh64 r2, r5\n"
432
+ " sub32 w4, 0\n"
433
+ " and32 w4, 63\n"
434
+ " mov64 r0, r3\n"
435
+ " lsh64 r0, r4\n"
436
+ " or64 r0, r2\n"
437
+ " rsh64 r3, r5\n"
438
+ " mov64 r2, r0\n"
439
+ " ja .Llshrti3_v2_a0\n"
440
+ ".Llshrti3_v2_80:\n"
441
+ " and32 w4, 63\n"
442
+ " rsh64 r3, r4\n"
443
+ " mov64 r2, r3\n"
444
+ " mov64 r3, 0\n"
445
+ ".Llshrti3_v2_a0:\n"
446
+ " stxdw [r1 + 0], r2\n"
447
+ " stxdw [r1 + 8], r3\n"
448
+ " exit\n"
449
+ ".size __lshrti3, .-__lshrti3\n"
450
+ ".section .text.__ashrti3,\"ax\",@progbits\n"
451
+ ".hidden __ashrti3\n"
452
+ ".globl __ashrti3\n"
453
+ ".p2align 3\n"
454
+ ".type __ashrti3,@function\n"
455
+ "__ashrti3:\n"
456
+ " mov64 r5, r4\n"
457
+ " and32 w5, 64\n"
458
+ " jne r5, 0, .Lashrti3_v2_78\n"
459
+ " mov32 w5, w4\n"
460
+ " jeq r5, 0, .Lashrti3_v2_a0\n"
461
+ " mov64 r5, r4\n"
462
+ " sub32 w5, 0\n"
463
+ " and32 w5, 63\n"
464
+ " mov64 r0, r3\n"
465
+ " lsh64 r0, r5\n"
466
+ " and32 w4, 63\n"
467
+ " rsh64 r2, r4\n"
468
+ " or64 r0, r2\n"
469
+ " mov64 r2, r0\n"
470
+ " ja .Lashrti3_v2_98\n"
471
+ ".Lashrti3_v2_78:\n"
472
+ " and32 w4, 63\n"
473
+ " mov64 r2, r3\n"
474
+ " arsh64 r2, r4\n"
475
+ " mov64 r4, 63\n"
476
+ ".Lashrti3_v2_98:\n"
477
+ " arsh64 r3, r4\n"
478
+ ".Lashrti3_v2_a0:\n"
479
+ " stxdw [r1 + 0], r2\n"
480
+ " stxdw [r1 + 8], r3\n"
481
+ " exit\n"
482
+ ".size __ashrti3, .-__ashrti3\n"
483
+ ".text\n");
484
+ #endif
@@ -2299,8 +2299,10 @@ static inline uint64_t ts_return_data_any(const TsAccount *program, uint8_t **ou
2299
2299
 
2300
2300
  /* A heap Vec (a Vec<T> in a @layout borsh struct, held on the heap while the instruction runs): room for at least
2301
2301
  `need` elements of `size` bytes, doubling as Rust's Vec does. Elements move when it grows (the compiler refuses
2302
- references into it that would outlive a push). Bounded by the heap; the account bounds it when it is packed (3004). */
2303
- typedef struct __attribute__((packed)) {
2302
+ references into it that would outlive a push). Bounded by the heap; the account bounds it when it is packed (3004).
2303
+ The generated code reads the Vec through its own struct type, of this layout: may_alias lets these accesses alias
2304
+ that type, so the build needs no -fno-strict-aliasing for the compiler to see the writes here. */
2305
+ typedef struct __attribute__((packed, may_alias)) {
2304
2306
  uint32_t len;
2305
2307
  uint32_t cap;
2306
2308
  uint8_t *items;
@@ -2967,10 +2969,11 @@ static inline uint64_t ts_init_extra_metas(TsParams *params, TsAccount *payer, T
2967
2969
  /*
2968
2970
  * ExtraAccountMetaList::update: rewrite an existing list (this program's PDA ["extra-account-metas", mint], holding the
2969
2971
  * execute discriminator), resizing it to `n` records. The payer tops it up to the rent of the new size when its
2970
- * lamports fall short, as the program-examples do before `resize`.
2972
+ * lamports fall short, as the program-examples do before `resize`. `entry_len` is the account's length when the
2973
+ * instruction started: the runtime's room for growth is 10 KiB past that, however the account was resized since.
2971
2974
  */
2972
2975
  static inline uint64_t ts_update_extra_metas(TsParams *params, TsAccount *payer, TsAccount *acct, const SolPubkey *mint, const uint8_t *entries,
2973
- uint32_t n) {
2976
+ uint32_t n, uint64_t entry_len) {
2974
2977
  SolSignerSeed seeds[2] = {{(const uint8_t *)"extra-account-metas", 19}, {(const uint8_t *)mint, 32}};
2975
2978
  SolPubkey pda;
2976
2979
  uint8_t bump;
@@ -2983,7 +2986,7 @@ static inline uint64_t ts_update_extra_metas(TsParams *params, TsAccount *payer,
2983
2986
  uint64_t rent;
2984
2987
  TS_TRY(ts_minimum_balance(new_len, &rent));
2985
2988
  if (rent > acct->lamports) TS_TRY(ts_system_transfer(params, payer, acct, rent - acct->lamports));
2986
- if (new_len > acct->data_len + MAX_PERMITTED_DATA_INCREASE) TS_FAIL(TS_ERR_REALLOC, "TypeSOL: account would grow more than 10 KiB in one instruction");
2989
+ if (new_len > entry_len + MAX_PERMITTED_DATA_INCREASE) TS_FAIL(TS_ERR_REALLOC, "TypeSOL: account would grow more than 10 KiB in one instruction");
2987
2990
  if (new_len > acct->data_len) ts_memzero(acct->data + acct->data_len, new_len - acct->data_len);
2988
2991
  acct->data_len = new_len;
2989
2992
  uint32_t len = 4 + 35 * n;