From 8c6feb89480910ca928323dcb602a5892f15d3e3 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Tue, 29 Jul 2025 05:13:21 +1000 Subject: [PATCH 01/16] Not working. Committed before I stuff shit up further. --- lib/CMakeLists.txt | 1 + lib/include/pl/helpers/sort_checks.hpp | 122 +++++++++++++++++++++ lib/include/pl/patterns/pattern_struct.hpp | 3 +- lib/source/pl/helpers/sort_checks.cpp | 7 ++ 4 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 lib/include/pl/helpers/sort_checks.hpp create mode 100644 lib/source/pl/helpers/sort_checks.cpp diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 29cbf1e6..869d269d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -13,6 +13,7 @@ endif () add_library(libpl ${LIBRARY_TYPE} source/pl/helpers/utils.cpp + source/pl/helpers/sort_checks.cpp source/pl/pattern_language.cpp diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp new file mode 100644 index 00000000..286a3799 --- /dev/null +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -0,0 +1,122 @@ +#pragma once + +#include + +void sortPredicateError(size_t l_idx, size_t r_idx, const char *pMsg); + +template +void genSortPredicateError(RandomIt collBegin, RandomIt l, RandomIt r, const char *pMsg) +{ + sortPredicateError(l-collBegin, r-collBegin, pMsg); +} + +// Logical implication +inline bool imp(bool l, bool r) { + return !(l && !r); +} + +template +auto checked_pedicate(RandomIt b, Predicate pred) { + return [=](const auto &l, const auto &r) { + // Irreflexivity: !(x +void transitivity(const Iter b, const Iter e, const Predicate pred) +{ + for (Iter l=b; l +void transitivity_of_incomparability(const Iter b, const Iter e, const Predicate pred) +{ + for (Iter l=b; l +void post_sort_check(const Iter b, const Iter e, const Predicate pred) { + if (b==e) + return; + + for (Iter l=b; l=r && l>r + genSortPredicateError(b, l, l+1, "Not sorted"); // NOT sorted! + ++l; + } + } +} + +template +void checked_sort(RandomIt b, RandomIt e, Compare comp) { + std::sort(b, e, checked_pedicate(b, comp)); + post_sort_check(b, e, comp); +} + +template +void checked_stable_sort(RandomIt b, RandomIt e, Compare comp) { + std::stable_sort(b, e, checked_pedicate(b, comp)); + post_sort_check(b, e, comp); +} diff --git a/lib/include/pl/patterns/pattern_struct.hpp b/lib/include/pl/patterns/pattern_struct.hpp index 900d517c..00d52c41 100644 --- a/lib/include/pl/patterns/pattern_struct.hpp +++ b/lib/include/pl/patterns/pattern_struct.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace pl::ptrn { @@ -160,7 +161,7 @@ namespace pl::ptrn { for (auto &member : this->m_members) this->m_sortedMembers.push_back(member.get()); - std::sort(this->m_sortedMembers.begin(), this->m_sortedMembers.end(), comparator); + checked_sort(this->m_sortedMembers.begin(), this->m_sortedMembers.end(), comparator); for (auto &member : this->m_sortedMembers) member->sort(comparator); diff --git a/lib/source/pl/helpers/sort_checks.cpp b/lib/source/pl/helpers/sort_checks.cpp new file mode 100644 index 00000000..6073fa1d --- /dev/null +++ b/lib/source/pl/helpers/sort_checks.cpp @@ -0,0 +1,7 @@ +#include +#include + +void sortPredicateError(size_t l_idx, size_t r_idx, const char *pMsg) { + (void)l_idx; (void)r_idx; + std::cout << pMsg << std::endl; +} From caeb6ea5bd860f235177afdf3d52a4c94b55a88b Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Tue, 29 Jul 2025 05:41:22 +1000 Subject: [PATCH 02/16] Undo lunacy --- lib/include/pl/helpers/sort_checks.hpp | 38 +++++++++++--------------- lib/source/pl/helpers/sort_checks.cpp | 3 +- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp index 286a3799..ed15a340 100644 --- a/lib/include/pl/helpers/sort_checks.hpp +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -2,33 +2,27 @@ #include -void sortPredicateError(size_t l_idx, size_t r_idx, const char *pMsg); - -template -void genSortPredicateError(RandomIt collBegin, RandomIt l, RandomIt r, const char *pMsg) -{ - sortPredicateError(l-collBegin, r-collBegin, pMsg); -} +void sortPredicateError(const char *pMsg); // Logical implication inline bool imp(bool l, bool r) { return !(l && !r); } -template -auto checked_pedicate(RandomIt b, Predicate pred) { +template +auto checked_pedicate(const Predicate pred) { return [=](const auto &l, const auto &r) { // Irreflexivity: !(x=r && l>r - genSortPredicateError(b, l, l+1, "Not sorted"); // NOT sorted! + sortPredicateError("Not sorted"); // NOT sorted! ++l; } } } template -void checked_sort(RandomIt b, RandomIt e, Compare comp) { - std::sort(b, e, checked_pedicate(b, comp)); - post_sort_check(b, e, comp); +void checked_sort(RandomIt first, RandomIt last, Compare comp) { + std::sort(first, last, checked_pedicate(comp)); + post_sort_check(first, last, comp); } template -void checked_stable_sort(RandomIt b, RandomIt e, Compare comp) { - std::stable_sort(b, e, checked_pedicate(b, comp)); - post_sort_check(b, e, comp); +void checked_stable_sort(RandomIt first, RandomIt last, Compare comp) { + std::stable_sort(first, last, checked_pedicate(comp)); + post_sort_check(first, last, comp); } diff --git a/lib/source/pl/helpers/sort_checks.cpp b/lib/source/pl/helpers/sort_checks.cpp index 6073fa1d..16a9be96 100644 --- a/lib/source/pl/helpers/sort_checks.cpp +++ b/lib/source/pl/helpers/sort_checks.cpp @@ -1,7 +1,6 @@ #include #include -void sortPredicateError(size_t l_idx, size_t r_idx, const char *pMsg) { - (void)l_idx; (void)r_idx; +void sortPredicateError(const char *pMsg) { std::cout << pMsg << std::endl; } From 05b9c8af159fb358302d67ee96be0d3871ea0e6d Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Tue, 29 Jul 2025 05:50:03 +1000 Subject: [PATCH 03/16] Note to self --- lib/include/pl/helpers/sort_checks.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp index ed15a340..9e13224e 100644 --- a/lib/include/pl/helpers/sort_checks.hpp +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -11,6 +11,7 @@ inline bool imp(bool l, bool r) { template auto checked_pedicate(const Predicate pred) { + // IDIOT: The lambda below can't know the location in the collection! return [=](const auto &l, const auto &r) { // Irreflexivity: !(x Date: Wed, 30 Jul 2025 05:24:55 +1000 Subject: [PATCH 04/16] This is actually starting to find issues --- lib/include/pl/helpers/sort_checks.hpp | 13 +++++++------ lib/include/pl/patterns/pattern_struct.hpp | 15 +++++++++++++++ lib/source/pl/helpers/sort_checks.cpp | 11 ++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp index 9e13224e..80b0a3a6 100644 --- a/lib/include/pl/helpers/sort_checks.hpp +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -3,6 +3,7 @@ #include void sortPredicateError(const char *pMsg); +void transitivityError(const char *pMsg, size_t b_idx, size_t e_idx, size_t x_idx, size_t y_idx); // Logical implication inline bool imp(bool l, bool r) { @@ -39,12 +40,12 @@ namespace impl { // b[n] -void transitivity(const Iter b, const Iter e, const Predicate pred) +void transitivity(const Iter cb, const Iter b, const Iter e, const Predicate pred) { for (Iter l=b; l -void transitivity_of_incomparability(const Iter b, const Iter e, const Predicate pred) +void transitivity_of_incomparability(const Iter cb, const Iter b, const Iter e, const Predicate pred) { for (Iter l=b; lm_members) this->m_sortedMembers.push_back(member.get()); + // DEBUGGING + auto smb = &m_sortedMembers[0]; (void)smb; + for (auto p : m_sortedMembers) { + auto vn = p->getVariableName(); + int a=1;(void)a; + } + // + checked_sort(this->m_sortedMembers.begin(), this->m_sortedMembers.end(), comparator); + // DEBUGGING + std::vector postSorted; + for (auto p : m_sortedMembers) { + postSorted.push_back(p); + } + // + for (auto &member : this->m_sortedMembers) member->sort(comparator); } diff --git a/lib/source/pl/helpers/sort_checks.cpp b/lib/source/pl/helpers/sort_checks.cpp index 16a9be96..780f2d93 100644 --- a/lib/source/pl/helpers/sort_checks.cpp +++ b/lib/source/pl/helpers/sort_checks.cpp @@ -1,6 +1,15 @@ #include #include +using std::cout; +using std::endl; + void sortPredicateError(const char *pMsg) { - std::cout << pMsg << std::endl; + cout << pMsg << endl; +} + +void transitivityError(const char *pMsg, size_t b_idx, size_t e_idx, size_t x_idx, size_t y_idx) { + cout << pMsg << endl + << " Run: " << "b_idx=" << b_idx << ", e_idx=" << e_idx << endl + << " Error: " << "x_idx=" << x_idx << ", y_idx=" << y_idx << endl; } From b70eac71422a4d84e2a07699234badeb6a7996db Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 00:47:36 +1000 Subject: [PATCH 05/16] Fix sort bug (ImHex, not checker) --- lib/source/pl/core/token.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/source/pl/core/token.cpp b/lib/source/pl/core/token.cpp index 3bbddfe6..fda0e4c7 100644 --- a/lib/source/pl/core/token.cpp +++ b/lib/source/pl/core/token.cpp @@ -110,6 +110,29 @@ namespace pl::core { return std::holds_alternative>(*this); } +/// +template +struct variant_index; + +template +struct variant_index> { + static constexpr std::size_t value = []{ + constexpr bool matches[] = { std::is_same_v, Ts>... }; + + std::size_t idx = 0; + for (std::size_t i = 0; i < sizeof...(Ts); ++i) { + if (matches[i]) { idx = i; } + } + + return idx; + }(); +}; + +template +inline constexpr std::size_t variant_index_v = variant_index::value; +/// + + std::strong_ordering Token::Literal::operator<=>(const Literal &other) const { return std::visit(wolv::util::overloaded { [](std::shared_ptr lhs, std::shared_ptr rhs) { @@ -160,8 +183,10 @@ namespace pl::core { return std::strong_ordering::greater; } }, - [](auto, auto) -> std::strong_ordering { - return std::strong_ordering::equal; + [](TL, TR) -> std::strong_ordering { + using V = std::variant>; + return variant_index_v <=> variant_index_v; + //return std::strong_ordering::equal; } }, *this, other); } From ef3fbc9a6beb3f7109cefb9021f7d8764467f9c3 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 01:13:02 +1000 Subject: [PATCH 06/16] Move variant type index code into header --- lib/include/pl/helpers/variant_type_index.hpp | 29 +++++++++++++++++++ lib/source/pl/core/token.cpp | 26 ++--------------- 2 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 lib/include/pl/helpers/variant_type_index.hpp diff --git a/lib/include/pl/helpers/variant_type_index.hpp b/lib/include/pl/helpers/variant_type_index.hpp new file mode 100644 index 00000000..f263553c --- /dev/null +++ b/lib/include/pl/helpers/variant_type_index.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include + +namespace pl::hlp { + +template +struct variant_type_index; + +template +struct variant_type_index> { + static constexpr std::size_t value = []{ + constexpr bool matches[] = { std::is_same_v, Ts>... }; + + std::size_t idx = 0; + for (std::size_t i = 0; i < sizeof...(Ts); ++i) { + if (matches[i]) { idx = i; } + } + + return idx; + }(); +}; + +template +inline constexpr std::size_t variant_type_index_v = variant_type_index::value; + +} // namespace pl::hlp \ No newline at end of file diff --git a/lib/source/pl/core/token.cpp b/lib/source/pl/core/token.cpp index fda0e4c7..b95bfa87 100644 --- a/lib/source/pl/core/token.cpp +++ b/lib/source/pl/core/token.cpp @@ -5,6 +5,7 @@ #include #include +#include #include namespace pl::core { @@ -110,29 +111,6 @@ namespace pl::core { return std::holds_alternative>(*this); } -/// -template -struct variant_index; - -template -struct variant_index> { - static constexpr std::size_t value = []{ - constexpr bool matches[] = { std::is_same_v, Ts>... }; - - std::size_t idx = 0; - for (std::size_t i = 0; i < sizeof...(Ts); ++i) { - if (matches[i]) { idx = i; } - } - - return idx; - }(); -}; - -template -inline constexpr std::size_t variant_index_v = variant_index::value; -/// - - std::strong_ordering Token::Literal::operator<=>(const Literal &other) const { return std::visit(wolv::util::overloaded { [](std::shared_ptr lhs, std::shared_ptr rhs) { @@ -185,7 +163,7 @@ inline constexpr std::size_t variant_index_v = variant_index::value; }, [](TL, TR) -> std::strong_ordering { using V = std::variant>; - return variant_index_v <=> variant_index_v; + return pl::hlp::variant_type_index_v <=> pl::hlp::variant_type_index_v; //return std::strong_ordering::equal; } }, *this, other); From 8deca652a983867a43aa7adabee55bc6db32be51 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 02:03:29 +1000 Subject: [PATCH 07/16] DRY --- lib/include/pl/core/token.hpp | 4 +++- lib/source/pl/core/token.cpp | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/include/pl/core/token.hpp b/lib/include/pl/core/token.hpp index 5c9198e4..e274d914 100644 --- a/lib/include/pl/core/token.hpp +++ b/lib/include/pl/core/token.hpp @@ -220,8 +220,10 @@ namespace pl::core { constexpr bool operator==(const Comment &) const = default; }; + using LiteralVariantType = std::variant>; - struct Literal : std::variant> { + + struct Literal : LiteralVariantType { using variant::variant; [[nodiscard]] std::shared_ptr toPattern() const; diff --git a/lib/source/pl/core/token.cpp b/lib/source/pl/core/token.cpp index b95bfa87..50799254 100644 --- a/lib/source/pl/core/token.cpp +++ b/lib/source/pl/core/token.cpp @@ -162,9 +162,7 @@ namespace pl::core { } }, [](TL, TR) -> std::strong_ordering { - using V = std::variant>; - return pl::hlp::variant_type_index_v <=> pl::hlp::variant_type_index_v; - //return std::strong_ordering::equal; + return pl::hlp::variant_type_index_v <=> pl::hlp::variant_type_index_v; } }, *this, other); } From 856af8d84019155c3920f43f314bc85efcae553a Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 03:57:06 +1000 Subject: [PATCH 08/16] Tidy up --- lib/include/pl/helpers/sort_checks.hpp | 7 ++++++- lib/include/pl/patterns/pattern_struct.hpp | 2 +- lib/source/pl/helpers/sort_checks.cpp | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp index 80b0a3a6..846c8c94 100644 --- a/lib/include/pl/helpers/sort_checks.hpp +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -1,9 +1,12 @@ #pragma once +#include #include +namespace pl::hlp { + void sortPredicateError(const char *pMsg); -void transitivityError(const char *pMsg, size_t b_idx, size_t e_idx, size_t x_idx, size_t y_idx); +void transitivityError(const char *pMsg, std::size_t b_idx, std::size_t e_idx, std::size_t x_idx, std::size_t y_idx); // Logical implication inline bool imp(bool l, bool r) { @@ -116,3 +119,5 @@ void checked_stable_sort(RandomIt first, RandomIt last, Compare comp) { std::stable_sort(first, last, checked_pedicate(comp)); post_sort_check(first, last, comp); } + +} // namespace pl::hlp diff --git a/lib/include/pl/patterns/pattern_struct.hpp b/lib/include/pl/patterns/pattern_struct.hpp index e61f3915..916d76c7 100644 --- a/lib/include/pl/patterns/pattern_struct.hpp +++ b/lib/include/pl/patterns/pattern_struct.hpp @@ -169,7 +169,7 @@ namespace pl::ptrn { } // - checked_sort(this->m_sortedMembers.begin(), this->m_sortedMembers.end(), comparator); + pl::hlp::checked_sort(this->m_sortedMembers.begin(), this->m_sortedMembers.end(), comparator); // DEBUGGING std::vector postSorted; diff --git a/lib/source/pl/helpers/sort_checks.cpp b/lib/source/pl/helpers/sort_checks.cpp index 780f2d93..f40a5be0 100644 --- a/lib/source/pl/helpers/sort_checks.cpp +++ b/lib/source/pl/helpers/sort_checks.cpp @@ -1,9 +1,13 @@ #include +#include #include +using std::size_t; using std::cout; using std::endl; +namespace pl::hlp { + void sortPredicateError(const char *pMsg) { cout << pMsg << endl; } @@ -13,3 +17,5 @@ void transitivityError(const char *pMsg, size_t b_idx, size_t e_idx, size_t x_id << " Run: " << "b_idx=" << b_idx << ", e_idx=" << e_idx << endl << " Error: " << "x_idx=" << x_idx << ", y_idx=" << y_idx << endl; } + +} // namespace pl::hlp From 8d7281ba61b013387437559251cd349f14216e75 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 04:16:38 +1000 Subject: [PATCH 09/16] Make sort checks optional --- lib/include/pl/helpers/sort_checks.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp index 846c8c94..6b256708 100644 --- a/lib/include/pl/helpers/sort_checks.hpp +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -1,10 +1,17 @@ #pragma once +#define ENABLE_STD_SORT_CHECKS + +#ifdef ENABLE_STD_SORT_CHECKS #include +#endif + #include namespace pl::hlp { +#ifdef ENABLE_STD_SORT_CHECKS + void sortPredicateError(const char *pMsg); void transitivityError(const char *pMsg, std::size_t b_idx, std::size_t e_idx, std::size_t x_idx, std::size_t y_idx); @@ -108,16 +115,26 @@ void post_sort_check(const Iter b, const Iter e, const Predicate pred) { } } +#endif // ENABLE_STD_SORT_CHECKS + template void checked_sort(RandomIt first, RandomIt last, Compare comp) { +#ifdef ENABLE_STD_SORT_CHECKS std::sort(first, last, checked_pedicate(comp)); post_sort_check(first, last, comp); +#else + std::sort(first, last, comp); +#endif } template void checked_stable_sort(RandomIt first, RandomIt last, Compare comp) { +#ifdef ENABLE_STD_SORT_CHECKS std::stable_sort(first, last, checked_pedicate(comp)); post_sort_check(first, last, comp); +#else + std::stable_sort(first, last, comp); +#endif } } // namespace pl::hlp From b1935367923cdf3edba58c29a65312d4305ee35d Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 04:25:29 +1000 Subject: [PATCH 10/16] tidy up --- lib/include/pl/helpers/sort_checks.hpp | 1 - lib/include/pl/patterns/pattern_struct.hpp | 16 ---------------- 2 files changed, 17 deletions(-) diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp index 6b256708..d42cb56a 100644 --- a/lib/include/pl/helpers/sort_checks.hpp +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -22,7 +22,6 @@ inline bool imp(bool l, bool r) { template auto checked_pedicate(const Predicate pred) { - // IDIOT: The lambda below can't know the location in the collection! return [=](const auto &l, const auto &r) { // Irreflexivity: !(xm_members) this->m_sortedMembers.push_back(member.get()); - // DEBUGGING - auto smb = &m_sortedMembers[0]; (void)smb; - for (auto p : m_sortedMembers) { - auto vn = p->getVariableName(); - int a=1;(void)a; - } - // - pl::hlp::checked_sort(this->m_sortedMembers.begin(), this->m_sortedMembers.end(), comparator); - - // DEBUGGING - std::vector postSorted; - for (auto p : m_sortedMembers) { - postSorted.push_back(p); - } - // - for (auto &member : this->m_sortedMembers) member->sort(comparator); } From f8d6a71e2d9294b5c0ecaf1869d6f53b645ab581 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 04:41:59 +1000 Subject: [PATCH 11/16] Put checks in other container types --- lib/include/pl/patterns/pattern_bitfield.hpp | 5 +++-- lib/include/pl/patterns/pattern_union.hpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/include/pl/patterns/pattern_bitfield.hpp b/lib/include/pl/patterns/pattern_bitfield.hpp index 8cedee67..cc6d113f 100644 --- a/lib/include/pl/patterns/pattern_bitfield.hpp +++ b/lib/include/pl/patterns/pattern_bitfield.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace pl::ptrn { @@ -497,7 +498,7 @@ namespace pl::ptrn { for (auto &member : this->m_entries) this->m_sortedEntries.push_back(member.get()); - std::sort(this->m_sortedEntries.begin(), this->m_sortedEntries.end(), comparator); + pl::hlp::checked_sort(this->m_sortedEntries.begin(), this->m_sortedEntries.end(), comparator); if (this->isReversed()) std::reverse(this->m_sortedEntries.begin(), this->m_sortedEntries.end()); @@ -774,7 +775,7 @@ namespace pl::ptrn { for (auto &member : this->m_fields) this->m_sortedFields.push_back(member.get()); - std::sort(this->m_sortedFields.begin(), this->m_sortedFields.end(), comparator); + pl::hlp::checked_sort(this->m_sortedFields.begin(), this->m_sortedFields.end(), comparator); if (this->isReversed()) std::reverse(this->m_sortedFields.begin(), this->m_sortedFields.end()); diff --git a/lib/include/pl/patterns/pattern_union.hpp b/lib/include/pl/patterns/pattern_union.hpp index a38be0f7..a911a5ba 100644 --- a/lib/include/pl/patterns/pattern_union.hpp +++ b/lib/include/pl/patterns/pattern_union.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace pl::ptrn { @@ -159,7 +160,7 @@ namespace pl::ptrn { for (auto &member : this->m_members) this->m_sortedMembers.push_back(member.get()); - std::sort(this->m_sortedMembers.begin(), this->m_sortedMembers.end(), comparator); + pl::hlp::checked_sort(this->m_sortedMembers.begin(), this->m_sortedMembers.end(), comparator); for (auto &member : this->m_members) member->sort(comparator); From 867a9a4609be46d2d510e7f8a8fdb1f372571dd0 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 05:35:55 +1000 Subject: [PATCH 12/16] Disable sort checks --- lib/include/pl/helpers/sort_checks.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp index d42cb56a..74a51466 100644 --- a/lib/include/pl/helpers/sort_checks.hpp +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -1,6 +1,6 @@ #pragma once -#define ENABLE_STD_SORT_CHECKS +//#define ENABLE_STD_SORT_CHECKS #ifdef ENABLE_STD_SORT_CHECKS #include From c0293ff8c96f07c1bb955ed46da1eba7217a8c0e Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 23:53:04 +1000 Subject: [PATCH 13/16] Make enable macro cover more code --- lib/include/pl/helpers/sort_checks.hpp | 2 +- lib/source/pl/helpers/sort_checks.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp index 74a51466..d42cb56a 100644 --- a/lib/include/pl/helpers/sort_checks.hpp +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -1,6 +1,6 @@ #pragma once -//#define ENABLE_STD_SORT_CHECKS +#define ENABLE_STD_SORT_CHECKS #ifdef ENABLE_STD_SORT_CHECKS #include diff --git a/lib/source/pl/helpers/sort_checks.cpp b/lib/source/pl/helpers/sort_checks.cpp index f40a5be0..e92c8f45 100644 --- a/lib/source/pl/helpers/sort_checks.cpp +++ b/lib/source/pl/helpers/sort_checks.cpp @@ -1,4 +1,6 @@ #include + +#ifdef ENABLE_STD_SORT_CHECKS #include #include @@ -19,3 +21,5 @@ void transitivityError(const char *pMsg, size_t b_idx, size_t e_idx, size_t x_id } } // namespace pl::hlp + +#endif // ENABLE_STD_SORT_CHECKS From 2f2ab7fcbf4959ce7e8c750db5fe60895e74bd29 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 31 Jul 2025 23:55:12 +1000 Subject: [PATCH 14/16] Remove namespace qual --- lib/source/pl/core/token.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/source/pl/core/token.cpp b/lib/source/pl/core/token.cpp index 50799254..b8078423 100644 --- a/lib/source/pl/core/token.cpp +++ b/lib/source/pl/core/token.cpp @@ -162,7 +162,7 @@ namespace pl::core { } }, [](TL, TR) -> std::strong_ordering { - return pl::hlp::variant_type_index_v <=> pl::hlp::variant_type_index_v; + return hlp::variant_type_index_v <=> hlp::variant_type_index_v; } }, *this, other); } From da9ea3f51831152036db4079456126d766d24e99 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Fri, 1 Aug 2025 00:05:18 +1000 Subject: [PATCH 15/16] disable sort checks --- lib/include/pl/helpers/sort_checks.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/include/pl/helpers/sort_checks.hpp b/lib/include/pl/helpers/sort_checks.hpp index d42cb56a..74a51466 100644 --- a/lib/include/pl/helpers/sort_checks.hpp +++ b/lib/include/pl/helpers/sort_checks.hpp @@ -1,6 +1,6 @@ #pragma once -#define ENABLE_STD_SORT_CHECKS +//#define ENABLE_STD_SORT_CHECKS #ifdef ENABLE_STD_SORT_CHECKS #include From 23669048b372da470938eeec45fa718f37f2991a Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Fri, 1 Aug 2025 01:11:24 +1000 Subject: [PATCH 16/16] Add static_assert. Fiddle around --- lib/include/pl/helpers/variant_type_index.hpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/include/pl/helpers/variant_type_index.hpp b/lib/include/pl/helpers/variant_type_index.hpp index f263553c..5252edcf 100644 --- a/lib/include/pl/helpers/variant_type_index.hpp +++ b/lib/include/pl/helpers/variant_type_index.hpp @@ -11,15 +11,17 @@ struct variant_type_index; template struct variant_type_index> { - static constexpr std::size_t value = []{ + static constexpr auto value = [] -> std::size_t { + static_assert( + (std::is_same_v, Ts> || ...), + "T not in std::variant"); constexpr bool matches[] = { std::is_same_v, Ts>... }; - std::size_t idx = 0; - for (std::size_t i = 0; i < sizeof...(Ts); ++i) { - if (matches[i]) { idx = i; } + for (std::size_t i=0; i