From b1369040c3d6d6a8704bdb17d9de99f36a108e07 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 26 May 2020 13:53:10 -0400 Subject: Improvements around hashing (#1355) * Fields from upper to lower case in slang-ast-decl.h * Lower camel field names in slang-ast-stmt.h * Fix fields in slang-ast-expr.h * slang-ast-type.h make fields lowerCamel. * slang-ast-base.h members functions lowerCamel. * Method names in slang-ast-type.h to lowerCamel. * GetCanonicalType -> getCanonicalType * Substitute -> substitute * Equals -> equals ToString -> toString * ParentDecl -> parentDecl Members -> members * * Make hash code types explicit * Use HashCode as return type of GetHashCode * Added conversion from double to int64_t * Split Stable from other hash functions * toHash32/64 to convert a HashCode to the other styles. GetHashCode32/64 -> getHashCode32/64 GetStableHashCode32/64 -> getStableHashCode32/64 * Other Get/Stable/HashCode32/64 fixes * GetHashCode -> getHashCode * Equals -> equals * CreateCanonicalType -> createCanonicalType * Catches of polymorphic types should be through references otherwise slicing can occur. * Fixes for newer verison of gcc. Fix hashing problem on gcc for Dictionary. * Another fix for GetHashPos * Fix signed issue around GetHashPos --- source/slang/slang-state-serialize.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source/slang/slang-state-serialize.cpp') diff --git a/source/slang/slang-state-serialize.cpp b/source/slang/slang-state-serialize.cpp index abdaae7c6..3d98f182d 100644 --- a/source/slang/slang-state-serialize.cpp +++ b/source/slang/slang-state-serialize.cpp @@ -53,19 +53,19 @@ namespace Slang { #define SLANG_STATE_TYPE_SIZE(x) uint32_t(sizeof(x)), // A function to calculate the hash related in list in part to how the types used are sized. Can catch crude breaking binary differences. -static uint32_t _calcTypeHash() +static HashCode32 _calcTypeHash() { typedef StateSerializeUtil Util; const uint32_t sizes[] = { SLANG_STATE_TYPES(SLANG_STATE_TYPE_SIZE) }; - return uint32_t(GetHashCode((const char*)&sizes, sizeof(sizes))); + return getStableHashCode32((const char*)&sizes, sizeof(sizes)); } -static uint32_t _getTypeHash() +static HashCode32 _getTypeHash() { - static uint32_t s_hash = _calcTypeHash(); + static HashCode32 s_hash = _calcTypeHash(); return s_hash; } @@ -1053,7 +1053,7 @@ struct LoadContext Header header; header.m_chunk.type = kSlangStateFourCC; header.m_semanticVersion = g_semanticVersion; - header.m_typeHash = _getTypeHash(); + header.m_typeHash = uint32_t(_getTypeHash()); return RiffUtil::writeData(&header.m_chunk, sizeof(header),container.getData(), container.getDataCount(), stream); } @@ -1071,7 +1071,7 @@ struct LoadContext { stream = new FileStream(filename, FileMode::Open, FileAccess::Read, FileShare::ReadWrite); } - catch (IOException&) + catch (const IOException&) { return SLANG_FAIL; } @@ -1094,7 +1094,7 @@ struct LoadContext return SLANG_FAIL; } - if (header.m_typeHash != _getTypeHash()) + if (header.m_typeHash != uint32_t(_getTypeHash())) { return SLANG_FAIL; } @@ -1550,7 +1550,7 @@ static SlangResult _findFirstSourcePath(EndToEndCompileRequest* request, String& outStream = new FileStream(builder, FileMode::CreateNew, FileAccess::Write, FileShare::WriteOnly); return SLANG_OK; } - catch (IOException&) + catch (const IOException&) { } -- cgit v1.2.3