nish 0.23.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
- | Functions and modules | annotated signatures, calls in any order, `export`/named relative `import`, whole-program attribute facts, `export const main` as the entry, `internal` linkage for everything not exported | [Declarations](docs/LANGUAGE.md#declarations) |
175
- | Control flow | `if`/`else`, `while`, `do`, `for`, `for...of`, `break`/`continue`, boolean-only conditions, definite return, unreachable-code errors | [Statements](docs/LANGUAGE.md#statements) |
176
- | Expressions | `+ - * / %` (integer `/` and `%` checked: zero divisor or `MIN / -1` panics), numeric-only ordering, `=== !==` (strings by content), `&& \|\|`, `?:`, `op=`, `++`/`--`, template literals, contextual numeric literals | [Expressions](docs/LANGUAGE.md#expressions) |
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` | [Arrays](docs/LANGUAGE.md#array-literals) |
179
- | Classes and interfaces | LLVM structs with clang's layout, constructors, methods, `readonly`, definite assignment, object literals, `implements` by identical layout | [Classes](docs/LANGUAGE.md#classes) |
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
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 (`Arena.reset` and `Arena.release` are deprecated) | [`using a = arena()`](docs/LANGUAGE.md#using-a--arena), [`Arena`](docs/LANGUAGE.md#arena), [Memory](docs/LANGUAGE.md#memory-model) |
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
- | Builtins | `console.log`, `Math.*` as LLVM intrinsics (ECMAScript `pow` corner cases included), `Math.random`, `toI32`/`toI64`/`toF64`, `process.exit`, `readFileSync`/`writeFileSync`/`appendFileSync`; the runtime-backed ones are also importable from `nish:fs` / `nish:process` / `nish:io` / `nish:net`, 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) |
185
- | Rejected | `any`, `unknown`, `var`, `==`, `?.`, `??`, generic type aliases, `async`, `try`, `throw`, `typeof`, `delete`, prototypes, `Object.assign`, string-keyed access, ... with exact messages | [Forbidden constructs](docs/LANGUAGE.md#forbidden-constructs-phase-0-validator) |
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), a test runner, so a compiled program can check
200
- itself and answer an exit code with no Node in the picture,
201
- [`std/text`](std/text.ts), the string operations a program would otherwise write
202
- inline — the language has no `split`, `trim` or regular expression, because each
203
- of those allocates and some need a character table the runtime has no room for —
204
- and [`std/json`](std/json.ts), the value of one field of one flat JSON object,
205
- which is the shape the compiler's own `--json` diagnostics have. Beside them,
206
- `nish/crypto/*` holds the primitives under TLS 1.3 (SHA-2, HMAC, HKDF,
207
- ChaCha20-Poly1305, AES-GCM, X25519, P-256 ECDSA, X.509) and `nish/net/*` the
208
- protocols written on them (TLS 1.3, QUIC, HPACK, HTTP/1.1, WebSocket); the
209
- [`std/` README](std/README.md) lists every module.
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. What the library does *not* have is callbacks,
226
- which is what makes a suite a value with methods rather than a
227
- `test("name", () => ...)`: a function is never a value here.
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 `?.` is forbidden — which is what lets the emitter put `nonnull dereferenceable` on every pointer that is not one | [Nullable types](docs/LANGUAGE.md#nullable-types) |
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
 
@@ -342,7 +356,12 @@ Capabilities, Interop, Inspect, Code generation), then the exit codes and a
342
356
  few examples; it is coloured on a terminal and plain when piped, under
343
357
  `NO_COLOR` or when a coding agent runs it. An unknown flag is refused in one
344
358
  line that points at `--help`. [The CLI](docs/guide/using-nish/cli.md) walks
345
- through the flags you will reach for.
359
+ through the flags you will reach for. Among them: `--link` builds a native
360
+ binary, and `--fix` applies the compiler's safe fixes in place.
361
+ `--allow`/`--deny` refuse a program that reaches more than a capability
362
+ policy grants, and `--update-capability-lock` records what each dependency
363
+ reaches. `--deny-panics` refuses any panic the compiler cannot prove away.
364
+ `--emit-ts` writes the program out as plain TypeScript instead of IR.
346
365
 
347
366
  Exit codes: `0` success, `1` compile error (`file:line:col: error: ...` plus
348
367
  a caret excerpt), `2` usage error, `3` toolchain error, `70` internal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nish",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
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.23.0",
96
- "@amritk/nish-aarch64-linux": "0.23.0",
97
- "@amritk/nish-aarch64-darwin": "0.23.0",
98
- "@amritk/nish-x86_64-darwin": "0.23.0"
95
+ "@amritk/nish-x86_64-linux": "0.23.1",
96
+ "@amritk/nish-aarch64-linux": "0.23.1",
97
+ "@amritk/nish-aarch64-darwin": "0.23.1",
98
+ "@amritk/nish-x86_64-darwin": "0.23.1"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@biomejs/biome": "2.5.12",
@@ -1334,18 +1334,24 @@ export class Http1Connection {
1334
1334
  }
1335
1335
 
1336
1336
  /**
1337
- * The soonest `expired` can turn true, however the connection moves from
1338
- * here: `lastActive` only grows, and a head clock not yet started starts
1339
- * no earlier than it.
1337
+ * The soonest `expired` can turn true at or after `now` (`monotonicNanos`),
1338
+ * however the connection moves from here: `lastActive` only grows, and a
1339
+ * head clock not yet started starts no earlier than `now`, unless an
1340
+ * exchange is open: `nextRequest` starts a pipelined head's clock at
1341
+ * `lastActive` when it ends. Counting a quiet keep-alive's clock from
1342
+ * `lastActive` put it in the past once it was quiet for longer than
1343
+ * `headTimeout`, so each `expire` walked every slot.
1340
1344
  */
1341
- expiresNoSooner(): i64 {
1342
- const idle: i64 = toI64(this.config.idleTimeout) * toI64(1000000)
1343
- const head: i64 = toI64(this.config.headTimeout) * toI64(1000000)
1344
- const soonest: i64 = this.lastActive + (head < idle ? head : idle)
1345
- if (this.headTimed && this.headSince + head < soonest) {
1346
- return this.headSince + head
1345
+ expiresNoSooner(now: i64): i64 {
1346
+ const idle: i64 = this.lastActive + toI64(this.config.idleTimeout) * toI64(1000000)
1347
+ let start: i64 = now
1348
+ if (this.headTimed) {
1349
+ start = this.headSince
1350
+ } else if (this.requestOpen) {
1351
+ start = this.lastActive
1347
1352
  }
1348
- return soonest
1353
+ const head: i64 = start + toI64(this.config.headTimeout) * toI64(1000000)
1354
+ return head < idle ? head : idle
1349
1355
  }
1350
1356
  }
1351
1357
 
@@ -1679,8 +1685,8 @@ export class Http1Server {
1679
1685
  if (conn.expired(now)) {
1680
1686
  this.close(k)
1681
1687
  n = n + 1
1682
- } else if (conn.expiresNoSooner() < soonest) {
1683
- soonest = conn.expiresNoSooner()
1688
+ } else if (conn.expiresNoSooner(now) < soonest) {
1689
+ soonest = conn.expiresNoSooner(now)
1684
1690
  }
1685
1691
  }
1686
1692
  }
@@ -1982,8 +1988,8 @@ export class Http1TlsServer {
1982
1988
  if (conn.expired(now)) {
1983
1989
  this.tls.close(k)
1984
1990
  n = n + 1
1985
- } else if (conn.expiresNoSooner() < soonest) {
1986
- soonest = conn.expiresNoSooner()
1991
+ } else if (conn.expiresNoSooner(now) < soonest) {
1992
+ soonest = conn.expiresNoSooner(now)
1987
1993
  }
1988
1994
  }
1989
1995
  }