-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[ClangImporter] Deduplicate clang buffers representing the same file #84904
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
Conversation
|
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very familiar with this logic, but the change seems reasonable!
lib/Basic/SourceLoc.cpp
Outdated
| SourceManager::addNewSourceBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer) { | ||
| assert(Buffer); | ||
| StringRef BufIdentifier = Buffer->getBufferIdentifier(); | ||
| assert(BufIdentIDMap.find(BufIdentifier) == BufIdentIDMap.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| assert(BufIdentIDMap.find(BufIdentifier) == BufIdentIDMap.end()); | |
| CONDITIONAL_ASSERT(BufIdentIDMap.find(BufIdentifier) == BufIdentIDMap.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this assert in the end. It was a bit optimistic, and the complete fix is a bit out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, didn't know that. LGTM.
Clang can end up with multiple file IDs representing the same file, but in different contexts. For example, file in the current module always have file IDs >0, while files in imported modules always have file IDs <-1. As we end up compiling multiple modules, the same file can be seen both as the "current" module, and a transitive import. We don't want multiple Swift buffer IDs for the same file, as it breaks things like -verify that compare buffer IDs. rdar://162661286
c3fc710 to
696c08e
Compare
|
Removed the assert I added in |
|
@swift-ci please smoke test |
Virtual files from different modules can differ despite having identical names (e.g. `<module-imports>`. This fixes some diagnostics related test failures when these virtual files were (incorrectly) deduplicated and the module imports from a previous module were shown, by checking if the buffer has a corresponding clang::FileEntry.
|
@swift-ci please smoke test |
This would trigger when path prefixes are remapped, as the buffer identifier is the remapped path, not the path on the file system. There is no easy way to recover the original path, so drop the assert.
|
@swift-ci please smoke test |
|
@swift-ci please test macos platform |
Clang can end up with multiple file IDs representing the same file, but in different contexts. For example, files in the current module always have file IDs >0, while files in imported modules always have file IDs <-1. As we end up compiling multiple modules, the same file can be seen both as the "current" module, and a transitive import. We don't want multiple Swift buffer IDs for the same file, as it breaks things like -verify that compare buffer IDs.
rdar://162661286