Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (#59)
Browse files Browse the repository at this point in the history
  CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGOpenMPRuntime.cpp
  • Loading branch information
bader committed Feb 15, 2020
2 parents fd438ca + 1228d42 commit 7517d36
Show file tree
Hide file tree
Showing 336 changed files with 10,349 additions and 3,526 deletions.
3 changes: 1 addition & 2 deletions clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ int main(int argc, const char **argv) {
Error = false;
llvm::sys::Mutex IndexMutex;
// ExecutorConcurrency is a flag exposed by AllTUsExecution.h
llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
: ExecutorConcurrency);
llvm::ThreadPool Pool(llvm::hardware_concurrency(ExecutorConcurrency));
for (auto &Group : USRToBitcode) {
Pool.async([&]() {
std::vector<std::unique_ptr<doc::Info>> Infos;
Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clangd/CodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
return CompletionItemKind::Text;
case SK::Enum:
return CompletionItemKind::Enum;
// FIXME(ioeric): use LSP struct instead of class when it is suppoted in the
// protocol.
case SK::Struct:
return CompletionItemKind::Struct;
case SK::Class:
case SK::Protocol:
case SK::Extension:
Expand All @@ -102,18 +101,16 @@ CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
case SK::Using:
return CompletionItemKind::Reference;
case SK::Function:
// FIXME(ioeric): this should probably be an operator. This should be fixed
// when `Operator` is support type in the protocol.
case SK::ConversionFunction:
return CompletionItemKind::Function;
case SK::Variable:
case SK::Parameter:
case SK::NonTypeTemplateParm:
return CompletionItemKind::Variable;
case SK::Field:
return CompletionItemKind::Field;
// FIXME(ioeric): use LSP enum constant when it is supported in the protocol.
case SK::EnumConstant:
return CompletionItemKind::Value;
return CompletionItemKind::EnumMember;
case SK::InstanceMethod:
case SK::ClassMethod:
case SK::StaticMethod:
Expand All @@ -125,6 +122,9 @@ CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
return CompletionItemKind::Property;
case SK::Constructor:
return CompletionItemKind::Constructor;
case SK::TemplateTypeParm:
case SK::TemplateTemplateParm:
return CompletionItemKind::TypeParameter;
}
llvm_unreachable("Unhandled clang::index::SymbolKind.");
}
Expand Down
72 changes: 48 additions & 24 deletions clang-tools-extra/clangd/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,6 @@ std::string printDefinition(const Decl *D) {
return Definition;
}

void printParams(llvm::raw_ostream &OS,
const std::vector<HoverInfo::Param> &Params) {
for (size_t I = 0, E = Params.size(); I != E; ++I) {
if (I)
OS << ", ";
OS << Params.at(I);
}
}

std::string printType(QualType QT, const PrintingPolicy &Policy) {
// TypePrinter doesn't resolve decltypes, so resolve them here.
// FIXME: This doesn't handle composite types that contain a decltype in them.
Expand All @@ -133,6 +124,43 @@ std::string printType(QualType QT, const PrintingPolicy &Policy) {
return QT.getAsString(Policy);
}

std::string printType(const TemplateTypeParmDecl *TTP) {
std::string Res = TTP->wasDeclaredWithTypename() ? "typename" : "class";
if (TTP->isParameterPack())
Res += "...";
return Res;
}

std::string printType(const NonTypeTemplateParmDecl *NTTP,
const PrintingPolicy &PP) {
std::string Res = printType(NTTP->getType(), PP);
if (NTTP->isParameterPack())
Res += "...";
return Res;
}

std::string printType(const TemplateTemplateParmDecl *TTP,
const PrintingPolicy &PP) {
std::string Res;
llvm::raw_string_ostream OS(Res);
OS << "template <";
llvm::StringRef Sep = "";
for (const Decl *Param : *TTP->getTemplateParameters()) {
OS << Sep;
Sep = ", ";
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
OS << printType(TTP);
else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
OS << printType(NTTP, PP);
else if (const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Param))
OS << printType(TTPD, PP);
}
// FIXME: TemplateTemplateParameter doesn't store the info on whether this
// param was a "typename" or "class".
OS << "> class";
return OS.str();
}

std::vector<HoverInfo::Param>
fetchTemplateParameters(const TemplateParameterList *Params,
const PrintingPolicy &PP) {
Expand All @@ -142,38 +170,30 @@ fetchTemplateParameters(const TemplateParameterList *Params,
for (const Decl *Param : *Params) {
HoverInfo::Param P;
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
P.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
if (TTP->isParameterPack())
*P.Type += "...";
P.Type = printType(TTP);

if (!TTP->getName().empty())
P.Name = TTP->getNameAsString();

if (TTP->hasDefaultArgument())
P.Default = TTP->getDefaultArgument().getAsString(PP);
} else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
P.Type = printType(NTTP, PP);

if (IdentifierInfo *II = NTTP->getIdentifier())
P.Name = II->getName().str();

P.Type = printType(NTTP->getType(), PP);
if (NTTP->isParameterPack())
*P.Type += "...";

if (NTTP->hasDefaultArgument()) {
P.Default.emplace();
llvm::raw_string_ostream Out(*P.Default);
NTTP->getDefaultArgument()->printPretty(Out, nullptr, PP);
}
} else if (const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
P.Type.emplace();
llvm::raw_string_ostream OS(*P.Type);
OS << "template <";
printParams(OS,
fetchTemplateParameters(TTPD->getTemplateParameters(), PP));
OS << "> class"; // FIXME: TemplateTemplateParameter doesn't store the
// info on whether this param was a "typename" or
// "class".
P.Type = printType(TTPD, PP);

if (!TTPD->getName().empty())
P.Name = TTPD->getNameAsString();

if (TTPD->hasDefaultArgument()) {
P.Default.emplace();
llvm::raw_string_ostream Out(*P.Default);
Expand Down Expand Up @@ -385,6 +405,10 @@ HoverInfo getHoverContents(const NamedDecl *D, const SymbolIndex *Index) {
fillFunctionTypeAndParams(HI, D, FD, Policy);
else if (const auto *VD = dyn_cast<ValueDecl>(D))
HI.Type = printType(VD->getType(), Policy);
else if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(D))
HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D))
HI.Type = printType(TTP, Policy);

// Fill in value with evaluated initializer if possible.
if (const auto *Var = dyn_cast<VarDecl>(D)) {
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/clangd/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Logger.h"
#include "URI.h"
#include "clang/Basic/LLVM.h"
#include "clang/Index/IndexSymbol.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
Expand Down Expand Up @@ -261,9 +262,13 @@ SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind) {
case index::SymbolKind::ConversionFunction:
return SymbolKind::Function;
case index::SymbolKind::Parameter:
case index::SymbolKind::NonTypeTemplateParm:
return SymbolKind::Variable;
case index::SymbolKind::Using:
return SymbolKind::Namespace;
case index::SymbolKind::TemplateTemplateParm:
case index::SymbolKind::TemplateTypeParm:
return SymbolKind::TypeParameter;
}
llvm_unreachable("invalid symbol kind");
}
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/Quality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ categorize(const index::SymbolInfo &D) {
case index::SymbolKind::Extension:
case index::SymbolKind::Union:
case index::SymbolKind::TypeAlias:
case index::SymbolKind::TemplateTypeParm:
case index::SymbolKind::TemplateTemplateParm:
return SymbolQualitySignals::Type;
case index::SymbolKind::Function:
case index::SymbolKind::ClassMethod:
Expand All @@ -147,6 +149,7 @@ categorize(const index::SymbolInfo &D) {
case index::SymbolKind::Field:
case index::SymbolKind::EnumConstant:
case index::SymbolKind::Parameter:
case index::SymbolKind::NonTypeTemplateParm:
return SymbolQualitySignals::Variable;
case index::SymbolKind::Using:
case index::SymbolKind::Module:
Expand Down
8 changes: 1 addition & 7 deletions clang-tools-extra/clangd/TUScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,13 +842,7 @@ std::string renderTUAction(const TUAction &Action) {
} // namespace

unsigned getDefaultAsyncThreadsCount() {
unsigned HardwareConcurrency = llvm::heavyweight_hardware_concurrency();
// heavyweight_hardware_concurrency may fall back to hardware_concurrency.
// C++ standard says that hardware_concurrency() may return 0; fallback to 1
// worker thread in that case.
if (HardwareConcurrency == 0)
return 1;
return HardwareConcurrency;
return llvm::heavyweight_hardware_concurrency().compute_thread_count();
}

FileStatus TUStatus::render(PathRef File) const {
Expand Down
5 changes: 3 additions & 2 deletions clang-tools-extra/clangd/index/Background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ BackgroundIndex::BackgroundIndex(
CDB.watch([&](const std::vector<std::string> &ChangedFiles) {
enqueue(ChangedFiles);
})) {
assert(ThreadPoolSize > 0 && "Thread pool size can't be zero.");
assert(Rebuilder.TUsBeforeFirstBuild > 0 &&
"Thread pool size can't be zero.");
assert(this->IndexStorageFactory && "Storage factory can not be null!");
for (unsigned I = 0; I < ThreadPoolSize; ++I) {
for (unsigned I = 0; I < Rebuilder.TUsBeforeFirstBuild; ++I) {
ThreadPool.runAsync("background-worker-" + llvm::Twine(I + 1), [this] {
WithContext Ctx(this->BackgroundContext.clone());
Queue.work([&] { Rebuilder.idle(); });
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/index/Background.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class BackgroundIndex : public SwapIndex {
Context BackgroundContext, const FileSystemProvider &,
const GlobalCompilationDatabase &CDB,
BackgroundIndexStorage::Factory IndexStorageFactory,
size_t ThreadPoolSize = llvm::heavyweight_hardware_concurrency(),
size_t ThreadPoolSize = 0, // 0 = use all hardware threads
std::function<void(BackgroundQueue::Stats)> OnProgress = nullptr);
~BackgroundIndex(); // Blocks while the current task finishes.

Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clangd/index/BackgroundRebuild.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class BackgroundIndexRebuilder {
public:
BackgroundIndexRebuilder(SwapIndex *Target, FileSymbols *Source,
unsigned Threads)
: TUsBeforeFirstBuild(Threads), Target(Target), Source(Source) {}
: TUsBeforeFirstBuild(llvm::heavyweight_hardware_concurrency(Threads)
.compute_thread_count()),
Target(Target), Source(Source) {}

// Called to indicate a TU has been indexed.
// May rebuild, if enough TUs have been indexed.
Expand Down
23 changes: 23 additions & 0 deletions clang-tools-extra/clangd/refactor/Rename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ParsedAST.h"
#include "Selection.h"
#include "SourceCode.h"
#include "Trace.h"
#include "index/SymbolCollector.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
Expand Down Expand Up @@ -124,6 +125,7 @@ llvm::Optional<ReasonToReject> renameable(const NamedDecl &RenameDecl,
StringRef MainFilePath,
const SymbolIndex *Index,
bool CrossFile) {
trace::Span Tracer("Renameable");
// Filter out symbols that are unsupported in both rename modes.
if (llvm::isa<NamespaceDecl>(&RenameDecl))
return ReasonToReject::UnsupportedSymbol;
Expand Down Expand Up @@ -225,6 +227,7 @@ llvm::Error makeError(ReasonToReject Reason) {
// Return all rename occurrences in the main file.
std::vector<SourceLocation> findOccurrencesWithinFile(ParsedAST &AST,
const NamedDecl &ND) {
trace::Span Tracer("FindOccurrenceeWithinFile");
// If the cursor is at the underlying CXXRecordDecl of the
// ClassTemplateDecl, ND will be the CXXRecordDecl. In this case, we need to
// get the primary template maunally.
Expand Down Expand Up @@ -260,6 +263,7 @@ std::vector<SourceLocation> findOccurrencesWithinFile(ParsedAST &AST,
llvm::Expected<tooling::Replacements>
renameWithinFile(ParsedAST &AST, const NamedDecl &RenameDecl,
llvm::StringRef NewName) {
trace::Span Tracer("RenameWithinFile");
const SourceManager &SM = AST.getSourceManager();

tooling::Replacements FilteredChanges;
Expand Down Expand Up @@ -319,6 +323,7 @@ std::vector<const CXXConstructorDecl *> getConstructors(const NamedDecl *ND) {
llvm::Expected<llvm::StringMap<std::vector<Range>>>
findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
llvm::StringRef MainFile, const SymbolIndex &Index) {
trace::Span Tracer("FindOccurrencesOutsideFile");
RefsRequest RQuest;
RQuest.IDs.insert(*getSymbolID(&RenameDecl));
// Classes and their constructors are different symbols, and have different
Expand Down Expand Up @@ -361,6 +366,9 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
auto &Ranges = FileAndOccurrences.getValue();
llvm::sort(Ranges);
Ranges.erase(std::unique(Ranges.begin(), Ranges.end()), Ranges.end());

SPAN_ATTACH(Tracer, FileAndOccurrences.first(),
static_cast<int64_t>(Ranges.size()));
}
return AffectedFiles;
}
Expand All @@ -381,6 +389,7 @@ llvm::Expected<FileEdits> renameOutsideFile(
const NamedDecl &RenameDecl, llvm::StringRef MainFilePath,
llvm::StringRef NewName, const SymbolIndex &Index,
llvm::function_ref<llvm::Expected<std::string>(PathRef)> GetFileContent) {
trace::Span Tracer("RenameOutsideFile");
auto AffectedFiles =
findOccurrencesOutsideFile(RenameDecl, MainFilePath, Index);
if (!AffectedFiles)
Expand Down Expand Up @@ -463,6 +472,7 @@ void findNearMiss(
} // namespace

llvm::Expected<FileEdits> rename(const RenameInputs &RInputs) {
trace::Span Tracer("Rename flow");
ParsedAST &AST = RInputs.AST;
const SourceManager &SM = AST.getSourceManager();
llvm::StringRef MainFileCode = SM.getBufferData(SM.getMainFileID());
Expand Down Expand Up @@ -555,6 +565,11 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
llvm::StringRef InitialCode,
std::vector<Range> Occurrences,
llvm::StringRef NewName) {
trace::Span Tracer("BuildRenameEdit");
SPAN_ATTACH(Tracer, "file_path", AbsFilePath);
SPAN_ATTACH(Tracer, "rename_occurrences",
static_cast<int64_t>(Occurrences.size()));

assert(std::is_sorted(Occurrences.begin(), Occurrences.end()));
assert(std::unique(Occurrences.begin(), Occurrences.end()) ==
Occurrences.end() &&
Expand Down Expand Up @@ -618,6 +633,7 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
llvm::Optional<std::vector<Range>>
adjustRenameRanges(llvm::StringRef DraftCode, llvm::StringRef Identifier,
std::vector<Range> Indexed, const LangOptions &LangOpts) {
trace::Span Tracer("AdjustRenameRanges");
assert(!Indexed.empty());
assert(std::is_sorted(Indexed.begin(), Indexed.end()));
std::vector<Range> Lexed =
Expand All @@ -628,12 +644,16 @@ adjustRenameRanges(llvm::StringRef DraftCode, llvm::StringRef Identifier,

llvm::Optional<std::vector<Range>> getMappedRanges(ArrayRef<Range> Indexed,
ArrayRef<Range> Lexed) {
trace::Span Tracer("GetMappedRanges");
assert(!Indexed.empty());
assert(std::is_sorted(Indexed.begin(), Indexed.end()));
assert(std::is_sorted(Lexed.begin(), Lexed.end()));

if (Indexed.size() > Lexed.size()) {
vlog("The number of lexed occurrences is less than indexed occurrences");
SPAN_ATTACH(
Tracer, "error",
"The number of lexed occurrences is less than indexed occurrences");
return llvm::None;
}
// Fast check for the special subset case.
Expand All @@ -660,15 +680,18 @@ llvm::Optional<std::vector<Range>> getMappedRanges(ArrayRef<Range> Indexed,
});
if (HasMultiple) {
vlog("The best near miss is not unique.");
SPAN_ATTACH(Tracer, "error", "The best near miss is not unique");
return llvm::None;
}
if (Best.empty()) {
vlog("Didn't find a near miss.");
SPAN_ATTACH(Tracer, "error", "Didn't find a near miss");
return llvm::None;
}
std::vector<Range> Mapped;
for (auto I : Best)
Mapped.push_back(Lexed[I]);
SPAN_ATTACH(Tracer, "mapped_ranges", static_cast<int64_t>(Mapped.size()));
return Mapped;
}

Expand Down
Loading

0 comments on commit 7517d36

Please sign in to comment.