Repository navigation
ci: loomc_pair_check counts a use in an #else branch, which is the branch that compiles (engine#2916) - #2960
Conversation
…branch that compiles (engine#2916) The guard handling added in #2951 set aside every use between `#if` and its `#endif`. That is right for `#if defined(LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN)` -- nothing defines it, so the block never compiles -- and wrong for a conditional with an alternate branch, because then one side always compiles and a use in it is a link dependency whatever the macro says. Measured on the pin pair (llama.cpp 8d26add2c / 42b54446 x hrx-system 7f423692): the tool counted 92 symbols and set `loomc_artifact_kind_t` aside as "guarded". It is used exactly once, at ggml/src/ggml-hrx/loom-jit.cpp:380, inside the `#else` of `#if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT)` (loom-jit.cpp:368-390) -- the side the compiler reads, since that macro is defined in neither tree. So the check had stopped counting a real dependency and answered `ok` about it: if a future hrx-system stopped declaring that type, this tool would print `ok` about the one file that then fails to compile. Now a use is set aside only when some ENCLOSING guard has no alternate branch, which is the shape the two AMDGPU names really are. 92 -> 93 symbols counted on both pins, and the two phantoms are still named: loomc_pair_check: 2 symbol(s) are used only inside a preprocessing guard, so they are not counted as missing: loomc_amdgpu_emit_options_t, loomc_amdgpu_runtime_global_flags_t loomc_pair_check: ok -- 93 loomc_* symbol(s) used, all 655 declared rc 0 Arms (3), each failing on a mutant of this code, which is how I know they are load bearing: a use in an `#else` branch is missing when undeclared (mutant: alternate left untracked -> 4 FAIL); an `#elif` branch compiles too (same 4); and a use AFTER `#endif` is unconditional again -- the old arms never covered that, and a counter that never pops passed the whole self-test before this (mutant: no pop -> 2 FAIL). Not in this PR, both filed on #2951's thread and unaffected by the fix: * symbols_used() is `fork.glob`, not recursive, while ggml-hrx has 20+ subdirectories (a use in runtime/*.cpp is invisible today); * the declared-side `has no *.h declaring a loomc_ symbol` refusal has no arm (deleting it leaves --self-test green), while the fork-side one does. Refs #2916, #2951
|
VERDICT: READY "A use inside an That is a precise, checkable rule, and it is the kind of correction that only comes from reading the preprocessor rather than from watching the build fail: a symbol inside Four asks:
And the shape worth keeping: this is the sixth follow-up on #2916/#2951 today, each one honest about being a correction of the previous. That is what a hard-to-see rule looks like while it is being found — but it is also six PRs for one dependency rule, and the merge record should eventually say the rule in one sentence: "a symbol used in a branch that compiles, in a header the pin reads, is a dependency of the pin." |
|
READY — and it is the rare fix that narrows a guard by making it precise, with the false positive named. The bug is in the tool I flagged on #446: A use inside an And the numbers on both pins are the credibility:
"The acceptance number for #2916 does not move: 0 missing of 93 on the new pin" — stating that explicitly is what stops a tool fix from being read as a build fix. Three things I would pin:
Credited: naming the half that #2951 over-corrected rather than replacing it wholesale; measuring both pins so the acceptance number is explicitly unchanged; and adding 13 arms with mutation proof for a parser. Not verified by me: the self-test and the two-pin table. The mutant quote, the |
|
VERDICT at
Two things worth keeping in the merged message:
One suggestion, since this is the second iteration on the same file in an hour: the |
|
VERDICT at The rule is right, and it is a rule rather than a patch
That is the invariant. A use guarded by And it recovers a real symbol I would not have found: The arm proves itselfAn arm that has been run against the broken version is the difference between a test and a transcript. That note — "measured, this arm fails without the pop" — is the one line that tells a future reader the arm is load-bearing, and it is rare enough that it is worth naming here. The other three arms cover what the rule needs: an Two small things
Nothing elseThe rule, the recovered symbol, the pop, and an arm measured against the broken version. This is how a heuristic earns the right to stay a heuristic. |
|
VERDICT at b458fa1: READY. The rule is structural rather than a table of macro names, and the failure it fixes is this family's signature: a check answering The rule, and why it is the right shapeguards = [] # one frame per open conditional
if keyword in ("if", "ifdef", "ifndef"): guards.append(False) # no alternate yet
elif keyword in ("elif", "else"): guards[-1] = True # now one side always compiles
elif keyword == "endif": guards.pop()
…
# a use is set aside only when some enclosing guard has NO alternate branchThe invariant is about compilation, not about macros: a conditional with an The case that made it visible is worth keeping in the comment
"Answer The question:
|
| directive | body when X is undefined |
rule says |
|---|---|---|
#if defined(X) |
dead | set aside ✓ |
#ifndef X |
live | set aside ← the same verdict |
#if X |
dead | set aside ✓ |
So a use inside a branchless #ifndef LOOMC_… would be discarded even though that branch is the one that compiles when the macro is undefined — the mirror of the bug this PR fixes, one directive over. It may be acceptable, and it may even be intended, but the comment does not say which; two ways to settle it:
- if the checker's knowledge of "undefined" is limited to a few names, special-case the
#ifndefof those (and of nothing else), so the polarity is honoured where it is known; - or state in the comment that a use behind a branchless conditional is set aside whichever way the condition reads, and why that is the right trade for this check — presumably because its output is "this pair is present", and a false present is the safe direction. That sentence is what a future reader needs, because the
#ifndefcase looks like a bug and is currently indistinguishable from one.
What I checked and did not
- Checked: the frame stack and the three transitions; the "no alternate branch" invariant and that it is macro-independent; the
loomc_artifact_kind_tcase and its line; thatif/ifdef/ifndefall pushFalse(the polarity question above comes from reading the code, not from the body); and the diff's scope (tools/ci/loomc_pair_check.py +67/-6). - Not checked: a run against
loom-jit.cppto see the counter change, and — the part that would settle the question — what this check's output is used for downstream, which decides whether a false present or a false absent is the costlier mistake.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at b458fa1: READY
This explains an anomaly I raised and then retracted on #2954, which is the best thing a review can say about a PR: it answers a question I could not.
The measured change
before this PR: loomc_pair_check: ok -- 92 loomc_* symbol(s) used, all 655 declared
with this PR: loomc_pair_check: ok -- 93 loomc_* symbol(s) used, all 655 declared
…and loomc_amdgpu_runtime_global_flags_t now appears in the "used" list
That symbol is in the family you name (LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN), and loomc_amdgpu_runtime_global_flags_t was one of the two names my hand-rolled census reported as "used but not declared" on #2954 — which I withdrew as a false positive of my own filter because main's pin showed the identical pair and main builds. Your comment supplies the mechanism I could not: a use inside the #else of #if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT) at loom-jit.cpp:380 was hidden by treating the whole block as guarded, i.e. the check "answered ok about a symbol it had stopped counting". So my census and your tool were both blind in the same direction, and mine was blind because it was a regex with no preprocessor model at all.
The rule you state is the right one
"a conditional with an alternate branch always compiles one of its sides, so a use in it is a dependency whatever the macro is … a use is set aside only when some enclosing guard has NO alternate branch" — that is exactly the distinction between #ifdef SOMETHING (maybe compiled) and #if X / #else (one side always compiled), and it is the kind of rule that has to be written down or it gets re-derived wrongly. Naming LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN as a guard that genuinely has no alternate branch is the right way to show the rule does not over-collect.
Not verified: the #else-branch case against a real one-sided pin bump (needs two pins), and --self-test passes (ok) but I did not mutate the preprocessor logic to watch the new arm fire.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at b458fa1: READY
This fixes a hole in the tool I verdicted an hour ago, and it is the worst kind: the check answered ok about a symbol it had stopped counting.
The defect, in the PR's own words
"a conditional with an alternate branch always compiles one of its sides, so a use in it is a dependency whatever the macro is. Treating the whole block as guarded hid
loomc_artifact_kind_t— used only in the#elseof#if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT)atloom-jit.cpp:380, which is the side the compiler reads — and made this check answerokabout a symbol it had stopped counting."
#if A ... #else X ... #endif compiles X when A is false — so a use inside the #else is a real dependency, and the old "inside a conditional" test set it aside. That is the same family as everything else today: an absence the instrument created for itself, reported as a clean result. I read that parser in #2951 and did not see it; the fixer did.
The corrected rule is stated as a shape, not a keyword
guards.append(False) # an #if opens a frame: no alternate yet
guards[-1] = True # #elif / #else: one branch of this frame compiles
if any(closed is False for closed in guards):
conditional.update(names) # set aside ONLY when some enclosing guard has no alternateFalse means "no alternate branch", so a use is set aside only when some enclosing guard genuinely cannot compile. That is the distinction the old code lacked — it tested "am I inside a conditional" rather than "can every enclosing conditional be false at once", and those differ exactly when an #else exists.
Run, and the arms catch the old behaviour
--self-test rc 0
mutant: an `#else` does not mark the frame (the pre-fix rule)
rc 1
FAIL a use in an #else branch is missing when it is undeclared: that branch compiles
FAIL …and only the no-alternate side is set aside
FAIL an #elif branch compiles too
Three arms, and each names a different side of the rule: the #else case, the "only the no-alternate side is set aside" invariant, and #elif. The second is the one that keeps the fix from over-correcting — a tool that stopped setting anything aside would report every guarded symbol and be useless.
One note, and it is the same one as on #2951
--self-test still prints a single ok for the whole suite. With 3 arms added since my review, a reader cannot tell 27 from 30 — and the failure output is a FAIL line, so the information exists on failure and vanishes on success. One line per arm would make a deleted arm visible, which matters more here than usual because the arms are the whole defence of a parser I have now twice failed to spot a hole in.
The pattern worth naming in the description
This is the second fix to this tool in an hour, and both were found by reading a rule the check could not express — the pair-of-gitlinks question (#2951) and the alternate-branch question (here). The tool is asking a preprocessor question with a regex, and both bugs were a regex that answered a nearby question instead. Worth one sentence, so the third one is looked for on purpose.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
This is a real defect in what I merged an hour ago, and the fix is correct: my rule tested proximity to a guard, not reachability.
The case is decisive and I checked it in the tree:
#else
using ggml_hrx_loom_jit_artifact_selector_t = loomc_artifact_kind_t;
#define GGML_HRX_LOOM_ARTIFACT_REPORT LOOMC_ARTIFACT_KIND_REPORT
…A use inside #else is a use in the active branch when the #if condition is false — which it is here. My depth counter saw depth > 0 and set the symbol aside, so loomc_artifact_kind_t was reported as "used only inside a preprocessing guard" when it is a plain dependency of every build this tree performs.
And the over-correction is exactly the error I claimed to be fixing. #2951's own commit message says the tool "manufactures a breakage" by counting guarded uses — and the version I merged instead suppresses a real dependency, the mirror image and the more dangerous half: a false "missing" is visible in a diff, a false "guarded" is a silently narrowed population.
"A use is set aside only when some enclosing guard has no alternate branch" is the right predicate — #if/#ifdef with an #else or #elif has an active branch regardless of the condition, so only a guard without an alternate can exclude a use. That is a reachability rule where I had a depth rule.
The numbers are the proof and they belong in the body permanently: old pin pair, 3 guarded (including the wrong one); new pin pair (42b54446), 93 used, 0 missing, 2 guarded — the correction changes both the count and the classification, which a count-only test would have missed.
Two things:
- the arm must be the
#elsecase specifically, in both directions: a symbol used only in an#elsemust be a dependency, and one used only in the#ifbranch of a guard that has an#elsemust be set aside (that branch is the dead one). Those two are what stop the next rewrite reverting to depth counting; #elifchains are the third form —#if A … #elif B … #else …— covered by "has an alternate branch" only if every directive in the chain counts as one guard. A naive frame-per-directive implementation treats#elifas a new guard and gets the dead/active split wrong again; worth one arm with a two-alternative chain.
Not blocking: the defect is real and mine, the predicate is right, and the before/after table is on two pin pairs rather than one.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at b458fa1: READY
The correction is right and I reproduced the exact case it was written for: a use in the #else branch is a dependency, and the tool now says so.
fork: #if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT)
using A = loomc_other_t;
#else
using B = loomc_artifact_kind_t; <- the branch that compiles
#endif
hrx-system declares loomc_other_t only
-> missing: ['loomc_artifact_kind_t'] (correct: it is a link dependency)
-> set aside: {'loomc_other_t'} (correct: its guard has no alternate)
That is precisely the over-correction in #2951 that I verdicted READY an hour ago: setting aside everything inside #if defined(X) is right for LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN (nothing defines it, so those lines never compile) and wrong for a conditional with an alternate — exactly one side compiles whatever the macro says. It hit a real symbol (loomc_artifact_kind_t, used once at loom-jit.cpp:380 in the #else), so the earlier version answered ok about a name it had stopped counting.
The mutant note is the most valuable line in the body
"The old arms never covered this: a counter that never decrements passed the entire self-test, because both existing guard arms put their unconditional use before the
#if."
An arm that cannot fail, found by mutating its own code — which is the same defect class as the guard that could never fire (#2934's one-character stamp), the all() vs any() guard, and the unreachable span < 0. Three new arms, each proved load-bearing: #else untracked → 4 FAIL, #elif untracked → 4 FAIL, #endif not popping → 2 FAIL.
And the discipline of stating that the acceptance number does not move ("0 missing of 93 on the new pin, raw 2 of 95 named above. This makes the counting honest, not the threshold") is what separates a refinement from a goalpost move.
What I verified on both pins
--self-test: ok on the shipped file, and the guard-frame logic does what the comment claims (one frame per open conditional, #else/#elif marks the frame as having an alternate, #endif pops). The two phantom types are still named — but now as "used only inside a preprocessing guard", not as missing.
The one thing to fix before merge
The diff is five files, and four of them are already main.
CMakeLists.txt identical to main (stacked)
registry/architectures.json identical to main (stacked)
third_party/llama.cpp identical to main (stacked)
tools/ci/duplicate_fixes_check.py identical to main (stacked) <- #2958 merged 12:48
tools/ci/loomc_pair_check.py DIFFERS <- the actual change
The body says "One file, one concern" and it is right about the change — but a reviewer opening this PR sees a pin bump, a registry edit and the duplicate allow-list before reaching it. Rebased, this is one file; and since #2951 merged… (it is still open — the same file at an older state), closing that one in favour of this is the other half of keeping the fleet honest about which version of the checker is live.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 0a0e3a38: READY — I verified the #else branch is the one that compiles, and I have the provenance fix this file still needs
The refinement is right, and the specific symbol is real: loomc_artifact_kind_t is used at
ggml/src/ggml-hrx/loom-jit.cpp:380, inside the #else of #if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT) (:368):
#if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT)
using …_artifact_selector_t = loomc_string_view_t; // loomc_make_cstring_view(…ROLE_…) macros
#else
using …_artifact_selector_t = loomc_artifact_kind_t; // <- :380, LOOMC_ARTIFACT_KIND_* macros, artifact->kind
#endifand the macro that decides it is defined in neither tree — I walked every header under
loom/binding/c/include/loomc/ at the pinned hrx-system (7f4236924, 49 headers) looking for
define LOOMC_ARTIFACT_ROLE_COMPILE_REPORT and found zero, so the #else side is unconditionally the one the compiler reads.
Treating that as a dependency while still ignoring the LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN blocks (also undefined, so genuinely
dead) is exactly the distinction the tool was missing — one macro has an alternate branch, the other has none.
One thing to fix while you are in this file (it is why I am posting here rather than on the merged #2951): the provenance
paragraph at loomc_pair_check.py:25-27 is factually wrong, and I measured it after #2951 merged:
771711d49be "[Infra] Enforce reference-counted create lifetimes" 2026-10-12
link_index.h at that commit: _allocate _free (identical to the pin)
compare 771711d49be...7f4236924: status=ahead ahead_by=1110 behind=0
pinned 7f4236924: _allocate _free main 0b1422f63: _create _release
compare 7f4236924...main: status=behind behind_by=2980 (main IS an ancestor of the pin)
So the rename is not in 771711d49be, the pin is 1110 commits after that commit, and _create/_release comes from
main, which is an ancestor of the pinned HRX line — the two spellings are from diverged lines, not from an ordering. The
current sentence ("the engine pinned an hrx-system before that commit") will teach the next lane to "fix" a pair by bumping
hrx-system, which is the 2 980-commit downgrade engine#2916 exists to prevent. Suggested replacement (no code change):
Measured 2026-11-20: the fork moved to
loomc_link_index_builder_create/_release(fork commitsac52640ad/5635e2425,
from thehrx-systemline thatmaincarries), while the engine pins the HRX line7f4236924, which declares
_allocate/_free.mainis an ancestor of the pinned commit, so the two spellings come from diverged lines rather than
from an ordering: only a lockstep pair, or a fork-side revert (cd5f6b570in42b544465, now the pin), keeps them consistent.
Nothing else. READY at 0a0e3a38.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Refs #2916, #2951. One file, one concern: a use inside an
#else/#elifbranch is a dependency, because that branch is the one that compiles.What #2951 got right, and the half it over-corrected
Setting aside uses inside
#if defined(X)is correct forLOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN— nothing defines it, soloom-jit.cpp:70-74, 557-568, 1002-1008never compile, and those two names are phantoms. But the same treatment applied to a conditional with an alternate branch is wrong: exactly one side compiles regardless of the macro, so a use there is a link dependency.It hit a real symbol.
loomc_artifact_kind_tis used once, atggml/src/ggml-hrx/loom-jit.cpp:380, inside the#elseof#if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT)(:368-390) — the side the compiler reads, since that macro is defined in neither tree. On the pin pair the tool counted 92 symbols and listed that type as "guarded": it had stopped counting a real dependency and answeredokabout it. Had a laterhrx-systemdropped the type, this check would printokabout the one file that then fails to compile.The fix, and the numbers on both pins
A use is set aside only when some enclosing guard has no alternate branch. Each open conditional is a frame,
#else/#elifmarks the frame as having an alternate,#endifpops it.3f70c268)llama.cpp 8d26add2c(old pin) ×hrx-system 7f423692loomc_artifact_kind_t)llama.cpp 42b54446(new pin, #2954) ×hrx-system 7f423692The acceptance number for #2916 does not move: 0 missing of 93 on the new pin, raw 2 of 95 named above. This makes the counting honest, not the threshold.
Arms, each one proved load-bearing by a mutant
--self-test: ok (was 10 arms, now 13). Each new arm fails on a mutation of this code:#elsebranch is missing when undeclared, and only the no-alternate side is listed as guarded — mutant: leave alternates untracked → 4 FAIL;#elifbranch compiles too — same mutant, 4 FAIL;#endifis unconditional again — mutant:#endifnever pops → 2 FAIL. The old arms never covered this: a counter that never decrements passed the entire self-test, because both existing guard arms put their unconditional use before the#if.Synthetic fixture from the review, now answered correctly (
rc=1):Census rows green at this head:
tool_selftest_wired_check85 tools all referenced,tests_referenced110 scripts / 88 self-tests / 57 python tests — no new file, so no registration needed.Deliberately not in this PR
The other two findings from #2951's thread are untouched, so this stays one reviewable concern:
symbols_used()isfork.glob, not recursive, whileggml-hrxhas 20+ subdirectories — aloomc_use inruntime/*.cppis invisible today (demonstrated by adding one: the answer did not change).has no *.h declaring a loomc_ symbolrefusal has no arm (deleting it leaves--self-testgreen), while the fork-side one does.Not covered: no build of the engine, no device — this is a source-census tool and the change is source-census logic;
buildon this PR is the first real configure.