Repository navigation
Description
What
Found while investigating #1266 (scala/matlab/haskell func_start recall). prism.py's
_strip_nested_comments -- the file-level comment/code splitter used for every language in the
recursive_block (scala, rust, swift), recursive_block_haskell (haskell), and
recursive_block_lisp (scheme) lexical families -- shields string/char literals with the shared
LITERAL_MASK_PATTERN before stripping comments, using an unbounded single-quote branch:
'(?:\\.|[^'\\])*'.
Every language routed through this function has a common source of unpaired single quotes that
are not real char literals:
- An English contraction inside a
///--/;comment (it's,don't,wasn't) - Scala Symbol literals (
'foo, no closing quote) - Haskell's idiomatic trailing-apostrophe identifiers (
x',map') - Scheme's pervasive quote syntax (
'expr)
Any of these pairs up with the next, completely unrelated, single quote anywhere later in the
file, masking everything in between as one giant fake "string" -- silently hiding real functions
(and sometimes losing them to the comment stream entirely, if the masked span lands back-to-back
with a //-style marker on the same physical line) from func_start before it ever runs.
Evidence (real corpus files, language-crucible)
code_stream length as a percentage of the original file, before the fix:
| File | Language | Original | code_stream | % kept |
|---|---|---|---|---|
kafka/ReplicaManager.scala |
scala | 134,357 | 18,479 | 13.75% |
kafka/KafkaApis.scala |
scala | 215,827 | 60,169 | 27.88% |
pandoc/Class.hs |
haskell | 1,184 | 498 | 42.06% |
pandoc/Pandoc.hs |
haskell | 2,564 | 1,216 | 47.43% |
alamofire/Session.swift |
swift | 85,179 | 9,419 | 11.06% |
holylang/semantic.rs* |
rust | -- | -- | (rust also affected, see below) |
This directly explains the bulk of #1266's reported scala recall gap: GitGalaxy's own
tree_sitter_accuracy_audit.py --lang scala measured found_functions at 205/499 (41%) against
the committed baseline. With only this fix applied (no regex changes at all), it jumps to
389/499 (78%).
Root cause (same bug class as #1184/#1192/#1222, missed here)
_strip_nested_comments runs string-shielding and single-line-comment-stripping as two
sequential passes instead of one atomic pass. #1192 fixed this exact ordering bug for
detector.py's Mode C/D/E shields, and #1222 fixed it for prism.py's own generic REGEX_MATRIX
stripper (the standard_block family: java/c/js/etc.) -- but _strip_nested_comments (a
different code path, used only by the three recursive_block* families) was never touched by
either fix.
Fix
Bound the single-quote branch's width to a small number of characters, mirroring the
already-shipped fix for Rust's lifetime-annotation 'a in detector.py's
_build_brace_safe_stream ({0,10}, gated to lang_id == "rust" there). Real char literals in
every language reaching this function are at most a few characters ('a', '\n', 'A'),
so a short bound can't break a legitimate one while making the unbounded cascade structurally
impossible. Applied locally within _strip_nested_comments (not the shared
LITERAL_MASK_PATTERN config, to keep the fix scoped to the affected code path).
Blast radius
Affects scala, rust, swift (recursive_block), haskell (recursive_block_haskell), and scheme
(recursive_block_lisp) -- confirmed via direct code_stream-size measurement on real corpus
files in language-crucible for all five. Fix verified to substantially improve code_stream
retention across all of them; full tree_sitter_accuracy_audit.py/crucible_check.py
re-verification to follow in the fix PR.
Related: #1266 (scala/matlab/haskell func_start broadening -- this bug was discovered while
investigating scala's reported recall gap there).
Activity
fix(core): broaden scala/matlab/haskell func_start recall -- closes #…
fix(tests): fix rust/swift tree-sitter ground-truth gaps behind #1311'…
fix(core): bound prism.py's unbounded single-quote shield -- closes s…
fix(prism,detector): widen C++ char-literal bound to cover named escapes
fix(prism): stop treating C++ digit separators as char-literal openers (
fix(detector): shield yaml block-scalar content in the indentation sl…