Skip to content

Commit d57ae01

Browse files
committed
Merge from 'main' to 'sycl-web' (#255)
2 parents 15033c9 + 1a49944 commit d57ae01

File tree

1,464 files changed

+77517
-35151
lines changed

Some content is hidden

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

1,464 files changed

+77517
-35151
lines changed

.github/lockdown.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Configuration for Repo Lockdown - https://github.com/dessant/repo-lockdown
2+
3+
skipCreatedBefore: "2020-03-21"
4+
5+
pulls:
6+
comment: >
7+
This repository does not accept pull requests.
8+
Please follow http://llvm.org/docs/Contributing.html#how-to-submit-a-patch for contribution to LLVM.

clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void UpgradeDurationConversionsCheck::check(
128128

129129
if (!match(isInTemplateInstantiation(), *OuterExpr, *Result.Context)
130130
.empty()) {
131-
if (MatchedTemplateLocations.count(Loc.getRawEncoding()) == 0) {
131+
if (MatchedTemplateLocations.count(Loc) == 0) {
132132
// For each location matched in a template instantiation, we check if the
133133
// location can also be found in `MatchedTemplateLocations`. If it is not
134134
// found, that means the expression did not create a match without the
@@ -144,7 +144,7 @@ void UpgradeDurationConversionsCheck::check(
144144
internal::Matcher<Stmt> IsInsideTemplate =
145145
hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl())));
146146
if (!match(IsInsideTemplate, *ArgExpr, *Result.Context).empty())
147-
MatchedTemplateLocations.insert(Loc.getRawEncoding());
147+
MatchedTemplateLocations.insert(Loc);
148148

149149
DiagnosticBuilder Diag = diag(Loc, Message);
150150
CharSourceRange SourceRange = Lexer::makeFileCharRange(

clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
#include "../ClangTidyCheck.h"
1313

14-
#include <unordered_set>
14+
#include "clang/Basic/SourceLocation.h"
15+
#include "llvm/ADT/DenseSet.h"
1516

1617
namespace clang {
1718
namespace tidy {
@@ -32,7 +33,7 @@ class UpgradeDurationConversionsCheck : public ClangTidyCheck {
3233
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3334

3435
private:
35-
std::unordered_set<unsigned> MatchedTemplateLocations;
36+
llvm::DenseSet<SourceLocation> MatchedTemplateLocations;
3637
};
3738

3839
} // namespace abseil

clang-tools-extra/clangd/AST.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ getQualification(ASTContext &Context, const DeclContext *DestContext,
116116
if (auto *TD = llvm::dyn_cast<TagDecl>(CurContext)) {
117117
// There can't be any more tag parents after hitting a namespace.
118118
assert(!ReachedNS);
119+
(void)ReachedNS;
119120
NNS = NestedNameSpecifier::Create(Context, nullptr, false,
120121
TD->getTypeForDecl());
121122
} else {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===--- ASTSignals.cpp ------------------------------------------*- C++-*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "ASTSignals.h"
10+
#include "AST.h"
11+
#include "FindTarget.h"
12+
13+
namespace clang {
14+
namespace clangd {
15+
ASTSignals ASTSignals::derive(const ParsedAST &AST) {
16+
ASTSignals Signals;
17+
const SourceManager &SM = AST.getSourceManager();
18+
findExplicitReferences(AST.getASTContext(), [&](ReferenceLoc Ref) {
19+
for (const NamedDecl *ND : Ref.Targets) {
20+
if (!isInsideMainFile(Ref.NameLoc, SM))
21+
continue;
22+
SymbolID ID = getSymbolID(ND);
23+
if (!ID)
24+
continue;
25+
unsigned &SymbolCount = Signals.ReferencedSymbols[ID];
26+
SymbolCount++;
27+
// Process namespace only when we see the symbol for the first time.
28+
if (SymbolCount != 1)
29+
continue;
30+
if (const auto *NSD = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
31+
if (NSD->isAnonymousNamespace())
32+
continue;
33+
std::string NS = printNamespaceScope(*NSD);
34+
if (!NS.empty())
35+
Signals.RelatedNamespaces[NS]++;
36+
}
37+
}
38+
});
39+
return Signals;
40+
}
41+
} // namespace clangd
42+
} // namespace clang

clang-tools-extra/clangd/ASTSignals.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===--- ASTSignals.h --------------------------------------------*- C++-*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_ASTSIGNALS_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_ASTSIGNALS_H
11+
12+
#include "ParsedAST.h"
13+
#include "index/SymbolID.h"
14+
#include "llvm/ADT/DenseMap.h"
15+
#include "llvm/ADT/StringMap.h"
16+
17+
namespace clang {
18+
namespace clangd {
19+
20+
/// Signals derived from a valid AST of a file.
21+
/// Provides information that can only be extracted from the AST to actions that
22+
/// can't access an AST. The signals are computed and updated asynchronously by
23+
/// the ASTWorker and thus they are always stale and also can be absent.
24+
/// Example usage: Information about the declarations used in a file affects
25+
/// code-completion ranking in that file.
26+
struct ASTSignals {
27+
/// Number of occurrences of each symbol present in the file.
28+
llvm::DenseMap<SymbolID, unsigned> ReferencedSymbols;
29+
/// Namespaces whose symbols are used in the file, and the number of such
30+
/// distinct symbols.
31+
llvm::StringMap<unsigned> RelatedNamespaces;
32+
33+
static ASTSignals derive(const ParsedAST &AST);
34+
};
35+
36+
} // namespace clangd
37+
} // namespace clang
38+
39+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_ASTSIGNALS_H

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}/../clang-tidy")
4646

4747
add_clang_library(clangDaemon
4848
AST.cpp
49+
ASTSignals.cpp
4950
ClangdLSPServer.cpp
5051
ClangdServer.cpp
5152
CodeComplete.cpp

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,11 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
243243
// No speculation in Fallback mode, as it's supposed to be much faster
244244
// without compiling.
245245
vlog("Build for file {0} is not ready. Enter fallback mode.", File);
246-
} else {
247-
if (CodeCompleteOpts.Index && CodeCompleteOpts.SpeculativeIndexRequest) {
248-
SpecFuzzyFind.emplace();
249-
{
250-
std::lock_guard<std::mutex> Lock(
251-
CachedCompletionFuzzyFindRequestMutex);
252-
SpecFuzzyFind->CachedReq =
253-
CachedCompletionFuzzyFindRequestByFile[File];
254-
}
246+
} else if (CodeCompleteOpts.Index) {
247+
SpecFuzzyFind.emplace();
248+
{
249+
std::lock_guard<std::mutex> Lock(CachedCompletionFuzzyFindRequestMutex);
250+
SpecFuzzyFind->CachedReq = CachedCompletionFuzzyFindRequestByFile[File];
255251
}
256252
}
257253
ParseInputs ParseInput{IP->Command, &TFS, IP->Contents.str()};

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ struct CodeCompletionBuilder {
277277
CodeCompletionContext::Kind ContextKind,
278278
const CodeCompleteOptions &Opts,
279279
bool IsUsingDeclaration, tok::TokenKind NextTokenKind)
280-
: ASTCtx(ASTCtx), ExtractDocumentation(Opts.IncludeComments),
280+
: ASTCtx(ASTCtx),
281281
EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets),
282282
IsUsingDeclaration(IsUsingDeclaration), NextTokenKind(NextTokenKind) {
283283
add(C, SemaCCS);
@@ -393,7 +393,7 @@ struct CodeCompletionBuilder {
393393
S.SnippetSuffix = std::string(C.IndexResult->CompletionSnippetSuffix);
394394
S.ReturnType = std::string(C.IndexResult->ReturnType);
395395
}
396-
if (ExtractDocumentation && !Completion.Documentation) {
396+
if (!Completion.Documentation) {
397397
auto SetDoc = [&](llvm::StringRef Doc) {
398398
if (!Doc.empty()) {
399399
Completion.Documentation.emplace();
@@ -512,7 +512,6 @@ struct CodeCompletionBuilder {
512512
ASTContext *ASTCtx;
513513
CodeCompletion Completion;
514514
llvm::SmallVector<BundledEntry, 1> Bundled;
515-
bool ExtractDocumentation;
516515
bool EnableFunctionArgSnippets;
517516
// No snippets will be generated for using declarations and when the function
518517
// arguments are already present.
@@ -1765,8 +1764,8 @@ class CodeCompleteFlow {
17651764

17661765
clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const {
17671766
clang::CodeCompleteOptions Result;
1768-
Result.IncludeCodePatterns = EnableSnippets && IncludeCodePatterns;
1769-
Result.IncludeMacros = IncludeMacros;
1767+
Result.IncludeCodePatterns = EnableSnippets;
1768+
Result.IncludeMacros = true;
17701769
Result.IncludeGlobals = true;
17711770
// We choose to include full comments and not do doxygen parsing in
17721771
// completion.

clang-tools-extra/clangd/CodeComplete.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ struct CodeCompleteOptions {
5050
/// b})).
5151
bool EnableSnippets = false;
5252

53-
/// Add code patterns to completion results.
54-
/// If EnableSnippets is false, this options is ignored and code patterns will
55-
/// always be omitted.
56-
bool IncludeCodePatterns = true;
57-
58-
/// Add macros to code completion results.
59-
bool IncludeMacros = true;
60-
61-
/// Add comments to code completion results, if available.
62-
bool IncludeComments = true;
63-
6453
/// Include results that are not legal completions in the current context.
6554
/// For example, private members are usually inaccessible.
6655
bool IncludeIneligibleResults = false;
@@ -93,16 +82,6 @@ struct CodeCompleteOptions {
9382
/// Expose origins of completion items in the label (for debugging).
9483
bool ShowOrigins = false;
9584

96-
/// If set to true, this will send an asynchronous speculative index request,
97-
/// based on the index request for the last code completion on the same file
98-
/// and the filter text typed before the cursor, before sema code completion
99-
/// is invoked. This can reduce the code completion latency (by roughly
100-
/// latency of sema code completion) if the speculative request is the same as
101-
/// the one generated for the ongoing code completion from sema. As a sequence
102-
/// of code completions often have the same scopes and proximity paths etc,
103-
/// this should be effective for a number of code completions.
104-
bool SpeculativeIndexRequest = false;
105-
10685
// Populated internally by clangd, do not set.
10786
/// If `Index` is set, it is used to augment the code completion
10887
/// results.

clang-tools-extra/clangd/CollectMacros.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
namespace clang {
1414
namespace clangd {
1515

16-
void CollectMainFileMacros::add(const Token &MacroNameTok,
17-
const MacroInfo *MI) {
16+
void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
17+
bool IsDefinition) {
1818
if (!InMainFile)
1919
return;
2020
auto Loc = MacroNameTok.getLocation();
@@ -26,9 +26,9 @@ void CollectMainFileMacros::add(const Token &MacroNameTok,
2626
auto Range = halfOpenToRange(
2727
SM, CharSourceRange::getCharRange(Loc, MacroNameTok.getEndLoc()));
2828
if (auto SID = getSymbolID(Name, MI, SM))
29-
Out.MacroRefs[SID].push_back(Range);
29+
Out.MacroRefs[SID].push_back({Range, IsDefinition});
3030
else
31-
Out.UnknownMacros.push_back(Range);
31+
Out.UnknownMacros.push_back({Range, IsDefinition});
3232
}
3333
} // namespace clangd
3434
} // namespace clang

clang-tools-extra/clangd/CollectMacros.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@
2121
namespace clang {
2222
namespace clangd {
2323

24-
struct MainFileMacros {
25-
llvm::StringSet<> Names;
24+
struct MacroOccurrence {
2625
// Instead of storing SourceLocation, we have to store the token range because
2726
// SourceManager from preamble is not available when we build the AST.
28-
llvm::DenseMap<SymbolID, std::vector<Range>> MacroRefs;
27+
Range Rng;
28+
bool IsDefinition;
29+
};
30+
31+
struct MainFileMacros {
32+
llvm::StringSet<> Names;
33+
llvm::DenseMap<SymbolID, std::vector<MacroOccurrence>> MacroRefs;
2934
// Somtimes it is not possible to compute the SymbolID for the Macro, e.g. a
3035
// reference to an undefined macro. Store them separately, e.g. for semantic
3136
// highlighting.
32-
std::vector<Range> UnknownMacros;
37+
std::vector<MacroOccurrence> UnknownMacros;
3338
// Ranges skipped by the preprocessor due to being inactive.
3439
std::vector<Range> SkippedRanges;
3540
};
@@ -49,7 +54,7 @@ class CollectMainFileMacros : public PPCallbacks {
4954
}
5055

5156
void MacroDefined(const Token &MacroName, const MacroDirective *MD) override {
52-
add(MacroName, MD->getMacroInfo());
57+
add(MacroName, MD->getMacroInfo(), /*IsDefinition=*/true);
5358
}
5459

5560
void MacroExpands(const Token &MacroName, const MacroDefinition &MD,
@@ -87,7 +92,8 @@ class CollectMainFileMacros : public PPCallbacks {
8792
}
8893

8994
private:
90-
void add(const Token &MacroNameTok, const MacroInfo *MI);
95+
void add(const Token &MacroNameTok, const MacroInfo *MI,
96+
bool IsDefinition = false);
9197
const SourceManager &SM;
9298
bool InMainFile = true;
9399
MainFileMacros &Out;

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ struct TargetFinder {
330330
llvm::SmallDenseMap<const NamedDecl *,
331331
std::pair<RelSet, /*InsertionOrder*/ size_t>>
332332
Decls;
333+
llvm::SmallDenseMap<const Decl *, RelSet> Seen;
333334
RelSet Flags;
334335

335336
template <typename T> void debug(T &Node, RelSet Flags) {
@@ -359,6 +360,15 @@ struct TargetFinder {
359360
if (!D)
360361
return;
361362
debug(*D, Flags);
363+
364+
// Avoid recursion (which can arise in the presence of heuristic
365+
// resolution of dependent names) by exiting early if we have
366+
// already seen this decl with all flags in Flags.
367+
auto Res = Seen.try_emplace(D);
368+
if (!Res.second && Res.first->second.contains(Flags))
369+
return;
370+
Res.first->second |= Flags;
371+
362372
if (const UsingDirectiveDecl *UDD = llvm::dyn_cast<UsingDirectiveDecl>(D))
363373
D = UDD->getNominatedNamespaceAsWritten();
364374

clang-tools-extra/clangd/FindTarget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ class DeclRelationSet {
194194
S &= Other.S;
195195
return *this;
196196
}
197+
bool contains(DeclRelationSet Other) const {
198+
return (S & Other.S) == Other.S;
199+
}
197200
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, DeclRelationSet);
198201
};
199202
// The above operators can't be looked up if both sides are enums.

0 commit comments

Comments
 (0)