[clang] [clang-tools-extra] [clang] NFC: Remove `OptionalFileEntryRefDegradesToFileEntryPtr` (PR #74899)

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

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/74899

>From de1d9c6808271ea802813daa71e6d94bce8a9894 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Thu, 7 Dec 2023 11:38:49 -0800
Subject: [PATCH 1/2] [clang] NFC: Remove
 `OptionalFileEntryRefDegradesToFileEntryPtr`

---
 .../ExpandModularHeadersPPCallbacks.cpp   |  2 +-
 clang/include/clang/Basic/FileEntry.h | 66 ---
 clang/include/clang/Basic/Module.h|  2 +-
 clang/include/clang/Basic/SourceManager.h | 14 ++--
 clang/include/clang/Lex/PreprocessorLexer.h   |  2 +-
 .../include/clang/Serialization/ModuleFile.h  |  2 +-
 clang/lib/Frontend/CompilerInstance.cpp   |  2 +-
 clang/lib/Lex/ModuleMap.cpp   |  4 +-
 clang/lib/Lex/PPDirectives.cpp|  3 +-
 clang/lib/Lex/Pragma.cpp  |  2 +-
 clang/lib/Lex/PreprocessorLexer.cpp   |  3 +-
 clang/lib/Serialization/ASTReader.cpp |  6 +-
 clang/lib/Serialization/ASTWriter.cpp |  6 +-
 clang/lib/Serialization/ModuleManager.cpp |  4 +-
 .../DependencyScanning/ModuleDepCollector.cpp |  2 +-
 clang/tools/libclang/CXIndexDataConsumer.cpp  |  6 +-
 clang/tools/libclang/CXIndexDataConsumer.h|  2 +-
 clang/unittests/Basic/FileEntryTest.cpp   | 25 ---
 18 files changed, 31 insertions(+), 122 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 52cc2e6569b05..0b1e9f59e1a70 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -171,7 +171,7 @@ void ExpandModularHeadersPPCallbacks::InclusionDirective(
   if (Imported) {
 serialization::ModuleFile *MF =
 Compiler.getASTReader()->getModuleManager().lookup(
-Imported->getASTFile());
+*Imported->getASTFile());
 handleModuleFile(MF);
   }
   parseToLocation(DirectiveLoc);
diff --git a/clang/include/clang/Basic/FileEntry.h 
b/clang/include/clang/Basic/FileEntry.h
index 6351aeae92e2c..35efa147950f0 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -279,72 +279,6 @@ template <> struct DenseMapInfo {
 
 namespace clang {
 
-/// Wrapper around OptionalFileEntryRef that degrades to 'const FileEntry*',
-/// facilitating incremental patches to propagate FileEntryRef.
-///
-/// This class can be used as return value or field where it's convenient for
-/// an OptionalFileEntryRef to degrade to a 'const FileEntry*'. The purpose
-/// is to avoid code churn due to dances like the following:
-/// \code
-/// // Old code.
-/// lvalue = rvalue;
-///
-/// // Temporary code from an incremental patch.
-/// OptionalFileEntryRef MaybeF = rvalue;
-/// lvalue = MaybeF ? () : nullptr;
-///
-/// // Final code.
-/// lvalue = rvalue;
-/// \endcode
-///
-/// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
-/// FileEntry::getName have been deleted, delete this class and replace
-/// instances with OptionalFileEntryRef.
-class OptionalFileEntryRefDegradesToFileEntryPtr : public OptionalFileEntryRef 
{
-public:
-  OptionalFileEntryRefDegradesToFileEntryPtr() = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr(
-  OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr(
-  const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr &
-  operator=(OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr &
-  operator=(const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
-
-  OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {}
-  OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref)
-  : OptionalFileEntryRef(Ref) {}
-  OptionalFileEntryRefDegradesToFileEntryPtr(OptionalFileEntryRef MaybeRef)
-  : OptionalFileEntryRef(MaybeRef) {}
-
-  OptionalFileEntryRefDegradesToFileEntryPtr =(std::nullopt_t) {
-OptionalFileEntryRef::operator=(std::nullopt);
-return *this;
-  }
-  OptionalFileEntryRefDegradesToFileEntryPtr =(FileEntryRef Ref) {
-OptionalFileEntryRef::operator=(Ref);
-return *this;
-  }
-  OptionalFileEntryRefDegradesToFileEntryPtr &
-  operator=(OptionalFileEntryRef MaybeRef) {
-OptionalFileEntryRef::operator=(MaybeRef);
-return *this;
-  }
-
-  /// Degrade to 'const FileEntry *' to allow  FileEntry::LastRef and
-  /// FileEntry::getName have been deleted, delete this class and replace
-  /// instances with OptionalFileEntryRef
-  operator const FileEntry *() const {
-return has_value() ? &(*this)->getFileEntry() : nullptr;
-  }
-};
-
-static_assert(
-std::is_trivially_copyable<
-OptionalFileEntryRefDegradesToFileEntryPtr>::value,
-"OptionalFileEntryRefDegradesToFileEntryPtr should be trivially 

[clang] [clang-tools-extra] [clang] NFC: Remove `OptionalFileEntryRefDegradesToFileEntryPtr` (PR #74899)

2023-12-08 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 8615ead9a6d37e6353df1b652aadebe71ec6c242 
de1d9c6808271ea802813daa71e6d94bce8a9894 -- 
clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
clang/include/clang/Basic/FileEntry.h clang/include/clang/Basic/Module.h 
clang/include/clang/Basic/SourceManager.h 
clang/include/clang/Lex/PreprocessorLexer.h 
clang/include/clang/Serialization/ModuleFile.h 
clang/lib/Frontend/CompilerInstance.cpp clang/lib/Lex/ModuleMap.cpp 
clang/lib/Lex/PPDirectives.cpp clang/lib/Lex/Pragma.cpp 
clang/lib/Lex/PreprocessorLexer.cpp clang/lib/Serialization/ASTReader.cpp 
clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ModuleManager.cpp 
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
clang/tools/libclang/CXIndexDataConsumer.cpp 
clang/tools/libclang/CXIndexDataConsumer.h 
clang/unittests/Basic/FileEntryTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp 
b/clang/tools/libclang/CXIndexDataConsumer.cpp
index a327d39ee0..c1022263a5 100644
--- a/clang/tools/libclang/CXIndexDataConsumer.cpp
+++ b/clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -1104,7 +1104,7 @@ void CXIndexDataConsumer::translateLoc(SourceLocation Loc,
 
   if (FID.isInvalid())
 return;
-  
+
   OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID);
   if (indexFile)
 *indexFile = getIndexFile(FE);
diff --git a/clang/tools/libclang/CXIndexDataConsumer.h 
b/clang/tools/libclang/CXIndexDataConsumer.h
index eb9b2eaae2..54a3add3a9 100644
--- a/clang/tools/libclang/CXIndexDataConsumer.h
+++ b/clang/tools/libclang/CXIndexDataConsumer.h
@@ -461,7 +461,7 @@ private:
   const DeclContext *getEntityContainer(const Decl *D) const;
 
   CXIdxClientFile getIndexFile(OptionalFileEntryRef File);
-  
+
   CXIdxLoc getIndexLoc(SourceLocation Loc) const;
 
   void getEntityInfo(const NamedDecl *D,

``




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


[clang] [clang-tools-extra] [clang] NFC: Remove `OptionalFileEntryRefDegradesToFileEntryPtr` (PR #74899)

2023-12-08 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-tidy

Author: Jan Svoboda (jansvoboda11)


Changes



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


18 Files Affected:

- (modified) clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
(+1-1) 
- (modified) clang/include/clang/Basic/FileEntry.h (-66) 
- (modified) clang/include/clang/Basic/Module.h (+1-1) 
- (modified) clang/include/clang/Basic/SourceManager.h (+8-6) 
- (modified) clang/include/clang/Lex/PreprocessorLexer.h (+1-1) 
- (modified) clang/include/clang/Serialization/ModuleFile.h (+1-1) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+1-1) 
- (modified) clang/lib/Lex/ModuleMap.cpp (+1-3) 
- (modified) clang/lib/Lex/PPDirectives.cpp (+2-1) 
- (modified) clang/lib/Lex/Pragma.cpp (+1-1) 
- (modified) clang/lib/Lex/PreprocessorLexer.cpp (+1-2) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+3-3) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+3-3) 
- (modified) clang/lib/Serialization/ModuleManager.cpp (+2-2) 
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+1-1) 
- (modified) clang/tools/libclang/CXIndexDataConsumer.cpp (+3-3) 
- (modified) clang/tools/libclang/CXIndexDataConsumer.h (+1-1) 
- (modified) clang/unittests/Basic/FileEntryTest.cpp (-25) 


``diff
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 52cc2e6569b052..0b1e9f59e1a70c 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -171,7 +171,7 @@ void ExpandModularHeadersPPCallbacks::InclusionDirective(
   if (Imported) {
 serialization::ModuleFile *MF =
 Compiler.getASTReader()->getModuleManager().lookup(
-Imported->getASTFile());
+*Imported->getASTFile());
 handleModuleFile(MF);
   }
   parseToLocation(DirectiveLoc);
diff --git a/clang/include/clang/Basic/FileEntry.h 
b/clang/include/clang/Basic/FileEntry.h
index 6351aeae92e2c4..35efa147950f06 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -279,72 +279,6 @@ template <> struct DenseMapInfo {
 
 namespace clang {
 
-/// Wrapper around OptionalFileEntryRef that degrades to 'const FileEntry*',
-/// facilitating incremental patches to propagate FileEntryRef.
-///
-/// This class can be used as return value or field where it's convenient for
-/// an OptionalFileEntryRef to degrade to a 'const FileEntry*'. The purpose
-/// is to avoid code churn due to dances like the following:
-/// \code
-/// // Old code.
-/// lvalue = rvalue;
-///
-/// // Temporary code from an incremental patch.
-/// OptionalFileEntryRef MaybeF = rvalue;
-/// lvalue = MaybeF ? () : nullptr;
-///
-/// // Final code.
-/// lvalue = rvalue;
-/// \endcode
-///
-/// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
-/// FileEntry::getName have been deleted, delete this class and replace
-/// instances with OptionalFileEntryRef.
-class OptionalFileEntryRefDegradesToFileEntryPtr : public OptionalFileEntryRef 
{
-public:
-  OptionalFileEntryRefDegradesToFileEntryPtr() = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr(
-  OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr(
-  const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr &
-  operator=(OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr &
-  operator=(const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
-
-  OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {}
-  OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref)
-  : OptionalFileEntryRef(Ref) {}
-  OptionalFileEntryRefDegradesToFileEntryPtr(OptionalFileEntryRef MaybeRef)
-  : OptionalFileEntryRef(MaybeRef) {}
-
-  OptionalFileEntryRefDegradesToFileEntryPtr =(std::nullopt_t) {
-OptionalFileEntryRef::operator=(std::nullopt);
-return *this;
-  }
-  OptionalFileEntryRefDegradesToFileEntryPtr =(FileEntryRef Ref) {
-OptionalFileEntryRef::operator=(Ref);
-return *this;
-  }
-  OptionalFileEntryRefDegradesToFileEntryPtr &
-  operator=(OptionalFileEntryRef MaybeRef) {
-OptionalFileEntryRef::operator=(MaybeRef);
-return *this;
-  }
-
-  /// Degrade to 'const FileEntry *' to allow  FileEntry::LastRef and
-  /// FileEntry::getName have been deleted, delete this class and replace
-  /// instances with OptionalFileEntryRef
-  operator const FileEntry *() const {
-return has_value() ? &(*this)->getFileEntry() : nullptr;
-  }
-};
-
-static_assert(
-std::is_trivially_copyable<
-OptionalFileEntryRefDegradesToFileEntryPtr>::value,
-"OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable");
-
 inline bool 

[clang] [clang-tools-extra] [clang] NFC: Remove `OptionalFileEntryRefDegradesToFileEntryPtr` (PR #74899)

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

https://github.com/jansvoboda11 created 
https://github.com/llvm/llvm-project/pull/74899

None

>From de1d9c6808271ea802813daa71e6d94bce8a9894 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Thu, 7 Dec 2023 11:38:49 -0800
Subject: [PATCH] [clang] NFC: Remove
 `OptionalFileEntryRefDegradesToFileEntryPtr`

---
 .../ExpandModularHeadersPPCallbacks.cpp   |  2 +-
 clang/include/clang/Basic/FileEntry.h | 66 ---
 clang/include/clang/Basic/Module.h|  2 +-
 clang/include/clang/Basic/SourceManager.h | 14 ++--
 clang/include/clang/Lex/PreprocessorLexer.h   |  2 +-
 .../include/clang/Serialization/ModuleFile.h  |  2 +-
 clang/lib/Frontend/CompilerInstance.cpp   |  2 +-
 clang/lib/Lex/ModuleMap.cpp   |  4 +-
 clang/lib/Lex/PPDirectives.cpp|  3 +-
 clang/lib/Lex/Pragma.cpp  |  2 +-
 clang/lib/Lex/PreprocessorLexer.cpp   |  3 +-
 clang/lib/Serialization/ASTReader.cpp |  6 +-
 clang/lib/Serialization/ASTWriter.cpp |  6 +-
 clang/lib/Serialization/ModuleManager.cpp |  4 +-
 .../DependencyScanning/ModuleDepCollector.cpp |  2 +-
 clang/tools/libclang/CXIndexDataConsumer.cpp  |  6 +-
 clang/tools/libclang/CXIndexDataConsumer.h|  2 +-
 clang/unittests/Basic/FileEntryTest.cpp   | 25 ---
 18 files changed, 31 insertions(+), 122 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 52cc2e6569b052..0b1e9f59e1a70c 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -171,7 +171,7 @@ void ExpandModularHeadersPPCallbacks::InclusionDirective(
   if (Imported) {
 serialization::ModuleFile *MF =
 Compiler.getASTReader()->getModuleManager().lookup(
-Imported->getASTFile());
+*Imported->getASTFile());
 handleModuleFile(MF);
   }
   parseToLocation(DirectiveLoc);
diff --git a/clang/include/clang/Basic/FileEntry.h 
b/clang/include/clang/Basic/FileEntry.h
index 6351aeae92e2c4..35efa147950f06 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -279,72 +279,6 @@ template <> struct DenseMapInfo {
 
 namespace clang {
 
-/// Wrapper around OptionalFileEntryRef that degrades to 'const FileEntry*',
-/// facilitating incremental patches to propagate FileEntryRef.
-///
-/// This class can be used as return value or field where it's convenient for
-/// an OptionalFileEntryRef to degrade to a 'const FileEntry*'. The purpose
-/// is to avoid code churn due to dances like the following:
-/// \code
-/// // Old code.
-/// lvalue = rvalue;
-///
-/// // Temporary code from an incremental patch.
-/// OptionalFileEntryRef MaybeF = rvalue;
-/// lvalue = MaybeF ? () : nullptr;
-///
-/// // Final code.
-/// lvalue = rvalue;
-/// \endcode
-///
-/// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
-/// FileEntry::getName have been deleted, delete this class and replace
-/// instances with OptionalFileEntryRef.
-class OptionalFileEntryRefDegradesToFileEntryPtr : public OptionalFileEntryRef 
{
-public:
-  OptionalFileEntryRefDegradesToFileEntryPtr() = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr(
-  OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr(
-  const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr &
-  operator=(OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
-  OptionalFileEntryRefDegradesToFileEntryPtr &
-  operator=(const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
-
-  OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {}
-  OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref)
-  : OptionalFileEntryRef(Ref) {}
-  OptionalFileEntryRefDegradesToFileEntryPtr(OptionalFileEntryRef MaybeRef)
-  : OptionalFileEntryRef(MaybeRef) {}
-
-  OptionalFileEntryRefDegradesToFileEntryPtr =(std::nullopt_t) {
-OptionalFileEntryRef::operator=(std::nullopt);
-return *this;
-  }
-  OptionalFileEntryRefDegradesToFileEntryPtr =(FileEntryRef Ref) {
-OptionalFileEntryRef::operator=(Ref);
-return *this;
-  }
-  OptionalFileEntryRefDegradesToFileEntryPtr &
-  operator=(OptionalFileEntryRef MaybeRef) {
-OptionalFileEntryRef::operator=(MaybeRef);
-return *this;
-  }
-
-  /// Degrade to 'const FileEntry *' to allow  FileEntry::LastRef and
-  /// FileEntry::getName have been deleted, delete this class and replace
-  /// instances with OptionalFileEntryRef
-  operator const FileEntry *() const {
-return has_value() ? &(*this)->getFileEntry() : nullptr;
-  }
-};
-
-static_assert(
-std::is_trivially_copyable<
-OptionalFileEntryRefDegradesToFileEntryPtr>::value,
-"OptionalFileEntryRefDegradesToFileEntryPtr should be