Skip to content

Commit 1d0d565

Browse files
Merge from 'master' to 'sycl-web' (#1)
2 parents 8e6e373 + e5699b8 commit 1d0d565

File tree

2,137 files changed

+177448
-147468
lines changed

Some content is hidden

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

2,137 files changed

+177448
-147468
lines changed

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
5252
/// Makes sure we have contents for all the files we were interested in. Ideally
5353
/// `FilesToRecord` should be empty.
5454
void checkAllFilesRecorded() {
55-
for (auto FileEntry : FilesToRecord)
56-
LLVM_DEBUG(llvm::dbgs() << "Did not record contents for input file: "
57-
<< FileEntry->getName() << "\n");
55+
LLVM_DEBUG({
56+
for (auto FileEntry : FilesToRecord)
57+
llvm::dbgs() << "Did not record contents for input file: "
58+
<< FileEntry->getName() << "\n";
59+
});
5860
}
5961

6062
private:

clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,26 @@ static StringRef const StyleNames[] = {
124124

125125
static std::vector<llvm::Optional<IdentifierNamingCheck::NamingStyle>>
126126
getNamingStyles(const ClangTidyCheck::OptionsView &Options) {
127-
std::vector<llvm::Optional<IdentifierNamingCheck::NamingStyle>> Styles;
128-
Styles.reserve(array_lengthof(StyleNames));
129-
for (auto const &StyleName : StyleNames) {
130-
auto CaseOptional = Options.getOptional<IdentifierNamingCheck::CaseType>(
131-
(StyleName + "Case").str());
132-
auto Prefix = Options.get((StyleName + "Prefix").str(), "");
133-
auto Postfix = Options.get((StyleName + "Suffix").str(), "");
127+
std::vector<llvm::Optional<IdentifierNamingCheck::NamingStyle>> Styles(
128+
SK_Count);
129+
SmallString<64> StyleString;
130+
for (unsigned I = 0; I < SK_Count; ++I) {
131+
StyleString = StyleNames[I];
132+
size_t StyleSize = StyleString.size();
133+
StyleString.append("Prefix");
134+
std::string Prefix(Options.get(StyleString, ""));
135+
// Fast replacement of [Pre]fix -> [Suf]fix.
136+
memcpy(&StyleString[StyleSize], "Suf", 3);
137+
std::string Postfix(Options.get(StyleString, ""));
138+
memcpy(&StyleString[StyleSize], "Case", 4);
139+
StyleString.pop_back();
140+
StyleString.pop_back();
141+
auto CaseOptional =
142+
Options.getOptional<IdentifierNamingCheck::CaseType>(StyleString);
134143

135144
if (CaseOptional || !Prefix.empty() || !Postfix.empty())
136-
Styles.emplace_back(IdentifierNamingCheck::NamingStyle{
137-
std::move(CaseOptional), std::move(Prefix), std::move(Postfix)});
138-
else
139-
Styles.emplace_back(llvm::None);
145+
Styles[I].emplace(std::move(CaseOptional), std::move(Prefix),
146+
std::move(Postfix));
140147
}
141148
return Styles;
142149
}
@@ -161,18 +168,23 @@ IdentifierNamingCheck::~IdentifierNamingCheck() = default;
161168

162169
void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
163170
RenamerClangTidyCheck::storeOptions(Opts);
164-
ArrayRef<llvm::Optional<NamingStyle>> NamingStyles =
165-
getStyleForFile(Context->getCurrentFile());
171+
SmallString<64> StyleString;
166172
for (size_t I = 0; I < SK_Count; ++I) {
167-
if (!NamingStyles[I])
173+
if (!MainFileStyle[I])
168174
continue;
169-
if (NamingStyles[I]->Case)
170-
Options.store(Opts, (StyleNames[I] + "Case").str(),
171-
*NamingStyles[I]->Case);
172-
Options.store(Opts, (StyleNames[I] + "Prefix").str(),
173-
NamingStyles[I]->Prefix);
174-
Options.store(Opts, (StyleNames[I] + "Suffix").str(),
175-
NamingStyles[I]->Suffix);
175+
StyleString = StyleNames[I];
176+
size_t StyleSize = StyleString.size();
177+
StyleString.append("Prefix");
178+
Options.store(Opts, StyleString, MainFileStyle[I]->Prefix);
179+
// Fast replacement of [Pre]fix -> [Suf]fix.
180+
memcpy(&StyleString[StyleSize], "Suf", 3);
181+
Options.store(Opts, StyleString, MainFileStyle[I]->Suffix);
182+
if (MainFileStyle[I]->Case) {
183+
memcpy(&StyleString[StyleSize], "Case", 4);
184+
StyleString.pop_back();
185+
StyleString.pop_back();
186+
Options.store(Opts, StyleString, *MainFileStyle[I]->Case);
187+
}
176188
}
177189
Options.store(Opts, "GetConfigPerFile", GetConfigPerFile);
178190
Options.store(Opts, "IgnoreFailedSplit", IgnoreFailedSplit);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ StringRef MakeCanonicalName(StringRef Str, IncludeSorter::IncludeStyle Style) {
4545

4646
// Objective-C categories have a `+suffix` format, but should be grouped
4747
// with the file they are a category of.
48+
size_t StartIndex = Canonical.find_last_of('/');
49+
if (StartIndex == StringRef::npos) {
50+
StartIndex = 0;
51+
}
4852
return Canonical.substr(
49-
0, Canonical.find_first_of('+', Canonical.find_last_of('/')));
53+
0, Canonical.find_first_of('+', StartIndex));
5054
}
5155
return RemoveFirstSuffix(
5256
RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}),

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -993,12 +993,24 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
993993
if (!Code)
994994
return Reply(llvm::make_error<LSPError>(
995995
"onCodeAction called for non-added file", ErrorCode::InvalidParams));
996+
997+
// Checks whether a particular CodeActionKind is included in the response.
998+
auto KindAllowed = [Only(Params.context.only)](llvm::StringRef Kind) {
999+
if (Only.empty())
1000+
return true;
1001+
return llvm::any_of(Only, [&](llvm::StringRef Base) {
1002+
return Kind.consume_front(Base) && (Kind.empty() || Kind.startswith("."));
1003+
});
1004+
};
1005+
9961006
// We provide a code action for Fixes on the specified diagnostics.
9971007
std::vector<CodeAction> FixIts;
998-
for (const Diagnostic &D : Params.context.diagnostics) {
999-
for (auto &F : getFixes(File.file(), D)) {
1000-
FixIts.push_back(toCodeAction(F, Params.textDocument.uri));
1001-
FixIts.back().diagnostics = {D};
1008+
if (KindAllowed(CodeAction::QUICKFIX_KIND)) {
1009+
for (const Diagnostic &D : Params.context.diagnostics) {
1010+
for (auto &F : getFixes(File.file(), D)) {
1011+
FixIts.push_back(toCodeAction(F, Params.textDocument.uri));
1012+
FixIts.back().diagnostics = {D};
1013+
}
10021014
}
10031015
}
10041016

@@ -1038,14 +1050,10 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
10381050
}
10391051
return Reply(llvm::json::Array(Commands));
10401052
};
1041-
10421053
Server->enumerateTweaks(
10431054
File.file(), Params.range,
1044-
[&](const Tweak &T) {
1045-
if (!Opts.TweakFilter(T))
1046-
return false;
1047-
// FIXME: also consider CodeActionContext.only
1048-
return true;
1055+
[this, KindAllowed(std::move(KindAllowed))](const Tweak &T) {
1056+
return Opts.TweakFilter(T) && KindAllowed(T.kind());
10491057
},
10501058
std::move(ConsumeActions));
10511059
}

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,19 +1644,10 @@ class CodeCompleteFlow {
16441644
return Scores;
16451645

16461646
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;
1647+
DecisionForestScores DFScores = Opts.DecisionForestScorer(
1648+
Quality, Relevance, Opts.DecisionForestBase);
1649+
Scores.ExcludingName = DFScores.ExcludingName;
1650+
Scores.Total = DFScores.Total;
16601651
return Scores;
16611652
}
16621653
llvm_unreachable("Unhandled CodeCompletion ranking model.");

clang-tools-extra/clangd/CodeComplete.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,21 @@ struct CodeCompleteOptions {
154154
DecisionForest,
155155
} RankingModel = Heuristics;
156156

157+
/// Callback used to score a CompletionCandidate if DecisionForest ranking
158+
/// model is enabled.
159+
/// This allows us to inject experimental models and compare them with
160+
/// baseline model using A/B testing.
161+
std::function<DecisionForestScores(
162+
const SymbolQualitySignals &, const SymbolRelevanceSignals &, float Base)>
163+
DecisionForestScorer = &evaluateDecisionForest;
157164
/// Weight for combining NameMatch and Prediction of DecisionForest.
158165
/// CompletionScore is NameMatch * pow(Base, Prediction).
159166
/// The optimal value of Base largely depends on the semantics of the model
160167
/// and prediction score (e.g. algorithm used during training, number of
161168
/// trees, etc.). Usually if the range of Prediciton is [-20, 20] then a Base
162169
/// 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.
170+
/// Semantics: E.g. For Base = 1.3, if the Prediciton score reduces by 2.6
171+
/// points then completion score reduces by 50% or 1.3^(-2.6).
165172
float DecisionForestBase = 1.3f;
166173
};
167174

