nish 0.27.2 → 0.29.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 (62) hide show
  1. package/README.md +7 -6
  2. package/docs/AI.md +118 -26
  3. package/docs/INSTALL.md +16 -8
  4. package/llms.txt +4 -2
  5. package/package.json +5 -6
  6. package/runtime/core/host.d.ts +2 -1
  7. package/runtime/core/host.mjs +4 -0
  8. package/runtime/core.d.ts +47 -0
  9. package/runtime/core.mjs +67 -0
  10. package/runtime/nish.d.ts +176 -0
  11. package/runtime/nish.h +120 -6
  12. package/runtime/nish.mjs +24 -4
  13. package/runtime/runtime-checksum.c +270 -0
  14. package/runtime/runtime-net.c +386 -5
  15. package/runtime/runtime-os.c +59 -8
  16. package/runtime/runtime-parallel.c +81 -5
  17. package/runtime/runtime-sandbox.c +479 -0
  18. package/runtime/runtime-sha256.c +239 -0
  19. package/runtime/runtime-shm.c +541 -0
  20. package/runtime/runtime.c +827 -791
  21. package/scripts/build.sh +79 -28
  22. package/scripts/changelog-gen.mjs +71 -18
  23. package/scripts/fuzz.sh +4 -0
  24. package/scripts/gen-pow10-table.py +80 -0
  25. package/scripts/gen-regex-unicode.mjs +822 -0
  26. package/scripts/gen-union-scale.mjs +294 -0
  27. package/scripts/size-report.sh +2 -2
  28. package/std/README.md +25 -13
  29. package/std/collections.ts +5 -5
  30. package/std/compress/checksum.ts +88 -75
  31. package/std/compress/deflate.ts +224 -0
  32. package/std/compress/gzip.ts +52 -0
  33. package/std/crypto/bcrypt.ts +816 -280
  34. package/std/crypto/hmac.ts +305 -2
  35. package/std/crypto/jwt.ts +1661 -0
  36. package/std/json-equal.ts +335 -0
  37. package/std/json-format.ts +1070 -0
  38. package/std/json-number.ts +428 -0
  39. package/std/json-pointer.ts +245 -0
  40. package/std/json-typed.ts +34 -0
  41. package/std/json-value.ts +510 -17
  42. package/std/json.ts +35 -6
  43. package/std/net/handler.ts +1348 -0
  44. package/std/net/http-client.ts +97 -16
  45. package/std/net/http-compress.ts +301 -16
  46. package/std/net/http1-client.ts +104 -19
  47. package/std/net/http1-server.ts +127 -24
  48. package/std/net/http1.ts +24 -4
  49. package/std/net/outbound.ts +409 -0
  50. package/std/net/postgres.ts +405 -0
  51. package/std/net/prefork.ts +344 -20
  52. package/std/net/websocket.ts +295 -14
  53. package/std/regex.ts +613 -52
  54. package/std/secret.ts +1 -1
  55. package/std/sync/ring.ts +587 -0
  56. package/std/sync/shm.ts +284 -0
  57. package/std/term-io.ts +35 -8
  58. package/std/term-rate.ts +13 -1
  59. package/std/threads.ts +35 -3
  60. package/std/yaml-json.ts +841 -0
  61. package/scripts/gen-pow5-tables.py +0 -50
  62. /package/runtime/{LICENSE-ryu → LICENSE-zmij} +0 -0
package/scripts/build.sh CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # scripts/build.sh <module.ll> [more .ll/.c files...] -o <out> [--profile debug|speed|size|wasm|wasi|napi]
5
5
  #
6
- # The C runtime is ten translation units and is named as one: an input
6
+ # The C runtime is fourteen translation units and is named as one: an input
7
7
  # <dir>/runtime.c also compiles <dir>/runtime-os.c, the half that wraps the
8
8
  # system calls (files, directories, subprocesses, the environment, the clock),
9
9
  # <dir>/runtime-parallel.c, the half that divides a range of work across
@@ -13,8 +13,12 @@
13
13
  # <dir>/runtime-simd.c, the byte searches that read a vector at a time and
14
14
  # the SSE4.1 rounding of `Math.floor` and its kin,
