-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][include-cleaner]skip stdlib recogntion only when there are defintion with body in main file. #95797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
[clang][include-cleaner]skip stdlib recogntion only when there are defintion with body in main file. #95797
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't think it's actually "right" layering-wise to perform any
sourcelocation <-> fileidmappings here. it's subtle and expensive, especially for every-redecl of stdlib symbols, which might be forward declared many times in STL (but also for any other symbol).Hence we actually have logic down the line that maps sourcelocations to files (it's also expensive today, but is in a single place and takes care of edge cases, like macros). at least this layering ensures that if we want to introduce caching/optimizations one day, we can rely on having certain separation between different kinds of mappings.
Moreover, I don't follow the check around a redeclaration having body only in the main file. I feel like you're focusing on a very specific issue you have and not solving the issue in general. e.g. what if the user only has forward declaration of the symbol in the main file? why don't we want to suppress in that case? or what if the user has body/declaration in a different header file, which also seems pretty common.
I think if you want to improve this case, you really need to address
// FIXME: Should we also provide physical locations?, which is definitely doable, we just need to make sure ranking is still done accordingly.I am still strongly arguing that we should never insert a custom header if there's a name-collision with a stdlib symbol. Hence we should make sure all physical locations for a stdlib symbol is downranked, i'd recommend stripping completesymbol signal from these symbols.
You also need to consider the macro-side of this. you're addressing this situation for decls, but the user might as well have
#define assert(X) Xin their main file (or some of the other headers). we need to make sure this same logic also works for that.Uh oh!
There was an error while loading. Please reload this page.
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.
Agree. This patch is a temporary fix to avoid breaking it for a long time. I think avoiding to include decl which already in the same file is always fine.
And I agree we need to consider more about how to handle this case elegantly because std library use more and more short name function which make it harder to avoid to use the same name.
I think more about this issue today. In my opinion, the basic requirements should be:
So the priority should be: decl in user written file > stdlib recognition > other found.
WDYT? If you also agree this high level feature request, then we can think about implement more detail.
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.
glad to hear that we're aligned here!
decl in user written file > stdlib recognition > other found.makes sense to me in theory, but i don't think it's implementable in practice. moreover i don't understand what the 3rd category around "other" means.telling apart a "physical" stdlib header (e.g.
<__utility/pair.h>) from a user header (e.g.<my_stdlib/pair.h>) isn't possible. hence when something goes wrong, we'll always "insert" the wrong header (implementation detail, rather than public header for a stdlib symbol).Hence I'd suggest going with:
clang::tooling::stdlib::Header)This means we might do the wrong thing when the user has their own stdlib implementation (mixing your own symbols with standard library is a recipe for disaster, i don't think we need to care about that state). But we'll at least stop complaining once they include the "right" header. Moreover if need be we can improve handling for this case by turning of virtual stdlib support completely, when we detect we're working in an environment with a custom stdlib implementaiton.
WDYT?
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 aggree it is not possible to identifier the user-defined stdlib with stdlib. But it is possible to identifier user-defined function with stdlib function which may have totally difference meanings. e.g.
logto print something andlogin<cmath>We may distinguish them by quota include or angle brackets? Since normally c++ developer will only use
#include <>for system header file butinclude ""for the other file.