GenEx: Limit TARGET_PROPERTY transitive closure optimization to subgraphs

Fixes: #25728
This commit is contained in:
Michael Herwig
2024-05-31 18:15:55 +02:00
parent 9673f61be1
commit 4a11772618
8 changed files with 78 additions and 8 deletions
+17 -5
View File
@@ -24,7 +24,7 @@ cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
std::string const& contextConfig)
: cmGeneratorExpressionDAGChecker(cmListFileBacktrace(), target,
std::move(property), content, parent,
contextLG, contextConfig)
contextLG, contextConfig, INHERIT)
{
}
@@ -33,8 +33,20 @@ cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
std::string property, const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* parent, cmLocalGenerator const* contextLG,
std::string const& contextConfig)
: cmGeneratorExpressionDAGChecker(std::move(backtrace), target,
std::move(property), content, parent,
contextLG, contextConfig, INHERIT)
{
}
cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
cmListFileBacktrace backtrace, cmGeneratorTarget const* target,
std::string property, const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* parent, cmLocalGenerator const* contextLG,
std::string const& contextConfig, TransitiveClosure closure)
: Parent(parent)
, Top(parent ? parent->Top : this)
, Closure((closure == SUBGRAPH || !parent) ? this : parent->Closure)
, Target(target)
, Property(std::move(property))
, Content(content)
@@ -53,16 +65,16 @@ cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
this->CheckResult = this->CheckGraph();
if (this->CheckResult == DAG && this->EvaluatingTransitiveProperty()) {
const auto* top = this->Top;
auto it = top->Seen.find(this->Target);
if (it != top->Seen.end()) {
const auto* transitiveClosure = this->Closure;
auto it = transitiveClosure->Seen.find(this->Target);
if (it != transitiveClosure->Seen.end()) {
const std::set<std::string>& propSet = it->second;
if (propSet.find(this->Property) != propSet.end()) {
this->CheckResult = ALREADY_SEEN;
return;
}
}
top->Seen[this->Target].insert(this->Property);
transitiveClosure->Seen[this->Target].insert(this->Property);
}
}
+12
View File
@@ -17,6 +17,17 @@ class cmLocalGenerator;
struct cmGeneratorExpressionDAGChecker
{
enum TransitiveClosure
{
INHERIT,
SUBGRAPH,
};
cmGeneratorExpressionDAGChecker(
cmListFileBacktrace backtrace, cmGeneratorTarget const* target,
std::string property, const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* parent, cmLocalGenerator const* contextLG,
std::string const& contextConfig, TransitiveClosure closure);
cmGeneratorExpressionDAGChecker(cmListFileBacktrace backtrace,
cmGeneratorTarget const* target,
std::string property,
@@ -76,6 +87,7 @@ private:
const cmGeneratorExpressionDAGChecker* const Parent;
const cmGeneratorExpressionDAGChecker* const Top;
const cmGeneratorExpressionDAGChecker* const Closure;
cmGeneratorTarget const* Target;
const std::string Property;
mutable std::map<cmGeneratorTarget const*, std::set<std::string>> Seen;
+3 -2
View File
@@ -2983,8 +2983,9 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
if (isInterfaceProperty) {
return cmGeneratorExpression::StripEmptyListElements(
target->EvaluateInterfaceProperty(propertyName, context,
dagCheckerParent, usage));
target->EvaluateInterfaceProperty(
propertyName, context, dagCheckerParent, usage,
cmGeneratorTarget::TransitiveClosure::Subgraph));
}
cmGeneratorExpressionDAGChecker dagChecker(
+12
View File
@@ -918,11 +918,23 @@ public:
const std::string& report,
const std::string& compatibilityType) const;
/** Configures TransitiveClosureOptimization. Re-evaluation of a
transitive property will only be optimized within a subgraph. */
enum class TransitiveClosure
{
Inherit, // node is in the same subgraph as its' parent
Subgraph, // the current node spans a new subgraph
};
class TargetPropertyEntry;
std::string EvaluateInterfaceProperty(
std::string const& prop, cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagCheckerParent, UseTo usage) const;
std::string EvaluateInterfaceProperty(
std::string const& prop, cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagCheckerParent, UseTo usage,
TransitiveClosure closure) const;
struct TransitiveProperty
{
@@ -98,6 +98,15 @@ bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
std::string cmGeneratorTarget::EvaluateInterfaceProperty(
std::string const& prop, cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagCheckerParent, UseTo usage) const
{
return EvaluateInterfaceProperty(prop, context, dagCheckerParent, usage,
TransitiveClosure::Inherit);
}
std::string cmGeneratorTarget::EvaluateInterfaceProperty(
std::string const& prop, cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagCheckerParent, UseTo usage,
TransitiveClosure closure) const
{
std::string result;
@@ -106,12 +115,15 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty(
return result;
}
auto const dagClosure = closure == TransitiveClosure::Inherit
? cmGeneratorExpressionDAGChecker::INHERIT
: cmGeneratorExpressionDAGChecker::SUBGRAPH;
// Evaluate $<TARGET_PROPERTY:this,prop> as if it were compiled. This is
// a subset of TargetPropertyNode::Evaluate without stringify/parse steps
// but sufficient for transitive interface properties.
cmGeneratorExpressionDAGChecker dagChecker(
context->Backtrace, this, prop, nullptr, dagCheckerParent,
this->LocalGenerator, context->Config);
this->LocalGenerator, context->Config, dagClosure);
switch (dagChecker.Check()) {
case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
dagChecker.ReportError(