15
15
  # <dir>/runtime-aes.c, AES-GCM on the CPU's AES instructions,
16
- # <dir>/runtime-term.c, stdin and the terminal of `nish:term`, and
17
- # <dir>/runtime-bytes.c, the byte-class runs of `nish/bytes`. Each of those
16
+ # <dir>/runtime-sha256.c, SHA-256 on the CPU's SHA instructions,
17
+ # <dir>/runtime-checksum.c, CRC-32 on its carry-less multiply or CRC instructions,
18
+ # <dir>/runtime-term.c, stdin and the terminal of `nish:term`,
19
+ # <dir>/runtime-bytes.c, the byte-class runs of `nish/bytes`,
20
+ # <dir>/runtime-sandbox.c, the confinement `--sandbox` applies, and
21
+ # <dir>/runtime-shm.c, the shared-memory regions of `nish/sync/shm`. Each of those
18
22
  # files says why they are compiled and measured apart.
19
23
  #
20
24
  # Profiles:
@@ -109,6 +113,12 @@
109
113
  # --sqlite-from <dir> link <dir>/<unit>.o in place of compiling
110
114
  # runtime/sqlite/, when the IR calls SQLite.
111
115
  # All four refuse the wasm, wasi and napi profiles and --pgo-*, with exit 2.
116
+ # --module-objects <dir> debug with --runtime-from only: the object of each
117
+ # input X.ll is <dir>/X.o, linked as it stands when
118
+ # the file is there and compiled into it when it is
119
+ # not, so the caller keeps every object it compiled
120
+ # (`nish run`'s module cache, src/build-cache.ts).
121
+ # The inputs' file names must differ.
112
122
  #
113
123
  # Works on Linux (clang + lld preferred, GNU ld tolerated) and macOS (Apple ld64
114
124
  # or Homebrew llvm). Set CC to pick a compiler (default: clang on PATH).
@@ -125,6 +135,7 @@ objects_from="" # --runtime-from <dir>: link against the
125
135
  cpu="" # --cpu x86-64-v3: the one CPU level above the baseline (WP38 S2)
126
136
  sqlite_to="" # --sqlite-objects <dir>: compile runtime/sqlite/ alone, into <dir>
127
137
  sqlite_from="" # --sqlite-from <dir>: link runtime/sqlite/ compiled there
138
+ modules_at="" # --module-objects <dir>: each X.ll's object is <dir>/X.o
128
139
  while [ $# -gt 0 ]; do
129
140
  case "$1" in
130
141
  -o) out="$2"; shift 2 ;;
@@ -138,6 +149,7 @@ while [ $# -gt 0 ]; do
138
149
  --runtime-from) objects_from="$2"; shift 2 ;;
139
150
  --sqlite-objects) sqlite_to="$2"; shift 2 ;;
140
151
  --sqlite-from) sqlite_from="$2"; shift 2 ;;
152
+ --module-objects) modules_at="$2"; shift 2 ;;
141
153
  --pgo-generate) pgo=(-fprofile-generate); shift ;;
142
154
  --pgo-use)
143
155
  [ -f "$2" ] || { echo "error: --pgo-use: profile '$2' not found (run the instrumented binary, then llvm-profdata merge)" >&2; exit 2; }
@@ -169,6 +181,15 @@ case "$profile" in
169
181
  if grep -E '^define [^@]*@memory\(' "$i" | grep -Evq '^define (internal|private) '; then
170
182
  echo "error: $i defines a function named \`memory\`, the name the $profile profile's module exports its linear memory under; rename the function" >&2
171
183
  exit 2
184
+ fi
185
+ # `--sandbox` IR compiled for the host confines through Linux system
186
+ # calls a wasm module has none of; the compiler emits no call for a
187
+ # wasm target, so only IR that never told it reaches this. The match
188
+ # is the call instruction, not the name: the compiler's own IR holds
189
+ # the name as string data.
190
+ if grep -Eq '^[[:space:]]+call void @nish_sandbox\(' "$i"; then
191
+ echo "error: $i was compiled with --sandbox, and a $profile module has no sandbox; compile it with --target wasm32 and without --sandbox" >&2
192
+ exit 2
172
193
  fi ;;