clang-tools-extra/clangd/FindSymbols.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ llvm::Optional<DocumentSymbol> declToSym(ASTContext &Ctx, const NamedDecl &ND) {
179179
return llvm::None;
180180

181181
index::SymbolInfo SymInfo = index::getSymbolInfo(&ND);
182-
// FIXME: this is not classifying constructors, destructors and operators
183-
// correctly (they're all "methods").
182+
// FIXME: This is not classifying constructors, destructors and operators
183+
// correctly.
184184
SymbolKind SK = indexSymbolKindToSymbolKind(SymInfo.Kind);
185185

186186
DocumentSymbol SI;

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,10 @@ llvm::json::Value toJSON(const PublishDiagnosticsParams &PDP) {
599599
bool fromJSON(const llvm::json::Value &Params, CodeActionContext &R,
600600
llvm::json::Path P) {
601601
llvm::json::ObjectMapper O(Params, P);
602-
return O && O.map("diagnostics", R.diagnostics);
602+
if (!O || !O.map("diagnostics", R.diagnostics))
603+
return false;
604+
O.map("only", R.only);
605+
return true;
603606
}
604607

605608
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Diagnostic &D) {

clang-tools-extra/clangd/Protocol.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,19 @@ struct PublishDiagnosticsParams {
863863
llvm::json::Value toJSON(const PublishDiagnosticsParams &);
864864

865865
struct CodeActionContext {
866-
/// An array of diagnostics.
866+
/// An array of diagnostics known on the client side overlapping the range
867+
/// provided to the `textDocument/codeAction` request. They are provided so
868+
/// that the server knows which errors are currently presented to the user for
869+
/// the given range. There is no guarantee that these accurately reflect the
870+
/// error state of the resource. The primary parameter to compute code actions
871+
/// is the provided range.
867872
std::vector<Diagnostic> diagnostics;
873+
874+
/// Requested kind of actions to return.
875+
///
876+
/// Actions not of this kind are filtered out by the client before being
877+
/// shown. So servers can omit computing them.
878+
std::vector<std::string> only;
868879
};
869880
bool fromJSON(const llvm::json::Value &, CodeActionContext &, llvm::json::Path);
870881

clang-tools-extra/clangd/Quality.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,9 @@ float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance) {
487487
return SymbolQuality * SymbolRelevance;
488488
}
489489

490-
float evaluateDecisionForest(const SymbolQualitySignals &Quality,
491-
const SymbolRelevanceSignals &Relevance) {
490+
DecisionForestScores
491+
evaluateDecisionForest(const SymbolQualitySignals &Quality,
492+
const SymbolRelevanceSignals &Relevance, float Base) {
492493
Example E;
493494
E.setIsDeprecated(Quality.Deprecated);
494495
E.setIsReservedName(Quality.ReservedName);
@@ -512,7 +513,19 @@ float evaluateDecisionForest(const SymbolQualitySignals &Quality,
512513
E.setHadSymbolType(Relevance.HadSymbolType);
513514
E.setTypeMatchesPreferred(Relevance.TypeMatchesPreferred);
514515
E.setFilterLength(Relevance.FilterLength);
515-
return Evaluate(E);
516+
517+
DecisionForestScores Scores;
518+
// Exponentiating DecisionForest prediction makes the score of each tree a
519+
// multiplciative boost (like NameMatch). This allows us to weigh the
520+
// prediciton score and NameMatch appropriately.
521+
Scores.ExcludingName = pow(Base, Evaluate(E));
522+
// NeedsFixIts is not part of the DecisionForest as generating training
523+
// data that needs fixits is not-feasible.
524+
if (Relevance.NeedsFixIts)
525+
Scores.ExcludingName *= 0.5;
526+
// NameMatch should be a multiplier on total score to support rescoring.
527+
Scores.Total = Relevance.NameMatch * Scores.ExcludingName;
528+
return Scores;
516529
}
517530

518531
// Produces an integer that sorts in the same order as F.

clang-tools-extra/clangd/Quality.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,18 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &,
165165
/// Combine symbol quality and relevance into a single score.
166166
float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance);
167167

168-
float evaluateDecisionForest(const SymbolQualitySignals &Quality,
169-
const SymbolRelevanceSignals &Relevance);
168+
/// Same semantics as CodeComplete::Score. Quality score and Relevance score
169+
/// have been removed since DecisionForest cannot assign individual scores to
170+
/// Quality and Relevance signals.
171+
struct DecisionForestScores {
172+
float Total = 0.f;
173+
float ExcludingName = 0.f;
174+
};
175+
176+
DecisionForestScores
177+
evaluateDecisionForest(const SymbolQualitySignals &Quality,
178+
const SymbolRelevanceSignals &Relevance, float Base);
179+
170180
/// TopN<T> is a lossy container that preserves only the "best" N elements.
171181
template <typename T, typename Compare = std::greater<T>> class TopN {
172182
public:

0 commit comments

Comments
 (0)