From aefbfa25bbffe02e691a7dec5aa450734c8535d9 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 29 Sep 2026 12:56:55 -0700 Subject: [PATCH 1/5] fix --- src/support/sorted_vector.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/support/sorted_vector.h b/src/support/sorted_vector.h index 11e6173c64e..df3eccd8ba5 100644 --- a/src/support/sorted_vector.h +++ b/src/support/sorted_vector.h @@ -26,7 +26,7 @@ namespace wasm { -template struct SortedVector : public std::vector { +template struct SortedVector : private std::vector { using Base = std::vector; using Base::back; using Base::begin; @@ -42,6 +42,8 @@ template struct SortedVector : public std::vector { SortedVector() = default; + bool operator==(const SortedVector&) const = default; + SortedVector merge(const SortedVector& other) const { SortedVector ret; ret.resize(size() + other.size()); From 355f805395c80cb3a98a881c3201e106635f1a24 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 29 Sep 2026 13:40:00 -0700 Subject: [PATCH 2/5] fix issues with resize and push_back --- src/support/sorted_vector.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/support/sorted_vector.h b/src/support/sorted_vector.h index df3eccd8ba5..8ba9944a157 100644 --- a/src/support/sorted_vector.h +++ b/src/support/sorted_vector.h @@ -34,8 +34,6 @@ template struct SortedVector : private std::vector { using Base::empty; using Base::end; using Base::erase; - using Base::push_back; - using Base::resize; using Base::size; using typename Base::const_iterator; using typename Base::iterator; @@ -77,7 +75,7 @@ template struct SortedVector : private std::vector { T& insert(T x) { if (empty() || back() < x) { - push_back(std::move(x)); + Base::push_back(std::move(x)); return back(); } auto it = std::lower_bound(begin(), end(), x); @@ -164,6 +162,13 @@ template struct SortedVector : private std::vector { resize(write); } + // Only support decreasing the size (increasing adds default-value items who + // may break the sorting order). + void resize(size_t newSize) { + assert(newSize <= size()); + Base::resize(newSize); + } + void verify() const { for (Index i = 1; i < size(); i++) { assert((*this)[i - 1] < (*this)[i]); From 3658cde2b418cf4d20abf931feec0081e228b39b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 29 Sep 2026 14:11:17 -0700 Subject: [PATCH 3/5] fix asserts --- src/support/sorted_vector.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/support/sorted_vector.h b/src/support/sorted_vector.h index 8ba9944a157..3b976af69d8 100644 --- a/src/support/sorted_vector.h +++ b/src/support/sorted_vector.h @@ -44,7 +44,7 @@ template struct SortedVector : private std::vector { SortedVector merge(const SortedVector& other) const { SortedVector ret; - ret.resize(size() + other.size()); + static_cast(ret).resize(size() + other.size()); Index i = 0, j = 0, t = 0; while (i < size() && j < other.size()) { const auto& left = (*this)[i]; @@ -69,7 +69,7 @@ template struct SortedVector : private std::vector { ret[t++] = other[j]; j++; } - ret.resize(t); + static_cast(ret).resize(t); return ret; } @@ -81,7 +81,7 @@ template struct SortedVector : private std::vector { auto it = std::lower_bound(begin(), end(), x); if (x < *it) { Index i = it - begin(); - resize(size() + 1); + Base::resize(size() + 1); std::move_backward(begin() + i, begin() + size() - 1, end()); (*this)[i] = std::move(x); return (*this)[i]; @@ -131,7 +131,7 @@ template struct SortedVector : private std::vector { skip++; } } - resize(size() - skip); + Base::resize(size() - skip); return *this; } @@ -159,7 +159,7 @@ template struct SortedVector : private std::vector { j++; } } - resize(write); + Base::resize(write); } // Only support decreasing the size (increasing adds default-value items who From 3b89bbfc7b61e1baae720b0d04832d2a0b21dadb Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 29 Sep 2026 14:13:44 -0700 Subject: [PATCH 4/5] rename to shrink --- src/support/sorted_vector.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/support/sorted_vector.h b/src/support/sorted_vector.h index 3b976af69d8..4d22216207e 100644 --- a/src/support/sorted_vector.h +++ b/src/support/sorted_vector.h @@ -38,13 +38,19 @@ template struct SortedVector : private std::vector { using typename Base::const_iterator; using typename Base::iterator; +private: + // Resize is dangerous, as adding new items may break the order. We only use + // this internally (and carefully). + using Base::resize; + +public: SortedVector() = default; bool operator==(const SortedVector&) const = default; SortedVector merge(const SortedVector& other) const { SortedVector ret; - static_cast(ret).resize(size() + other.size()); + ret.resize(size() + other.size()); Index i = 0, j = 0, t = 0; while (i < size() && j < other.size()) { const auto& left = (*this)[i]; @@ -69,7 +75,7 @@ template struct SortedVector : private std::vector { ret[t++] = other[j]; j++; } - static_cast(ret).resize(t); + ret.resize(t); return ret; } @@ -81,7 +87,7 @@ template struct SortedVector : private std::vector { auto it = std::lower_bound(begin(), end(), x); if (x < *it) { Index i = it - begin(); - Base::resize(size() + 1); + resize(size() + 1); std::move_backward(begin() + i, begin() + size() - 1, end()); (*this)[i] = std::move(x); return (*this)[i]; @@ -131,7 +137,7 @@ template struct SortedVector : private std::vector { skip++; } } - Base::resize(size() - skip); + resize(size() - skip); return *this; } @@ -159,14 +165,7 @@ template struct SortedVector : private std::vector { j++; } } - Base::resize(write); - } - - // Only support decreasing the size (increasing adds default-value items who - // may break the sorting order). - void resize(size_t newSize) { - assert(newSize <= size()); - Base::resize(newSize); + resize(write); } void verify() const { From 88185fdd4ca94e1c36c464d4cfc66af9e03a5dd9 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 29 Sep 2026 14:17:07 -0700 Subject: [PATCH 5/5] remove dead code --- src/support/sorted_vector.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/support/sorted_vector.h b/src/support/sorted_vector.h index 4d22216207e..4d0e8046882 100644 --- a/src/support/sorted_vector.h +++ b/src/support/sorted_vector.h @@ -168,12 +168,6 @@ template struct SortedVector : private std::vector { resize(write); } - void verify() const { - for (Index i = 1; i < size(); i++) { - assert((*this)[i - 1] < (*this)[i]); - } - } - void dump(const char* str = nullptr) const { std::cout << "SortedVector " << (str ? str : "") << ": "; for (const auto& x : *this) {