@@ -125,7 +125,79 @@ void cbm_reset_profile(void) {
125125 } \
126126 } while (0)
127127
128+ /* A definition name never spans lines. Config extractors hand over a node's
129+ * whole text — a YAML block key, a Makefile recipe (`endif\n\n$(obj)/x.h`), a
130+ * ktest .conf directive — and the line break rode into the graph (2026-09-16
131+ * probe: 8,301 Field nodes on elastic/elasticsearch, 91 kernel nodes). Cut at
132+ * the first line break and drop trailing blanks; the qualified name carries
133+ * the same text as its last segment and is cut the same way. */
134+ static const char * cbm_first_line (CBMArena * a , const char * text ) {
135+ if (!text ) {
136+ return text ;
137+ }
138+ const char * nl = strpbrk (text , "\r\n" );
139+ if (!nl ) {
140+ return text ;
141+ }
142+ size_t n = (size_t )(nl - text );
143+ while (n > 0 && (text [n - 1 ] == ' ' || text [n - 1 ] == '\t' )) {
144+ n -- ;
145+ }
146+ char * cut = (char * )cbm_arena_alloc (a , n + 1 );
147+ if (!cut ) {
148+ return text ;
149+ }
150+ memcpy (cut , text , n );
151+ cut [n ] = '\0' ;
152+ return cut ;
153+ }
154+
155+ /* JS/TS files: a definition named by a literal token is the walker naming a
156+ * function or variable from an object key or a numeric pattern element —
157+ * `{}` (1,534 incoming CALLS on microsoft/TypeScript's test baselines), `1`
158+ * (38 nodes), a quoted string. An identifier starts with a letter, `_`, `$`,
159+ * `#` (private members) or a non-ASCII byte; anything else is not a name. */
160+ static bool cbm_js_family_path (const char * path ) {
161+ if (!path ) {
162+ return false;
163+ }
164+ const char * dot = strrchr (path , '.' );
165+ if (!dot ) {
166+ return false;
167+ }
168+ static const char * const exts [] = {".js" , ".mjs" , ".cjs" , ".jsx" , ".ts" ,
169+ ".mts" , ".cts" , ".tsx" , ".ets" , NULL };
170+ for (int i = 0 ; exts [i ]; i ++ ) {
171+ if (strcmp (dot , exts [i ]) == 0 ) {
172+ return true;
173+ }
174+ }
175+ return false;
176+ }
177+
178+ static bool cbm_js_name_is_junk (const char * name ) {
179+ if (!name || !name [0 ]) {
180+ return false; /* empty names are handled by the callers' own rules */
181+ }
182+ unsigned char c = (unsigned char )name [0 ];
183+ bool identifier_start = (c >= 'A' && c <= 'Z' ) || (c >= 'a' && c <= 'z' ) || c == '_' ||
184+ c == '$' || c == '#' || c >= 0x80 ;
185+ /* Member names JS spells without an identifier start are still names:
186+ * computed keys (`[Symbol.iterator]`), string-literal keys (`"my-key"`,
187+ * `'x'`) and escaped identifiers (`А`). Measured on the TypeScript
188+ * corpus: 1,531 `[…]` members, 97 quoted members, 154 escaped
189+ * identifiers — all real definitions. What remains ({…} patterns, numeric
190+ * literals, parenthesised types, `...rest`) is a token, not a name. */
191+ bool member_key_start = c == '[' || c == '"' || c == '\'' || c == '\\' ;
192+ return !identifier_start && !member_key_start ;
193+ }
194+
128195void cbm_defs_push (CBMDefArray * arr , CBMArena * a , CBMDefinition def ) {
196+ def .name = cbm_first_line (a , def .name );
197+ def .qualified_name = cbm_first_line (a , def .qualified_name );
198+ if (cbm_js_family_path (def .file_path ) && cbm_js_name_is_junk (def .name )) {
199+ return ;
200+ }
129201 GROW_ARRAY (arr , a );
130202 arr -> items [arr -> count ++ ] = def ;
131203}
@@ -1358,14 +1430,89 @@ static void cbm_mark_pp_error_rows(TSNode n, uint8_t *rows, uint32_t row_count,
13581430/* Recovery subtraction (#963): tree-sitter error recovery plus the
13591431 * ERROR-descending def walker often still extract constructs INSIDE a failed
13601432 * region (verified: a function in an #ifdef-split ERROR region and even a
1361- * `def broken(:` both came back as defs). A region whose every line is
1362- * covered by definitions that START inside it is definitely recovered — its
1363- * constructs ARE in the graph — so flagging it would be a false miss.
1364- * Container defs (Module/Package) are ignored: a file-spanning Module node is
1365- * not evidence the region's constructs survived. Conservative: partially
1366- * covered regions stay flagged. */
1367- static bool cbm_region_is_recovered (uint32_t rs , uint32_t re , const CBMDefArray * defs ) {
1368- enum { MAX_COVER_DEFS = 256 };
1433+ * `def broken(:` both came back as defs). The lines a definition that STARTS
1434+ * inside the region covers are therefore in the graph, and only the lines no
1435+ * definition covers can honestly be called missed. Container defs
1436+ * (Module/Package) are ignored: a file-spanning Module node is not evidence
1437+ * the region's constructs survived.
1438+ *
1439+ * This used to be all-or-nothing — a region stayed flagged whole unless every
1440+ * line was covered. On torvalds/linux (2026-09-16 probe) one ERROR node that
1441+ * swallowed the second half of kernel/sched/core.c (lines 5522–11284) survived
1442+ * because of the comment and macro lines between its 286 extracted functions,
1443+ * and the coverage report told a reader 68 % of the scheduler was unindexed.
1444+ * Now the uncovered gaps are reported instead, and a gap holding only blank,
1445+ * comment or preprocessor lines is not a miss at all. */
1446+ static uint32_t * cbm_line_offsets (const char * src , int src_len , uint32_t * out_lines ) {
1447+ uint32_t lines = 1 ;
1448+ for (int i = 0 ; i < src_len ; i ++ ) {
1449+ if (src [i ] == '\n' ) {
1450+ lines ++ ;
1451+ }
1452+ }
1453+ uint32_t * offs =
1454+ (uint32_t * )cbm_alloc (CBM_MEM_CLASS_EXTRACT , (size_t )(lines + 1 ) * sizeof (uint32_t ));
1455+ if (!offs ) {
1456+ * out_lines = 0 ;
1457+ return NULL ;
1458+ }
1459+ uint32_t n = 0 ;
1460+ offs [n ++ ] = 0 ;
1461+ for (int i = 0 ; i < src_len && n < lines ; i ++ ) {
1462+ if (src [i ] == '\n' ) {
1463+ offs [n ++ ] = (uint32_t )i + 1 ;
1464+ }
1465+ }
1466+ offs [n ] = (uint32_t )src_len ;
1467+ * out_lines = n ;
1468+ return offs ;
1469+ }
1470+
1471+ /* A 1-based line that holds nothing a reader would call missed code: blank,
1472+ * a comment line, or a preprocessor directive (the import pass owns #include;
1473+ * #if/#endif carry no construct of their own). */
1474+ static bool cbm_line_is_inert (const char * src , const uint32_t * offs , uint32_t nlines ,
1475+ uint32_t line ) {
1476+ if (!src || !offs || line == 0 || line > nlines ) {
1477+ return true;
1478+ }
1479+ const char * p = src + offs [line - 1 ];
1480+ const char * end = src + offs [line ];
1481+ while (p < end && (* p == ' ' || * p == '\t' || * p == '\r' )) {
1482+ p ++ ;
1483+ }
1484+ if (p >= end || * p == '\n' ) {
1485+ return true;
1486+ }
1487+ if (p [0 ] == '/' && p + 1 < end && (p [1 ] == '/' || p [1 ] == '*' )) {
1488+ return true;
1489+ }
1490+ return p [0 ] == '*' || p [0 ] == '#' ;
1491+ }
1492+
1493+ static void cbm_regions_emit_gap (cbm_error_regions_t * out , uint32_t gs , uint32_t ge ,
1494+ const char * src , const uint32_t * offs , uint32_t nlines ) {
1495+ bool live = false;
1496+ for (uint32_t l = gs ; l <= ge && !live ; l ++ ) {
1497+ live = !cbm_line_is_inert (src , offs , nlines , l );
1498+ }
1499+ if (!live ) {
1500+ return ;
1501+ }
1502+ if (out -> count < CBM_MAX_ERROR_REGIONS ) {
1503+ out -> starts [out -> count ] = gs ;
1504+ out -> ends [out -> count ] = ge ;
1505+ out -> count ++ ;
1506+ } else {
1507+ out -> dropped ++ ;
1508+ }
1509+ }
1510+
1511+ /* Replace [rs, re] by the sub-ranges no in-region definition covers. */
1512+ static void cbm_region_uncovered_gaps (uint32_t rs , uint32_t re , const CBMDefArray * defs ,
1513+ const char * src , const uint32_t * offs , uint32_t nlines ,
1514+ cbm_error_regions_t * out ) {
1515+ enum { MAX_COVER_DEFS = 1024 };
13691516 uint32_t starts [MAX_COVER_DEFS ];
13701517 uint32_t ends [MAX_COVER_DEFS ];
13711518 int n = 0 ;
@@ -1377,14 +1524,25 @@ static bool cbm_region_is_recovered(uint32_t rs, uint32_t re, const CBMDefArray
13771524 if (d -> start_line < rs || d -> start_line > re ) {
13781525 continue ; /* recovery evidence must originate inside the region */
13791526 }
1527+ /* A one-line definition salvaged from inside an error region is the
1528+ * walker's guess at broken text (`def x(:` comes back as a def, a
1529+ * mis-parsed `static _Thread_local int x` as a Variable named `int`,
1530+ * and Python's synthetic builtins all sit on line 1); only a construct
1531+ * whose body spans lines proves it was understood. Conservative: real
1532+ * one-line variables and macros inside a failed region keep their line
1533+ * flagged. */
1534+ if (d -> end_line <= d -> start_line ) {
1535+ continue ;
1536+ }
13801537 starts [n ] = d -> start_line ;
1381- ends [n ] = d -> end_line < d -> start_line ? d -> start_line : d -> end_line ;
1538+ ends [n ] = d -> end_line ;
13821539 n ++ ;
13831540 }
13841541 if (n == 0 ) {
1385- return false;
1542+ cbm_regions_emit_gap (out , rs , re , src , offs , nlines );
1543+ return ;
13861544 }
1387- /* Insertion-sort by start, then sweep for gaps in [rs, re]. */
1545+ /* Insertion-sort by start, then sweep and emit the gaps in [rs, re]. */
13881546 for (int i = 1 ; i < n ; i ++ ) {
13891547 uint32_t s = starts [i ];
13901548 uint32_t e = ends [i ];
@@ -1397,16 +1555,18 @@ static bool cbm_region_is_recovered(uint32_t rs, uint32_t re, const CBMDefArray
13971555 starts [j + 1 ] = s ;
13981556 ends [j + 1 ] = e ;
13991557 }
1400- uint32_t covered_to = rs - 1 ;
1558+ uint32_t cursor = rs ;
14011559 for (int i = 0 ; i < n ; i ++ ) {
1402- if (starts [i ] > covered_to + 1 ) {
1403- return false; /* uncovered gap */
1560+ if (starts [i ] > cursor ) {
1561+ cbm_regions_emit_gap ( out , cursor , starts [ i ] - 1 , src , offs , nlines );
14041562 }
1405- if (ends [i ] > covered_to ) {
1406- covered_to = ends [i ];
1563+ if (ends [i ] + 1 > cursor ) {
1564+ cursor = ends [i ] + 1 ;
14071565 }
14081566 }
1409- return covered_to >= re ;
1567+ if (cursor <= re ) {
1568+ cbm_regions_emit_gap (out , cursor , re , src , offs , nlines );
1569+ }
14101570}
14111571
14121572/* #961: true when 1-based `line` of `src` contains `name` (used to verify a
@@ -1598,16 +1758,19 @@ static bool cbm_remap_preprocessed_def(CBMDefinition *def, const CBMPreprocessed
15981758 return true;
15991759}
16001760
1601- static void cbm_subtract_recovered_regions (cbm_error_regions_t * regs , const CBMDefArray * defs ) {
1602- int kept = 0 ;
1761+ static void cbm_subtract_recovered_regions (cbm_error_regions_t * regs , const CBMDefArray * defs ,
1762+ const char * src , int src_len ) {
1763+ if (regs -> count <= 0 ) {
1764+ return ;
1765+ }
1766+ uint32_t nlines = 0 ;
1767+ uint32_t * offs = cbm_line_offsets (src , src_len , & nlines );
1768+ cbm_error_regions_t out = {{0 }, {0 }, 0 , regs -> dropped };
16031769 for (int i = 0 ; i < regs -> count ; i ++ ) {
1604- if (!cbm_region_is_recovered (regs -> starts [i ], regs -> ends [i ], defs )) {
1605- regs -> starts [kept ] = regs -> starts [i ];
1606- regs -> ends [kept ] = regs -> ends [i ];
1607- kept ++ ;
1608- }
1770+ cbm_region_uncovered_gaps (regs -> starts [i ], regs -> ends [i ], defs , src , offs , nlines , & out );
16091771 }
1610- regs -> count = kept ;
1772+ cbm_free (CBM_MEM_CLASS_EXTRACT , offs );
1773+ * regs = out ;
16111774}
16121775
16131776/* #1071: a function-like macro invocation whose argument is a type token
@@ -2019,6 +2182,9 @@ static CBMFileResult *extract_file_ex_body(const char *source, int source_len, C
20192182
20202183 TSTree * tree = ts_parser_parse_with_options (parser , NULL , ts_input , opts );
20212184 uint64_t t1 = now_ns ();
2185+ #ifdef CBM_ENABLE_TEST_SEAMS
2186+ t1 += tl_parse_wall_seam_offset_ns ; /* the stall seam inflates every wall reading */
2187+ #endif
20222188
20232189 if (!tree ) {
20242190 result -> has_error = true;
@@ -2669,7 +2835,7 @@ static CBMFileResult *extract_file_ex_body(const char *source, int source_len, C
26692835 * splitting a brace inside a recovered function looks unrecovered:
26702836 * the refinement keeps only the discarded branch, the function starts
26712837 * above it, and the evidence falls outside the range. */
2672- cbm_subtract_recovered_regions (& regs , & result -> defs );
2838+ cbm_subtract_recovered_regions (& regs , & result -> defs , source , source_len );
26732839 /* Phase 2: cut what is left down to the lines the preprocessed parse
26742840 * could not explain. */
26752841 if (pp_line_map ) {
0 commit comments