Repository navigation
Merged
Conversation
added 5 commits
October 3, 2026 05:01
… payload union (#2017) The C backend refused every enum variant with more than one payload field ("C backend does not support enum variants with 2 payload fields"), so `:emit-c-test` could not emit the compiler's own C. - The payload union holds such a variant as a struct of its fields in declaration order (`payloadV.fieldI`), the layout with-abi.md §2 and TypeLayout's TY_ENUM rule give the payload area. - Construction builds that struct field by field; place text and the three place-type walks read `Downcast(v), Field(i)` as payload field i of variant v (MirCore's projection typing), so a one-field variant whose payload is a tuple no longer has its Field(0) read as the tuple's first element. - Display formats `Name(a, b)`, as the LLVM backend does. test/emit_c/enum_multi_field_payload.w: 2- and 3-field positional, named and generic variants built, matched, passed, borrowed and displayed; main's release compiler refuses its emission, stage1 with this change emits C that prints the same lines as the LLVM backend.
… tuple (#2017) Main's C backend printed `tuple payload 3 0`: after the downcast it took the payload's type, so the payload field projection Field(0) became the tuple's .field0. The previous commit reads Field(i) after a downcast as payload field i.
…ption; a refusal names its function (#2017) With multi-field payloads emitted, the compiler's C stopped at "payload downcast for unit enum variant 1" with no function named. - CCodegen.emit_fn_body prefixes a refusal raised inside a body with the body's C name: the failure was in ZipArchive_entries. - Root cause (lldb on the q.w reduction, `out.push(get(i)?)`): the body-local type pass (emit_body_text) took body_downcast_option_tids' guess over MIR's declared type. `_9 = move _7<as v0>.f0` made it type `_7` Option[Entry] (Option of the destination's type) although MIR declares it Result[Entry, str]; place_text then read `_7<as v1>` as Option's unit None. The guess now skips a local MIR declares as a payload enum other than Option (local_declared_non_option_payload_enum), in the body pass and in the per-local local_payload_downcast_option_tid. test/emit_c/result_try_pushed.w: main's release compiler refuses its emission; this stage1's C prints the LLVM backend's lines.
Next stop in the compiler's C: "in Codegen_mir_emit_owned_map_insert: emit-c does not support generic intrinsic __collection_literal" (`let get_params: Vec[i64] = [ptr_ty, ptr_ty, i64_ty]`). MirLower lowers `[a, b]` into a Vec or HashSet and `[k: v]` into a HashMap as a COLLECTION_LITERAL / MAP_LITERAL call that only the LLVM backend handled. emit_collection_literal_term builds the collection empty and pushes or inserts each element in order, as the LLVM backend's mir_emit_collection_literal_intrinsic_call and this backend's own VEC_PUSH / MAP_NEW / MAP_INSERT do; any other target refuses loudly. test/emit_c/collection_literals.w: Vec of ints, strs and records, a HashSet, a HashMap and an empty Vec; main's release compiler refuses its emission, this stage1's C prints the LLVM backend's lines.
…rs as the emitted C declares them (#2017) With the compiler's C emitted, emit-c-test stopped in the bridge prototype scan: "could not parse public ABI signature for wl_is_packed_struct" (`-> bool` had no C spelling; `packed: bool = false` kept its default in the type). Past that, the -included wl_decls.h declared every `&str` parameter `const with_str *` (#785) while the emitted definitions take the #1810 view by value: 762 "passing 'with_str' to parameter of incompatible type" and 104 "conflicting types" of the 1027 errors `cc -fsyntax-only` reported on main.c. - emitc_c_type: `bool` is C's bool; `&str` is `with_str`. - emitc_parse_param: a default value is not part of the prototype. 165 errors remain in main.c (tracked by #955): 131 member references through an int32_t-typed local, 23 `&str` arguments passed as `with_str *`, 3 void results assigned to bool, zlib's ct_data_s arrays before the struct's definition, one ComptimeValue view assignment, and the two bridge functions whose omitted return type the line scanner reads as void.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the emission half of #2017:
out/release/bin/with build out/gen/versioned_main.w --emit-c --bundle-corpus std/renow writes the compiler's C. Three C-backend refusals stood in the way, each found by the one before it moving:ba92adcb,3644629d). A variant with several fields is a struct of them in the payload union (payloadV.fieldI), the layout with-abi.md §2 / TypeLayout's TY_ENUM rule give the payload area. Construction, place text, the three place-type walks and Display handle it;Downcast(v), Field(i)is read as payload field i of variant v (MirCore's projection typing). That also fixes a silent miscompile on main: a one-field variant whose payload is a tuple read its payload as the tuple's first element (V((3, 4))printed3 0).db1780e3). After (1), emission stopped atpayload downcast for unit enum variant 1with no function named. CCodegen now names the function a refusal came from (in ZipArchive_entries__53862: ...). lldb on the reduction (out.push(get(i)?)): emit_body_text's local-type pass tookbody_downcast_option_tids' guess over MIR's declared type:_9 = move _7<as v0>.f0typed_7Option[Entry] although MIR declares Result[Entry, str]. The guess now skips a local that MIR declares as a payload enum other than Option.06492ee2).[a, b]into Vec/HashSet and[k: v]into HashMap (MirLower's COLLECTION_LITERAL / MAP_LITERAL) were LLVM-only; the C backend now builds the collection and pushes or inserts each element in order.Each has an emit_c fixture that main's release compiler refuses to emit, and whose C output this branch's compiler prints identically to the LLVM backend:
test/emit_c/enum_multi_field_payload.w(2- and 3-field positional, named and generic variants),result_try_pushed.w,collection_literals.w.Bridge prototypes (
72799f6c): the next stop was emit-c-test's line scanner (could not parse public ABI signature for wl_is_packed_struct). It now handlesbool, defaulted parameters, and&stras the #1810 viewwith_str(it had beenconst with_str *). That cutscc -fsyntax-onlyerrors on main.c from 1027 to 165.:emit-c-testis still red after emission. The 165 errors are the post-emission backlog #955 tracks:int32_t-typed local (Analysis, SemaVector, MirVector, ...)&strarguments passed aswith_str *ct_data_sarrays used before the struct is definedwith_cimport_is_cxx,with_cimport_record_is_class) whose return type is left for the compiler to infer, which the line scanner reads as voidVerification:
src/main build :gategreen (fixed list);:emit-c-smokegreen (26 cases, the 3 new fixtures among them); stage1--emit-cof versioned_main.w succeeds.Also filed: #2022 (emit-C ignores
@[align(N)]; found while checking payload layout).