Skip to content

Commit 7517d36

Browse files
committed
Merge from 'master' to 'sycl-web' (#59)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGOpenMPRuntime.cpp
2 parents fd438ca + 1228d42 commit 7517d36

File tree

336 files changed

+10349
-3526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

336 files changed

+10349
-3526
lines changed

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ int main(int argc, const char **argv) {
268268
Error = false;
269269
llvm::sys::Mutex IndexMutex;
270270
// ExecutorConcurrency is a flag exposed by AllTUsExecution.h
271-
llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
272-
: ExecutorConcurrency);
271+
llvm::ThreadPool Pool(llvm::hardware_concurrency(ExecutorConcurrency));
273272
for (auto &Group : USRToBitcode) {
274273
Pool.async([&]() {
275274
std::vector<std::unique_ptr<doc::Info>> Infos;

clang-tools-extra/clangd/CodeComplete.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
8787
return CompletionItemKind::Text;
8888
case SK::Enum:
8989
return CompletionItemKind::Enum;
90-
// FIXME(ioeric): use LSP struct instead of class when it is suppoted in the
91-
// protocol.
9290
case SK::Struct:
91+
return CompletionItemKind::Struct;
9392
case SK::Class:
9493
case SK::Protocol:
9594
case SK::Extension:
@@ -102,18 +101,16 @@ CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
102101
case SK::Using:
103102
return CompletionItemKind::Reference;
104103
case SK::Function:
105-
// FIXME(ioeric): this should probably be an operator. This should be fixed
106-
// when `Operator` is support type in the protocol.
107104
case SK::ConversionFunction:
108105
return CompletionItemKind::Function;
109106
case SK::Variable:
110107
case SK::Parameter:
108+
case SK::NonTypeTemplateParm:
111109
return CompletionItemKind::Variable;
112110
case SK::Field:
113111
return CompletionItemKind::Field;
114-
// FIXME(ioeric): use LSP enum constant when it is supported in the protocol.
115112
case SK::EnumConstant:
116-
return CompletionItemKind::Value;
113+
return CompletionItemKind::EnumMember;
117114
case SK::InstanceMethod:
118115
case SK::ClassMethod:
119116
case SK::StaticMethod:
@@ -125,6 +122,9 @@ CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
125122
return CompletionItemKind::Property;
126123
case SK::Constructor:
127124
return CompletionItemKind::Constructor;
125+
case SK::TemplateTypeParm:
126+
case SK::TemplateTemplateParm:
127+
return CompletionItemKind::TypeParameter;
128128
}
129129
llvm_unreachable("Unhandled clang::index::SymbolKind.");
130130
}

clang-tools-extra/clangd/Hover.cpp

+48-24
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,6 @@ std::string printDefinition(const Decl *D) {
115115
return Definition;
116116
}
117117

118-
void printParams(llvm::raw_ostream &OS,
119-
const std::vector<HoverInfo::Param> &Params) {
120-
for (size_t I = 0, E = Params.size(); I != E; ++I) {
121-
if (I)
122-
OS << ", ";
123-
OS << Params.at(I);
124-
}
125-
}
126-
127118
std::string printType(QualType QT, const PrintingPolicy &Policy) {
128119
// TypePrinter doesn't resolve decltypes, so resolve them here.
129120
// FIXME: This doesn't handle composite types that contain a decltype in them.
@@ -133,6 +124,43 @@ std::string printType(QualType QT, const PrintingPolicy &Policy) {
133124
return QT.getAsString(Policy);
134125
}
135126

127+
std::string printType(const TemplateTypeParmDecl *TTP) {
128+
std::string Res = TTP->wasDeclaredWithTypename() ? "typename" : "class";
129+
if (TTP->isParameterPack())
130+
Res += "...";
131+
return Res;
132+
}
133+
134+
std::string printType(const NonTypeTemplateParmDecl *NTTP,
135+
const PrintingPolicy &PP) {
136+
std::string Res = printType(NTTP->getType(), PP);
137+
if (NTTP->isParameterPack())
138+
Res += "...";
139+
return Res;
140+
}
141+
142+
std::string printType(const TemplateTemplateParmDecl *TTP,
143+
const PrintingPolicy &PP) {
144+
std::string Res;
145+
llvm::raw_string_ostream OS(Res);
146+
OS << "template <";
147+
llvm::StringRef Sep = "";
148+
for (const Decl *Param : *TTP->getTemplateParameters()) {
149+
OS << Sep;
150+
Sep = ", ";
151+
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
152+
OS << printType(TTP);
153+
else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
154+
OS << printType(NTTP, PP);
155+
else if (const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Param))
156+
OS << printType(TTPD, PP);
157+
}
158+
// FIXME: TemplateTemplateParameter doesn't store the info on whether this
159+
// param was a "typename" or "class".
160+
OS << "> class";
161+
return OS.str();
162+
}
163+
136164
std::vector<HoverInfo::Param>
137165
fetchTemplateParameters(const TemplateParameterList *Params,
138166
const PrintingPolicy &PP) {
@@ -142,38 +170,30 @@ fetchTemplateParameters(const TemplateParameterList *Params,
142170
for (const Decl *Param : *Params) {
143171
HoverInfo::Param P;
144172
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
145-
P.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
146-
if (TTP->isParameterPack())
147-
*P.Type += "...";
173+
P.Type = printType(TTP);
148174

149175
if (!TTP->getName().empty())
150176
P.Name = TTP->getNameAsString();
177+
151178
if (TTP->hasDefaultArgument())
152179
P.Default = TTP->getDefaultArgument().getAsString(PP);
153180
} else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
181+
P.Type = printType(NTTP, PP);
182+
154183
if (IdentifierInfo *II = NTTP->getIdentifier())
155184
P.Name = II->getName().str();
156185

157-
P.Type = printType(NTTP->getType(), PP);
158-
if (NTTP->isParameterPack())
159-
*P.Type += "...";
160-
161186
if (NTTP->hasDefaultArgument()) {
162187
P.Default.emplace();
163188
llvm::raw_string_ostream Out(*P.Default);
164189
NTTP->getDefaultArgument()->printPretty(Out, nullptr, PP);
165190
}
166191
} else if (const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
167-
P.Type.emplace();
168-
llvm::raw_string_ostream OS(*P.Type);
169-
OS << "template <";
170-
printParams(OS,
171-
fetchTemplateParameters(TTPD->getTemplateParameters(), PP));
172-
OS << "> class"; // FIXME: TemplateTemplateParameter doesn't store the
173-
// info on whether this param was a "typename" or
174-
// "class".
192+
P.Type = printType(TTPD, PP);
193+
175194
if (!TTPD->getName().empty())
176195
P.Name = TTPD->getNameAsString();
196+
177197
if (TTPD->hasDefaultArgument()) {
178198
P.Default.emplace();
179199
llvm::raw_string_ostream Out(*P.Default);
@@ -385,6 +405,10 @@ HoverInfo getHoverContents(const NamedDecl *D, const SymbolIndex *Index) {
385405
fillFunctionTypeAndParams(HI, D, FD, Policy);
386406
else if (const auto *VD = dyn_cast<ValueDecl>(D))
387407
HI.Type = printType(VD->getType(), Policy);
408+
else if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(D))
409+
HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
410+
else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D))
411+
HI.Type = printType(TTP, Policy);
388412

389413
// Fill in value with evaluated initializer if possible.
390414
if (const auto *Var = dyn_cast<VarDecl>(D)) {

clang-tools-extra/clangd/Protocol.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Logger.h"
1515
#include "URI.h"
1616
#include "clang/Basic/LLVM.h"
17+
#include "clang/Index/IndexSymbol.h"
1718
#include "llvm/ADT/Hashing.h"
1819
#include "llvm/ADT/SmallString.h"
1920
#include "llvm/ADT/StringSwitch.h"
@@ -261,9 +262,13 @@ SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind) {
261262
case index::SymbolKind::ConversionFunction:
262263
return SymbolKind::Function;
263264
case index::SymbolKind::Parameter:
265+
case index::SymbolKind::NonTypeTemplateParm:
264266
return SymbolKind::Variable;
265267
case index::SymbolKind::Using:
266268
return SymbolKind::Namespace;
269+
case index::SymbolKind::TemplateTemplateParm:
270+
case index::SymbolKind::TemplateTypeParm:
271+
return SymbolKind::TypeParameter;
267272
}
268273
llvm_unreachable("invalid symbol kind");
269274
}

clang-tools-extra/clangd/Quality.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ categorize(const index::SymbolInfo &D) {
129129
case index::SymbolKind::Extension:
130130
case index::SymbolKind::Union:
131131
case index::SymbolKind::TypeAlias:
132+
case index::SymbolKind::TemplateTypeParm:
133+
case index::SymbolKind::TemplateTemplateParm:
132134
return SymbolQualitySignals::Type;
133135
case index::SymbolKind::Function:
134136
case index::SymbolKind::ClassMethod:
@@ -147,6 +149,7 @@ categorize(const index::SymbolInfo &D) {
147149
case index::SymbolKind::Field:
148150
case index::SymbolKind::EnumConstant:
149151
case index::SymbolKind::Parameter:
152+
case index::SymbolKind::NonTypeTemplateParm:
150153
return SymbolQualitySignals::Variable;
151154
case index::SymbolKind::Using:
152155
case index::SymbolKind::Module:

clang-tools-extra/clangd/TUScheduler.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,7 @@ std::string renderTUAction(const TUAction &Action) {
842842
} // namespace
843843

844844
unsigned getDefaultAsyncThreadsCount() {
845-
unsigned HardwareConcurrency = llvm::heavyweight_hardware_concurrency();
846-
// heavyweight_hardware_concurrency may fall back to hardware_concurrency.
847-
// C++ standard says that hardware_concurrency() may return 0; fallback to 1
848-
// worker thread in that case.
849-
if (HardwareConcurrency == 0)
850-
return 1;
851-
return HardwareConcurrency;
845+
return llvm::heavyweight_hardware_concurrency().compute_thread_count();
852846
}
853847

854848
FileStatus TUStatus::render(PathRef File) const {

clang-tools-extra/clangd/index/Background.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ BackgroundIndex::BackgroundIndex(
148148
CDB.watch([&](const std::vector<std::string> &ChangedFiles) {
149149
enqueue(ChangedFiles);
150150
})) {
151-
assert(ThreadPoolSize > 0 && "Thread pool size can't be zero.");
151+
assert(Rebuilder.TUsBeforeFirstBuild > 0 &&
152+
"Thread pool size can't be zero.");
152153
assert(this->IndexStorageFactory && "Storage factory can not be null!");
153-
for (unsigned I = 0; I < ThreadPoolSize; ++I) {
154+
for (unsigned I = 0; I < Rebuilder.TUsBeforeFirstBuild; ++I) {
154155
ThreadPool.runAsync("background-worker-" + llvm::Twine(I + 1), [this] {
155156
WithContext Ctx(this->BackgroundContext.clone());
156157
Queue.work([&] { Rebuilder.idle(); });

clang-tools-extra/clangd/index/Background.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class BackgroundIndex : public SwapIndex {
135135
Context BackgroundContext, const FileSystemProvider &,
136136
const GlobalCompilationDatabase &CDB,
137137
BackgroundIndexStorage::Factory IndexStorageFactory,
138-
size_t ThreadPoolSize = llvm::heavyweight_hardware_concurrency(),
138+
size_t ThreadPoolSize = 0, // 0 = use all hardware threads
139139
std::function<void(BackgroundQueue::Stats)> OnProgress = nullptr);
140140
~BackgroundIndex(); // Blocks while the current task finishes.
141141

clang-tools-extra/clangd/index/BackgroundRebuild.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class BackgroundIndexRebuilder {
4949
public:
5050
BackgroundIndexRebuilder(SwapIndex *Target, FileSymbols *Source,
5151
unsigned Threads)
52-
: TUsBeforeFirstBuild(Threads), Target(Target), Source(Source) {}
52+
: TUsBeforeFirstBuild(llvm::heavyweight_hardware_concurrency(Threads)
53+
.compute_thread_count()),
54+
Target(Target), Source(Source) {}
5355

5456
// Called to indicate a TU has been indexed.
5557
// May rebuild, if enough TUs have been indexed.

clang-tools-extra/clangd/refactor/Rename.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "ParsedAST.h"
1414
#include "Selection.h"
1515
#include "SourceCode.h"
16+
#include "Trace.h"
1617
#include "index/SymbolCollector.h"
1718
#include "clang/AST/DeclCXX.h"
1819
#include "clang/AST/DeclTemplate.h"
@@ -124,6 +125,7 @@ llvm::Optional<ReasonToReject> renameable(const NamedDecl &RenameDecl,
124125
StringRef MainFilePath,
125126
const SymbolIndex *Index,
126127
bool CrossFile) {
128+
trace::Span Tracer("Renameable");
127129
// Filter out symbols that are unsupported in both rename modes.
128130
if (llvm::isa<NamespaceDecl>(&RenameDecl))
129131
return ReasonToReject::UnsupportedSymbol;
@@ -225,6 +227,7 @@ llvm::Error makeError(ReasonToReject Reason) {
225227
// Return all rename occurrences in the main file.
226228
std::vector<SourceLocation> findOccurrencesWithinFile(ParsedAST &AST,
227229
const NamedDecl &ND) {
230+
trace::Span Tracer("FindOccurrenceeWithinFile");
228231
// If the cursor is at the underlying CXXRecordDecl of the
229232
// ClassTemplateDecl, ND will be the CXXRecordDecl. In this case, we need to
230233
// get the primary template maunally.
@@ -260,6 +263,7 @@ std::vector<SourceLocation> findOccurrencesWithinFile(ParsedAST &AST,
260263
llvm::Expected<tooling::Replacements>
261264
renameWithinFile(ParsedAST &AST, const NamedDecl &RenameDecl,
262265
llvm::StringRef NewName) {
266+
trace::Span Tracer("RenameWithinFile");
263267
const SourceManager &SM = AST.getSourceManager();
264268

265269
tooling::Replacements FilteredChanges;
@@ -319,6 +323,7 @@ std::vector<const CXXConstructorDecl *> getConstructors(const NamedDecl *ND) {
319323
llvm::Expected<llvm::StringMap<std::vector<Range>>>
320324
findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
321325
llvm::StringRef MainFile, const SymbolIndex &Index) {
326+
trace::Span Tracer("FindOccurrencesOutsideFile");
322327
RefsRequest RQuest;
323328
RQuest.IDs.insert(*getSymbolID(&RenameDecl));
324329
// Classes and their constructors are different symbols, and have different
@@ -361,6 +366,9 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
361366
auto &Ranges = FileAndOccurrences.getValue();
362367
llvm::sort(Ranges);
363368
Ranges.erase(std::unique(Ranges.begin(), Ranges.end()), Ranges.end());
369+
370+
SPAN_ATTACH(Tracer, FileAndOccurrences.first(),
371+
static_cast<int64_t>(Ranges.size()));
364372
}
365373
return AffectedFiles;
366374
}
@@ -381,6 +389,7 @@ llvm::Expected<FileEdits> renameOutsideFile(
381389
const NamedDecl &RenameDecl, llvm::StringRef MainFilePath,
382390
llvm::StringRef NewName, const SymbolIndex &Index,
383391
llvm::function_ref<llvm::Expected<std::string>(PathRef)> GetFileContent) {
392+
trace::Span Tracer("RenameOutsideFile");
384393
auto AffectedFiles =
385394
findOccurrencesOutsideFile(RenameDecl, MainFilePath, Index);
386395
if (!AffectedFiles)
@@ -463,6 +472,7 @@ void findNearMiss(
463472
} // namespace
464473

465474
llvm::Expected<FileEdits> rename(const RenameInputs &RInputs) {
475+
trace::Span Tracer("Rename flow");
466476
ParsedAST &AST = RInputs.AST;
467477
const SourceManager &SM = AST.getSourceManager();
468478
llvm::StringRef MainFileCode = SM.getBufferData(SM.getMainFileID());
@@ -555,6 +565,11 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
555565
llvm::StringRef InitialCode,
556566
std::vector<Range> Occurrences,
557567
llvm::StringRef NewName) {
568+
trace::Span Tracer("BuildRenameEdit");
569+
SPAN_ATTACH(Tracer, "file_path", AbsFilePath);
570+
SPAN_ATTACH(Tracer, "rename_occurrences",
571+
static_cast<int64_t>(Occurrences.size()));
572+
558573
assert(std::is_sorted(Occurrences.begin(), Occurrences.end()));
559574
assert(std::unique(Occurrences.begin(), Occurrences.end()) ==
560575
Occurrences.end() &&
@@ -618,6 +633,7 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
618633
llvm::Optional<std::vector<Range>>
619634
adjustRenameRanges(llvm::StringRef DraftCode, llvm::StringRef Identifier,
620635
std::vector<Range> Indexed, const LangOptions &LangOpts) {
636+
trace::Span Tracer("AdjustRenameRanges");
621637
assert(!Indexed.empty());
622638
assert(std::is_sorted(Indexed.begin(), Indexed.end()));
623639
std::vector<Range> Lexed =
@@ -628,12 +644,16 @@ adjustRenameRanges(llvm::StringRef DraftCode, llvm::StringRef Identifier,
628644

629645
llvm::Optional<std::vector<Range>> getMappedRanges(ArrayRef<Range> Indexed,
630646
ArrayRef<Range> Lexed) {
647+
trace::Span Tracer("GetMappedRanges");
631648
assert(!Indexed.empty());
632649
assert(std::is_sorted(Indexed.begin(), Indexed.end()));
633650
assert(std::is_sorted(Lexed.begin(), Lexed.end()));
634651

635652
if (Indexed.size() > Lexed.size()) {
636653
vlog("The number of lexed occurrences is less than indexed occurrences");
654+
SPAN_ATTACH(
655+
Tracer, "error",
656+
"The number of lexed occurrences is less than indexed occurrences");
637657
return llvm::None;
638658
}
639659
// Fast check for the special subset case.
@@ -660,15 +680,18 @@ llvm::Optional<std::vector<Range>> getMappedRanges(ArrayRef<Range> Indexed,
660680
});
661681
if (HasMultiple) {
662682
vlog("The best near miss is not unique.");
683+
SPAN_ATTACH(Tracer, "error", "The best near miss is not unique");
663684
return llvm::None;
664685
}
665686
if (Best.empty()) {
666687
vlog("Didn't find a near miss.");
688+
SPAN_ATTACH(Tracer, "error", "Didn't find a near miss");
667689
return llvm::None;
668690
}
669691
std::vector<Range> Mapped;
670692
for (auto I : Best)
671693
Mapped.push_back(Lexed[I]);
694+
SPAN_ATTACH(Tracer, "mapped_ranges", static_cast<int64_t>(Mapped.size()));
672695
return Mapped;
673696
}
674697

0 commit comments

Comments
 (0)