-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
FileEntryRef
in include_cleaner::Header
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,15 +122,15 @@ struct Header { | |
Verbatim, | ||
}; | ||
|
||
Header(const FileEntry *FE) : Storage(FE) {} | ||
Header(FileEntryRef FE) : Storage(FE) {} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jansvoboda11
Author
Contributor
|
||
Header(tooling::stdlib::Header H) : Storage(H) {} | ||
Header(StringRef VerbatimSpelling) : Storage(VerbatimSpelling) {} | ||
|
||
Kind kind() const { return static_cast<Kind>(Storage.index()); } | ||
bool operator==(const Header &RHS) const { return Storage == RHS.Storage; } | ||
bool operator<(const Header &RHS) const; | ||
|
||
const FileEntry *physical() const { return std::get<Physical>(Storage); } | ||
FileEntryRef physical() const { return std::get<Physical>(Storage); } | ||
tooling::stdlib::Header standard() const { | ||
return std::get<Standard>(Storage); | ||
} | ||
|
@@ -142,7 +142,7 @@ struct Header { | |
|
||
private: | ||
// Order must match Kind enum! | ||
std::variant<const FileEntry *, tooling::stdlib::Header, StringRef> Storage; | ||
std::variant<FileEntryRef, tooling::stdlib::Header, StringRef> Storage; | ||
This comment has been minimized.
Sorry, something went wrong.
sam-mccall
Collaborator
|
||
|
||
// Disambiguation tag to make sure we can call the right constructor from | ||
// DenseMapInfo methods. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ llvm::StringRef basename(llvm::StringRef Header) { | |
bool nameMatch(llvm::StringRef DeclName, Header H) { | ||
switch (H.kind()) { | ||
case Header::Physical: | ||
return basename(H.physical()->getName()).equals_insensitive(DeclName); | ||
return basename(H.physical().getName()).equals_insensitive(DeclName); | ||
case Header::Standard: | ||
return basename(H.standard().name()).equals_insensitive(DeclName); | ||
case Header::Verbatim: | ||
|
@@ -101,7 +101,7 @@ hintedHeadersForStdHeaders(llvm::ArrayRef<tooling::stdlib::Header> Headers, | |
Results.emplace_back(H, Hints::PublicHeader | Hints::OriginHeader); | ||
if (!PI) | ||
continue; | ||
for (const auto *Export : PI->getExporters(H, SM.getFileManager())) | ||
for (FileEntryRef Export : PI->getExporters(H, SM.getFileManager())) | ||
Results.emplace_back(Header(Export), isPublicHeader(Export, *PI)); | ||
} | ||
// StandardLibrary returns headers in preference order, so only mark the | ||
|
@@ -186,31 +186,31 @@ llvm::SmallVector<Hinted<Header>> findHeaders(const SymbolLocation &Loc, | |
switch (Loc.kind()) { | ||
case SymbolLocation::Physical: { | ||
FileID FID = SM.getFileID(SM.getExpansionLoc(Loc.physical())); | ||
const FileEntry *FE = SM.getFileEntryForID(FID); | ||
OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID); | ||
if (!FE) | ||
return {}; | ||
if (!PI) | ||
return {{FE, Hints::PublicHeader | Hints::OriginHeader}}; | ||
return {{*FE, Hints::PublicHeader | Hints::OriginHeader}}; | ||
bool IsOrigin = true; | ||
std::queue<const FileEntry *> Exporters; | ||
std::queue<FileEntryRef> Exporters; | ||
while (FE) { | ||
Results.emplace_back(FE, | ||
isPublicHeader(FE, *PI) | | ||
Results.emplace_back(*FE, | ||
isPublicHeader(*FE, *PI) | | ||
(IsOrigin ? Hints::OriginHeader : Hints::None)); | ||
for (const auto *Export : PI->getExporters(FE, SM.getFileManager())) | ||
for (FileEntryRef Export : PI->getExporters(*FE, SM.getFileManager())) | ||
Exporters.push(Export); | ||
|
||
if (auto Verbatim = PI->getPublic(FE); !Verbatim.empty()) { | ||
if (auto Verbatim = PI->getPublic(*FE); !Verbatim.empty()) { | ||
Results.emplace_back(Verbatim, | ||
Hints::PublicHeader | Hints::PreferredHeader); | ||
break; | ||
} | ||
if (PI->isSelfContained(FE) || FID == SM.getMainFileID()) | ||
if (PI->isSelfContained(*FE) || FID == SM.getMainFileID()) | ||
break; | ||
|
||
// Walkup the include stack for non self-contained headers. | ||
FID = SM.getDecomposedIncludedLoc(FID).first; | ||
FE = SM.getFileEntryForID(FID); | ||
FE = SM.getFileEntryRefForID(FID); | ||
IsOrigin = false; | ||
} | ||
// Now traverse provider trees rooted at exporters. | ||
|
@@ -219,12 +219,12 @@ llvm::SmallVector<Hinted<Header>> findHeaders(const SymbolLocation &Loc, | |
// being exported in this header. | ||
std::set<const FileEntry *> SeenExports; | ||
This comment has been minimized.
Sorry, something went wrong.
sam-mccall
Collaborator
|
||
while (!Exporters.empty()) { | ||
auto *Export = Exporters.front(); | ||
FileEntryRef Export = Exporters.front(); | ||
Exporters.pop(); | ||
if (!SeenExports.insert(Export).second) // In case of cyclic exports | ||
continue; | ||
Results.emplace_back(Export, isPublicHeader(Export, *PI)); | ||
for (const auto *Export : PI->getExporters(Export, SM.getFileManager())) | ||
for (FileEntryRef Export : PI->getExporters(Export, SM.getFileManager())) | ||
Exporters.push(Export); | ||
} | ||
return Results; | ||
|
2 comments
on commit 98e6deb
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 realize this is part of a wider cleanup, but this is a meaningful design change to structures that have been carefully designed (the choice to avoid FileEntryRef here was deliberate) and actively maintained (we did already Include to FileEntryRef, where it made conceptual sense).
I don't think this was appropriate to submit without review, and it needs some further changes to be sufficiently clear.
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.
Point well-taken. Can you clarify why was FileEntryRef
avoided in the first place? I don't see how it conflicts with the desired semantics here, except for making the reported name less arbitrary.
Do the changes you imply consist of anything else besides adding comments and tests?
this is a significant conceptual change, and needs to be clearly documented
The intent has always been that Header/Physical corresponds to a single file (inode identity).
We do occasionally rely on being able to spell that file through some arbitrary spelling: this is the contract of FileEntry, but not of FileEntryRef: usually that signifies having the "right name", and a false guarantee of having the "right name" tends to lead us into bugs.
If there's a goal of removing this arbitrary-spelling functionality from FileEntry, then we can probably define Header so it still has FileEntry identity, but exposes some arbitrary name that was used to resolve the
#include
- I think that's what's been implemented here.