From 89e6f845739a9a764189c0e9acc443ba142de4f3 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Wed, 10 Jul 2024 15:58:25 +0200 Subject: DAG: remove IsValid since it is used in tests only. --- src/buildtool/execution_engine/dag/dag.hpp | 67 ++---------------------------- 1 file changed, 3 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/buildtool/execution_engine/dag/dag.hpp b/src/buildtool/execution_engine/dag/dag.hpp index d5c96b2e..e5f81308 100644 --- a/src/buildtool/execution_engine/dag/dag.hpp +++ b/src/buildtool/execution_engine/dag/dag.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -49,13 +48,11 @@ class DirectedAcyclicGraph { /// \brief Abstract class for DAG nodes. /// \tparam T_Content Type of content. /// \tparam T_Other Type of neighboring nodes. - /// Sub classes need to implement \ref IsValid method. /// TODO: once we have hashes, require sub classes to implement generating /// IDs depending on its unique content. template class Node { public: - using Id = std::uintptr_t; using OtherNode = T_Other; using OtherNodePtr = gsl::not_null; @@ -76,11 +73,7 @@ class DirectedAcyclicGraph { Node(Node&&) = delete; auto operator=(Node const&) -> Node& = delete; auto operator=(Node&&) -> Node& = delete; - - [[nodiscard]] auto NodeId() const noexcept -> Id { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - return reinterpret_cast(this); - } + ~Node() = default; [[nodiscard]] auto Content() const& noexcept -> T_Content const& { return content_; @@ -120,9 +113,6 @@ class DirectedAcyclicGraph { return true; } - [[nodiscard]] virtual auto IsValid() const noexcept -> bool = 0; - virtual ~Node() noexcept = default; - private: T_Content content_{}; std::vector parents_{}; @@ -179,37 +169,6 @@ class DirectedAcyclicGraph { std::atomic is_queued_to_be_processed_{false}; std::atomic is_required_{false}; }; - - protected: - template - // NOLINTNEXTLINE(misc-no-recursion) - [[nodiscard]] static auto check_validity( - gsl::not_null node) noexcept -> bool { - // Check node-specified validity (e.g. bipartiteness requirements) - if (!node->IsValid()) { - return false; - } - - // Search for cycles - thread_local std::vector stack{}; - for (auto const& child : node->Children()) { - auto node_id = child->NodeId(); - - if (std::find(stack.begin(), stack.end(), node_id) != stack.end()) { - return false; - } - - stack.push_back(node_id); - bool valid = check_validity(child); - stack.pop_back(); - - if (!valid) { - return false; - } - } - - return true; - } }; class DependencyGraph : DirectedAcyclicGraph { @@ -292,7 +251,7 @@ class DependencyGraph : DirectedAcyclicGraph { }; /// \brief Action node (bipartite) - /// Cannot be entry (see \ref IsValid). + /// Cannot be entry. class ActionNode final : public Node { using base = Node; @@ -313,11 +272,6 @@ class DependencyGraph : DirectedAcyclicGraph { return std::make_unique(std::move(content)); } - // only valid if it has parents - [[nodiscard]] auto IsValid() const noexcept -> bool final { - return (!base::Parents().empty()); - } - [[nodiscard]] auto AddOutputFile( NamedOtherNodePtr const& output) noexcept -> bool { base::AddParent(output.node); @@ -474,8 +428,7 @@ class DependencyGraph : DirectedAcyclicGraph { }; /// \brief Artifact node (bipartite) - /// Can be entry or leaf (see \ref IsValid) and can only have single child - /// (see \ref AddChild) + /// Can be entry or leaf and can only have single child (see \ref AddChild) class ArtifactNode final : public Node { using base = Node; @@ -510,10 +463,6 @@ class DependencyGraph : DirectedAcyclicGraph { return base::AddParent(action); } - [[nodiscard]] auto IsValid() const noexcept -> bool final { - return base::Children().size() <= 1; - } - [[nodiscard]] auto HasBuilderAction() const noexcept -> bool { return !base::Children().empty(); } @@ -572,16 +521,6 @@ class DependencyGraph : DirectedAcyclicGraph { [[nodiscard]] auto ArtifactWithId( ArtifactIdentifier const& id) const noexcept -> std::optional; - [[nodiscard]] auto IsValid() const noexcept -> bool { - return std::all_of( - artifact_nodes_.begin(), - artifact_nodes_.end(), - [](auto const& node) { - return DirectedAcyclicGraph::check_validity< - std::remove_reference_t>(&(*node)); - }); - } - private: // List of action nodes we already created std::vector action_nodes_{}; -- cgit v1.2.3