@amritk/nish-aarch64-linux 0.42.0 → 0.45.1

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 (124) hide show
  1. package/bin/nish +0 -0
  2. package/docs/AI.md +287 -129
  3. package/package.json +1 -1
  4. package/runtime/core/numbers.mjs +3 -1
  5. package/runtime/core/strings.mjs +90 -38
  6. package/runtime/core.d.ts +24 -0
  7. package/runtime/core.mjs +21 -0
  8. package/runtime/nish.d.ts +167 -24
  9. package/runtime/nish.mjs +7 -1
  10. package/runtime/runtime-cross.c +9 -0
  11. package/runtime/runtime-net.c +51 -13
  12. package/runtime/runtime-region.c +13 -0
  13. package/runtime/runtime-text.c +11 -0
  14. package/runtime/runtime-uring.c +83 -25
  15. package/runtime/runtime-wasm.c +3 -0
  16. package/runtime/runtime.c +329 -6
  17. package/runtime/sqlite/README.md +16 -3
  18. package/runtime/sqlite/nish-sqlite.c +940 -29
  19. package/scripts/build.sh +111 -29
  20. package/std/README.md +6 -6
  21. package/std/array.ts +10 -2
  22. package/std/bytes.ts +239 -26
  23. package/std/cli-args.ts +1072 -606
  24. package/std/cli-flags.ts +180 -98
  25. package/std/cli.ts +21 -13
  26. package/std/collections.ts +245 -127
  27. package/std/compress/checksum.ts +32 -37
  28. package/std/compress/deflate.ts +1102 -542
  29. package/std/compress/gzip.ts +290 -145
  30. package/std/compress/zlib.ts +57 -21
  31. package/std/crypto/aes.ts +153 -75
  32. package/std/crypto/base64url.ts +163 -39
  33. package/std/crypto/bcrypt-batch.ts +164 -90
  34. package/std/crypto/bcrypt.ts +185 -107
  35. package/std/crypto/chacha20poly1305.ts +84 -68
  36. package/std/crypto/ct.ts +9 -7
  37. package/std/crypto/ed25519.ts +64 -27
  38. package/std/crypto/hkdf.ts +105 -63
  39. package/std/crypto/hmac.ts +95 -89
  40. package/std/crypto/jwt.ts +248 -126
  41. package/std/crypto/p256.ts +758 -444
  42. package/std/crypto/p384.ts +20 -13
  43. package/std/crypto/pki-roots.ts +95 -38
  44. package/std/crypto/pki.ts +164 -60
  45. package/std/crypto/rsa.ts +266 -223
  46. package/std/crypto/scram.ts +141 -0
  47. package/std/crypto/sha1.ts +157 -57
  48. package/std/crypto/sha256.ts +502 -422
  49. package/std/crypto/sha512.ts +204 -135
  50. package/std/crypto/x509-random.ts +9 -3
  51. package/std/crypto/x509.ts +331 -171
  52. package/std/host/ring.ts +1 -1
  53. package/std/host/text.ts +1 -1
  54. package/std/json-equal.ts +35 -19
  55. package/std/json-format.ts +215 -108
  56. package/std/json-number.ts +126 -72
  57. package/std/json-pointer.ts +42 -13
  58. package/std/json-tokenizer.ts +498 -307
  59. package/std/json-typed.ts +115 -36
  60. package/std/json-value.ts +341 -152
  61. package/std/json.ts +300 -158
  62. package/std/net/buffer-pool.ts +17 -7
  63. package/std/net/dns-config.ts +427 -236
  64. package/std/net/dns-message.ts +114 -47
  65. package/std/net/dns-resolver.ts +736 -237
  66. package/std/net/dns.ts +205 -52
  67. package/std/net/fetch.ts +320 -184
  68. package/std/net/grpc.ts +948 -0
  69. package/std/net/handler.ts +1276 -218
  70. package/std/net/hpack.ts +395 -180
  71. package/std/net/http-compress.ts +502 -65
  72. package/std/net/http-fields.ts +85 -49
  73. package/std/net/http-server.ts +1764 -603
  74. package/std/net/http1-client-codec.ts +372 -161
  75. package/std/net/http1-codec.ts +665 -331
  76. package/std/net/http1-server.ts +881 -269
  77. package/std/net/http2-cleartext.ts +165 -95
  78. package/std/net/http2-frame.ts +232 -89
  79. package/std/net/http2-tls.ts +42 -12
  80. package/std/net/http2.ts +327 -101
  81. package/std/net/http3-frame.ts +68 -33
  82. package/std/net/http3-server.ts +672 -206
  83. package/std/net/http3.ts +669 -191
  84. package/std/net/oidc.ts +63 -24
  85. package/std/net/outbound.ts +207 -142
  86. package/std/net/postgres-async.ts +1223 -470
  87. package/std/net/postgres-carrier.ts +575 -372
  88. package/std/net/postgres.ts +1521 -632
  89. package/std/net/prefork.ts +254 -98
  90. package/std/net/protobuf.ts +1017 -0
  91. package/std/net/qpack.ts +143 -92
  92. package/std/net/quic-conn-ack.ts +104 -22
  93. package/std/net/quic-conn-cid.ts +66 -26
  94. package/std/net/quic-conn-params.ts +13 -7
  95. package/std/net/quic-datagram.ts +90 -27
  96. package/std/net/quic-frame.ts +324 -121
  97. package/std/net/quic-listener.ts +206 -91
  98. package/std/net/quic-packet.ts +289 -163
  99. package/std/net/quic-recovery.ts +279 -128
  100. package/std/net/quic-stream.ts +466 -167
  101. package/std/net/quic.ts +584 -258
  102. package/std/net/router.ts +450 -99
  103. package/std/net/serve.ts +661 -240
  104. package/std/net/static.ts +1458 -0
  105. package/std/net/tls/client.ts +140 -45
  106. package/std/net/tls/codec.ts +510 -260
  107. package/std/net/tls/record-client.ts +268 -76
  108. package/std/net/tls/record-server.ts +236 -79
  109. package/std/net/tls/record.ts +173 -47
  110. package/std/net/tls/schedule.ts +58 -39
  111. package/std/net/tls/ticket.ts +295 -103
  112. package/std/net/tls/verify.ts +1 -1
  113. package/std/net/tls-tcp.ts +218 -75
  114. package/std/net/tls.ts +260 -152
  115. package/std/net/upstream.ts +283 -86
  116. package/std/net/url.ts +277 -102
  117. package/std/net/websocket.ts +532 -209
  118. package/std/net/webtransport.ts +755 -436
  119. package/std/regex.ts +1659 -829
  120. package/std/sqlite.ts +325 -0
  121. package/std/sync/ring.ts +320 -156
  122. package/std/sync/shm.ts +53 -6
  123. package/std/text.ts +285 -135
  124. package/std/threads.ts +22 -2