173
194
  esac
174
195
  done ;;
@@ -183,6 +204,12 @@ if [ -n "$objects_to" ] || [ -n "$objects_from" ]; then
183
204
  [ ${#pgo[@]} -eq 0 ] || { echo "error: --runtime-objects and --runtime-from do not take --pgo-*" >&2; exit 2; }
184
205
  [ -z "$objects_to" ] || [ -z "$objects_from" ] || { echo "error: --runtime-objects and --runtime-from are two different builds" >&2; exit 2; }
185
206
  fi
207
+ if [ -n "$modules_at" ]; then
208
+ [ -n "$objects_from" ] || { echo "error: --module-objects takes --runtime-from" >&2; exit 2; }
209
+ [ -d "$modules_at" ] || { echo "error: --module-objects: $modules_at is not a directory" >&2; exit 2; }
210
+ # Speed and size compile a module to LTO bitcode, not the native object kept there.
211
+ [ "$profile" = debug ] || { echo "error: --module-objects takes the debug profile, not '$profile'" >&2; exit 2; }
212
+ fi
186
213
  if [ -n "$sqlite_to" ] || [ -n "$sqlite_from" ]; then
187
214
  # The cached SQLite objects sit beside the cached runtime and take what it takes.
188
215
  case "$profile" in
@@ -195,15 +222,18 @@ if [ -n "$sqlite_to" ] || [ -n "$sqlite_from" ]; then
195
222
  fi
196
223
  [ -n "$out" ] || [ -n "$objects_to" ] || [ -n "$sqlite_to" ] || { echo "error: -o <out> is required" >&2; exit 2; }
197
224
 
198
- # The runtime is ten translation units, and a caller names one: whoever passes
225
+ # The runtime is fourteen translation units, and a caller names one: whoever passes
199
226
  # <dir>/runtime.c gets <dir>/runtime-os.c, <dir>/runtime-parallel.c,
200
227
  # <dir>/runtime-cross.c, <dir>/runtime-host.c, <dir>/runtime-net.c, <dir>/runtime-simd.c,
201
- # <dir>/runtime-aes.c, <dir>/runtime-term.c and <dir>/runtime-bytes.c compiled beside it, on every profile,
228
+ # <dir>/runtime-aes.c, <dir>/runtime-sha256.c, <dir>/runtime-checksum.c, <dir>/runtime-term.c,
229
+ # <dir>/runtime-bytes.c, <dir>/runtime-sandbox.c and <dir>/runtime-shm.c compiled beside it, on every profile,
202
230
  # wasi included: runtime-simd.c and runtime-bytes.c take their scalar paths there
203
231
  # unless the build adds -msimd128,
204
- # runtime-aes.c compiles to an answer of 0 and stubs that nothing calls,
205
- # because the compiler emits no call to its kernels for wasm32, and
206
- # runtime-term.c reads stdin and answers "not a terminal". They were one file until the
232
+ # runtime-aes.c, runtime-sha256.c and runtime-checksum.c compile to an answer of 0 and
233
+ # stubs that nothing calls, because the compiler emits no call to their kernels for wasm32, and
234
+ # runtime-term.c reads stdin and answers "not a terminal", and runtime-sandbox.c
235
+ # compiles to two functions that refuse to run, which no wasm build calls, and
236
+ # runtime-shm.c answers -95 for every region. They were one file until the
207
237
  # operating-system half was split out for its own size budget, and the parallel
208
238
  # half followed for the same reason (each file's header comment says why), and
209
239
  # a link line is where those splits
@@ -213,7 +243,7 @@ fi
213
243
  # here keeps every one of those correct, and keeps "the runtime" one thing to
214
244
  # name from the outside. A caller that names one itself is left alone, because
215
245
  # naming one object twice is a duplicate-symbol error.
216
- halves="runtime-os.c runtime-parallel.c runtime-cross.c runtime-host.c runtime-net.c runtime-simd.c runtime-aes.c runtime-term.c runtime-bytes.c"
246
+ halves="runtime-os.c runtime-parallel.c runtime-cross.c runtime-host.c runtime-net.c runtime-simd.c runtime-aes.c runtime-sha256.c runtime-checksum.c runtime-term.c runtime-bytes.c runtime-sandbox.c runtime-shm.c"
217
247
  for i in ${inputs[@]+"${inputs[@]}"}; do
218
248
  case "$i" in
219
249
  */runtime.c|runtime.c)
@@ -248,11 +278,15 @@ if [ -n "$sqlite_to" ]; then
248
278
  fi
249
279
  sqlite_wanted=1
250
280
  fi
281
+ # One grep reads every module, not one grep each: a program of forty modules
282
+ # spent a third of a second here starting greps.
283
+ lls=()
251
284
  for i in ${inputs[@]+"${inputs[@]}"}; do
252
- case "$i" in
253
- *.ll) if grep -Eq '^declare [^"]*@(sqlite3|nishsqlite)_' "$i"; then sqlite_wanted=1; fi ;;
254
- esac
285
+ case "$i" in *.ll) lls+=("$i") ;; esac
255
286
  done
