Skip to content

Skip parsing non-templated dependency function bodies in rs_bindings_from_cc. - #3280

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1035182488
Open

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1035182488

Conversation

@copybara-service

Copy link
Copy Markdown

Skip parsing non-templated dependency function bodies in rs_bindings_from_cc.

Header analysis spends much of its time parsing and instantiating inline function bodies from dependency headers that it never uses. This matters most for targets that parse their dependencies from source instead of loading header modules: profiles showed 43% to 59% of CPU time in Parser::ParseFunctionStatementBody and Sema::PerformPendingInstantiations on such bodies.

Enable FrontendOptions::SkipFunctionBodies and override AstConsumer::shouldSkipFunctionBody to skip only non-templated, non-dependent function definitions that the importer doesn't treat as part of the current target. Bodies stay parsed for current-target functions (needed by GetMemberFuncSemantic, --carcinize, and diagnostics), for members of full class template specializations (which the importer attributes to the current target wherever they are written), and for templated and dependent functions (needed for template validation and std::make_unique lifetimebound inference). Clang's Sema::canSkipFunctionBody already keeps constexpr, consteval, and deduced-return bodies.

To keep the filter and the importer in agreement, move the importer's ownership rules into the free functions GetOwningTarget and GetOwningTargetOfLocation, which both use.

Add the kill switch --//third_party/crubit/rs_bindings_from_cc/bazel_support:skip_dependency_function_bodies=false (tool flag --skip_dependency_function_bodies, default true). The aspect only passes the tool flag when it is false, because older rs_bindings_from_cc binaries reject unknown flags.

…from_cc.

Header analysis spends much of its time parsing and instantiating inline function bodies from dependency headers that it never uses. This matters most for targets that parse their dependencies from source instead of loading header modules: profiles showed 43% to 59% of CPU time in `Parser::ParseFunctionStatementBody` and `Sema::PerformPendingInstantiations` on such bodies.

Enable `FrontendOptions::SkipFunctionBodies` and override `AstConsumer::shouldSkipFunctionBody` to skip only non-templated, non-dependent function definitions that the importer doesn't treat as part of the current target. Bodies stay parsed for current-target functions (needed by `GetMemberFuncSemantic`, `--carcinize`, and diagnostics), for members of full class template specializations (which the importer attributes to the current target wherever they are written), and for templated and dependent functions (needed for template validation and `std::make_unique` `lifetimebound` inference). Clang's `Sema::canSkipFunctionBody` already keeps `constexpr`, `consteval`, and deduced-return bodies.

To keep the filter and the importer in agreement, move the importer's ownership rules into the free functions `GetOwningTarget` and `GetOwningTargetOfLocation`, which both use.

Add the kill switch `--//third_party/crubit/rs_bindings_from_cc/bazel_support:skip_dependency_function_bodies=false` (tool flag `--skip_dependency_function_bodies`, default true). The aspect only passes the tool flag when it is false, because older `rs_bindings_from_cc` binaries reject unknown flags.

PiperOrigin-RevId: 1035182488

This branch has not been deployed

No deployments
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.

1 participant