Skip to content

tools/sweep_gate_corpus.w does not compile: bare extern calls, str-Copy if, argv borrow #1068

Closed

Description

@eas4ai

At 450733e, the committed sweep-gate tool fails under its canonical invocation:

$ out/bootstrap/bin/with-stage1 run tools/sweep_gate_corpus.w
error: manual extern function call requires unsafe context
 --> tools/sweep_gate_corpus.w:21:17
21 |     for line in with_fs_read_file(diag_path).split("\n"):
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: if would need to copy a `str`, which is not Copy
 --> tools/sweep_gate_corpus.w:32:35
32 | let d_corpus = if argv.len() > 4: argv.get(4) else: ""
  |                                   ^^^^^^^^^^^
error: manual extern function call requires unsafe context
 --> tools/sweep_gate_corpus.w:37:10
37 | for f in with_fs_read_file(list_file).split("\n"):
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(plus further errors below the head cut). Reproduced identically under the tree-built stage2, so it is not a stale seed. Probable repair: wrap the extern calls in unsafe:, thread &str through gate_count, clone the argv.get(4) arm (the owned(...)/++ "" idiom used by drop_audit/move_audit).

Evidence: .audit/modules/tools__sweep_gate_corpus.w.md, .audit/probes/tools_sweep_gate_corpus/noargs.txt

Activity

  1. ehartford commented on Sep 16, 2026

    @ehartford
    Contributor

    Review: reproduced

    Verdict. Reproduced: tools/sweep_gate_corpus.w does not compile. All three reported errors occur on the reported revision and on current main: two manual extern function call requires unsafe context on the bare with_fs_read_file calls, and one if would need to copy a str, which is not Copy on the argv.get(4) ternary. It is a stale internal tool, same family as #1066/#1067.

    Tested.

    Source main @ 5809ac1 (2026-09-14); tools/sweep_gate_corpus.w unchanged since it was committed (7d8d085), pre-dating the reported revision 450733e
    Compilers with v0.15.2.1 built from 5809ac1 (staging worktree); a compiler built from 450733e with the nightly-20260903 seed (3/3 errors)
    Platform macOS Darwin 25.6.0 arm64

    with run tools/sweep_gate_corpus.w, both compilers:

    error: manual extern function call requires unsafe context   --> :21:17  (with_fs_read_file)
    error: if would need to copy a `str`, which is not Copy       --> :32:35  (argv.get(4))
    error: manual extern function call requires unsafe context   --> :37:10  (with_fs_read_file)
    

    Root cause. Two stale idioms:

    1. The tool declares its own extern fn with_fs_read_file(path: &str) -> str (:9) and calls it in ordinary context (:21, :37); a manual extern call now requires unsafe. This is also the D30-deprecated with_fs_* seam that user/tool programs should not declare (per AGENTS.md; it SEGFAULTs in user programs, extern fn with_fs_read_file segfaults in user programs (D30-transitional seam) — std.fs works; CLAUDE.md still recommends the broken idiom #901). The right form is use std.fs and read_file.
    2. let d_corpus = if argv.len() > 4: argv.get(4) else: "" (:32): the two arms have different ownership (a &str view vs an owned literal), and str is not Copy, so the if cannot yield an owned str without a clone.

    No compiler defect; the errors are the checker correctly enforcing the unsafe-extern rule and str non-Copy semantics. Established by the run above.

    Severity. Low: an internal sweep-gate tool that does not run. No user-facing impact.

    Related. #1066 (lib/test harness), #1067 (rt_in_unit_sweep.w) — same "committed tool has rotted" family. std.fs.read_file now returns Result[str, IoError] (lib/std/fs.w:74, per #953/#909), so a migration must handle the Result.

    Recommendation — champion, mechanical. Replace the with_fs_read_file extern + calls with std.fs.read_file (unwrapping the Result), and clone the argv.get(4) arm (the owned(...) / ++ "" idiom used by drop_audit/move_audit), exactly as the report suggests. Also thread &str through gate_count to avoid copying the path. Acceptance criteria: with run tools/sweep_gate_corpus.w <stage1> <list> <diag_tmp> runs; no bare with_fs_* extern remains in the tool.

    Blockers / not tested. I fixed nothing (read-only) and did not exercise the tool's gate logic beyond the compile failure; there are further errors below the head cut, consistent with the same two idioms. 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.

    $ with check tools/sweep_gate_corpus.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