287
+ if [ ${#lls[@]} -gt 0 ] && grep -Eq '^declare [^"]*@(sqlite3|nishsqlite)_' "${lls[@]}"; then
288
+ sqlite_wanted=1
289
+ fi
256
290
  for i in ${inputs[@]+"${inputs[@]}"}; do
257
291
  case "$i" in
258
292
  *.c) if [ -n "$sqlite_dir" ] && [ "$(cd "$(dirname -- "$i")" && pwd -P)" = "$sqlite_dir" ]; then sqlite_wanted=0; break; fi ;;
@@ -597,9 +631,19 @@ if [ -n "$objects_from" ]; then
597
631
  for i in "${inputs[@]}"; do
598
632
  case "$i" in */runtime.c|runtime.c) echo "error: --runtime-from links the runtime in $objects_from, so $i is not an input" >&2; exit 2 ;; esac
599
633
  n=$((n + 1))
600
- "$CC" "${module_compile[@]}" -c "$i" -o "$work/$n.o" &
634
+ object="$work/$n.o"
635
+ if [ -n "$modules_at" ]; then
636
+ case "$i" in
637
+ *.ll)
638
+ name=${i##*/}
639
+ object="$modules_at/${name%.ll}.o"
640
+ # An object the caller left there is this module's, compiled before.
641
+ if [ -f "$object" ]; then objects+=("$object"); continue; fi ;;
642
+ esac
643
+ fi
644
+ "$CC" "${module_compile[@]}" -c "$i" -o "$object" &
601
645
  pids+=("$!")
602
- objects+=("$work/$n.o")
646
+ objects+=("$object")
603
647
  done
604
648
  join_jobs || { echo "error: a module did not compile" >&2; exit 1; }
605
649
  # In the order the one-command link names them: the inputs, then runtime.c
@@ -635,22 +679,29 @@ case "$profile" in
635
679
  exit 2
636
680
  fi
637
681
  # IR compiled for the host rather than with `--target wasm32` calls std/crypto/aes.ts's
638
- # AES kernels behind `nish_aes_hw` (src/kernels.ts). runtime-aes.c's wasm32 build
639
- # answers 0 there, so the bitsliced code runs, and it is added only for such IR:
640
- # every other module links the bytes it always did.
641
- # A caller that names runtime-aes.c itself is left alone, as `halves` leaves it:
682
+ # AES kernels behind `nish_aes_hw`, std/crypto/sha256.ts's block function behind
683
+ # `nish_sha256_hw` and std/compress/checksum.ts's CRC-32 kernel behind
684
+ # `nish_crc32_hw` (src/kernels.ts). runtime-aes.c's, runtime-sha256.c's and
685
+ # runtime-checksum.c's wasm32 builds answer 0 there, so the Nish code runs, and
686
+ # each is added only for such IR: every other module links the bytes it always did.
687
+ # Each pair is a unit and the kernel its probe names.
688
+ # A caller that names the unit itself is left alone, as `halves` leaves it:
642
689
  # one object named twice is a duplicate-symbol error.
643
- aes_named=0
644
- aes_wanted=0
645
- for i in ${inputs[@]+"${inputs[@]}"}; do
646
- case "$i" in
647
- */runtime-aes.c|runtime-aes.c) aes_named=1 ;;
648
- *.ll) if grep -q '@nish_aes_hw(' "$i"; then aes_wanted=1; fi ;;
649
- esac
690
+ for pair in aes:aes sha256:sha256 checksum:crc32; do
691
+ unit=${pair%%:*}
692
+ kernel=${pair#*:}
693
+ named=0
694
+ wanted=0
695
+ for i in ${inputs[@]+"${inputs[@]}"}; do
696
+ case "$i" in
697
+ */runtime-"$unit".c|runtime-"$unit".c) named=1 ;;
698
+ *.ll) if grep -q "@nish_${kernel}_hw(" "$i"; then wanted=1; fi ;;
699
+ esac
700
+ done
701
+ if [ "$wanted" = 1 ] && [ "$named" = 0 ]; then
702
+ inputs+=("$(cd "$(dirname "$0")/../runtime" && pwd)/runtime-$unit.c")
703
+ fi
650
704
  done
