Repository navigation
Migrated unit constants stay in their unit; a later global read by an initializer is typed first; E1102 for a name a std corpus declares - #2835
Merged
Conversation
added 3 commits
October 30, 2026 01:19
…sed; a migrated unit's constant over its own table stays in the unit A module's initializers run in declaration order (§9.1c). Sema typed them in that order and never asked whether a read global had a value yet: an untyped later global left the reader's type 0 and codegen hit "missing concrete semantic specialization for MIR generic user call" (#2006 BUG), and a typed one read zeroed storage or a folded constant by accident. The initializer pass now records each initializer and the one it is checking (Sema.top_level_let_*); check_ident refuses a read of a later global of the same module, refuses an initializer that reads its own global, and checks another module's later global first so its type is known. A `const` is a comptime value and has no order. ee3aa89 (#809) stopped folding sizeof ratios to the host's number, so pcre2test's `#define cmdlistcount (sizeof(cmdlist)/sizeof(cmdstruct))` became D119's `cmdlist.len()` -- in the shared defs, which cannot see the unit's static `cmdlist`: the fresh pcre2 migration did not check (pcre2-check-generated, corpus-migrator-gate red on every seed leg of nightly-20261030-local-1). A macro constant naming a variable the unit defines is the unit's own and is emitted after the unit's variables. Tests: compile_errors err_global_init_reads_later_global, err_global_init_reads_later_typed_global, err_global_init_reads_itself (an internal error, a silent `6`, and silence before); c-migrator-basic-tests shared_defs_unit_static_count (migrates, checks, runs: `3 8`).
…ares is not a duplicate (E1102)
`type cmdstruct {...}` with `impl Copy for cmdstruct` was refused,
"duplicate implementation of trait for type", because pcre2's migrated
defs (reached through the prelude's std.regex) declare `cmdstruct` with
`impl Copy` too. For a colliding name the impl's declaration identity
already decides a duplicate (#1457, impl_identity_traits); the
name-keyed record below then re-decided it from the name, filtered only
by the shadow tier mask, which the engine corpus's types are not in. A
colliding name's record is now bookkeeping only; a same-name duplicate
of one declaration is still E1102 (err_duplicate_trait_impl,
err_coherence_duplicate_trait_impl).
Found by c-migrator-basic-tests shared_defs_unit_static_count, whose
fixture names its record `cmdstruct` after pcre2test's.
Test: behavior behav_impl_for_name_a_std_corpus_declares (E1102 before).
The declaration-order refusal broke the libxml2 UAT: its modeled headers declare `let QUAD_MIN = LLONG_MIN` before `LLONG_MIN`, a constant with no runtime order, and one facade's c_imports share a source path, so they read as one module. Which initializers run at runtime is codegen's fact today, not Sema's; whether a read of a later runtime-initialized global is refused or reordered is a §9.1c ruling, taken to Eric. Kept: the later global's initializer is checked first (the ICE and 'no initializer codegen can lower' fixed), and an initializer that reads its own global is refused. Test: behavior behav_global_init_reads_later_constant (the UAT's shape; 'no initializer codegen can lower' before).
Contributor
Author
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.
Unblocks the seed cut
nightly-20261030-local-1-e86624ac1fdd: darwin, linux-x86_64 and linux-aarch64 all failed:release-checksatpcre2-check-generated/corpus-migrator-gate. Nothing was published.1. The migrator (root cause). ee3aa89 (#809) stopped folding sizeof ratios to the host's number, so pcre2test's
#define cmdlistcount (sizeof(cmdlist)/sizeof(cmdstruct))became D119'scmdlist.len()— in the shareddefs.w, which cannot see pcre2test'sstatic cmdlist. A macro constant that names a variable its unit defines is now emitted into that unit, after its variables.2. Sema, global initializers. A global's initializer that read an untyped global declared after it left the reader untyped:
missing concrete semantic specialization, a Codegen silent fallbacks: when a default trait method, closure or global-initializer body can't place its terminator, the emitter returns a constant 0 #2006 BUG), or refused with "no initializer codegen can lower";let a: i64 = a + 1was accepted.The later global's initializer is now checked first, and a self-read is refused. A declaration-order refusal (§9.1c) was tried and dropped: it broke the libxml2 UAT, whose modeled headers alias a later constant (
QUAD_MIN = LLONG_MIN). The remaining hole — a read of a later runtime-initialized global sees zeroed storage — is a §9.1c ruling, taken to Eric.3. E1102. A program's
impl Copy for cmdstructwas refused as a duplicate because pcre2's migrated defs declare acmdstructtoo. For a colliding name, the declaration-identity check (#1457) now decides alone.Tests:
behav_global_init_reads_later_constanterr_global_init_reads_itselfbehav_impl_for_name_a_std_corpus_declaresshared_defs_unit_static_count(migrates, checks, runs3 8)Each new test failed before its fix.
Evidence:
:release-checksgreen (on 56863f4+eb174c36b).