@@ -48,15 +48,9 @@ const CRC32_TABLE_SIZE: i32 = 2048
48
48
  const CRC32_BRAIDS: i32 = 5
49
49
  const CRC32_BLOCK: i32 = 40
50
50
 
51
- /** The shortest input `Crc32.update` braids: two blocks, one braided and the last joined. */
52
- const CRC32_BRAID_MIN: i32 = 80
53
-
54
51
  /** zlib's `NMAX`: the most bytes Adler-32's sums take before they must be reduced. */
55
52
  const ADLER32_NMAX: i32 = 5552
56
53
 
57
- /** The Adler-32 modulus, the largest prime below 2^16 (RFC 1950 §9). */
58
- const ADLER32_BASE: i32 = 65521
59
-
60
54
  /**
61
55
  * The little-endian 64-bit word at `buf[p .. p + 8)`, which the caller has
62
56
  * checked. `p`'s range makes each `p + k` an `add nsw`, which lets LLVM load
@@ -133,7 +127,7 @@ export class Crc32 {
133
127
  const bits: u32[] = new Array<u32>(8)
134
128
  for (let k: i32 = 0; k < 8; k += 1) {
135
129
  for (let i: i32 = 0; i < 8; i += 1) {
136
- let c: u32 = uncheckedGet(t, k * 256 + (toI32(1) << i))
130
+ let c: u32 = uncheckedGet(t, k * 256 + ((toI32(1) << i) & 255))
137
131
  for (let z: i32 = 0; z < (CRC32_BRAIDS - 1) * 8; z += 1) {
138
132
  c = (c >>> 8) ^ uncheckedGet(t, toI32(c & 255))
139
133
  }
@@ -165,19 +159,15 @@ export class Crc32 {
165
159
  */