651
- if [ "$aes_wanted" = 1 ] && [ "$aes_named" = 0 ]; then
652
- inputs+=("$(cd "$(dirname "$0")/../runtime" && pwd)/runtime-aes.c")
653
- fi
654
705
  # IR of either kind that imports std/json or calls nish/bytes's byte-class runs
655
706
  # calls runtime-bytes.c's kernels (src/kernels.ts), which compile freestanding:
656
707
  # the scalar path, or the 128-bit one under -msimd128. It is added the same way,
@@ -40,6 +40,18 @@
40
40
  // about the review rather than about the change
41
41
  // Release-As: 1.0.0 -- the version the next release takes, when it is not
42
42
  // the one the types imply (see nextVersion)
43
+ // Changelog: skip -- this commit produces no entry
44
+ // Changelog-Skip: 1a2b3c4, 5d6e7f8 -- the named commits produce no entry
45
+ //
46
+ // The last two keep internal or unannounced work out of the notes without
47
+ // rewriting history: `Changelog-Skip:` names commits by SHA (an abbreviation of
48
+ // at least seven hex digits is a prefix of the full one), so a squash merge
49
+ // can drop commits that landed earlier in the same release. A SHA outside the
50
+ // range is ignored, since it may name a commit an earlier release already
51
+ // covered. The commits they drop are counted on stderr, never listed, and their
52
+ // types do not move the version: a bump the notes cannot explain would be a
53
+ // mystery. A `Release-As:` on a dropped commit still applies, since it is an
54
+ // explicit request rather than a bump the types imply.
43
55
  //
44
56
  // `type!` or a `BREAKING CHANGE:` trailer marks a breaking change.
45
57
  //
@@ -53,7 +65,9 @@
53
65
  // `--include-unconventional` flag files them under "Uncategorised" the way this
54
66
  // tool behaved before. Use it for the first release after the convention
55
67
  // lands, or write the history up by hand in `changelog/<version>.intro.md`,
56
- // which renders above the sections.
68
+ // which renders above the sections. A commit kept out by a `Changelog` trailer
69
+ // is the one exception to the listing: it was dropped on purpose, so only a
70
+ // count is printed.
57
71
  import fs from "node:fs"
58
72
  import path from "node:path"
59
73
  import { execFileSync } from "node:child_process"
@@ -104,7 +118,8 @@ const CONVENTIONAL_TYPES = TYPES.filter(([k]) => k !== "other").map(([k]) => k)
104
118
  const DROPPED_TRAILERS = /^(Co-Authored-By|Claude-Session|Signed-off-by|Reviewed-by):/i
105
119
 
106
120
  /** Trailers this tool reads. Everything else is left in the body. */
107
- const KNOWN_TRAILERS = /^(Measured|Refs|Tests|Release-Note|Release-As|BREAKING[ -]CHANGE):\s*(.*)$/i
121
+ const KNOWN_TRAILERS =
122
+ /^(Measured|Refs|Tests|Release-Note|Release-As|Changelog|Changelog-Skip|BREAKING[ -]CHANGE):\s*(.*)$/i
108
123
 
