This is an archive of the discontinued LLVM Phabricator instance.

Change the implementation of tooling::Replacements to std::vector.
AbandonedPublic

Authored by ioeric on Jun 15 2016, 8:31 AM.

Details

Reviewers
klimek
djasper
Summary

Change the implementation of tooling::Replacements to std::vector.

Pair programmed with Martin Böhme!

Diff Detail

Event Timeline

ioeric updated this revision to Diff 60839.Jun 15 2016, 8:31 AM
ioeric retitled this revision from to Change the implementation of tooling::Replacements to std::vector..
ioeric updated this object.
klimek added inline comments.Jun 15 2016, 8:36 AM
lib/Tooling/Core/Replacement.cpp
141

Why?

211–212

Ah, so, I believe this is exactly what we're trying to get rid of:
Making applyAllReplacements always unique / unstable-sort doesn't help with the underlying problem, which is that we have some edit sequences we cannot express (which I believe this change is all about).
For example:
insert(0, "a"), insert(0, "a") might want to insert "a" 2 times at 0
insert(0, "a"), insert(0, "b"), insert(0, "a") leads to a different end-state depending on the sort order.

ioeric added a subscriber: mboehme.
ioeric updated this revision to Diff 60843.Jun 15 2016, 8:47 AM
ioeric marked an inline comment as done.
  • Remove shiftedCodePositionInternal.
lib/Tooling/Core/Replacement.cpp
141

Previously, there are two implementations of shiftedCodePosition, and both call this template function. Now that there is only one version, we can get rid of the template.

211

This ensures that the behavior is the same as the std::set version of Replacements.

ioeric added inline comments.Jun 15 2016, 8:49 AM
lib/Tooling/Core/Replacement.cpp
211–212

Ah, I see. So, what we want is actually stable_sort without deduplicating?

ioeric added inline comments.Jun 15 2016, 8:52 AM
lib/Tooling/Core/Replacement.cpp
211–212

Hmm, we might need more than that. I'm looking into this.

ioeric updated this revision to Diff 60956.Jun 16 2016, 3:20 AM
  • Preserve applyAllReplacements' behavior with sorting+deduplicating.
ioeric added inline comments.Jun 16 2016, 3:26 AM
lib/Tooling/Core/Replacement.cpp
210–211

As per offline discussion with Manuel, we will preserve the behavior of applyAllReplacements as before (std::set version) with sorting and deduplicating for now. For the problems above (i.e. allowing identical replacements), we might want to create a new set of interfaces (possibly) without preprocessing replacements before applying them and let users ensure that replacements are correct by themselves.

ioeric updated this revision to Diff 61076.Jun 17 2016, 2:52 AM
  • Make callers responsile for deduplicate replacements before calling applyAllReplacements.
ioeric updated this revision to Diff 61081.Jun 17 2016, 5:50 AM
  • Make LessNoPath consistent with operator< for tooling::Replacement.
mboehme added inline comments.Jun 17 2016, 6:10 AM
include/clang/Format/Format.h
784

Add "///" at beginning of line? (I.e. make this an empty comment line, not a plain empty line.)

lib/Tooling/Core/Replacement.cpp
209

I think "Replaces" can go back to being a const reference. (We originally changed this to pass-by-value because we were sorting the replacements inside the function, but we're no longer doing that.)

223–224

Again, I think "Replaces" can go back to being a const reference here.

ioeric updated this revision to Diff 61087.Jun 17 2016, 6:16 AM
ioeric marked 5 inline comments as done.
  • Make applyAllReplcements take const reference Replaces again.
include/clang/Format/Format.h
784

Thanks for the catches! :)