@fraczak/k 8.9.0 → 9.1.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/CHANGELOG.md +28 -0
- package/DOCS/ARCHITECTURE.md +5 -4
- package/DOCS/DICTIONARY.md +2 -2
- package/DOCS/FILE_FORMATS.md +11 -9
- package/DOCS/KIR_V1.md +5 -1
- package/DOCS/KTVM_SPEC.md +907 -0
- package/DOCS/KVM_EXECUTION_MODEL.md +3 -2
- package/DOCS/KVM_VS_KTVM_COMPARATIVE_STUDY.md +127 -0
- package/DOCS/PROFILING_AND_TRACING.md +13 -4
- package/DOCS/README.md +3 -2
- package/DOCS/REPL.md +16 -12
- package/README.md +138 -2
- package/backend-api.mjs +31 -16
- package/backends/llvm/README.md +4 -5
- package/backends/llvm/bin/k-llvm-build.mjs +7 -19
- package/backends/llvm/bin/k-llvm-compile.mjs +6 -18
- package/backends/llvm/bin/k-llvm.mjs +11 -33
- package/backends/llvm/src/cli.mjs +2 -12
- package/backends/llvm/src/executable.mjs +7 -95
- package/backends/llvm/src/kvm2llvm.mjs +1 -7
- package/backends/llvm/src/llvm.mjs +4 -113
- package/backends/llvm/tests/k-llvm-run.mjs +1 -6
- package/backends/llvm/tests/perf-support.mjs +3 -5
- package/backends/llvm/tests/test-llvm.mjs +2 -16
- package/backends/wasm/README.md +7 -3
- package/backends/wasm/bin/k-wasm-compile.mjs +4 -7
- package/backends/wasm/bin/k-wasm.mjs +4 -6
- package/backends/wasm/src/cli.mjs +8 -24
- package/backends/wasm/src/wasm.mjs +60 -57
- package/backends/wasm/tests/test-wasm.mjs +41 -2
- package/browser/repl-browser.mjs +9 -8
- package/browser/shims/buffer.mjs +31 -2
- package/browser/shims/child_process.mjs +26 -0
- package/browser/shims/fs.mjs +3 -1
- package/codecs/runtime/prefix-codec.mjs +67 -1
- package/conformance/run.mjs +17 -2
- package/harness/adapters/ktvm-llvm.mjs +118 -0
- package/harness/adapters/ktvm-wasm.mjs +104 -0
- package/harness/adapters/ktvm.mjs +133 -0
- package/harness/registry.mjs +9 -0
- package/ktvm/ast.mjs +218 -0
- package/ktvm/bit-deque.mjs +497 -0
- package/ktvm/fixtures/integer-streaming.k +477 -0
- package/ktvm/index.mjs +130 -0
- package/ktvm/llvm/index.mjs +202 -0
- package/ktvm/llvm/lower-c.mjs +1258 -0
- package/ktvm/llvm/runtime.h +3542 -0
- package/ktvm/llvm/test-llvm.mjs +476 -0
- package/ktvm/lower-kir.mjs +2221 -0
- package/ktvm/optimize/fuse-kernel.mjs +2111 -0
- package/ktvm/optimize/index.mjs +116 -0
- package/ktvm/optimize/mwtr.mjs +283 -0
- package/ktvm/optimize/simplify-procs.mjs +5250 -0
- package/ktvm/optimize/synthesize-tables.mjs +1105 -0
- package/ktvm/parser.mjs +1101 -0
- package/ktvm/printer.mjs +281 -0
- package/ktvm/schema.mjs +1134 -0
- package/ktvm/specialize.mjs +538 -0
- package/ktvm/test-conformance.mjs +597 -0
- package/ktvm/test-ktvm.mjs +1805 -0
- package/ktvm/test-optimize.mjs +598 -0
- package/ktvm/validator.mjs +1280 -0
- package/ktvm/vm.mjs +2225 -0
- package/ktvm/wasm/index.mjs +331 -0
- package/ktvm/wasm/lower-wasm.mjs +1272 -0
- package/ktvm/wasm/runtime.wat +4404 -0
- package/ktvm/wasm/test-wasm.mjs +429 -0
- package/ktvm/wire.mjs +679 -0
- package/package.json +1 -9
- package/paper/Makefile +8 -5
- package/paper/k-transducer-compiler.pdf +0 -0
- package/paper/k-transducer-compiler.tex +658 -0
- package/paper/replay-diagnostic.mjs +63 -0
- package/repl.mjs +101 -20
- package/scripts/build-repl-html.mjs +40 -18
- package/scripts/perf-bigint-compare.mjs +12 -16
- package/scripts/perf-ieee.mjs +14 -232
- package/scripts/perf-int.mjs +16 -274
- package/scripts/perf-multiplication.mjs +116 -121
- package/scripts/perf-poly.mjs +9 -263
- package/scripts/run-tests.mjs +5 -2
- package/scripts/test-package.mjs +15 -3
- package/tests/README.md +3 -3
- package/tests/test-repl-html.mjs +72 -15
- package/tests/test-repl.mjs +24 -17
- package/DOCS/POLYMORPHIC_IR.md +0 -86
- package/access-table.mjs +0 -343
- package/pkir.mjs +0 -772
- package/tests/test-access-table.mjs +0 -213
- package/tests/test-pkir.mjs +0 -530
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,34 @@ All notable changes to this project will be documented here.
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [9.1.0] — 2026-11-29 — Runtime Improvements and Published kTVM Paper
|
|
9
|
+
|
|
10
|
+
- Reuse LLVM arena blocks after same-block rollback in kVM, reducing repeated allocation.
|
|
11
|
+
- Forward validated wire for proven kVM WebAssembly identities and validate kTVM
|
|
12
|
+
WebAssembly input in its existing channel buffer.
|
|
13
|
+
- Document the current kTVM implementation, schema derivatives, prime decomposition,
|
|
14
|
+
specialization paths, and backend trade-offs in the reviewed compiler paper.
|
|
15
|
+
- Publish [kTVM: A Packed-Wire Execution Model and Compiler for K](https://zenodo.org/records/24653605)
|
|
16
|
+
and link the preprint, PDF, and LaTeX source from the README.
|
|
17
|
+
- Add reproducible compiler performance baselines and update profiling tools and documentation.
|
|
18
|
+
|
|
19
|
+
## [9.0.0] — 2026-11-26 — kTVM Packed-Wire Transducer VM, Wasm & LLVM Backends, and PKIR Removal
|
|
20
|
+
|
|
21
|
+
- **Breaking Changes (PKIR Removal)**:
|
|
22
|
+
- Remove the experimental PKIR layer (`pkir.mjs`, `access-table.mjs`, `DOCS/POLYMORPHIC_IR.md`, `tests/test-pkir.mjs`, `tests/test-access-table.mjs`) now that all execution backends (JS, kVM Wasm/LLVM, and kTVM JS/Wasm/LLVM) are natively polymorphic.
|
|
23
|
+
- Remove `--pkir`, `.pkir` input handling, `:pkir`, `:engine pkir`, `usePKIR`, and `compile*FromPKIR` APIs across `backend-api.mjs`, `backends/wasm/`, `backends/llvm/`, `repl.mjs`, `browser/repl-browser.mjs`, `scripts/build-repl-html.mjs`, `package.json`, and `scripts/perf-*.mjs`.
|
|
24
|
+
- **kTVM Packed-Wire Transducer VM (`ktvm/`)**:
|
|
25
|
+
- Introduce the standalone **kTVM** (`kTVM-P` / `kTVM`, `format: "k-tvm"`, v0.1) streaming pushdown transducer VM executing k relations directly over unmodified prefix-free `k-wire` bitstreams without materializing heap value trees.
|
|
26
|
+
- Implement core IR, `.ktvmp`/`.ktvm` DSL parser/printer, JSON serialization, Moore schema minimization, static validator (SPSC linearity, dual `(prodSchema, consSchema)` checking, DAG acyclicity, and table-to-CFG bisimulation verification), boundary envelope specializer (`specializeKTVM`), `KIR-P → kTVM-P` lowering (`lower-kir.mjs`), and strictly iterative `BitDeque` reference VM (`vm.mjs`, `wire.mjs`).
|
|
27
|
+
- Add verified `kTVM → kTVM` optimization pipeline (`ktvm/optimize/`): procedure deforestation, entry-guard `spec → switch` compilation, bounded short-bit unfolding, strict accumulator settlement (`after %tok`), CPS symbolic kernel fusion, TMC streaming with register/LIFO virtual-stack promotion, and L1-budgeted (64 KiB) SWAR bit-chunk/stack-chunk/FSM table synthesis via Howard's MWTR criterion.
|
|
28
|
+
- **kTVM WebAssembly & Native C/LLVM Backends (`ktvm/wasm/`, `ktvm/llvm/`)**:
|
|
29
|
+
- Add `ktvm/wasm/` lowering concrete `kTVM` modules to validated `.wasm` binaries via WABT with zero JS tree marshaling at the wire boundary, reusable `<= 128b`-inline + segmented-slab `BitDeque` buffers, slab freelist reclamation, and static table data segments.
|
|
30
|
+
- Add `ktvm/llvm/` lowering concrete `kTVM` modules to C99 compiled with `clang -O3` into standalone wire-to-wire native executables (register-cached fixed-width/self-looping DPDA, zero-`memset` inline-channel node slabs, eager `const_unit`/`wrap`/`splice` lowering, and batched slab reclamation).
|
|
31
|
+
- Integrate `ktvm-wasm` into the terminal and browser REPLs (`--ktvm`, `:ktvm`, `:engine ktvm`, and interactive 3-way badge cycling `wasm → ktvm → js`), and add `ktvm`, `ktvm-wasm`, and `ktvm-llvm` lanes to `harness/cli.mjs` and the five `ktvm/` test suites to `npm test`.
|
|
32
|
+
- **Documentation & Packaging**:
|
|
33
|
+
- Add [DOCS/KTVM_SPEC.md](DOCS/KTVM_SPEC.md) and [DOCS/KVM_VS_KTVM_COMPARATIVE_STUDY.md](DOCS/KVM_VS_KTVM_COMPARATIVE_STUDY.md), document all execution backends and usage in [README.md](README.md), and update all architecture, REPL, file-format, backend, and test guides.
|
|
34
|
+
- Tighten `.npmignore` (exclude `experiments/`, `DOCS/*.pdf`, `DOCS/ktvm-explainer.*`) and verify packed `ktvm/wasm/runtime.wat`, `ktvm/llvm/runtime.h`, and end-to-end kTVM Wasm execution in `scripts/test-package.mjs`.
|
|
35
|
+
|
|
8
36
|
## [8.9.0] — 2026-11-22 — Canonical Empty-Bit Zero Representation and BigInt-Free Integer Codec
|
|
9
37
|
|
|
10
38
|
- **Canonical Zero Representation (`{}|_` / `{}|_|+`)**:
|
package/DOCS/ARCHITECTURE.md
CHANGED
|
@@ -48,7 +48,7 @@ The execution representations have distinct roles:
|
|
|
48
48
|
| --- | --- | --- |
|
|
49
49
|
| KIR-P | `kir.mjs` | Portable export of object relations and pattern graphs |
|
|
50
50
|
| kVM | `kvm.mjs` | Register instructions, polymorphic templates, and specialization |
|
|
51
|
-
|
|
|
51
|
+
| kTVM | `ktvm/` | Packed-wire transducer VM: bit-stream lowering, optimization, Wasm & LLVM backends |
|
|
52
52
|
|
|
53
53
|
KIR-P envelope specialization (`retypeObjectRelation` and related functions)
|
|
54
54
|
can rerun contract derivation. kVM template specialization (`specializeKVM`)
|
|
@@ -57,11 +57,12 @@ Do not treat these as the same pass.
|
|
|
57
57
|
|
|
58
58
|
The Wasm and LLVM backends lower kVM instructions through
|
|
59
59
|
`backends/wasm/src/kvm2wasm.mjs` and `backends/llvm/src/kvm2llvm.mjs`.
|
|
60
|
-
|
|
60
|
+
In parallel, `ktvm/wasm/` and `ktvm/llvm/` lower packed-wire kTVM modules
|
|
61
|
+
directly to WebAssembly and LLVM IR over `BitDeque` bit-streams.
|
|
61
62
|
`backend-api.mjs` exposes the shared compiler/backend API.
|
|
62
63
|
|
|
63
64
|
See the [KIR-P](KIR_V1.md), [kVM](KVM_EXECUTION_MODEL.md), and
|
|
64
|
-
[
|
|
65
|
+
[kTVM](KTVM_SPEC.md) references for their contracts.
|
|
65
66
|
|
|
66
67
|
## Codecs and user interfaces
|
|
67
68
|
|
|
@@ -73,7 +74,7 @@ See the [KIR-P](KIR_V1.md), [kVM](KVM_EXECUTION_MODEL.md), and
|
|
|
73
74
|
- `repl.mjs` manages sessions; `repl-codecs.mjs` handles codec loading/rendering.
|
|
74
75
|
- `browser/repl-browser.mjs` implements the browser UI.
|
|
75
76
|
- `scripts/build-repl-html.mjs` bundles browser shims, VFS libraries, codecs,
|
|
76
|
-
and Wasm resources into one HTML file.
|
|
77
|
+
and Wasm / kTVM-Wasm resources into one HTML file.
|
|
77
78
|
|
|
78
79
|
`core.k` defines the fixed `pattern[]` schema used to decode a stream's leading
|
|
79
80
|
pattern value. This does not automatically import the library into user scope.
|
package/DOCS/DICTIONARY.md
CHANGED
|
@@ -23,12 +23,12 @@ These terms are used throughout the [documentation](README.md).
|
|
|
23
23
|
| **Wire stream** | The binary representation of an envelope followed by a payload encoded under it. |
|
|
24
24
|
| **Codec** | A translator between an external representation and enveloped k values. |
|
|
25
25
|
| **Contract derivation** | Compiler propagation and unification of pattern constraints, with fixed-point iteration for recursive relation groups. |
|
|
26
|
-
| **Specialization** | Adapting a relation or execution artifact to a particular input envelope. The KIR-P and
|
|
26
|
+
| **Specialization** | Adapting a relation or execution artifact to a particular input envelope. The KIR-P, kVM, and kTVM passes use different mechanisms. |
|
|
27
27
|
| **Partial failure** | Ordinary undefinedness during execution, distinct from a schema contradiction or system error. |
|
|
28
28
|
| **Object / library** | Stored compiled definitions: `.ko` has an entry relation; `.klib` has no main entry. |
|
|
29
29
|
| **KIR-P** | Portable relation and pattern export from compiled objects. |
|
|
30
30
|
| **kVM** | Register-based execution representation, with polymorphic templates and specialized artifacts. |
|
|
31
|
-
| **
|
|
31
|
+
| **kTVM** | Packed-wire transducer virtual machine that executes k relations directly over canonical prefix-coded bit-streams (with JS, WebAssembly, and LLVM backends). |
|
|
32
32
|
|
|
33
33
|
A contract's input pattern is a static constraint, not necessarily the exact
|
|
34
34
|
mathematical domain of the relation. A relation can be undefined for values
|
package/DOCS/FILE_FORMATS.md
CHANGED
|
@@ -12,7 +12,7 @@ Run the examples below from the repository root after `npm install`.
|
|
|
12
12
|
| `.ko` | Compiled executable object with a main relation | `k-compile`, `k`, backend tools |
|
|
13
13
|
| `.klib` | Compiled definitions with no main relation | `k-compile`, `:klib`, `--lib`, `:load` |
|
|
14
14
|
| `.kvm` | JSON kVM artifact: polymorphic `KVM-P` template or specialized `KVM` program | `k-compile`, specialization API, backends |
|
|
15
|
-
| `.
|
|
15
|
+
| `.ktvm` / `.ktvmp` | Textual DSL or JSON kTVM module (`format: "k-tvm"`, version 1) | JavaScript API (`ktvm/`) |
|
|
16
16
|
| `.wasm` | WebAssembly module with k runner metadata | `k-wasm-compile`, `k-wasm-run` |
|
|
17
17
|
|
|
18
18
|
A source file executed directly needs a terminal expression. A library can
|
|
@@ -219,15 +219,17 @@ node codecs/unit.mjs --parse | node kvm.mjs /tmp/k-ok.ko |
|
|
|
219
219
|
node codecs/k-print.mjs
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
-
##
|
|
222
|
+
## kTVM and target backends
|
|
223
223
|
|
|
224
|
-
[
|
|
225
|
-
|
|
226
|
-
`
|
|
224
|
+
[kTVM](KTVM_SPEC.md) is the packed-wire transducer VM (`ktvm/`), which lowers
|
|
225
|
+
KIR-P relations into polymorphic `.ktvmp` or concrete `.ktvm` modules
|
|
226
|
+
(`format: "k-tvm"`, version 1) and executes them directly over `k-wire`
|
|
227
|
+
bitstreams via its JavaScript interpreter, WebAssembly backend (`ktvm/wasm/`),
|
|
228
|
+
and native LLVM backend (`ktvm/llvm/`).
|
|
227
229
|
|
|
228
|
-
The backend compile commands accept
|
|
229
|
-
|
|
230
|
-
programs. A library still needs an entry relation.
|
|
230
|
+
The kVM backend compile commands accept source, executable objects (`.ko`),
|
|
231
|
+
and kVM programs (`.kvm`). A `.klib` library still needs an entry relation.
|
|
231
232
|
|
|
232
|
-
See the [
|
|
233
|
+
See the [kTVM specification](KTVM_SPEC.md),
|
|
234
|
+
[WebAssembly](../backends/wasm/README.md), and
|
|
233
235
|
[LLVM](../backends/llvm/README.md) guides for target compilation and execution.
|
package/DOCS/KIR_V1.md
CHANGED
|
@@ -184,6 +184,8 @@ The current kVM lowerer consumes KIR-P relation bodies directly:
|
|
|
184
184
|
k source -> .ko / .klib -> KIR-P -> kVM template
|
|
185
185
|
+ input envelope
|
|
186
186
|
-> specialized kVM -> interpreter / Wasm / LLVM
|
|
187
|
+
-> kTVM-P / kTVM (packed-wire)
|
|
188
|
+
-> interpreter / Wasm / LLVM
|
|
187
189
|
```
|
|
188
190
|
|
|
189
191
|
KIR-P envelope specialization is also available as a separate derivation pass,
|
|
@@ -215,7 +217,9 @@ call-site worklists are local compiler data; they are not part of the
|
|
|
215
217
|
serialized KIR artifact.
|
|
216
218
|
|
|
217
219
|
- [DOCS/FILE_FORMATS.md](./FILE_FORMATS.md) —
|
|
218
|
-
source, object, library,
|
|
220
|
+
source, object, library, and kVM workflows
|
|
219
221
|
- [DOCS/KVM_EXECUTION_MODEL.md](./KVM_EXECUTION_MODEL.md) —
|
|
220
222
|
kVM execution model and bytecode design
|
|
223
|
+
- [DOCS/KTVM_SPEC.md](./KTVM_SPEC.md) —
|
|
224
|
+
kTVM packed-wire transducer VM specification
|
|
221
225
|
- [DOCS/DICTIONARY.md](./DICTIONARY.md) — concept names and terminology
|