Skip to content

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
ehartford merged 3 commits into
mainfrom
global-init-order
Oct 30, 2026
Merged

ehartford merged 3 commits into
mainfrom
global-init-order

Conversation

@ehartford

@ehartford ehartford commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Unblocks the seed cut nightly-20261030-local-1-e86624ac1fdd: darwin, linux-x86_64 and linux-aarch64 all failed :release-checks at pcre2-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's cmdlist.len() — in the shared defs.w, which cannot see pcre2test's static 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:

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 cmdstruct was refused as a duplicate because pcre2's migrated defs declare a cmdstruct too. For a colliding name, the declaration-identity check (#1457) now decides alone.

Tests:

  • behav_global_init_reads_later_constant
  • err_global_init_reads_itself
  • behav_impl_for_name_a_std_corpus_declares
  • c-migrator-basic-tests shared_defs_unit_static_count (migrates, checks, runs 3 8)

Each new test failed before its fix.

Evidence:

  • :release-checks green (on 56863f4+eb174c36b).
  • Battery green on 6cd53d0: gate, UAT (libxml2 included) and battery-checks.

Eric Hartford 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).
@ehartford ehartford changed the title §9.1c initializer order; migrated unit constants stay in their unit; E1102 for a name a std corpus declares 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 Oct 30, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on 6cd53d0 (seed-driven: gate, uat 9 pass / 3 skip (display, platform), battery-checks). :release-checks green on eb174c3.

@ehartford
ehartford marked this pull request as ready for review October 30, 2026 05:56
@ehartford
ehartford merged commit 507c222 into main Oct 30, 2026
@ehartford
ehartford deleted the global-init-order branch October 30, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant