From: Maxwell Pirtle Date: Fri, 24 Feb 2023 13:15:12 +0000 (+0100) Subject: Fix most cosmetics and code warnings X-Git-Tag: v3.34~422^2~14 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f456852dd160e1f60f58e2a3ef37a0e688993fe0 Fix most cosmetics and code warnings --- diff --git a/src/mc/explo/UdporChecker.cpp b/src/mc/explo/UdporChecker.cpp index c15c280553..3d97acdf6e 100644 --- a/src/mc/explo/UdporChecker.cpp +++ b/src/mc/explo/UdporChecker.cpp @@ -33,12 +33,13 @@ void UdporChecker::run() unfolding.insert(std::move(root_event)); C_root.add_event(root_event_handle); - explore(std::move(C_root), EventSet(), EventSet(), std::move(initial_state), EventSet()); + explore(C_root, EventSet(), EventSet(), std::move(initial_state), EventSet()); XBT_INFO("UDPOR exploration terminated -- model checking completed"); } -void UdporChecker::explore(Configuration C, EventSet D, EventSet A, std::unique_ptr stateC, EventSet prev_exC) +void UdporChecker::explore(const Configuration& C, EventSet D, EventSet A, std::unique_ptr stateC, + EventSet prev_exC) { // Perform the incremental computation of exC // @@ -55,14 +56,9 @@ void UdporChecker::explore(Configuration C, EventSet D, EventSet A, std::unique_ // "sleep-set blocked" trace. if (enC.is_subset_of(D)) { - if (C.get_events().size() > 0) { + if (not C.get_events().empty()) { // g_var::nb_traces++; - - // TODO: Log here correctly - // XBT_DEBUG("\n Exploring executions: %d : \n", g_var::nb_traces); - // ... - // ... } // When `en(C)` is empty, intuitively this means that there @@ -104,8 +100,7 @@ void UdporChecker::explore(Configuration C, EventSet D, EventSet A, std::unique_ // TODO: Determine a value of K to use or don't use it at all constexpr unsigned K = 10; - auto J = compute_partial_alternative(D, C, K); - if (!J.empty()) { + if (auto J = compute_partial_alternative(D, C, K); !J.empty()) { J.subtract(C.get_events()); // Before searching the "right half", we need to make diff --git a/src/mc/explo/UdporChecker.hpp b/src/mc/explo/UdporChecker.hpp index 471d8a255c..f19c8c61de 100644 --- a/src/mc/explo/UdporChecker.hpp +++ b/src/mc/explo/UdporChecker.hpp @@ -110,7 +110,7 @@ private: * TODO: Add the optimization where we can check if e == e_prior * to prevent repeated work when computing ex(C) */ - void explore(Configuration C, EventSet D, EventSet A, std::unique_ptr stateC, EventSet prev_exC); + void explore(const Configuration& C, EventSet D, EventSet A, std::unique_ptr stateC, EventSet prev_exC); /** * @brief Identifies the next event from the unfolding of the concurrent system diff --git a/src/mc/explo/udpor/Configuration.cpp b/src/mc/explo/udpor/Configuration.cpp index 447b5f0823..8cc96f2581 100644 --- a/src/mc/explo/udpor/Configuration.cpp +++ b/src/mc/explo/udpor/Configuration.cpp @@ -18,7 +18,7 @@ Configuration::Configuration(std::initializer_list events) : Co { } -Configuration::Configuration(EventSet events) : events_(events) +Configuration::Configuration(const EventSet& events) : events_(events) { if (!events_.is_valid_configuration()) { throw std::invalid_argument("The events do not form a valid configuration"); diff --git a/src/mc/explo/udpor/Configuration.hpp b/src/mc/explo/udpor/Configuration.hpp index 8449c76bde..ead739e407 100644 --- a/src/mc/explo/udpor/Configuration.hpp +++ b/src/mc/explo/udpor/Configuration.hpp @@ -23,8 +23,8 @@ public: Configuration& operator=(Configuration const&) = default; Configuration(Configuration&&) = default; - Configuration(EventSet events); - Configuration(std::initializer_list events); + explicit Configuration(const EventSet& events); + explicit Configuration(std::initializer_list events); auto begin() const { return this->events_.begin(); } auto end() const { return this->events_.end(); } diff --git a/src/mc/explo/udpor/EventSet.cpp b/src/mc/explo/udpor/EventSet.cpp index 6f486b7732..b03bef5933 100644 --- a/src/mc/explo/udpor/EventSet.cpp +++ b/src/mc/explo/udpor/EventSet.cpp @@ -11,7 +11,7 @@ namespace simgrid::mc::udpor { -EventSet::EventSet(Configuration&& config) : EventSet(std::move(config.get_events())) {} +EventSet::EventSet(Configuration&& config) : EventSet(config.get_events()) {} void EventSet::remove(UnfoldingEvent* e) { diff --git a/src/mc/explo/udpor/EventSet.hpp b/src/mc/explo/udpor/EventSet.hpp index e640f0c9de..db42ff2198 100644 --- a/src/mc/explo/udpor/EventSet.hpp +++ b/src/mc/explo/udpor/EventSet.hpp @@ -25,7 +25,7 @@ public: EventSet& operator=(EventSet&&) = default; EventSet(EventSet&&) = default; explicit EventSet(Configuration&& config); - explicit EventSet(std::unordered_set&& raw_events) : events_(raw_events) {} + explicit EventSet(std::unordered_set&& raw_events) : events_(std::move(raw_events)) {} explicit EventSet(std::initializer_list event_list) : events_(std::move(event_list)) {} auto begin() const { return this->events_.begin(); } diff --git a/src/mc/explo/udpor/EventSet_test.cpp b/src/mc/explo/udpor/EventSet_test.cpp index 77a555d2f4..14fb1627fb 100644 --- a/src/mc/explo/udpor/EventSet_test.cpp +++ b/src/mc/explo/udpor/EventSet_test.cpp @@ -51,7 +51,6 @@ TEST_CASE("simgrid::mc::udpor::EventSet: Initial conditions when creating sets") SECTION("List initialization") { - UnfoldingEvent e1, e2, e3; EventSet event_set{&e1, &e2, &e3}; REQUIRE(event_set.size() == 3); REQUIRE(event_set.contains(&e1)); @@ -117,7 +116,7 @@ TEST_CASE("simgrid::mc::udpor::EventSet: Deletions") { REQUIRE(event_set.contains(&e1)); - // event_set = {e2, e3} + // Recall that event_set = {e2, e3} event_set.remove(&e1); // Check that @@ -132,7 +131,7 @@ TEST_CASE("simgrid::mc::udpor::EventSet: Deletions") SECTION("Remove a single element more than once") { - // event_set = {e2, e3} + // Recall that event_set = {e2, e3} event_set.remove(&e1); REQUIRE(event_set.size() == 2); REQUIRE_FALSE(event_set.contains(&e1)); @@ -143,7 +142,7 @@ TEST_CASE("simgrid::mc::udpor::EventSet: Deletions") SECTION("Remove more than one element") { - // event_set = {e3} + // Recall that event_set = {e3} event_set.remove(&e2); REQUIRE(event_set.size() == 1); @@ -152,7 +151,7 @@ TEST_CASE("simgrid::mc::udpor::EventSet: Deletions") REQUIRE(event_set.contains(&e3)); REQUIRE_FALSE(event_set.empty()); - // event_set = {} + // Recall that event_set = {} event_set.remove(&e3); REQUIRE(event_set.size() == 0); @@ -167,7 +166,7 @@ TEST_CASE("simgrid::mc::udpor::EventSet: Deletions") { REQUIRE_FALSE(event_set.contains(&e4)); - // event_set = {e1, e2, e3} + // Recall that event_set = {e1, e2, e3} event_set.remove(&e4); REQUIRE(event_set.size() == 3); REQUIRE(event_set.contains(&e1)); diff --git a/src/mc/explo/udpor/History.cpp b/src/mc/explo/udpor/History.cpp index 544980a8cf..bb24494273 100644 --- a/src/mc/explo/udpor/History.cpp +++ b/src/mc/explo/udpor/History.cpp @@ -45,7 +45,7 @@ History::Iterator& History::Iterator::operator++() maximal_events.subtract(candidates); candidates.subtract(current_history); - frontier.form_union(std::move(candidates)); + frontier.form_union(candidates); } return *this; } @@ -72,9 +72,9 @@ EventSet History::get_all_maximal_events() const return first.maximal_events; } -bool History::contains(UnfoldingEvent* e) const +bool History::contains(const UnfoldingEvent* e) const { - return std::any_of(this->begin(), this->end(), [=](UnfoldingEvent* e_hist) { return e == e_hist; }); + return std::any_of(this->begin(), this->end(), [=](const UnfoldingEvent* e_hist) { return e == e_hist; }); } EventSet History::get_event_diff_with(const Configuration& config) const diff --git a/src/mc/explo/udpor/History.hpp b/src/mc/explo/udpor/History.hpp index e667424175..7087927801 100644 --- a/src/mc/explo/udpor/History.hpp +++ b/src/mc/explo/udpor/History.hpp @@ -71,7 +71,7 @@ public: * @param e the event to check * @returns whether or not `e` is contained in the collection */ - bool contains(UnfoldingEvent* e) const; + bool contains(const UnfoldingEvent* e) const; /** * @brief Computes all events in the history described by this instance @@ -102,14 +102,14 @@ private: struct Iterator { public: Iterator& operator++(); - auto operator->() { return frontier.begin().operator->(); } + auto operator->() const { return frontier.begin().operator->(); } auto operator*() const { return *frontier.begin(); } // If what the iterator sees next is the same, we consider them // to be the same iterator. This way, once the iterator has completed // its search, it will be "equal" to an iterator searching nothing - bool operator==(const Iterator& other) { return this->frontier == other.frontier; } - bool operator!=(const Iterator& other) { return not(this->operator==(other)); } + bool operator==(const Iterator& other) const { return this->frontier == other.frontier; } + bool operator!=(const Iterator& other) const { return not(this->operator==(other)); } using iterator_category = std::forward_iterator_tag; using difference_type = int; // # of steps between diff --git a/src/mc/explo/udpor/UnfoldingEvent.hpp b/src/mc/explo/udpor/UnfoldingEvent.hpp index 2bd29e991b..4468b210c5 100644 --- a/src/mc/explo/udpor/UnfoldingEvent.hpp +++ b/src/mc/explo/udpor/UnfoldingEvent.hpp @@ -18,7 +18,7 @@ namespace simgrid::mc::udpor { class UnfoldingEvent { public: - UnfoldingEvent(std::initializer_list init_list); + explicit UnfoldingEvent(std::initializer_list init_list); UnfoldingEvent(EventSet immediate_causes = EventSet(), std::shared_ptr transition = std::make_unique()); @@ -38,7 +38,6 @@ public: bool operator==(const UnfoldingEvent&) const; -private: /** * @brief The transition that UDPOR "attaches" to this * specific event for later use while computing e.g. extension