[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)

2024-10-31 Thread Cyndy Ishida via cfe-commits

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

I initially touched this code because I needed to be able to map back input 
headers from a destination location (DSTROOT) to where they were resolved with 
headermaps (SRCROOT) for `tapi`/`clang-installapi`. But looking at the code it 
only really calls into `getIncludeNameForHeader()` for this now, so seems fine. 

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


[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)

2024-10-31 Thread Ben Langmuir via cfe-commits

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


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


[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)

2024-10-31 Thread Jan Svoboda via cfe-commits


@@ -2045,21 +2041,7 @@ namespace {
 LE.write(
 Writer.getIdentifierRef(Data.HFI.LazyControllingMacro.getPtr()));
 
-  unsigned Offset = 0;
-  if (!Data.HFI.Framework.empty()) {
-// If this header refers into a framework, save the framework name.
-llvm::StringMap::iterator Pos
-  = FrameworkNameOffset.find(Data.HFI.Framework);
-if (Pos == FrameworkNameOffset.end()) {
-  Offset = FrameworkStringData.size() + 1;
-  FrameworkStringData.append(Data.HFI.Framework);
-  FrameworkStringData.push_back(0);
-
-  FrameworkNameOffset[Data.HFI.Framework] = Offset;
-} else
-  Offset = Pos->second;
-  }
-  LE.write(Offset);
+  LE.write(0);

jansvoboda11 wrote:

I will probably remove this and bump the serialization format version.

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


[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)

2024-10-31 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 3452149c059010e834050acd41a64595eb74df11 
a623a41c4b4c02a87e2aaf225c15856c35ed4150 --extensions cpp,h -- 
clang-tools-extra/clangd/index/SymbolCollector.cpp 
clang/include/clang/Lex/DirectoryLookup.h 
clang/include/clang/Lex/HeaderSearch.h 
clang/include/clang/Lex/HeaderSearchOptions.h 
clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/CompilerInvocation.cpp 
clang/lib/Lex/HeaderSearch.cpp clang/lib/Lex/InitHeaderSearch.cpp 
clang/lib/Serialization/ASTReader.cpp 
clang/lib/Serialization/ASTReaderInternals.h 
clang/lib/Serialization/ASTWriter.cpp clang/unittests/Lex/HeaderSearchTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 91ae9d3003..3675eea536 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -427,8 +427,7 @@ private:
   CachePathToFrameworkSpelling.erase(Res.first);
   return std::nullopt;
 }
-if (auto UmbrellaSpelling =
-getFrameworkUmbrellaSpelling(HS, *HeaderPath)) {
+if (auto UmbrellaSpelling = getFrameworkUmbrellaSpelling(HS, *HeaderPath)) 
{
   *CachedHeaderSpelling = *UmbrellaSpelling;
   return llvm::StringRef(*CachedHeaderSpelling);
 }
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 50e5d4af32..118614ba41 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2028,11 +2028,11 @@ namespace {
   endian::Writer LE(Out, llvm::endianness::little);
   uint64_t Start = Out.tell(); (void)Start;
 
-  unsigned char Flags = (Data.AlreadyIncluded << 6)
-  | (Data.HFI.isImport << 5)
-  | (Writer.isWritingStdCXXNamedModules() ? 0 :
- Data.HFI.isPragmaOnce << 4)
-  | (Data.HFI.DirInfo << 1);
+  unsigned char Flags =
+  (Data.AlreadyIncluded << 6) | (Data.HFI.isImport << 5) |
+  (Writer.isWritingStdCXXNamedModules() ? 0
+: Data.HFI.isPragmaOnce << 4) |
+  (Data.HFI.DirInfo << 1);
   LE.write(Flags);
 
   if (Data.HFI.LazyControllingMacro.isID())

``




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


[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Jan Svoboda (jansvoboda11)


Changes

This PR removes the `HeaderFileInfo::Framework` member and reduces the size of 
this data type from 32B to 16B. This should improve Clang's memory usage in 
situations where it keeps track of lots of header files. NFCI. Depends on #114459.

---

Patch is 26.90 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/114460.diff


14 Files Affected:

- (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+28-30) 
- (modified) clang/include/clang/Driver/Options.td (-3) 
- (modified) clang/include/clang/Lex/DirectoryLookup.h (+3-13) 
- (modified) clang/include/clang/Lex/HeaderSearch.h (+3-15) 
- (modified) clang/include/clang/Lex/HeaderSearchOptions.h (-3) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-2) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+6-24) 
- (modified) clang/lib/Lex/HeaderSearch.cpp (-60) 
- (modified) clang/lib/Lex/InitHeaderSearch.cpp (+4-5) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+7-15) 
- (modified) clang/lib/Serialization/ASTReaderInternals.h (+2-5) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+2-25) 
- (removed) clang/test/Driver/index-header-map.c (-4) 
- (modified) clang/unittests/Lex/HeaderSearchTest.cpp (+1-4) 


``diff
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index d1d744a21cfd55..91ae9d3003a971 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -335,9 +335,10 @@ class SymbolCollector::HeaderFileURICache {
   }
 
   struct FrameworkHeaderPath {
-// Path to the framework directory containing the Headers/PrivateHeaders
-// directories  e.g. /Frameworks/Foundation.framework/
-llvm::StringRef HeadersParentDir;
+// Path to the frameworks directory containing the .framework directory.
+llvm::StringRef FrameworkParentDir;
+// Name of the framework.
+llvm::StringRef FrameworkName;
 // Subpath relative to the Headers or PrivateHeaders dir, e.g. NSObject.h
 // Note: This is NOT relative to the `HeadersParentDir`.
 llvm::StringRef HeaderSubpath;
@@ -351,19 +352,17 @@ class SymbolCollector::HeaderFileURICache {
 path::reverse_iterator I = path::rbegin(Path);
 path::reverse_iterator Prev = I;
 path::reverse_iterator E = path::rend(Path);
+FrameworkHeaderPath HeaderPath;
 while (I != E) {
-  if (*I == "Headers") {
-FrameworkHeaderPath HeaderPath;
-HeaderPath.HeadersParentDir = Path.substr(0, I - E);
+  if (*I == "Headers" || *I == "PrivateHeaders") {
 HeaderPath.HeaderSubpath = Path.substr(Prev - E);
-HeaderPath.IsPrivateHeader = false;
-return HeaderPath;
-  }
-  if (*I == "PrivateHeaders") {
-FrameworkHeaderPath HeaderPath;
-HeaderPath.HeadersParentDir = Path.substr(0, I - E);
-HeaderPath.HeaderSubpath = Path.substr(Prev - E);
-HeaderPath.IsPrivateHeader = true;
+HeaderPath.IsPrivateHeader = *I == "PrivateHeaders";
+if (++I == E)
+  break;
+HeaderPath.FrameworkName = *I;
+if (!HeaderPath.FrameworkName.consume_back(".framework"))
+  break;
+HeaderPath.FrameworkParentDir = Path.substr(0, I - E);
 return HeaderPath;
   }
   Prev = I;
@@ -379,26 +378,27 @@ class SymbolCollector::HeaderFileURICache {
   //  which should be used instead of directly
   // importing the header.
   std::optional
-  getFrameworkUmbrellaSpelling(llvm::StringRef Framework,
-   const HeaderSearch &HS,
+  getFrameworkUmbrellaSpelling(const HeaderSearch &HS,
FrameworkHeaderPath &HeaderPath) {
+StringRef Framework = HeaderPath.FrameworkName;
 auto Res = CacheFrameworkToUmbrellaHeaderSpelling.try_emplace(Framework);
 auto *CachedSpelling = &Res.first->second;
 if (!Res.second) {
   return HeaderPath.IsPrivateHeader ? CachedSpelling->PrivateHeader
 : CachedSpelling->PublicHeader;
 }
-SmallString<256> UmbrellaPath(HeaderPath.HeadersParentDir);
-llvm::sys::path::append(UmbrellaPath, "Headers", Framework + ".h");
+SmallString<256> UmbrellaPath(HeaderPath.FrameworkParentDir);
+llvm::sys::path::append(UmbrellaPath, Framework + ".framework", "Headers",
+Framework + ".h");
 
 llvm::vfs::Status Status;
 auto StatErr = HS.getFileMgr().getNoncachedStatValue(UmbrellaPath, Status);
 if (!StatErr)
   CachedSpelling->PublicHeader = llvm::formatv("<{0}/{0}.h>", Framework);
 
-UmbrellaPath = HeaderPath.HeadersParentDir;
-llvm::sys::path::append(UmbrellaPath, "PrivateHeaders",
-Framework + "_Private.h");
+UmbrellaPath = HeaderPath.FrameworkParentDir;
+llvm::sys::path::ap

[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Jan Svoboda (jansvoboda11)


Changes

This PR removes the `HeaderFileInfo::Framework` member and reduces the size of 
this data type from 32B to 16B. This should improve Clang's memory usage in 
situations where it keeps track of lots of header files. NFCI. Depends on #114459.

---

Patch is 26.90 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/114460.diff


14 Files Affected:

- (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+28-30) 
- (modified) clang/include/clang/Driver/Options.td (-3) 
- (modified) clang/include/clang/Lex/DirectoryLookup.h (+3-13) 
- (modified) clang/include/clang/Lex/HeaderSearch.h (+3-15) 
- (modified) clang/include/clang/Lex/HeaderSearchOptions.h (-3) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-2) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+6-24) 
- (modified) clang/lib/Lex/HeaderSearch.cpp (-60) 
- (modified) clang/lib/Lex/InitHeaderSearch.cpp (+4-5) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+7-15) 
- (modified) clang/lib/Serialization/ASTReaderInternals.h (+2-5) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+2-25) 
- (removed) clang/test/Driver/index-header-map.c (-4) 
- (modified) clang/unittests/Lex/HeaderSearchTest.cpp (+1-4) 


``diff
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index d1d744a21cfd55..91ae9d3003a971 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -335,9 +335,10 @@ class SymbolCollector::HeaderFileURICache {
   }
 
   struct FrameworkHeaderPath {
-// Path to the framework directory containing the Headers/PrivateHeaders
-// directories  e.g. /Frameworks/Foundation.framework/
-llvm::StringRef HeadersParentDir;
+// Path to the frameworks directory containing the .framework directory.
+llvm::StringRef FrameworkParentDir;
+// Name of the framework.
+llvm::StringRef FrameworkName;
 // Subpath relative to the Headers or PrivateHeaders dir, e.g. NSObject.h
 // Note: This is NOT relative to the `HeadersParentDir`.
 llvm::StringRef HeaderSubpath;
@@ -351,19 +352,17 @@ class SymbolCollector::HeaderFileURICache {
 path::reverse_iterator I = path::rbegin(Path);
 path::reverse_iterator Prev = I;
 path::reverse_iterator E = path::rend(Path);
+FrameworkHeaderPath HeaderPath;
 while (I != E) {
-  if (*I == "Headers") {
-FrameworkHeaderPath HeaderPath;
-HeaderPath.HeadersParentDir = Path.substr(0, I - E);
+  if (*I == "Headers" || *I == "PrivateHeaders") {
 HeaderPath.HeaderSubpath = Path.substr(Prev - E);
-HeaderPath.IsPrivateHeader = false;
-return HeaderPath;
-  }
-  if (*I == "PrivateHeaders") {
-FrameworkHeaderPath HeaderPath;
-HeaderPath.HeadersParentDir = Path.substr(0, I - E);
-HeaderPath.HeaderSubpath = Path.substr(Prev - E);
-HeaderPath.IsPrivateHeader = true;
+HeaderPath.IsPrivateHeader = *I == "PrivateHeaders";
+if (++I == E)
+  break;
+HeaderPath.FrameworkName = *I;
+if (!HeaderPath.FrameworkName.consume_back(".framework"))
+  break;
+HeaderPath.FrameworkParentDir = Path.substr(0, I - E);
 return HeaderPath;
   }
   Prev = I;
@@ -379,26 +378,27 @@ class SymbolCollector::HeaderFileURICache {
   //  which should be used instead of directly
   // importing the header.
   std::optional
-  getFrameworkUmbrellaSpelling(llvm::StringRef Framework,
-   const HeaderSearch &HS,
+  getFrameworkUmbrellaSpelling(const HeaderSearch &HS,
FrameworkHeaderPath &HeaderPath) {
+StringRef Framework = HeaderPath.FrameworkName;
 auto Res = CacheFrameworkToUmbrellaHeaderSpelling.try_emplace(Framework);
 auto *CachedSpelling = &Res.first->second;
 if (!Res.second) {
   return HeaderPath.IsPrivateHeader ? CachedSpelling->PrivateHeader
 : CachedSpelling->PublicHeader;
 }
-SmallString<256> UmbrellaPath(HeaderPath.HeadersParentDir);
-llvm::sys::path::append(UmbrellaPath, "Headers", Framework + ".h");
+SmallString<256> UmbrellaPath(HeaderPath.FrameworkParentDir);
+llvm::sys::path::append(UmbrellaPath, Framework + ".framework", "Headers",
+Framework + ".h");
 
 llvm::vfs::Status Status;
 auto StatErr = HS.getFileMgr().getNoncachedStatValue(UmbrellaPath, Status);
 if (!StatErr)
   CachedSpelling->PublicHeader = llvm::formatv("<{0}/{0}.h>", Framework);
 
-UmbrellaPath = HeaderPath.HeadersParentDir;
-llvm::sys::path::append(UmbrellaPath, "PrivateHeaders",
-Framework + "_Private.h");
+UmbrellaPath = HeaderPath.FrameworkParentDir;
+llvm::sys::p

[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Jan Svoboda (jansvoboda11)


Changes

This PR removes the `HeaderFileInfo::Framework` member and reduces the size of 
this data type from 32B to 16B. This should improve Clang's memory usage in 
situations where it keeps track of lots of header files. NFCI. Depends on #114459.

---

Patch is 26.90 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/114460.diff


14 Files Affected:

- (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+28-30) 
- (modified) clang/include/clang/Driver/Options.td (-3) 
- (modified) clang/include/clang/Lex/DirectoryLookup.h (+3-13) 
- (modified) clang/include/clang/Lex/HeaderSearch.h (+3-15) 
- (modified) clang/include/clang/Lex/HeaderSearchOptions.h (-3) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-2) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+6-24) 
- (modified) clang/lib/Lex/HeaderSearch.cpp (-60) 
- (modified) clang/lib/Lex/InitHeaderSearch.cpp (+4-5) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+7-15) 
- (modified) clang/lib/Serialization/ASTReaderInternals.h (+2-5) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+2-25) 
- (removed) clang/test/Driver/index-header-map.c (-4) 
- (modified) clang/unittests/Lex/HeaderSearchTest.cpp (+1-4) 


``diff
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index d1d744a21cfd55..91ae9d3003a971 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -335,9 +335,10 @@ class SymbolCollector::HeaderFileURICache {
   }
 
   struct FrameworkHeaderPath {
-// Path to the framework directory containing the Headers/PrivateHeaders
-// directories  e.g. /Frameworks/Foundation.framework/
-llvm::StringRef HeadersParentDir;
+// Path to the frameworks directory containing the .framework directory.
+llvm::StringRef FrameworkParentDir;
+// Name of the framework.
+llvm::StringRef FrameworkName;
 // Subpath relative to the Headers or PrivateHeaders dir, e.g. NSObject.h
 // Note: This is NOT relative to the `HeadersParentDir`.
 llvm::StringRef HeaderSubpath;
@@ -351,19 +352,17 @@ class SymbolCollector::HeaderFileURICache {
 path::reverse_iterator I = path::rbegin(Path);
 path::reverse_iterator Prev = I;
 path::reverse_iterator E = path::rend(Path);
+FrameworkHeaderPath HeaderPath;
 while (I != E) {
-  if (*I == "Headers") {
-FrameworkHeaderPath HeaderPath;
-HeaderPath.HeadersParentDir = Path.substr(0, I - E);
+  if (*I == "Headers" || *I == "PrivateHeaders") {
 HeaderPath.HeaderSubpath = Path.substr(Prev - E);
-HeaderPath.IsPrivateHeader = false;
-return HeaderPath;
-  }
-  if (*I == "PrivateHeaders") {
-FrameworkHeaderPath HeaderPath;
-HeaderPath.HeadersParentDir = Path.substr(0, I - E);
-HeaderPath.HeaderSubpath = Path.substr(Prev - E);
-HeaderPath.IsPrivateHeader = true;
+HeaderPath.IsPrivateHeader = *I == "PrivateHeaders";
+if (++I == E)
+  break;
+HeaderPath.FrameworkName = *I;
+if (!HeaderPath.FrameworkName.consume_back(".framework"))
+  break;
+HeaderPath.FrameworkParentDir = Path.substr(0, I - E);
 return HeaderPath;
   }
   Prev = I;
@@ -379,26 +378,27 @@ class SymbolCollector::HeaderFileURICache {
   //  which should be used instead of directly
   // importing the header.
   std::optional
-  getFrameworkUmbrellaSpelling(llvm::StringRef Framework,
-   const HeaderSearch &HS,
+  getFrameworkUmbrellaSpelling(const HeaderSearch &HS,
FrameworkHeaderPath &HeaderPath) {
+StringRef Framework = HeaderPath.FrameworkName;
 auto Res = CacheFrameworkToUmbrellaHeaderSpelling.try_emplace(Framework);
 auto *CachedSpelling = &Res.first->second;
 if (!Res.second) {
   return HeaderPath.IsPrivateHeader ? CachedSpelling->PrivateHeader
 : CachedSpelling->PublicHeader;
 }
-SmallString<256> UmbrellaPath(HeaderPath.HeadersParentDir);
-llvm::sys::path::append(UmbrellaPath, "Headers", Framework + ".h");
+SmallString<256> UmbrellaPath(HeaderPath.FrameworkParentDir);
+llvm::sys::path::append(UmbrellaPath, Framework + ".framework", "Headers",
+Framework + ".h");
 
 llvm::vfs::Status Status;
 auto StatErr = HS.getFileMgr().getNoncachedStatValue(UmbrellaPath, Status);
 if (!StatErr)
   CachedSpelling->PublicHeader = llvm::formatv("<{0}/{0}.h>", Framework);
 
-UmbrellaPath = HeaderPath.HeadersParentDir;
-llvm::sys::path::append(UmbrellaPath, "PrivateHeaders",
-Framework + "_Private.h");
+UmbrellaPath = HeaderPath.FrameworkParentDir;
+llvm::sys::pa

[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)

2024-10-31 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)


Changes

This PR removes the `HeaderFileInfo::Framework` member and reduces the size of 
this data type from 32B to 16B. This should improve Clang's memory usage in 
situations where it keeps track of lots of header files. NFCI. Depends on #114459.

---

Patch is 26.90 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/114460.diff


14 Files Affected:

- (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+28-30) 
- (modified) clang/include/clang/Driver/Options.td (-3) 
- (modified) clang/include/clang/Lex/DirectoryLookup.h (+3-13) 
- (modified) clang/include/clang/Lex/HeaderSearch.h (+3-15) 
- (modified) clang/include/clang/Lex/HeaderSearchOptions.h (-3) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-2) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+6-24) 
- (modified) clang/lib/Lex/HeaderSearch.cpp (-60) 
- (modified) clang/lib/Lex/InitHeaderSearch.cpp (+4-5) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+7-15) 
- (modified) clang/lib/Serialization/ASTReaderInternals.h (+2-5) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+2-25) 
- (removed) clang/test/Driver/index-header-map.c (-4) 
- (modified) clang/unittests/Lex/HeaderSearchTest.cpp (+1-4) 


``diff
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index d1d744a21cfd55..91ae9d3003a971 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -335,9 +335,10 @@ class SymbolCollector::HeaderFileURICache {
   }
 
   struct FrameworkHeaderPath {
-// Path to the framework directory containing the Headers/PrivateHeaders
-// directories  e.g. /Frameworks/Foundation.framework/
-llvm::StringRef HeadersParentDir;
+// Path to the frameworks directory containing the .framework directory.
+llvm::StringRef FrameworkParentDir;
+// Name of the framework.
+llvm::StringRef FrameworkName;
 // Subpath relative to the Headers or PrivateHeaders dir, e.g. NSObject.h
 // Note: This is NOT relative to the `HeadersParentDir`.
 llvm::StringRef HeaderSubpath;
@@ -351,19 +352,17 @@ class SymbolCollector::HeaderFileURICache {
 path::reverse_iterator I = path::rbegin(Path);
 path::reverse_iterator Prev = I;
 path::reverse_iterator E = path::rend(Path);
+FrameworkHeaderPath HeaderPath;
 while (I != E) {
-  if (*I == "Headers") {
-FrameworkHeaderPath HeaderPath;
-HeaderPath.HeadersParentDir = Path.substr(0, I - E);
+  if (*I == "Headers" || *I == "PrivateHeaders") {
 HeaderPath.HeaderSubpath = Path.substr(Prev - E);
-HeaderPath.IsPrivateHeader = false;
-return HeaderPath;
-  }
-  if (*I == "PrivateHeaders") {
-FrameworkHeaderPath HeaderPath;
-HeaderPath.HeadersParentDir = Path.substr(0, I - E);
-HeaderPath.HeaderSubpath = Path.substr(Prev - E);
-HeaderPath.IsPrivateHeader = true;
+HeaderPath.IsPrivateHeader = *I == "PrivateHeaders";
+if (++I == E)
+  break;
+HeaderPath.FrameworkName = *I;
+if (!HeaderPath.FrameworkName.consume_back(".framework"))
+  break;
+HeaderPath.FrameworkParentDir = Path.substr(0, I - E);
 return HeaderPath;
   }
   Prev = I;
@@ -379,26 +378,27 @@ class SymbolCollector::HeaderFileURICache {
   //  which should be used instead of directly
   // importing the header.
   std::optional
-  getFrameworkUmbrellaSpelling(llvm::StringRef Framework,
-   const HeaderSearch &HS,
+  getFrameworkUmbrellaSpelling(const HeaderSearch &HS,
FrameworkHeaderPath &HeaderPath) {
+StringRef Framework = HeaderPath.FrameworkName;
 auto Res = CacheFrameworkToUmbrellaHeaderSpelling.try_emplace(Framework);
 auto *CachedSpelling = &Res.first->second;
 if (!Res.second) {
   return HeaderPath.IsPrivateHeader ? CachedSpelling->PrivateHeader
 : CachedSpelling->PublicHeader;
 }
-SmallString<256> UmbrellaPath(HeaderPath.HeadersParentDir);
-llvm::sys::path::append(UmbrellaPath, "Headers", Framework + ".h");
+SmallString<256> UmbrellaPath(HeaderPath.FrameworkParentDir);
+llvm::sys::path::append(UmbrellaPath, Framework + ".framework", "Headers",
+Framework + ".h");
 
 llvm::vfs::Status Status;
 auto StatErr = HS.getFileMgr().getNoncachedStatValue(UmbrellaPath, Status);
 if (!StatErr)
   CachedSpelling->PublicHeader = llvm::formatv("<{0}/{0}.h>", Framework);
 
-UmbrellaPath = HeaderPath.HeadersParentDir;
-llvm::sys::path::append(UmbrellaPath, "PrivateHeaders",
-Framework + "_Private.h");
+UmbrellaPath = HeaderPath.Framew

[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)

2024-10-31 Thread Jan Svoboda via cfe-commits

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

This PR removes the `HeaderFileInfo::Framework` member and reduces the size of 
this data type from 32B to 16B. This should improve Clang's memory usage in 
situations where it keeps track of lots of header files. NFCI. Depends on 
#114459.

>From 57c87b5326ebe557fc8830d4a558bd6fabf907fb Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Thu, 31 Oct 2024 09:24:11 -0700
Subject: [PATCH 1/2] [clang][lex] Remove `-index-header-map`

---
 clang/include/clang/Driver/Options.td |  3 --
 clang/include/clang/Lex/DirectoryLookup.h | 16 ++-
 clang/include/clang/Lex/HeaderSearch.h| 12 +
 clang/include/clang/Lex/HeaderSearchOptions.h |  3 --
 clang/lib/Driver/ToolChains/Clang.cpp |  3 +-
 clang/lib/Frontend/CompilerInvocation.cpp | 30 +++-
 clang/lib/Lex/HeaderSearch.cpp| 47 +--
 clang/lib/Lex/InitHeaderSearch.cpp|  9 ++--
 clang/lib/Serialization/ASTReader.cpp |  1 -
 clang/lib/Serialization/ASTWriter.cpp |  3 +-
 clang/test/Driver/index-header-map.c  |  4 --
 clang/unittests/Lex/HeaderSearchTest.cpp  |  3 +-
 12 files changed, 18 insertions(+), 116 deletions(-)
 delete mode 100644 clang/test/Driver/index-header-map.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8bc2fe377b8ec..7a05cc03353ac1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4564,9 +4564,6 @@ def ibuiltininc : Flag<["-"], "ibuiltininc">, 
Group,
   HelpText<"Enable builtin #include directories even when -nostdinc is used "
"before or after -ibuiltininc. "
"Using -nobuiltininc after the option disables it">;
-def index_header_map : Flag<["-"], "index-header-map">,
-  Visibility<[ClangOption, CC1Option]>,
-  HelpText<"Make the next included directory (-I or -F) an indexer header 
map">;
 def iapinotes_modules : JoinedOrSeparate<["-"], "iapinotes-modules">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Add directory to the API notes search path referenced by module 
name">, MetaVarName<"">;
diff --git a/clang/include/clang/Lex/DirectoryLookup.h 
b/clang/include/clang/Lex/DirectoryLookup.h
index 81680d3b271e08..bb703dfad2b28f 100644
--- a/clang/include/clang/Lex/DirectoryLookup.h
+++ b/clang/include/clang/Lex/DirectoryLookup.h
@@ -58,10 +58,6 @@ class DirectoryLookup {
   LLVM_PREFERRED_TYPE(LookupType_t)
   unsigned LookupType : 2;
 
-  /// Whether this is a header map used when building a framework.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned IsIndexHeaderMap : 1;
-
   /// Whether we've performed an exhaustive search for module maps
   /// within the subdirectories of this directory.
   LLVM_PREFERRED_TYPE(bool)
@@ -73,13 +69,12 @@ class DirectoryLookup {
   bool isFramework)
   : u(Dir), DirCharacteristic(DT),
 LookupType(isFramework ? LT_Framework : LT_NormalDir),
-IsIndexHeaderMap(false), SearchedAllModuleMaps(false) {}
+SearchedAllModuleMaps(false) {}
 
   /// This ctor *does not take ownership* of 'Map'.
-  DirectoryLookup(const HeaderMap *Map, SrcMgr::CharacteristicKind DT,
-  bool isIndexHeaderMap)
+  DirectoryLookup(const HeaderMap *Map, SrcMgr::CharacteristicKind DT)
   : u(Map), DirCharacteristic(DT), LookupType(LT_HeaderMap),
-IsIndexHeaderMap(isIndexHeaderMap), SearchedAllModuleMaps(false) {}
+SearchedAllModuleMaps(false) {}
 
   /// getLookupType - Return the kind of directory lookup that this is: either 
a
   /// normal directory, a framework path, or a HeaderMap.
@@ -146,11 +141,6 @@ class DirectoryLookup {
 return getDirCharacteristic() != SrcMgr::C_User;
   }
 
-  /// Whether this header map is building a framework or not.
-  bool isIndexHeaderMap() const {
-return isHeaderMap() && IsIndexHeaderMap;
-  }
-
   /// LookupFile - Lookup the specified file in this search path, returning it
   /// if it exists or returning null if not.
   ///
diff --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index df75c192c700a0..8128377d38c35a 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -108,16 +108,6 @@ struct HeaderFileInfo {
   LLVM_PREFERRED_TYPE(bool)
   unsigned Resolved : 1;
 
-  /// Whether this is a header inside a framework that is currently
-  /// being built.
-  ///
-  /// When a framework is being built, the headers have not yet been placed
-  /// into the appropriate framework subdirectories, and therefore are
-  /// provided via a header map. This bit indicates when this is one of
-  /// those framework headers.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned IndexHeaderMapHeader : 1;
-
   /// Whether this file has been looked up as a header.
   LLVM_PREFERRED_TYPE(bool)
   unsigned IsValid : 1;
@@ -140,7 +130,7 @@ struc