[clang] [clang][modules] Remove preloaded SLocEntries from PCM files (PR #66962)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 3 15:11:03 PDT 2023


================
@@ -701,6 +701,10 @@ class SourceManager : public RefCountedBase<SourceManager> {
   /// use (-ID - 2).
   SmallVector<SrcMgr::SLocEntry, 0> LoadedSLocEntryTable;
 
+  /// For each allocation in LoadedSLocEntryTable, we keep the new size. This
+  /// can be used to determine whether two FileIDs come from the same AST file.
+  SmallVector<size_t, 0> LoadedSLocEntryTableSegments;
----------------
jansvoboda11 wrote:

> IIUC what you're ultimately checking is whether two FileIDs were allocated in the same call to AllocateLoadedSLocEntries, and relying on ASTReader to make a single call to that function for each AST file.

That's right.

> Is there a reason you're storing the size (ie translating to 0-based) instead of storing the actual boundary FileID and doing the search based on that?

I just found it easy to reason about, since it's an `upper_bound` on increasing positive values.

I guess I could store `FileID(ModuleFile::SLocEntryBaseID - 1)` instead (which is the module's `FileID(1)` translated into the importer address space for loaded entries) and do `lower_bound` over that:

```c++
SmallVector<FileID, 0> LoadedSLocEntryTableSegments{
  FileID(-10),  // represents FileIDs from -10 to -2
  FileID(-50),  // represents FileIDs from -50 to -11
  FileID(-90)}; // represents FileIDs from -90 to -51

llvm::lower_bound(LoadedSLocEntryTableSegments, FID, [](FileID Element, FileID Value) {
  return Element.ID > Value.ID;
});
```

The lambda is still confusing... Any better ideas?

https://github.com/llvm/llvm-project/pull/66962


More information about the cfe-commits mailing list