109
124
  /**
110
125
  * GitHub ends a squashed body with a rule when the branch had more than one
@@ -167,6 +182,8 @@ const parseTrailers = (lines) => {
167
182
  releaseNote: undefined,
168
183
  releaseAs: [],
169
184
  breaking: undefined,
185
+ skipSelf: false,
186
+ skipShas: [],
170
187
  }
171
188
  for (const line of lines) {
172
189
  if (DROPPED_TRAILERS.test(line)) {
@@ -200,6 +217,17 @@ const parseTrailers = (lines) => {
200
217
  out.releaseAs.push(value)
201
218
  } else if (key === "breakingchange") {
202
219
  out.breaking = value
220
+ } else if (key === "changelog") {
221
+ out.skipSelf ||= value.toLowerCase() === "skip"
222
+ } else if (key === "changelogskip") {
223
+ // A value that is not a SHA names nothing, the way a SHA outside the
224
+ // range does, and is ignored the same way.
225
+ out.skipShas.push(
226
+ ...value
227
+ .split(/[\s,]+/)
228
+ .filter((s) => /^[0-9a-f]{7,40}$/i.test(s))
229
+ .map((s) => s.toLowerCase())
230
+ )
203
231
  }
204
232
  }
205
233
  return out
@@ -234,8 +262,9 @@ const slug = (title, taken) => {
234
262
  }
235
263
 
236
264
  /**
237
- * The entries a release contains, the subjects that did not become one, and
238
- * the `Release-As:` trailers the range carries.
265
+ * The entries a release contains, the subjects that did not become one, the
266
+ * number of commits a `Changelog` trailer kept out, and the `Release-As:`
267
+ * trailers the range carries.
239
268
  *
240
269
  * A subject that does not classify is skipped: `pr-title.yml` makes every
241
270
  * squash-merge subject conventional, so what is left over is the branch
@@ -247,7 +276,9 @@ const slug = (title, taken) => {
247
276
  *
248
277
  * A trailer is read from every commit in the range, skipped or not: a version
249
278
  * someone asked for is not lost because the commit that asked was the
250
- * work-in-progress half of a merge.
279
+ * work-in-progress half of a merge. That is also why the log is read whole
280
+ * before any entry is made: a `Changelog-Skip:` usually names a commit that
281
+ * came before it.
251
282
  */
