You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
c-migrate: designated inits over payload-enum carriers (tag + anonymous union) are untranslatable #749
The #746 fix: record initializers that cannot recover field names now fail
loudly instead of emitting positional (invalid-With) literals. The first such
construct in the prelude-bearing fixture is:
migrate: untranslatable function 'str_to_cstring__83': unsupported assignment rhs in goto CFG (kind=100) at .../generic_intrinsics.w:439:10
The construct
The emitted compiler C models With payload enums as tag + anonymous union:
with_cimport_struct_field_count / the record-field queries do not
enumerate through the anonymous union member (the typedef-of-anon path is
also a stubbed TODO returning -1 at ClangBridge.w's with_cimport_typedef_anon_record_field_count).
Even with names, the migrator's designated-init lowering pairs children
with fields BY INDEX (lower_init_list_ir), which cannot express a
partial, designator-selected init — .payload1 selects a union arm, not
the field at index 1.
Correct translation
These carriers are the emit-C rendering of With enums; the faithful migration
of {.tag = K, .payloadN = expr} is the corresponding With enum-variant
construction (variant K with payload expr), not a struct literal. The
migrator needs a payload-enum recognition pass (tag + lone anonymous union is
exactly the emit-C carrier shape) or, failing that, honest per-designator
lowering (store to .tag, store through the union arm).
Priority
On the roundtrip's critical path: the emitted compiler C is full of Result/
Option carriers, so migrate-compiler-c stops here immediately after #744's
pin lets it run. Repro is fast (~2 min): migrate the 5 MB emit_c_generic_intrinsics_case fixture C.
Deeper root cause, one layer below the init-list: the DECL translation is already wrong.
The migrated carrier type is type Result_CString__CStringError_ { @[align(8)] tag: c_int = 0 } — one field, wrong size, and every downstream .payload0/.payload1 access references a field that does not exist.
Why: collect_field (src/compiler/ClangBridge.w:993) visits record children and keeps only CXCursor_FieldDecl. A C11 anonymous member (union { ... }; with no declarator) has no FieldDecl cursor — libclang surfaces only the bare UnionDecl child — so with_cimport_struct_field_count returns 1 for the carrier and the struct renderer never sees the union. The existing anon-record machinery (ci_field_cursor_anon_record_decl, ci_translate_anon_record_cursor, synth naming) only handles NAMED fields of anonymous types (union {...} u;), which do get a FieldDecl.
Fix layering, bottom up:
Bridge: surface anonymous members in field enumeration — an anonymous record child that no FieldDecl consumes is a member; expose it as an unnamed field of the anon record type (clang_Cursor_isAnonymous is already bound; the field cache needs a synthetic entry carrying the anon decl cursor).
Decl translation: with the member visible, the existing synth-type path renders Parent_anon_N = union {...} + a named field — With unions exist (type X = union {...} is already emitted for top-level unions at CImport.w:2204).
Init lowering: designated inits then need designator-aware lowering (.tag, .payloadN through the member) — index-pairing cannot express union-arm selection; or, better, recognize the tag+lone-anon-union shape as the emit-C enum carrier and lower to variant construction.
Also worth noting for scoping: with_cimport_typedef_anon_record_field_count (ClangBridge.w:2573) is a stubbed return -1 // TODO — the same campaign should implement or remove it per no-silent-fallbacks.
Blast-radius census from the first-ever complete migration scan of the compiler C (roundtrip ran end-to-end under a keep-awake hold, 639 s total, uncapped per the D28 pin — no memory death, no environment death):
1,111 untranslatable functions, all reporting unsupported assignment rhs in goto CFG (kind=100) — the payload-enum carrier shape. The inventory spans the whole compiler: the std.regex family, InternPool intern paths, large swaths of AstPool, and onward (full list in out/command/emit-c-roundtrip/migrate-compiler-c.stderr). Result/Option carriers are everywhere the compiler returns fallible values, so this issue IS the roundtrip gate — nothing else is queued behind mystery anymore: the memory chain (#744 pin), the loud-failure conversion, and the field-name recovery (#746) all held; migration now runs its full course deterministically and stops exactly here.
Also confirms the fix must be the enum-carrier recognition path rather than per-designator stores: at 1,111 sites the faithful-translation shape (tag + lone anonymous union → With enum variant construction) is the only one that scales.
Major progress in 2545b05 — the initializer side is done:
Bridge: collect_field enumerates C11 anonymous members (FieldInfo now carries the field cursor; nameless members answer offsets via clang_Cursor_getOffsetOfField); ci_field_cursor_anon_record_decl detects members by cursor identity instead of the version-dependent "(unnamed ...)" spelling — that spelling mismatch is what silently demoted every carrier decl to opaque.
Inits: designator-driven lowering (designators recovered from source text — libclang's C visitor doesn't surface them as cursors); arm-correct nested union literals; C's {0} lowers to a zero marker; designated-init assignments print as memset + field stores (C's own semantics), removing all dependence on With field defaults.
The 5 MB prelude-bearing fixture C now migrates with zero untranslatable functions (this issue's class was 1,111 functions across the compiler C). Migrator basic/core lanes green.
Remaining for the roundtrip:
Access hop: payload reads still render .payload0 without the .anon_0 member hop (masked in the fixture check by item 2 aborting early). The member-ref lowering needs the same anon-member resolution: when the referenced field's parent is an anonymous member, insert the synthesized member name.
extern fn 'write' shadows prelude function 'write' on the migrated output — standalone-check artifact or real migrated-compiler-build blocker, to be determined at the roundtrip's build-migrated step.
Access side done in 6bed71c: with_ci_member_field_name returns the full dotted path through anonymous members (semantic-parent chain walk, ordinals by cursor equality), so x.payload0 renders x.anon_0.payload0 — 27 fixture access sites carry the hop, none remain bare. Prelude-collision renames also landed: main-file C decls named write/print/etc. rename with @[link_name] preserving C linkage (the emitted compiler C declares POSIX write through std.libc's link-named externs, which round-tripped into a prelude shadow).
Fixture state: migrates fully; with check of the output is down from the 1,111-function class to ONE new error family (~11): the migrated program's own runtime types (CString, Regex, Captures, ...) collide with the embedded std's types under a prelude build — duplicate implementation of trait, Copy-with-Drop conflicts. --no-prelude is not the answer (the output depends on prelude surface: ~993 errors).
Next design question for the roundtrip's build-migrated step: how a migrated self-hosting program relates to the std it embeds — dedup/alias identical type definitions against the prelude, rename-namespace the migrated copies, or a dedicated migrate-build mode. That wants the decision procedure (spec §type-identity, reference projects, mission) rather than an ad-hoc pick. Migrator basic/core lanes green on everything above.
The 'type identity design question' was a false fork — the spec already rules it (§18.1 name precedence; the #627 shadowable-aliases ruling). The implementation is non-conforming: visible user declarations lose to prelude/std names (probes in #750). Filed as #750 with the fix scope; it is the roundtrip's next gate after this issue's migrator work. When #750 lands, the prelude-surface renames from 6bed71c revert (link_name emission stays).
Triage 2026-08-31: CLOSE (overcome by events). Landed in 2545b05 + 6bed71c — tag + anonymous-union designated inits now migrate to named anon-member inits (Res { tag: 0, anon_0: Res_anon_0 { payload0: 42 } }) and the output checks clean.
Activity
ehartford commentedon Jul 31, 2026
Deeper root cause, one layer below the init-list: the DECL translation is already wrong.
The migrated carrier type is
type Result_CString__CStringError_ { @[align(8)] tag: c_int = 0 }— one field, wrong size, and every downstream.payload0/.payload1access references a field that does not exist.Why:
collect_field(src/compiler/ClangBridge.w:993) visits record children and keeps onlyCXCursor_FieldDecl. A C11 anonymous member (union { ... };with no declarator) has no FieldDecl cursor — libclang surfaces only the bareUnionDeclchild — sowith_cimport_struct_field_countreturns 1 for the carrier and the struct renderer never sees the union. The existing anon-record machinery (ci_field_cursor_anon_record_decl,ci_translate_anon_record_cursor, synth naming) only handles NAMED fields of anonymous types (union {...} u;), which do get a FieldDecl.Fix layering, bottom up:
clang_Cursor_isAnonymousis already bound; the field cache needs a synthetic entry carrying the anon decl cursor).Parent_anon_N = union {...}+ a named field — With unions exist (type X = union {...}is already emitted for top-level unions at CImport.w:2204)..tag,.payloadNthrough the member) — index-pairing cannot express union-arm selection; or, better, recognize the tag+lone-anon-union shape as the emit-C enum carrier and lower to variant construction.Also worth noting for scoping:
with_cimport_typedef_anon_record_field_count(ClangBridge.w:2573) is a stubbedreturn -1 // TODO— the same campaign should implement or remove it per no-silent-fallbacks.ehartford commentedon Jul 31, 2026
Blast-radius census from the first-ever complete migration scan of the compiler C (roundtrip ran end-to-end under a keep-awake hold, 639 s total, uncapped per the D28 pin — no memory death, no environment death):
1,111 untranslatable functions, all reporting
unsupported assignment rhs in goto CFG (kind=100)— the payload-enum carrier shape. The inventory spans the whole compiler: the std.regex family, InternPool intern paths, large swaths of AstPool, and onward (full list inout/command/emit-c-roundtrip/migrate-compiler-c.stderr). Result/Option carriers are everywhere the compiler returns fallible values, so this issue IS the roundtrip gate — nothing else is queued behind mystery anymore: the memory chain (#744 pin), the loud-failure conversion, and the field-name recovery (#746) all held; migration now runs its full course deterministically and stops exactly here.Also confirms the fix must be the enum-carrier recognition path rather than per-designator stores: at 1,111 sites the faithful-translation shape (tag + lone anonymous union → With enum variant construction) is the only one that scales.
ehartford commentedon Aug 1, 2026
Major progress in 2545b05 — the initializer side is done:
collect_fieldenumerates C11 anonymous members (FieldInfo now carries the field cursor; nameless members answer offsets viaclang_Cursor_getOffsetOfField);ci_field_cursor_anon_record_decldetects members by cursor identity instead of the version-dependent "(unnamed ...)" spelling — that spelling mismatch is what silently demoted every carrier decl toopaque.type X_anon_0 = union { payload0: ..., payload1: ... }+anon_0member), matching sizes/offsets.{0}lowers to a zero marker; designated-init assignments print as memset + field stores (C's own semantics), removing all dependence on With field defaults.The 5 MB prelude-bearing fixture C now migrates with zero untranslatable functions (this issue's class was 1,111 functions across the compiler C). Migrator basic/core lanes green.
Remaining for the roundtrip:
.payload0without the.anon_0member hop (masked in the fixture check by item 2 aborting early). The member-ref lowering needs the same anon-member resolution: when the referenced field's parent is an anonymous member, insert the synthesized member name.extern fn 'write' shadows prelude function 'write'on the migrated output — standalone-check artifact or real migrated-compiler-build blocker, to be determined at the roundtrip's build-migrated step.ehartford commentedon Aug 1, 2026
Access side done in 6bed71c:
with_ci_member_field_namereturns the full dotted path through anonymous members (semantic-parent chain walk, ordinals by cursor equality), sox.payload0rendersx.anon_0.payload0— 27 fixture access sites carry the hop, none remain bare. Prelude-collision renames also landed: main-file C decls namedwrite/print/etc. rename with@[link_name]preserving C linkage (the emitted compiler C declares POSIXwritethrough std.libc's link-named externs, which round-tripped into a prelude shadow).Fixture state: migrates fully;
with checkof the output is down from the 1,111-function class to ONE new error family (~11): the migrated program's own runtime types (CString,Regex,Captures, ...) collide with the embedded std's types under a prelude build —duplicate implementation of trait,Copy-with-Dropconflicts.--no-preludeis not the answer (the output depends on prelude surface: ~993 errors).Next design question for the roundtrip's build-migrated step: how a migrated self-hosting program relates to the std it embeds — dedup/alias identical type definitions against the prelude, rename-namespace the migrated copies, or a dedicated migrate-build mode. That wants the decision procedure (spec §type-identity, reference projects, mission) rather than an ad-hoc pick. Migrator basic/core lanes green on everything above.
ehartford commentedon Aug 1, 2026
The 'type identity design question' was a false fork — the spec already rules it (§18.1 name precedence; the #627 shadowable-aliases ruling). The implementation is non-conforming: visible user declarations lose to prelude/std names (probes in #750). Filed as #750 with the fix scope; it is the roundtrip's next gate after this issue's migrator work. When #750 lands, the prelude-surface renames from 6bed71c revert (link_name emission stays).
c-migrate: resolve record fields through self-referential typedefs; r…
docs: handoff reflects D28 execution and the #749 queue head
docs: handoff records the decl-level root of #749
docs: record the 1,111-function #749 census; roundtrip chain now dete…
c-migrate: translate payload-enum carriers — anonymous members, desig…
docs: handoff records #749 initializer-side completion and the access…
c-migrate: access hop through anonymous members; prelude-collision re…
docs: handoff records #749 access-side completion and the type-identi…
docs: reframe the #749 tail as conformance bug #750, not a design fork
c-migrate: index record/typedef name lookups; widen session string co…
migrate: calls to prelude-collision libc functions keep the original …
ehartford commentedon Aug 31, 2026
Triage 2026-08-31: CLOSE (overcome by events). Landed in 2545b05 + 6bed71c — tag + anonymous-union designated inits now migrate to named anon-member inits (
Res { tag: 0, anon_0: Res_anon_0 { payload0: 42 } }) and the output checks clean.STC corpus (std.stc) and its test lanes: stdlib_sourcing_plan Phase 3…