Skip to content

Prefilter plain C headers before C++ parsing - #876

Open
yzxcj797 wants to merge 1 commit into
tirth8205:mainfrom
yzxcj797:fix/802-cpp-parse-prefilter
Open

Prefilter plain C headers before C++ parsing#876
yzxcj797 wants to merge 1 commit into
tirth8205:mainfrom
yzxcj797:fix/802-cpp-parse-prefilter

Conversation

@yzxcj797

Copy link
Copy Markdown
Contributor

Summary

Header promotion introduced two throughput costs for plain C repositories:

  • every .h file paid a speculative tree-sitter-cpp parse;
  • every C++ file paid the per-byte Qt macro masking walk even when no Qt macros existed.

This change adds cheap source-level prefilters:

  • .h files are only speculatively parsed as C++ when they contain textual evidence such as class, namespace, template, ::, constexpr, noexcept, or a trailing return arrow;
  • Qt macro masking returns immediately when the source contains neither Q_ nor QT_.

Qt/C++ behavior is unchanged when those signals are present.

Fixes #802.

Testing

  • Added a plain C header regression that fails if the C++ parser is probed.
  • Added a C++ header regression confirming speculative promotion still happens.
  • Added a direct Qt-mask fast-path regression.
  • Existing Qt header behavior remains covered.
  • pytest tests/test_pr802_cpp_prefilter.py tests/test_cpp_qt_headers.py -q — 17 passed
  • ruff check on changed files — passes
  • git diff --check — passes

@github-actions

Copy link
Copy Markdown

code-review-graph review

Overall risk: 0.40 (MEDIUM) — 8 changed function(s)/class(es), 0 affected flow(s), 2 test gap(s)

Risk-scored changes

Risk Level Symbol Location Tested
0.40 medium code_review_graph/parser.py::CodeParser._mask_cpp_qt_macros code_review_graph/parser.py:2839 yes
0.35 low code_review_graph/parser.py::CodeParser._has_cpp_header_text_evidence code_review_graph/parser.py:2828 no
0.30 low code_review_graph/parser.py::CodeParser code_review_graph/parser.py:2405 yes
0.30 low code_review_graph/parser.py::CodeParser.parse_bytes code_review_graph/parser.py:2600 yes
0.30 low tests/test_pr802_cpp_prefilter.py::guarded_parser tests/test_pr802_cpp_prefilter.py:13 no
0.20 low tests/test_pr802_cpp_prefilter.py::test_qt_mask_skips_sources_without_structural_macros tests/test_pr802_cpp_prefilter.py:33 (test)
0.05 low tests/test_pr802_cpp_prefilter.py::test_plain_c_header_skips_speculative_cpp_parser tests/test_pr802_cpp_prefilter.py:8 (test)
0.05 low tests/test_pr802_cpp_prefilter.py::test_cpp_header_still_uses_speculative_parser tests/test_pr802_cpp_prefilter.py:25 (test)

Test gaps

  • code_review_graph/parser.py::CodeParser._has_cpp_header_text_evidence (code_review_graph/parser.py:2828)
  • tests/test_pr802_cpp_prefilter.py::guarded_parser (tests/test_pr802_cpp_prefilter.py:13)

Token savings: this graph-backed report used ~162,901 fewer tokens (~99%) than reading every changed file in full (estimated, chars/4 approximation).


Powered by code-review-graph — local-first analysis; no code leaves the CI runner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C/C++ parse throughput regression from header promotion and Qt masking (follow-up to #775)

1 participant