This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add a symbol-name-based blacklist for rename.
ClosedPublic

Authored by hokein on Jan 27 2020, 1:48 AM.

Details

Summary

This patch adds a simple mechanism to disallow global rename
on std symbols. We might extend it to other symbols, e.g. protobuf.

Diff Detail

Event Timeline

hokein created this revision.Jan 27 2020, 1:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2020, 1:48 AM

Unit tests: pass. 62202 tests passed, 0 failed and 815 were skipped.

clang-tidy: fail. clang-tidy found 0 errors and 1 warnings. 1 of them are added as review comments below (why?).

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

kadircet added inline comments.Jan 27 2020, 2:42 AM
clang-tools-extra/clangd/refactor/Rename.cpp
145–146

nit: maybe just if (!shouldCollectSymbol...) return nonindexable; ?

474

locateDeclAt is already working on NamedDecls but returning a set of Decls could you rather update that helper to return a set of NamedDecls instead?

clang-tools-extra/clangd/refactor/RenameBlacklist.cpp
14 ↗(On Diff #240497)

I don't think there's much value in having that in its own file, could you move it into the rename.cpp ?

clang-tools-extra/clangd/unittests/RenameTests.cpp
454

maybe SCOPEDT_TRACE(T) instead?

hokein updated this revision to Diff 240528.Jan 27 2020, 4:56 AM
hokein marked 5 inline comments as done.

address comments.

hokein updated this revision to Diff 240529.Jan 27 2020, 4:58 AM

update the code.

clang-tools-extra/clangd/refactor/Rename.cpp
474

I think the main problem is that NamedDecl->getCanonicalDecl() returns a Decl*, which we need to do a dyn_cast.

clang-tools-extra/clangd/refactor/RenameBlacklist.cpp
14 ↗(On Diff #240497)

I thought we will extend this in the near future, moved to rename.cpp now as it is pretty short.

clang-tools-extra/clangd/unittests/RenameTests.cpp
454

good point, reverted the change in this patch, and will do this in a separate patch.

Unit tests: pass. 62202 tests passed, 0 failed and 815 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

Unit tests: pass. 62202 tests passed, 0 failed and 815 were skipped.

clang-tidy: pass.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

Harbormaster failed remote builds in B44986: Diff 240529!
kadircet added inline comments.Jan 27 2020, 7:25 AM
clang-tools-extra/clangd/refactor/Rename.cpp
148

maybe move comment to be above if statement, and clang-format

474

ah right, but still it should be safe to perform just an llvm:cast here, as a NamedDecl shouldn't have an unnamed decl as its canonical declaration.

hokein updated this revision to Diff 240822.Jan 28 2020, 3:25 AM
hokein marked an inline comment as done.

move the comment.

hokein marked an inline comment as done.Jan 28 2020, 3:25 AM
hokein added inline comments.
clang-tools-extra/clangd/refactor/Rename.cpp
474

a NamedDecl shouldn't have an unnamed decl as its canonical declaration.

yeah, this is true for most cases, but it is not safe, we have corn cases, see the comment in SymbolCollector about ObjCPropertyDecl.

Unit tests: pass. 62202 tests passed, 0 failed and 815 were skipped.

clang-tidy: pass.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

kadircet added inline comments.Jan 28 2020, 4:33 AM
clang-tools-extra/clangd/refactor/Rename.cpp
148

looks like it is still not clang-formatted

474

I don't think that's relevant in here though, it is performing the cast on a Decl. It is the ASTNode.OrigD that has been populated by libIndex.
So it doesn't need to be related with whatever nameddecl is being processed.

Am I missing something?

hokein updated this revision to Diff 240853.Jan 28 2020, 6:08 AM
hokein marked an inline comment as done.

address comment.

clang-tools-extra/clangd/refactor/Rename.cpp
474

ah, you are right. I thought ASTNode.OrigD was the decl getting from getCanonicalDecl, but it turns out not.

I also checked with the Decl::getCanonicalDecl default implementation, if the Decl subclass doesn't override this method, it just returns itself. so it is safe for NamedDecl.

kadircet accepted this revision.Jan 28 2020, 6:37 AM
kadircet added inline comments.
clang-tools-extra/clangd/refactor/Rename.cpp
225

nit: maybe revert this one?

This revision is now accepted and ready to land.Jan 28 2020, 6:37 AM

Unit tests: pass. 62202 tests passed, 0 failed and 815 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.