Skip to content

runtime/with_runtime.h disagrees with the runtime (with_arg_at, with_fs_read_file): emitted C of a std.process program does not compile #1038

Closed

Description

@ehartford

Restated 2026-10-25. c444d6f made the with_* prototypes come from the With declarations, but runtime/with_runtime.h still disagrees with the runtime: with_arg_at(int32_t idx) against rt_core.w's with_arg_at(idx: isize), and with_fs_read_file(with_str path) against with_fs_read_file(path: &str). The emitted C of a five-line program that uses std.process does not compile.


Original report

Seen on the C4 branch (wo-c4 on afab485) once the compiler's C emits again (emit-c-test, emit-c-fixpoint, package-bootstrap-c all red at the cc step), and independent of C4:

out/gen/versioned_main.w:42:26: error: passing 'with_str[1]' to parameter of incompatible type 'with_str'
out/gen/versioned_main.w:44:28: error: passing 'const with_str *' to parameter of incompatible type 'with_str'
out/gen/versioned_main.w:57:27: error: passing 'const with_str *' to parameter of incompatible type 'with_str'
(18 more of the same; -ferror-limit stops at 20)

src/main.w:42-57 declare extern fn with_fs_write_file(path: &str, data: &str), with_fs_mkdir_p(path: &str), with_fs_read_file(path: &str) -> str, with_exec_argv_capture(args: &str, stdout_path: &str, stderr_path: &str, timeout_ms: i32); rt/rt_core.w:3306/3328 define them with &str (the #747 Phase C flip, 7d8d085). The C backend skips prototypes for every with_* name (CCodegen.should_emit_extern_fn_decl) on the assumption that runtime/with_runtime.h declares them — and the header still says

runtime/with_runtime.h:194: with_str with_fs_read_file(with_str path);
runtime/with_runtime.h:196: int32_t with_fs_write_file(with_str path, with_str data);
runtime/with_runtime.h:307: int32_t with_exec_argv_capture(with_str args, with_str stdout_path, with_str stderr_path, int32_t timeout_ms);
runtime/with_runtime.h:308: … with_exec_argv_capture_input(with_str …)

(header last touched d62409c). So the emitted call passes const with_str* where the header promises a by-value with_str. Either the header follows the runtime (these four and any other &str wrapper it still spells by value), or the backend stops trusting the header for with_* names whose With declaration it has (emit the prototype from the extern fn, as it now does for with_libc_*). The D30 rule applies: one ABI source, never two.

emit-c-smoke (hello world, no fs/exec calls) does not exercise these and stays green.

Activity

  1. changed the title [-]emit-C: runtime/with_runtime.h still declares the fs/exec wrappers by value (with_str), the runtime and the compiler's externs take &str since 7d8d085e — the compiler's C does not compile[/-] [+]runtime/with_runtime.h disagrees with the runtime (with_arg_at, with_fs_read_file): emitted C of a std.process program does not compile[/+] on Oct 25, 2026
  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced in today's terms.

    $ cat main.w
    use std.fs
    use std.process
    fn main:
        print(read_file("x.txt").is_ok())
        print(run(&["true"]))
    $ with build main.w --emit-c -o main.c && cc -fsyntax-only -I runtime main.c
    main.c:2591:17: error: conflicting types for 'with_arg_at'
     2591 | extern with_str with_arg_at(int64_t _1);
    runtime/with_runtime.h:206:10: note: previous declaration is here
      206 | with_str with_arg_at(int32_t idx);
    

    post-release: part of the emit-C lane campaign (#955).

  3. added this to the post-v0.16.0 milestone on Oct 28, 2026
  4. ehartford commented on Nov 11, 2026

    @ehartford
    ContributorAuthor

    Fixed on main (ae20d89): runtime/with_runtime.h declares with_str with_arg_at(int64_t idx) against rt_core.w's idx: isize, and a shared &str is the {ptr, len} view by value, the with_str itself (#1810), so with_str with_fs_read_file(with_str path) is the runtime's path: &str. Verified: a program that uses std.process (args()) and std.fs (read_file) emitted with with build --emit-c from a source checkout compiles with cc -fsyntax-only -I runtime with no error.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions