Author: rupprecht Date: Wed Mar 20 15:51:56 2019 New Revision: 356623 URL: http://llvm.org/viewvc/llvm-project?rev=356623&view=rev Log: Revert "[clangd] Print arguments in template specializations"
This reverts commit 44a63f6a150dec72dea43730d2a89d292e58bd6f. It segfaults on an internal test case (will follow up off thread). Modified: clang-tools-extra/trunk/clangd/AST.cpp clang-tools-extra/trunk/clangd/index/MemIndex.cpp clang-tools-extra/trunk/clangd/index/dex/Dex.cpp clang-tools-extra/trunk/unittests/clangd/DexTests.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/AST.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=356623&r1=356622&r2=356623&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/AST.cpp (original) +++ clang-tools-extra/trunk/clangd/AST.cpp Wed Mar 20 15:51:56 2019 @@ -11,12 +11,9 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclTemplate.h" -#include "clang/AST/TemplateBase.h" -#include "clang/AST/TypeLoc.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Index/USRGeneration.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ScopedPrinter.h" @@ -53,22 +50,6 @@ SourceLocation findNameLoc(const clang:: return SM.getSpellingLoc(D->getLocation()); } -static llvm::Optional<llvm::ArrayRef<TemplateArgumentLoc>> -getTemplateSpecializationArgLocs(const NamedDecl &ND) { - if (auto *Func = llvm::dyn_cast<FunctionDecl>(&ND)) { - if (auto *Args = Func->getTemplateSpecializationArgsAsWritten()) - return Args->arguments(); - } else if (auto *Cls = - llvm::dyn_cast<ClassTemplatePartialSpecializationDecl>(&ND)) { - if (auto *Args = Cls->getTemplateArgsAsWritten()) - return Args->arguments(); - } else if (auto *Var = llvm::dyn_cast<VarTemplateSpecializationDecl>(&ND)) - return Var->getTemplateArgsInfo().arguments(); - // We return None for ClassTemplateSpecializationDecls because it does not - // contain TemplateArgumentLoc information. - return llvm::None; -} - std::string printQualifiedName(const NamedDecl &ND) { std::string QName; llvm::raw_string_ostream OS(QName); @@ -79,19 +60,6 @@ std::string printQualifiedName(const Nam // namespaces to query: the preamble doesn't have a dedicated list. Policy.SuppressUnwrittenScope = true; ND.printQualifiedName(OS, Policy); - if (auto Args = getTemplateSpecializationArgLocs(ND)) - printTemplateArgumentList(OS, *Args, Policy); - else if (auto *Cls = llvm::dyn_cast<ClassTemplateSpecializationDecl>(&ND)) { - if (auto STL = Cls->getTypeAsWritten() - ->getTypeLoc() - .getAs<TemplateSpecializationTypeLoc>()) { - llvm::SmallVector<TemplateArgumentLoc, 8> ArgLocs; - ArgLocs.reserve(STL.getNumArgs()); - for (unsigned I = 0; I < STL.getNumArgs(); ++I) - ArgLocs.push_back(STL.getArgLoc(I)); - printTemplateArgumentList(OS, ArgLocs, Policy); - } - } OS.flush(); assert(!StringRef(QName).startswith("::")); return QName; Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=356623&r1=356622&r2=356623&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Wed Mar 20 15:51:56 2019 @@ -38,6 +38,15 @@ bool MemIndex::fuzzyFind( for (const auto Pair : Index) { const Symbol *Sym = Pair.second; + // FIXME: Enable fuzzy find on template specializations once we start + // storing template arguments in the name. Currently we only store name for + // class template, which would cause duplication in the results. + if (Sym->SymInfo.Properties & + (static_cast<index::SymbolPropertySet>( + index::SymbolProperty::TemplateSpecialization) | + static_cast<index::SymbolPropertySet>( + index::SymbolProperty::TemplatePartialSpecialization))) + continue; // Exact match against all possible scopes. if (!Req.AnyScope && !llvm::is_contained(Req.Scopes, Sym->Scope)) continue; Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=356623&r1=356622&r2=356623&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Wed Mar 20 15:51:56 2019 @@ -86,6 +86,15 @@ void Dex::buildIndex() { llvm::DenseMap<Token, std::vector<DocID>> TempInvertedIndex; for (DocID SymbolRank = 0; SymbolRank < Symbols.size(); ++SymbolRank) { const auto *Sym = Symbols[SymbolRank]; + // FIXME: Enable fuzzy find on template specializations once we start + // storing template arguments in the name. Currently we only store name for + // class template, which would cause duplication in the results. + if (Sym->SymInfo.Properties & + (static_cast<index::SymbolPropertySet>( + index::SymbolProperty::TemplateSpecialization) | + static_cast<index::SymbolPropertySet>( + index::SymbolProperty::TemplatePartialSpecialization))) + continue; for (const auto &Token : generateSearchTokens(*Sym)) TempInvertedIndex[Token].push_back(SymbolRank); } Modified: clang-tools-extra/trunk/unittests/clangd/DexTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DexTests.cpp?rev=356623&r1=356622&r2=356623&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/DexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/DexTests.cpp Wed Mar 20 15:51:56 2019 @@ -714,30 +714,35 @@ TEST(DexTest, TemplateSpecialization) { SymbolSlab::Builder B; Symbol S = symbol("TempSpec"); + S.ID = SymbolID("0"); B.insert(S); - S = symbol("TempSpec<int, bool>"); + S = symbol("TempSpec"); + S.ID = SymbolID("1"); S.SymInfo.Properties = static_cast<index::SymbolPropertySet>( index::SymbolProperty::TemplateSpecialization); B.insert(S); - S = symbol("TempSpec<int, U>"); + S = symbol("TempSpec"); + S.ID = SymbolID("2"); S.SymInfo.Properties = static_cast<index::SymbolPropertySet>( index::SymbolProperty::TemplatePartialSpecialization); B.insert(S); auto I = dex::Dex::build(std::move(B).build(), RefSlab()); FuzzyFindRequest Req; + Req.Query = "TempSpec"; Req.AnyScope = true; - Req.Query = "TempSpec"; - EXPECT_THAT(match(*I, Req), - UnorderedElementsAre("TempSpec", "TempSpec<int, bool>", - "TempSpec<int, U>")); - - Req.Query = "TempSpec<int"; - EXPECT_THAT(match(*I, Req), - UnorderedElementsAre("TempSpec<int, bool>", "TempSpec<int, U>")); + std::vector<Symbol> Symbols; + I->fuzzyFind(Req, [&Symbols](const Symbol &Sym) { Symbols.push_back(Sym); }); + EXPECT_EQ(Symbols.size(), 1U); + EXPECT_FALSE(Symbols.front().SymInfo.Properties & + static_cast<index::SymbolPropertySet>( + index::SymbolProperty::TemplateSpecialization)); + EXPECT_FALSE(Symbols.front().SymInfo.Properties & + static_cast<index::SymbolPropertySet>( + index::SymbolProperty::TemplatePartialSpecialization)); } } // namespace Modified: clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp?rev=356623&r1=356622&r2=356623&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp Wed Mar 20 15:51:56 2019 @@ -187,30 +187,35 @@ TEST(MemIndexTest, TemplateSpecializatio SymbolSlab::Builder B; Symbol S = symbol("TempSpec"); + S.ID = SymbolID("0"); B.insert(S); - S = symbol("TempSpec<int, bool>"); + S = symbol("TempSpec"); + S.ID = SymbolID("1"); S.SymInfo.Properties = static_cast<index::SymbolPropertySet>( index::SymbolProperty::TemplateSpecialization); B.insert(S); - S = symbol("TempSpec<int, U>"); + S = symbol("TempSpec"); + S.ID = SymbolID("2"); S.SymInfo.Properties = static_cast<index::SymbolPropertySet>( index::SymbolProperty::TemplatePartialSpecialization); B.insert(S); auto I = MemIndex::build(std::move(B).build(), RefSlab()); FuzzyFindRequest Req; + Req.Query = "TempSpec"; Req.AnyScope = true; - Req.Query = "TempSpec"; - EXPECT_THAT(match(*I, Req), - UnorderedElementsAre("TempSpec", "TempSpec<int, bool>", - "TempSpec<int, U>")); - - Req.Query = "TempSpec<int"; - EXPECT_THAT(match(*I, Req), - UnorderedElementsAre("TempSpec<int, bool>", "TempSpec<int, U>")); + std::vector<Symbol> Symbols; + I->fuzzyFind(Req, [&Symbols](const Symbol &Sym) { Symbols.push_back(Sym); }); + EXPECT_EQ(Symbols.size(), 1U); + EXPECT_FALSE(Symbols.front().SymInfo.Properties & + static_cast<index::SymbolPropertySet>( + index::SymbolProperty::TemplateSpecialization)); + EXPECT_FALSE(Symbols.front().SymInfo.Properties & + static_cast<index::SymbolPropertySet>( + index::SymbolProperty::TemplatePartialSpecialization)); } TEST(MergeIndexTest, Lookup) { Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=356623&r1=356622&r2=356623&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Wed Mar 20 15:51:56 2019 @@ -394,80 +394,23 @@ TEST_F(SymbolCollectorTest, Template) { Annotations Header(R"( // Primary template and explicit specialization are indexed, instantiation // is not. - template <class X> class $barclasstemp[[Bar]] {}; - template <class T, class U, template<typename> class Z, int Q> - struct [[Tmpl]] { T $xdecl[[x]] = 0; }; - - // template-template, non-type and type full spec - template <> struct $specdecl[[Tmpl]]<int, bool, Bar, 3> {}; - - // template-template, non-type and type partial spec - template <class U, int T> struct $partspecdecl[[Tmpl]]<bool, U, Bar, T> {}; - // instantiation - extern template struct Tmpl<float, bool, Bar, 8>; - // instantiation - template struct Tmpl<double, bool, Bar, 2>; - - template <typename ...> class $fooclasstemp[[Foo]] {}; - // parameter-packs full spec - template<> class $parampack[[Foo]]<Bar<int>, int, double> {}; - // parameter-packs partial spec - template<class T> class $parampackpartial[[Foo]]<T, T> {}; - - template <int ...> class $bazclasstemp[[Baz]] {}; - // non-type parameter-packs full spec - template<> class $parampacknontype[[Baz]]<3, 5, 8> {}; - // non-type parameter-packs partial spec - template<int T> class $parampacknontypepartial[[Baz]]<T, T> {}; - - template <template <class> class ...> class $fozclasstemp[[Foz]] {}; - // template-template parameter-packs full spec - template<> class $parampacktempltempl[[Foz]]<Bar, Bar> {}; - // template-template parameter-packs partial spec - template<template <class> class T> - class $parampacktempltemplpartial[[Foz]]<T, T> {}; + template <class T, class U> struct [[Tmpl]] {T $xdecl[[x]] = 0;}; + template <> struct $specdecl[[Tmpl]]<int, bool> {}; + template <class U> struct $partspecdecl[[Tmpl]]<bool, U> {}; + extern template struct Tmpl<float, bool>; + template struct Tmpl<double, bool>; )"); runSymbolCollector(Header.code(), /*Main=*/""); - EXPECT_THAT(Symbols.size(), 14U); - EXPECT_THAT( - Symbols, - AllOf( - Contains(AllOf(QName("Tmpl"), DeclRange(Header.range()), - ForCodeCompletion(true))), - Contains(AllOf(QName("Bar"), DeclRange(Header.range("barclasstemp")), - ForCodeCompletion(true))), - Contains(AllOf(QName("Foo"), DeclRange(Header.range("fooclasstemp")), - ForCodeCompletion(true))), - Contains(AllOf(QName("Baz"), DeclRange(Header.range("bazclasstemp")), - ForCodeCompletion(true))), - Contains(AllOf(QName("Foz"), DeclRange(Header.range("fozclasstemp")), - ForCodeCompletion(true))), - Contains(AllOf(QName("Tmpl<int, bool, Bar, 3>"), - DeclRange(Header.range("specdecl")), - ForCodeCompletion(false))), - Contains(AllOf(QName("Tmpl<bool, U, Bar, T>"), - DeclRange(Header.range("partspecdecl")), - ForCodeCompletion(false))), - Contains(AllOf(QName("Foo<Bar<int>, int, double>"), - DeclRange(Header.range("parampack")), - ForCodeCompletion(false))), - Contains(AllOf(QName("Foo<T, T>"), - DeclRange(Header.range("parampackpartial")), - ForCodeCompletion(false))), - Contains(AllOf(QName("Baz<3, 5, 8>"), - DeclRange(Header.range("parampacknontype")), - ForCodeCompletion(false))), - Contains(AllOf(QName("Baz<T, T>"), - DeclRange(Header.range("parampacknontypepartial")), - ForCodeCompletion(false))), - Contains(AllOf(QName("Foz<Bar, Bar>"), - DeclRange(Header.range("parampacktempltempl")), - ForCodeCompletion(false))), - Contains(AllOf(QName("Foz<T, T>"), - DeclRange(Header.range("parampacktempltemplpartial")), - ForCodeCompletion(false))), - Contains(AllOf(QName("Tmpl::x"), DeclRange(Header.range("xdecl")), - ForCodeCompletion(false))))); + EXPECT_THAT(Symbols, + UnorderedElementsAre( + AllOf(QName("Tmpl"), DeclRange(Header.range()), + ForCodeCompletion(true)), + AllOf(QName("Tmpl"), DeclRange(Header.range("specdecl")), + ForCodeCompletion(false)), + AllOf(QName("Tmpl"), DeclRange(Header.range("partspecdecl")), + ForCodeCompletion(false)), + AllOf(QName("Tmpl::x"), DeclRange(Header.range("xdecl")), + ForCodeCompletion(false)))); } TEST_F(SymbolCollectorTest, ObjCSymbols) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits