nish 0.39.0 → 0.41.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.
- package/README.md +190 -555
- package/docs/AI.md +112 -33
- package/docs/INSTALL.md +79 -133
- package/llms.txt +2 -9
- package/package.json +17 -19
- package/runtime/nish.d.ts +21 -17
- package/runtime/nish.h +10 -0
- package/runtime/page-frame.d.ts +123 -0
- package/runtime/page-frame.mjs +736 -0
- package/runtime/page-game.d.ts +132 -0
- package/runtime/page-game.mjs +738 -0
- package/runtime/runtime-aes.c +85 -8
- package/runtime/runtime-bytes.c +88 -4
- package/runtime/runtime-net.c +32 -0
- package/runtime/runtime-sandbox.c +55 -28
- package/runtime/runtime-uring.c +1194 -0
- package/runtime/runtime-wasm.c +422 -0
- package/runtime/vite.mjs +1 -1
- package/scripts/build.sh +22 -6
- package/std/README.md +74 -87
- package/std/array.ts +36 -3
- package/std/collections.ts +51 -0
- package/std/crypto/hmac.ts +37 -10
- package/std/crypto/p256.ts +1388 -2664
- package/std/crypto/pki.ts +116 -4
- package/std/crypto/sha256.ts +34 -6
- package/std/crypto/x509.ts +7 -0
- package/std/host/game.ts +273 -0
- package/std/input.ts +56 -0
- package/std/json-tokenizer.ts +325 -112
- package/std/json-typed.ts +43 -8
- package/std/json-value.ts +144 -3
- package/std/json.ts +63 -8
- package/std/net/fetch.ts +22 -4
- package/std/net/http-server.ts +3382 -0
- package/std/net/http1-client-codec.ts +6 -2
- package/std/net/http1-codec.ts +137 -12
- package/std/net/http1-server.ts +83 -29
- package/std/net/http2.ts +47 -14
- package/std/net/http3-server.ts +29 -3
- package/std/net/http3.ts +180 -7
- package/std/net/prefork.ts +49 -13
- package/std/net/quic-recovery.ts +240 -9
- package/std/net/quic-stream.ts +21 -1
- package/std/net/quic.ts +98 -4
- package/std/net/router.ts +378 -31
- package/std/net/serve.ts +873 -65
- package/std/net/tls/verify.ts +19 -1
- package/std/net/url.ts +83 -35
- package/std/net/websocket.ts +74 -1
- package/std/net/webtransport.ts +7 -1
- package/std/raster.ts +837 -0
- package/std/release.ts +593 -0
- package/std/synth.ts +143 -0
- package/std/temporal.ts +3091 -0
- package/std/threads.ts +298 -0
- package/std/yaml-json.ts +368 -28
- package/std/yaml.ts +122 -27
- package/scripts/bootstrap.sh +0 -375
- package/scripts/build-id-smoke.sh +0 -28
- package/scripts/changelog-gen.mjs +0 -649
- package/scripts/changelog-section.sh +0 -28
- package/scripts/check-hardening.mjs +0 -202
- package/scripts/ci-profile.mjs +0 -200
- package/scripts/codes-registry.js +0 -85
- package/scripts/fuzz.sh +0 -280
- package/scripts/gen-diagnostic-codes.mjs +0 -243
- package/scripts/gen-json-pow5.mjs +0 -130
- package/scripts/gen-p256-table.mjs +0 -177
- package/scripts/gen-pow10-table.py +0 -80
- package/scripts/gen-regex-unicode.mjs +0 -822
- package/scripts/gen-union-scale.mjs +0 -294
- package/scripts/nish-compiler.sh +0 -19
- package/scripts/platform-package.mjs +0 -93
- package/scripts/security-scope.mjs +0 -139
- package/scripts/shard-costs.mjs +0 -429
- package/scripts/size-report.sh +0 -84
- package/scripts/smoke.sh +0 -105
- package/scripts/std-module-paths.mjs +0 -25
- package/scripts/undocumented.txt +0 -14
- package/scripts/verify-binaries.sh +0 -214
package/scripts/shard-costs.mjs
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Rewrite `tests/shard-costs.json` from the logs of green CI runs.
|
|
4
|
-
*
|
|
5
|
-
* node scripts/shard-costs.mjs <run-dir> <run-dir> <run-dir> ... print the table
|
|
6
|
-
* node scripts/shard-costs.mjs --write <run-dir> ... and write it
|
|
7
|
-
*
|
|
8
|
-
* A `<run-dir>` is a `ci.yml` run's log archive, unzipped: the "Download log
|
|
9
|
-
* archive" button on the run's page, or
|
|
10
|
-
* `gh api repos/<owner>/<repo>/actions/runs/<id>/logs > run.zip && unzip -d <dir> run.zip`.
|
|
11
|
-
* Only its `<n>_test (<os>, shard <i>_<n>).txt` files are read, and every one
|
|
12
|
-
* of a run's shards must be there.
|
|
13
|
-
*
|
|
14
|
-
* Why this exists. `tests/run.js` deals its link programs and its
|
|
15
|
-
* `DEALT_SECTIONS` across the `test` job's shards by the seconds this table
|
|
16
|
-
* gives them, and the deal is only as even as the table is true. Written by
|
|
17
|
-
* hand from one run, it drifted: the sections that moved into shard 8 cost
|
|
18
|
-
* about 330 s there against the 220 s the table gave them, and shard 8 became
|
|
19
|
-
* the longest job of every run. One run is also not a measurement, since a
|
|
20
|
-
* GitHub-hosted runner varies by minutes on the same shard; so this takes the
|
|
21
|
-
* median of each piece over every run it is given (`docs/wp10-ci.md`,
|
|
22
|
-
* "Regenerating the shard costs").
|
|
23
|
-
*
|
|
24
|
-
* **What a piece's seconds are.** Each is read from the timestamps GitHub puts
|
|
25
|
-
* on every log line, as the gap between two printed lines, the same way
|
|
26
|
-
* `scripts/ci-profile.mjs` reads a local run:
|
|
27
|
-
*
|
|
28
|
-
* - a link program is the gap from the last line of the program printed before
|
|
29
|
-
* it to its own last line. The pool reports programs in order, so a program
|
|
30
|
-
* that finished behind a slower one reads near 0; `linkFloor` in
|
|
31
|
-
* `tests/run.js` is what keeps that from dealing it as free.
|
|
32
|
-
* - a section is found in the one shard that ran it (every other shard's log
|
|
33
|
-
* delegates it by name) by the name of a check it prints (`RECOGNIZERS`). A
|
|
34
|
-
* section before the link programs is the gap from the line before its first
|
|
35
|
-
* check to its last one; one after them runs until the next section that
|
|
36
|
-
* shard ran starts, or its summary.
|
|
37
|
-
* - `shardOne` is what only shard 1 runs: from its first check after the
|
|
38
|
-
* dealt sections to its summary, plus its job's steps after the suite. A
|
|
39
|
-
* `pinned` section likewise takes its shard's steps after the suite, since
|
|
40
|
-
* they are there to read it.
|
|
41
|
-
*
|
|
42
|
-
* Anything it cannot find is an error, never a guess: a section with no
|
|
43
|
-
* recognizer, a recognizer that matches nothing in the shard that ran the
|
|
44
|
-
* section, or a shard whose link programs do not number what shard 1 says it
|
|
45
|
-
* dealt it. A renamed check fails this script rather than writing a 0.
|
|
46
|
-
*
|
|
47
|
-
* node scripts/shard-costs.mjs --check-runner <nish-runner> <slices> <parts>
|
|
48
|
-
*
|
|
49
|
-
* checks the deal the Nish runner (`tests/nish/run.ts`) makes from the same
|
|
50
|
-
* table's `link` costs, through its `--list`: that the `<slices>` slices
|
|
51
|
-
* cover the whole list once, that each slice's `<parts>` parts (what `--jobs`
|
|
52
|
-
* runs as separate processes) cover that slice once, and that no slice or
|
|
53
|
-
* part carries more link cost than the mean of its siblings plus the dearest
|
|
54
|
-
* program among them, which a cost deal guarantees and the position deal it
|
|
55
|
-
* replaced broke (504 s against a mean of 418 s on the last of three slices).
|
|
56
|
-
*/
|
|
57
|
-
import fs from "node:fs"
|
|
58
|
-
import path from "node:path"
|
|
59
|
-
import { spawnSync } from "node:child_process"
|
|
60
|
-
import { fileURLToPath } from "node:url"
|
|
61
|
-
|
|
62
|
-
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), "..")
|
|
63
|
-
const argv = process.argv.slice(2)
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The `--check-runner` mode; see the header. It answers before the
|
|
67
|
-
* log-reading part of this file asks for run directories.
|
|
68
|
-
*/
|
|
69
|
-
const checkRunner = (runner, slices, parts) => {
|
|
70
|
-
if (!runner || !(slices >= 1) || !(parts >= 1)) {
|
|
71
|
-
console.error("usage: node scripts/shard-costs.mjs --check-runner <nish-runner> <slices> <parts>")
|
|
72
|
-
process.exit(2)
|
|
73
|
-
}
|
|
74
|
-
const list = (...flags) => {
|
|
75
|
-
const r = spawnSync(runner, ["--list", ...flags], { cwd: root, encoding: "utf8" })
|
|
76
|
-
if (r.status !== 0) {
|
|
77
|
-
console.error(`${runner} --list ${flags.join(" ")} exited ${r.status}: ${r.stderr}`)
|
|
78
|
-
process.exit(1)
|
|
79
|
-
}
|
|
80
|
-
return r.stdout.split("\n").filter((l) => l.length > 0)
|
|
81
|
-
}
|
|
82
|
-
const costs = JSON.parse(fs.readFileSync(path.join(root, "tests", "shard-costs.json"), "utf8")).link
|
|
83
|
-
// tests/run.js's `linkFloor`, which the runner's `dealByCost` copies.
|
|
84
|
-
const cost = (line) => {
|
|
85
|
-
const name = line.slice("link ".length)
|
|
86
|
-
const floor = fs.existsSync(path.join(root, "tests", "link", name, "expected.err")) ? 0.05 : 0.5
|
|
87
|
-
return Math.max(costs[name] ?? 0, floor)
|
|
88
|
-
}
|
|
89
|
-
const problems = []
|
|
90
|
-
// `pieces` must hold exactly `all`'s lines, and none more link cost than the mean plus its dearest program.
|
|
91
|
-
const covers = (what, all, pieces) => {
|
|
92
|
-
const joined = pieces.flat().sort()
|
|
93
|
-
const sorted = [...all].sort()
|
|
94
|
-
if (joined.length !== sorted.length || joined.some((l, i) => l !== sorted[i])) {
|
|
95
|
-
problems.push(
|
|
96
|
-
`${what}: its ${pieces.length} pieces list ${joined.length} items, not the ${sorted.length} it has once each`
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
const links = pieces.map((p) => p.filter((l) => l.startsWith("link ")))
|
|
100
|
-
const loads = links.map((p) => p.reduce((sum, l) => sum + cost(l), 0))
|
|
101
|
-
const mean = loads.reduce((a, b) => a + b, 0) / loads.length
|
|
102
|
-
const dearest = Math.max(0, ...links.flat().map(cost))
|
|
103
|
-
loads.forEach((load, i) => {
|
|
104
|
-
if (load > mean + dearest + 1e-6) {
|
|
105
|
-
problems.push(
|
|
106
|
-
`${what}: piece ${i + 1} carries ${load.toFixed(1)} s of link programs, over the mean ${mean.toFixed(1)} s plus the dearest ${dearest} s`
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
return loads
|
|
111
|
-
}
|
|
112
|
-
const whole = list()
|
|
113
|
-
const shards = []
|
|
114
|
-
for (let i = 1; i <= slices; i++) {
|
|
115
|
-
shards.push(list("--shard", `${i}/${slices}`))
|
|
116
|
-
}
|
|
117
|
-
const loads = covers("the whole list", whole, shards)
|
|
118
|
-
shards.forEach((shard, i) => {
|
|
119
|
-
const pieces = []
|
|
120
|
-
for (let k = 1; k <= parts; k++) {
|
|
121
|
-
pieces.push(list("--shard", `${i + 1}/${slices}`, "--part", `${k}/${parts}`))
|
|
122
|
-
}
|
|
123
|
-
covers(`slice ${i + 1}/${slices}`, shard, pieces)
|
|
124
|
-
})
|
|
125
|
-
if (problems.length > 0) {
|
|
126
|
-
for (const p of problems) {
|
|
127
|
-
console.error(p)
|
|
128
|
-
}
|
|
129
|
-
process.exit(1)
|
|
130
|
-
}
|
|
131
|
-
console.log(
|
|
132
|
-
`the runner's ${slices} slices of ${whole.length} items carry ${loads.map((l) => l.toFixed(1)).join(", ")} s of link programs, each in ${parts} parts that cover it once`
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (argv[0] === "--check-runner") {
|
|
137
|
-
checkRunner(argv[1], Number(argv[2]), Number(argv[3]))
|
|
138
|
-
process.exit(0)
|
|
139
|
-
}
|
|
140
|
-
const write = argv.includes("--write")
|
|
141
|
-
const runs = argv.filter((a) => a !== "--write")
|
|
142
|
-
// A median of fewer than three runs is one runner's luck, not a measurement;
|
|
143
|
-
// and a flag this does not know (`--help`, a typo) is not a run directory.
|
|
144
|
-
if (runs.length < 3 || runs.some((a) => a.startsWith("-"))) {
|
|
145
|
-
console.error(
|
|
146
|
-
"usage: node scripts/shard-costs.mjs [--write] <unzipped run log dir>... (at least three green runs)"
|
|
147
|
-
)
|
|
148
|
-
process.exit(2)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* The first check each dealt section prints, by its key in `DEALT_SECTIONS`.
|
|
153
|
-
* A check's name is the text after `PASS `, `SKIP ` or `FAIL `.
|
|
154
|
-
*/
|
|
155
|
-
const RECOGNIZERS = {
|
|
156
|
-
termIo: /^term-io: /,
|
|
157
|
-
emitTs: /^emit-ts: /,
|
|
158
|
-
selfHosting: /^src\/ has at least one module/,
|
|
159
|
-
cryptoBench: /^crypto-bench:/,
|
|
160
|
-
sanitizers: /^runtime_sanitize:/,
|
|
161
|
-
nishRunner: /^tests\/nish\/run\.ts /,
|
|
162
|
-
bench: /^bench: /,
|
|
163
|
-
runtimeCache: /^runtime cache:/,
|
|
164
|
-
sqliteLink: /^sqlite-link:/,
|
|
165
|
-
fileServer: /^file-server:/,
|
|
166
|
-
differential: /^differential: native and Node/,
|
|
167
|
-
p256Seams: /^p256/,
|
|
168
|
-
netStartup: /^net_\w+: /,
|
|
169
|
-
threadWasi: /^(skipped: )?link\/thread_mutex_counter: (the `--profile wasi` build|no WASI sysroot)/,
|
|
170
|
-
cryptoChecks: /^nish:secret: (the wipe survives|no opt)/,
|
|
171
|
-
arrayChecks: /^arr_range_call/,
|
|
172
|
-
runtimeChecks: /^async: /,
|
|
173
|
-
simd: /^simd: /,
|
|
174
|
-
cliChecks: /^tests\/nish\/cli\.ts /,
|
|
175
|
-
releaseChecks: /^runtime\/nish\.d\.ts type-checks/,
|
|
176
|
-
cSymbols: /^c-symbols:/,
|
|
177
|
-
runCache: /^module cache:/,
|
|
178
|
-
}
|
|
179
|
-
/** Shard 1's first check after every dealt section: where `shardOne` starts. */
|
|
180
|
-
const SHARD_ONE_STARTS = /^every program LINK_READ_LATER keeps in shard 1/
|
|
181
|
-
|
|
182
|
-
const fail = (message) => {
|
|
183
|
-
console.error(`shard-costs: ${message}`)
|
|
184
|
-
process.exit(1)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* `DEALT_SECTIONS` as `tests/run.js` declares it: each key, the name a shard
|
|
189
|
-
* that does not run it delegates it by, whether it is `pinned`, and whether it
|
|
190
|
-
* runs before the link programs. Read from the source so the table this writes
|
|
191
|
-
* has exactly the keys the deal reads.
|
|
192
|
-
*/
|
|
193
|
-
const sections = (() => {
|
|
194
|
-
const source = fs.readFileSync(path.join(root, "tests", "run.js"), "utf8")
|
|
195
|
-
const start = source.indexOf("const DEALT_SECTIONS = {")
|
|
196
|
-
const end = source.indexOf("\n}\n", start)
|
|
197
|
-
const pool = source.indexOf("await pool(linkSelected")
|
|
198
|
-
if (start < 0 || end < 0 || pool < 0) {
|
|
199
|
-
fail("tests/run.js no longer declares DEALT_SECTIONS or runs the link pool where this looks")
|
|
200
|
-
}
|
|
201
|
-
const out = []
|
|
202
|
-
for (const m of source.slice(start, end).matchAll(/\n {2}(\w+): \{\s*name:\s*"([^"]+)",([^}]*)\}/g)) {
|
|
203
|
-
const at = source.indexOf(`dealtHere("${m[1]}")`)
|
|
204
|
-
if (at < 0) {
|
|
205
|
-
fail(`DEALT_SECTIONS.${m[1]} has no dealtHere("${m[1]}") block`)
|
|
206
|
-
}
|
|
207
|
-
if (RECOGNIZERS[m[1]] === undefined) {
|
|
208
|
-
fail(`DEALT_SECTIONS.${m[1]} has no recognizer: add the first check it prints to RECOGNIZERS`)
|
|
209
|
-
}
|
|
210
|
-
out.push({
|
|
211
|
-
key: m[1],
|
|
212
|
-
name: m[2],
|
|
213
|
-
pinned: /pinned:/.test(m[3]),
|
|
214
|
-
tail: /tail:/.test(m[3]),
|
|
215
|
-
at,
|
|
216
|
-
beforeLink: at < pool,
|
|
217
|
-
})
|
|
218
|
-
}
|
|
219
|
-
return out.sort((a, b) => a.at - b.at)
|
|
220
|
-
})()
|
|
221
|
-
|
|
222
|
-
/** One log line: its time in seconds and, for a check, its name. */
|
|
223
|
-
const parse = (log) =>
|
|
224
|
-
log.split("\n").map((line) => {
|
|
225
|
-
const m = /^\uFEFF?(\d{4}-\d\d-\d\dT[\d:.]+Z) (.*)$/.exec(line)
|
|
226
|
-
const t = m ? Date.parse(m[1]) / 1000 : Number.NaN
|
|
227
|
-
const check = m ? /^(?:PASS|SKIP|FAIL) {2}(.*)$/.exec(m[2]) : null
|
|
228
|
-
return { t, body: m ? m[2] : line, check: check ? check[1] : null }
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
const LINK = /^link\/([^:]+)[: ]/
|
|
232
|
-
|
|
233
|
-
/** The pieces one shard's log measures, keyed as the table keys them. */
|
|
234
|
-
const measureShard = (lines, shard, shards, linkCount) => {
|
|
235
|
-
const summary = lines.findIndex((l) => /^\d+ passed, \d+ failed/.test(l.body))
|
|
236
|
-
if (summary < 0) {
|
|
237
|
-
fail(`shard ${shard}/${shards} has no summary line; was the run green?`)
|
|
238
|
-
}
|
|
239
|
-
// A failed check can stop a section early, so a red run's seconds are not its cost.
|
|
240
|
-
const failed = Number(/^\d+ passed, (\d+) failed/.exec(lines[summary].body)[1])
|
|
241
|
-
if (failed !== 0) {
|
|
242
|
-
fail(`shard ${shard}/${shards} reports ${failed} failed; measure green runs only`)
|
|
243
|
-
}
|
|
244
|
-
const delegated = new Set(
|
|
245
|
-
lines.map((l) => /^DELEGATED {2}(.*) -- proved by /.exec(l.body)?.[1]).filter((n) => n !== undefined)
|
|
246
|
-
)
|
|
247
|
-
const owned = sections.filter((s) => !delegated.has(s.name))
|
|
248
|
-
const find = (re, start, to) => {
|
|
249
|
-
for (let i = start; i < to; i++) {
|
|
250
|
-
if (lines[i].check !== null && re.test(lines[i].check)) {
|
|
251
|
-
return i
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return -1
|
|
255
|
-
}
|
|
256
|
-
const before = (i) => {
|
|
257
|
-
let j = i - 1
|
|
258
|
-
while (j > 0 && Number.isNaN(lines[j].t)) {
|
|
259
|
-
j--
|
|
260
|
-
}
|
|
261
|
-
return lines[j].t
|
|
262
|
-
}
|
|
263
|
-
const out = {}
|
|
264
|
-
const after = owned.filter((s) => !s.beforeLink)
|
|
265
|
-
// Each section after the link programs, in the order they run: where it starts.
|
|
266
|
-
const starts = []
|
|
267
|
-
let from = 0
|
|
268
|
-
for (const s of after) {
|
|
269
|
-
const i = find(RECOGNIZERS[s.key], from, summary)
|
|
270
|
-
if (i < 0) {
|
|
271
|
-
fail(
|
|
272
|
-
`shard ${shard}/${shards} ran ${s.key} (it does not delegate it) but prints nothing ${RECOGNIZERS[s.key]} matches`
|
|
273
|
-
)
|
|
274
|
-
}
|
|
275
|
-
starts.push(i)
|
|
276
|
-
from = i + 1
|
|
277
|
-
}
|
|
278
|
-
if (shard === 1) {
|
|
279
|
-
const i = find(SHARD_ONE_STARTS, from, summary)
|
|
280
|
-
if (i < 0) {
|
|
281
|
-
fail(`shard 1/${shards} prints no check ${SHARD_ONE_STARTS} matches`)
|
|
282
|
-
}
|
|
283
|
-
starts.push(i)
|
|
284
|
-
}
|
|
285
|
-
// The link programs end where the first section after them starts, or where
|
|
286
|
-
// the shard stops; they are the run of `link/` checks just before that, with
|
|
287
|
-
// whatever else prints between them (a delegation, a failure's detail).
|
|
288
|
-
const linkEnd = starts.length > 0 ? starts[0] : summary
|
|
289
|
-
let linkStart = linkEnd
|
|
290
|
-
for (let i = linkEnd - 1; i > 0; i--) {
|
|
291
|
-
if (lines[i].check !== null) {
|
|
292
|
-
if (!LINK.test(lines[i].check)) {
|
|
293
|
-
break
|
|
294
|
-
}
|
|
295
|
-
linkStart = i
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const programs = []
|
|
299
|
-
for (let i = linkStart; i < linkEnd; i++) {
|
|
300
|
-
if (lines[i].check === null) {
|
|
301
|
-
continue
|
|
302
|
-
}
|
|
303
|
-
const name = LINK.exec(lines[i].check)[1]
|
|
304
|
-
const last = programs.at(-1)
|
|
305
|
-
if (last && last.name === name) {
|
|
306
|
-
last.end = i
|
|
307
|
-
} else {
|
|
308
|
-
programs.push({ name, end: i })
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
const names = new Set(programs.map((p) => p.name))
|
|
312
|
-
if (linkCount !== undefined && names.size !== linkCount) {
|
|
313
|
-
fail(
|
|
314
|
-
`shard ${shard}/${shards} prints ${names.size} link programs where shard 1 says it dealt it ${linkCount}`
|
|
315
|
-
)
|
|
316
|
-
}
|
|
317
|
-
out.link = {}
|
|
318
|
-
let prev = before(linkStart)
|
|
319
|
-
for (const p of programs) {
|
|
320
|
-
out.link[p.name] = (out.link[p.name] ?? 0) + Math.max(0, lines[p.end].t - prev)
|
|
321
|
-
prev = lines[p.end].t
|
|
322
|
-
}
|
|
323
|
-
for (const s of owned.filter((o) => o.beforeLink)) {
|
|
324
|
-
const first = find(RECOGNIZERS[s.key], 0, linkStart)
|
|
325
|
-
if (first < 0) {
|
|
326
|
-
fail(
|
|
327
|
-
`shard ${shard}/${shards} ran ${s.key} but prints nothing ${RECOGNIZERS[s.key]} matches before its link programs`
|
|
328
|
-
)
|
|
329
|
-
}
|
|
330
|
-
let last = first
|
|
331
|
-
for (let i = first; i < linkStart; i++) {
|
|
332
|
-
if (lines[i].check !== null && RECOGNIZERS[s.key].test(lines[i].check)) {
|
|
333
|
-
last = i
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
out[s.key] = lines[last].t - before(first)
|
|
337
|
-
}
|
|
338
|
-
const jobEnd = lines.findLast((l) => !Number.isNaN(l.t)).t
|
|
339
|
-
const afterSuite = jobEnd - lines[summary].t
|
|
340
|
-
after.forEach((s, k) => {
|
|
341
|
-
const end = k + 1 < starts.length ? before(starts[k + 1]) : lines[summary].t
|
|
342
|
-
out[s.key] = end - before(starts[k]) + (s.pinned ? afterSuite : 0)
|
|
343
|
-
})
|
|
344
|
-
if (shard === 1) {
|
|
345
|
-
out.shardOne = lines[summary].t - before(starts.at(-1)) + afterSuite
|
|
346
|
-
}
|
|
347
|
-
const total = (lines[summary].t - lines.find((l) => !Number.isNaN(l.t)).t) / 60
|
|
348
|
-
const toLink = (before(linkStart) - lines.find((l) => !Number.isNaN(l.t)).t) / 60
|
|
349
|
-
console.error(
|
|
350
|
-
` shard ${shard}/${shards}: ${total.toFixed(1)} min to its summary, ${toLink.toFixed(1)} min before its ` +
|
|
351
|
-
`${names.size} link programs; ran ${owned.map((s) => s.key).join(", ") || "no dealt section"}`
|
|
352
|
-
)
|
|
353
|
-
return out
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/** The pieces one run measures: every shard's, merged. */
|
|
357
|
-
const measureRun = (dir) => {
|
|
358
|
-
const files = fs
|
|
359
|
-
.readdirSync(dir)
|
|
360
|
-
.map((f) => ({ f, m: /^\d+_test \(.*shard (\d+)_(\d+)\)\.txt$/.exec(f) }))
|
|
361
|
-
.filter((x) => x.m !== null)
|
|
362
|
-
.map((x) => ({ file: path.join(dir, x.f), shard: Number(x.m[1]), shards: Number(x.m[2]) }))
|
|
363
|
-
.sort((a, b) => a.shard - b.shard)
|
|
364
|
-
const shards = files[0]?.shards
|
|
365
|
-
if (files.length === 0 || files.length !== shards || files.some((x, i) => x.shard !== i + 1)) {
|
|
366
|
-
fail(
|
|
367
|
-
`${dir}: wants one test (…, shard i_n).txt for each i of n, found ${files.map((x) => x.shard).join(", ") || "none"}`
|
|
368
|
-
)
|
|
369
|
-
}
|
|
370
|
-
console.error(`${dir}:`)
|
|
371
|
-
const logs = files.map((x) => parse(fs.readFileSync(x.file, "utf8")))
|
|
372
|
-
// Shard 1 names how many link programs it dealt each other shard.
|
|
373
|
-
const counts = new Map()
|
|
374
|
-
for (const l of logs[0]) {
|
|
375
|
-
const m = /^DELEGATED {2}(\d+) tests\/link program\(s\) -- proved by shard (\d+)\//.exec(l.body)
|
|
376
|
-
if (m) {
|
|
377
|
-
counts.set(Number(m[2]), Number(m[1]))
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
const run = { link: {} }
|
|
381
|
-
logs.forEach((lines, i) => {
|
|
382
|
-
const got = measureShard(lines, i + 1, shards, i === 0 ? undefined : (counts.get(i + 1) ?? 0))
|
|
383
|
-
Object.assign(run.link, got.link)
|
|
384
|
-
for (const [key, value] of Object.entries(got)) {
|
|
385
|
-
if (key !== "link") {
|
|
386
|
-
if (run[key] !== undefined) {
|
|
387
|
-
fail(`${dir}: two shards ran ${key}`)
|
|
388
|
-
}
|
|
389
|
-
run[key] = value
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
})
|
|
393
|
-
for (const s of sections) {
|
|
394
|
-
if (run[s.key] === undefined) {
|
|
395
|
-
fail(`${dir}: no shard ran ${s.key}`)
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
return run
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
const median = (xs) => {
|
|
402
|
-
const s = [...xs].sort((a, b) => a - b)
|
|
403
|
-
return s.length % 2 === 1 ? s[(s.length - 1) / 2] : (s[s.length / 2 - 1] + s[s.length / 2]) / 2
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
const measured = runs.map(measureRun)
|
|
407
|
-
const table = { shardOne: Math.round(median(measured.map((r) => r.shardOne))) }
|
|
408
|
-
for (const s of sections.filter((x) => !x.tail)) {
|
|
409
|
-
table[s.key] = Math.round(median(measured.map((r) => r[s.key])))
|
|
410
|
-
}
|
|
411
|
-
// A program a run did not have (added since) is left out of that run's median.
|
|
412
|
-
const programs = [...new Set(measured.flatMap((r) => Object.keys(r.link)))].sort()
|
|
413
|
-
table.link = Object.fromEntries(
|
|
414
|
-
programs.map((name) => {
|
|
415
|
-
const seen = measured.map((r) => r.link[name]).filter((v) => v !== undefined)
|
|
416
|
-
return [name, Math.round(median(seen) * 10) / 10]
|
|
417
|
-
})
|
|
418
|
-
)
|
|
419
|
-
for (const s of sections.filter((x) => x.tail)) {
|
|
420
|
-
table[s.key] = Math.round(median(measured.map((r) => r[s.key])))
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
const text = `${JSON.stringify(table, null, 2)}\n`
|
|
424
|
-
if (write) {
|
|
425
|
-
fs.writeFileSync(path.join(root, "tests", "shard-costs.json"), text)
|
|
426
|
-
console.error(`wrote tests/shard-costs.json from ${runs.length} run(s)`)
|
|
427
|
-
} else {
|
|
428
|
-
process.stdout.write(text)
|
|
429
|
-
}
|
package/scripts/size-report.sh
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Before/after binary size report for an Nish module + driver + runtime.
|
|
3
|
-
# scripts/size-report.sh [--markdown] [--budgets] [module.ll] [driver.c]
|
|
4
|
-
#
|
|
5
|
-
# Prints one row per runtime .text* budget the gate measures, with its ceiling
|
|
6
|
-
# (from tests/runtime-budgets.js), the core's .rodata, and one row per build
|
|
7
|
-
# profile (debug, speed, size, and wasm when wasm-ld is available). --budgets
|
|
8
|
-
# stops after the runtime rows. --markdown emits a GitHub-flavoured table, used
|
|
9
|
-
# by CI for the job summary; the default is a plain aligned table. Linux and macOS.
|
|
10
|
-
set -euo pipefail
|
|
11
|
-
cd "$(dirname "$0")/.."
|
|
12
|
-
|
|
13
|
-
format=plain
|
|
14
|
-
budgets_only=0
|
|
15
|
-
args=()
|
|
16
|
-
for a in "$@"; do
|
|
17
|
-
case "$a" in
|
|
18
|
-
--markdown|--md) format=markdown ;;
|
|
19
|
-
--budgets) budgets_only=1 ;;
|
|
20
|
-
-h|--help) sed -n '2,9p' "$0"; exit 0 ;;
|
|
21
|
-
*) args+=("$a") ;;
|
|
22
|
-
esac
|
|
23
|
-
done
|
|
24
|
-
ll=${args[0]:-build/add.ll}
|
|
25
|
-
driver=${args[1]:-examples/main.c}
|
|
26
|
-
mkdir -p build/size
|
|
27
|
-
|
|
28
|
-
bytes() { wc -c < "$1" | tr -d ' '; } # macOS wc pads with spaces
|
|
29
|
-
row() { # row <profile> <bytes> <command>
|
|
30
|
-
if [ "$format" = markdown ]; then
|
|
31
|
-
printf '| `%s` | %s | `%s` |\n' "$1" "$2" "$3"
|
|
32
|
-
else
|
|
33
|
-
printf '%-36s %10s %s\n' "$1" "$2" "$3"
|
|
34
|
-
fi
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if [ "$format" = markdown ]; then
|
|
38
|
-
printf '| Profile | Bytes | Command |\n| --- | ---: | --- |\n'
|
|
39
|
-
else
|
|
40
|
-
printf '%-36s %10s %s\n' PROFILE BYTES COMMAND
|
|
41
|
-
fi
|
|
42
|
-
# The runtime budgets (docs/wp7-runtime.md, "Runtime additions and budget"): each runtime
|
|
43
|
-
# translation unit, in each configuration the gate measures, compiled alone at -Oz, the sum
|
|
44
|
-
# of its `.text*` sections, against its own ceiling. The gate is `node tests/run.js
|
|
45
|
-
# runtime-budget`; these rows are the same numbers for a reader, and the rows and their
|
|
46
|
-
# ceilings come from the table the gate reads, tests/runtime-budgets.js, because the two
|
|
47
|
-
# ceilings this script once wrote into its own labels stayed at 3,584 and 1,280 while the
|
|
48
|
-
# gate's moved to 3,606 and 1,536, and seven of the gate's nine rows were never here.
|
|
49
|
-
# `tests/run.js` checks that every row is printed, with its ceiling and the gate's number.
|
|
50
|
-
#
|
|
51
|
-
# It was reported here as the `text` *column* of `size` once, which also counts `.rodata`
|
|
52
|
-
# and the `.eh_frame` entries the size profile strips -- so this row read 4,696 against a
|
|
53
|
-
# 4,096 budget while the code it is about was at 2,775. Read-only data ships too, so it
|
|
54
|
-
# gets its own row rather than being folded in: Zmij's power-of-ten table is 9,872
|
|
55
|
-
# bytes of it, and section GC keeps them out of any binary that never formats a double (WP15).
|
|
56
|
-
# `.text.unlikely.` is summed with `.text` because a linked binary pays for both, and a ceiling
|
|
57
|
-
# on `.text` alone can be met by moving code to another section instead of by shrinking it.
|
|
58
|
-
text_sum() { # text_sum <object>: every .text* section, summed
|
|
59
|
-
size -A "$1" | awk '$1 ~ /^\.text/ { n += $2 } END { print n + 0 }'
|
|
60
|
-
}
|
|
61
|
-
sect() { size -A "$2" | awk -v s="$1" '$1 == s { print $2 }'; }
|
|
62
|
-
budgets=$(node tests/runtime-budgets.js)
|
|
63
|
-
while IFS=$'\t' read -r label src budget constant flags; do
|
|
64
|
-
obj="build/size/$(printf '%s' "$label" | tr -c 'A-Za-z0-9' _).o"
|
|
65
|
-
# shellcheck disable=SC2086 # the flags are words
|
|
66
|
-
"${CC:-clang}" -Oz $flags -c "$src" -o "$obj"
|
|
67
|
-
row "$label" "$(text_sum "$obj")" \
|
|
68
|
-
"clang -Oz ${flags:+$flags }-c $src && size -A (.text*; budget $budget, $constant)"
|
|
69
|
-
done <<< "$budgets"
|
|
70
|
-
row rodata "$(sect .rodata build/size/runtime_text_c.o)" "the text object's .rodata (no budget; the Zmij table lives here)"
|
|
71
|
-
if [ "$budgets_only" = 1 ]; then exit 0; fi
|
|
72
|
-
# `scripts/build.sh` compiles every other unit (its `halves`) beside any runtime.c it is handed, so naming the
|
|
73
|
-
# core here builds the whole runtime -- and `--gc-sections` then drops whatever this module
|
|
74
|
-
# never calls, which for `examples/add.ts` is all of it.
|
|
75
|
-
for p in debug speed size; do
|
|
76
|
-
scripts/build.sh "$ll" runtime/runtime.c "$driver" -o "build/size/app-$p" --profile "$p" >/dev/null
|
|
77
|
-
row "$p" "$(bytes "build/size/app-$p")" "scripts/build.sh $ll runtime/runtime.c $driver --profile $p"
|
|
78
|
-
done
|
|
79
|
-
# The wasm profile needs wasm-ld; ask clang where it would look (it checks its own
|
|
80
|
-
# bin dir before PATH). Skip the row when the linker is not installed.
|
|
81
|
-
if [ -x "$("${CC:-clang}" -print-prog-name=wasm-ld)" ]; then
|
|
82
|
-
scripts/build.sh "$ll" -o build/size/app.wasm --profile wasm >/dev/null
|
|
83
|
-
row wasm "$(bytes build/size/app.wasm)" "scripts/build.sh $ll --profile wasm"
|
|
84
|
-
fi
|
package/scripts/smoke.sh
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Smoke test: build every example program with `--link` in the `size` profile,
|
|
3
|
-
# run it, and print a table of binary sizes.
|
|
4
|
-
#
|
|
5
|
-
# scripts/smoke.sh [examples-dir] (default: examples/)
|
|
6
|
-
# npm run smoke (after `npm run build`)
|
|
7
|
-
# NISH=<nish> scripts/smoke.sh with that compiler instead
|
|
8
|
-
#
|
|
9
|
-
# NISH names the compiler, run as scripts/nish-compiler.sh says: a native
|
|
10
|
-
# `nish` directly and a Node entry point under node. Unset, it is build/nish,
|
|
11
|
-
# what `npm run build` leaves.
|
|
12
|
-
#
|
|
13
|
-
# A program is any examples/**/*.ts that declares `export const main`. It
|
|
14
|
-
# is expected to exit 0 unless it carries a `// smoke: exit <n>` comment; a
|
|
15
|
-
# `// smoke: argv <args>` comment passes those arguments on its command line
|
|
16
|
-
# (process.argv). A `// smoke: skip <reason>` comment leaves a file out: it
|
|
17
|
-
# declares a `main` but is not a native program, such as a browser page's
|
|
18
|
-
# entry (examples/wasm-arena/page.ts), and the reason is printed in the table.
|
|
19
|
-
# Every program reads /dev/null for stdin, so a run is the
|
|
20
|
-
# same from a terminal as in CI. The script exits non-zero if any program fails to compile,
|
|
21
|
-
# link, or run with the expected status. Binaries and IR go to build/smoke/.
|
|
22
|
-
# Needs clang on PATH.
|
|
23
|
-
set -uo pipefail
|
|
24
|
-
cd "$(dirname "$0")/.." || exit
|
|
25
|
-
|
|
26
|
-
examples=${1:-examples}
|
|
27
|
-
out=build/smoke
|
|
28
|
-
mkdir -p "$out"
|
|
29
|
-
|
|
30
|
-
# shellcheck source=scripts/nish-compiler.sh
|
|
31
|
-
. scripts/nish-compiler.sh
|
|
32
|
-
nish_compiler "${NISH:-build/nish}"
|
|
33
|
-
|
|
34
|
-
if ! command -v clang >/dev/null 2>&1 && [ -z "${CC:-}" ]; then
|
|
35
|
-
echo "error: smoke test needs clang on PATH (see docs/INSTALL.md)" >&2
|
|
36
|
-
exit 3
|
|
37
|
-
fi
|
|
38
|
-
|
|
39
|
-
# Either spelling declares the entry (docs/wp22-arrow-functions.md): the arrow
|
|
40
|
-
# `export const main = (...) => ...` is the form the corpus is written in, and
|
|
41
|
-
# `export function main` is still legal.
|
|
42
|
-
#
|
|
43
|
-
# `mapfile` would say this in one line and is a bash 4 builtin: macOS ships
|
|
44
|
-
# bash 3.2 (Apple will not ship GPLv3) and this script runs there too, since
|
|
45
|
-
# WP19 G3 wants the matrix on both operating systems. `while read` over the
|
|
46
|
-
# same pipeline is the portable spelling, and the process substitution keeps
|
|
47
|
-
# the loop out of a subshell so `programs` survives it.
|
|
48
|
-
programs=()
|
|
49
|
-
while IFS= read -r program; do
|
|
50
|
-
programs+=("$program")
|
|
51
|
-
done < <(grep -rl --include='*.ts' -E '^export (function main\b|const main[[:space:]]*=)' "$examples" | sort)
|
|
52
|
-
if [ ${#programs[@]} -eq 0 ]; then
|
|
53
|
-
echo "error: no examples with \`export const main\` under $examples" >&2
|
|
54
|
-
exit 1
|
|
55
|
-
fi
|
|
56
|
-
|
|
57
|
-
failed=0
|
|
58
|
-
skipped=0
|
|
59
|
-
rows=()
|
|
60
|
-
for src in "${programs[@]}"; do
|
|
61
|
-
# examples/multi/main.ts -> multi_main; examples/hello.ts -> hello
|
|
62
|
-
name=$(printf '%s' "${src#"$examples"/}" | sed -e 's/\.ts$//' -e 's#/#_#g')
|
|
63
|
-
exe="$out/$name"
|
|
64
|
-
skip=$(sed -n 's#^// smoke: skip \(.*\)#\1#p' "$src" | head -n 1)
|
|
65
|
-
if [ -n "$skip" ]; then
|
|
66
|
-
skipped=$((skipped + 1))
|
|
67
|
-
rows+=("$(printf '%-24s %10s %s' "$src" "-" "skipped: $skip")")
|
|
68
|
-
continue
|
|
69
|
-
fi
|
|
70
|
-
want=$(sed -n 's#^// smoke: exit \([0-9][0-9]*\).*#\1#p' "$src" | head -n 1)
|
|
71
|
-
want=${want:-0}
|
|
72
|
-
# `// smoke: args <flags>` passes extra compiler flags (e.g. --number-mode f64).
|
|
73
|
-
extra=$(sed -n 's#^// smoke: args \(.*\)#\1#p' "$src" | head -n 1)
|
|
74
|
-
# shellcheck disable=SC2086
|
|
75
|
-
if ! "${compiler[@]}" "$src" $extra --link "$exe" --profile size >"$out/$name.log" 2>&1; then
|
|
76
|
-
status="BUILD FAIL"
|
|
77
|
-
failed=1
|
|
78
|
-
sed 's/^/ /' "$out/$name.log" >&2
|
|
79
|
-
rows+=("$(printf '%-24s %10s %s' "$src" "-" "$status")")
|
|
80
|
-
continue
|
|
81
|
-
fi
|
|
82
|
-
bytes=$(wc -c < "$exe" | tr -d ' ') # macOS wc pads with spaces
|
|
83
|
-
|
|
84
|
-
# `// smoke: argv <args>` is the program's command line (WP7 process.argv).
|
|
85
|
-
argv=$(sed -n 's#^// smoke: argv \(.*\)#\1#p' "$src" | head -n 1)
|
|
86
|
-
# shellcheck disable=SC2086
|
|
87
|
-
"$exe" $argv </dev/null >"$out/$name.out" 2>"$out/$name.err"
|
|
88
|
-
got=$?
|
|
89
|
-
if [ "$got" -eq "$want" ]; then
|
|
90
|
-
status="ok (exit $got)"
|
|
91
|
-
else
|
|
92
|
-
status="RUN FAIL (exit $got, expected $want)"
|
|
93
|
-
failed=1
|
|
94
|
-
sed 's/^/ /' "$out/$name.err" >&2
|
|
95
|
-
fi
|
|
96
|
-
rows+=("$(printf '%-24s %10s %s' "$src" "$bytes" "$status")")
|
|
97
|
-
done
|
|
98
|
-
|
|
99
|
-
printf '%-24s %10s %s\n' PROGRAM BYTES STATUS
|
|
100
|
-
printf '%s\n' "${rows[@]}"
|
|
101
|
-
if [ "$failed" -ne 0 ]; then
|
|
102
|
-
echo "smoke: FAILED" >&2
|
|
103
|
-
exit 1
|
|
104
|
-
fi
|
|
105
|
-
echo "smoke: $((${#programs[@]} - skipped)) program(s) built (size profile) and ran, $skipped skipped"
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// The standard library's module files, one repository path per line:
|
|
3
|
-
// `std/text.ts`, `std/crypto/sha256.ts`, ...
|
|
4
|
-
//
|
|
5
|
-
// node scripts/std-module-paths.mjs
|
|
6
|
-
//
|
|
7
|
-
// Read from `stdModuleNames` in `src/std-modules.ts` of the tree this script
|
|
8
|
-
// sits in, so a release's presence gates (`.github/workflows/release.yml`)
|
|
9
|
-
// check the modules of the commit being released and adding a module never
|
|
10
|
-
// edits a workflow. `tests/run.js` holds the literal to what `std/` has, and
|
|
11
|
-
// this script's answer and each gate's call to it to that literal.
|
|
12
|
-
import fs from "node:fs"
|
|
13
|
-
import path from "node:path"
|
|
14
|
-
|
|
15
|
-
const root = path.resolve(import.meta.dirname, "..")
|
|
16
|
-
const source = fs.readFileSync(path.join(root, "src", "std-modules.ts"), "utf8")
|
|
17
|
-
// The formatter may break the arrow before a long literal, so the literal is
|
|
18
|
-
// read from the declaration wherever it wrapped (the same pattern tests/run.js uses).
|
|
19
|
-
const listed = /stdModuleNames = \(\): string =>\s*"([^"]*)"/.exec(source)
|
|
20
|
-
const names = listed?.[1].split(", ").filter(Boolean) ?? []
|
|
21
|
-
if (names.length === 0) {
|
|
22
|
-
console.error('std-module-paths: no `stdModuleNames = (): string => "..."` in src/std-modules.ts')
|
|
23
|
-
process.exit(1)
|
|
24
|
-
}
|
|
25
|
-
console.log(names.map((name) => `std/${name}.ts`).join("\n"))
|
package/scripts/undocumented.txt
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Public declarations of std/ and runtime/nish.d.ts that lack their documentation.
|
|
2
|
-
#
|
|
3
|
-
# This list only shrinks. `node scripts/gen-reference.mjs --check` fails on a gap
|
|
4
|
-
# it does not list and on a line that is no longer a gap: document the
|
|
5
|
-
# declaration and delete its line. `--update-baseline` rewrites the file and
|
|
6
|
-
# refuses to add a line; `--grow-baseline` adds them, only for a change to the rule.
|
|
7
|
-
# docs/README.md -> "The library reference" states the rule.
|
|
8
|
-
#
|
|
9
|
-
# module.Name.member the declaration has no doc comment
|
|
10
|
-
# module.Name#param:p parameter p has no @param
|
|
11
|
-
# module.Name#returns a return type other than void or never has no @returns
|
|
12
|
-
|
|
13
|
-
runtime/nish.HostHandle.__type.__nishHostKind
|
|
14
|
-
runtime/nish.nish.HostHandle.__type.__nishHostKind
|