Skip to content

Parse src.cpp rules at build time#61

Open
lucic71 wants to merge 11 commits intoCpp2Rust:masterfrom
lucic71:rule-loading
Open

Parse src.cpp rules at build time#61
lucic71 wants to merge 11 commits intoCpp2Rust:masterfrom
lucic71:rule-loading

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented May 4, 2026

Fixes #55

Each src.cpp from the rules/ dir is now parsed at build time, instead of on every invocation of cpp2rust. This gives a 5-8x speedup in running the unit tests in the Github runner. Translating a simple unit test like assert.cpp went down form 6 seconds to 0.1 seconds.

The new cpp-rule-preprocessor binary from cpp2rust/ is responsible for parsing one src.cpp at a time and to generate a ir_src.json in the same dir as the src.cpp file. The format of the json file is: f<n> / t<n>: { "to_string": <Mapper::ToString> }.

All src.cpp files are parsed in parallel, CMakeLists takes care of that. The check-rules target is now responsible for parsing the Rust rules and the C++ rules. The IR for src.cpp is not indexed in git. The IR for the Rust rules remains unchanged.

I ported the clang AST matcher form translation_rule.cpp into the new file rule_src_parser.cpp. As a result, translation_rule.cpp is only responsible for loading IR JSONs.

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.

Parsing rules's source (C++) is the bottleneck

1 participant