Skip to content

Commit 8503189

Browse files
author
iclsrc
committed
Merge from 'main' to 'sycl-web' (171 commits)
2 parents 958cd99 + 250f2bb commit 8503189

File tree

712 files changed

+17103
-7162
lines changed

Some content is hidden

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

712 files changed

+17103
-7162
lines changed

.github/workflows/closed-issues.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Labeling closed issues
22
on:
3-
issues:
4-
types: ['closed']
3+
workflow_dispatch
4+
# issues:
5+
# types: ['closed']
56

67
permissions:
78
contents: read

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,6 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
650650
CodeAction::INFO_KIND}}}
651651
: llvm::json::Value(true);
652652

653-
654653
std::vector<llvm::StringRef> Commands;
655654
for (llvm::StringRef Command : Handlers.CommandHandlers.keys())
656655
Commands.push_back(Command);
@@ -1721,7 +1720,7 @@ std::vector<CodeAction> ClangdLSPServer::getFixes(llvm::StringRef File,
17211720
}
17221721

17231722
// A completion request is sent when the user types '>' or ':', but we only
1724-
// want to trigger on '->' and '::'. We check the preceeding text to make
1723+
// want to trigger on '->' and '::'. We check the preceding text to make
17251724
// sure it matches what we expected.
17261725
// Running the lexer here would be more robust (e.g. we can detect comments
17271726
// and avoid triggering completion there), but we choose to err on the side
@@ -1744,7 +1743,7 @@ bool ClangdLSPServer::shouldRunCompletion(
17441743
}
17451744

17461745
void ClangdLSPServer::onDiagnosticsReady(PathRef File, llvm::StringRef Version,
1747-
std::vector<Diag> Diagnostics) {
1746+
llvm::ArrayRef<Diag> Diagnostics) {
17481747
PublishDiagnosticsParams Notification;
17491748
Notification.version = decodeVersion(Version);
17501749
Notification.uri = URIForFile::canonicalize(File, /*TUPath=*/File);

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDLSPSERVER_H
1111

1212
#include "ClangdServer.h"
13+
#include "Diagnostics.h"
1314
#include "GlobalCompilationDatabase.h"
1415
#include "LSPBinder.h"
1516
#include "Protocol.h"
@@ -18,6 +19,7 @@
1819
#include "support/MemoryTree.h"
1920
#include "support/Path.h"
2021
#include "support/Threading.h"
22+
#include "llvm/ADT/ArrayRef.h"
2123
#include "llvm/Support/JSON.h"
2224
#include <chrono>
2325
#include <cstddef>
@@ -80,7 +82,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
8082
private:
8183
// Implement ClangdServer::Callbacks.
8284
void onDiagnosticsReady(PathRef File, llvm::StringRef Version,
83-
std::vector<Diag> Diagnostics) override;
85+
llvm::ArrayRef<Diag> Diagnostics) override;
8486
void onFileUpdated(PathRef File, const TUStatus &Status) override;
8587
void onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats) override;
8688
void onSemanticsMaybeChanged(PathRef File) override;
@@ -197,7 +199,6 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
197199
void bindMethods(LSPBinder &, const ClientCapabilities &Caps);
198200
std::vector<CodeAction> getFixes(StringRef File, const clangd::Diagnostic &D);
199201

200-
201202
/// Checks if completion request should be ignored. We need this due to the
202203
/// limitation of the LSP. Per LSP, a client sends requests for all "trigger
203204
/// character" we specify, but for '>' and ':' we need to check they actually

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,10 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
124124
if (FIndex)
125125
FIndex->updateMain(Path, AST);
126126

