- Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang] NFCI: Use FileEntryRef in SourceManager::FileInfos #67742
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
You can test this locally with the following command:git-clang-format --diff 3e9c36303ca72929275fb97767af43b3aa04cab1 9e605fbaeb72f79307316f5408993c04d4400ed1 -- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp clang/include/clang/Basic/FileEntry.h clang/include/clang/Basic/SourceManager.h clang/lib/Basic/SourceManager.cpp clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/unittests/Basic/FileEntryTest.cppView the diff from clang-format here.diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index d6e65966c0ea..7589818b3546 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -649,7 +649,7 @@ class SourceManager : public RefCountedBase<SourceManager> { /// This map allows us to merge ContentCache entries based /// on their FileEntry*. All ContentCache objects will thus have unique, /// non-null, FileEntry pointers. - llvm::DenseMap<FileEntryRef, SrcMgr::ContentCache*> FileInfos; + llvm::DenseMap<FileEntryRef, SrcMgr::ContentCache *> FileInfos; /// True if the ContentCache for files that are overridden by other /// files, should report the original file name. Defaults to true. |
242fa18 to 8570546 Compare
benlangmuir left a comment
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 skeptical that treating FileEntryRef as FileEntry * for the purposes of equality and hashing is a good idea. To me, the obvious interpretation of FileEntryRef == is that the path must be equal, and having it based on the dev/inode is surprising. I know that's not something you're introducing in this PR, but I would prefer we remove that functionality rather than build more on top of it.
Here are some alternative ways we could handle this that I think are more principled:
- We could do
DenseMap<FileEntry *, FileEntryRef>instead of the DenseSet, and similarly embed the FileEntryRef into the RHS type in cases with DenseMap - Alternatively, we could add a wrapper type for FileEntryRef that continues to have the
FileEntry *equality/hashing semantics, but where the name of that wrapper and/or the fact you need to unwrap it explicitly makes it obvious that the semantics are not "just" FileEntryRef. If we can figure out a good name for this I think it would be a good solution.
| I understand your concern, we should definitely look into this. However, I think the inode uniquing functionality is pretty fundamental to But, since we're only 5 more commits away from finally finishing the whole What do you think? |
| For what it's worth, until recently there was almost no use of the implicit unique file semantics for FileEntryRef even though the DenseMapInfo had been available for a long time. But okay, I see there are more uses now so this is not the right place to push back on that. |
benlangmuir left a comment
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.
Comment in the test needs a fix, but otherwise LGTM
| EXPECT_TRUE(Set.find(R2)->isSameRef(R2)); | ||
| } | ||
| | ||
| // Insert R1Also second and confirm R1 "wins" when looked up as FileEntry. |
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.
This comment looks like it's for the other test case. R1Also is inserted first and it wins here.
Reverts : breaks hipify in win build, need combo build 3661a48 [clang] NFCI: Use `FileEntryRef` in `SourceManager::getMemoryBufferForFileOr{None,Fake}()` 2fc90af [lldb] Fix build after 2da8f30 2da8f30 [clang] NFCI: Use `FileEntryRef` in `SourceManager::overrideFileContents()` b0abc9d [clang] NFCI: Use `FileEntryRef` in `ASTReader::GetHeaderFileInfo() 8a2fb13 [clang] NFCI: Use `FileEntryRef` in `SourceManager::FileInfos` (llvm#67742) Change-Id: I38e0934bab24684c2b79c5f113bc00f78258abfd
…ipify 3661a48 [clang] NFCI: Use `FileEntryRef` in `SourceManager::getMemoryBufferForFileOr{None,Fake}()` 2fc90af [lldb] Fix build after 2da8f30 2da8f30 [clang] NFCI: Use `FileEntryRef` in `SourceManager::overrideFileContents()` b0abc9d [clang] NFCI: Use `FileEntryRef` in `ASTReader::GetHeaderFileInfo() 8a2fb13 [clang] NFCI: Use `FileEntryRef` in `SourceManager::FileInfos` (llvm#67742) Change-Id: Iac2cec8b3d43bccc22dd0a62ce7bb8cf721466e6
No description provided.