[clang] Clang-Refactor (PR #94855)
=?utf-8?b?0JjQs9C90LDRgiDQodC10YDQsw=?=, =?utf-8?b?0JjQs9C90LDRgiDQodC10YDQsw=?Message-ID: In-Reply-To: bartlettroscoe wrote: > I would love to hear some thoughts on it #123782 Moreover, i have some (very > simple and not very useful) refactoring actions based on those rules, test > support for source location option, and tests that cover location option, and > these actions; all of that is not included in linked PR @IgnatSergeev, thanks for the response! We will definitely look at #123782 and provide some feedback. https://github.com/llvm/llvm-project/pull/94855 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Clang-Refactor (PR #94855)
=?utf-8?b?0JjQs9C90LDRgiDQodC10YDQsw=?=, =?utf-8?b?0JjQs9C90LDRgiDQodC10YDQsw=?Message-ID: In-Reply-To: bartlettroscoe wrote: @IgnatSergeev, no-one ever commented on this PR? We are interested in potentially extending this `clang-refactor` tool. Any suggestions or advance on doing so? (You can contact me directly at raba...@sandia.gov.) https://github.com/llvm/llvm-project/pull/94855 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-refactor] Add Matcher Edit refactoring rule (PR #123782)
=?utf-8?b?0JjQs9C90LDRgiDQodC10YDQsw=?=, =?utf-8?b?0JjQs9C90LDRgiDQodC10YDQsw=?Message-ID: In-Reply-To: bartlettroscoe wrote: @IgnatSergeev, thanks for the detailed information on the clang-refactor testing infrastructure. We will try to run these tests and dig in deeper to see how the testing system works. > I could add every piece of code related to those Refactoring Actions and > tests here, and later remove them if needed. No need for unnecessary work. We just appreciate your willingness to help answer our questions š I have been looking for other PRs that extend clang-refactor, but it is hard to find them. There is not even a GitHub Issue label `clang-refactor`, so it is hard to find PRs and Issues specific to that tool. (Unlike for the tools with labels [`clang-tidy`](https://github.com/llvm/llvm-project/labels/clang-tidy) and [`clang-format`](https://github.com/llvm/llvm-project/labels/clang-format).) > P. S. I'm using some Refactoring Engine terms here, if you are not sure, I > recommend reading these docs > [clang.llvm.org/docs/RefactoringEngine.html](https://clang.llvm.org/docs/RefactoringEngine.html) Thanks! We have been looking that over. Do you know why so few refactorings are supported in the `clang-refactor` tool or the [`clangd`](https://github.com/clangd/vscode-clangd/blob/master/README.md#refactoring) tool? For example, the `extract` function refactoring seems to only extracts a new function from a given range of code in a larger function. It does not seem refactor the larger original function to call the new extracted function (which is one of the most important parts of the classic ["Extract Method" refactoring](https://refactoring.guru/extract-method)). (We can't seem to find any examples of the usage of extract function. We determined this gap by experimentation.) It seems that LLMV/Clang LibTool could support an endless set of refactorings (due to arbitrary AST changes), but there seems to be very limited user-ready refactorings supported by tools in the llvm-project repo itself. I know that major companies are using LLVM/Clang LibTool to do large refctorings. Are these companies mostly just developing their own proprietary in-house refactoring tools based on LLVM/Clang LibTool? https://github.com/llvm/llvm-project/pull/123782 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-refactor] Add Matcher Edit refactoring rule (PR #123782)
=?utf-8?b?0JjQs9C90LDRgiDQodC10YDQsw=?=, =?utf-8?b?0JjQs9C90LDRgiDQodC10YDQsw=?Message-ID: In-Reply-To: bartlettroscoe wrote: @IgnatSergeev, thanks for the reply! > You were right about the amount of refactorings that LibTool could support > And actually AST transformations are already supported in clang-transformer > tool and its library So is this really transforming the AST? According to: * https://clang.llvm.org/docs/ClangTransformerTutorial.html#rewriting-asts-to-text it says: > The astute reader may have noticed that weāve been somewhat vague in our > explanation of what the rewrite rules are actually rewriting. Weāve referred > to ācodeā, but code can be represented both as raw source text and as an > abstract syntax tree. So, which one is it? > > **Ideally, weād be rewriting the input AST to a new AST, but clangās AST is > not terribly amenable to this kind of transformation.** So, we compromise: we > express our patterns and the names that they bind in terms of the AST, **but > our changes in terms of source code text**. Weāve designed Transformerās > language to bridge the gap between the two representations, in an attempt to > minimize the userās need to reason about source code locations and other, > low-level syntactic details. > so the clang-refactor tool is abandoned as i could tell Furthermore, > transformer is the main tool (or actually library) for transformations in > clang-tidy Just an FYI, we have found that the Apple fork of the llvm-project repo appears to have some additional C++ refactoring tooling that is used by the XCode IDE: * https://github.com/swiftlang/llvm-project/tree/next/clang/tools For example, there appears to be an "Extract Function" refactor that might actually be able to refactor real C++ code the exectuable: * https://github.com/swiftlang/llvm-project/blob/next/clang/tools/clang-refactor-test/ClangRefactorTest.cpp We have not done an in-depth evaluation of this capability yet, but it looks promising. > So i would recommend reading about them, and searching through their code, > maybe you could find some of the refactorings already implemented for those > tools And i could be wrong, but everyone mostly uses transformer to implement > their own refactorings privately, as sad for open source as it may sound Are people using clang-transformer for more than just [clang-tidy "FixIt" checks](https://clang.llvm.org/docs/ClangTransformerTutorial.html#using-a-rewriterule-as-a-clang-tidy-check)? I have done some initial searches and I can't seem to find anything other than just clang-tidy FixIts. The question is how his does this clang transformer mapping of AST to source code work for larger chucks of C++ code, like for "Extract Function"? FYI: We are starting to look at the LLNL ROSE Outliner tool: * https://github.com/rose-compiler/rose/wiki/Publications#effective-source-to-source-outlining-to-support-whole-program-empirical-optimization which is supposed to be able to implement a robust C++ "Extract Function" refactoring. Or, perhaps everyone is waiting for better AI to be able to refactor C++ automatically? https://github.com/llvm/llvm-project/pull/123782 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits