diff options
author | Thomas Lively <tlively@google.com> | 2023-10-19 07:41:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-18 22:41:53 -0700 |
commit | f79b5aa26b1fc722853e56b541cd35128786ef6b (patch) | |
tree | 0a8255cb2a3d2c4f1ee41dcb64cbcce4758f4341 /src/tools | |
parent | c170fe7893fc05147de455e36d0a36b356b3f3db (diff) | |
download | binaryen-f79b5aa26b1fc722853e56b541cd35128786ef6b.tar.gz binaryen-f79b5aa26b1fc722853e56b541cd35128786ef6b.tar.bz2 binaryen-f79b5aa26b1fc722853e56b541cd35128786ef6b.zip |
[analysis][NFC] Use C++20 concepts for Lattice (#6027)
Replace the static assertions ensuring that Lattice types have the necessary
operations with a C++20 concept called `Lattice`. To avoid name conflicts with
the new concept, rename existing type parameters named `Lattice` to `L`. When
not building with C++20, `Lattice` is a macro that resolves to `typename` so the
code continues compiling and has the same behavior, but without any eager checks
of the requirements on lattices.
Add a new C++20 builder to CI to ensure that future changes compile with both
C++17 and C++20. Once we switch to C++20 by default, the new builder can be
removed. Update the lint builder to use a recent clang-format that understands
concepts.
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/wasm-fuzz-lattices.cpp | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/tools/wasm-fuzz-lattices.cpp b/src/tools/wasm-fuzz-lattices.cpp index 6bb79b106..730e6d621 100644 --- a/src/tools/wasm-fuzz-lattices.cpp +++ b/src/tools/wasm-fuzz-lattices.cpp @@ -44,15 +44,15 @@ uint64_t getSeed() { // Utility class which provides methods to check properties of the transfer // function and lattice of an analysis. -template<typename Lattice, typename TransferFunction> struct AnalysisChecker { - Lattice& lattice; +template<Lattice L, typename TransferFunction> struct AnalysisChecker { + L& lattice; TransferFunction& transferFunction; std::string latticeName; std::string transferFunctionName; uint64_t latticeElementSeed; Name funcName; - AnalysisChecker(Lattice& lattice, + AnalysisChecker(L& lattice, TransferFunction& transferFunction, std::string latticeName, std::string transferFunctionName, @@ -71,9 +71,9 @@ template<typename Lattice, typename TransferFunction> struct AnalysisChecker { // Prints information about a particular test case consisting of a randomly // generated function and triple of randomly generate lattice elements. void printVerboseFunctionCase(std::ostream& os, - typename Lattice::Element& x, - typename Lattice::Element& y, - typename Lattice::Element& z) { + typename L::Element& x, + typename L::Element& y, + typename L::Element& z) { os << "Using lattice element seed " << latticeElementSeed << "\nGenerated " << latticeName << " elements:\n"; x.print(os); @@ -86,7 +86,7 @@ template<typename Lattice, typename TransferFunction> struct AnalysisChecker { } // Checks reflexivity of a lattice element, i.e. x = x. - void checkReflexivity(typename Lattice::Element& element) { + void checkReflexivity(typename L::Element& element) { LatticeComparison result = lattice.compare(element, element); if (result != LatticeComparison::EQUAL) { std::stringstream ss; @@ -106,8 +106,7 @@ template<typename Lattice, typename TransferFunction> struct AnalysisChecker { // // Instead, we check for a related concept that x < y implies y > x, and // vice versa in this checkAntiSymmetry function. - void checkAntiSymmetry(typename Lattice::Element& x, - typename Lattice::Element& y) { + void checkAntiSymmetry(typename L::Element& x, typename L::Element& y) { LatticeComparison result = lattice.compare(x, y); LatticeComparison reverseResult = lattice.compare(y, x); @@ -127,9 +126,9 @@ private: // Prints the error message when a triple of lattice elements violates // transitivity. void printTransitivityError(std::ostream& os, - typename Lattice::Element& a, - typename Lattice::Element& b, - typename Lattice::Element& c, + typename L::Element& a, + typename L::Element& b, + typename L::Element& c, LatticeComparison ab, LatticeComparison bc, LatticeComparison ac) { @@ -163,9 +162,9 @@ private: public: // Given three lattice elements x, y, and z, checks if transitivity holds // between them. - void checkTransitivity(typename Lattice::Element& x, - typename Lattice::Element& y, - typename Lattice::Element& z) { + void checkTransitivity(typename L::Element& x, + typename L::Element& y, + typename L::Element& z) { LatticeComparison xy = lattice.compare(x, y); LatticeComparison yz = lattice.compare(y, z); LatticeComparison xz = lattice.compare(x, z); @@ -194,10 +193,10 @@ public: // the CFG block input which caused the transfer function to exhibit // non-monotonic behavior. void checkMonotonicity(const BasicBlock* cfgBlock, - typename Lattice::Element& first, - typename Lattice::Element& second, - typename Lattice::Element& firstResult, - typename Lattice::Element& secondResult) { + typename L::Element& first, + typename L::Element& second, + typename L::Element& firstResult, + typename L::Element& secondResult) { LatticeComparison beforeCmp = lattice.compare(first, second); LatticeComparison afterCmp = lattice.compare(firstResult, secondResult); @@ -241,9 +240,9 @@ public: } // Checks lattice-only properties for a triple of lattices. - void checkLatticeElements(typename Lattice::Element x, - typename Lattice::Element y, - typename Lattice::Element z) { + void checkLatticeElements(typename L::Element x, + typename L::Element y, + typename L::Element z) { checkReflexivity(x); checkReflexivity(y); checkReflexivity(z); @@ -258,16 +257,16 @@ public: // using the same three input states each time and then checking properties on // the inputs and outputs. void checkTransferFunction(CFG& cfg, - typename Lattice::Element x, - typename Lattice::Element y, - typename Lattice::Element z) { + typename L::Element x, + typename L::Element y, + typename L::Element z) { for (auto cfgIter = cfg.begin(); cfgIter != cfg.end(); ++cfgIter) { // Apply transfer function on each lattice element. - typename Lattice::Element xResult = x; + typename L::Element xResult = x; transferFunction.transfer(&(*cfgIter), xResult); - typename Lattice::Element yResult = y; + typename L::Element yResult = y; transferFunction.transfer(&(*cfgIter), yResult); - typename Lattice::Element zResult = z; + typename L::Element zResult = z; transferFunction.transfer(&(*cfgIter), zResult); // Check monotonicity for every pair of transfer function outputs. |