[clang-tools-extra] [clang] [clang] NFC: Remove `OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr` (PR #74900)

2023-12-08 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 closed 
https://github.com/llvm/llvm-project/pull/74900
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [clang] NFC: Remove `OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr` (PR #74900)

2023-12-08 Thread Ben Langmuir via cfe-commits

https://github.com/benlangmuir approved this pull request.

Nice simplification

https://github.com/llvm/llvm-project/pull/74900
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [clang] NFC: Remove `OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr` (PR #74900)

2023-12-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Jan Svoboda (jansvoboda11)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/74900.diff


7 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clangd/IncludeCleaner.cpp (+4-4) 
- (modified) clang-tools-extra/include-cleaner/lib/Analysis.cpp (+3-3) 
- (modified) clang/include/clang/Basic/DirectoryEntry.h (-74) 
- (modified) clang/include/clang/Basic/Module.h (+1-1) 
- (modified) clang/include/clang/Lex/ModuleMap.h (+5-9) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+1-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index e336ba1ee1fa72..5ae6caedb7f4c0 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -124,7 +124,7 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult ) {
 MainFileDecls.push_back(D);
   }
   llvm::DenseSet SeenSymbols;
-  const DirectoryEntry *ResourceDir =
+  OptionalDirectoryEntryRef ResourceDir =
   PP->getHeaderSearchInfo().getModuleMap().getBuiltinDir();
   // FIXME: Find a way to have less code duplication between include-cleaner
   // analysis implementation and the below code.
diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index b0a3c290bad660..dda7c9f581f69c 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -397,10 +397,10 @@ IncludeCleanerFindings 
computeIncludeCleanerFindings(ParsedAST ) {
   std::vector MissingIncludes;
   llvm::DenseSet Used;
   trace::Span Tracer("include_cleaner::walkUsed");
-  const DirectoryEntry *ResourceDir = AST.getPreprocessor()
-.getHeaderSearchInfo()
-.getModuleMap()
-.getBuiltinDir();
+  OptionalDirectoryEntryRef ResourceDir = AST.getPreprocessor()
+  .getHeaderSearchInfo()
+  .getModuleMap()
+  .getBuiltinDir();
   include_cleaner::walkUsed(
   AST.getLocalTopLevelDecls(), /*MacroRefs=*/Macros,
   AST.getPragmaIncludes().get(), AST.getPreprocessor(),
diff --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 09365c36f9f2c5..450c4c796c1415 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -87,7 +87,7 @@ analyze(llvm::ArrayRef ASTRoots,
   llvm::StringSet<> Missing;
   if (!HeaderFilter)
 HeaderFilter = [](llvm::StringRef) { return false; };
-  const DirectoryEntry *ResourceDir =
+  OptionalDirectoryEntryRef ResourceDir =
   PP.getHeaderSearchInfo().getModuleMap().getBuiltinDir();
   walkUsed(ASTRoots, MacroRefs, PI, PP,
[&](const SymbolReference , llvm::ArrayRef Providers) {
@@ -95,7 +95,7 @@ analyze(llvm::ArrayRef ASTRoots,
  for (const Header  : Providers) {
if (H.kind() == Header::Physical &&
(H.physical() == MainFile ||
-H.physical().getDir() == ResourceDir)) {
+(ResourceDir && H.physical().getDir() == *ResourceDir))) {
  Satisfied = true;
}
for (const Include *I : Inc.match(H)) {
@@ -114,7 +114,7 @@ analyze(llvm::ArrayRef ASTRoots,
   for (const Include  : Inc.all()) {
 if (Used.contains() || !I.Resolved ||
 HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()) ||
-I.Resolved->getFileEntry().getDir() == ResourceDir)
+(ResourceDir && I.Resolved->getFileEntry().getDir() == *ResourceDir))
   continue;
 if (PI) {
   if (PI->shouldKeep(*I.Resolved))
diff --git a/clang/include/clang/Basic/DirectoryEntry.h 
b/clang/include/clang/Basic/DirectoryEntry.h
index 5d083e68facd7a..906c2e9af23b31 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -245,78 +245,4 @@ template <> struct DenseMapInfo {
 
 } // end namespace llvm
 
-namespace clang {
-
-/// Wrapper around OptionalDirectoryEntryRef that degrades to 'const
-/// DirectoryEntry*', facilitating incremental patches to propagate
-/// DirectoryEntryRef.
-///
-/// This class can be used as return value or field where it's convenient for
-/// an OptionalDirectoryEntryRef to degrade to a 'const DirectoryEntry*'. The
-/// purpose is to avoid code churn due to dances like the following:
-/// \code
-/// // Old code.
-/// lvalue = rvalue;
-///
-/// // Temporary code from an incremental patch.
-/// OptionalDirectoryEntryRef MaybeF = rvalue;
-/// lvalue = MaybeF ? () : nullptr;
-///
-/// // Final code.
-///