This is an archive of the discontinued LLVM Phabricator instance.

[clang-rename] Do not print out error message upon encountering multiple replacements in the same SourceLocation.
AbandonedPublic

Authored by omtcyfz on Sep 26 2016, 7:35 AM.

Details

Reviewers
None
Summary

clang-rename might sometimes have multiple replacements at one SourceLocation, both trying to perform the same renaming. While this issue should be addressed properly at some point, for now it's fine to prevent clang-rename from printing out the error message to prevent confusion as it works just fine even if the error happens.

Diff Detail

Event Timeline

omtcyfz updated this revision to Diff 72483.Sep 26 2016, 7:35 AM
omtcyfz retitled this revision from to [clang-rename] Do not print out error message upon encountering multiple replacements in the same SourceLocation..
omtcyfz updated this object.
omtcyfz added a reviewer: alexfh.
omtcyfz added a subscriber: cfe-commits.
arphaman added inline comments.
clang-rename/RenamingAction.cpp
75

s/ingore/ignore/

76

Did you mean to use 'the' instead of 'there' here?

omtcyfz updated this revision to Diff 72511.Sep 26 2016, 10:06 AM
omtcyfz marked 2 inline comments as done.

Address two comments.

@arphaman, thank you for the comments! Improved the wording.

alexfh requested changes to this revision.Sep 26 2016, 4:07 PM
alexfh edited edge metadata.
alexfh added inline comments.
clang-rename/RenamingAction.cpp
73

Did you mean "adding a replacement fails..."?

75

"Specific header"? What exactly does it mean here?

This revision now requires changes to proceed.Sep 26 2016, 4:07 PM
omtcyfz updated this revision to Diff 72604.Sep 26 2016, 11:25 PM
omtcyfz edited edge metadata.
omtcyfz marked 2 inline comments as done.

Address two comments from Alex.

alexander-shaposhnikov added inline comments.
clang-rename/RenamingAction.cpp
74

Let's consider the following example:
src/include/Point.h:

struct Point {};

src/a.cpp:

include <Point.h>

src/b.cpp:

include <Point.h>

clang-rename -qualified-name Point -new-name Point2 srcs/a.cpp srcs/b.cpp
Renaming failed in /Users/Alexshap/PlayRename/srcs/./include/Point.h! New replacement:
/Users/Alexshap/PlayRename/srcs/./include/Point.h: 7:+5:"Point2"
conflicts with existing replacement:
/Users/Alexshap/PlayRename/srcs/./include/Point.h: 7:+5:"Point2"

The thing is that clang-rename is trying to modify the same code twice (as in the example) and the return value (Error) of the method Replacements::add doesn't allow us to distinguish two cases: A. conflict (trying to apply different modifications to the same source code) B. (still conflict, but different) (trying to apply the same modification twice).
In the past when Replacements was a typedef on std::set and clang-rename was using insert(...) the case B wasn't an issue.
P.S. However (imo) the new (FIXME) comment seems to be a little bit misleading.

omtcyfz added inline comments.Sep 27 2016, 12:17 AM
clang-rename/RenamingAction.cpp
74

But the thing is that it's never the A. case. Unlike other refactorings, clang-rename doesn't introduce any name conflicts, it will only sometimes try to rename something multiple times.

clang-rename/RenamingAction.cpp
74

Yup

omtcyfz updated this revision to Diff 72616.Sep 27 2016, 1:57 AM
omtcyfz edited edge metadata.

Slightly change wording.

clang-rename/RenamingAction.cpp
74

Hence, I'm not sure what your concern is. Can you please elaborate?

clang-rename/RenamingAction.cpp
74

My concerns were about wording, the new version looks good to me.
I think the long-term fix would be to improve the interface of the class Replacements,
but it's clearly not in the scope of this patch (the other tools have the same issue),
so to me your diff is OK.

omtcyfz added inline comments.Sep 27 2016, 12:38 PM
clang-rename/RenamingAction.cpp
74

Eric actually has a patch for that: https://reviews.llvm.org/D24800

omtcyfz abandoned this revision.Sep 28 2016, 6:11 AM

Abandoning this, because rL282577, which introduces replacement deduplication, eliminates this issue. Big thanks to Eric!