[PATCH] D47944: Add support for arrays (and structure that use naked pointers for their iterator, like std::array) in performance-implicit-conversion-in-loop

2018-06-08 Thread Alex Pilkiewicz via Phabricator via cfe-commits
pilki created this revision.
pilki added a reviewer: alexfh.
Herald added subscribers: cfe-commits, jkorous.

Add support for arrays (and structure that use naked pointers for their 
iterator, like std::array) in performance-implicit-conversion-in-loop.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47944

Files:
  clangd/CodeComplete.cpp
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -193,6 +193,7 @@
 
 TEST(CompletionTest, Filter) {
   std::string Body = R"cpp(
+#define FooBarMacro
 int Abracadabra;
 int Alakazam;
 struct S {
@@ -202,7 +203,8 @@
 };
   )cpp";
   EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
-  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux";
+  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+Not(Has("Qux";
 
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -1015,6 +1015,15 @@
 return std::move(Top).items();
   }
 
+  Optional fuzzyScore(const CompletionCandidate &C) {
+// Macros can be very spammy, so we only support prefix completion.
+// We won't end up with underfull index results, as macros are sema-only.
+if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+!C.Name.startswith_lower(Filter->pattern()))
+  return None;
+return Filter->match(C.Name);
+  }
+
   // Scores a candidate and adds it to the TopN structure.
   void addCandidate(TopN &Candidates,
 const CodeCompletionResult *SemaResult,
@@ -1027,7 +1036,7 @@
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-if (auto FuzzyScore = Filter->match(C.Name))
+if (auto FuzzyScore = fuzzyScore(C))
   Relevance.NameMatch = *FuzzyScore;
 else
   return;


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -193,6 +193,7 @@
 
 TEST(CompletionTest, Filter) {
   std::string Body = R"cpp(
+#define FooBarMacro
 int Abracadabra;
 int Alakazam;
 struct S {
@@ -202,7 +203,8 @@
 };
   )cpp";
   EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
-  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux";
+  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+Not(Has("Qux";
 
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -1015,6 +1015,15 @@
 return std::move(Top).items();
   }
 
+  Optional fuzzyScore(const CompletionCandidate &C) {
+// Macros can be very spammy, so we only support prefix completion.
+// We won't end up with underfull index results, as macros are sema-only.
+if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+!C.Name.startswith_lower(Filter->pattern()))
+  return None;
+return Filter->match(C.Name);
+  }
+
   // Scores a candidate and adds it to the TopN structure.
   void addCandidate(TopN &Candidates,
 const CodeCompletionResult *SemaResult,
@@ -1027,7 +1036,7 @@
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-if (auto FuzzyScore = Filter->match(C.Name))
+if (auto FuzzyScore = fuzzyScore(C))
   Relevance.NameMatch = *FuzzyScore;
 else
   return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47945: Add support for arrays in performance-implicit-conversion-in-loop

2018-06-08 Thread Alex Pilkiewicz via Phabricator via cfe-commits
pilki created this revision.
pilki added a reviewer: alexfh.
Herald added a subscriber: cfe-commits.

Add support for arrays (and structure that use naked pointers for their 
iterator, like std::array) in performance-implicit-conversion-in-loop


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47945

Files:
  clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
  clang-tidy/performance/ImplicitConversionInLoopCheck.h
  test/clang-tidy/performance-implicit-conversion-in-loop.cpp

Index: test/clang-tidy/performance-implicit-conversion-in-loop.cpp
===
--- test/clang-tidy/performance-implicit-conversion-in-loop.cpp
+++ test/clang-tidy/performance-implicit-conversion-in-loop.cpp
@@ -40,7 +40,7 @@
 template 
 class OperatorWrapper {
  public:
-  explicit OperatorWrapper(const T& t);
+  OperatorWrapper() = delete;
 };
 
 struct SimpleClass {
@@ -101,61 +101,97 @@
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the loop variable 'foo' is different from the one returned by the iterator and generates an implicit conversion; you can either change the type to the matching one ('const SimpleClass &' but 'const auto&' is always a valid option) or remove the reference to make it explicit that you are creating a new value [performance-implicit-conversion-in-loop]
   // for (ImplicitWrapper& foo : SimpleView()) {}
   for (const ImplicitWrapper foo : SimpleView()) {}
-  for (ImplicitWrapperfoo : SimpleView()) {}
+  for (ImplicitWrapper foo : SimpleView()) {}
 }
 
 void ImplicitSimpleClassRefIterator() {
   for (const ImplicitWrapper& foo : SimpleRefView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
   // for (ImplicitWrapper& foo : SimpleRefView()) {}
   for (const ImplicitWrapper foo : SimpleRefView()) {}
-  for (ImplicitWrapperfoo : SimpleRefView()) {}
+  for (ImplicitWrapper foo : SimpleRefView()) {}
+}
+
+void ImplicitSimpleClassArray() {
+  SimpleClass array[5];
+  for (const ImplicitWrapper& foo : array) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
+  // for (ImplicitWrapper& foo : array) {}
+  for (const ImplicitWrapper foo : array) {}
+  for (ImplicitWrapper foo : array) {}
 }
 
 void ImplicitComplexClassIterator() {
   for (const ImplicitWrapper& foo : ComplexView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
   // for (ImplicitWrapper& foo : ComplexView()) {}
   for (const ImplicitWrapper foo : ComplexView()) {}
-  for (ImplicitWrapperfoo : ComplexView()) {}
+  for (ImplicitWrapper foo : ComplexView()) {}
 }
 
 void ImplicitComplexClassRefIterator() {
+  ComplexClass array[5];
+  for (const ImplicitWrapper& foo : array) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
+  // for (ImplicitWrapper& foo : array) {}
+  for (const ImplicitWrapper foo : array) {}
+  for (ImplicitWrapper foo : array) {}
+}
+
+void ImplicitComplexClassArray() {
   for (const ImplicitWrapper& foo : ComplexRefView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
   // for (ImplicitWrapper& foo : ComplexRefView()) {}
   for (const ImplicitWrapper foo : ComplexRefView()) {}
-  for (ImplicitWrapperfoo : ComplexRefView()) {}
+  for (ImplicitWrapper foo : ComplexRefView()) {}
 }
 
 void OperatorSimpleClassIterator() {
   for (const OperatorWrapper& foo : SimpleView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
   // for (OperatorWrapper& foo : SimpleView()) {}
   for (const OperatorWrapper foo : SimpleView()) {}
-  for (OperatorWrapperfoo : SimpleView()) {}
+  for (OperatorWrapper foo : SimpleView()) {}
 }
 
 void OperatorSimpleClassRefIterator() {
   for (const OperatorWrapper& foo : SimpleRefView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
   // for (OperatorWrapper& foo : SimpleRefView()) {}
   for (const OperatorWrapper foo : SimpleRefView()) {}
-  for (OperatorWrapperfoo : SimpleRefView()) {}
+  for (OperatorWrapper foo : SimpleRefView()) {}
+}
+
+void OperatorSimpleClassArray() {
+  SimpleClass array[5];
+  for (const OperatorWrapper& foo : array) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
+  // for (OperatorWrapper& foo : array) {}
+  for (const OperatorWrapper foo : array) {}
+  for (OperatorWrapper foo : array) {}
 }
 
 void OperatorComplexClassIterator() {
   for (const OperatorWrapper& foo : ComplexView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
   // for (OperatorWrapper& foo : ComplexView()) {}
   for (const OperatorWrapper foo : ComplexView()) {}
-  for (OperatorWrapperfoo : ComplexView()) {}
+  for (Ope

[PATCH] D47945: Add support for arrays in performance-implicit-conversion-in-loop

2018-06-10 Thread Alex Pilkiewicz via Phabricator via cfe-commits
pilki added a comment.

Thanks Alex!

I do not have the submit right, can you take care of it?

Thanks


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47945



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