From 96d2c946329f26bb742684a70cb48e98aa55083d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 12 Aug 2021 09:32:39 -0700 Subject: Add a shallowHash() method (#4077) This adds and tests the new method. It will be used in a new pass later, where computing shallow hashes allows it to be done in linear time. 99% of the diff is whitespace. --- test/example/hash.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'test/example/hash.cpp') diff --git a/test/example/hash.cpp b/test/example/hash.cpp index ba9ca24ea..944cef14c 100644 --- a/test/example/hash.cpp +++ b/test/example/hash.cpp @@ -11,6 +11,14 @@ using namespace wasm; #define assertNotEqual(left, right) \ assert(ExpressionAnalyzer::hash(&left) != ExpressionAnalyzer::hash(&right)); +#define assertShallowEqual(left, right) \ + assert(ExpressionAnalyzer::shallowHash(&left) == \ + ExpressionAnalyzer::shallowHash(&right)); + +#define assertShallowNotEqual(left, right) \ + assert(ExpressionAnalyzer::shallowHash(&left) != \ + ExpressionAnalyzer::shallowHash(&right)); + int main() { { Const x, y; @@ -33,7 +41,7 @@ int main() { assertNotEqual(x, y); } { - // Nested child. + // Nested identical child. Drop dx, dy; Const x, y; x.set(Literal(int32_t(10))); @@ -43,7 +51,17 @@ int main() { assertEqual(dx, dy); } { - // Nested child. + // Nested identical child, checked shallowly. + Drop dx, dy; + Const x, y; + x.set(Literal(int32_t(10))); + y.set(Literal(int32_t(10))); + dx.value = &x; + dy.value = &y; + assertShallowEqual(dx, dy); + } + { + // Nested different child. Drop dx, dy; Const x, y; x.set(Literal(int32_t(10))); @@ -52,6 +70,17 @@ int main() { dy.value = &y; assertNotEqual(dx, dy); } + { + // Nested different child, checked shallowly (so we ignore the difference, + // and return equal). + Drop dx, dy; + Const x, y; + x.set(Literal(int32_t(10))); + y.set(Literal(int32_t(11))); + dx.value = &x; + dy.value = &y; + assertShallowEqual(dx, dy); + } MixedArena arena; { // Blocks -- cgit v1.2.3