Finds instances where the user depends on internal details and warns them against doing so.
Should not be run on internal Abseil files or Abseil source code.
Details
Diff Detail
Event Timeline
Why not to use dependencies instead of deps in check's name?
docs/ReleaseNotes.rst | ||
---|---|---|
55 | Please remove this line. | |
58 | Please add first statement from documentation. | |
docs/clang-tidy/checks/abseil-no-internal-deps.rst | ||
7 | May be just Warns instead of This check gives users a warning? Also misspelled dpened. | |
7 | Abseil. | |
17 | Please remove empty line. | |
24 | Please add new line at end. |
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
25 | Actually that one is generally useful. Accessing the foo::internal from outside of foo is always a problem. Maybe this matcher can become configurable or just match on any internal access from outside the enclosing namespace. | |
clang-tidy/abseil/NoInternalDepsCheck.h | ||
22 | Please make this a full sentence, like This check should not be run on internal ... (if that is grammatically correct) |
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
25 | That's a good idea. While we agree, right now our efforts are focused on releasing abseil specific functions. Perhaps we can refactor this check at a later time. |
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
25 | Ok. Could you please add a TODO or FIXME that it is not forgotten? |
Thank you for your first contribution to LLVM btw :)
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
25 | Missing // | |
36 | Please follow the LLVM naming convention (s/initr_dep/InternalDependency/ or similar) https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly |
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
25 | Also, we don't add developer names to comments. | |
40โ42 | Diagnostic text is not supposed to be grammatically correct with capitalization and punctuation. Please do not put links into diagnostics. It's more appropriate for this to be in the documentation. I think this might be improved wording: do not reference the 'internal' namespace; those implementation details are reserved to Abeil or something along those lines. | |
clang-tidy/abseil/NoInternalDepsCheck.h | ||
20โ22 | Can you re-flow these comments? | |
docs/clang-tidy/checks/abseil-no-internal-deps.rst | ||
7 | Please wrap lines to 80 cols. Nothing in this check looks at filenames and paths, but this suggests the check will find those. Is that intended work that's missed in this patch, or are the docs incorrect? |
docs/clang-tidy/checks/abseil-no-internal-deps.rst | ||
---|---|---|
7 | Please provide a link for the abseil guideline. | |
test/clang-tidy/abseil-no-internal-deps.cpp | ||
3 | nit: please make sure the code follow LLVM code style, even for test code :) | |
12 | Since we have multiple abseil checks that might use these fake abseil declarations, I'd suggest pull out these to a common header, and include it in this test file. |
test/clang-tidy/abseil-no-internal-deps.cpp | ||
---|---|---|
3 | CHECK-MESSAGE can be on one line, even if its longer (that is common in the clang-tidy tests). But dont use many empty lines and respect naming conventions and run clang-format over the code (except there is a valid reason that the formatting would infer with the tested logic). | |
12 | yes, there is one other similar case hicpp-signed-bitwise-standard-types.h |
test/clang-tidy/abseil-no-internal-deps.cpp | ||
---|---|---|
3 | Do my function names have to be verbs, they're not doing anything. I could rename InternalFunction to something like InternallyProcessString annd StringFunction to process String |
test/clang-tidy/abseil-no-internal-deps.cpp | ||
---|---|---|
3 | It helps if you somehow show the "topic of the function". But I wrote some tests, that did not strictly follow and they passed review too ;) Foo is just too generic, sth like DirectAccess, FriendUsage, OpeningNamespace or so is already telling and I guess good enough :) |
test/clang-tidy/abseil-no-internal-deps.cpp | ||
---|---|---|
6 | Please run clang-format over the test code as well. The braces here in FriendUsage miss a space. |
@hugoeg, it looks like you are waiting for review, but this patch doesn't include the IsExpansionInAbseilHeader matcher. What's your plan of it?
test/clang-tidy/abseil-fake-declarations.h | ||
---|---|---|
1 โ | (On Diff #160562) | I'd expect this header file is used as as a real absl library file:
This would make the lit test align with the real world case, and it could be helpful if you implement the IsExpansionInAbseilHeader matcher in this check. |
test/clang-tidy/abseil-no-internal-deps.cpp | ||
20 | the style doesn't looks correct to me. |
test/clang-tidy/abseil-fake-declarations.h | ||
---|---|---|
1 โ | (On Diff #160562) | My mentors on the absl team told me to refrain from using real absl function/class names as I did originally. They would prefer I use fake names. I'd be happy to update the filename something real like str_cat.h though I have been implementing IsExpansionInHeader for the past couple days and I hope to have it included on this patch by the end of the week. |
test/clang-tidy/abseil-no-internal-deps.cpp | ||
20 | This is the style given from clang-format |
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
22 | You can elide the braces for single stmt ifs | |
25 | Please dont use auto here as the typ is not clear | |
27 | ellide braces | |
30 | no auto plz | |
33 | Are the parens necessary? I think match does return a bool, then you can just return it without the braces. If not, please make it a boolean with an expression like match() > 0 or so. |
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
21 | I think we can make it as an ASTMatcher instead of a function like: AST_POLYMORPHIC_MATCHER_P(isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) { // your code here. } |
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
21 | Unfortunately, I do not think we can. That was the way I originally tried to implement it. It worked on no-namespace-check, but not in this one. This is because as an AST_POLYMORPHIC_MATCHER_P, we are trying to match an usage of a Decl, not the Decl itself and since we are matching a TypeLoc in no-internal-deps-check, not really the usage, it doesn't work. As a result, I modified my original implementation, which you will see in no-namespace-check and turned it into IsInAbseilFile(SourceManager&, SourceLocation), which is just takes a source location and returns whether the location we matched is in an Abseil file |
From my side not!
You still have unresolved comments that cause the revision to not be Ready To Review for the main reviewers, maybe that causes them to overlook it.
test/clang-tidy/abseil-no-internal-deps.cpp | ||
---|---|---|
3 | I think the names are ok. |
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
21 | Could you explain a bit more why it won't work? I don't understand why it doesn't work. Basically you define the matcher like: AST_POLYMORPHIC_MATCHER( isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) { auto &SourceManager = Finder->getASTContext().getSourceManager(); SourceLocation loc = Node.getBeginLoc(); if (loc.isInvalid()) return false; const FileEntry *FileEntry = SourceManager.getFileEntryForID(SourceManager.getFileID(loc)); if (!FileEntry) return false; StringRef Filename = FileEntry->getName(); llvm::Regex RE("absl/(base|container|debugging|memory|meta|numeric|strings|" "synchronization|types|utiliy)"); return RE.match(Filename); } And use it for example in your check Finder->addMatcher(nestedNameSpecifierLoc( loc(specifiesNamespace(namespaceDecl( matchesName("internal"), hasParent(namespaceDecl(hasName("absl")))))), unless(isInAbseilFile())) .bind("InternalDep"), this); | |
21 | nit: LLVM code guideline uses Camel for variable names. | |
27 | typo: utiliy => utility. | |
52 | nit: remove the empty line. | |
docs/clang-tidy/checks/abseil-no-internal-deps.rst | ||
9 | This sentence doesn't parse. | |
18 | nit: Please add a trailing comment on the line where it'd trigger the warning. | |
19 | nit: space between foo and {. |
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
21 | You're right, this implementation seems to work, I seemed to have a simple logic error in my original implementation, the new diff will include this version |
Your patch seems have some comments unaddressed but you marked done.
About the abseil matcher stuff, you and @deannagarcia have an overlap, maybe just wait for https://reviews.llvm.org/D50580 to submit, and reuse the matcher in this patch?
clang-tidy/abseil/NoInternalDepsCheck.cpp | ||
---|---|---|
25 | nit: loc => Loc |
Ok , so I've clean some stuff up, I'm currently working with @deannagarcia to get https://reviews.llvm.org/D50580 submitted with the matcher I implemented for us first, then will adjust this as necessary. Documentation has been added.
docs/clang-tidy/checks/abseil-no-internal-deps.rst | ||
---|---|---|
18 | I think this line is also triggered the warning? | |
test/clang-tidy/abseil-no-internal-deps.cpp | ||
9 | Does the test get passed on the first run RUN: %check_clang_tidy %s abseil-no-internal-deps %t, -- -- -I %S/Inputs of the test? It will suppress clang-tidy warnings from the header, and the warning here should not appear. |
fixed comments
test/clang-tidy/abseil-no-internal-deps.cpp | ||
---|---|---|
9 | Yes, the test passes cleanly on both runs, I just re ran it a couple times to make sure. |
Please rebase your patch, since the absl matcher patch is submitted. Thanks.
test/clang-tidy/abseil-no-internal-deps.cpp | ||
---|---|---|
9 | Yeah, I misread it as CHECK-MESSAGE. |
test/clang-tidy/Inputs/absl/external-file.h | ||
---|---|---|
1 โ | (On Diff #162864) | The file can not self-compile, and we should make it compilable. And put the newly-added code at the end of the file, so that other test file can keep unchanged. |
test/clang-tidy/Inputs/absl/strings/internal-file.h | ||
34 โ | (On Diff #162864) | nit: remove the empty line. |
test/clang-tidy/Inputs/absl/external-file.h | ||
---|---|---|
1 โ | (On Diff #162864) | how do I make it compilable? |
LGTM with a nit, thanks for your work.
clang-tidy/abseil/NoInternalDependenciesCheck.h | ||
---|---|---|
20 โ | (On Diff #162921) | This comment is out of date. The check can handle it, I think. |
Committed r340928. Thanks very much!
Will you (and your team) upstream even more abseil checks? I think it might be reasonable to ask for commit rights.
We will likely not be up streaming more in the near future. Possibly one or two. I am also an intern really close to being done, so it will probably not be worth applying for commit rights. Thank you though for all the help.
Ok. Then we can commit for you guys, no problem :)
Am 29.08.2018 um 16:34 schrieb Hugo Gonzalez via Phabricator:
hugoeg added a comment.
In https://reviews.llvm.org/D50542#1217517, @JonasToth wrote:
Committed r340928. Thanks very much!
Will you (and your team) upstream even more abseil checks? I think it might be reasonable to ask for commit rights.
We will likely not be up streaming more in the near future. Possibly one or two. I am also an intern really close to being done, so it will probably not be worth applying for commit rights. Thank you though for all the help.
Repository:
rL LLVM
Please make this a full sentence, like This check should not be run on internal ... (if that is grammatically correct)