cmComputeComponentGraph: use a name for "invalid component"

This is to prepare for making the graph use `size_t`.
This commit is contained in:
Ben Boeckel
2023-01-26 13:23:42 -05:00
parent 50abdaab93
commit 65c0a64dc5
5 changed files with 29 additions and 17 deletions

View File

@@ -5,6 +5,8 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
const int cmComputeComponentGraph::INVALID_COMPONENT = -1;
cmComputeComponentGraph::cmComputeComponentGraph(Graph const& input) cmComputeComponentGraph::cmComputeComponentGraph(Graph const& input)
: InputGraph(input) : InputGraph(input)
{ {
@@ -30,7 +32,7 @@ void cmComputeComponentGraph::Tarjan()
this->TarjanEntries.resize(0); this->TarjanEntries.resize(0);
this->TarjanEntries.resize(n, entry); this->TarjanEntries.resize(n, entry);
this->TarjanComponents.resize(0); this->TarjanComponents.resize(0);
this->TarjanComponents.resize(n, -1); this->TarjanComponents.resize(n, INVALID_COMPONENT);
this->TarjanWalkId = 0; this->TarjanWalkId = 0;
this->TarjanVisited.resize(0); this->TarjanVisited.resize(0);
this->TarjanVisited.resize(n, 0); this->TarjanVisited.resize(n, 0);
@@ -52,7 +54,7 @@ void cmComputeComponentGraph::TarjanVisit(int i)
// Initialize the entry. // Initialize the entry.
this->TarjanEntries[i].Root = i; this->TarjanEntries[i].Root = i;
this->TarjanComponents[i] = -1; this->TarjanComponents[i] = INVALID_COMPONENT;
this->TarjanEntries[i].VisitIndex = ++this->TarjanIndex; this->TarjanEntries[i].VisitIndex = ++this->TarjanIndex;
this->TarjanStack.push(i); this->TarjanStack.push(i);
@@ -77,7 +79,7 @@ void cmComputeComponentGraph::TarjanVisit(int i)
// If the destination has not yet been assigned to a component, // If the destination has not yet been assigned to a component,
// check if it has a better root for the current object. // check if it has a better root for the current object.
if (this->TarjanComponents[j] < 0) { if (this->TarjanComponents[j] == INVALID_COMPONENT) {
if (this->TarjanEntries[this->TarjanEntries[j].Root].VisitIndex < if (this->TarjanEntries[this->TarjanEntries[j].Root].VisitIndex <
this->TarjanEntries[this->TarjanEntries[i].Root].VisitIndex) { this->TarjanEntries[this->TarjanEntries[i].Root].VisitIndex) {
this->TarjanEntries[i].Root = this->TarjanEntries[j].Root; this->TarjanEntries[i].Root = this->TarjanEntries[j].Root;

View File

@@ -53,6 +53,8 @@ public:
return this->TarjanComponents; return this->TarjanComponents;
} }
static const int INVALID_COMPONENT;
private: private:
void TransferEdges(); void TransferEdges();

View File

@@ -518,7 +518,10 @@ void cmComputeLinkDepends::AddLinkObject(cmLinkItem const& item)
void cmComputeLinkDepends::FollowLinkEntry(BFSEntry qe) void cmComputeLinkDepends::FollowLinkEntry(BFSEntry qe)
{ {
// Get this entry representation. // Get this entry representation.
int depender_index = qe.GroupIndex == -1 ? qe.Index : qe.GroupIndex; int depender_index =
qe.GroupIndex == cmComputeComponentGraph::INVALID_COMPONENT
? qe.Index
: qe.GroupIndex;
LinkEntry const& entry = this->EntryList[qe.Index]; LinkEntry const& entry = this->EntryList[qe.Index];
// Follow the item's dependencies. // Follow the item's dependencies.
@@ -679,13 +682,15 @@ void cmComputeLinkDepends::AddDirectLinkEntries()
// Add direct link dependencies in this configuration. // Add direct link dependencies in this configuration.
cmLinkImplementation const* impl = this->Target->GetLinkImplementation( cmLinkImplementation const* impl = this->Target->GetLinkImplementation(
this->Config, cmGeneratorTarget::LinkInterfaceFor::Link); this->Config, cmGeneratorTarget::LinkInterfaceFor::Link);
this->AddLinkEntries(-1, impl->Libraries); this->AddLinkEntries(cmComputeComponentGraph::INVALID_COMPONENT,
impl->Libraries);
this->AddLinkObjects(impl->Objects); this->AddLinkObjects(impl->Objects);
for (auto const& language : impl->Languages) { for (auto const& language : impl->Languages) {
auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language); auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language);
if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) { if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
this->AddLinkEntries(-1, runtimeEntries->second); this->AddLinkEntries(cmComputeComponentGraph::INVALID_COMPONENT,
runtimeEntries->second);
} }
} }
for (cmLinkItem const& wi : impl->WrongConfigLibraries) { for (cmLinkItem const& wi : impl->WrongConfigLibraries) {
@@ -702,7 +707,8 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
std::string feature = LinkEntry::DEFAULT; std::string feature = LinkEntry::DEFAULT;
bool inGroup = false; bool inGroup = false;
std::pair<int, bool> groupIndex{ -1, false }; std::pair<int, bool> groupIndex{ cmComputeComponentGraph::INVALID_COMPONENT,
false };
std::vector<int> groupItems; std::vector<int> groupItems;
// Loop over the libraries linked directly by the depender. // Loop over the libraries linked directly by the depender.
@@ -719,7 +725,7 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
feature = ExtractFeature(item.AsStr()); feature = ExtractFeature(item.AsStr());
// emit a warning if an undefined feature is used as part of // emit a warning if an undefined feature is used as part of
// an imported target // an imported target
if (depender_index >= 0) { if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) {
const auto& depender = this->EntryList[depender_index]; const auto& depender = this->EntryList[depender_index];
if (depender.Target != nullptr && depender.Target->IsImported() && if (depender.Target != nullptr && depender.Target->IsImported() &&
!IsFeatureSupported(this->Makefile, this->LinkLanguage, feature)) { !IsFeatureSupported(this->Makefile, this->LinkLanguage, feature)) {
@@ -752,7 +758,7 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
entry.Feature = ExtractGroupFeature(item.AsStr()); entry.Feature = ExtractGroupFeature(item.AsStr());
} }
inGroup = true; inGroup = true;
if (depender_index >= 0) { if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) {
this->EntryConstraintGraph[depender_index].emplace_back( this->EntryConstraintGraph[depender_index].emplace_back(
groupIndex.first, false, false, cmListFileBacktrace()); groupIndex.first, false, false, cmListFileBacktrace());
} else { } else {
@@ -775,7 +781,8 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
continue; continue;
} }
if (depender_index >= 0 && inGroup) { if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT &&
inGroup) {
const auto& depender = this->EntryList[depender_index]; const auto& depender = this->EntryList[depender_index];
const auto& groupFeature = this->EntryList[groupIndex.first].Feature; const auto& groupFeature = this->EntryList[groupIndex.first].Feature;
if (depender.Target != nullptr && depender.Target->IsImported() && if (depender.Target != nullptr && depender.Target->IsImported() &&
@@ -913,7 +920,7 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
for (auto index : indexes) { for (auto index : indexes) {
// The dependee must come after the depender. // The dependee must come after the depender.
if (depender_index >= 0) { if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) {
this->EntryConstraintGraph[depender_index].emplace_back( this->EntryConstraintGraph[depender_index].emplace_back(
index, false, false, cmListFileBacktrace()); index, false, false, cmListFileBacktrace());
} else { } else {
@@ -962,7 +969,7 @@ cmLinkItem cmComputeLinkDepends::ResolveLinkItem(int depender_index,
{ {
// Look for a target in the scope of the depender. // Look for a target in the scope of the depender.
cmGeneratorTarget const* from = this->Target; cmGeneratorTarget const* from = this->Target;
if (depender_index >= 0) { if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) {
if (cmGeneratorTarget const* depender = if (cmGeneratorTarget const* depender =
this->EntryList[depender_index].Target) { this->EntryList[depender_index].Target) {
from = depender; from = depender;
@@ -1140,7 +1147,7 @@ void cmComputeLinkDepends::OrderLinkEntries()
this->ComponentOrderId = n; this->ComponentOrderId = n;
// Run in reverse order so the topological order will preserve the // Run in reverse order so the topological order will preserve the
// original order where there are no constraints. // original order where there are no constraints.
for (int c = n - 1; c >= 0; --c) { for (int c = n - 1; c != cmComputeComponentGraph::INVALID_COMPONENT; --c) {
this->VisitComponent(c); this->VisitComponent(c);
} }

View File

@@ -93,8 +93,9 @@ private:
std::pair<std::map<cmLinkItem, int>::iterator, bool> AllocateLinkEntry( std::pair<std::map<cmLinkItem, int>::iterator, bool> AllocateLinkEntry(
cmLinkItem const& item); cmLinkItem const& item);
std::pair<int, bool> AddLinkEntry(cmLinkItem const& item, std::pair<int, bool> AddLinkEntry(
int groupIndex = -1); cmLinkItem const& item,
int groupIndex = cmComputeComponentGraph::INVALID_COMPONENT);
void AddLinkObject(cmLinkItem const& item); void AddLinkObject(cmLinkItem const& item);
void AddVarLinkEntries(int depender_index, const char* value); void AddVarLinkEntries(int depender_index, const char* value);
void AddDirectLinkEntries(); void AddDirectLinkEntries();

View File

@@ -693,7 +693,7 @@ bool cmComputeTargetDepends::IntraComponent(std::vector<int> const& cmap,
} }
// Prepend to a linear linked-list of intra-component edges. // Prepend to a linear linked-list of intra-component edges.
if (*head >= 0) { if (*head != cmComputeComponentGraph::INVALID_COMPONENT) {
this->FinalGraph[i].emplace_back(*head, false, false, this->FinalGraph[i].emplace_back(*head, false, false,
cmListFileBacktrace()); cmListFileBacktrace());
} else { } else {
@@ -721,7 +721,7 @@ bool cmComputeTargetDepends::ComputeFinalDepends(
this->ComponentTail.resize(components.size()); this->ComponentTail.resize(components.size());
int nc = static_cast<int>(components.size()); int nc = static_cast<int>(components.size());
for (int c = 0; c < nc; ++c) { for (int c = 0; c < nc; ++c) {
int head = -1; int head = cmComputeComponentGraph::INVALID_COMPONENT;
std::set<int> emitted; std::set<int> emitted;
NodeList const& nl = components[c]; NodeList const& nl = components[c];
for (int ni : cmReverseRange(nl)) { for (int ni : cmReverseRange(nl)) {