Skip to content

c api: a file-scope variable is globals' hit, not public surface (#2907) - #2911

Merged
squid-protocol merged 1 commit into
mainfrom
fix/2907-c-api-variable-declarations
Sep 9, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/2907-c-api-variable-declarations

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #2907. Phase 1 of #2908 (child of #2812).

What

c's api rule counted every column-0 variable declaration as public surface: the third alternative (^type name … =?) accepted anything shaped like two identifiers at column 0, so int shared_region = 1;, PyTypeObject PyDict_Type = {, FILE *out; and Doom's whole boolean nomonsters; block were api hits. The contract (docs/api_rule_contract.md) says api is a declaration that publishes a function or type; a file-scope variable is globals' hit (#2858), and the one-owner corollary collapses the dual to its owner.

The shape is now a function declarator (one to four type words, the name, (; paren allowed on the next line for Doom's K&R layout) plus the type declarations the old shape happened to cover (^typedef, ^struct name {). The bare-prototype alternative it subsumes never excluded static, so static MP_DEFINE_CONST_FUN_OBJ_0(...) had counted as well.

Measured

tests/tools/rule_probe.py api c before/after on both corpora:

corpus before after
language-crucible (32 files) 1141 1040
keyword-rosetta (4 files) 15 13

Nothing gained. Every one of the 103 lost matches was read: file-scope variables (Doom's globals, cpython's PyTypeObject … = { instances, const … [] = { tables), forward declarations (struct lemon;), two prose lines inside a C string literal, one macro (_Py_COMP_DIAG_PUSH), and five static MP_DEFINE_…(…) lines. Every K&R and Doom-style function definition (void\nI_Tactile\n( int on,) still matches — the first candidate lost 21 of those until the paren was allowed after a newline, which is why the pin test covers that layout explicitly.

Corpus

rosetta_audit.py against keyword-rosetta at origin/main: c a.c api 5 → 3; nothing else in any of the 46 languages moves. raw_arch_api for c goes from 3.75 (+25.0%, at the band edge) to the 3.0 median; risk_documentation for c from 48.6 (+24%) to 38.3. Label rosetta:rebless-owed — the corpus PR re-blesses data/c/expected_signals.json (a.c api 3) after this merges.

Golden masters

Both fixtures regenerated with crucible_check.py --update --yes. Scoped with a full golden_diff pass (not the capped window): 260 differences in zero-dep, of which 126 are the topological coordinate re-solve; the remaining 134 are 21 .c/.h files (cpython ×5, doom ×7, micropython ×3, sqlite lemon.c, racket eval.c/fun.c, godot object.h, gnucobol fileio.c, worldwideweb HText.c) each moving on exactly Public Exports / API Exposure / Documentation Exposure / Structural Magnitude, plus the directory-group and global aggregates those roll into. No other language's file moves.

Tests

Cross-repo

Engine merges first. Companion: keyword-rosetta re-bless of data/c (opens after merge; the c api plant is unchanged, only a.c's number).

🤖 Generated with Claude Code

The column-0 declaration shape in c's api rule matched every file-scope
VARIABLE alongside function declarators: `int shared_region = 1;` in the
rosetta corpus read api 5 for three functions (raw_arch_api 3.75 vs median
3.0, +25.0% -- inside the band by zero margin, unledgered, and c's
risk_documentation +24% for the same reason), and 101 of the crucible's
1141 c hits were `PyTypeObject PyDict_Type = {`, `FILE *out;`, Doom's
`boolean nomonsters;` block and the like. The api contract gives those to
`globals` (#2858): api is a declaration that publishes a function or type.

The shape is now a function declarator -- one to four type words, the
name, `(` -- with the paren allowed on the next line for Doom's
`void\nI_Tactile\n( int on,` layout, plus the type declarations the old
shape happened to cover (`typedef ...`, `struct name {`). The
bare-prototype alternative it subsumes never excluded `static`, so
`static MP_DEFINE_CONST_FUN_OBJ_0(...)` had counted too.

Measured with rule_probe on both corpora: crucible 1141 -> 1040, rosetta
15 -> 13, nothing gained; every lost match read one by one is a file-scope
variable, a forward `struct x;`, prose inside a string literal, or a static
macro line. rosetta_audit against the corpus at origin/main: c a.c api
5 -> 3, nothing else moves (label rosetta:rebless-owed). Golden masters
re-blessed in both modes: 21 .c/.h files across cpython, doom, micropython,
sqlite, racket, godot, gnucobol and worldwideweb move on exactly Public
Exports / API Exposure / Documentation Exposure / Structural Magnitude,
their aggregates follow, the rest is the coordinate re-solve.

Phase 1 of #2908.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@squid-protocol squid-protocol added metrics Heuristics, risk exposures, and topological math updates core-engine Modifications to the central physics and parsing engine rosetta:rebless-owed Intentionally moves keyword-rosetta counts; audit warns, corpus re-blesses after merge labels Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit d228e01 into main Sep 9, 2026
70 of 71 checks passed
@squid-protocol
squid-protocol deleted the fix/2907-c-api-variable-declarations branch September 9, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-engine Modifications to the central physics and parsing engine metrics Heuristics, risk exposures, and topological math updates rosetta:rebless-owed Intentionally moves keyword-rosetta counts; audit warns, corpus re-blesses after merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

c api rule counts top-level variable declarations as public surface (a.c reads api 5 for 3 functions; +25.0% sits at the band edge)

1 participant