feat(cli): route print through the bundled stdlib (Compat-B)
- Add Program.print_override and lazy stdlib injection: only programs that call 打印/print load std:io and route to io.写值 (ADR-0030). - Record resource.open/read/write/close as trace effect events so the stdlib print path is auditable; HostOp::Print no longer runs on that path. - Permit only stdio/stdout (existing console) in strict; file/network resource opens remain permission.denied. - Exclude std: modules from the human-readable checked-module count; update the Python analysis consumer to accept std: instance ids. - Add print-routing and strict-console tests, ADR-0030 and evidence. Gate: fmt, clippy -D warnings, 418 tests passed.
This commit is contained in:
1 parent
e119727c5d
commit
e26971f489
21 files changed
+560
-36
No files matched your search
@@ -103,9 +103,12 @@ resource.close(handle: Resource)
|
||||
caller constructs a `Capabilities` set with a matching `fs_read` pattern.
|
||||
Network/process resources do not exist in this slice.
|
||||
* `project`: stdio stdout and explicitly granted project-file reads.
|
||||
* `strict`: **every** `resource.open` is refused with `permission.denied`.
|
||||
Strict L1 is unchanged and no new provider is silently enabled. A future ADR
|
||||
must add real OS-level evidence before strict accepts streams.
|
||||
* `strict`: only the existing **stdio/stdout** console channel is permitted
|
||||
(`resource.open("stdio","stdout",["write"])`, console grant); every file,
|
||||
network, process or device resource open is refused with
|
||||
`permission.denied`. This is the existing console capability reached through
|
||||
the resource ABI, not a new OS capability (ADR-0030). Strict L1 is otherwise
|
||||
unchanged.
|
||||
* Manifest capability requests are not grants; only the operator-provided
|
||||
effective set is consulted.
|
||||
|
||||
@@ -143,8 +146,8 @@ file bytes or handles.
|
||||
process, clock, random or device operations.
|
||||
* No generic third-party provider registration; CM-A09 remains open.
|
||||
* No zero-copy, async, deadlines per stream, seek or shared memory.
|
||||
* No strict-mode resource support and no claim that host-in-process I/O is a
|
||||
sandbox.
|
||||
* No strict-mode file/network/process resource support and no claim that
|
||||
host-in-process I/O is a sandbox; strict stdio is the existing console.
|
||||
|
||||
## Compatibility
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ resource.open("file", "<project-relative path>", ["write"]) -> Resource
|
||||
* `project` mode only, with an `fs_write` glob grant matching the normalised
|
||||
relative path.
|
||||
* `pure` still refuses file resources by mode check; `strict` still refuses
|
||||
every `resource.open` (CM-A11 fail-closed).
|
||||
file resources (only the existing stdio console channel is permitted,
|
||||
ADR-0030).
|
||||
* Absolute paths, `..`, symlink escapes and non-regular targets are rejected by
|
||||
`ProjectFs` exactly like the existing `fs.write`.
|
||||
* A writer owns an in-memory byte buffer. `resource.write` appends bytes and
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
# ADR-0030: Compat-B `打印` routing through the bundled stdlib
|
||||
|
||||
Status: **Accepted**
|
||||
Date: 2026-11-20
|
||||
Relates to: `docs/MARQDO_COMPUTE_CORE_STDLIB_MIGRATION_RFC_0002.md`
|
||||
(CM-A07, CM-A11, P3), ADR-0027, ADR-0028, ADR-0029
|
||||
Specs: `spec/evaluation.md`, `spec/security.md`
|
||||
Evidence: `docs/evidence/2026-11-20-print-compat-b.md`
|
||||
|
||||
## Context
|
||||
|
||||
ADR-0027 implemented Compat-A: the stdlib print chain exists behind explicit
|
||||
imports, but builtin `打印` still runs `Value::display()` in Rust. ADR-0029
|
||||
removed the formatting gap: the stdlib can reproduce `打印` for all 15 value
|
||||
types. ADR-0028 made a verified stdlib bundle available offline. The remaining
|
||||
Compat-B requirement is to route the **same name** to one implementation and
|
||||
prove the old callers behave, before Compat-C removes the legacy formatting
|
||||
path.
|
||||
|
||||
## Decision
|
||||
|
||||
### 1. One program-level override
|
||||
|
||||
`Program` gains an optional `print_override: FunctionId`. The loader sets it to
|
||||
the bundled `io.写值` function when:
|
||||
|
||||
* the verified bundle is available, and
|
||||
* at least one loaded module calls `打印` or `print` as a bare builtin call.
|
||||
|
||||
The stdlib `io` module is injected only in that case. A program without print
|
||||
calls keeps the same module graph and Analysis output as before. If no bundle
|
||||
is available, the loader leaves the override unset and the legacy builtin is the
|
||||
fallback; an official release always ships the bundle.
|
||||
|
||||
### 2. Resolution order
|
||||
|
||||
At a call site, name resolution is:
|
||||
|
||||
1. a local variable holding a callable (`f = ...; f(x)`) — local shadow wins;
|
||||
2. `打印`/`print` with `Program.print_override` set — call the stdlib function;
|
||||
3. the existing builtin table;
|
||||
4. a same-module/imported function declaration.
|
||||
|
||||
This is a controlled compatibility route for exactly two names. It is not a
|
||||
general name-shadowing mechanism and does not add a new namespace.
|
||||
|
||||
### 3. Runtime behavior
|
||||
|
||||
The stdlib function is a normal Marqdo function: its source spans, fuel,
|
||||
frames and trace are the stdlib file's. It formats through
|
||||
`stdlib/format.mq.md`, encodes UTF-8 through `stdlib/text.mq.md`, and writes
|
||||
through `resource.open("stdio","stdout",["write"])` plus `resource.write`.
|
||||
`打印` still returns `Unit` and appends exactly one newline.
|
||||
|
||||
The console/output-budget checks remain in the host: the stdlib path uses the
|
||||
same console grant and output budget as the legacy path. Resource operations
|
||||
are recorded as Trace `effect` events (`resource.open/read/write/close`); the
|
||||
legacy `HostOp::Print` effect does not appear in Compat-B runs.
|
||||
|
||||
### 4. Strict mode and CM-A11
|
||||
|
||||
Strict L1 already permits the console channel. Compat-B needs stdout writes in
|
||||
strict so the same print implementation works there. Therefore strict mode
|
||||
permits **only** `stdio/stdout` write with the console grant; project-file,
|
||||
network, process and device resource opens remain refused, and no new provider
|
||||
is enabled. This is the existing console capability reached through the
|
||||
resource ABI, not a new OS capability. File resources stay fail-closed.
|
||||
|
||||
### 5. Compatibility and fallback
|
||||
|
||||
* Output for all 15 value types is the ADR-0029 formatter and is
|
||||
comparison-tested against the legacy path.
|
||||
* Trace shape changes from one `print` effect to resource effects. Consumers
|
||||
that hard-code `operation == "print"` must accept `resource.*`; this is a
|
||||
documented P3 migration.
|
||||
* `check`/`analysis` include stdlib modules for print-using programs only.
|
||||
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.
|
||||
|
||||
## Non-goals
|
||||
|
||||
* No routing for `长度`, `类型`, `文本`, table or any other builtin.
|
||||
* No bundled stdlib upgrade workflow; the bundle version stays `0.1.0`.
|
||||
* No removal of `HostOp::Print`, `Value::display()` or the legacy builtin.
|
||||
* No new OS isolation claim; strict still refuses file/network/process
|
||||
resources.
|
||||
* No guarantee for a CLI installed without `stdlib/`; that configuration keeps
|
||||
legacy print and is not the official layout.
|
||||
|
||||
## Verification
|
||||
|
||||
`docs/evidence/2026-11-20-print-compat-b.md` records:
|
||||
|
||||
* a print program whose trace contains `resource.write` and no `print` effect;
|
||||
* all semantic goldens and CLI print tests passing byte-identically;
|
||||
* lazy stdlib injection: no print → no stdlib modules; print → stdlib modules
|
||||
and `project.stdlib` identity;
|
||||
* host tests for strict stdio-only permission and file refusal.
|
||||
Reference in new issue
Block a user