On this page

0050. The cli platform passes capabilities to main

Context

Effects need explicit, unforgeable authority without adding grammar or inflating scalar programs. The built-in platform must be movable into M10's plugin manifest.

Decision

Accept fn main() and fn main(cli: Cli) -> result<unit, CliError>; the parameter name is arbitrary. Capabilities are checked Type::Cap values erased to IR unit (File later erases to i64). They can be passed, stored and specialized normally, but never constructed or concretely compared. Generic equality compares units.

platform.rs is a data table of capability fields and methods, with marked L1, L2, L3 and L4 sections. Effects lower through lower_platform.rs and Rvalue::Platform; pure operations remain intrinsics. Feature bits select runtime includes. Stage A installs all five include-guarded headers and driver entries. No platform use means byte-identical existing IR/C.

Output is cli.stdout.print/println/write/flush, likewise stderr. Printable interpolation keeps the direct no-allocation path. Cli also exposes stdin, args, raw_args, env, fs and process, implemented in their later tasks. No parser changes.

Removal lands in three stages: A adds this surface beside global print; B uses a compiler-backed call-graph codemod; C rejects globals with E0800 and deletes the codemod. No public transition period: CP-6.1 has no global I/O.

M6.7 CLI tools belong at bench/cli/harness/<tool>.hn for python3 bench/cli/run.py --id <cp>, or examples/tools/ with --harness-bin-dir. Do not change the benchmark runner to locate them.

Alternatives considered

Consequences

Stage A is the branch point for paths, maps and streams. M5.8 follows M6.2 and uses cli.stdin.read_all(), never a new global read_stdin. Empty pure main remains legal and keeps diagnostic fixtures stable. ADR-0051 defines the synthetic entry point and unit-result rules. Parameter assignability remains an open decision.