Repository navigation
Description
detector.py's api_declared_orphans (#2731, the input to galaxyscope.py's orphan → api
conversion) decides whether the api rule already counted an unreferenced function by tokenizing
each api-matched line with \b\w+\b and testing the orphan's name for membership:
api_line_tokens.update(re.findall(r"\b\w+\b", code_lines[line_no - 1]))
api_declared_orphans = sum(1 for name in orphan_names if name in api_line_tokens)\b\w+\b cannot produce a token containing -, :, ., ! or ?. Every function whose name
holds one is therefore invisible to the test, the overlap reads 0, and the conversion credits the
orphan a second time — which is exactly the double count #2731/#2734 was built to remove.
This is the same tokenizer family as #2754, where the census itself counted with \b\w+\b
and every hyphenated Scheme define, Verb-Noun PowerShell function, ::ns::proc and
Class::method read as an orphan regardless of use. #2754 fixed the census and left this
consumer on the old tokenizer.
Measured
Per-file over keyword-rosetta/data, engine fix/2823-export-list-declarations, comparing the
current \b\w+\b line tokenizer against _name_boundary_pattern(name) searched over the same
api-line text:
| language | api_declared_orphans today |
with a name-aware test | why |
|---|---|---|---|
cobol |
0 | 9 | PROBE-GLOBALS, PROBE-TEST, … — hyphenated paragraph names, 3 per file in a/b/c. Present on main today |
scheme |
0 | 9 | (export probe-globals) — 3 per file in a/b/c |
| every other language (42) | 292 | 292 | unchanged; all-\w names |
haskell is the control that shows the mechanism working correctly when the names cooperate: its
export list is module A (probeGlobals, probeTest, probeSafety) where, all three names are
plain \w, api_declared_orphans reads 3, and api_orphan_credit correctly stays 0.
Consequence
api_orphan_credit (= arch_api − raw_arch_api) over-reads for these languages, and it feeds
risk_api_exposure and risk_documentation. cobol's a.cpy/b.cpy/c.cpy carry
api_orphan_credit: 3 in keyword-rosetta's manifest today; under a name-aware test they are 0,
because PROBE-GLOBALS really is declared by the api rule that matched its own paragraph line.
Fix shape
Test the orphan's real name against the api-line text instead of tokenizing the line:
api_blob = "\n".join(api_lines)
api_declared_orphans = sum(1 for name in orphan_names if re.search(_name_boundary_pattern(name), api_blob))_name_boundary_pattern is the same lookaround pair _is_orphan already uses, so the two halves
of the census agree about what an occurrence of a name is — which is the property #2754's fix
established and this line never inherited. The "no false positives are possible" argument in the
existing comment still holds verbatim: an orphan's name occurs exactly once in the whole file, so
a match on an api-matched line can only be its own declaration.
It needs a golden-master bless (cobol moves) and a keyword-rosetta re-bless of cobol's three
api_orphan_credit cells, which is why it is filed rather than folded into #2823.
Provenance
Found while doing #2823. Giving haskell and scheme a _visibility_export_list made scheme
produce orphans for the first time, and rosetta_audit.py --baseline-bin reported scheme's
api_orphan_credit 0 → 3 as the only cell moved outside the census. cobol's identical reading is
pre-existing and unrelated to that change. #2823 re-blesses scheme's cell against a ledger entry
naming this issue; both cells come back to 0 when this lands.
Part of #2812. Same tokenizer family as #2754; same double count as #2731/#2734.
Activity
squid-protocol commentedon Sep 6, 2026
The real corpus makes this much bigger than the control corpus does
Same probe over
language-crucible(all 24 languages that produce both orphans andapihits):4,983 → 5,122
api_declared_orphans, +139 across three languages. Every other language isunchanged, and every mover is a name shape
\b\w+\bcannot tokenize:zig@"?TryGetCurrent@Isolate@v8@@SAPEAV12@XZ",@"resume"— quoted identifiers (bun/napi.zigalone: 402 → 478)luabit.bor,bit.lshift,M.start,mt.__gc,cli.autoboot— dotted module memberspowershellNew-ScriptShim,Get-MachineArchitecture—Verb-Noun, i.e. every idiomatic PowerShell function namepowershell is the clearest reading of the defect:
api_declared_orphansis 0 for the wholelanguage across the crucible, because a PowerShell function name essentially always contains a
hyphen. The mechanism is not degraded there, it is entirely off.
This is why the fix is filed on its own rather than folded into #2823 — it moves five languages
(these three plus cobol and scheme on the control corpus), needs its own golden-master bless, and
its own
keyword-rosettare-bless of cobol's threeapi_orphan_creditcells.fix(core-engine): an export construct that names many functions is st…
api_declared_orphans: test the orphan's real name, not \b\w+\b tokens (…
fix(rules): objective-c api counts the method definition -- closes #2940