Skip to content

tools/gen_init_templates.w documented invocation broken: bare extern calls outside unsafe #1070

Closed

Description

@eas4ai

At 450733e, the header comment's documented command with run tools/gen_init_templates.w fails:

error: manual extern function call requires unsafe context
 --> tools/gen_init_templates.w:28:11
28 | let doc = with_fs_read_file("docs/with_for_ai.md")
error: manual extern function call requires unsafe context
 --> tools/gen_init_templates.w:52:4
52 | if with_fs_write_file("src/InitTemplates.w", out) != 0:
error: run failed

Same drift signature as #1068/#1069 (predates the unsafe-extern rule). Sibling tools/nightly_release_metadata.w (:9, :60) shows the required shape (unsafe { with_fs_... }). Per the audit, the generation logic itself is byte-verified (a fixed copy regenerates the checked-in file byte-exact), so the fix is two unsafe wraps. Risk if unfixed: the next docs/with_for_ai.md edit cannot regenerate templates, and the cli-selfhost-project-tests lane (byte-exact doc comparison) has no working producer.

Evidence: .audit/modules/tools__gen_init_templates.w.md

Activity

  1. ehartford commented on Sep 16, 2026

    @ehartford
    Contributor

    Review: reproduced

    Verdict. Reproduced: with run tools/gen_init_templates.w (the command in the file's own header comment) fails with two manual extern function call requires unsafe context errors on the bare with_fs_read_file/with_fs_write_file calls. Same drift as #1068/#1069 — the tool predates the rule that a manual extern call needs unsafe.

    Tested.

    Source main @ 5809ac1 (2026-09-14); the tool predates 450733e
    Compilers with v0.15.2.1 built from 5809ac1 (staging worktree); a compiler built from 450733e with the nightly-20260903 seed (2 errors)
    Platform macOS Darwin 25.6.0 arm64

    with run tools/gen_init_templates.w, both compilers:

    error: manual extern function call requires unsafe context  --> :28:11  (with_fs_read_file)
    error: manual extern function call requires unsafe context  --> :52:4   (with_fs_write_file)
    

    Source / fix template. The tool declares extern fn with_fs_read_file/with_fs_write_file (tools/gen_init_templates.w:6-7) and calls them at :28/:52 without unsafe. The sibling tools/nightly_release_metadata.w shows the required shape: if unsafe { with_fs_write_file(path, data) } != 0: (:9). Established by the run above; no compiler defect (the checker correctly requires unsafe for a manual extern call).

    Severity. Low: the tool that regenerates src/InitTemplates.w from docs/with_for_ai.md cannot run, so the next guide edit cannot regenerate the templates and the byte-exact doc-comparison lane (cli-selfhost-project-tests) has no working producer. No user-facing impact.

    Related. #1068/#1069/#1073 — same stale-tool wave. No open PR.

    Recommendation — champion, two unsafe wraps. Wrap the with_fs_read_file/with_fs_write_file calls in unsafe { ... } (or switch to std.fs, noting read_file now returns Result). The report states a fixed copy regenerates the checked-in file byte-exact, so the generation logic is sound. Acceptance criteria: with run tools/gen_init_templates.w runs and reproduces src/InitTemplates.w byte-for-byte.

    Not tested. I did not run a fixed copy to confirm byte-exact regeneration (read-only); the report did. Linux/Windows not exercised.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    Contributor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce; the documented tool (with run tools/gen_init_templates.w) compiles. It was checked rather than run because running it rewrites generated files in the tree.

    $ with check tools/gen_init_templates.w
    ok
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions