nish 0.23.0 → 0.24.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 +51 -40
- package/docs/AI.md +26 -19
- package/llms.txt +1 -1
- package/package.json +5 -5
- package/runtime/core/arrays.d.ts +0 -2
- package/runtime/core/arrays.mjs +0 -2
- package/runtime/core/numbers.mjs +2 -3
- package/runtime/nish.d.ts +0 -4
- package/runtime/nish.mjs +2 -5
- package/runtime/runtime-net.c +1 -1
- package/runtime/runtime-term.c +2 -2
- package/runtime/runtime.c +1 -1
- package/scripts/gen-diagnostic-codes.mjs +2 -1
- package/std/README.md +20 -0
- package/std/compress/checksum.ts +178 -0
- package/std/compress/deflate.ts +2400 -0
- package/std/compress/gzip.ts +747 -0
- package/std/compress/zlib.ts +168 -0
- package/std/crypto/sha256.ts +2 -3
- package/std/crypto/x25519.ts +3 -4
- package/std/net/http-compress.ts +393 -0
- package/std/net/http1-server.ts +115 -14
package/README.md
CHANGED
|
@@ -170,19 +170,25 @@ ship in the npm package, and [llms.txt](llms.txt) indexes them.
|
|
|
170
170
|
|
|
171
171
|
| Feature | Summary | Reference |
|
|
172
172
|
|:---|:---|:---|
|
|
173
|
-
| Types | `number` (`i32` by default, `double` with `--number-mode f64`), `i32`, `i64`, `f64`, `boolean`, `string`, `T[]`, classes, interfaces, `T \| null`, `void`; 1:1 LLVM mapping, no implicit conversions | [Types](docs/LANGUAGE.md#types) |
|
|
174
|
-
|
|
|
175
|
-
|
|
|
176
|
-
|
|
|
173
|
+
| Types | `number` (`i32` by default, `double` with `--number-mode f64`), `i32`, `i64`, unsigned `u8`/`u16`/`u32`/`u64`, `f32`, `f64`, ranged `integer<Lo, Hi>`, `boolean`, `string`, `T[]` and `readonly T[]`, classes, interfaces, `T \| null`, `void`; 1:1 LLVM mapping, no implicit conversions | [Types](docs/LANGUAGE.md#types) |
|
|
174
|
+
| Enums, aliases and unions | numeric `enum`s as a distinct type, with members usable as types (`Kind.Circle`); `type` aliases; discriminated unions `Circle \| Square` of classes or interfaces tagged by an enum-member field, narrowed by testing the tag; all exportable across modules | [Enums](docs/LANGUAGE.md#enums), [Type aliases](docs/LANGUAGE.md#type-aliases), [Discriminated unions](docs/LANGUAGE.md#discriminated-unions) |
|
|
175
|
+
| Functions and modules | annotated signatures, calls in any order, `export`/named relative `import`, packages by name, whole-program attribute facts, `export const main` as the entry, `internal` linkage for everything not exported; a parameter may have a function type, and each function or arrow passed to it compiles to its own instantiation with a direct call, never a function pointer | [Declarations](docs/LANGUAGE.md#declarations), [Function parameters](docs/LANGUAGE.md#function-parameters) |
|
|
176
|
+
| Control flow | `if`/`else`, `while`, `do`, `for`, `for...of` (arrays, `Map` keys and values, `Set`), `switch` (exhaustive over a union's tag), `break`/`continue`, boolean-only conditions, definite return, unreachable-code errors | [Statements](docs/LANGUAGE.md#statements) |
|
|
177
|
+
| Expressions | `+ - * / %` (integer `/` and `%` checked: zero divisor or `MIN / -1` panics), shifts and bitwise operators, numeric-only ordering, `=== !==` (strings by content), `&& \|\|`, `?:`, `??` on a `T \| null` and a `?.` chain that ends in `??`, `op=`, `++`/`--`, template literals, contextual numeric literals | [Expressions](docs/LANGUAGE.md#expressions) |
|
|
177
178
|
| Strings | immutable UTF-8 (`.length` is the byte length), literals as constant data, `+`, `===`, templates, `console.log` | [Builtins](docs/LANGUAGE.md#builtins), [Semantics](docs/LANGUAGE.md#semantics-decisions) |
|
|
178
|
-
| Arrays | `T[]` with one element type, literals, `new Array<T>(n)` zero-filled, bounds-checked `a[i]` (panic, or `uncheckedGet` from `nish:unsafe`), `.length`, `push`, `for...of
|
|
179
|
-
|
|
|
179
|
+
| Arrays | `T[]` with one element type, literals, `new Array<T>(n)` zero-filled, bounds-checked `a[i]` (panic, or `uncheckedGet` from `nish:unsafe`), `.length`, `push`/`pop`, `set`/`fill`, `for...of`; arrays of records stored contiguously and fixed-length array fields inline | [Arrays](docs/LANGUAGE.md#array-literals) |
|
|
180
|
+
| `Map` and `Set` | the global `Map<K, V>` and `Set<T>`, insertion-ordered, one probe per `get`/`set`/`has`/`delete`; `get` is `V \| undefined` and narrowed as TypeScript does | [`Map` and `Set`](docs/LANGUAGE.md#map-and-set) |
|
|
181
|
+
| Classes and interfaces | LLVM structs with clang's layout, constructors, methods, `readonly`, definite assignment, object literals, `implements` by identical layout; no inheritance | [Classes](docs/LANGUAGE.md#classes) |
|
|
180
182
|
| Generics | generic functions, classes, interfaces and methods by monomorphisation: one specialised `define` per instantiation, type arguments inferred at a call and written after `new` or in an annotation, `<T extends Shape>` constraints, exported instantiations callable from C and JavaScript as `nish_gen_identity_i32` | [Generic functions](docs/LANGUAGE.md#generic-functions) |
|
|
181
|
-
| Memory | no GC: objects that provably do not escape their function are stack `alloca`s, functions whose temporaries die with them get an automatic arena scope, `using a = arena()` frees a batch the compiler has checked nothing outlives, and `Arena.mark`/`Arena.used` read the arena
|
|
182
|
-
| `T \| null` | for class, interface, array and string types; `=== null`, and narrowing to `T` by `if`, early return, `while`, `&&`, `?:`, enforced by the checker | [Nullable types](docs/LANGUAGE.md#nullable-types) |
|
|
183
|
-
| Errors | Rust-style `Result<T, E>` with `Ok`/`Err`, `isOk()`/`isErr()`, `orReturn()` (the `?`), `unwrapOr`, `expect`; the checker refuses to let a failure be dropped or the success payload be read before the error is handled. No `throw`, no unwinding | [Result and error handling](docs/LANGUAGE.md#result-and-error-handling) |
|
|
184
|
-
|
|
|
185
|
-
|
|
|
183
|
+
| Memory | no GC: objects that provably do not escape their function are stack `alloca`s, functions whose temporaries die with them get an automatic arena scope, `using a = arena()` frees a batch the compiler has checked nothing outlives, and `Arena.mark`/`Arena.used` read the arena | [`using a = arena()`](docs/LANGUAGE.md#using-a--arena), [`Arena`](docs/LANGUAGE.md#arena), [Memory](docs/LANGUAGE.md#memory-model) |
|
|
184
|
+
| `T \| null` | for class, interface, array and string types; `=== null`, a `??` default, and narrowing to `T` by `if`, early return, `while`, `&&`, `?:`, enforced by the checker | [Nullable types](docs/LANGUAGE.md#nullable-types) |
|
|
185
|
+
| Errors | Rust-style `Result<T, E>` with `Ok`/`Err`, `isOk()`/`isErr()`, `orReturn()` (the `?`), `unwrapOr`, `expect`; the checker refuses to let a failure be dropped or the success payload be read before the error is handled. No `throw`, no unwinding: `panic(message)` ends the process | [Result and error handling](docs/LANGUAGE.md#result-and-error-handling) |
|
|
186
|
+
| Threads | `nish/threads`: `parallelMap`/`parallelReduce`, scoped tasks (`using s = scope()`), `Mutex<T>`, `AtomicI32`/`AtomicI64`, `Channel<T>`; data races and deadlocks refused at compile time | [Data parallelism](docs/LANGUAGE.md#data-parallelism-nishthreads) |
|
|
187
|
+
| Builtins | `console.log`, `Math.*` as LLVM intrinsics (JavaScript's `pow`, `round`, `min`/`max` corner cases included), `Math.random`, `toI32`/`toI64`/`toF64`, `process.exit`, files, directories, subprocesses, the environment and the clock; the runtime-backed ones are also importable from `nish:fs` / `nish:process` / `nish:io` / `nish:net` / `nish:term`, which is the same builtin under a name nothing can shadow; `nish:unsafe` (unchecked access, defined wrapping) and `nish:secret` (`Secret<T>`, key material the checker keeps in and wipes) are reached only by import | [Builtins](docs/LANGUAGE.md#builtins), [Builtin modules](docs/LANGUAGE.md#builtin-modules-nish) |
|
|
188
|
+
| Calling C | `declare function` binds a C symbol, `CPtr` holds an opaque C pointer, and a handle class bound with `using` is closed at every exit of its block | [Calling C](docs/LANGUAGE.md#calling-c) |
|
|
189
|
+
| Capabilities and policies | the compiler reports which capabilities (`fs.read`, `net`, `process.spawn`, `ffi`, `unsafe`, ...) every function, module and package reaches, with the call chain; `--allow`/`--deny` and `package.json` refuse a program that reaches one it is not granted, a dependency gets none it is not given, and a capability lockfile fails a build when a dependency reaches a new one. `--deny-panics` or `noPanic` refuses every panic site the compiler cannot prove away | [Capabilities](docs/LANGUAGE.md#capabilities), [The no-panic scope](docs/LANGUAGE.md#the-no-panic-scope) |
|
|
190
|
+
| Rejected | `any`, `unknown`, `var`, `==`, `?.` outside a `??` chain, generic type aliases, `async`, `try`, `throw`, `typeof`, `instanceof`, `delete`, prototypes, `Object.assign`, string-keyed access, ... with exact messages | [Forbidden constructs](docs/LANGUAGE.md#forbidden-constructs-phase-0-validator) |
|
|
191
|
+
|
|
186
192
|
Semantics that differ from JavaScript on purpose: signed integer overflow
|
|
187
193
|
panics unless the compiler proves the operation fits (`wrappingAdd`,
|
|
188
194
|
`wrappingSub` and `wrappingMul` from `nish:unsafe` wrap two's-complement; the
|
|
@@ -195,18 +201,25 @@ Node.
|
|
|
195
201
|
|
|
196
202
|
### The standard library
|
|
197
203
|
|
|
198
|
-
[`std/`](std/README.md) is Nish written in Nish, for Nish programs to import
|
|
199
|
-
[`std/testing`](std/testing.ts)
|
|
200
|
-
itself and
|
|
201
|
-
[`std/text`](std/text.ts)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
`
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
204
|
+
[`std/`](std/README.md) is Nish written in Nish, for Nish programs to import.
|
|
205
|
+
[`std/testing`](std/testing.ts) is a test runner, so a compiled program can
|
|
206
|
+
check itself and return an exit code with no Node involved. For text there is
|
|
207
|
+
[`std/text`](std/text.ts) (`trim`, `splitLines`, `splitWhitespace`,
|
|
208
|
+
`replaceAll`) and [`std/regex`](std/regex.ts), regular expressions in
|
|
209
|
+
JavaScript syntax whose search time is linear in the input. For data there is
|
|
210
|
+
`std/json` (plus a tokenizer, typed decoding and a value tree), `std/yaml`,
|
|
211
|
+
`std/base64` and `std/bytes`. Programs also get `std/cli` for arguments,
|
|
212
|
+
`std/random` (a seeded `Rng`), `std/map`, `std/collections`, `std/threads`,
|
|
213
|
+
`std/sqlite` (SQLite, the database in a file) and `std/term` (raw-mode
|
|
214
|
+
terminal I/O and styling, with pixel graphics in `std/term-pixels`).
|
|
215
|
+
`nish/crypto/*` holds the primitives: SHA-1/2, HMAC, PBKDF2, HKDF,
|
|
216
|
+
ChaCha20-Poly1305, AES-GCM, X25519, Ed25519, P-256 ECDSA, bcrypt and X.509,
|
|
217
|
+
with secret material held as a wiped `Secret<T>`. `nish/net/*` holds the
|
|
218
|
+
protocols built on them: TLS 1.3, QUIC, HTTP/1.1, HTTP/2 (HPACK), HTTP/3
|
|
219
|
+
(QPACK), WebSocket, WebTransport, a URL parser, an HTTP router, a prefork
|
|
220
|
+
server and a sans-IO PostgreSQL client. The [standard
|
|
221
|
+
library](docs/guide/using-nish/standard-library.md) guide page walks through
|
|
222
|
+
them, and the [`std/` README](std/README.md) lists every module.
|
|
210
223
|
|
|
211
224
|
```ts
|
|
212
225
|
import { Suite } from "nish/testing";
|
|
@@ -222,9 +235,10 @@ A library module is source, not a built artifact, so it compiles with the
|
|
|
222
235
|
program that imports it and the whole-program pass sees straight through it
|
|
223
236
|
([docs/wp21-packages.md](docs/wp21-packages.md)): `nish/<module>` resolves to
|
|
224
237
|
`std/<module>.ts` beside the running compiler, and what you import but never
|
|
225
|
-
call is dropped at the link.
|
|
226
|
-
|
|
227
|
-
|
|
238
|
+
call is dropped at the link. A function can be *passed* as a typed parameter.
|
|
239
|
+
Each call site is specialised into a direct call. A function is never a stored
|
|
240
|
+
value, so a suite is an object with methods rather than a registry of
|
|
241
|
+
`test("name", () => ...)` closures.
|
|
228
242
|
|
|
229
243
|
The suite's own golden cases are run by [`tests/nish/run.ts`](tests/nish/run.ts),
|
|
230
244
|
which is this repository's test harness written in the language it tests:
|
|
@@ -253,7 +267,7 @@ call on purpose.
|
|
|
253
267
|
|:---|:---|:---|
|
|
254
268
|
| Use-after-free, double free | Not expressible: nothing is freed individually. Four compile-time mechanisms decide where a value lives — a stack `alloca` when escape analysis proves it dies with the frame, an automatic arena scope when a function's temporaries do, a `nish_arena_keep` reclaim at the call site for a returned string, the bump arena otherwise — and the arena goes back when `main` returns | [Memory model](docs/LANGUAGE.md#memory-model), [wp6-memory.md](docs/wp6-memory.md) |
|
|
255
269
|
| Out-of-bounds read or write | Every `a[i]`, `a[i] op= v`, `s.charCodeAt(i)`, `s.slice(a, b)` and `a.pop()` is bounds-checked, with an unsigned compare, so a negative index fails too; the failure prints `index out of range: <i> >= <len>` (or, for `slice`, `slice out of range: [<a>, <b>) of length <len>`) and exits 1. Where a flow-sensitive proof shows the index is already in range — a loop condition, a length guard, a hoisted `const n = a.length`, an unsigned index — **no check is emitted at all**, and the checks that survive inside a loop say so as a `performance` warning naming the guard that would remove them | [Element access](docs/LANGUAGE.md#element-access), `tests/cases/arr_bounds_panic`, `arr_bounds_proven` |
|
|
256
|
-
| Null dereference | `T \| null` is a separate type, for pointers only; member access needs a narrowing the checker accepts and `?.`
|
|
270
|
+
| Null dereference | `T \| null` is a separate type, for pointers only; member access needs a narrowing the checker accepts, and `?.` appears only in a chain that ends in a `??` default — which is what lets the emitter put `nonnull dereferenceable` on every pointer that is not one | [Nullable types](docs/LANGUAGE.md#nullable-types) |
|
|
257
271
|
| Uninitialised memory | `new Array<T>(n)` zero-fills and rejects pointer element types, because a zeroed pointer would be a null nobody declared; class fields are definitely assigned | [Classes](docs/LANGUAGE.md#classes), `tests/cases/arr_new_zeroed` |
|
|
258
272
|
| Unwinding past a release | There is none. Every function is `nounwind`; a failure a caller should handle is a `Result<T, E>` and one it should not is `panic(message)` — stderr, exit 1 | [Result](docs/LANGUAGE.md#result-and-error-handling) |
|
|
259
273
|
|
|
@@ -299,25 +313,17 @@ weaker: one global arena, per-function granularity, no region polymorphism.
|
|
|
299
313
|
### Where it is not safe
|
|
300
314
|
|
|
301
315
|
> [!CAUTION]
|
|
302
|
-
>
|
|
303
|
-
|
|
304
|
-
- **`Arena.reset()` / `Arena.release(m)`** release or recycle in O(1), and
|
|
305
|
-
doing either while anything allocated after the mark is still referenced is
|
|
306
|
-
undefined behaviour. The compiler protects its own marks — a function that
|
|
307
|
-
touches either, directly or through a callee, never gets an automatic
|
|
308
|
-
scope — and not yours. Both are deprecated (NL7001) in favour of
|
|
309
|
-
`using a = arena()`, the same release with the compiler refusing anything
|
|
310
|
-
that would outlive it ([`Arena`](docs/LANGUAGE.md#arena)).
|
|
316
|
+
> Two holes, each of them asked for by name.
|
|
317
|
+
|
|
311
318
|
- **`uncheckedGet` and `uncheckedSet`** from `nish:unsafe` read and write an
|
|
312
319
|
element with no bounds check, after which an out-of-range index at that site
|
|
313
320
|
is undefined behaviour. A module reaches them only through the import, so
|
|
314
321
|
every module that gives up a check says so at its top and every site is a
|
|
315
322
|
call (`tests/cases/unsafe_get_set`). That is a different thing from the
|
|
316
323
|
proof above: the proof removes a check the compiler showed was never going
|
|
317
|
-
to fire, and changes nothing about what the program means
|
|
318
|
-
`--unchecked-indexing` does the same to every index of your own package and
|
|
319
|
-
never reaches a dependency or `nish/`
|
|
324
|
+
to fire, and changes nothing about what the program means
|
|
320
325
|
([`nish:unsafe`](docs/LANGUAGE.md#nishunsafe-unchecked-access-and-defined-wrapping)).
|
|
326
|
+
No flag turns the checks off for a whole program.
|
|
321
327
|
- **Interop** hands a pointer to a C, wasm or N-API host, and what happens to
|
|
322
328
|
it there is the host's business
|
|
323
329
|
([wp8-interop.md](docs/wp8-interop.md)).
|
|
@@ -342,7 +348,12 @@ Capabilities, Interop, Inspect, Code generation), then the exit codes and a
|
|
|
342
348
|
few examples; it is coloured on a terminal and plain when piped, under
|
|
343
349
|
`NO_COLOR` or when a coding agent runs it. An unknown flag is refused in one
|
|
344
350
|
line that points at `--help`. [The CLI](docs/guide/using-nish/cli.md) walks
|
|
345
|
-
through the flags you will reach for.
|
|
351
|
+
through the flags you will reach for. Among them: `--link` builds a native
|
|
352
|
+
binary, and `--fix` applies the compiler's safe fixes in place.
|
|
353
|
+
`--allow`/`--deny` refuse a program that reaches more than a capability
|
|
354
|
+
policy grants, and `--update-capability-lock` records what each dependency
|
|
355
|
+
reaches. `--deny-panics` refuses any panic the compiler cannot prove away.
|
|
356
|
+
`--emit-ts` writes the program out as plain TypeScript instead of IR.
|
|
346
357
|
|
|
347
358
|
Exit codes: `0` success, `1` compile error (`file:line:col: error: ...` plus
|
|
348
359
|
a caret excerpt), `2` usage error, `3` toolchain error, `70` internal
|
package/docs/AI.md
CHANGED
|
@@ -90,8 +90,7 @@ so it refuses `-o` and `--link`. It rewrites your files in place, with no
|
|
|
90
90
|
backup, so run it on a committed or backed-up tree. Run it first, then read
|
|
91
91
|
what remains. A warning can carry a fix too, and `--fix` applies it only when the program
|
|
92
92
|
compiles and the warning would be printed: `NL9007`'s inserts the guard that
|
|
93
|
-
proves an index in range (not under `--no-warn-performance`)
|
|
94
|
-
migrates a site off `--unchecked-indexing` (below).
|
|
93
|
+
proves an index in range (not under `--no-warn-performance`).
|
|
95
94
|
|
|
96
95
|
When it compiles, **check the native build against the program's TypeScript
|
|
97
96
|
reading**. Run the project's tests natively; where it has none, write the
|
|
@@ -247,14 +246,9 @@ the site: `uncheckedGet(xs, i)` and `uncheckedSet(xs, i, v)` on an array of
|
|
|
247
246
|
numbers with an `i32` index (out of range is undefined behaviour), and
|
|
248
247
|
`wrappingAdd` / `wrappingSub` / `wrappingMul` on two `i32`s or two `i64`s.
|
|
249
248
|
The sixth export, `readCString`, copies a C string out of a `CPtr`
|
|
250
|
-
([Calling C](#calling-c)). Calling one without the import is NL2456.
|
|
251
|
-
`--
|
|
252
|
-
|
|
253
|
-
`nish --unchecked-indexing --fix` on your files: each index the flag leaves
|
|
254
|
-
unchecked is a `deprecation` warning of its own (NL7002), and where the site
|
|
255
|
-
is a number array with an `i32` index its `fix` rewrites it to `uncheckedGet`
|
|
256
|
-
or `uncheckedSet` and adds the import. A site with no rewrite keeps its
|
|
257
|
-
warning; dropping the flag gives it back its bounds check.
|
|
249
|
+
([Calling C](#calling-c)). Calling one without the import is NL2456. No flag turns the checks off for a
|
|
250
|
+
whole program: `--unchecked-indexing` and `--wrapping` were removed before 1.0
|
|
251
|
+
and are refused with exit 2.
|
|
258
252
|
|
|
259
253
|
```ts nish:ok
|
|
260
254
|
import { uncheckedGet, wrappingAdd, wrappingMul } from "nish:unsafe";
|
|
@@ -280,8 +274,7 @@ where it can prove the result fits — a loop counter under `i < n`, a byte
|
|
|
280
274
|
widened with `toI32`, an `integer<Lo, Hi>`, a value masked with `& c`. Arithmetic
|
|
281
275
|
that is *meant* to wrap — a hash, a PRNG, a checksum — goes in `u32` or `u64`,
|
|
282
276
|
which always wrap and are never checked; convert back with `toI32` (free), or
|
|
283
|
-
call `wrappingAdd` / `wrappingSub` / `wrappingMul` at the site.
|
|
284
|
-
`--wrapping` makes every signed operation of your own package wrap instead.
|
|
277
|
+
call `wrappingAdd` / `wrappingSub` / `wrappingMul` at the site.
|
|
285
278
|
|
|
286
279
|
```ts nish:ok
|
|
287
280
|
// FNV-1a: the multiply overflows on purpose, so the state is a `u32`.
|
|
@@ -2209,7 +2202,8 @@ unread is reported again. Add `signalFd()` to the loop to wake on SIGTERM. None
|
|
|
2209
2202
|
exists on a wasm target, and under Node each throws.
|
|
2210
2203
|
|
|
2211
2204
|
**Arena.** `Arena.mark()`, `Arena.used()` and `using a = arena()` — see below.
|
|
2212
|
-
`Arena.release(m)` and `Arena.reset()`
|
|
2205
|
+
`Arena.release(m)` and `Arena.reset()` were removed before 1.0: write
|
|
2206
|
+
`using a = arena()`.
|
|
2213
2207
|
|
|
2214
2208
|
### Map and Set
|
|
2215
2209
|
|
|
@@ -2494,10 +2488,9 @@ anything that runs for a long time, should compile with `--deny-retention`,
|
|
|
2494
2488
|
which makes this warning and the three like it errors.
|
|
2495
2489
|
|
|
2496
2490
|
Everything else is bumped from the arena, which is released when `main`
|
|
2497
|
-
returns.
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
with a `deprecation` warning (NL7001) pointing to `using a = arena()`.
|
|
2491
|
+
returns. To give memory back sooner, scope it with `using a = arena()`;
|
|
2492
|
+
`Arena.release` and `Arena.reset` are gone, and a call to either is an unknown
|
|
2493
|
+
builtin (NL2244).
|
|
2501
2494
|
|
|
2502
2495
|
## Recipes for what is missing
|
|
2503
2496
|
|
|
@@ -2584,6 +2577,21 @@ most 100 pairs. (No block, as for `nish/text`; `tests/link/std_url` is its
|
|
|
2584
2577
|
program, and the user guide's [standard-library
|
|
2585
2578
|
page](guide/using-nish/standard-library.md#nishneturl) its walk-through.)
|
|
2586
2579
|
|
|
2580
|
+
**Gzip a response, or read a gzipped body** — there is no `node:zlib` and no
|
|
2581
|
+
`CompressionStream`: `nish/compress/gzip` (and `zlib`, `deflate`) compress
|
|
2582
|
+
and decompress into buffers you own. Build a `GzipCompressor(DEFLATE_FAST)`
|
|
2583
|
+
once and call `compress(src, off, len, out, at)`, which answers the end or -1
|
|
2584
|
+
when `out` is shorter than `compressBound(len)`; `GzipDecompressor`'s
|
|
2585
|
+
`decompress(..., limit)` never writes more than `limit` bytes and answers a
|
|
2586
|
+
negative `DEFLATE_ERR_*` / `GZIP_ERR_*` code for any malformed stream, so test
|
|
2587
|
+
it before reading `out`. `GzipWriter` and `GzipReader` stream. On HTTP/1.1,
|
|
2588
|
+
`conn.respondEncoded(status, names, values, body, off, len, enc,
|
|
2589
|
+
conn.acceptEncoding())` with an `HttpCompressor` from `nish/net/http-compress`
|
|
2590
|
+
negotiates, compresses and sets the fields. Do not compress a secret beside
|
|
2591
|
+
text the client chose (BREACH). (No block, as for `nish/text`;
|
|
2592
|
+
`tests/link/std_compress` is its program, and the user guide's
|
|
2593
|
+
[compression page](guide/using-nish/compression.md) its walk-through.)
|
|
2594
|
+
|
|
2587
2595
|
**Pass a list to a PostgreSQL statement** — there is no driver that expands
|
|
2588
2596
|
`IN (...)` and no `pg`'s array serialiser: in `nish/net/postgres`, write
|
|
2589
2597
|
`= any($1::int8[])` or `unnest($1::text[])` and bind the list as one
|
|
@@ -2731,8 +2739,7 @@ export const at = (xs: i32[], i: i32): i32 => xs[i];
|
|
|
2731
2739
|
A call into the standard library or a dependency that may panic is refused at
|
|
2732
2740
|
the call (NL2458), because only its own author can prove it: call a function
|
|
2733
2741
|
that cannot panic, or make the call from a module outside the scope.
|
|
2734
|
-
|
|
2735
|
-
still refused. `uncheckedGet` and `uncheckedSet` are not proofs either, but
|
|
2742
|
+
`uncheckedGet` and `uncheckedSet` are not proofs, but
|
|
2736
2743
|
they cannot panic, and their `nish:unsafe` import is the module's visible
|
|
2737
2744
|
opt-in to an index out of range being undefined behaviour, so the scope allows
|
|
2738
2745
|
them (as `"allowed": true` sites) and a call into them is never refused:
|
package/llms.txt
CHANGED
|
@@ -27,7 +27,7 @@ the compiler.
|
|
|
27
27
|
- [User guide](https://raw.githubusercontent.com/amritk/nish/main/docs/guide/index.md): the language taught page by page for people writing programs — getting started, the language, the CLI, the standard library, interop and threads. Every marked example program is compiled by `npm test`.
|
|
28
28
|
- [Language reference](https://raw.githubusercontent.com/amritk/nish/main/docs/LANGUAGE.md): normative and exhaustive. Every rule cites the test that pins it and quotes the exact rejection message. Settles any disagreement with the rules card.
|
|
29
29
|
- [Ambient declarations](https://raw.githubusercontent.com/amritk/nish/main/runtime/nish.d.ts): reference this from `tsconfig.json` and `tsc --strict`, your editor and your language server accept `Result<T, E>`, `i32` and the rest. `nish` is still the authority — `tsc` cannot see the flow rules.
|
|
30
|
-
- [Standard library](https://raw.githubusercontent.com/amritk/nish/main/std/README.md): `std/testing`, a suite a program drives to check itself and answer an exit code; `std/text`, the `split` / `trim` / `replace` the language does not have; `std/json`, the value of one field of one flat JSON object — enough to read this compiler's own `--json` output; `nish/crypto`, SHA-256, SHA-384 and SHA-512, HMAC, HKDF, a constant-time compare, base64url, X25519, ChaCha20-Poly1305, AES-GCM, P-256 ECDSA and X.509 certificates, one module each (`nish/crypto/sha256` and so on), plus SHA-1 for WebSocket's handshake only; `nish/net`, the protocols written on them — the TLS 1.3 server handshake and record layer, TLS over TCP, QUIC, HPACK, the HTTP/1.1 parser, WebSocket framing, percent-decoding and query strings (`nish/net/url`), and a PostgreSQL client (`nish/net/postgres`); `nish/threads`, a parallel map and reduce. Source rather than a built library, imported as `nish/<module>`, and shipped in the npm package under `std/`.
|
|
30
|
+
- [Standard library](https://raw.githubusercontent.com/amritk/nish/main/std/README.md): `std/testing`, a suite a program drives to check itself and answer an exit code; `std/text`, the `split` / `trim` / `replace` the language does not have; `std/json`, the value of one field of one flat JSON object — enough to read this compiler's own `--json` output; `nish/crypto`, SHA-256, SHA-384 and SHA-512, HMAC, HKDF, a constant-time compare, base64url, X25519, ChaCha20-Poly1305, AES-GCM, P-256 ECDSA and X.509 certificates, one module each (`nish/crypto/sha256` and so on), plus SHA-1 for WebSocket's handshake only; `nish/net`, the protocols written on them — the TLS 1.3 server handshake and record layer, TLS over TCP, QUIC, HPACK, the HTTP/1.1 parser, WebSocket framing, percent-decoding and query strings (`nish/net/url`), and a PostgreSQL client (`nish/net/postgres`); `nish/compress`, gzip, zlib and raw DEFLATE both ways with CRC-32 and Adler-32, and `nish/net/http-compress` to gzip an HTTP response; `nish/threads`, a parallel map and reduce. Source rather than a built library, imported as `nish/<module>`, and shipped in the npm package under `std/`.
|
|
31
31
|
- [FAQ](https://raw.githubusercontent.com/amritk/nish/main/docs/FAQ.md): why no `any`, why `i32`, how to get JavaScript numbers, why no GC, why signed overflow panics and how to wrap on purpose, what errors look like.
|
|
32
32
|
- [Install](https://raw.githubusercontent.com/amritk/nish/main/docs/INSTALL.md): prerequisites per OS, hello world, exit codes, troubleshooting.
|
|
33
33
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nish",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Nish: an ahead-of-time compiler from a static subset of TypeScript to LLVM IR",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -92,10 +92,10 @@
|
|
|
92
92
|
"nish"
|
|
93
93
|
],
|
|
94
94
|
"optionalDependencies": {
|
|
95
|
-
"@amritk/nish-x86_64-linux": "0.
|
|
96
|
-
"@amritk/nish-aarch64-linux": "0.
|
|
97
|
-
"@amritk/nish-aarch64-darwin": "0.
|
|
98
|
-
"@amritk/nish-x86_64-darwin": "0.
|
|
95
|
+
"@amritk/nish-x86_64-linux": "0.24.0",
|
|
96
|
+
"@amritk/nish-aarch64-linux": "0.24.0",
|
|
97
|
+
"@amritk/nish-aarch64-darwin": "0.24.0",
|
|
98
|
+
"@amritk/nish-x86_64-darwin": "0.24.0"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@biomejs/biome": "2.5.12",
|
package/runtime/core/arrays.d.ts
CHANGED
|
@@ -15,8 +15,6 @@ export declare function arraySetAt<T>(dst: T[], src: readonly T[], offset?: numb
|
|
|
15
15
|
export declare function newArray<T>(n: number | bigint, zero: unknown): T[];
|
|
16
16
|
export declare function arenaUsed(): i64;
|
|
17
17
|
export declare function arenaMark(): i64;
|
|
18
|
-
export declare function arenaRelease(m?: unknown): void;
|
|
19
|
-
export declare function arenaReset(): void;
|
|
20
18
|
/**
|
|
21
19
|
* The protocol `using` reads, declared here as `nish.d.ts` does, so `using a =
|
|
22
20
|
* arena()` type-checks with no `"esnext.disposable"` in a program's `lib`.
|
package/runtime/core/arrays.mjs
CHANGED
|
@@ -145,8 +145,6 @@ export function newArray(n, zero) {
|
|
|
145
145
|
// that is when this file grows a second arena to keep count of.
|
|
146
146
|
export function arenaUsed() { return 0n; }
|
|
147
147
|
export function arenaMark() { return 0n; }
|
|
148
|
-
export function arenaRelease() {}
|
|
149
|
-
export function arenaReset() {}
|
|
150
148
|
/** `using a = arena()`: a disposable whose disposal does nothing, because there is no arena to release. */
|
|
151
149
|
export function arena() {
|
|
152
150
|
return { [Symbol.dispose]() {} };
|
package/runtime/core/numbers.mjs
CHANGED
|
@@ -90,7 +90,7 @@ export function ctEq(a, b) {
|
|
|
90
90
|
// ---- Checked arithmetic (wp33 R4) ----------------------------------------------------
|
|
91
91
|
//
|
|
92
92
|
// What `--emit-ts` writes for a signed `+ - *` and unary minus the compiler
|
|
93
|
-
//
|
|
93
|
+
// did not prove in range: the exact
|
|
94
94
|
// answer, or the panic `nish_panic_overflow` prints, in its words. An i32 is
|
|
95
95
|
// exact in a double until it leaves the range, and `Math.imul` is the
|
|
96
96
|
// wrapped product, so a product that differs from the double one overflowed.
|
|
@@ -121,8 +121,7 @@ function checkI64(r, op) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// `wrappingAdd`, `wrappingSub` and `wrappingMul` from `nish:unsafe`: the
|
|
124
|
-
// two's-complement answer at the operands' width, i32 or i64
|
|
125
|
-
// `--wrapping` says.
|
|
124
|
+
// two's-complement answer at the operands' width, i32 or i64.
|
|
126
125
|
export function wrappingAdd(a, b) {
|
|
127
126
|
return typeof a === "bigint" ? BigInt.asIntN(64, a + b) : (a + b) | 0;
|
|
128
127
|
}
|
package/runtime/nish.d.ts
CHANGED
|
@@ -617,10 +617,6 @@ declare module "nish:secret" {
|
|
|
617
617
|
declare const Arena: {
|
|
618
618
|
/** The current bump address. */
|
|
619
619
|
mark(): i64;
|
|
620
|
-
/** Free everything allocated since `m`. */
|
|
621
|
-
release(m: i64): void;
|
|
622
|
-
/** Recycle everything in O(1), keeping the newest chunk. */
|
|
623
|
-
reset(): void;
|
|
624
620
|
/** Bytes bumped in the current chunk. */
|
|
625
621
|
used(): i64;
|
|
626
622
|
};
|
package/runtime/nish.mjs
CHANGED
|
@@ -265,15 +265,12 @@ globalThis.parseFloat = shim.parseFloat;
|
|
|
265
265
|
// script under Node, which is one index later than Node's own `argv`.
|
|
266
266
|
process.argv = shim.argv();
|
|
267
267
|
|
|
268
|
-
// There is no arena. `mark
|
|
269
|
-
//
|
|
270
|
-
// zero, which is the honest number for a host that is not bump-allocating.
|
|
268
|
+
// There is no arena. `mark()` answers zero rather than failing so that a
|
|
269
|
+
// program which reads it still runs; `used()` answers zero too, which is the honest number for a host that is not bump-allocating.
|
|
271
270
|
// Delegated like everything else here rather than written inline, so that the
|
|
272
271
|
// answers cannot drift from the ones the rewritten runner gives.
|
|
273
272
|
provide("Arena", {
|
|
274
273
|
mark: shim.arenaMark,
|
|
275
|
-
release: shim.arenaRelease,
|
|
276
|
-
reset: shim.arenaReset,
|
|
277
274
|
used: shim.arenaUsed,
|
|
278
275
|
});
|
|
279
276
|
// `using a = arena()` releases nothing here either: what the block allocated
|
package/runtime/runtime-net.c
CHANGED
|
@@ -359,7 +359,7 @@ int32_t nish_connect_result(int32_t fd) {
|
|
|
359
359
|
|
|
360
360
|
/* `netRead(fd, buf, off, len)`: at most `len` bytes into `buf` from `off`.
|
|
361
361
|
The compiled call has already checked `0 <= off <= off + len <=
|
|
362
|
-
buf.length
|
|
362
|
+
buf.length`. */
|
|
363
363
|
int32_t nish_net_read(int32_t fd, nish_array *buf, int64_t off, int64_t len) {
|
|
364
364
|
ssize_t n = recv(fd, buf->data + off, (size_t)len, 0);
|
|
365
365
|
return n < 0 ? nish_net_fail() : (int32_t)n;
|
package/runtime/runtime-term.c
CHANGED
|
@@ -145,8 +145,8 @@ static int nish_stdin_ready(int32_t timeout_ms) {
|
|
|
145
145
|
|
|
146
146
|
/* `readStdin(buf, off, len)`: at most `len` bytes into `buf` from `off`, the
|
|
147
147
|
count, 0 at the end of the stream and -11 when nothing is waiting. The
|
|
148
|
-
compiled call has already checked `0 <= off <= off + len <= buf.length
|
|
149
|
-
|
|
148
|
+
compiled call has already checked `0 <= off <= off + len <= buf.length`.
|
|
149
|
+
A `read` that a
|
|
150
150
|
signal interrupts is asked again; one that would block (a descriptor some
|
|
151
151
|
other program made non-blocking) is -11 too, and so is a readiness check a
|
|
152
152
|
signal interrupts, which would otherwise fall through to a `read` that
|
package/runtime/runtime.c
CHANGED
|
@@ -1354,7 +1354,7 @@ nish_array *nish_alloc_array(uint64_t elem_size, uint64_t len) {
|
|
|
1354
1354
|
return a;
|
|
1355
1355
|
}
|
|
1356
1356
|
|
|
1357
|
-
/* process.argv: malloc, not the arena, so
|
|
1357
|
+
/* process.argv: malloc, not the arena, so no arena scope can free it. Built once by @main.
|
|
1358
1358
|
Deliberately *not* NISH_TLS (WP20 T0 §3.2): `nish_argv_init` writes it once
|
|
1359
1359
|
before the program's `main` body runs and nothing writes it afterwards, so
|
|
1360
1360
|
every thread may read the one copy. That holds only while no thread is
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
* - **The `NL9xxx` codes run from `NL9001` with no gap**, one per WP15
|
|
55
55
|
* section 8 rule, so a missing number is a rule that lost its code; and
|
|
56
56
|
* the `NL8xxx` codes run from `NL8001` the same way, one per WP33 row,
|
|
57
|
-
* and the `NL7xxx` codes from `NL7001`, one per deprecation
|
|
57
|
+
* and the `NL7xxx` codes from `NL7001`, one per deprecation, retired ones
|
|
58
|
+
* included.
|
|
58
59
|
* - **`RULE_COUNT` is the number of entries.**
|
|
59
60
|
*
|
|
60
61
|
* A fragment is the longest literal run of its message's template -- the rule
|
package/std/README.md
CHANGED
|
@@ -158,6 +158,25 @@ Three rules hold across the modules:
|
|
|
158
158
|
whose one secret, a private key, is base64-decoded by range masks and
|
|
159
159
|
otherwise only copied and handed to `crypto/p256.ts`.
|
|
160
160
|
|
|
161
|
+
## `nish/compress` — gzip, zlib and DEFLATE
|
|
162
|
+
|
|
163
|
+
Compression for a server that gzips its responses and reads compressed
|
|
164
|
+
bodies, in pure Nish. Every call takes caller-owned windows and answers where
|
|
165
|
+
its output ends; the objects (`Deflater`, `Inflater`, `GzipCompressor`, ...)
|
|
166
|
+
allocate their tables once and nothing per call, and a free function
|
|
167
|
+
(`gzipCompress`, ...) builds one for a single call. The inner loops use
|
|
168
|
+
`nish:unsafe`'s unchecked access, each site justified in
|
|
169
|
+
`docs/security/compress.md`, so a program built with `--deny unsafe` cannot
|
|
170
|
+
import them. Written from the RFCs, not ported. Speed against zlib and
|
|
171
|
+
libdeflate: `bench/gzip/`. Guide: [Compression](../docs/guide/using-nish/compression.md).
|
|
172
|
+
|
|
173
|
+
| Module | What it is | Reproduces |
|
|
174
|
+
| --- | --- | --- |
|
|
175
|
+
| [`compress/deflate.ts`](./compress/deflate.ts) | `Deflater(level)` and `Inflater`, raw DEFLATE. Levels 0 (stored), 1 to 3 (greedy on a four-byte hash, `DEFLATE_FAST` = 1) and 4 to 9 (lazy, `DEFLATE_DEFAULT` = 6); each block is the smallest of dynamic, fixed and stored by its exact size. `compress(src, off, len, out, at)` answers the end or `DEFLATE_NO_ROOM` (-1); `deflateBound(n)` / `compressBound(n)` are the most any level writes. `decompress(src, off, len, out, at, limit)` answers the end or a `DEFLATE_ERR_*` code (truncated, block type, stored length, Huffman, symbol, distance, output limit, trailing) and never panics on a stream; `inflate` is the resumable step under it (`INFLATE_DONE`, `INFLATE_NEED_INPUT`, `INFLATE_NEED_OUTPUT`) | RFC 1951: every level against Node's zlib both ways (`tests/link/std_compress_node`), round trips of empty to 1 MB inputs, a 1,500-input fuzz, every prefix and random corruption refused (`tests/link/std_compress`) |
|
|
176
|
+
| [`compress/gzip.ts`](./compress/gzip.ts) | `GzipCompressor(level)` / `GzipDecompressor` one-shot (the decompressor reads concatenated members, refuses trailing bytes, checks the header CRC, CRC-32 and length: `GZIP_ERR_HEADER`, `GZIP_ERR_CRC`, `GZIP_ERR_SIZE`), `gzipCompress` / `gzipDecompress`; `GzipWriter` (`write`, `flush`, `finish`, `bound`) and `GzipReader` (`feed` or `inputBuffer` / `commit`, `endInput`, `read` answering bytes, `GZIP_NEED_INPUT`, `GZIP_END` or an error, with a total `limit`) for bodies that arrive in pieces | RFC 1952: Node's gzip at every level, strategy and window, through both readers; the writer's output through Node's gunzip (`std_compress_node`, `std_compress`) |
|
|
177
|
+
| [`compress/zlib.ts`](./compress/zlib.ts) | `ZlibCompressor(level)` / `ZlibDecompressor`, `zlibCompress` / `zlibDecompress`: the two-byte header and Adler-32 trailer (`ZLIB_ERR_HEADER`, `ZLIB_ERR_ADLER`, `ZLIB_ERR_DICTIONARY` for `FDICT`) | RFC 1950, against Node's `deflateSync` / `inflateSync` (`std_compress_node`) |
|
|
178
|
+
| [`compress/checksum.ts`](./compress/checksum.ts) | `Crc32` (slicing-by-8 tables built once; `update(crc, buf, off, len)`), `crc32` for a one-off, `adler32`, `adler32Update` | The check values of "123456789", pieces against the whole, Adler-32's deferred reduction against its definition (`std_compress`) |
|
|
179
|
+
|
|
161
180
|
## `nish/net` — the protocol stack
|
|
162
181
|
|
|
163
182
|
The protocol lanes of [WP34](../docs/wp34-hosting-cs.md) §5, written on
|
|
@@ -201,6 +220,7 @@ reads one, and it still takes its randomness as an argument.
|
|
|
201
220
|
| [`net/http3.ts`](./net/http3.ts) | `Http3Connection`, the server side of HTTP/3 over a `QuicConnection`'s streams: `next()` answers `H3_REQUEST` (`stream`, `fields`), `H3_DATA` (a window onto `data`, at most `bodyChunk`), `H3_TRAILERS`, `H3_END`, `H3_RESET`, `H3_WRITABLE`, `H3_GOAWAY` or the final `H3_ERROR`; `respond`, `writeData` (takes what the send buffer has room for), `writeTrailers`, `reset` and `goaway` write. It opens its control stream with SETTINGS and its QPACK streams (capacity 0, through `nish/net/qpack`), checks every field section with `nish/net/http-fields`, answers a section past `maxFieldSectionSize` with a 431, sends one `date` field from the connection's `date` bytes on every final head (straight after `:status`, counted against the client's field-section limit, never on trailers) unless the program's fields hold one, and closes the connection with RFC 9114's code for each connection error. No server push. A warm connection allocates nothing per request (`docs/security/http3.md`) | RFC 9114 §4–§8 and RFC 9204 §4.2: a Nish client over QUIC, requests with bodies both ways, trailers, the date and its limit, GOAWAY, cancellation, every error code (`tests/link/net_http3`, `net_http3_errors`) |
|
|
202
221
|
| [`net/http3-server.ts`](./net/http3-server.ts) | `Http3Server`: HTTP/3 over QUIC on one UDP socket for a program that owns its loop — a pool of `QuicConnection` slots with an `Http3Connection` each, a slot's built on the first Initial accepted into it, slots 0 up, and reused, while the connection-ID index, the timer wheel and the rings are sized from the cap at start-up; a `QuicListener` in front; datagrams routed by a hashed index of every slot's connection IDs; `receive(now, key)`, `tick(now)`, `ready()` for the next slot with news, `flush(now)` sending paced GSO flights, `timeout(now)` from a timer wheel. A handshake that did not choose ALPN `h3` is closed with no_application_protocol (RFC 9114 §3.1); a slot done after GOAWAY is closed and freed. Every slot's final responses carry the server's one `HttpDate` (`date`), refreshed at `connection(slot)` and `ready()` and formatted at most once a second. `stop()` releases every connection and the listener and wipes the configuration's stateless reset and Retry token keys, which are the server's once handed in, and its last answer; the keys are zeroed in place, so a `QuicServerConfig` serves one server (QUIC-5). Native only, as `nish:net` is | A Nish client across loopback (`tests/link/net_http3_server`): requests, a paced 300 KB response, GOAWAY and the slot freed, ALPN, a full pool, the arena over connections through one slot while the pinned date moves a second on for each, one date formatted for two slots; every key read back as zero after `stop()` (`tests/link/net_quic_server_wipes`); aioquic and `curl --http3` against its `serve` mode |
|
|
203
222
|
| [`net/webtransport.ts`](./net/webtransport.ts) | `WebTransport`, the server side of WebTransport over HTTP/3 as draft-ietf-webtrans-http3-02 has it and Chrome and `wtransport` 0.7 negotiate it, a layer over one `Http3Connection` whose `Http3Config.webtransportSessions` turns it on (extended CONNECT, SETTINGS_H3_DATAGRAM and the draft's two WebTransport settings): `next()` answers `WT_SESSION` (the program `accept`s or `refuse`s it), `WT_DATAGRAM`, `WT_STREAM`, `WT_STREAM_DATA`, `WT_STREAM_END`, `WT_STREAM_RESET`, `WT_STREAM_STOPPED`, `WT_WRITABLE`, `WT_DRAIN` and `WT_CLOSED`, and passes a plain request's `H3_*` events through; `sendDatagram` (the quarter stream ID, then the payload), `openStream`, `write`, `resetStream`, `stopSending`, `close` (CLOSE_WEBTRANSPORT_SESSION) and `drain`. Streams that arrive before their session wait, bounded; every cap is fixed at start-up, and a warm session allocates nothing per datagram or stream (`docs/security/webtransport.md`) | RFC 9220, RFC 9297 and draft-02: a Nish client over QUIC — sessions, datagrams at the size limits, streams both ways, close and drain from either side, every refusal — and one exchange recorded from a `wtransport` 0.7 client replayed byte for byte (`tests/link/net_webtransport`) |
|
|
223
|
+
| [`net/http-compress.ts`](./net/http-compress.ts) | Content coding for HTTP responses: `httpAcceptEncoding(buf, start, end, offered)` reads an `Accept-Encoding` value (q-values, `*`, `identity`, `x-gzip`) into `HTTP_CODING_GZIP`, `HTTP_CODING_DEFLATE`, `HTTP_CODING_IDENTITY` or `HTTP_CODING_NONE`, allocating nothing; `HttpCompressor(level, minLength, maxLength)` gzips a body into its own buffer when it is worth it (-1 to send it as it is) and builds the response fields (`addFields`: `Content-Encoding: gzip` and, while `vary`, `Vary: Accept-Encoding`). On HTTP/1.1, `Http1Connection.acceptEncoding()` and `respondEncoded(status, names, values, body, off, len, enc, coding)` answer a request in one call with the compressed `Content-Length`, or nothing at all (`H1_AGAIN`, `H1_INVALID`). Opt-in; BREACH is the program's to avoid (`docs/security/compress.md`) | RFC 9110 §8.4 and §12.5.3: the negotiation table, and sans-IO responses gunzipped back (`tests/link/std_http_compress`) |
|
|
204
224
|
| [`net/router.ts`](./net/router.ts) | `Router`, a method and path router that knows no carrier and allocates nothing per match: `add(method, pattern)` answers the route's index (0, 1, 2 in the order added) or a refusal — `ROUTER_BAD_PATTERN`, `ROUTER_BAD_METHOD`, `ROUTER_TOO_LONG`, `ROUTER_AMBIGUOUS` (`*` not last), `ROUTER_DUPLICATE` (the same shape and method, whatever the parameter names) or `ROUTER_FULL`, against `RouterLimits`; `match(method, mStart, mEnd, target, tStart, tEnd, params)` answers the index, `ROUTER_NOT_FOUND` or `ROUTER_METHOD_NOT_ALLOWED`, writing each `:name` and a final `*` as a `[start, end)` pair into the caller's `params` (`ROUTER_TOO_MANY_PARAMS` when it is short). Literal before parameter before `*`, segment by segment, backtracking; a lookup enters each node at most once. The query is left unparsed and nothing is decoded: `routerDecode` decodes one parameter (`ROUTER_BAD_ESCAPE`, `ROUTER_NO_ROOM`) (`docs/security/router.md`) | Every refusal code, precedence and backtracking, 405 against 404, `%2F` kept in one segment, the query, `*` and authority-form targets, a target deeper than any route, the lookup bound, params past storage, and the arena flat over matches (`tests/link/net_router`, `net_router_f64`, five `net_router_negative_*`) |
|
|
205
225
|
| [`net/postgres.ts`](./net/postgres.ts) | `PgConnection`, a PostgreSQL client that reads no socket: the program fills `inputBuffer()` and sends `outputBuffer()`, and `next()` answers `PG_NEED_MORE`, `PG_READY`, `PG_DESCRIBED`, `PG_ROW`, `PG_COMPLETE`, `PG_ERROR`, `PG_NOTICE`, `PG_GROUP_DONE` or the final `PG_FAILED` (`failure`, one of the `PG_ERR_*` codes). Protocol 3.0: startup, `trust` and SCRAM-SHA-256 with the server's signature checked (cleartext and MD5 refused), the extended query protocol — `prepare`, `bindStart`, `paramInt` / `paramText` / `paramBytes` / `paramTextArray` / `paramIntArray` / `paramNull`, an array built element by element into the Bind (`arrayStart`, `arrayElement`, `arrayInt`, `arrayNull`, `arrayEnd`), `bindEnd`, `bindCancel` to drop a Bind not yet ended, `closeStatement`, `sync` — with up to `maxInFlight` groups pipelined. `PgBatcher` queues keyed reads of one statement shape (`addInt`, `addText`) and `take(conn)` binds up to `maxRequests` of them, each key once, as one execution over `unnest($1) with ordinality`; `row`, `end` and `fail` route its rows by their server-supplied ordinal, checked first, to `next(run)`'s per-request `PG_BATCH_ROW` and `PG_BATCH_DONE` / `PG_BATCH_MISSING` / `PG_BATCH_FAILED`; `take` answers a fresh handle each time, so a server's late or repeated event on a spent one is counted in `stray`, never routed or panicked on. It reads no clock and allocates nothing per request or row. A row's columns are windows onto the receive buffer (`colStart`, `colLength`), read in place by `int`, `bool`, `isNull` and `PgText`'s decoders (`timestamptz`, `PgArrayWalker` for `text[]`); no per-row or per-column allocation. The password is a `Secret<u8[]>`, wiped once the proof is made. Caps on message size, columns, groups in flight and SCRAM iterations (`docs/security/postgres.md`) | PostgreSQL 18's frontend/backend protocol chapter, RFC 5802 and RFC 7677: every builder, event and refusal (`tests/link/std_postgres`), and exchanges recorded from PostgreSQL 18 by `tests/postgres/record.mjs` replayed byte for byte (`tests/link/std_postgres_replay`); the batcher's queueing, caps and ordinal refusals (`tests/link/std_postgres_batch`) |
|
|
206
226
|
|