Skip to content

Windows x64 codegen: a c_import auto-method over an opaque struct asks for its layout (#1430 BUG) — blocks the libcurl UAT run #1495

Closed

Description

@ehartford

Found while fixing #1417: with #1417's c_import fixes, the libcurl release UAT passes with check on native Windows 10 x64 and then fails with run:

BUG: layout requested for a type holding 'Curl_URL' by value before 'Curl_URL' has a body (#1430)
error: code generation failed

It does not need curl or windows.h. Stage2 of main 5848ae9, native windows-x86_64 (with build):

use c_import("typedef struct Thing Thing;\nThing *thing_new(void);\nint thing_get(const Thing *t, int what);\nvoid thing_set(Thing *t, int what);\n")
fn main:
    print("x")
BUG: layout requested for a type holding 'Thing$149' by value before 'Thing$149' has a body (#1430)
error: code generation failed
error: build failed

The import makes Thing opaque (incomplete in C) and auto-generates methods over it (§16.2a): impl Thing: unsafe fn get(what: i32) -> c_int (a read receiver, from const Thing *) and unsafe mut fn set(...). On darwin arm64 the same program builds, and the libcurl UAT (whose Curl_URL gets the same four methods) runs. The failure is #1430's guard in Codegen.layout_is_complete, reached from abi_size_of / abi_align_of: on windows-x86_64 something sizes the opaque receiver type by value — presumably the x64 classification of the read receiver (fn over Thing) in compute_fn_abi, which asks for the size to choose between by-value and by-reference; not yet located at the line (no lldb on this box).

Expected: an opaque receiver is passed by address on every target (it has no size; C only ever has a pointer to it), the program prints x, and the libcurl UAT runs on Windows.

Activity

  1. ehartford commented on Oct 2, 2026

    @ehartford
    ContributorAuthor

    Fixed on main 1688728 (by #1937: a place passes its address whatever its type). Verified on native windows-x86_64 (win10, fresh clone W:\verify-1, pinned seed nightly-20260930-local-2-bd6e00d1dee6, src\main build :dev, out\bootstrap\bin\with-stage1.exe --version = with v0.15.3.0-g168872857), the repro from the body:

    > out\bootstrap\bin\with-stage1.exe run W:\thing.w
    x
    rc=0
    > out\bootstrap\bin\with-stage1.exe build W:\thing.w -o W:\thing.exe && W:\thing.exe
    x
    rc=0
    

    No BUG: layout requested for a type holding 'Thing$…' by value — the opaque receiver is passed by address.

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