Skip to content

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) #2907

Closed

Description

@squid-protocol

What

c's api rule counts a non-static top-level variable declaration as public surface. On the keyword-rosetta corpus data/c/a.c records raw_arch_api 5 for three functions: the two globals plants (int shared_region = ..., int shared_home = ...) match the rule's fourth alternative, the generic ^(?!static\b)... <type> <name> ... =? declaration shape, alongside the three function headers.

$ rule_probe api on data/c/a.c
  (5, 'int shared_region ='), (6, 'int shared_home ='), (8, 'int probe_globals'), (12, 'int probe_test'), (18, 'int probe_safety')

main.c reads 4 (entry + 3 probes, correct) and b.c reads 3, so the language's mean is 3.75 against a cross-language median of 3.0: +25.0%, inside the ±25% band by zero margin. No ledger entry names it, and risk_documentation for c sits at +24% for the same reason (a.c scores 68.2 where its siblings score 40.6; see the per-file decomposition on the risk_documentation epic).

Why it is a contract violation

docs/api_rule_contract.md: "api matches a declaration that makes a named function or type visible outside the file." A file-scope variable has external linkage, but it is neither, and the same token is already globals's hit — the count contract's one-owner corollary (#2841 C2, #2852 C2) says a token that two rules claim collapses to its owner. Here the owner is globals.

Fix

Anchor the generic alternative to a function declarator: require ( after the name (<type> <name>(), the way the c func_start rule already does, and keep extern, __declspec(dllexport) and the visibility attribute as they are. Expected corpus effect: a.c api 5 → 3, c mean 3.75 → 3.0, risk_documentation c 48.6 → 38.3 (the median). Check the crucible for header files: extern int x; stays counted by the first alternative, which is the intended public-variable form.

Golden-master diff expected on c-heavy crucible repos (curl, cpython); scope it with bless_scope.py before blessing. Label rosetta:rebless-owed: the corpus c manifest re-blesses api in a.c.

Phase 1 prerequisite of the risk_documentation score-contract epic (child of #2812).

Metadata

Metadata

Assignees

No one assigned

    Labels

    core-engineModifications to the central physics and parsing enginemetricsHeuristics, risk exposures, and topological math updates

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions