Skip to content

linux-aarch64: a resource that wraps *mut c_char is matched by every *mut u8 parameter; the contract view differs by target and contract-view-tests is red there #3375

Closed

Description

@ehartford

Found by the dispatched nightly release, run 43869111995 (2026-11-16), job "Verify and package linux-aarch64", step :test: contract-view-tests fails on test/contract/ok_toolchain_contract_place. That test arrived 2026-11-14 (#3323); selfhost-linux-aarch64 has no :test step, so nothing ran it on that platform before.

Two differences from the expected view, reproduced on the Mac with with analyze test/contract/ok_toolchain_contract_place.w contract --target aarch64-linux-gnu:

  1. resource CHeapStr wraps *mut u8 where every other target prints *mut i8. The view printed the resolved width. §57 already says a contract view spells a C type as the header does. Fixed in the PR that references this issue: the view and the resource diagnostics print the item own spelling, *mut c_char.

  2. invalidation: views invalidated by: no operation (and 5 compiler runtime seams) where every other target prints no operation. Still open. c_char is a name for u8 on linux-aarch64 and i8 elsewhere (D155, D156), and Sema.facade_param_receives (SemaFacade.w) matches a parameter to a resource by resolved type. So on linux-aarch64 every *mut u8 parameter, the runtime with_* seams and any C unsigned char * among them, receives a CHeapStr; on the other targets none does.

The question in 2 is about C interop, so it is Eric to rule: should a resource declared over *mut c_char be received only by parameters the header declares as char * (one answer on every target), or by resolved type (the answer differs on linux-aarch64)? Until then contract-view-tests stays red on linux-aarch64 for this one file.

Activity

  1. ehartford commented on Nov 17, 2026

    @ehartford
    ContributorAuthor

    Brief (2026-11-16): which parameters receive a resource that wraps *mut c_char

    The facts, run on the installed compiler. One facade, two targets (with analyze f.w contract [--target aarch64-linux-gnu]):

    use c_import("char *mk(void);
    void fr(char *s);
    int hash_bytes(unsigned char *p, int n);
    int name_len(char *s);
    ")
    c contract x:
        resource Name wraps *mut c_char
            from mk
            drop fr
        fn hash_bytes
        fn name_len
    
    • darwin (and every target where char is signed): fn hash_bytes is refused: "param 0: *mut u8 p is a caller-owned buffer that no clause pairs".
    • linux-aarch64: accepted. param 0: *mut u8 p: lend … receives Name, presented as the safe method Name.hash_bytes.

    So the same facade is an error on one target and a safe method on another, and on linux-aarch64 safe code hands a Name to a C parameter declared unsigned char *. The cause is one line: Sema.facade_param_receives compares the parameter's and the resource's types after resolve_alias, and c_char resolves to u8 there (D155). The red contract-view-tests line ("and 5 compiler runtime seams") is the same match reaching the runtime's *mut u8 parameters.

    1. What the others do (checked in .reference/).

    • Zig: c_char is a primitive type of its own (Type.zig), signedness from the target; [*]c_char is never [*]u8 on any target.
    • Go: cgo's C.char is its own named type on every target (gcc.go, dwarf.CharType), C.uchar another.
    • Rust: c_char is a type alias, u8 or i8 by target (core/src/ffi/primitives.rs); *mut c_char and *mut u8 are one type on aarch64 Linux and two elsewhere, and code that compiles on one fails on the other. It is the known portability trap.
    • Swift: CChar = Int8 everywhere (CTypes.swift); D155 already declined that.

    2. What the spec says. §16 (D155): "c_char … are builtin names, resolved from the target"; "A pointer to one integer type is not a pointer to another"; "A facade written against c_char is portable without edits." D155's ruling adds why: "(it must be, or facades become per-target)". §16.2b.3: "When exactly one resource wraps a representation, operations taking that representation may be associated with it." §57: a contract view spells a C type as the header does. Nothing says whether "that representation" is the declared type or the resolved one; today's code takes the resolved one, and the portability sentence is then false.

    3. Mission fit. Receiving a resource is an ownership fact (it decides what is lent, what a safe method is made over, what invalidates views). D51's test: what if the inference is wrong? Matching unsigned char * to a char * resource on one target creates a safe call nobody stated; it must not come from a representation coincidence. And a meaning that changes with the target's char sign is a default picking a meaning, not a representation.

    Options.

    • A. A facade matches the declared C type. c_char stays symbolic wherever a facade compares a parameter with a resource's representation (and with CStr): char * receives a resource over *mut c_char; unsigned char *, signed char * and the runtime's *mut u8 never do, on every target. One function (facade_param_receives and its twin in FacadeRender.w), one fixture per target. linux-aarch64 contract-view-tests goes green.
    • B. c_char is a type of its own everywhere, as in Zig. Then A falls out, and so does the same split outside facades: today puts(p) with p: *const u8 is an error on darwin ("expects *const i8") and accepted on linux-aarch64, so a program written on aarch64 Linux stops compiling on a Mac. This is the complete answer to "a pointer to one integer type is not a pointer to another", but it changes the type system (arithmetic and comparison between c_char and u8/i8, every as between them, the corpora's c_char uses) and is a campaign.
    • (Matching by resolved type, as today, is dropped: it makes the portability sentence false and grants a safe call by coincidence.)

    4. Prediction. A now, 85%: it is what D155 already said ("or facades become per-target"), it removes capability rather than adding it, and it is small. B is the honest follow-up question and I would file it on its own rather than hold this for it (your "fix the mechanism, not c_char" in D155 is the reason I give B 15% as the ruling instead of 5%).

    Spec words A would add (derived, for your blessing or edit; nothing is landed), after "A facade written against c_char is portable without edits." in §16:

    A facade compares C types as the header declares them: a resource that wraps *mut c_char receives the parameters C declares char *, and none declared unsigned char *, signed char * or any fixed-width byte pointer, on every target.

    Found beside it (mine to fix, no ruling needed): the darwin diagnostic above prints expects *const i8 and gives no fix-it; D155 says it names c_char and suggests p as *const c_char.

  2. ehartford commented on Nov 17, 2026

    @ehartford
    ContributorAuthor

    Correction to the brief's last paragraph: the darwin diagnostic for a *const u8 passed to a *const c_char parameter does carry D155's fix-it. I had cut the output short. In full:

    error: wrong argument type in call to 'puts'
      = note: argument 1 expects *const i8
      = note: actual type: *const u8
      = help: a pointer to one integer type is not a pointer to another; spell the conversion `p as *const c_char` (D155)
    

    Nothing to fix there beyond the note saying *const i8 where the help says c_char. The brief's question and options are unchanged.

  3. ehartford commented on Nov 17, 2026

    @ehartford
    ContributorAuthor

    Brief for the ruling of 2026-11-17: c_char is a type of its own (B, in full)

    Nothing is implemented. This is the proposed §16 text, what each rule does today on two targets, the wider class, and the counts. One count is incomplete and I say where.

    Every "today" cell was run with the installed compiler (main f64f283): with check on darwin-aarch64 and with --target aarch64-linux-gnu. The probes are 47 small programs; the ones that matter are quoted.

    The principle the rules follow

    c_char holds one byte whose sign the target chooses. So a rule about it is target-independent only if it never asks which sign that is. The proposed rules allow, without a cast, exactly what means the same thing whether char is signed or unsigned, and ask for as everywhere else. That gives "compiles on one target, compiles on every target" by construction.

    Proposed §16 text (for your blessing or edit)

    Replacing the sentences of the D155 paragraph that concern c_char:

    c_char is a builtin integer type of its own on every target: one byte, with the signedness of the target's char. It is never an alias: it is not i8 and not u8, and a pointer, slice, array or collection of c_char is never one of i8 or u8. A program is accepted or refused the same on every target as far as c_char is concerned.

    A c_char converts to and from every integer type with as. To and from u8 and i8 the conversion keeps the byte and never fails. A pointer to c_char converts to and from a pointer to u8 or i8 with as, in safe code: it reinterprets no memory until the pointer is read.

    Without as, a c_char widens into i16, i32, i64 and isize, with the value C gives it on the target; it does not widen into an unsigned type. An integer literal from 0 to 127 and an ASCII character literal are c_char values where one is expected; any other literal is written … as c_char.

    Two c_char values add, subtract and compare as the target's char does. Arithmetic or comparison between a c_char and a u8 or an i8 is refused: one operand is converted with as.

    C's three character types are three With types: char is c_char, signed char is i8, unsigned char is u8.

    A str is lent to a const char * parameter as before (§16.3c), and a buffer clause over a char * parameter takes the same byte buffers it takes over unsigned char * (§16.2b.8). A raw byte pointer meets a char * parameter as p as *const c_char.

    The last existing sentences ("c"…".ptr is *const c_char on every target", "A facade written against c_char is portable without edits") stay as they are; the second becomes true.

    1. Conversions

    darwin today linux-aarch64 today proposed, every target
    let b: u8 = c ok ok refused: c as u8
    let b: i8 = c ok ok refused: c as i8
    let c: c_char = b (b: u8) ok ok refused: b as c_char
    c as u8 ok ok ok, keeps the byte
    take(p) with p: *const c_char, take(*const u8) refused ok refused: p as *const u8
    take(p as *const u8) ok ok ok, safe
    fc(s) with s: *mut i8, C char * ok refused refused: s as *mut c_char

    The pointer cast is already safe code today (the probe has no unsafe); it stays so. The value conversions between c_char and u8/i8 are implicit today on both targets. I propose as for them because today's implicit u8 ← c_char carries a range check on a signed-char target and none on an unsigned one: the same program would panic on one target for a byte above 0x7f and not on the other. as keeps the byte on both.

    2. Widening and literals

    darwin today linux-aarch64 today proposed
    let w: i32 = c, let w: i64 = c ok ok ok (sign- or zero-extended as C does)
    c == 65, c == 'A' ok ok ok
    let k: c_char = 200 refused (does not fit) ok refused: 200 as c_char
    let k: c_char = -1, c < -1 ok refused (does not fit) refused: -1 as c_char

    Widening into a signed wider type is the one implicit conversion both an i8 and a u8 have, so it is the one c_char keeps. The value differs by target for bytes above 0x7f; that is C's char, and D155 chose it on purpose ("a char that's unsigned to C and signed to With breaks every API where the value matters"). Widening into an unsigned type is refused because only an unsigned char could do it. Literals 0..127 are the values every target's char holds.

    3. Arithmetic and comparison

    darwin today linux-aarch64 today proposed
    a + b, both c_char ok ok ok, result c_char
    a + b, c_char and u8 refused (§4.2.6, no implicit sign change) ok refused: (a as u8) + b
    a < b, c_char and u8 ok ok refused: (a as u8) < b
    a < b, c_char and i8 ok ok refused: (a as i8) < b

    The two mixed comparisons are accepted on both targets today and would be newly refused. I propose refusing them because c_char < u8 orders differently on a signed and an unsigned target for the same two bytes. This is the rule most likely to add casts; see the counts.

    4. Literals

    c"hi".ptr is *const c_char and *p is a c_char on both targets today (let e: c_char = *p ok on both). A single constant is 'A' (or 65) where a c_char is expected, on both targets today and under the proposal; no new literal syntax.

    5. Text and bytes reaching char *

    darwin today linux-aarch64 today proposed
    puts("hi") (a str, c_import) ok ok ok, unchanged
    count("hi") through a contract (lend) ok ok ok, unchanged
    put(bytes), bytes: List[u8], buffer param src len param n over const char * ok ok ok, unchanged
    the same over const unsigned char * ok ok ok
    puts(c"hi".ptr) ok ok ok
    raw: puts(&buf[0] as *const u8), puts(list.as_ptr()) refused ok refused: … as *const c_char
    raw: strcpy(&raw mut buf[0], …), buf: [u8; 8] refused ok refused: … as *mut c_char

    The common cases (a str, a contract's text, a buffer clause) gain no cast. The raw byte-pointer case is what darwin already refuses; linux-aarch64 joins it. The buffer clause keeps taking List[u8] and [u8] over a char *: that reinterpretation is the facade's, inside the compiler.

    6. Generics and layout

    darwin today linux-aarch64 today proposed
    List[c_char] passed as List[u8] refused ok refused
    List[c_char] passed as List[i8] ok refused refused
    size_of[c_char]() 1 1 1
    struct field c: c_char ok ok ok, size 1, align 1

    ABI: a c_char is passed as it is today (one byte, extended per the target's char). FnAbi's pass modes do not change. src/TypeLayout.w and src/FnAbi.w are the ABI-hashed files; if the new type needs a line in either, the ABI hash moves and every stored .wo object is rebuilt once (objects only, nothing is migrated). I will say which before touching them.

    7. C's three character types

    Confirmed by migrating one file under each data model (with migrate --c-target … --c-sysroot …):

    C darwin linux x86_64 Windows x86_64
    char * *mut c_char *mut c_char *mut c_char
    signed char * *mut i8 *mut i8 *mut i8
    unsigned char * *mut u8 *mut u8 *mut u8

    And a typedef unsigned char byte; void fb(byte *p) takes a *mut u8 on both check targets. Three types stay three.

    The rest of the class (for your rulings; nothing is changed)

    Same method, one file of prototypes under each data model:

    C darwin, linux (LP64) Windows (LLP64) identity depends on the target?
    long * *mut i64 *mut i32 yes: it is long long * and int64_t * on LP64, int * on Windows
    long long *, int64_t * *mut i64 *mut i64 no (but one type with long on LP64)
    unsigned long * *mut u64 *mut u32 yes: it is size_t * on LP64, unsigned * on Windows
    size_t * *mut u64 *mut u64 no (but one type with unsigned long on LP64)
    wchar_t * *mut i32 *mut u16 yes: it is int * on LP64, unsigned short * on Windows
    enum color * *mut i32 *mut i32 no; it is int * everywhere
    enum big { HUGE_V = 0x80000000u } * *mut i32 *mut i32 no; but C gives this enum an unsigned type, so i32 looks wrong. Separate finding, not investigated

    So long, unsigned long and wchar_t have today exactly the defect c_char has: a pointer to one is a pointer to a different fixed-width type on different targets, and a program that passes *mut i64 to a long * parameter compiles on Linux and not on Windows. The c_long alias in With source behaves the same way (*mut c_long is accepted as *mut i64 on darwin).

    One caveat on method: with check --target x86_64-w64-windows-gnu on a Mac does not switch the header parse to the Windows data model (it printed long * as *mut i64), so the Windows column above comes from with migrate --c-target with the Windows sysroot, which does.

    What it breaks: the counts

    Where c_char is written (occurrences, pointer forms in brackets):

    tree occurrences files
    src/ 123 (64 pointer) 22
    lib/std/ outside the corpora 87 (all pointer) 4
    rt/ 568 (all pointer) 7
    build/, tools/ 19 (6 pointer) 2
    test/ 3,461 (3,000 pointer), of which test/corpora 3,354 111
    promoted corpora (lib/std/engines) 3,571 (2,755 pointer) 54

    Sites that stop compiling: not yet counted, and I will not guess. The tree compiles today on a signed-char and an unsigned-char target, so no pointer, collection or arithmetic site can be mixing c_char with u8 or i8 already: each of those is refused on one of the two targets (rows marked bold above). What can break is only what both targets accept today: an implicit value conversion (let b: u8 = *p), and a mixed comparison (*p == some_u8). Those do not show in a search for the name, because the c_char is the type of an expression, not a word in the line. rt/ reads C strings byte by byte and is where I expect most of them.

    The exact number, by kind, needs a compiler that has the type. I propose to get it with a throwaway measuring build before any layer is written: the type and the refusals only, on a scratch branch that is never pushed, compiled against src/, lib/, rt/, the corpora and test/ for both targets, and the errors classified. That gives you the real table and tells us whether the mixed-comparison rule is the expensive one. Say so if you would rather I bring the table first and the words second.

    Corpora. The migrator already emits char as c_char on every data model (table in 7; D156). So migrator output does not change, and no corpus is re-promoted for its text. Whether a promoted corpus still compiles is the same open count: migrated C compares and assigns char values freely, and a corpus is never edited by hand, so if a corpus has a site the new rules refuse, the choice is between a migrator change with a re-promotion under this ruling, or a rule that accepts it. The measuring build answers that.

    The seed. No seed cut is needed first. src/ is compiled by the pinned seed, where c_char is still an alias; every fix a break site needs is an as cast, which the seed accepts and the new compiler requires, so one source text satisfies both. lib/std and rt/ are compiled by the tree's compiler and move at once. A seed cut afterwards is routine, not a step of this stack.

    Published programs. One mention in all of uat/, examples/ and README.md: uat/fixtures/libcurl_main.w:17, a callback parameter ptr: *mut c_char that is never read. No published program passes a byte pointer to a char * parameter or converts between the two (searched for raw byte pointers, as_ptr() and pointer casts in uat/ and examples/: none). I expect no character to change, and the measuring build will confirm it by compiling them; if one does, I stop and bring it.

    Ceremony

    tools/ceremony_census.w --diff will be run on the measuring build's fixes. My expectation, to be checked not assumed: the pointer rules add nothing on darwin (already refused there); the value rules add as at each implicit conversion and mixed comparison. If the census rises, the rule that caused it comes back to you rather than an allowance.

    Decision-log entry (draft; number assigned when it lands)

    c_char is a type of its own on every target (amends D155). D155 made c_char "the target's": an alias of u8 on AArch64 Linux and wasm, of i8 elsewhere. An alias makes type identity follow the target: puts(p) with p: *const u8 was an error on darwin and accepted on linux-aarch64, and a facade resource over *mut c_char received every unsigned char * parameter there and none elsewhere (#3375: one facade, an error on one target and a safe method on the other). Ruled (Eric, 2026-11-17): c_char is a builtin integer type distinct from u8 and i8 everywhere, one byte, signedness the target's, never an alias; the facade fix falls out with no special case. D155's reasons stand (C's value of a char, c"…" is *const c_char); only "alias" is withdrawn. D156 is unaffected: the migrator already keeps char symbolic. Reopens if a target appears whose char is not one byte.

    What I need from you

    1. The §16 words: bless, or edit.
    2. The mixed-comparison rule (section 3) and the value-conversion rule (section 1) are the two that add casts. If you want either kept implicit, say which; the principle then needs a stated exception.
    3. Go or no-go on the throwaway measuring build as the way to finish the counts.
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