252
283
  const collect = (fromRef, toRef, withUnconventional = false) => {
253
284
  const range = fromRef ? `${fromRef}..${toRef}` : toRef
@@ -255,11 +286,8 @@ const collect = (fromRef, toRef, withUnconventional = false) => {
255
286
  // newlines and may contain anything else, so the separators must be bytes
256
287
  // that cannot appear in one.
257
288
  const raw = git(["log", "--no-merges", "--reverse", "--format=%H%x00%an%x00%aI%x00%s%x00%b%x1e", range])
258
- const taken = new Set()
259
- const entries = []
260
- const skipped = []
261
- const releaseAs = []
262
-
289
+ const commits = []
290
+ const skipShas = []
263
291
  for (const record of raw.split("\x1e")) {
264
292
  const text = record.replace(/^\n/, "")
265
293
  if (!text.trim()) {
@@ -268,8 +296,25 @@ const collect = (fromRef, toRef, withUnconventional = false) => {
268
296
  const [sha, author, date, subject, body = ""] = text.split("\x00")
269
297
  const { prose: rawProse, trailers } = splitTrailers(body)
270
298
  const t = parseTrailers(trailers)
299
+ skipShas.push(...t.skipShas)
300
+ commits.push({ sha, author, date, subject, rawProse, t })
301
+ }
302
+
303
+ const taken = new Set()
304
+ const entries = []
305
+ const skipped = []
306
+ const releaseAs = []
307
+ let hidden = 0
308
+
309
+ for (const { sha, author, date, subject, rawProse, t } of commits) {
310
+ const hide = t.skipSelf || skipShas.some((prefix) => sha.startsWith(prefix))
271
311
  for (const version of t.releaseAs) {
272
- releaseAs.push({ version, commit: `${sha.slice(0, 7)} ${subject}` })
312
+ // A hidden commit is named by its SHA alone, should a refusal quote it.
313
+ releaseAs.push({ version, commit: hide ? sha.slice(0, 7) : `${sha.slice(0, 7)} ${subject}` })
314
+ }
315
+ if (hide) {
316
+ hidden += 1
317
+ continue
273
318
  }
274
319
 
275
320
  const parsed = parseSubject(subject)
@@ -302,7 +347,7 @@ const collect = (fromRef, toRef, withUnconventional = false) => {
302
347
  date: date.slice(0, 10),
303
348
  })
304
349
  }
305
- return { entries, skipped, releaseAs }
350
+ return { entries, skipped, hidden, releaseAs }
306
351
  }
307
352
 
308
353
  const renderMarkdown = (releaseData) => {
@@ -507,7 +552,7 @@ const stdoutKind = flag("stdout", "md")
507
552
  const write = argv.includes("--write")
508
553
  const includeUnconventional = argv.includes("--include-unconventional")
509
554
 
510
- const { entries, skipped, releaseAs } = collect(from, to, includeUnconventional)
555
+ const { entries, skipped, hidden, releaseAs } = collect(from, to, includeUnconventional)
511
556
 
512
557
  // `--next` answers the version and nothing else, for the release PR to name
513
558
  // itself and to bump package.json with. Everything release-pr.yml writes reads
@@ -539,13 +584,21 @@ if (skipped.length > 0 && !includeUnconventional) {
539
584
  console.error('Pass --include-unconventional to file them under "Uncategorised" instead.')
540
585
  }
541
586
 
542
- if (entries.length === 0) {
543
- const range = from ? `${from}..${to}` : to
587
+ if (hidden > 0) {
544
588
  console.error(
545
- skipped.length > 0
546
- ? `changelog-gen: no commit in ${range} carries a conventional subject (${skipped.length} skipped, listed above), so the release has no entries; fix the subjects or pass --include-unconventional`
547
- : `changelog-gen: no commits in ${range}; a release with no changes is a mistake, not an empty section`
589
+ `changelog-gen: ${hidden} commit${hidden === 1 ? "" : "s"} kept out of the changelog by trailer`
548
590
  )
591
+ }
592
+
593
+ if (entries.length === 0) {
594
+ const range = from ? `${from}..${to}` : to
595
+ let why = `no commits in ${range}; a release with no changes is a mistake, not an empty section`
596
+ if (skipped.length > 0) {
597
+ why = `no commit in ${range} carries a conventional subject (${skipped.length} skipped, listed above), so the release has no entries; fix the subjects or pass --include-unconventional`
598
+ } else if (hidden > 0) {
599
+ why = `every commit in ${range} is kept out by trailer, so the release has no entries; a release with nothing to announce is a mistake, not an empty section`
600
+ }
601
+ console.error(`changelog-gen: ${why}`)
549
602
  process.exit(1)
550
603
  }
551
604
 
package/scripts/fuzz.sh CHANGED
@@ -52,8 +52,12 @@ RUNTIME_C=(
52
52
  runtime/runtime-net.c
53
53
  runtime/runtime-simd.c
54
54
  runtime/runtime-aes.c
55
+ runtime/runtime-sha256.c
56
+ runtime/runtime-checksum.c
55
57
  runtime/runtime-term.c
56
58
  runtime/runtime-bytes.c
59
+ runtime/runtime-sandbox.c
60
+ runtime/runtime-shm.c
57
61
  )
58
62
 
59
63
  SAN_FLAGS=(-g -O1 "-fsanitize=fuzzer,address,undefined" -fno-sanitize-recover=undefined)
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env python3
2
+ """Regenerate the power-of-ten table `runtime/runtime.c` uses for Zmij.
3
+
4
+ python3 scripts/gen-pow10-table.py
5
+
6
+ Prints the C to stdout; paste it over the `NISH_POW10_SIG` definition. The
7
+ point of having this in the tree is that the ~10 KB of constants in the
8
+ runtime are *derived*, with exact integer arithmetic, rather than transcribed
9
+ from somewhere -- so a reader can check them rather than trust them. See
10
+ docs/wp15-performance.md section 7a.
11
+
12
+ Each row is the 128-bit significand of 10^k, normalised so its top bit is set
13
+ and rounded *down*, as `{ hi, lo }`: the convention of Zmij's
14
+ `pow10_significands` (zmij.c, Copyright (c) 2025 - present, Victor Zverovich,
15
+ used under the Boost Software License, Version 1.0; runtime/LICENSE-zmij has
16
+ the text and THIRD_PARTY_NOTICES.md the entry). Upstream ships 10^-307 to
17
+ 10^341 because its fixed-precision paths read further out; the shortest-digits
18
+ path, the only one ported, reaches fewer, and the range below is computed from
19
+ the same exponent arithmetic `nish_shortest_digits` does rather than copied.
20
+ """
21
+
22
+ M = (1 << 64) - 1
23
+ EXP_OFFSET = 1075 # a double is sig * 2^(raw_exp - 1075)
24
+ EXTRA_SHIFT = 6
25
+
26
+
27
+ def dec_exp_of(bin_exp, regular):
28
+ # compute_dec_exp: floor(log10(2^bin_exp)), or of 3/4 of it when irregular.
29
+ # Python's >> floors like the arithmetic shift clang emits for C's int.
30
+ return (bin_exp * 315653 - (0 if regular else 131072)) >> 20
31
+
32
+
33
+ def exp_shift(bin_exp, dec_exp):
34
+ # compute_exp_shift(bin_exp, dec_exp + 1) + extra_shift, as the runtime does it.
35
+ return bin_exp + ((-(dec_exp + 1) * 217707) >> 16) + 1 + EXTRA_SHIFT
36
+
37
+
38
+ def significand(k):
39
+ # floor(10^k * 2^s) for the s that leaves exactly 128 bits.
40
+ if k >= 0:
41
+ p = 10**k
42
+ s = 128 - p.bit_length()
43
+ v = p << s if s >= 0 else p >> -s
44
+ else:
45
+ p = 10**-k
46
+ # 2^(127 + b) / 10^-k with b the bit length of 10^-k lands in [2^127, 2^128).
47
+ v = (1 << (127 + p.bit_length())) // p
48
+ assert v >> 127 == 1, k
49
+ return v
50
+
51
+
52
+ # Every power the shortest path reads: raw_exp 1 (the subnormals and 2^-1022,
53
+ # which share its spacing) to 2046, the irregular branch only from 2 up.
54
+ reach = set()
55
+ for raw_exp in range(1, 2047):
56
+ bin_exp = raw_exp - EXP_OFFSET
57
+ for regular in (True, False) if raw_exp > 1 else (True,):
58
+ d = dec_exp_of(bin_exp, regular)
59
+ shift = exp_shift(bin_exp, d)
60
+ # `bin_sig << shift` must keep a 53-bit significand, and the half-ulp
61
+ # shift `extra_shift + 1 - shift` must be a legal shift count.
62
+ assert 0 <= shift and 53 + shift <= 64, (raw_exp, shift)
63
+ assert 0 <= EXTRA_SHIFT + 1 - shift < 64, (raw_exp, shift)
64
+ reach.add(-d - 1)
65
+ lo, hi = min(reach), max(reach)
66
+ assert reach == set(range(lo, hi + 1))
67
+ assert (lo, hi) == (-293, 323), (lo, hi)
68
+
69
+ # Spot checks against values a reader can do by hand.
70
+ assert significand(0) == 1 << 127
71
+ assert significand(-1) == int("cc" * 16, 16)
72
+ assert significand(1) == 0xA << 124
73
+
74
+ print(f"/* Generated by scripts/gen-pow10-table.py; do not hand-edit. 10^{lo} to 10^{hi}. */")
75
+ print(f"#define NISH_POW10_MIN ({lo})")
76
+ print(f"static const uint64_t NISH_POW10_SIG[{hi - lo + 1}][2] = {{")
77
+ for k in range(lo, hi + 1):
78
+ v = significand(k)
79
+ print(f" {{ 0x{v >> 64:016x}u, 0x{v & M:016x}u }},")
80
+ print("};")