17
17
#include < optional>
18
18
#include < random>
19
19
#include < string>
20
+ #include < type_traits>
20
21
#include < variant>
21
22
22
23
#include " analysis/lattice.h"
@@ -170,14 +171,14 @@ RandomFullLattice::RandomFullLattice(Random& rand,
170
171
uint32_t pick = maybePick ? *maybePick : rand.upTo (3 );
171
172
switch (pick) {
172
173
case 0 :
173
- lattice = std::make_unique<L>(Bool{});
174
+ lattice = std::make_unique<L>(L{ Bool{} });
174
175
return ;
175
176
case 1 :
176
- lattice = std::make_unique<L>(UInt32{});
177
+ lattice = std::make_unique<L>(L{ UInt32{} });
177
178
return ;
178
179
case 2 :
179
180
lattice =
180
- std::make_unique<L>(Inverted{RandomFullLattice{rand, depth + 1 }});
181
+ std::make_unique<L>(L{ Inverted{RandomFullLattice{rand, depth + 1 } }});
181
182
return ;
182
183
}
183
184
WASM_UNREACHABLE (" unexpected pick" );
@@ -190,13 +191,13 @@ RandomLattice::RandomLattice(Random& rand, size_t depth) : rand(rand) {
190
191
case 0 :
191
192
case 1 :
192
193
case 2 :
193
- lattice = std::make_unique<L>(RandomFullLattice{rand, depth, pick});
194
+ lattice = std::make_unique<L>(L{ RandomFullLattice{rand, depth, pick} });
194
195
return ;
195
196
case 3 :
196
- lattice = std::make_unique<L>(Flat<uint32_t >{});
197
+ lattice = std::make_unique<L>(L{ Flat<uint32_t >{} });
197
198
return ;
198
199
case 4 :
199
- lattice = std::make_unique<L>(Lift{RandomLattice{rand, depth + 1 }});
200
+ lattice = std::make_unique<L>(L{ Lift{RandomLattice{rand, depth + 1 } }});
200
201
return ;
201
202
}
202
203
WASM_UNREACHABLE (" unexpected pick" );
@@ -670,15 +671,18 @@ RandomFullLattice::Element RandomFullLattice::getTop() const noexcept {
670
671
*lattice);
671
672
}
672
673
674
+ // TODO: use std::remove_cvref_t from C++20 instead.
675
+ template <typename T> using bare = std::remove_cv_t <std::remove_reference_t <T>>;
676
+
673
677
LatticeComparison RandomFullLattice::compare (const Element& a,
674
678
const Element& b) const noexcept {
675
679
return std::visit (
676
680
[](const auto & l,
677
681
const auto & elemA,
678
682
const auto & elemB) -> LatticeComparison {
679
- using ElemT = typename std:: remove_cvref_t <decltype (l)>::Element;
680
- using A = std:: remove_cvref_t <decltype (elemA)>;
681
- using B = std:: remove_cvref_t <decltype (elemB)>;
683
+ using ElemT = typename bare <decltype (l)>::Element;
684
+ using A = bare <decltype (elemA)>;
685
+ using B = bare <decltype (elemB)>;
682
686
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
683
687
return l.compare (elemA, elemB);
684
688
}
@@ -692,9 +696,9 @@ LatticeComparison RandomFullLattice::compare(const Element& a,
692
696
bool RandomFullLattice::join (Element& a, const Element& b) const noexcept {
693
697
return std::visit (
694
698
[](const auto & l, auto & elemA, const auto & elemB) -> bool {
695
- using ElemT = typename std:: remove_cvref_t <decltype (l)>::Element;
696
- using A = std:: remove_cvref_t <decltype (elemA)>;
697
- using B = std:: remove_cvref_t <decltype (elemB)>;
699
+ using ElemT = typename bare <decltype (l)>::Element;
700
+ using A = bare <decltype (elemA)>;
701
+ using B = bare <decltype (elemB)>;
698
702
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
699
703
return l.join (elemA, elemB);
700
704
}
@@ -708,9 +712,9 @@ bool RandomFullLattice::join(Element& a, const Element& b) const noexcept {
708
712
bool RandomFullLattice::meet (Element& a, const Element& b) const noexcept {
709
713
return std::visit (
710
714
[](const auto & l, auto & elemA, const auto & elemB) -> bool {
711
- using ElemT = typename std:: remove_cvref_t <decltype (l)>::Element;
712
- using A = std:: remove_cvref_t <decltype (elemA)>;
713
- using B = std:: remove_cvref_t <decltype (elemB)>;
715
+ using ElemT = typename bare <decltype (l)>::Element;
716
+ using A = bare <decltype (elemA)>;
717
+ using B = bare <decltype (elemB)>;
714
718
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
715
719
return l.meet (elemA, elemB);
716
720
}
@@ -732,9 +736,9 @@ LatticeComparison RandomLattice::compare(const Element& a,
732
736
[](const auto & l,
733
737
const auto & elemA,
734
738
const auto & elemB) -> LatticeComparison {
735
- using ElemT = typename std:: remove_cvref_t <decltype (l)>::Element;
736
- using A = std:: remove_cvref_t <decltype (elemA)>;
737
- using B = std:: remove_cvref_t <decltype (elemB)>;
739
+ using ElemT = typename bare <decltype (l)>::Element;
740
+ using A = bare <decltype (elemA)>;
741
+ using B = bare <decltype (elemB)>;
738
742
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
739
743
return l.compare (elemA, elemB);
740
744
}
@@ -748,9 +752,9 @@ LatticeComparison RandomLattice::compare(const Element& a,
748
752
bool RandomLattice::join (Element& a, const Element& b) const noexcept {
749
753
return std::visit (
750
754
[](const auto & l, auto & elemA, const auto & elemB) -> bool {
751
- using ElemT = typename std:: remove_cvref_t <decltype (l)>::Element;
752
- using A = std:: remove_cvref_t <decltype (elemA)>;
753
- using B = std:: remove_cvref_t <decltype (elemB)>;
755
+ using ElemT = typename bare <decltype (l)>::Element;
756
+ using A = bare <decltype (elemA)>;
757
+ using B = bare <decltype (elemB)>;
754
758
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
755
759
return l.join (elemA, elemB);
756
760
}
0 commit comments