166
160
  update(crc: u32, buf: u8[], off: i32, len: i32): u32 {
167
161
  checksumWindow("Crc32.update", buf, off, len)
168
- const t: u32[] = this.table
169
- const bt: u32[] = this.braid
170
- if (toI32(t.length) !== CRC32_TABLE_SIZE || toI32(bt.length) !== CRC32_TABLE_SIZE) {
171
- panic("Crc32.update: the table is not its size")
172
- }
173
- return crc32Walk(t, bt, crc, buf, off, len)
162
+ return crc32Walk(this.table, this.braid, crc, buf, off, len)
174
163
  }
175
164
  }
176
165
 
177
166
  /**
178
167
  * `Crc32.update`'s loop: the CRC-32 of the bytes `crc` was the CRC of,
179
168
  * followed by `buf[off .. off + len)`, a window its one caller has checked,
180
- * as it has checked both tables' length. Natively the compiler puts the call
169
+ * over the two tables `Crc32`'s constructor built at their full size and
170
+ * nothing replaces. Natively the compiler puts the call
181
171
  * behind a branch on `nish_crc32_hw` and hands the same window to the
182
172
  * runtime's `nish_crc32_update`, which runs it on PCLMULQDQ or the ARMv8
183
173
  * CRC32 instructions (`src/kernels.ts`); a machine without them, a process
@@ -186,8 +176,13 @@ export class Crc32 {
186
176
  const crc32Walk = (t: u32[], bt: u32[], crc: u32, buf: u8[], off: i32, len: i32): u32 => {
187
177
  let c: u32 = ~crc
188
178
  let p: i32 = off
189
- const end: i32 = off + len
190
- if (len >= CRC32_BRAID_MIN) {
179
+ // The caller checked the window, so its end fits an i32; adding in i64
180
+ // says so to the prover, which does not carry that check across the call.
181
+ const end: i32 = toI32(toI64(off) + toI64(len))
182
+ // The shortest input braided is two blocks (80 bytes), one braided and
183
+ // the last joined; the guard and the divisor of `blocks` are literals, not
184
+ // `CRC32_BLOCK`, since the prover bounds `blocks` only when both are.
185
+ if (len >= 80) {
191
186
  // Braided (Kadatch and Jenkins, "Everything we know about CRC but
192
187
  // afraid to forget", 2010): five chains, each over every fifth 8-byte
193
188
  // word, so a step's table reads overlap the other four's instead of
@@ -196,18 +191,18 @@ const crc32Walk = (t: u32[], bt: u32[], crc: u32, buf: u8[], off: i32, len: i32)
196
191
  // its own word's place. The last block is taken one word at a time
197
192
  // with the plain table, each braid's register joining as its word
198
193
  // comes, which adds them into one.
199
- const blocks: i32 = len / CRC32_BLOCK
200
- const lastBlock: i32 = off + (blocks - 1) * CRC32_BLOCK
194
+ const blocks: i32 = len / 40
195
+ const lastBlock: i32 = toI32(toI64(off) + toI64(blocks - 1) * 40)
201
196
  let c1: u32 = 0
202
197
  let c2: u32 = 0
203
198
  let c3: u32 = 0
204
199
  let c4: u32 = 0
205
200
  // Each word's position is a local the loop condition bounds, which
206
201
  // is what lets it enter the loader's range without a check.
207
- let p1: i32 = p + 8
208
- let p2: i32 = p + 16
209
- let p3: i32 = p + 24
210
- let p4: i32 = p + 32
202
+ let p1: i32 = toI32(toI64(p) + 8)
203
+ let p2: i32 = toI32(toI64(p) + 16)
204
+ let p3: i32 = toI32(toI64(p) + 24)
205
+ let p4: i32 = toI32(toI64(p) + 32)
211
206
  while (
212
207
  p < lastBlock &&
213
208
  p >= 0 &&
@@ -215,11 +210,11 @@ const crc32Walk = (t: u32[], bt: u32[], crc: u32, buf: u8[], off: i32, len: i32)
215
210
  p2 >= 0 &&
216
211
  p3 >= 0 &&
217
212
  p4 >= 0 &&
218
- p4 <= 2147483639 &&
219
- p3 <= 2147483639 &&
220
- p2 <= 2147483639 &&
221
- p1 <= 2147483639 &&
222
- p <= 2147483639
213
+ p4 <= 2147483607 &&
214
+ p3 <= 2147483607 &&
215
+ p2 <= 2147483607 &&
216
+ p1 <= 2147483607 &&
217
+ p <= 2147483607
223
218
  ) {
224
219
  c = crc32Step(bt, c, checksumLoad64(buf, p))
225
220
  c1 = crc32Step(bt, c1, checksumLoad64(buf, p1))
@@ -242,7 +237,7 @@ const crc32Walk = (t: u32[], bt: u32[], crc: u32, buf: u8[], off: i32, len: i32)
242
237
  p3 <= 2147483639 &&
243
238
  p2 <= 2147483639 &&
244
239
  p1 <= 2147483639 &&
245
- p <= 2147483639
240
+ p <= 2147483607
246
241
  ) {
247
242
  c = crc32Step(t, c, checksumLoad64(buf, p))
248
243
  c = crc32Step(t, c ^ c1, checksumLoad64(buf, p1))
@@ -252,7 +247,7 @@ const crc32Walk = (t: u32[], bt: u32[], crc: u32, buf: u8[], off: i32, len: i32)
252
247
  p += CRC32_BLOCK
253
248
  }
254
249
  }
255
- const whole: i32 = end - (len & 7)
250
+ const whole: i32 = toI32(toI64(end) - toI64(len & 7))
256
251
  while (p < whole && p >= 0 && p <= 2147483639) {
257
252
  c = crc32Step(t, c, checksumLoad64(buf, p))
258
253
  p += 8
@@ -307,13 +302,12 @@ const adler32Walk = (adler: u32, buf: u8[], off: i32, len: i32): u32 => {
307
302
  let s1: u32 = adler & 0xffff
308
303
  let s2: u32 = adler >>> 16
309
304
  let p: i32 = off
310
- const end: i32 = off + len
305
+ // As in `crc32Walk`: the checked window's end, added in i64.
306
+ const end: i32 = toI32(toI64(off) + toI64(len))
311
307
  while (p < end) {
312
- let stop: i32 = p + ADLER32_NMAX
313
- if (stop > end) {
314
- stop = end
315
- }
316
- while (p + 4 <= stop) {
308
+ const reach: i64 = toI64(p) + toI64(ADLER32_NMAX)
309
+ const stop: i32 = reach < toI64(end) ? toI32(reach) : end
310
+ while (p <= 2147483643 && p + 4 <= stop) {
317
311
  s1 += toU32(uncheckedGet(buf, p))
318
312
  s2 += s1
319
313
  s1 += toU32(uncheckedGet(buf, p + 1))
@@ -329,8 +323,9 @@ const adler32Walk = (adler: u32, buf: u8[], off: i32, len: i32): u32 => {
329
323
  s2 += s1
330
324
  p += 1
331
325
  }
332
- s1 = s1 % toU32(ADLER32_BASE)
333
- s2 = s2 % toU32(ADLER32_BASE)
326
+ // 65521, the Adler-32 modulus: the largest prime below 2^16 (RFC 1950 §9).
327
+ s1 = s1 % 65521
328
+ s2 = s2 % 65521
334
329
  }
335
330
  return (s2 << 16) | s1
336
331
  }