Repository navigation
c api: a file-scope variable is globals' hit, not public surface (#2907) - #2911
Merged
Merged
Conversation
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]>
7 of 11 tasks
Contributor
Closed
13 of 24 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2907. Phase 1 of #2908 (child of #2812).
What
c's
apirule counted every column-0 variable declaration as public surface: the third alternative (^type name … =?) accepted anything shaped like two identifiers at column 0, soint shared_region = 1;,PyTypeObject PyDict_Type = {,FILE *out;and Doom's wholeboolean 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 isglobals' 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 excludedstatic, sostatic MP_DEFINE_CONST_FUN_OBJ_0(...)had counted as well.Measured
tests/tools/rule_probe.py api cbefore/after on both corpora: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 fivestatic 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.pyagainst keyword-rosetta at origin/main: ca.capi 5 → 3; nothing else in any of the 46 languages moves.raw_arch_apifor c goes from 3.75 (+25.0%, at the band edge) to the 3.0 median;risk_documentationfor c from 48.6 (+24%) to 38.3. Labelrosetta:rebless-owed— the corpus PR re-blessesdata/c/expected_signals.json(a.capi 3) after this merges.Golden masters
Both fixtures regenerated with
crucible_check.py --update --yes. Scoped with a fullgolden_diffpass (not the capped window): 260 differences in zero-dep, of which 126 are the topological coordinate re-solve; the remaining 134 are 21.c/.hfiles (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
test_c_api_variable_declarations_are_globals_not_api_2907intests/extraction/languages/test_c_strict.py: eight variable/forward/static shapes must not match, seven declarator layouts and four type declarations must, the The api rule has no stated contract: 7 languages' own visibility idiom is invisible to it, and 5 others count anypublictoken #2730 body-local guard holds, two ReDoS detonations on the bounded{1,4}type-word run.test_c_strict.py91 passed;test_c.py+test_detector.py+test_language_standards_strict.py+signal_contract_audit.py249 passed (run as barepytestfrom an unrelated cwd).audit_check.py: all clear.Cross-repo
Engine merges first. Companion: keyword-rosetta re-bless of
data/c(opens after merge; the c api plant is unchanged, onlya.c's number).🤖 Generated with Claude Code