127-
assert(AST.getDiagnostics() &&
128-
"We issue callback only with fresh preambles");
129-
std::vector<Diag> Diagnostics = *AST.getDiagnostics();
130127
if (ServerCallbacks)
131128
Publish([&]() {
132129
ServerCallbacks->onDiagnosticsReady(Path, AST.version(),
133-
std::move(Diagnostics));
130+
AST.getDiagnostics());
134131
if (CollectInactiveRegions) {
135132
ServerCallbacks->onInactiveRegionsReady(Path,
136133
getInactiveRegions(AST));
@@ -366,7 +363,7 @@ ClangdServer::createConfiguredContextProvider(const config::Provider *Provider,
366363
std::lock_guard<std::mutex> Lock(PublishMu);
367364
for (auto &Entry : ReportableDiagnostics)
368365
Publish->onDiagnosticsReady(Entry.first(), /*Version=*/"",
369-
std::move(Entry.second));
366+
Entry.second);
370367
}
371368
return Context::current().derive(Config::Key, std::move(C));
372369
}
@@ -1046,11 +1043,7 @@ void ClangdServer::diagnostics(PathRef File, Callback<std::vector<Diag>> CB) {
10461043
[CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
10471044
if (!InpAST)
10481045
return CB(InpAST.takeError());
1049-
if (auto Diags = InpAST->AST.getDiagnostics())
1050-
return CB(*Diags);
1051-
// FIXME: Use ServerCancelled error once it is settled in LSP-3.17.
1052-
return CB(llvm::make_error<LSPError>("server is busy parsing includes",
1053-
ErrorCode::InternalError));
1046+
return CB(InpAST->AST.getDiagnostics());
10541047
};
10551048

10561049
WorkScheduler->runWithAST("Diagnostics", File, std::move(Action));

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "support/Path.h"
3131
#include "support/ThreadsafeFS.h"
3232
#include "clang/Tooling/Core/Replacement.h"
33+
#include "llvm/ADT/ArrayRef.h"
3334
#include "llvm/ADT/FunctionExtras.h"
3435
#include "llvm/ADT/StringRef.h"
3536
#include <functional>
@@ -67,7 +68,7 @@ class ClangdServer {
6768
/// file, they do not interfere with "pull-based" ClangdServer::diagnostics.
6869
/// May be called concurrently for separate files, not for a single file.
6970
virtual void onDiagnosticsReady(PathRef File, llvm::StringRef Version,
70-
std::vector<Diag> Diagnostics) {}
71+
llvm::ArrayRef<Diag> Diagnostics) {}
7172
/// Called whenever the file status is updated.
7273
/// May be called concurrently for separate files, not for a single file.
7374
virtual void onFileUpdated(PathRef File, const TUStatus &Status) {}

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ struct CompletionCandidate {
214214
// Returns a token identifying the overload set this is part of.
215215
// 0 indicates it's not part of any overload set.
216216
size_t overloadSet(const CodeCompleteOptions &Opts, llvm::StringRef FileName,
217-
IncludeInserter *Inserter) const {
217+
IncludeInserter *Inserter,
218+
CodeCompletionContext::Kind CCContextKind) const {
218219
if (!Opts.BundleOverloads.value_or(false))
219220
return 0;
220221

@@ -223,7 +224,7 @@ struct CompletionCandidate {
223224
// bundle those, so we must resolve the header to be included here.
224225
std::string HeaderForHash;
225226
if (Inserter) {
226-
if (auto Header = headerToInsertIfAllowed(Opts)) {
227+
if (auto Header = headerToInsertIfAllowed(Opts, CCContextKind)) {
227228
if (auto HeaderFile = toHeaderFile(*Header, FileName)) {
228229
if (auto Spelled =
229230
Inserter->calculateIncludePath(*HeaderFile, FileName))
@@ -271,11 +272,21 @@ struct CompletionCandidate {
271272
return 0;
272273
}
273274

275+
bool contextAllowsHeaderInsertion(CodeCompletionContext::Kind Kind) const {
276+
// Explicitly disable insertions for forward declarations since they don't
277+
// reference the declaration.
278+
if (Kind == CodeCompletionContext::CCC_ObjCClassForwardDecl)
279+
return false;
280+
return true;
281+
}
282+
274283
// The best header to include if include insertion is allowed.
275284
std::optional<llvm::StringRef>
276-
headerToInsertIfAllowed(const CodeCompleteOptions &Opts) const {
285+
headerToInsertIfAllowed(const CodeCompleteOptions &Opts,
286+
CodeCompletionContext::Kind ContextKind) const {
277287
if (Opts.InsertIncludes == CodeCompleteOptions::NeverInsert ||
278-
RankedIncludeHeaders.empty())
288+
RankedIncludeHeaders.empty() ||
289+
!contextAllowsHeaderInsertion(ContextKind))
279290
return std::nullopt;
280291
if (SemaResult && SemaResult->Declaration) {
281292
// Avoid inserting new #include if the declaration is found in the current
@@ -401,7 +412,8 @@ struct CodeCompletionBuilder {
401412
std::move(*Spelled),
402413
Includes.shouldInsertInclude(*ResolvedDeclaring, *ResolvedInserted));
403414
};
404-
bool ShouldInsert = C.headerToInsertIfAllowed(Opts).has_value();
415+
bool ShouldInsert =
416+
C.headerToInsertIfAllowed(Opts, ContextKind).has_value();
405417
Symbol::IncludeDirective Directive = insertionDirective(Opts);
406418
// Calculate include paths and edits for all possible headers.
407419
for (const auto &Inc : C.RankedIncludeHeaders) {
@@ -780,6 +792,7 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K) {
780792
case CodeCompletionContext::CCC_ObjCInterfaceName:
781793
case CodeCompletionContext::CCC_Symbol:
782794
case CodeCompletionContext::CCC_SymbolOrNewName:
795+
case CodeCompletionContext::CCC_ObjCClassForwardDecl:
783796
return true;
784797
case CodeCompletionContext::CCC_OtherWithMacros:
785798
case CodeCompletionContext::CCC_DotMemberAccess:
@@ -1422,6 +1435,10 @@ bool includeSymbolFromIndex(CodeCompletionContext::Kind Kind,
14221435
else if (Kind == CodeCompletionContext::CCC_ObjCProtocolName)
14231436
// Don't show anything else in ObjC protocol completions.
14241437
return false;
1438+
1439+
if (Kind == CodeCompletionContext::CCC_ObjCClassForwardDecl)
1440+
return Sym.SymInfo.Kind == index::SymbolKind::Class &&
1441+
Sym.SymInfo.Lang == index::SymbolLanguage::ObjC;
14251442
return true;
14261443
}
14271444

@@ -1832,8 +1849,8 @@ class CodeCompleteFlow {
18321849
assert(IdentifierResult);
18331850
C.Name = IdentifierResult->Name;
18341851
}
1835-
if (auto OverloadSet =
1836-
C.overloadSet(Opts, FileName, Inserter ? &*Inserter : nullptr)) {
1852+
if (auto OverloadSet = C.overloadSet(
1853+
Opts, FileName, Inserter ? &*Inserter : nullptr, CCContextKind)) {
18371854
auto Ret = BundleLookup.try_emplace(OverloadSet, Bundles.size());
18381855
if (Ret.second)
18391856
Bundles.emplace_back();

clang-tools-extra/clangd/Config.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,11 @@ struct Config {
100100

101101
/// Configures what clang-tidy checks to run and options to use with them.
102102
struct {
103-
// A comma-seperated list of globs specify which clang-tidy checks to run.
103+
// A comma-separated list of globs specify which clang-tidy checks to run.
104104
std::string Checks;
105105
llvm::StringMap<std::string> CheckOptions;
106106
} ClangTidy;
107107

108-
/// Enable emitting diagnostics using stale preambles.
109-
bool AllowStalePreamble = false;
110-
111108
IncludesPolicy UnusedIncludes = IncludesPolicy::Strict;
112109
IncludesPolicy MissingIncludes = IncludesPolicy::None;
113110

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,6 @@ struct FragmentCompiler {
451451
}
452452
}
453453

454-
if (F.AllowStalePreamble) {
455-
if (auto Val = F.AllowStalePreamble)
456-
Out.Apply.push_back([Val](const Params &, Config &C) {
457-
C.Diagnostics.AllowStalePreamble = **Val;
458-
});
459-
}
460-
461454
if (F.MissingIncludes)
462455
if (auto Val = compileEnum<Config::IncludesPolicy>("MissingIncludes",
463456
**F.MissingIncludes)

clang-tools-extra/clangd/ConfigFragment.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ struct Fragment {
235235
/// - std::nullopt
236236
std::optional<Located<std::string>> UnusedIncludes;
237237

238-
/// Enable emitting diagnostics using stale preambles.
239-
std::optional<Located<bool>> AllowStalePreamble;
240-
241238
/// Controls if clangd should analyze missing #include directives.
242239
/// clangd will warn if no header providing a symbol is `#include`d
243240
/// (missing) directly, and suggest adding it.

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ class Parser {
134134
});
135135
Dict.handle("Includes", [&](Node &N) { parse(F.Includes, N); });
136136
Dict.handle("ClangTidy", [&](Node &N) { parse(F.ClangTidy, N); });
137-
Dict.handle("AllowStalePreamble", [&](Node &N) {
138-
F.AllowStalePreamble = boolValue(N, "AllowStalePreamble");
139-
});
140137
Dict.parse(N);
141138
}
142139

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,13 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
422422
});
423423

424424
std::optional<PreamblePatch> Patch;
425-
bool PreserveDiags = true;
426425
// We might use an ignoring diagnostic consumer if they are going to be
427426
// dropped later on to not pay for extra latency by processing them.
428427
DiagnosticConsumer *DiagConsumer = &ASTDiags;
429428
IgnoreDiagnostics DropDiags;
430429
if (Preamble) {
431430
Patch = PreamblePatch::createFullPatch(Filename, Inputs, *Preamble);
432431
Patch->apply(*CI);
433-
PreserveDiags = Patch->preserveDiagnostics();
434-
if (!PreserveDiags)
435-
DiagConsumer = &DropDiags;
436432
}
437433
auto Clang = prepareCompilerInstance(
438434
std::move(CI), PreamblePCH,
@@ -448,7 +444,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
448444
return std::nullopt;
449445
}
450446
tidy::ClangTidyOptions ClangTidyOpts;
451-
if (PreserveDiags) {
447+
{
452448
trace::Span Tracer("ClangTidyOpts");
453449
ClangTidyOpts = getTidyOptionsForFile(Inputs.ClangTidyProvider, Filename);
454450
dlog("ClangTidy configuration for file {0}: {1}", Filename,
@@ -479,9 +475,6 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
479475
applyWarningOptions(*ClangTidyOpts.ExtraArgsBefore, TidyGroups, Diags);
480476
if (ClangTidyOpts.ExtraArgs)
481477
applyWarningOptions(*ClangTidyOpts.ExtraArgs, TidyGroups, Diags);
482-
} else {
483-
// Skips some analysis.
484-
Clang->getDiagnosticOpts().IgnoreWarnings = true;
485478
}
486479

487480
auto Action = std::make_unique<ClangdFrontendAction>();
@@ -517,7 +510,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
517510
llvm::DenseMap<diag::kind, DiagnosticsEngine::Level> OverriddenSeverity;
518511
// No need to run clang-tidy or IncludeFixerif we are not going to surface
519512
// diagnostics.
520-
if (PreserveDiags) {
513+
{
521514
trace::Span Tracer("ClangTidyInit");
522515
static const auto *CTFactories = [] {
523516
auto *CTFactories = new tidy::ClangTidyCheckFactories;
@@ -712,28 +705,24 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
712705
// CompilerInstance won't run this callback, do it directly.
713706
ASTDiags.EndSourceFile();
714707

715-
std::optional<std::vector<Diag>> Diags;
716-
// FIXME: Also skip generation of diagnostics alltogether to speed up ast
708+
std::vector<Diag> Diags = CompilerInvocationDiags;
709+
// FIXME: Also skip generation of diagnostics altogether to speed up ast
717710
// builds when we are patching a stale preamble.
718-
if (PreserveDiags) {
719-
Diags = CompilerInvocationDiags;
720-
// Add diagnostics from the preamble, if any.
721-
if (Preamble)
722-
llvm::append_range(*Diags, Patch->patchedDiags());
723-
// Finally, add diagnostics coming from the AST.
724-
{
725-
std::vector<Diag> D = ASTDiags.take(&*CTContext);
726-
Diags->insert(Diags->end(), D.begin(), D.end());
727-
}
711+
// Add diagnostics from the preamble, if any.
712+
if (Preamble)
713+
llvm::append_range(Diags, Patch->patchedDiags());
714+
// Finally, add diagnostics coming from the AST.
715+
{
716+
std::vector<Diag> D = ASTDiags.take(&*CTContext);
717+
Diags.insert(Diags.end(), D.begin(), D.end());
728718
}
729719
ParsedAST Result(Filename, Inputs.Version, std::move(Preamble),
730720
std::move(Clang), std::move(Action), std::move(Tokens),
731721
std::move(Macros), std::move(Marks), std::move(ParsedDecls),
732722
std::move(Diags), std::move(Includes),
733723
std::move(CanonIncludes));
734-
if (Result.Diags)
735-
llvm::move(getIncludeCleanerDiags(Result, Inputs.Contents),
736-
std::back_inserter(*Result.Diags));
724+
llvm::move(getIncludeCleanerDiags(Result, Inputs.Contents),
725+
std::back_inserter(Result.Diags));
737726
return std::move(Result);
738727
}
739728

@@ -785,8 +774,8 @@ std::size_t ParsedAST::getUsedBytes() const {
785774
auto &AST = getASTContext();
786775
// FIXME(ibiryukov): we do not account for the dynamically allocated part of
787776
// Message and Fixes inside each diagnostic.
788-
std::size_t Total = clangd::getUsedBytes(LocalTopLevelDecls) +
789-
(Diags ? clangd::getUsedBytes(*Diags) : 0);
777+
std::size_t Total =
778+
clangd::getUsedBytes(LocalTopLevelDecls) + clangd::getUsedBytes(Diags);
790779

791780
// FIXME: the rest of the function is almost a direct copy-paste from
792781
// libclang's clang_getCXTUResourceUsage. We could share the implementation.
@@ -828,8 +817,8 @@ ParsedAST::ParsedAST(PathRef TUPath, llvm::StringRef Version,
828817
syntax::TokenBuffer Tokens, MainFileMacros Macros,
829818
std::vector<PragmaMark> Marks,
830819
std::vector<Decl *> LocalTopLevelDecls,
831-
std::optional<std::vector<Diag>> Diags,
832-
IncludeStructure Includes, CanonicalIncludes CanonIncludes)
820+
std::vector<Diag> Diags, IncludeStructure Includes,
821+
CanonicalIncludes CanonIncludes)
833822
: TUPath(TUPath), Version(Version), Preamble(std::move(Preamble)),
834823
Clang(std::move(Clang)), Action(std::move(Action)),
835824
Tokens(std::move(Tokens)), Macros(std::move(Macros)),
@@ -853,5 +842,6 @@ std::optional<llvm::StringRef> ParsedAST::preambleVersion() const {
853842
return llvm::StringRef(Preamble->Version);
854843
}
855844

845+
llvm::ArrayRef<Diag> ParsedAST::getDiagnostics() const { return Diags; }
856846
} // namespace clangd
857847
} // namespace clang

0 commit comments

Comments
 (0)