Skip to content

[clang][modules] Do not resolve HeaderFileInfo externally in ASTWriter #8567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2024

Conversation

jansvoboda11
Copy link

Cherry-pick of llvm#87848 and llvm#88446

Explanation: When writing out a PCM file, Clang doesn't need to deserialize header file info from loaded PCM files since we're only writing headers the current compilation already knows about.

Risk: Low. This is supposed to be a non-functional change.

Testing: Existing test suite coverage exercises the relevant code-paths affected by this change.

Reviewed By: @benlangmuir

…iter` (llvm#87848)

Clang uses the `HeaderFileInfo` struct to track bits of information on
header files, which gets used throughout the compiler. We also use this
to compute the set of affecting module maps in `ASTWriter` and in the
end serialize the information into the `HEADER_SEARCH_TABLE` record of a
PCM file, allowing clients to learn about headers from the module. In
doing so, Clang asks for existing `HeaderFileInfo` for all known
`FileEntries`. Note that this asks the loaded PCM files for the
information they have on each header file in question. This seems
unnecessary: we only want to serialize information on header files that
either belong to the current module or that got included textually.
Loaded PCM files can't provide us with any useful information.

For explicit modules with lazy loading (using `-fmodule-map-file=<path>`
with `-fmodule-file=<name>=<path>`) the compiler knows about header
files listed in the module map files on the command-line. This can be a
large number.

Asking for existing `HeaderFileInfo` can trigger deserialization of
`HEADER_SEARCH_TABLE` from loaded PCM files. Keys of the on-disk hash
table consist of the header file size and modification time. However,
with explicit modules Clang zeroes out the modification time. Moreover,
if you import lots of modules, some of their header files end up having
identical sizes. This means lots of hash collisions that can only be
resolved by running the serialized filename through `FileManager` and
comparing equality of the `FileEntry`. This ends up being super
expensive, essentially re-stating lots of the transitively loaded SDK
header files.

This patch cleans up the API for getting `HeaderFileInfo` and makes sure
`ASTWriter` uses the version that doesn't ask loaded PCM files for more
information. This removes the excessive stat traffic coming from
`ASTWriter` hopefully without changing observable behavior.

(cherry picked from commit 84df7a0)
The `FileEntry` corresponds to a `FileID` containing the
`SourceLocation` of a `NamedDecl` which (I think) might've been
deserialized from a PCM file. Considering external `HeaderFileInfo` here
is most likely the right thing to do here in order to get the correct
spelling in case the current compiler instance has not register this
file as a header yet.

(cherry picked from commit 95fbd8d)
@jansvoboda11 jansvoboda11 requested a review from artemcm April 12, 2024 19:05
@jansvoboda11
Copy link
Author

@swift-ci please test

@jansvoboda11 jansvoboda11 changed the title [clang][modules] Do not resolve HeaderFileInfo externally in ASTWriter [clang][modules] Do not resolve HeaderFileInfo externally in ASTWriter Apr 12, 2024
@artemcm artemcm requested a review from nkcsgexi April 12, 2024 19:31
@nkcsgexi nkcsgexi merged commit c5ac128 into swift/release/6.0 Apr 15, 2024
3 checks passed
@jansvoboda11 jansvoboda11 deleted the jan_svoboda/astwriter-hfi branch April 24, 2024 00:00
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.

3 participants