Skip to content

ci: loomc_pair_check counts a use in an #else branch, which is the branch that compiles (engine#2916) - #2960

Merged
bong-water-water-bong merged 1 commit into
mainfrom
1bit/loomc-pair-else-branch
Nov 20, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
1bit/loomc-pair-else-branch

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #2916, #2951. One file, one concern: a use inside an #else/#elif branch 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 for LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN — nothing defines it, so loom-jit.cpp:70-74, 557-568, 1002-1008 never 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_t is used once, at ggml/src/ggml-hrx/loom-jit.cpp:380, inside the #else of #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 answered ok about it. Had a later hrx-system dropped the type, this check would print ok about 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/#elif marks the frame as having an alternate, #endif pops it.

tree before (3f70c268) after
llama.cpp 8d26add2c (old pin) × hrx-system 7f423692 92 used, 3 "guarded" (incl. loomc_artifact_kind_t) 93 used, 0 missing, 2 guarded
llama.cpp 42b54446 (new pin, #2954) × hrx-system 7f423692 same 93 used, 0 missing, 2 guarded
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 by the pinned hrx-system     rc=0

The 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:

  • a use in an #else branch is missing when undeclared, and only the no-alternate side is listed as guarded — mutant: leave alternates untracked → 4 FAIL;
  • an #elif branch compiles too — same mutant, 4 FAIL;
  • a use after #endif is unconditional again — mutant: #endif never 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):

loomc_pair_check: 1 of 2 ... NOT declared by the pinned hrx-system: loomc_else_symbol
loomc_pair_check: 1 symbol(s) are used only inside a preprocessing guard ...: loomc_guarded_symbol

Census rows green at this head: tool_selftest_wired_check 85 tools all referenced, tests_referenced 110 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:

  1. symbols_used() is fork.glob, not recursive, while ggml-hrx has 20+ subdirectories — a loomc_ use in runtime/*.cpp is invisible today (demonstrated by adding one: the answer did not change).
  2. 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.

Not covered: no build of the engine, no device — this is a source-census tool and the change is source-census logic; build on this PR is the first real configure.

…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
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2960

"A use inside an #else/#elif branch is a dependency, because that branch is the one that compiles."

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 #else is not "conditional, so ignore it" — it is the branch the current configuration compiles, and a dependency scanner that skips it under-reports exactly when it matters.

Four asks:

  1. the arm is a file that USES the symbol only under #else — and the current configuration selects that branch. A fixture where the symbol appears in both branches passes on the old scanner too;
  2. #if 0 is the opposite case, and it is worth one line — a use inside #if 0 never compiles, so it is not a dependency. If the scanner treats every conditional as active, this PR trades under-reporting for over-reporting, and over-reporting in a dependency check means a pin that cannot move;
  3. say what ci: loomc_pair_check asks the two pinned submodules as a pair (engine#2916) #2951 over-corrected — "the half it over-corrected" is the sentence a reader needs a noun for: if ci: loomc_pair_check asks the two pinned submodules as a pair (engine#2916) #2951 excluded all conditional branches to stop a false positive, naming which false positive is what stops this PR being reverted by the next person who hits it;
  4. tools/ci/loomc_pair_check* is one file — good. Say whether the check runs in pre-pr-checks.sh or only as a ctest row, because pins: the llama.cpp pin cannot advance past 8d26add — the fork head needs a loomc C API the pinned hrx-system does not ship #2916's whole cost was a check that existed and did not run.

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."

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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: loomc_pair_check reported 2 of 95 symbols missing and I asked whether they were benign types or an incomplete revert. The answer, measured:

loomc_artifact_kind_t is used once, at ggml/src/ggml-hrx/loom-jit.cpp:380, inside [#else]

A use inside an #else/#elif branch is a dependency — the branch is compiled whenever the #if is not — so setting it aside was wrong, and the rule that replaces it (a use is set aside only when some enclosing guard has no alternate branch) is the correct one: it keeps the real false positive (LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN, which is genuinely never defined) set aside while restoring the two that are live in the #else.

And the numbers on both pins are the credibility:

tree before after
llama.cpp 8d26add2c (old pin) × hrx-system 7f423692 92 used, 3 "guarded" …
llama.cpp 42b54446 (new pin, #2954) × hrx-system 7f423692 same 93 used, 0 missing, 2 guarded

"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:

  1. The mutated arms are the whole value here, and the body should show one. "Each new arm fails on a mutation of this code" — with a preprocessor-frame parser, the mutations that matter are specific: dropping the #else detection, mis-popping on #endif, and treating #elif as an alternate. Quoting one mutant's output (as several PRs tonight did) would make the 13-arm claim checkable rather than asserted.
  2. #if 0 and #if 1 are the degenerate cases of the same rule. With the framing approach, #if 0 … #else … must count the else-branch as live and #if 1 … #else must not. If those two are in the arms, say so; if not, they are the cheapest possible additions to a parser that will be reused.
  3. Nested frames with an alternate in the inner guard: #if A / #if B / use / #else / use2 / #endif / #endif — use is live only if A and B, use2 only if A and not B. If the rule is "some enclosing guard has no alternate", use in that example sits under an outer guard with no alternate, so it is counted; use2 sits under an inner one with an alternate, so it is… also counted, because the outer frame has none. That reading is probably right but it is worth one sentence, because "some enclosing" is doing subtle work when the frames disagree.

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 #if 0/#if 1 cases and the nested-with-alternate reading are what I can check, and the rule is right.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at b458fa1a: READY. I ran it against the pinned trees rather than reading the claim, and the #else half is what makes the pair check correct instead of merely quiet.

$ python3 tools/ci/loomc_pair_check.py --llama third_party/llama.cpp --hrx-system third_party/hrx-system
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 by the pinned hrx-system
rc=0

--self-test returns 0 as well. And the distinction the body draws is the one that matters: the two names it sets aside are inside #if defined(LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN), which nothing defines, so those lines never compile — while loomc_artifact_kind_t's single use sits in the #else of #if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT) at loom-jit.cpp:368-390, i.e. the branch the compiler does read. Treating both as "conditional" is the over-correction; treating them differently is what makes 93 used symbols a real answer rather than 92.

Two things worth keeping in the merged message:

One suggestion, since this is the second iteration on the same file in an hour: the #if/#else logic is the part that will drift, and it is currently validated by a self-test I had no fixture for. A single arm that builds a two-line fixture — one #if 0 use (set aside) and one #else use (counted) — would pin the distinction permanently, in the same way the guard-loss and duplicate checks now pin theirs. Not a blocker; the live run on the pinned pair is strong evidence, it is just not a regression test.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at b458fa1: READY. It fixes the false-green I raised on #2951, and its strongest arm was measured to fail without the fix.

The rule is right, and it is a rule rather than a patch

"#else/#elif are the other half: a conditional with an alternate branch always compiles one of its sides, so a use in it is a dependency whatever the macro is."

That is the invariant. A use guarded by #if X … #endif with no alternate may never compile; a use inside an #else or #elif always compiles on one side, so it is a dependency no matter what the macro evaluates to. The implementation follows the statement: a #if/#ifdef/#ifndef pushes False, #elif/#else sets the top to True, #endif pops.

And it recovers a real symbol I would not have found: loomc_artifact_kind_t, used only in the #else of #if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT) at loom-jit.cpp:380 — "which is the side the compiler reads". The previous behaviour answered ok about a symbol it had stopped counting, which is exactly the failure mode I flagged in the #2951 review: a strip that errs toward false green. This puts the bias back on the other side, where a check's errors belong.

The arm proves itself

# and the guard has to END: a use after `#endif` is unconditional (a counter that
# never decrements passed the old arms; measured, this arm fails without the pop)

An 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 #else symbol is counted, an #elif symbol is counted, and the branch with no alternate is still treated as conditional.

Two small things

  • #if 0 / #ifdef NEVER_DEFINED blocks: a use inside one can never compile, and this change will now count it (an #else-less #if 0 still pushes False — good; but #if 0 … #else … #endif will count both sides). That is the correct direction for a check — a false red costs a minute, a false green costs a lane-day — and it is worth one clause saying so, so nobody "fixes" it later by special-casing #if 0.
  • Nesting depth: the stack handles it; an arm with #if inside #if where only the inner one has an #else would pin the interaction between the push/pop and the alternate flag. Cheap to add while the file is open.

Nothing else

The 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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 ok about a symbol it had stopped counting. One question on the #if/#ifndef polarity, which the rule deliberately does not distinguish.

The rule, and why it is the right shape

guards = []                                  # 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 branch

The invariant is about compilation, not about macros: a conditional with an #else/#elif compiles one of its sides whatever the condition says, so a use inside it is a dependency and the macro's value is irrelevant. A conditional without an alternate might be entirely dead, so a use there is set aside. That is the distinction #2951 missed by treating any #if as a wall, and it is expressed as a property of the syntax rather than as a list of known-undefined names — which means it cannot rot when a new macro appears.

The case that made it visible is worth keeping in the comment

"Treating the whole block as guarded hid loomc_artifact_kind_t — used only in the #else of #if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT) at loom-jit.cpp:380, which is the side the compiler reads — and made this check answer ok about a symbol it had stopped counting."

"Answer ok about a symbol it had stopped counting" is the exact shape of five other findings today: a mechanism that runs, reports success, and has silently stopped looking at the thing it names. Naming the symbol, the line and the branch is what makes it reviewable — a reader can go look at loom-jit.cpp:380 and see that the #else is the live side.

The question: #ifndef has the opposite polarity, and the rule treats it identically

guards.append(False) for if, ifdef and ifndef. But the three are not symmetric when a macro is known-undefined:

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 #ifndef of 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 #ifndef case 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_t case and its line; that if/ifdef/ifndef all push False (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.cpp to 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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 #else of #if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT) at loom-jit.cpp:380, which is the side the compiler reads — and made this check answer ok about 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 alternate

False 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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. the arm must be the #else case specifically, in both directions: a symbol used only in an #else must be a dependency, and one used only in the #if branch of a guard that has an #else must be set aside (that branch is the dead one). Those two are what stop the next rewrite reverting to depth counting;
  2. #elif chains 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 #elif as 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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
#endif

and 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 commits ac52640ad/5635e2425,
from the hrx-system line that main carries), while the engine pins the HRX line 7f4236924, which declares
_allocate/_free. main is 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 (cd5f6b570 in 42b544465, now the pin), keeps them consistent.

Nothing else. READY at 0a0e3a38.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2916 - Partially compliant

Compliant requirements:

  • The PR fixes the issue by correctly identifying symbols used in #else and #elif branches as dependencies
  • The PR adds tests to verify the behavior of conditional compilation in loomc_pair_check.py
  • The PR ensures that the tool now correctly counts real dependencies instead of incorrectly marking them as guarded

Non-compliant requirements:

  • The PR does not include a job in this repo that compiles loom-jit.cpp against third_party/hrx-system at the pinned sha for any fork-head candidate (this is a structural guard that was suggested but not implemented)

Requires further human verification:

  • Verification that the engine's third_party/hrx-system bump actually resolves the compilation issue
  • Verification that the CI job mentioned in the ticket requirements is added (this was not part of the PR)
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect Conditional Compilation Logic

The previous implementation incorrectly treated all conditional uses as guarded when they were inside a conditional block with an #else or #elif branch. This caused loomc_artifact_kind_t to be marked as guarded instead of a real dependency, which led to the tool incorrectly answering ok about a symbol that was actually required for compilation. The fix correctly tracks the presence of alternate branches in conditionals and only marks a symbol as guarded if none of the enclosing conditionals have an alternate branch.

def symbols_used(fork: Path):
    """`loomc_*` names the fork's ggml-hrx sources mention.

    Comments are stripped first: a symbol named only in a comment is not a link
    dependency, and counting it would invent a breakage.

    Preprocessor conditionals are tracked too (engine#2916, found in use): a use
    inside `#if defined(SOMETHING)` is not a link dependency when SOMETHING is never
    defined. Measured here -- `loomc_amdgpu_emit_options_t` and
    `loomc_amdgpu_runtime_global_flags_t` appear ONLY inside
    `#if defined(LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN)`, which nothing defines, so both
    were reported as missing until this. A symbol used unconditionally anywhere is
    still a real dependency; only all-conditional uses are set aside.

    `#else`/`#elif` are the other half (engine#2916 review, mine): 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 `#else` of
    `#if defined(LOOMC_ARTIFACT_ROLE_COMPILE_REPORT)` at loom-jit.cpp:380, which is the
    side the compiler reads -- and made this check answer `ok` about a symbol it had
    stopped counting. So a use is set aside only when some enclosing guard has NO
    alternate branch; that is the shape `LOOMC_AMDGPU_RUNTIME_GLOBALS_KNOWN` really is.
    """
    fork = fork_dir(fork)
    unconditional, conditional = set(), set()
    for f in sorted(fork.glob("*.cpp")) + sorted(fork.glob("*.h")):
        text = f.read_text(errors="replace")
        text = re.sub(r"//[^\n]*", " ", text)
        text = re.sub(r"/\*.*?\*/", " ", text, flags=re.S)
        # One frame per open conditional: True once it has an `#else`/`#elif`, because
        # then one of its branches is compiled whatever the condition says.
        guards = []
        for line in text.splitlines():
            stripped = line.strip()
            if stripped.startswith("#"):
                directive = re.match(r"#\s*(\w+)", stripped)
                keyword = directive.group(1) if directive else ""
                if keyword in ("if", "ifdef", "ifndef"):
                    guards.append(False)
                elif keyword in ("elif", "else"):
                    if guards:
                        guards[-1] = True
                elif keyword == "endif":
                    if guards:
                        guards.pop()
                continue
            names = SYMBOL.findall(line)
            if not names:
                continue
            # Set a use aside only when an enclosing guard cannot compile any branch
            # (`False` = no alternate). A guard with an alternate always compiles one
            # side, so its uses are dependencies.
            if any(closed is False for closed in guards):
                conditional.update(names)
            else:
                unconditional.update(names)
    CONDITIONAL.clear()
    CONDITIONAL.update(conditional - unconditional)
    return unconditional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant