refactor(print): remove HostOp::Print and legacy formatting (Compat-C)
- Delete HostOp::Print and StdHost::op_print; the print builtin only routes to bundled io.写值 when Program.print_override is set, otherwise returns a structured kernel.unavailable error (ADR-0031). - Keep the 打印/print builtin name for arity/static validation; Value::display remains only for CLI result rendering, not print execution. - Teach the direct-runtime semantic harness to mirror loader stdlib injection and import edges; replace runtime tests that used print with non-print effects. - Update spec/security/status/changelog/README, add ADR-0031 and evidence. Gate: fmt, clippy -D warnings, 419 tests passed.
This commit is contained in:
1 parent
e26971f489
commit
49910ece43
16 files changed
+304
-56
No files matched your search
+7
-1
@@ -123,6 +123,9 @@ This is still a **local VM lane**, not a self-hosted GitHub Actions security URL
|
||||
(`format.显示` → UTF-8 encode → `Memory` → `resource.write(stdout)`) matches
|
||||
builtin `打印` for the covered value set; builtin remains default and no
|
||||
alias is routed.
|
||||
- Compat-C print completion (ADR-0031): `HostOp::Print`/`op_print` removed;
|
||||
the print builtin only routes to bundled `io.写值` or fails with
|
||||
`kernel.unavailable`; trace has resource effects only.
|
||||
- Compat-B print routing (ADR-0030): `Program.print_override` routes
|
||||
`打印/print` to the bundled `io.写值` when the program uses it; stdlib
|
||||
modules are injected lazily; resource operations are trace `effect` events
|
||||
@@ -182,7 +185,7 @@ behavior. This table records only what is in this tree now.
|
||||
| P0 freeze (ADRs, spec deltas, baseline) | **P1 + partial P2 slice done** | ADR-0022 freezes CM-A01/CM-A02/CM-A03; ADR-0023 freezes CM-A04 (minimal List/Map/Text/Table observation and construction); ADR-0024 freezes CM-A05 (recoverable `Result` map convention); `spec/expression.ebnf`, `spec/evaluation.md`, `spec/value-wire.md`, `spec/analysis-v2.md`, `spec/security.md` updated; existing AST/value goldens unchanged |
|
||||
| P1 Memory + place assignment | **Implemented locally** | `Value::Memory`, run-scoped `MemoryStore` (64 KiB pages, 64 MiB total / 16 MiB region), `memory.new/size/grow`, `m[i]` read, `m[i] = byte`; semantic fixtures 45–47, runtime negatives 13–18, `examples/memory-buffer.mq.md`; evidence [`evidence/2026-11-20-memory-p1.md`](evidence/2026-11-20-memory-p1.md) |
|
||||
| P2 Marqdo-written allocator/data structures + minimal structure observation | **PARTIAL, gate NOT passed** | `.mq.md`-only evidence: bump allocator with u32 codec, linked list, failed-allocation atomicity (48–50); CM-A04 structure primitives and a table filter (51–54, ADR-0023); a first-fit free-list allocator with block reuse, splitting, address-adjacent coalescing and `Result` maps (55, ADR-0024), a `Memory`-backed binary tree with recursive insert/in-order traversal (56), a `.mq.md` CSV row splitter (57), an open-addressing hash table with linear probing, update and `hash.full` (58), a `.mq.md` UTF-8 encoder over `Memory` (59), a validating UTF-8 decoder rejecting truncated, bad-continuation and surrogate/overlong input (60), a `Memory`-backed graph adjacency list (61), a recursive JSON parser for nested arrays/objects, strings with escapes, integers, booleans, null and error Results (62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (63), big-endian 16/32/64-bit plus LEB128 integer codecs (64), a `.mq.md` table sort rebuilding a new table from `table.row/columns/cell` (65), a table join (67), a quoted/escaped CSV row parser (68), table group (69), and an Int matrix multiply (70); the first-fit allocator also detects double free (`alloc.double_free`). Evidence: [`memory-p2-closure`](evidence/2026-11-20-memory-p2-closure.md), [`structure-api-p2`](evidence/2026-11-20-structure-api-p2.md), [`result-and-free-list-p2`](evidence/2026-11-20-result-and-free-list-p2.md). P2 remaining: publication as a separate external stdlib repository. The bundled `stdlib/` tree, `std:` imports, digest verification, Analysis identity and frozen-CLI closure test are implemented (ADR-0028). C01–C06/C11/C12 each have `.mq.md` evidence, including JSON floats and a JSON formatter. |
|
||||
| P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict permits only stdio/stdout and refuses file/network resources. Fixture 66 + CLI/host tests. CM-A07 **Compat-B** is implemented: when a program calls `打印/print`, the loader injects the bundled `stdlib/io.mq.md` and the runtime routes to `io.写值`, which formats all 15 value types, UTF-8-encodes via `Memory` and writes via `resource.write(stdout)`; legacy `HostOp::Print` is only a no-bundle fallback. Strict permits only the existing stdio console channel. Still missing: Compat-C, directories, network, generic provider registry. |
|
||||
| P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict permits only stdio/stdout and refuses file/network resources. Fixture 66 + CLI/host tests. CM-A07 **Compat-C** is implemented: when a program calls `打印/print`, the loader injects the bundled `stdlib/io.mq.md` and the runtime routes to `io.写值` (all 15 value types, UTF-8 via `Memory`, `resource.write(stdout)`); `HostOp::Print` and the legacy `Value::display()` print path are removed, and a missing bundle fails with `kernel.unavailable`. Strict permits only the existing stdio console channel. Still missing: directories, network, generic provider registry, Table storage, strict file/network resources. |
|
||||
| P4 Table logical/physical migration | **NOT IMPLEMENTED** | `Value::Table` remains `Vec<Vec<Value>>`; no stdlib table algorithms |
|
||||
| P5 third-party Provider / TCP / HTTP | **NOT IMPLEMENTED** | `fs.write`, `net.request`, `process`, `clock`, `random` remain unavailable broker services (see §4) |
|
||||
| P6 performance / native backends | **NOT IMPLEMENTED** | no bytecode/JIT/GPU/QPU work |
|
||||
@@ -216,6 +219,9 @@ user-written allocator is explicitly **not** claimed.
|
||||
- [`evidence/2026-11-20-print-compat-b.md`](evidence/2026-11-20-print-compat-b.md)
|
||||
— ADR-0030 Compat-B print routing, trace resource effects, lazy stdlib
|
||||
injection and strict stdio console permission.
|
||||
- [`evidence/2026-11-20-print-compat-c.md`](evidence/2026-11-20-print-compat-c.md)
|
||||
— ADR-0031 removal of `HostOp::Print`, no-bundle fail-closed behavior and
|
||||
embedder compatibility note.
|
||||
- [`evidence/RELEASE_CANDIDATE_0.1.0_8af7262.md`](evidence/RELEASE_CANDIDATE_0.1.0_8af7262.md)
|
||||
— G0..G12 matrix and RC decision.
|
||||
- [`security-gate.md`](security-gate.md) — mechanism, attack matrix and strict
|
||||
|
||||
@@ -77,8 +77,8 @@ resource ABI, not a new OS capability. File resources stay fail-closed.
|
||||
The human-readable `checked N module(s)` count excludes stdlib modules so
|
||||
bundle internals do not change the project count.
|
||||
* Compat-C (removing `HostOp::Print` and `Value::display()` formatting from the
|
||||
public builtin) is **not** part of this ADR. The legacy path remains the
|
||||
fallback when no bundle exists.
|
||||
public builtin) is **not** part of this ADR; it is implemented by ADR-0031,
|
||||
which supersedes the "legacy fallback" sentence above.
|
||||
|
||||
## Non-goals
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
# ADR-0031: Compat-C — remove `HostOp::Print` and the legacy formatting path
|
||||
|
||||
Status: **Accepted**
|
||||
Date: 2026-11-20
|
||||
Relates to: `docs/MARQDO_COMPUTE_CORE_STDLIB_MIGRATION_RFC_0002.md`
|
||||
(CM-A07, P3), ADR-0027, ADR-0029, ADR-0030
|
||||
Specs: `spec/evaluation.md`, `spec/security.md`
|
||||
Evidence: `docs/evidence/2026-11-20-print-compat-c.md`
|
||||
|
||||
## Context
|
||||
|
||||
Compat-A produced a stdlib print chain; Compat-B (ADR-0030) routed
|
||||
`打印/print` to the bundled `io.写值` and proved output parity for all 15 value
|
||||
types. The legacy path (`HostOp::Print` → `Value::display()` → output buffer)
|
||||
remained as a no-bundle fallback and a comparison reference. Compat-C removes
|
||||
the **public builtin formatting path** so a print call can no longer silently
|
||||
fall back to a Rust formatter.
|
||||
|
||||
## Decision
|
||||
|
||||
### 1. Remove the host operation
|
||||
|
||||
* `HostOp::Print` and `StdHost::op_print` are deleted. There is no host
|
||||
operation that formats a value.
|
||||
* `打印/print` remains a **builtin name** for static arity validation and
|
||||
compatibility diagnostics. Its implementation no longer writes anything; if
|
||||
the runtime reaches it (no `Program.print_override`), it returns the
|
||||
structured `kernel.unavailable` error:
|
||||
"打印 requires the bundled stdlib print module; install the official CLI
|
||||
bundle."
|
||||
* The official CLI ships the verified bundle, so a print-using program always
|
||||
loads `stdlib/io.mq.md`, sets `print_override`, and executes `io.写值`.
|
||||
A CLI installed without `stdlib/` cannot print; that layout is not official.
|
||||
|
||||
### 2. Formatting ownership
|
||||
|
||||
All print formatting, UTF-8 encoding and byte output now live in `.mq.md`:
|
||||
|
||||
```text
|
||||
打印(value)
|
||||
-> stdlib/io.写值
|
||||
-> stdlib/format.显示
|
||||
-> stdlib/text.utf8编码
|
||||
-> resource.open("stdio","stdout",["write"])
|
||||
-> resource.write
|
||||
-> resource.close
|
||||
```
|
||||
|
||||
`Value::display()` still exists for CLI result rendering (`call --json`,
|
||||
diagnostics), but it is **not** reachable from the print builtin. No `HostOp`
|
||||
accepts a value for display.
|
||||
|
||||
### 3. Trace and budgets
|
||||
|
||||
Print produces only resource effects (`resource.open/write/close`) and stdlib
|
||||
semantic events. There is no `print` effect. Output budget and console grant
|
||||
are enforced at the resource/stdio boundary exactly as before.
|
||||
|
||||
### 4. Compatibility
|
||||
|
||||
* All semantic goldens, CLI print tests and the full-value formatting demo pass
|
||||
unchanged.
|
||||
* The runtime embedding API (`marqdo_runtime::run`) no longer prints unless the
|
||||
caller installs a `Program.print_override`; a direct runtime program that
|
||||
calls `打印` gets the structured no-bundle error. This is a **breaking change
|
||||
for embedders** and is recorded here; the CLI loader maintains the official
|
||||
behavior.
|
||||
* `callable.rs` still advertises the builtin name for diagnostics and arity;
|
||||
this is not a second implementation.
|
||||
* Compat-A/B evidence remains as history; its "legacy fallback" wording is
|
||||
superseded by this ADR.
|
||||
|
||||
### 5. Non-goals
|
||||
|
||||
* Removing the `打印/print` builtin name, alias, or arity validation.
|
||||
* Removing `Value::display()` for CLI result output, diagnostics or format
|
||||
helpers.
|
||||
* Supporting print without the bundle; no implicit formatting fallback.
|
||||
* Changing Resource ABI, strict mode or stdlib version.
|
||||
|
||||
## Consequences
|
||||
|
||||
* It is now impossible for `打印` to execute a hidden Rust formatter; the only
|
||||
print implementation on an official installation is `.mq.md`.
|
||||
* Embedders that build a `Program` directly must load the stdlib print module
|
||||
and set `print_override` (the semantic test harness does this).
|
||||
* Trace consumers see resource effects, not a print effect.
|
||||
* A missing/corrupt bundle fails closed for print instead of silently using a
|
||||
different implementation.
|
||||
|
||||
## Verification
|
||||
|
||||
`docs/evidence/2026-11-20-print-compat-c.md` records: no `HostOp::Print` or
|
||||
`op_print` references; the no-bundle structured error; trace still shows
|
||||
resource effects; all 419 tests and the full-value demo pass.
|
||||
@@ -27,7 +27,8 @@ implementation status lives in `docs/STATUS.md`; frozen behavior is in
|
||||
| CM-A10 bundled stdlib / `std:` imports / digest | [0028](../adr/0028-bundled-stdlib-and-std-imports.md) | Accepted (first slice) |
|
||||
| Full-value stdlib formatting / FunctionRef+PluginHandle observation | [0029](../adr/0029-full-value-formatting-and-handle-observation.md) | Accepted |
|
||||
| CM-A07 Compat-B print routing | [0030](../adr/0030-print-compat-b-routing.md) | Accepted |
|
||||
| CM-A07 Compat-C, Table storage, generic providers, strict file/network resources | — | Not decided; do not implement by implication |
|
||||
| CM-A07 Compat-C remove legacy print formatting | [0031](../adr/0031-print-compat-c-remove-host-formatting.md) | Accepted |
|
||||
| Table storage, generic providers, strict file/network resources | — | Not decided; do not implement by implication |
|
||||
|
||||
## What a future phase must not do
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
# RFC-CM CM-A07 Compat-C evidence: legacy print formatting removed
|
||||
|
||||
Date: 2026-11-20 (Asia/Shanghai)
|
||||
Repository: `marqdo-cli`
|
||||
Baseline: `e26971f` plus this step's changes.
|
||||
Decision record: [ADR-0031](../adr/0031-print-compat-c-remove-host-formatting.md)
|
||||
Related: [Compat-A](2026-11-20-stdlib-print-compat-a.md),
|
||||
[Compat-B](2026-11-20-print-compat-b.md),
|
||||
[full-value formatting](2026-11-20-full-value-formatting.md).
|
||||
Scope: Compat-C removal of the public host formatting path.
|
||||
|
||||
## Environment and gate
|
||||
|
||||
Ubuntu 26.04 development container, Linux x86_64, Rust 1.100.0.
|
||||
|
||||
```text
|
||||
cargo fmt --all -- --check PASS
|
||||
cargo clippy --workspace --all-targets -- -D warnings PASS
|
||||
cargo test --workspace --locked PASS
|
||||
419 passed, 0 failed, 2 ignored (existing plugin-sdk doc-tests)
|
||||
```
|
||||
|
||||
No GitHub CI is available from this checkout; this is local evidence.
|
||||
|
||||
## Removed
|
||||
|
||||
* `HostOp::Print` variant, its stable op name and `StdHost::op_print`.
|
||||
* The print builtin's host dispatch. `打印/print` remains a builtin **name**
|
||||
for arity validation, but it no longer formats or writes:
|
||||
* with `Program.print_override` set (official CLI + bundle), the runtime calls
|
||||
`stdlib/io.写值`;
|
||||
* without an override, it returns `kernel.unavailable`:
|
||||
"打印 requires the bundled stdlib print module; install the official CLI
|
||||
bundle."
|
||||
|
||||
`Value::display()` remains for CLI result rendering/diagnostics but is not
|
||||
reachable from the print builtin.
|
||||
|
||||
## Runtime/embedder behavior
|
||||
|
||||
`crates/marqdo-runtime/tests/interpreter.rs::print_without_the_bundled_stdlib_is_a_structured_error`
|
||||
builds a Program without an override and asserts the structured error.
|
||||
|
||||
The semantic conformance harness builds Programs directly, so it now mirrors
|
||||
the loader's Compat-B injection: it loads `stdlib/io.mq.md` (with
|
||||
`format`/`text`), adds import edges and sets `print_override`. Existing print
|
||||
fixtures 22/23/30/42 pass byte-identically.
|
||||
|
||||
## Trace and output
|
||||
|
||||
`crates/cli/tests/print_routing.rs` still asserts a print program's trace
|
||||
contains `resource.write` and no `print` effect. The CLI loader routes official
|
||||
runs through stdlib; `打印` output remains byte-identical, including the
|
||||
full-value Formula/Code/FunctionRef demo.
|
||||
|
||||
## Compatibility notes
|
||||
|
||||
* Breaking for embedders that call `打印` without installing the stdlib print
|
||||
module; the official CLI loader does this automatically.
|
||||
* `HostOp` loses a variant; any external exhaustive match must be updated.
|
||||
This is pre-1.0 and recorded in ADR-0031.
|
||||
* No bundle means no print; this is fail-closed rather than a silent formatter.
|
||||
* Compat-A/B evidence remains historical; their fallback wording is superseded.
|
||||
|
||||
## Reproduce
|
||||
|
||||
```bash
|
||||
export PATH=/root/.cargo/bin:$PATH
|
||||
export CARGO_HOME=/root/work/marqdo-cli/.cache/cargo
|
||||
export CARGO_TARGET_DIR=/root/work/marqdo-cli/.cache/target
|
||||
cargo test -p marqdo-runtime --test interpreter print_without
|
||||
cargo test -p marqdo-cli --test print_routing
|
||||
cargo test -p marqdo-cli --test conformance_semantics
|
||||
cargo test --workspace --locked
|
||||
```
|
||||
Reference in new issue
Block a user