Skip to content

Commit 80ed4b5

Browse files
author
iclsrc
committed
Merge from 'master' to 'sycl-web'
2 parents 9b2364e + da036b4 commit 80ed4b5

File tree

411 files changed

+392607
-4150
lines changed

Some content is hidden

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

411 files changed

+392607
-4150
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
106106
// Create a preprocessor #include FixIt hint (CreateIncludeInsertion checks
107107
// whether this already exists).
108108
Diagnostic << IncludeInserter.createIncludeInsertion(
109-
Source.getFileID(ComparisonExpr->getBeginLoc()), AbseilStringsMatchHeader,
110-
false);
109+
Source.getFileID(ComparisonExpr->getBeginLoc()),
110+
AbseilStringsMatchHeader);
111111
}
112112

113113
void StringFindStartswithCheck::registerPPCallbacks(

clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ InitVariablesCheck::InitVariablesCheck(StringRef Name,
2828
: ClangTidyCheck(Name, Context),
2929
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
3030
utils::IncludeSorter::IS_LLVM)),
31-
MathHeader(Options.get("MathHeader", "math.h")) {}
31+
MathHeader(Options.get("MathHeader", "<math.h>")) {}
3232

3333
void InitVariablesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
3434
Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
@@ -103,7 +103,7 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
103103
InitializationString);
104104
if (AddMathInclude) {
105105
Diagnostic << IncludeInserter.createIncludeInsertion(
106-
Source.getFileID(MatchedDecl->getBeginLoc()), MathHeader, false);
106+
Source.getFileID(MatchedDecl->getBeginLoc()), MathHeader);
107107
}
108108
}
109109
}

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ void ProBoundsConstantArrayIndexCheck::check(
8585
IndexRange.getBegin().getLocWithOffset(-1)),
8686
", ")
8787
<< FixItHint::CreateReplacement(Matched->getEndLoc(), ")")
88-
<< Inserter.createMainFileIncludeInsertion(GslHeader,
89-
/*IsAngled=*/false);
88+
<< Inserter.createMainFileIncludeInsertion(GslHeader);
9089
}
9190
return;
9291
}

clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace modernize {
1919

2020
namespace {
2121

22-
constexpr char StdMemoryHeader[] = "memory";
2322
constexpr char ConstructorCall[] = "constructorCall";
2423
constexpr char ResetCall[] = "resetCall";
2524
constexpr char NewExpression[] = "newExpression";
@@ -47,7 +46,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
4746
Inserter(Options.getLocalOrGlobal("IncludeStyle",
4847
utils::IncludeSorter::IS_LLVM)),
4948
MakeSmartPtrFunctionHeader(
50-
Options.get("MakeSmartPtrFunctionHeader", StdMemoryHeader)),
49+
Options.get("MakeSmartPtrFunctionHeader", "<memory>")),
5150
MakeSmartPtrFunctionName(
5251
Options.get("MakeSmartPtrFunction", MakeSmartPtrFunctionName)),
5352
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
@@ -430,9 +429,7 @@ void MakeSmartPtrCheck::insertHeader(DiagnosticBuilder &Diag, FileID FD) {
430429
if (MakeSmartPtrFunctionHeader.empty()) {
431430
return;
432431
}
433-
Diag << Inserter.createIncludeInsertion(
434-
FD, MakeSmartPtrFunctionHeader,
435-
/*IsAngled=*/MakeSmartPtrFunctionHeader == StdMemoryHeader);
432+
Diag << Inserter.createIncludeInsertion(FD, MakeSmartPtrFunctionHeader);
436433
}
437434

438435
} // namespace modernize

clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
216216
Initializer->getLParenLoc().getLocWithOffset(1), "std::move(")
217217
<< Inserter.createIncludeInsertion(
218218
Result.SourceManager->getFileID(Initializer->getSourceLocation()),
219-
"utility",
220-
/*IsAngled=*/true);
219+
"<utility>");
221220
}
222221

223222
} // namespace modernize

clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ void ReplaceAutoPtrCheck::check(const MatchFinder::MatchResult &Result) {
147147
auto Diag = diag(Range.getBegin(), "use std::move to transfer ownership")
148148
<< FixItHint::CreateInsertion(Range.getBegin(), "std::move(")
149149
<< FixItHint::CreateInsertion(Range.getEnd(), ")")
150-
<< Inserter.createMainFileIncludeInsertion("utility",
151-
/*IsAngled=*/true);
150+
<< Inserter.createMainFileIncludeInsertion("<utility>");
152151

153152
return;
154153
}

clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void ReplaceRandomShuffleCheck::check(const MatchFinder::MatchResult &Result) {
9494
Diag << IncludeInserter.createIncludeInsertion(
9595
Result.Context->getSourceManager().getFileID(
9696
MatchedCallExpr->getBeginLoc()),
97-
"random", /*IsAngled=*/true);
97+
"<random>");
9898
}
9999

100100
} // namespace modernize

clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void TypePromotionInMathFnCheck::check(const MatchFinder::MatchResult &Result) {
192192
if (FnInCmath)
193193
Diag << IncludeInserter.createIncludeInsertion(
194194
Result.Context->getSourceManager().getFileID(Call->getBeginLoc()),
195-
"cmath", /*IsAngled=*/true);
195+
"<cmath>");
196196
}
197197

198198
} // namespace performance

clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ void UnnecessaryValueParamCheck::handleMoveFix(const ParmVarDecl &Var,
203203
Diag << FixItHint::CreateInsertion(CopyArgument.getBeginLoc(), "std::move(")
204204
<< FixItHint::CreateInsertion(EndLoc, ")")
205205
<< Inserter.createIncludeInsertion(
206-
SM.getFileID(CopyArgument.getBeginLoc()), "utility",
207-
/*IsAngled=*/true);
206+
SM.getFileID(CopyArgument.getBeginLoc()), "<utility>");
208207
}
209208

210209
} // namespace performance

clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ IncludeInserter::createIncludeInsertion(FileID FileID, StringRef Header,
7777
return getOrCreate(FileID).CreateIncludeInsertion(Header, IsAngled);
7878
}
7979

80+
llvm::Optional<FixItHint>
81+
IncludeInserter::createIncludeInsertion(FileID FileID, llvm::StringRef Header) {
82+
bool IsAngled = Header.consume_front("<");
83+
if (IsAngled != Header.consume_back(">"))
84+
return llvm::None;
85+
return createIncludeInsertion(FileID, Header, IsAngled);
86+
}
87+
8088
llvm::Optional<FixItHint>
8189
IncludeInserter::createMainFileIncludeInsertion(StringRef Header,
8290
bool IsAngled) {
@@ -85,6 +93,13 @@ IncludeInserter::createMainFileIncludeInsertion(StringRef Header,
8593
return createIncludeInsertion(SourceMgr->getMainFileID(), Header, IsAngled);
8694
}
8795

96+
llvm::Optional<FixItHint>
97+
IncludeInserter::createMainFileIncludeInsertion(StringRef Header) {
98+
assert(SourceMgr && "SourceMgr shouldn't be null; did you remember to call "
99+
"registerPreprocessor()?");
100+
return createIncludeInsertion(SourceMgr->getMainFileID(), Header);
101+
}
102+
88103
void IncludeInserter::addInclude(StringRef FileName, bool IsAngled,
89104
SourceLocation HashLocation,
90105
SourceLocation EndLocation) {

clang-tools-extra/clang-tidy/utils/IncludeInserter.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,35 @@ class IncludeInserter {
6969
/// Creates a \p Header inclusion directive fixit in the File \p FileID.
7070
/// Returns ``llvm::None`` on error or if the inclusion directive already
7171
/// exists.
72+
/// FIXME: This should be removed once the clients are migrated to the
73+
/// overload without the ``IsAngled`` parameter.
7274
llvm::Optional<FixItHint>
7375
createIncludeInsertion(FileID FileID, llvm::StringRef Header, bool IsAngled);
7476

77+
/// Creates a \p Header inclusion directive fixit in the File \p FileID.
78+
/// When \p Header is enclosed in angle brackets, uses angle brackets in the
79+
/// inclusion directive, otherwise uses quotes.
80+
/// Returns ``llvm::None`` on error or if the inclusion directive already
81+
/// exists.
82+
llvm::Optional<FixItHint> createIncludeInsertion(FileID FileID,
83+
llvm::StringRef Header);
84+
7585
/// Creates a \p Header inclusion directive fixit in the main file.
7686
/// Returns``llvm::None`` on error or if the inclusion directive already
7787
/// exists.
88+
/// FIXME: This should be removed once the clients are migrated to the
89+
/// overload without the ``IsAngled`` parameter.
7890
llvm::Optional<FixItHint>
7991
createMainFileIncludeInsertion(llvm::StringRef Header, bool IsAngled);
8092

93+
/// Creates a \p Header inclusion directive fixit in the main file.
94+
/// When \p Header is enclosed in angle brackets, uses angle brackets in the
95+
/// inclusion directive, otherwise uses quotes.
96+
/// Returns``llvm::None`` on error or if the inclusion directive already
97+
/// exists.
98+
llvm::Optional<FixItHint>
99+
createMainFileIncludeInsertion(llvm::StringRef Header);
100+
81101
IncludeSorter::IncludeStyle getStyle() const { return Style; }
82102

83103
private:

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,13 +1625,51 @@ class CodeCompleteFlow {
16251625
return Filter->match(C.Name);
16261626
}
16271627

1628+
CodeCompletion::Scores
1629+
evaluateCompletion(const SymbolQualitySignals &Quality,
1630+
const SymbolRelevanceSignals &Relevance) {
1631+
using RM = CodeCompleteOptions::CodeCompletionRankingModel;
1632+
CodeCompletion::Scores Scores;
1633+
switch (Opts.RankingModel) {
1634+
case RM::Heuristics:
1635+
Scores.Quality = Quality.evaluateHeuristics();
1636+
Scores.Relevance = Relevance.evaluateHeuristics();
1637+
Scores.Total =
1638+
evaluateSymbolAndRelevance(Scores.Quality, Scores.Relevance);
1639+
// NameMatch is in fact a multiplier on total score, so rescoring is
1640+
// sound.
1641+
Scores.ExcludingName = Relevance.NameMatch
1642+
? Scores.Total / Relevance.NameMatch
1643+
: Scores.Quality;
1644+
return Scores;
1645+
1646+
case RM::DecisionForest:
1647+
Scores.Quality = 0;
1648+
Scores.Relevance = 0;
1649+
// Exponentiating DecisionForest prediction makes the score of each tree a
1650+
// multiplciative boost (like NameMatch). This allows us to weigh the
1651+
// prediciton score and NameMatch appropriately.
1652+
Scores.ExcludingName = pow(Opts.DecisionForestBase,
1653+
evaluateDecisionForest(Quality, Relevance));
1654+
// NeedsFixIts is not part of the DecisionForest as generating training
1655+
// data that needs fixits is not-feasible.
1656+
if (Relevance.NeedsFixIts)
1657+
Scores.ExcludingName *= 0.5;
1658+
// NameMatch should be a multiplier on total score to support rescoring.
1659+
Scores.Total = Relevance.NameMatch * Scores.ExcludingName;
1660+
return Scores;
1661+
}
1662+
llvm_unreachable("Unhandled CodeCompletion ranking model.");
1663+
}
1664+
16281665
// Scores a candidate and adds it to the TopN structure.
16291666
void addCandidate(TopN<ScoredBundle, ScoredBundleGreater> &Candidates,
16301667
CompletionCandidate::Bundle Bundle) {
16311668
SymbolQualitySignals Quality;
16321669
SymbolRelevanceSignals Relevance;
16331670
Relevance.Context = CCContextKind;
16341671
Relevance.Name = Bundle.front().Name;
1672+
Relevance.FilterLength = HeuristicPrefix.Name.size();
16351673
Relevance.Query = SymbolRelevanceSignals::CodeComplete;
16361674
Relevance.FileProximityMatch = FileProximity.getPointer();
16371675
if (ScopeProximity)
@@ -1680,15 +1718,7 @@ class CodeCompleteFlow {
16801718
}
16811719
}
16821720

1683-
CodeCompletion::Scores Scores;
1684-
Scores.Quality = Quality.evaluate();
1685-
Scores.Relevance = Relevance.evaluate();
1686-
Scores.Total = evaluateSymbolAndRelevance(Scores.Quality, Scores.Relevance);
1687-
// NameMatch is in fact a multiplier on total score, so rescoring is sound.
1688-
Scores.ExcludingName = Relevance.NameMatch
1689-
? Scores.Total / Relevance.NameMatch
1690-
: Scores.Quality;
1691-
1721+
CodeCompletion::Scores Scores = evaluateCompletion(Quality, Relevance);
16921722
if (Opts.RecordCCResult)
16931723
Opts.RecordCCResult(toCodeCompletion(Bundle), Quality, Relevance,
16941724
Scores.Total);

clang-tools-extra/clangd/CodeComplete.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ struct CodeCompleteOptions {
147147
std::function<void(const CodeCompletion &, const SymbolQualitySignals &,
148148
const SymbolRelevanceSignals &, float Score)>
149149
RecordCCResult;
150+
151+
/// Model to use for ranking code completion candidates.
152+
enum CodeCompletionRankingModel {
153+
Heuristics,
154+
DecisionForest,
155+
} RankingModel = Heuristics;
156+
157+
/// Weight for combining NameMatch and Prediction of DecisionForest.
158+
/// CompletionScore is NameMatch * pow(Base, Prediction).
159+
/// The optimal value of Base largely depends on the semantics of the model
160+
/// and prediction score (e.g. algorithm used during training, number of
161+
/// trees, etc.). Usually if the range of Prediciton is [-20, 20] then a Base
162+
/// in [1.2, 1.7] works fine.
163+
/// Semantics: E.g. the completion score reduces by 50% if the Prediciton
164+
/// score is reduced by 2.6 points for Base = 1.3.
165+
float DecisionForestBase = 1.3f;
150166
};
151167

152168
// Semi-structured representation of a code-complete suggestion for our C++ API.

clang-tools-extra/clangd/FindSymbols.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ getWorkspaceSymbols(llvm::StringRef Query, int Limit,
116116
return;
117117
}
118118
Relevance.merge(Sym);
119-
auto Score =
120-
evaluateSymbolAndRelevance(Quality.evaluate(), Relevance.evaluate());
119+
auto Score = evaluateSymbolAndRelevance(Quality.evaluateHeuristics(),
120+
Relevance.evaluateHeuristics());
121121
dlog("FindSymbols: {0}{1} = {2}\n{3}{4}\n", Sym.Scope, Sym.Name, Score,
122122
Quality, Relevance);
123123

clang-tools-extra/clangd/Quality.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "Quality.h"
1010
#include "AST.h"
11+
#include "CompletionModel.h"
1112
#include "FileDistance.h"
1213
#include "SourceCode.h"
1314
#include "URI.h"
@@ -200,7 +201,7 @@ void SymbolQualitySignals::merge(const Symbol &IndexResult) {
200201
ReservedName = ReservedName || isReserved(IndexResult.Name);
201202
}
202203

203-
float SymbolQualitySignals::evaluate() const {
204+
float SymbolQualitySignals::evaluateHeuristics() const {
204205
float Score = 1;
205206

206207
// This avoids a sharp gradient for tail symbols, and also neatly avoids the
@@ -252,7 +253,7 @@ float SymbolQualitySignals::evaluate() const {
252253

253254
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
254255
const SymbolQualitySignals &S) {
255-
OS << llvm::formatv("=== Symbol quality: {0}\n", S.evaluate());
256+
OS << llvm::formatv("=== Symbol quality: {0}\n", S.evaluateHeuristics());
256257
OS << llvm::formatv("\tReferences: {0}\n", S.References);
257258
OS << llvm::formatv("\tDeprecated: {0}\n", S.Deprecated);
258259
OS << llvm::formatv("\tReserved name: {0}\n", S.ReservedName);
@@ -363,7 +364,7 @@ SymbolRelevanceSignals::calculateDerivedSignals() const {
363364
return Derived;
364365
}
365366

366-
float SymbolRelevanceSignals::evaluate() const {
367+
float SymbolRelevanceSignals::evaluateHeuristics() const {
367368
DerivedSignals Derived = calculateDerivedSignals();
368369
float Score = 1;
369370

@@ -444,7 +445,7 @@ float SymbolRelevanceSignals::evaluate() const {
444445

445446
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
446447
const SymbolRelevanceSignals &S) {
447-
OS << llvm::formatv("=== Symbol relevance: {0}\n", S.evaluate());
448+
OS << llvm::formatv("=== Symbol relevance: {0}\n", S.evaluateHeuristics());
448449
OS << llvm::formatv("\tName: {0}\n", S.Name);
449450
OS << llvm::formatv("\tName match: {0}\n", S.NameMatch);
450451
if (S.ContextWords)
@@ -486,6 +487,34 @@ float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance) {
486487
return SymbolQuality * SymbolRelevance;
487488
}
488489

490+
float evaluateDecisionForest(const SymbolQualitySignals &Quality,
491+
const SymbolRelevanceSignals &Relevance) {
492+
Example E;
493+
E.setIsDeprecated(Quality.Deprecated);
494+
E.setIsReservedName(Quality.ReservedName);
495+
E.setIsImplementationDetail(Quality.ImplementationDetail);
496+
E.setNumReferences(Quality.References);
497+
E.setSymbolCategory(Quality.Category);
498+
499+
SymbolRelevanceSignals::DerivedSignals Derived =
500+
Relevance.calculateDerivedSignals();
501+
E.setIsNameInContext(Derived.NameMatchesContext);
502+
E.setIsForbidden(Relevance.Forbidden);
503+
E.setIsInBaseClass(Relevance.InBaseClass);
504+
E.setFileProximityDistance(Derived.FileProximityDistance);
505+
E.setSemaFileProximityScore(Relevance.SemaFileProximityScore);
506+
E.setSymbolScopeDistance(Derived.ScopeProximityDistance);
507+
E.setSemaSaysInScope(Relevance.SemaSaysInScope);
508+
E.setScope(Relevance.Scope);
509+
E.setContextKind(Relevance.Context);
510+
E.setIsInstanceMember(Relevance.IsInstanceMember);
511+
E.setHadContextType(Relevance.HadContextType);
512+
E.setHadSymbolType(Relevance.HadSymbolType);
513+
E.setTypeMatchesPreferred(Relevance.TypeMatchesPreferred);
514+
E.setFilterLength(Relevance.FilterLength);
515+
return Evaluate(E);
516+
}
517+
489518
// Produces an integer that sorts in the same order as F.
490519
// That is: a < b <==> encodeFloat(a) < encodeFloat(b).
491520
static uint32_t encodeFloat(float F) {

clang-tools-extra/clangd/Quality.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct SymbolQualitySignals {
7878
void merge(const Symbol &IndexResult);
7979

8080
// Condense these signals down to a single number, higher is better.
81-
float evaluate() const;
81+
float evaluateHeuristics() const;
8282
};
8383
llvm::raw_ostream &operator<<(llvm::raw_ostream &,
8484
const SymbolQualitySignals &);
@@ -136,6 +136,10 @@ struct SymbolRelevanceSignals {
136136
// Whether the item matches the type expected in the completion context.
137137
bool TypeMatchesPreferred = false;
138138

139+
/// Length of the unqualified partial name of Symbol typed in
140+
/// CompletionPrefix.
141+
unsigned FilterLength = 0;
142+
139143
/// Set of derived signals computed by calculateDerivedSignals(). Must not be
140144
/// set explicitly.
141145
struct DerivedSignals {
@@ -153,14 +157,16 @@ struct SymbolRelevanceSignals {
153157
void merge(const Symbol &IndexResult);
154158

155159
// Condense these signals down to a single number, higher is better.
156-
float evaluate() const;
160+
float evaluateHeuristics() const;
157161
};
158162
llvm::raw_ostream &operator<<(llvm::raw_ostream &,
159163
const SymbolRelevanceSignals &);
160164

161165
/// Combine symbol quality and relevance into a single score.
162166
float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance);
163167

168+
float evaluateDecisionForest(const SymbolQualitySignals &Quality,
169+
const SymbolRelevanceSignals &Relevance);
164170
/// TopN<T> is a lossy container that preserves only the "best" N elements.
165171
template <typename T, typename Compare = std::greater<T>> class TopN {
166172
public:

0 commit comments

Comments
 (0)