[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2020-03-02 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 247615.
hokein added a comment.

rebase to master.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/RenameMain.cpp
  clang-tools-extra/clangd/eval-rename/eval-rename.py
  clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt

Index: clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
@@ -0,0 +1,16 @@
+# normal functions
+clang-tools-extra/clangd/XRefs.h clang::clangd::findReferences clangd
+# normal class methods
+clang-tools-extra/clangd/index/Index.h clang::clangd::SwapIndex::reset clangd
+# normal classes
+clang-tools-extra/clangd/index/Index.h clang::clangd::SymbolIndex clangd
+clang-tools-extra/clangd/ClangdServer.h clang::clangd::ClangdServer clangd
+clang-tools-extra/clangd/GlobalCompilationDatabase.h clang::clangd::GlobalCompilationDatabase clangd
+clang-tools-extra/clangd/GlobalCompilationDatabase.h clang::clangd::OverlayCDB clangd
+clang-tools-extra/clangd/Protocol.h clang::clangd::CodeAction clangd
+# rename enum
+clang-tools-extra/clangd/index/Ref.h clang::clangd::RefKind clangd
+# rename enum constants
+clang-tools-extra/clangd/FindTarget.h clang::clangd::DeclRelation::Alias clangd
+# class with template constructors
+clang-tools-extra/clangd/index/MemIndex.h clang::clangd::MemIndex clangd
\ No newline at end of file
Index: clang-tools-extra/clangd/eval-rename/eval-rename.py
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/eval-rename.py
@@ -0,0 +1,88 @@
+#!/usr/bin/python
+"""
+A script to perform cross-file rename and evalute the results.
+
+Usage:
+
+$ cd /llvm-project
+$ ninja -C build clangd-indexer
+$ ./build/bin/clangd-indexer -format=binary -executor=all-TUs . > llvm-index.idx
+$ ninja -C build clangd-rename
+$ clang-tools-extra/clangd/eval-rename/eval-rename.py --index=llvm-index.idx --file=clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
+"""
+
+from __future__ import print_function
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+import tempfile
+
+RENAME_EXECUTOR='build/bin/clangd-rename'
+
+def Run(cmd):
+  s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  print('>', ' '.join(cmd))
+  [stdout, stderr] = s.communicate()
+  return (s.returncode, stdout, stderr)
+
+if __name__ == '__main__':
+  if not os.getcwd().endswith('llvm-project'):
+sys.exit('The tool must be run from llvm-project/ root.')
+
+  ap = argparse.ArgumentParser()
+  ap.add_argument(
+  '-f',
+  '--file',
+  required=True,
+  help='A file containing rename symbols to be evaluted.'
+  )
+  ap.add_argument(
+  '-idx',
+  '--index',
+  required=True,
+  help='A path to the index file'
+  )
+  args = ap.parse_args()
+
+  with open(args.file) as f:
+out = f.read()
+  test_cases = [line.strip().split() for line in out.split('\n') \
+ if line and not line.startswith('#') and line.strip()]
+
+  log_output_dir = tempfile.mkdtemp(prefix='eval-rename_')
+  success_cnt = 0
+  for file_name, rename_symbol, verify_target in test_cases:
+Run(['git', 'reset', '--hard'])
+execute_rename_cmd = [
+  RENAME_EXECUTOR,
+   '--index-path=%s' % args.index,
+   '--rename-symbol=%s' % rename_symbol,
+   '-fix',
+   file_name,
+]
+rename_results = Run(execute_rename_cmd)
+if rename_results[0] != 0:
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_RenameFailed'), 'w')
+  log_file.write(rename_results[1]) # stdout
+  log_file.write(rename_results[2]) # stderr
+  log_file.close()
+  continue
+
+build_results = Run(['ninja', '-C', 'build', verify_target])
+if build_results[0] != 0:
+  print('failed on renaming %s' % rename_symbol)
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_BuildFailed'), 'w')
+  log_file.write(build_results[1]) # stdout
+  log_file.write(build_results[2]) # stderr
+  log_file.close()
+  continue
+print('succeed on renaming %s' % rename_symbol)
+success_cnt += 1
+  Run(['git', 'reset', '--hard'])
+  print('Evaluated rename on %d symbols, %d symbol succeeded, go %s for failure logs' %
+  (len(test_cases), success_cnt, log_output_dir))
Index: clang-tools-extra/clangd/eval-rename/RenameMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/RenameMain.cpp
@@ -0,0 +1,208 @@
+//===--- RenameMain.cpp --*- C++-*-===//
+//
+// Part of 

[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2020-02-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

> Also, the llvm::Twine fails too, many of the failures are related to the 
> forward declarations (I think the problem is that they are treated 
> differently from the original symbol and are not being renamed at all in the 
> corresponding files, but that's just my guess). It`s probably a good idea to 
> keep track of all the entries that can break global rename in some issue on 
> the Github so that they're not lost?

Yeap, that sounds good to me. Just create an issue, and put all details there, 
attach the detailed log would be helpful. I suspect we may encounter bugs in 
xrefs/rename code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2020-02-12 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

In D71110#1871896 , @hokein wrote:

> Thanks for the feedback!
>
> Yeah, currently template classes are not supported in cross-file rename, see 
> https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clangd/refactor/Rename.cpp#L187.
>
> So `llvm::Optional` and `llvm::Optional` should fail to rename, but StringRef 
> and llvm::None should work (if you remove the hard-coded max limit 50).


Ah, I see, thank you for the explanation! I think it would be super useful to 
have the error message reflecting that!

Also, the `llvm::Twine` fails too, many of the failures are related to the 
forward declarations (I think the problem is that they are treated differently 
from the original symbol and are not being renamed at all in the corresponding 
files, but that's just my guess). It`s probably a good idea to keep track of 
all the entries that can break global rename in some issue on the Github so 
that they're not lost?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2020-02-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks for the feedback!

Yeah, currently template classes are not supported in cross-file rename, see 
https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clangd/refactor/Rename.cpp#L187.

So `llvm::Optional` and `llvm::Optional` should fail to rename, but StringRef 
and llvm::None should work (if you remove the hard-coded max limit 50).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2020-02-12 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

Renaming `llvm::Optional` also fails (clangd-rename says the symbol is not of a 
supported kind even though it's a class).

Renaming `llvm::None` is also not working: there seem to be many problems but a 
lot of them are connected with function's argument default values (`void 
foo(llvm::Optional Bar = None`).

  llvm/include/llvm/ADT/Optional.h llvm::Optional clangd
  llvm/include/llvm/ADT/None.h llvm::None clangd


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2020-02-11 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

Thanks! Now I can build it.

I was able to get some rename failures through this tool, though :( I had to 
disable the check for number of affected files first, but then this seems to be 
problematic:

  llvm/include/llvm/ADT/ArrayRef.h llvm::ArrayRef clangd
  llvm/include/llvm/ADT/StringRef.h llvm::StringRef clangd


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2020-02-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 243768.
hokein marked 3 inline comments as done.
hokein added a comment.

- rebase to master
- fix the breakage of the rename tool
- add more symbol to the tests
- some tweaks on the python script


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/RenameMain.cpp
  clang-tools-extra/clangd/eval-rename/eval-rename.py
  clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt

Index: clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
@@ -0,0 +1,16 @@
+# normal functions
+clang-tools-extra/clangd/XRefs.h clang::clangd::findReferences clangd
+# normal class methods
+clang-tools-extra/clangd/index/Index.h clang::clangd::SwapIndex::reset clangd
+# normal classes
+clang-tools-extra/clangd/index/Index.h clang::clangd::SymbolIndex clangd
+clang-tools-extra/clangd/ClangdServer.h clang::clangd::ClangdServer clangd
+clang-tools-extra/clangd/GlobalCompilationDatabase.h clang::clangd::GlobalCompilationDatabase clangd
+clang-tools-extra/clangd/GlobalCompilationDatabase.h clang::clangd::OverlayCDB clangd
+clang-tools-extra/clangd/Protocol.h clang::clangd::CodeAction clangd
+# rename enum
+clang-tools-extra/clangd/index/Ref.h clang::clangd::RefKind clangd
+# rename enum constants
+clang-tools-extra/clangd/FindTarget.h clang::clangd::DeclRelation::Alias clangd
+# class with template constructors
+clang-tools-extra/clangd/index/MemIndex.h clang::clangd::MemIndex clangd
\ No newline at end of file
Index: clang-tools-extra/clangd/eval-rename/eval-rename.py
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/eval-rename.py
@@ -0,0 +1,88 @@
+#!/usr/bin/python
+"""
+A script to perform cross-file rename and evalute the results.
+
+Usage:
+
+$ cd /llvm-project
+$ ninja -C build clangd-indexer
+$ ./build/bin/clangd-indexer -format=binary -executor=all-TUs . > llvm-index.idx
+$ ninja -C build clangd-rename
+$ clang-tools-extra/clangd/eval-rename/eval-rename.py --index=llvm-index.idx --file=clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
+"""
+
+from __future__ import print_function
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+import tempfile
+
+RENAME_EXECUTOR='build/bin/clangd-rename'
+
+def Run(cmd):
+  s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  print('>', ' '.join(cmd))
+  [stdout, stderr] = s.communicate()
+  return (s.returncode, stdout, stderr)
+
+if __name__ == '__main__':
+  if not os.getcwd().endswith('llvm-project'):
+sys.exit('The tool must be run from llvm-project/ root.')
+
+  ap = argparse.ArgumentParser()
+  ap.add_argument(
+  '-f',
+  '--file',
+  required=True,
+  help='A file containing rename symbols to be evaluted.'
+  )
+  ap.add_argument(
+  '-idx',
+  '--index',
+  required=True,
+  help='A path to the index file'
+  )
+  args = ap.parse_args()
+
+  with open(args.file) as f:
+out = f.read()
+  test_cases = [line.strip().split() for line in out.split('\n') \
+ if line and not line.startswith('#') and line.strip()]
+
+  log_output_dir = tempfile.mkdtemp(prefix='eval-rename_')
+  success_cnt = 0
+  for file_name, rename_symbol, verify_target in test_cases:
+Run(['git', 'reset', '--hard'])
+execute_rename_cmd = [
+  RENAME_EXECUTOR,
+   '--index-path=%s' % args.index,
+   '--rename-symbol=%s' % rename_symbol,
+   '-fix',
+   file_name,
+]
+rename_results = Run(execute_rename_cmd)
+if rename_results[0] != 0:
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_RenameFailed'), 'w')
+  log_file.write(rename_results[1]) # stdout
+  log_file.write(rename_results[2]) # stderr
+  log_file.close()
+  continue
+
+build_results = Run(['ninja', '-C', 'build', verify_target])
+if build_results[0] != 0:
+  print('failed on renaming %s' % rename_symbol)
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_BuildFailed'), 'w')
+  log_file.write(build_results[1]) # stdout
+  log_file.write(build_results[2]) # stderr
+  log_file.close()
+  continue
+print('succeed on renaming %s' % rename_symbol)
+success_cnt += 1
+  Run(['git', 'reset', '--hard'])
+  print('Evaluated rename on %d symbols, %d symbol succeeded, go %s for failure logs' %
+  (len(test_cases), success_cnt, log_output_dir))
Index: clang-tools-extra/clangd/eval-rename/RenameMain.cpp
===
--- /dev/null
+++ 

[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2020-02-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

sorry for the delay, I just saw the comment today.

In D71110#1799960 , @kbobyrev wrote:

> For some reason, running this patch on a recent version of the source tree 
> fails. The AST parsing fails with fatal diagnostics, but I can't understand 
> why:
>
>   E[15:14:33.084] source file unknown type name 'PathRef' is illformed: 1
>   E[15:15:02.831] source file unknown type name 'NestedNameSpecifierLoc'; did 
> you mean 'std::clang::NestedNameSpecifierLoc'? is illformed: 1
>   E[15:14:02.912] source file unknown type name 'Location' is illformed: 1
>   E[15:14:47.797] source file 'index' is not a class, namespace, or 
> enumeration is illformed: 1
>   E[15:14:17.658] source file no template named 'vector' in namespace 'std' 
> is illformed: 1
>


I encountered the same error when rebasing to master. It was work before. To 
parse the file correctly, we need to inject the clang builtin header directory 
(via `resource-dir`) to the compile command, it was done by OverlayCDB, but 
there was a patch changing this behavior in December, which broke the tool.
It should be fixed now.




Comment at: clang-tools-extra/clangd/eval-rename/eval-rename.py:1
+#!/usr/bin/python
+"""

kbobyrev wrote:
> It probably makes sense to migrate this to Python 3 instead (shouldn't be too 
> hard, from what I can see there are Python 2 print statements, but nothing 
> else I can find).
good point.



Comment at: clang-tools-extra/clangd/eval-rename/eval-rename.py:21
+
+RENAME_EXECUTOR='build/bin/clangd-rename'
+

kbobyrev wrote:
> Would be useful to add an argument to the build directory, I typically don't 
> put `build/` into `llvm/`.
yeah. the current script currently assumes the directory layout:

```
llvm-project
  - build/
- bin/...
  - clang-tools-extra
  - ...
```



Comment at: clang-tools-extra/clangd/eval-rename/eval-rename.py:82
+success_cnt += 1
+  Run(['git', 'reset', '--hard'])
+  print 'Evaluated rename on %d symbols, %d symbol succeeded, go %s for 
failure logs' % (

kbobyrev wrote:
> `git reset --hard` might be dangerous if compile-commands are symlinked to 
> the build directory: `ninja -C build` would re-generate them and `git reset 
> --hard` will e.g. erase `add_subdirectory(eval-rename)` if it's not 
> committed. Maybe this should be mentioned somewhere in the comments/user 
> guide.
agree. it is dangerous, the script is expected to be ran on a clean client. we 
could improve it, e.g. prompt a confirm dialog, or abandon if  there are dirty 
changes in the client. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2019-12-31 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

For some reason, running this patch on a recent version of the source tree 
fails. The AST parsing fails with fatal diagnostics, but I can't understand why:

  E[15:14:33.084] source file unknown type name 'PathRef' is illformed: 1
  E[15:15:02.831] source file unknown type name 'NestedNameSpecifierLoc'; did 
you mean 'std::clang::NestedNameSpecifierLoc'? is illformed: 1
  E[15:14:02.912] source file unknown type name 'Location' is illformed: 1
  E[15:14:47.797] source file 'index' is not a class, namespace, or enumeration 
is illformed: 1
  E[15:14:17.658] source file no template named 'vector' in namespace 'std' is 
illformed: 1

I've had many unsuccessful attempts to track down the bug and use multiple 
different configurations (i.e. I thought something might be wrong with my index 
location or directory structure, so in the end I replicated the setup that I 
can infer from the code), but I still didn't manage to run the renames.

In order to make it easier for you to understand what went wrong I have logged 
my commands and output so that one could understand what happens. I've tried 
several versions of LLVM, the log is for the most recent one, 
https://github.com/kirillbobyrev/llvm-project/commit/c7dc4734d23f45f576ba5af2aae5be9dfa2d3643.
 I've made sure to run `check-all` to validate correctness of source tree and 
to generate all test files so that indexer does not crash. I've made sure that 
all the commands ran without any errors.

Because the output is quite verbose, I'm submitting another file which only 
lists the commands instead of the one with verbose output. If you need the full 
log, please let me know. Attached file: F11162505: log.txt 


Please let me know if I have done something incorrectly.




Comment at: clang-tools-extra/clangd/eval-rename/RenameMain.cpp:34
+static llvm::cl::opt
+Fix("fix", llvm::cl::desc("Apply the rename edits to disk files"),
+llvm::cl::init(false));

Maybe just `Apply`? `Fix` seems slightly confusing.



Comment at: clang-tools-extra/clangd/eval-rename/eval-rename.py:1
+#!/usr/bin/python
+"""

It probably makes sense to migrate this to Python 3 instead (shouldn't be too 
hard, from what I can see there are Python 2 print statements, but nothing else 
I can find).



Comment at: clang-tools-extra/clangd/eval-rename/eval-rename.py:11
+$ ninja -C build clangd-rename
+$ clang-tools-extra/clangd/eval-rename/eval-rename.py --index=llvm-index.idx 
--file=clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
+"""

Maybe some comments regarding what each field in `symbol_to_rename.txt` 
corresponds to and how it is parsed would be useful.



Comment at: clang-tools-extra/clangd/eval-rename/eval-rename.py:21
+
+RENAME_EXECUTOR='build/bin/clangd-rename'
+

Would be useful to add an argument to the build directory, I typically don't 
put `build/` into `llvm/`.



Comment at: clang-tools-extra/clangd/eval-rename/eval-rename.py:23
+
+def Run(cmd):
+  s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

nit: `run`?



Comment at: clang-tools-extra/clangd/eval-rename/eval-rename.py:82
+success_cnt += 1
+  Run(['git', 'reset', '--hard'])
+  print 'Evaluated rename on %d symbols, %d symbol succeeded, go %s for 
failure logs' % (

`git reset --hard` might be dangerous if compile-commands are symlinked to the 
build directory: `ninja -C build` would re-generate them and `git reset --hard` 
will e.g. erase `add_subdirectory(eval-rename)` if it's not committed. Maybe 
this should be mentioned somewhere in the comments/user guide.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2019-12-06 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: pass - 60496 tests passed, 0 failed and 726 were skipped.

Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2019-12-06 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: pass - 60496 tests passed, 0 failed and 726 were skipped.

Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2019-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 232554.
hokein added a comment.

Fix empty lines.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/RenameMain.cpp
  clang-tools-extra/clangd/eval-rename/eval-rename.py
  clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt

Index: clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
@@ -0,0 +1,5 @@
+clang-tools-extra/clangd/XRefs.h clang::clangd::findReferences clangd
+clang-tools-extra/clangd/index/Index.h clang::clangd::SymbolIndex clangd
+clang-tools-extra/clangd/ClangdServer.h clang::clangd::ClangdServer clangd
+clang-tools-extra/clangd/index/Ref.h clang::clangd::RefKind clangd
+clang-tools-extra/clangd/FindTarget.h clang::clangd::DeclRelation::Alias clangd
Index: clang-tools-extra/clangd/eval-rename/eval-rename.py
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/eval-rename.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+"""
+A script to perform cross-file rename and evalute the results.
+
+Usage:
+
+$ cd /llvm-project
+$ ninja -C build clangd-indexer
+$ ./build/bin/clangd-indexer -format=binary -executor=all-TUs . > llvm-index.idx
+$ ninja -C build clangd-rename
+$ clang-tools-extra/clangd/eval-rename/eval-rename.py --index=llvm-index.idx --file=clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
+"""
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+import tempfile
+
+RENAME_EXECUTOR='build/bin/clangd-rename'
+
+def Run(cmd):
+  s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  print '>', ' '.join(cmd)
+  [stdout, stderr] = s.communicate()
+  return (s.returncode, stdout, stderr)
+
+if __name__ == '__main__':
+  if not os.getcwd().endswith('llvm-project'):
+sys.exit('The tool must be run from llvm-project/ root.')
+
+  ap = argparse.ArgumentParser()
+  ap.add_argument(
+  '-f',
+  '--file',
+  required=True,
+  help='A file containing rename symbols to be evaluted.'
+  )
+  ap.add_argument(
+  '-idx',
+  '--index',
+  required=True,
+  help='A path to the index file'
+  )
+  args = ap.parse_args()
+
+  with open(args.file) as f:
+out = f.read()
+  test_cases = [line.strip().split() for line in out.split('\n') if line.strip()]
+
+  log_output_dir = tempfile.mkdtemp(prefix='eval-rename_')
+  success_cnt = 0
+  for file_name, rename_symbol, verify_target in test_cases:
+Run(['git', 'reset', '--hard'])
+execute_rename_cmd = [
+  RENAME_EXECUTOR,
+   '--index-path=%s' % args.index,
+   '--rename-symbol=%s' % rename_symbol,
+   '-fix',
+   file_name,
+]
+rename_results = Run(execute_rename_cmd)
+if rename_results[0] != 0:
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_RenameFailed'), 'w')
+  log_file.write(rename_results[1]) # stdout
+  log_file.write(rename_results[2]) # stderr
+  log_file.close()
+  continue
+
+build_results = Run(['ninja', '-C', 'build', verify_target])
+if build_results[0] != 0:
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_BuildFailed'), 'w')
+  log_file.write(build_results[1]) # stdout
+  log_file.write(build_results[2]) # stderr
+  log_file.close()
+  continue
+
+success_cnt += 1
+  Run(['git', 'reset', '--hard'])
+  print 'Evaluated rename on %d symbols, %d symbol succeeded, go %s for failure logs' % (
+len(test_cases), success_cnt, log_output_dir)
Index: clang-tools-extra/clangd/eval-rename/RenameMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/RenameMain.cpp
@@ -0,0 +1,198 @@
+//===--- RenameMain.cpp --*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Compiler.h"
+#include "FS.h"
+#include "FSProvider.h"
+#include "FindTarget.h"
+#include "GlobalCompilationDatabase.h"
+#include "Logger.h"
+#include "ParsedAST.h"
+#include "SourceCode.h"
+#include "index/MemIndex.h"
+#include "index/Serialization.h"
+#include "refactor/Rename.h"
+#include "clang/AST/Decl.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/ReplacementsYaml.h"
+#include "llvm/ADT/STLExtras.h"
+

[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2019-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 232553.
hokein added a comment.

add more symbols.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/RenameMain.cpp
  clang-tools-extra/clangd/eval-rename/eval-rename.py
  clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt

Index: clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
@@ -0,0 +1,5 @@
+clang-tools-extra/clangd/XRefs.h clang::clangd::findReferences clangd
+clang-tools-extra/clangd/index/Index.h clang::clangd::SymbolIndex clangd
+clang-tools-extra/clangd/ClangdServer.h clang::clangd::ClangdServer clangd
+clang-tools-extra/clangd/index/Ref.h clang::clangd::RefKind clangd
+clang-tools-extra/clangd/FindTarget.h clang::clangd::DeclRelation::Alias clangd
\ No newline at end of file
Index: clang-tools-extra/clangd/eval-rename/eval-rename.py
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/eval-rename.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+"""
+A script to perform cross-file rename and evalute the results.
+
+Usage:
+
+$ cd /llvm-project
+$ ninja -C build clangd-indexer
+$ ./build/bin/clangd-indexer -format=binary -executor=all-TUs . > llvm-index.idx
+$ ninja -C build clangd-rename
+$ clang-tools-extra/clangd/eval-rename/eval-rename.py --index=llvm-index.idx --file=clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
+"""
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+import tempfile
+
+RENAME_EXECUTOR='build/bin/clangd-rename'
+
+def Run(cmd):
+  s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  print '>', ' '.join(cmd)
+  [stdout, stderr] = s.communicate()
+  return (s.returncode, stdout, stderr)
+
+if __name__ == '__main__':
+  if not os.getcwd().endswith('llvm-project'):
+sys.exit('The tool must be run from llvm-project/ root.')
+
+  ap = argparse.ArgumentParser()
+  ap.add_argument(
+  '-f',
+  '--file',
+  required=True,
+  help='A file containing rename symbols to be evaluted.'
+  )
+  ap.add_argument(
+  '-idx',
+  '--index',
+  required=True,
+  help='A path to the index file'
+  )
+  args = ap.parse_args()
+
+  with open(args.file) as f:
+out = f.read()
+  test_cases = [line.strip().split() for line in out.split('\n') if line.strip()]
+
+  log_output_dir = tempfile.mkdtemp(prefix='eval-rename_')
+  success_cnt = 0
+  for file_name, rename_symbol, verify_target in test_cases:
+Run(['git', 'reset', '--hard'])
+execute_rename_cmd = [
+  RENAME_EXECUTOR,
+   '--index-path=%s' % args.index,
+   '--rename-symbol=%s' % rename_symbol,
+   '-fix',
+   file_name,
+]
+rename_results = Run(execute_rename_cmd)
+if rename_results[0] != 0:
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_RenameFailed'), 'w')
+  log_file.write(rename_results[1]) # stdout
+  log_file.write(rename_results[2]) # stderr
+  log_file.close()
+  continue
+
+build_results = Run(['ninja', '-C', 'build', verify_target])
+if build_results[0] != 0:
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_BuildFailed'), 'w')
+  log_file.write(build_results[1]) # stdout
+  log_file.write(build_results[2]) # stderr
+  log_file.close()
+  continue
+
+success_cnt += 1
+  Run(['git', 'reset', '--hard'])
+  print 'Evaluated rename on %d symbols, %d symbol succeeded, go %s for failure logs' % (
+len(test_cases), success_cnt, log_output_dir)
\ No newline at end of file
Index: clang-tools-extra/clangd/eval-rename/RenameMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/RenameMain.cpp
@@ -0,0 +1,198 @@
+//===--- RenameMain.cpp --*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Compiler.h"
+#include "FS.h"
+#include "FSProvider.h"
+#include "FindTarget.h"
+#include "GlobalCompilationDatabase.h"
+#include "Logger.h"
+#include "ParsedAST.h"
+#include "SourceCode.h"
+#include "index/MemIndex.h"
+#include "index/Serialization.h"
+#include "refactor/Rename.h"
+#include "clang/AST/Decl.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include 

[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2019-12-06 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: pass - 60496 tests passed, 0 failed and 726 were skipped.

Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71110/new/

https://reviews.llvm.org/D71110



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2019-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov, mgorny.
Herald added a project: clang.

This is a tool that helps us to evaluate the rename results, we may not
submit this tool to the code repository, but it has value, helps us find
out bugs in AST/Refs/Rename code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71110

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/RenameMain.cpp
  clang-tools-extra/clangd/eval-rename/eval-rename.py
  clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt

Index: clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
@@ -0,0 +1,4 @@
+clang-tools-extra/clangd/XRefs.h clang::clangd::findReferences clangd
+clang-tools-extra/clangd/index/Index.h clang::clangd::SymbolIndex clangd
+clang-tools-extra/clangd/ClangdServer.h clang::clangd::ClangdServer clangd
+clang-tools-extra/clangd/index/Ref.h clang::clangd::RefKind clangd
\ No newline at end of file
Index: clang-tools-extra/clangd/eval-rename/eval-rename.py
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/eval-rename.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+"""
+A script to perform cross-file rename and evalute the results.
+
+Usage:
+
+$ cd /llvm-project
+$ ninja -C build clangd-indexer
+$ ./build/bin/clangd-indexer -format=binary -executor=all-TUs . > llvm-index.idx
+$ ninja -C build clangd-rename
+$ clang-tools-extra/clangd/eval-rename/eval-rename.py --index=llvm-index.idx --file=clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
+"""
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+import tempfile
+
+RENAME_EXECUTOR='build/bin/clangd-rename'
+
+def Run(cmd):
+  s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  print '>', ' '.join(cmd)
+  [stdout, stderr] = s.communicate()
+  return (s.returncode, stdout, stderr)
+
+if __name__ == '__main__':
+  if not os.getcwd().endswith('llvm-project'):
+sys.exit('The tool must be run from llvm-project/ root.')
+
+  ap = argparse.ArgumentParser()
+  ap.add_argument(
+  '-f',
+  '--file',
+  required=True,
+  help='A file containing rename symbols to be evaluted.'
+  )
+  ap.add_argument(
+  '-idx',
+  '--index',
+  required=True,
+  help='A path to the index file'
+  )
+  args = ap.parse_args()
+
+  with open(args.file) as f:
+out = f.read()
+  test_cases = [line.strip().split() for line in out.split('\n') if line.strip()]
+
+  log_output_dir = tempfile.mkdtemp(prefix='eval-rename_')
+  success_cnt = 0
+  for file_name, rename_symbol, verify_target in test_cases:
+Run(['git', 'reset', '--hard'])
+execute_rename_cmd = [
+  RENAME_EXECUTOR,
+   '--index-path=%s' % args.index,
+   '--rename-symbol=%s' % rename_symbol,
+   '-fix',
+   file_name,
+]
+rename_results = Run(execute_rename_cmd)
+if rename_results[0] != 0:
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_RenameFailed'), 'w')
+  log_file.write(rename_results[1]) # stdout
+  log_file.write(rename_results[2]) # stderr
+  log_file.close()
+  continue
+
+build_results = Run(['ninja', '-C', 'build', verify_target])
+if build_results[0] != 0:
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_BuildFailed'), 'w')
+  log_file.write(build_results[1]) # stdout
+  log_file.write(build_results[2]) # stderr
+  log_file.close()
+  continue
+
+success_cnt += 1
+  Run(['git', 'reset', '--hard'])
+  print 'Evaluated rename on %d symbols, %d symbol succeeded, go %s for failure logs' % (
+len(test_cases), success_cnt, log_output_dir)
\ No newline at end of file
Index: clang-tools-extra/clangd/eval-rename/RenameMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/RenameMain.cpp
@@ -0,0 +1,198 @@
+//===--- RenameMain.cpp --*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Compiler.h"
+#include "FS.h"
+#include "FSProvider.h"
+#include "FindTarget.h"
+#include "GlobalCompilationDatabase.h"
+#include "Logger.h"
+#include "ParsedAST.h"
+#include "SourceCode.h"
+#include "index/MemIndex.h"
+#include "index/Serialization.h"
+#include "refactor/Rename.h"
+#include