Repository navigation
[clang] option to leave out exported function bodies by path - #2344
Open
VladimirMakaev wants to merge 1 commit into
Open
VladimirMakaev wants to merge 1 commit into
VladimirMakaev wants to merge 1 commit into
Conversation
Contributor
|
Can the description be more clear about what this enables? Again, do we have any perf/memory win? |
Generated headers can dominate the serialized AST when their function bodies will not be translated. Add an optional SKIP_BODIES_PATH_REGEX filter that retains declarations while omitting matching header bodies. Empty or invalid expressions preserve export. Bodies physically written in the main file remain protected, including #line remapping and header macro expansions. The option is unset by default, and Infer does not enable it. Explicit activation can remove needed definitions, so callers must validate their chosen paths. ## Test plan 73 direct tests and the annotation target pass without regeneration. The native JSON fixture passes. Paired base/candidate output is identical with the option unset, empty or invalid; header and broad filters preserve both main-file bodies.
VladimirMakaev
force-pushed
the
pr/skip-bodies-1201
branch
from
December 2, 2026 12:26
1e8a046 to
400c28e
Compare
Contributor
Author
|
Thanks, I've updated the PR description to cover both questions. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this enables
Infer's clang frontend serializes the AST of a translation unit, including the bodies of every
function defined in the headers it pulls in. When a build includes large generated or vendored
headers whose functions will never be analyzed, those bodies are most of the serialized AST, and
the capture pays for them in time, memory and output size.
SKIP_BODIES_PATH_REGEXlets the caller name those files by path. A function defined in amatching file is still exported, with its name, signature, attributes and source location; only
its body is left out, so it is exported exactly as if it had been declared and not defined.
The option is for the caller who already knows which headers are irrelevant to the analysis they
are running: a build where generated protocol or serialization headers are included everywhere, a
vendored library analyzed separately, or a bisection that only needs one directory's code. Infer
does not set it, and nothing in the default pipeline changes.
Usage
It is a plugin argument, unset by default:
The expression is matched against the normalized path recorded in the AST for the location where
the function is defined.
What changes, and what does not
Changed: the body of a function whose definition is in a file matching the regex.
Not changed:
including when a
#linedirective gives them a different presumed name and when they arrivethrough a macro expanded from a header.
expression exports every body, which is the safe direction.
untouched.
Measured effect
One header-heavy translation unit,
facebook-clang-plugins/libtooling/ASTExporter.cpp, compiledagainst the bundled clang headers with the plugin attached as Infer attaches it, with the regex
naming the clang include directory. Seven runs per arm, the two arms interleaved; same binary,
same input, same flags, the option the only difference. Median [min..max]:
The two arms do not overlap on any of the three measures. With
-fsyntax-only, which drops codegeneration and leaves the frontend and the export, the same comparison gives -10.6% wall time,
-7.7% peak RSS and the same -26.0% of AST bytes.
The saving scales with how much of the translation unit is bodies in matching files, so it says
more about the shape of the input than about the option: a unit dominated by generated headers
should do better than this one, and a unit whose code is all in the main file gains nothing.
Setting the option but giving it a regex that matches nothing, or an invalid one, produces
byte-identical output to leaving it unset and costs no measurable time (+0.6% and +1.8% of median
wall time, both inside the run-to-run spread). Enabling the feature is not itself a cost; skipping
bodies is where the win comes from.
Limitations
Skipping a body the analysis needed removes that definition from the analysis, so a caller must
validate the paths they choose; this is why the option is off by default and why Infer does not
set it.
On preprocessed input (
.i) every body is physically written in the file being compiled, so themain-file protection covers all of them and
SKIP_BODIES_PATH_REGEXskips nothing there,including when the regex names the
.ifile itself.Test plan
73 direct tests and the annotation target pass without regeneration. The native JSON fixture
passes. Paired base/candidate output is identical with the option unset, empty or invalid; header
and broad filters preserve both main-file bodies.