You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ADR-015 S4 first slice: clocks. Native WASI clocks via the preview1
import surface (the adapter S3 wraps it with bridges to preview2
`wasi:clocks` on a real host).
- `lib/wasi_runtime.ml`: `create_clock_time_get_import` + `gen_clock_now_ms`
(emits `clock_time_get(clock_id, 0_precision, scratch)` → drops
errno → loads i64 ns from scratch → `/ 1_000_000` → wrap to i32 ms;
~24-day wrap, documented).
- `lib/codegen.ml`: builtin special-case `clock_now_ms(clock_id) -> Int`
(mirrors `print`'s `ExprVar`-name pattern). **Conditional import on
use**: a pre-scan via `Effect_sites.fold_calls` adds the
`wasi_snapshot_preview1.clock_time_get` import iff the unit calls
`clock_now_ms` — units that don't use it are byte-identical to
pre-S4a (zero LinkError surface for existing harnesses; the
"import what you use" principle). Idx 1 after fd_write at 0, deterministic
(cross-module imports from gen_imports follow); type indices are
computed via `List.length`, so the +1 in ctx.types is a uniform
shift (safe — verified by the gate). Hardcoded `clock_func_idx = 1`
matches the assembly.
- `lib/typecheck.ml` register_builtins + `lib/resolve.ml` builtin list:
`clock_now_ms : Int -> Int / { Time }` (`Time` is reserved; tracking
only, like the rest of the v1 effect system).
Tests:
- `tests/codegen/clock_now_ms.{affine,mjs}` — host stubs
`clock_time_get` writing 5_000_000_000 ns, asserts the guest
returns 5000 (the ns/1_000_000 arithmetic + import wiring +
CLOCK_MONOTONIC threading). V8 passes wasm i64 to JS as **BigInt**
(3 params, not 4-split-i32) — load-bearing.
- The S3 componentize smoke + S3 path on the clock fixture: the
component is structurally valid, the `affinescript.ownership`
section survives, wasmtime loads it. Real-host main invoke
through wasi:clocks needs WIT export lifting / `wasi:cli/run`
command shape — that's S6, NOT S4 (the S4 contract is correct
preview1 emission; the adapter does the preview2 bridge).
Gate: `dune test --force` 295/295; full
`tools/run_codegen_wasm_tests.sh` PASSED incl. the new test (the
critical proof that the import-space shift didn't break anything —
print, #199 closure ABI, #234 effect-table, #225 CPS, all green).
S3 smoke still PASSED. Zero regression.
Refs #180 — S4a done; next S4b (env+argv, same preview1-import
pattern), S5 filesystem (unblocks INT-06), S6 flip default. Not
Closes.
0 commit comments