Skip to content

emit-c call marshalling: &str params need address-of for literal/value args (direct extern path) #785

Closed

Description

@ehartford

Follow-up to the emit-c decl sync. The decl table and with_runtime.h now match rt's &str (pointer) signatures, but the call-arg renderer (CCodegen.w cc gen_call args, ~5720) only takes addresses when call_param_expects_c_pointer fires; for the fixture shape

extern fn with_print_str(s: &str) -> Unit
...
unsafe { with_print_str("ok") }

the emitted C is with_print_str(WITH_STR_LIT("ok")) — a with_str value passed to const with_str* (now a loud cc error; before the decl sync it silently passed the data pointer as a header pointer and printed nothing).

Needed: the direct-extern path must resolve the callee sig (callee_sig_from_operand / fn_param_is_c_pointer) for these calls and wrap value operands as &((with_str){...}) — or better, route the whole C backend through one FnAbi-derived descriptor per D6 instead of per-path param classification. Also audit: mixed decls remaining in with_runtime.h (eprintln still owned — correct today), and the .ptr cast branch at ~5768 for TY_REF-of-str params looks wrong for header-pointer params.

Test: cli-selfhost-edge-tests emit_c_receiver_abi (currently the only red).

Activity

  1. ehartford commented on Aug 15, 2026

    @ehartford
    ContributorAuthor

    Progress: decl table + with_runtime.h synced (committed), and the TY_REF-of-str .ptr wrong-code branch now passes a real header pointer via (with_str[]){arg} (committed). Remaining sites from the receiver_abi cc log, all in emitted prelude shims:

    1. with_str_concat_n((const with_str[]){_1, WITH_STR_LIT("")}, 2) — _1 is a pointer local; array elements need *_1 when the local is pointer-typed.
    2. (*_3) == _2 — eq renders one operand deref'd, the other raw pointer; comparison rendering must deref pointer locals consistently.
    3. with_print_str(WITH_STR_LIT("ok")) — the direct-extern call path never consults the marshaller (callee sig resolution comes back empty for the user-declared extern), so no address-of is applied.

    All three want the same cure: one FnAbi-derived per-param descriptor consulted by every renderer (D6), instead of per-site pointer classification.

  2. ehartford commented on Aug 15, 2026

    @ehartford
    ContributorAuthor

    Correction to the map: the fresh stage1 emit shows neither compound-literal patch fires for the direct-extern literal call — that call is rendered by a different path than the ~5720 args marshaller (unidentified; do not trust my earlier claim that sites 1/2 were cleared — they persist at 6220/6356 in the emitted shims). The committed decl-table/header sync and the .ptr wrong-code fix stand; everything else here needs the D6 descriptor pass with the renderer actually located first (grep for where CK_STR const args render in calls — it is not callee_sig-driven).

  3. ehartford commented on Aug 18, 2026

    @ehartford
    ContributorAuthor

    Status: the pinned red (emit_c_receiver_abi in cli-selfhost-edge-tests) passes as of today's full green battery on 830018d — 2fff2a8's header-pointer marshalling covered the failing shape. Remaining asks from this issue (the per-D6 single FnAbi-derived descriptor for the C backend, the .ptr cast branch audit at ~5768, the residual mixed decls in with_runtime.h) are now tracked as part of the D30 campaign's R2c stage — see docs/d30-implementation-plan.md, which subsumes the emit-c decl-sync work: each runtime family flip deletes its hand-maintained with_runtime.h prototypes as the family moves to sema-resolved in-unit calls. Keeping this open until the .ptr branch is audited or R2c retires the path.

  4. ehartford commented on Aug 31, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-08-31: CLOSE (overcome by events). Fixed by 2fff2a8 + 5a312d9 — the filed fixture now emits the pointer-decay form (with_print_str(((with_str[]){ WITH_STR_LIT("ok") }))) and the emitted C passes cc -fsyntax-only -I runtime (rc=0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions