Files
TheRock/compiler/amd-llvm/clang-tools-extra/clangd/DecisionForest.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

99 lines
3.3 KiB
C++

//===--- DecisionForest.cpp --------------------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "Features.inc"
#if !CLANGD_DECISION_FOREST
#include "Quality.h"
#include <cstdlib>
namespace clang {
namespace clangd {
DecisionForestScores
evaluateDecisionForest(const SymbolQualitySignals &Quality,
const SymbolRelevanceSignals &Relevance, float Base) {
llvm::errs() << "Clangd was compiled without decision forest support.\n";
std::abort();
}
} // namespace clangd
} // namespace clang
#else // !CLANGD_DECISION_FOREST
#include "CompletionModel.h"
#include "Quality.h"
#include <cmath>
namespace clang {
namespace clangd {
DecisionForestScores
evaluateDecisionForest(const SymbolQualitySignals &Quality,
const SymbolRelevanceSignals &Relevance, float Base) {
Example E;
E.setIsDeprecated(Quality.Deprecated);
E.setIsReservedName(Quality.ReservedName);
E.setIsImplementationDetail(Quality.ImplementationDetail);
E.setNumReferences(Quality.References);
E.setSymbolCategory(Quality.Category);
SymbolRelevanceSignals::DerivedSignals Derived =
Relevance.calculateDerivedSignals();
int NumMatch = 0;
if (Relevance.ContextWords) {
for (const auto &Word : Relevance.ContextWords->keys()) {
if (Relevance.Name.contains_insensitive(Word)) {
++NumMatch;
}
}
}
E.setIsNameInContext(NumMatch > 0);
E.setNumNameInContext(NumMatch);
E.setFractionNameInContext(
Relevance.ContextWords && !Relevance.ContextWords->empty()
? NumMatch * 1.0 / Relevance.ContextWords->size()
: 0);
E.setIsInBaseClass(Relevance.InBaseClass);
E.setFileProximityDistanceCost(Derived.FileProximityDistance);
E.setSemaFileProximityScore(Relevance.SemaFileProximityScore);
E.setSymbolScopeDistanceCost(Derived.ScopeProximityDistance);
E.setSemaSaysInScope(Relevance.SemaSaysInScope);
E.setScope(Relevance.Scope);
E.setContextKind(Relevance.Context);
E.setIsInstanceMember(Relevance.IsInstanceMember);
E.setHadContextType(Relevance.HadContextType);
E.setHadSymbolType(Relevance.HadSymbolType);
E.setTypeMatchesPreferred(Relevance.TypeMatchesPreferred);
DecisionForestScores Scores;
// Exponentiating DecisionForest prediction makes the score of each tree a
// multiplciative boost (like NameMatch). This allows us to weigh the
// prediction score and NameMatch appropriately.
Scores.ExcludingName = pow(Base, Evaluate(E));
// Following cases are not part of the generated training dataset:
// - Symbols with `NeedsFixIts`.
// - Forbidden symbols.
// - Keywords: Dataset contains only macros and decls.
if (Relevance.NeedsFixIts)
Scores.ExcludingName *= 0.5;
if (Relevance.Forbidden)
Scores.ExcludingName *= 0;
if (Quality.Category == SymbolQualitySignals::Keyword)
Scores.ExcludingName *= 4;
// NameMatch should be a multiplier on total score to support rescoring.
Scores.Total = Relevance.NameMatch * Scores.ExcludingName;
return Scores;
}
} // namespace clangd
} // namespace clang
#endif // !CLANGD_DECISION_FOREST