Repository navigation
CCodegen: a global whose type cannot be recovered fails loudly instead of being declared int (#1429) - #1524
Merged
Conversation
This was referenced Sep 23, 2026
Contributor
Author
|
Stack #1528 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main + #1522 → … → #1527 (head 33e6ba5; every PR head is a tested commit): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Merges cleanly into main. Merge the stack: |
ehartford
marked this pull request as ready for review
September 23, 2026 16:45
…d of being declared int (#1429) global_decl_tid answered `ty_i32` whenever it could not recover a global's type: an `extern var` whose declared type did not resolve, a `let` whose annotation did not resolve (it then took the initializer's type, which may differ from the annotation), and an unannotated `let` whose initializer Sema never typed. The emitted C then declared the global `int` — an extern of another C type read the wrong bytes, a `let` stored its value truncated (AGENTS.md No Silent Fallbacks). Until #1377 the root module's frozen resolution reached the extern branch for any global whose type the root cannot name; #1377 resolves in the declaring module, which removed that route but left the fallback. Now each case calls `fail` with the global's name and kind, the type's spelling and the module it was resolved from, like the sizeof failure since #1377, and returns 0, which both callers already skip. No program reaches these branches on this tree, so no fixture reaches the failure; the fix is that it can no longer be silent. Probed with --emit-c: extern vars of arrays, pointers to arrays, tuples, fn types, Option, Result and Vec, and unannotated lets of arrays, tuples, Option, str, float, bool, suffixed ints and shifts all resolve. Emitting the whole compiler (src/main.w) as C passes every global of every module through the new check: emit_global_var_defs runs before any body, and both the base stage1 and this one then stop in a body on the loud "HashMap traversal lowering is not implemented" limitation. The same probe showed CCodegen.global_init_text zero-initializing every global whose initializer is not a literal (`let SHIFTED = 1 << 3` emits `static int32_t ... = 0`): filed as #1484.
ehartford
force-pushed
the
fix-1429-emit-c-global-type
branch
from
September 23, 2026 19:40
603e7fd to
b79b2cd
Compare
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.
global_decl_tid answered
ty_i32whenever it could not recover a global'stype: an
extern varwhose declared type did not resolve, aletwhoseannotation did not resolve (it then took the initializer's type, which may
differ from the annotation), and an unannotated
letwhose initializerSema never typed. The emitted C then declared the global
int— an externof another C type read the wrong bytes, a
letstored its value truncated(AGENTS.md No Silent Fallbacks). Until #1377 the root module's frozen
resolution reached the extern branch for any global whose type the root
cannot name; #1377 resolves in the declaring module, which removed that
route but left the fallback.
Now each case calls
failwith the global's name and kind, the type'sspelling and the module it was resolved from, like the sizeof failure
since #1377, and returns 0, which both callers already skip.
No program reaches these branches on this tree, so no fixture reaches the
failure; the fix is that it can no longer be silent. Probed with --emit-c:
extern vars of arrays, pointers to arrays, tuples, fn types, Option,
Result and Vec, and unannotated lets of arrays, tuples, Option, str,
float, bool, suffixed ints and shifts all resolve. Emitting the whole
compiler (src/main.w) as C passes every global of every module through
the new check: emit_global_var_defs runs before any body, and both the
base stage1 and this one then stop in a body on the loud "HashMap
traversal lowering is not implemented" limitation.
The same probe showed CCodegen.global_init_text zero-initializing every
global whose initializer is not a literal (
let SHIFTED = 1 << 3emitsstatic int32_t ... = 0): filed as #1484.Closes #1429
Stack #1528, bottom to top: #1522 (#1411) → #1523 (#1413) → #1524 (#1429) → #1525 (#1414) → #1526 (#1372) → #1527 (#1417). Each layer holds only its own commit.
Verification (iterate tier; no battery yet — draft until the seed-driven battery is green): stage1 and stage2 built from the stack top on darwin-aarch64 (SDKROOT CLT 15.4) and on native Windows 10 x64; fixtures below pass on both;
check --validate-allswept over test/, examples/, lib/std (3188 files) with base stage2 (main f1e3bd2) vs the stack's stage2.