diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-05-26 13:53:10 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-26 13:53:10 -0400 |
| commit | b1369040c3d6d6a8704bdb17d9de99f36a108e07 (patch) | |
| tree | 2761b93946969fe2f505161d3c75e8cabb6107b6 /source | |
| parent | ee2ec68596262398b2d77c128f45b3f32a28c35e (diff) | |
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
Diffstat (limited to 'source')
43 files changed, 348 insertions, 286 deletions
diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h index be7cc21f5..72b24f81c 100644 --- a/source/core/slang-dictionary.h +++ b/source/core/slang-dictionary.h @@ -54,11 +54,11 @@ namespace Slang Value = that.Value; return *this; } - int GetHashCode() + HashCode getHashCode() { return combineHash( - Slang::GetHashCode(Key), - Slang::GetHashCode(Value)); + Slang::getHashCode(Key), + Slang::getHashCode(Value)); } bool operator==(const KeyValuePair<TKey, TValue>& that) const { @@ -135,8 +135,10 @@ namespace Slang }; inline int GetHashPos(TKey& key) const - { - return ((unsigned int)(GetHashCode(key) * 2654435761)) % bucketSizeMinusOne; + { + SLANG_ASSERT(bucketSizeMinusOne > 0); + const unsigned int hash = (unsigned int)getHashCode(key); + return (hash * 2654435761u) % (unsigned int)(bucketSizeMinusOne); } FindPositionResult FindPosition(const TKey& key) const { @@ -166,7 +168,7 @@ namespace Slang } if (insertPos != -1) return FindPositionResult(-1, insertPos); - throw InvalidOperationException("Hash map is full. This indicates an error in Key::Equal or Key::GetHashCode."); + throw InvalidOperationException("Hash map is full. This indicates an error in Key::Equal or Key::getHashCode."); } TValue & _Insert(KeyValuePair<TKey, TValue>&& kvPair, int pos) { diff --git a/source/core/slang-downstream-compiler.h b/source/core/slang-downstream-compiler.h index bcf53d065..f43c4b560 100644 --- a/source/core/slang-downstream-compiler.h +++ b/source/core/slang-downstream-compiler.h @@ -154,7 +154,7 @@ public: { typedef Desc ThisType; - UInt GetHashCode() const { return combineHash(int(type), combineHash(int(majorVersion), int(minorVersion))); } + HashCode getHashCode() const { return combineHash(HashCode(type), combineHash(HashCode(majorVersion), HashCode(minorVersion))); } bool operator==(const ThisType& rhs) const { return type == rhs.type && majorVersion == rhs.majorVersion && minorVersion == rhs.minorVersion; } bool operator!=(const ThisType& rhs) const { return !(*this == rhs); } diff --git a/source/core/slang-hash.h b/source/core/slang-hash.h index 08a40491c..5a0766c98 100644 --- a/source/core/slang-hash.h +++ b/source/core/slang-hash.h @@ -7,56 +7,102 @@ namespace Slang { - typedef int HashCode; + // Ideally Hash codes should be unsigned types - makes accumulation simpler (as overflow/underflow behavior are defined) + // Only downside is around multiply, where unsigned multiply can be slightly slower on some targets. - inline int GetHashCode(double key) + // HashCode - size may vary by platform. Typically has 'best' combination of bits/performance. Should not be exposed externally as value from same input may change depending on compilation platform. + typedef unsigned int HashCode; + + // A fixed 64bit wide hash on all targets. + typedef uint64_t HashCode64; + // A fixed 32bit wide hash on all targets. + typedef uint32_t HashCode32; + + SLANG_FORCE_INLINE HashCode32 toHash32(HashCode value) { return (sizeof(HashCode) == sizeof(int64_t)) ? (HashCode32(uint64_t(value) >> 32) ^ HashCode(value)) : HashCode32(value); } + SLANG_FORCE_INLINE HashCode64 toHash64(HashCode value) { return (sizeof(HashCode) == sizeof(int64_t)) ? HashCode(value) : ((HashCode64(value) << 32) | value); } + + SLANG_FORCE_INLINE HashCode getHashCode(int64_t value) + { + return (sizeof(HashCode) == sizeof(int64_t)) ? HashCode(value) : (HashCode(uint64_t(value) >> 32) ^ HashCode(value)); + } + SLANG_FORCE_INLINE HashCode getHashCode(uint64_t value) + { + return (sizeof(HashCode) == sizeof(uint64_t)) ? HashCode(value) : (HashCode(value >> 32) ^ HashCode(value)); + } + + inline HashCode getHashCode(double key) { - return FloatAsInt((float)key); + return getHashCode(DoubleAsInt64(key)); } - inline int GetHashCode(float key) + inline HashCode getHashCode(float key) { return FloatAsInt(key); - } - inline int GetHashCode(const char * buffer) + } + inline HashCode getHashCode(const char* buffer) { if (!buffer) return 0; - int hash = 0; - int c; + HashCode hash = 0; auto str = buffer; - c = *str++; + HashCode c = HashCode(*str++); while (c) { hash = c + (hash << 6) + (hash << 16) - hash; - c = *str++; + c = HashCode(*str++); } return hash; - } - inline int GetHashCode(char * buffer) + } + inline HashCode getHashCode(char* buffer) { - return GetHashCode(const_cast<const char *>(buffer)); + return getHashCode(const_cast<const char *>(buffer)); } - inline int GetHashCode(const char * buffer, size_t numChars) + inline HashCode getHashCode(const char* buffer, size_t numChars) { - int hash = 0; + HashCode hash = 0; for (size_t i = 0; i < numChars; ++i) { - hash = int(buffer[i]) + (hash << 6) + (hash << 16) - hash; + hash = HashCode(buffer[i]) + (hash << 6) + (hash << 16) - hash; } return hash; } - inline uint64_t GetHashCode64(const char * buffer, size_t numChars) + /* The 'Stable' hash code functions produce hashes that must be + + * The same result for the same inputs on all targets + * Rarely change - as their values can change the output of the Slang API/Serialization + + Hash value used from the 'Stable' functions can also be used as part of serialization - + so it is in effect part of the API. + + In effect this means changing a 'Stable' algorithm will typically require doing a new release. + */ + inline HashCode32 getStableHashCode32(const char* buffer, size_t numChars) + { + HashCode32 hash = 0; + for (size_t i = 0; i < numChars; ++i) + { + hash = HashCode32(buffer[i]) + (hash << 6) + (hash << 16) - hash; + } + return hash; + } + + inline HashCode64 getStableHashCode64(const char* buffer, size_t numChars) { - // Use uints because hash requires wrap around behavior and int is undefined on over/underflows - uint64_t hash = 0; + // Use HashCode64 is assumed unsigned because hash requires wrap around behavior and int is undefined on over/underflows + HashCode64 hash = 0; for (size_t i = 0; i < numChars; ++i) { - hash = uint64_t(int64_t(buffer[i])) + (hash << 6) + (hash << 16) - hash; + hash = HashCode64(HashCode64(buffer[i])) + (hash << 6) + (hash << 16) - hash; } return hash; } + // Hash functions with specific sized results + // TODO(JS): We might want to implement HashCode as just an alias a suitable Hash32/Hash32 based on target. + // For now just use Stable for 64bit. + SLANG_FORCE_INLINE HashCode64 getHashCode64(const char* buffer, size_t numChars) { return getStableHashCode64(buffer, numChars); } + SLANG_FORCE_INLINE HashCode32 getHashCode32(const char* buffer, size_t numChars) { return toHash32(getHashCode(buffer, numChars)); } + template<int IsInt> class Hash { @@ -67,9 +113,9 @@ namespace Slang { public: template<typename TKey> - static int GetHashCode(TKey & key) + static HashCode getHashCode(TKey& key) { - return (int)key; + return (HashCode)key; } }; template<> @@ -77,9 +123,9 @@ namespace Slang { public: template<typename TKey> - static int GetHashCode(TKey & key) + static HashCode getHashCode(TKey& key) { - return int(key.GetHashCode()); + return HashCode(key.getHashCode()); } }; template<int IsPointer> @@ -90,9 +136,9 @@ namespace Slang { public: template<typename TKey> - static int GetHashCode(TKey const& key) + static HashCode getHashCode(TKey const& key) { - return (int)((PtrInt)key) / 16; // sizeof(typename std::remove_pointer<TKey>::type); + return (HashCode)((PtrInt)key) / 16; // sizeof(typename std::remove_pointer<TKey>::type); } }; template<> @@ -100,25 +146,25 @@ namespace Slang { public: template<typename TKey> - static int GetHashCode(TKey & key) + static HashCode getHashCode(TKey& key) { - return Hash<std::is_integral<TKey>::value || std::is_enum<TKey>::value>::GetHashCode(key); + return Hash<std::is_integral<TKey>::value || std::is_enum<TKey>::value>::getHashCode(key); } }; template<typename TKey> - int GetHashCode(const TKey & key) + HashCode getHashCode(const TKey& key) { - return PointerHash<std::is_pointer<TKey>::value>::GetHashCode(key); + return PointerHash<std::is_pointer<TKey>::value>::getHashCode(key); } template<typename TKey> - int GetHashCode(TKey & key) + HashCode getHashCode(TKey& key) { - return PointerHash<std::is_pointer<TKey>::value>::GetHashCode(key); + return PointerHash<std::is_pointer<TKey>::value>::getHashCode(key); } - inline int combineHash(int left, int right) + inline HashCode combineHash(HashCode left, HashCode right) { return (left * 16777619) ^ right; } @@ -131,13 +177,13 @@ namespace Slang template<typename T> void hashValue(T const& value) { - m_hashCode = combineHash(m_hashCode, GetHashCode(value)); + m_hashCode = combineHash(m_hashCode, getHashCode(value)); } template<typename T> void hashObject(T const& object) { - m_hashCode = combineHash(m_hashCode, object->GetHashCode()); + m_hashCode = combineHash(m_hashCode, object->getHashCode()); } HashCode getResult() const diff --git a/source/core/slang-hex-dump-util.cpp b/source/core/slang-hex-dump-util.cpp index 69c6d3f21..cb7187499 100644 --- a/source/core/slang-hex-dump-util.cpp +++ b/source/core/slang-hex-dump-util.cpp @@ -26,8 +26,8 @@ static const char s_hex[] = "0123456789abcdef"; SLANG_RETURN_ON_FAIL(helper.write(s_start.begin(), s_start.getLength())); SLANG_RETURN_ON_FAIL(helper.print(" %zu", dataCount)); - const int hash = GetHashCode((const char*)data, dataCount); - SLANG_RETURN_ON_FAIL(helper.print(" %d\n", hash )); + const HashCode32 hash = getStableHashCode32((const char*)data, dataCount); + SLANG_RETURN_ON_FAIL(helper.print(" %d\n", int(hash) )); SLANG_RETURN_ON_FAIL(dump(data, dataCount, maxBytesPerLine, writer)); @@ -191,7 +191,7 @@ static SlangResult _findLine(const UnownedStringSlice& find, UnownedStringSlice& UnownedStringSlice startLine, endLine; SLANG_RETURN_ON_FAIL(findStartAndEndLines(lines, startLine, endLine)); - int hash; + HashCode32 hash; size_t size; { // Get the size and the hash @@ -203,13 +203,13 @@ static SlangResult _findLine(const UnownedStringSlice& find, UnownedStringSlice& } // Extract the size size = StringToInt(String(slices[1])); - hash = int(StringToInt(String(slices[2]))); + hash = HashCode32(StringToInt(String(slices[2]))); } SLANG_RETURN_ON_FAIL(parse(UnownedStringSlice(startLine.end(), endLine.begin()), outBytes)); // Calc the hash - const int readHash = GetHashCode((const char*)outBytes.begin(), outBytes.getCount()); + const HashCode32 readHash = getStableHashCode32((const char*)outBytes.begin(), outBytes.getCount()); if (readHash != hash || size_t(outBytes.getCount()) != size) { diff --git a/source/core/slang-math.h b/source/core/slang-math.h index 7d3a741a4..2378b73a0 100644 --- a/source/core/slang-math.h +++ b/source/core/slang-math.h @@ -21,10 +21,16 @@ namespace Slang float fvalue; int ivalue; - inline static FloatIntUnion makeFromInt(int i) { FloatIntUnion cast; cast.ivalue = i; return cast; } - inline static FloatIntUnion makeFromFloat(float f) { FloatIntUnion cast; cast.fvalue = f; return cast; } + SLANG_FORCE_INLINE static FloatIntUnion makeFromInt(int i) { FloatIntUnion cast; cast.ivalue = i; return cast; } + SLANG_FORCE_INLINE static FloatIntUnion makeFromFloat(float f) { FloatIntUnion cast; cast.fvalue = f; return cast; } + }; + union DoubleInt64Union + { + double dvalue; + int64_t ivalue; + SLANG_FORCE_INLINE static DoubleInt64Union makeFromInt64(int64_t i) { DoubleInt64Union cast; cast.ivalue = i; return cast; } + SLANG_FORCE_INLINE static DoubleInt64Union makeFromDouble(double d) { DoubleInt64Union cast; cast.dvalue = d; return cast; } }; - static const float Pi; @@ -171,6 +177,15 @@ namespace Slang return Math::FloatIntUnion::makeFromInt(val).fvalue; } + SLANG_FORCE_INLINE int64_t DoubleAsInt64(double val) + { + return Math::DoubleInt64Union::makeFromDouble(val).ivalue; + } + SLANG_FORCE_INLINE double Int64AsDouble(int64_t value) + { + return Math::DoubleInt64Union::makeFromInt64(value).dvalue; + } + inline unsigned short FloatToHalf(float val) { const auto x = FloatAsInt(val); diff --git a/source/core/slang-riff.cpp b/source/core/slang-riff.cpp index da547319b..9fc23fbc8 100644 --- a/source/core/slang-riff.cpp +++ b/source/core/slang-riff.cpp @@ -32,7 +32,7 @@ namespace Slang { stream->read(&outChunk, sizeof(RiffHeader)); } - catch (IOException&) + catch (const IOException&) { return SLANG_FAIL; } @@ -77,7 +77,7 @@ namespace Slang out->write(end, padSize - payloadSize); } } - catch (IOException&) + catch (const IOException&) { return SLANG_FAIL; } @@ -99,7 +99,7 @@ namespace Slang } outReadSize = alignedSize; } - catch (IOException&) + catch (const IOException&) { return SLANG_FAIL; } @@ -126,7 +126,7 @@ namespace Slang stream->read(outHeader + 1, headerSize - sizeof(RiffHeader)); } } - catch (IOException&) + catch (const IOException&) { return SLANG_FAIL; } @@ -187,7 +187,7 @@ struct DumpVisitor : public RiffContainer::Visitor _dumpRiffType(data->m_fourCC); m_writer.put(" "); - int hash = data->calcHash(); + const RiffHashCode hash = data->calcHash(); // We don't know in general what the contents is or means... but we can display a hash HexDumpUtil::dump(uint32_t(hash), m_writer.getWriter()); @@ -630,21 +630,21 @@ RiffReadHelper RiffContainer::DataChunk::asReadHelper() const return RiffReadHelper(nullptr, 0); } -int RiffContainer::DataChunk::calcHash() const +RiffHashCode RiffContainer::DataChunk::calcHash() const { - int hash = 0; + RiffHashCode hash = 0; Data* data = m_dataList; while (data) { - // This is a little contrived (in that we don't use the function GetHashCode), but the + // This is a little contrived (in that we don't use the function getHashCode), but the // reason to be careful is we want the same result however many Data blocks there are. const char* buffer = (const char*)data->getPayload(); const size_t size = data->getSize(); for (size_t i = 0; i < size; ++i) { - hash = int(buffer[i]) + (hash << 6) + (hash << 16) - hash; + hash = RiffHashCode(buffer[i]) + (hash << 6) + (hash << 16) - hash; } data = data->m_next; diff --git a/source/core/slang-riff.h b/source/core/slang-riff.h index 535eaffc2..6eeb0a722 100644 --- a/source/core/slang-riff.h +++ b/source/core/slang-riff.h @@ -39,6 +39,9 @@ enum kRiffPadMask = kRiffPadSize - 1, }; +// Uses it's own version of a hash +typedef int RiffHashCode; + struct RiffHeader { FourCC type; ///< The FourCC code that identifies this chunk @@ -186,6 +189,7 @@ public: struct ListChunk; struct DataChunk; + struct Data { /// Get the payload @@ -297,7 +301,7 @@ public: SLANG_FORCE_INLINE static bool isType(const Chunk* chunk) { return chunk->m_kind == Kind::Data; } /// Calculate a hash (not necessarily very fast) - int calcHash() const; + RiffHashCode calcHash() const; /// Calculate the payload size size_t calcPayloadSize() const; diff --git a/source/core/slang-smart-pointer.h b/source/core/slang-smart-pointer.h index 1bbcffe47..53ac010ed 100644 --- a/source/core/slang-smart-pointer.h +++ b/source/core/slang-smart-pointer.h @@ -24,6 +24,8 @@ namespace Slang : referenceCount(0) {} + RefObject& operator=(const RefObject& rhs) = default; + virtual ~RefObject() {} @@ -152,13 +154,13 @@ namespace Slang releaseReference(old); } - int GetHashCode() + HashCode getHashCode() { // Note: We need a `RefPtr<T>` to hash the same as a `T*`, // so that a `T*` can be used as a key in a dictionary with // `RefPtr<T>` keys, and vice versa. // - return Slang::GetHashCode(pointer); + return Slang::getHashCode(pointer); } bool operator==(const T * ptr) const diff --git a/source/core/slang-string.h b/source/core/slang-string.h index 5eb113dc1..02a43a806 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -170,9 +170,9 @@ namespace Slang UnownedStringSlice trim() const; - int GetHashCode() const + HashCode getHashCode() const { - return Slang::GetHashCode(m_begin, size_t(m_end - m_begin)); + return Slang::getHashCode(m_begin, size_t(m_end - m_begin)); } template <size_t SIZE> @@ -802,9 +802,9 @@ namespace Slang return contains(str.begin()); } - int GetHashCode() const + HashCode getHashCode() const { - return Slang::GetHashCode((const char*)begin()); + return Slang::getHashCode(StringRepresentation::asSlice(m_buffer)); } UnownedStringSlice getUnownedSlice() const diff --git a/source/core/slang-text-io.cpp b/source/core/slang-text-io.cpp index 4e989b627..ca3b9447c 100644 --- a/source/core/slang-text-io.cpp +++ b/source/core/slang-text-io.cpp @@ -278,7 +278,7 @@ namespace Slang } destBuffer[i] = ch; } - catch (EndOfStreamException) + catch (const EndOfStreamException& ) { break; } @@ -307,7 +307,7 @@ namespace Slang } sb.Append(ch); } - catch (EndOfStreamException) + catch (const EndOfStreamException&) { break; } @@ -333,7 +333,7 @@ namespace Slang else sb.Append(ch); } - catch (EndOfStreamException) + catch (const EndOfStreamException&) { break; } diff --git a/source/core/slang-uint-set.cpp b/source/core/slang-uint-set.cpp index 656bd8ba8..3ac1c530a 100644 --- a/source/core/slang-uint-set.cpp +++ b/source/core/slang-uint-set.cpp @@ -27,7 +27,7 @@ UIntSet& UIntSet::operator=(const UIntSet& other) return *this; } -int UIntSet::GetHashCode() +HashCode UIntSet::getHashCode() { int rs = 0; for (auto val : m_buffer) diff --git a/source/core/slang-uint-set.h b/source/core/slang-uint-set.h index 77930ba0d..7833ffa25 100644 --- a/source/core/slang-uint-set.h +++ b/source/core/slang-uint-set.h @@ -4,6 +4,7 @@ #include "slang-list.h" #include "slang-math.h" #include "slang-common.h" +#include "slang-hash.h" #include <memory.h> @@ -24,7 +25,7 @@ public: UIntSet& operator=(UIntSet&& other); UIntSet& operator=(const UIntSet& other); - int GetHashCode(); + HashCode getHashCode(); /// Return the count of all bits directly represented Int getCount() const { return Int(m_buffer.getCount()) * kElementSize; } diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h index 373f38018..ffa065323 100644 --- a/source/slang/slang-ast-base.h +++ b/source/slang/slang-ast-base.h @@ -89,7 +89,7 @@ class Val : public NodeBase virtual bool equalsVal(Val* val) = 0; virtual String toString() = 0; - virtual int GetHashCode() = 0; + virtual HashCode getHashCode() = 0; bool operator == (const Val & v) { return equalsVal(const_cast<Val*>(&v)); @@ -141,7 +141,7 @@ public: protected: virtual bool equalsImpl(Type* type) = 0; - virtual RefPtr<Type> CreateCanonicalType() = 0; + virtual RefPtr<Type> createCanonicalType() = 0; Type* canonicalType = nullptr; SLANG_UNREFLECTED @@ -167,7 +167,7 @@ class Substitutions: public RefObject // Check if these are equivalent substitutions to another set virtual bool equals(Substitutions* subst) = 0; - virtual int GetHashCode() const = 0; + virtual HashCode getHashCode() const = 0; }; class GenericSubstitution : public Substitutions @@ -187,12 +187,12 @@ class GenericSubstitution : public Substitutions // Check if these are equivalent substitutions to another set virtual bool equals(Substitutions* subst) override; - virtual int GetHashCode() const override + virtual HashCode getHashCode() const override { - int rs = 0; + HashCode rs = 0; for (auto && v : args) { - rs ^= v->GetHashCode(); + rs ^= v->getHashCode(); rs *= 16777619; } return rs; @@ -217,7 +217,7 @@ class ThisTypeSubstitution : public Substitutions // Check if these are equivalent substitutions to another set virtual bool equals(Substitutions* subst) override; - virtual int GetHashCode() const override; + virtual HashCode getHashCode() const override; }; class GlobalGenericParamSubstitution : public Substitutions @@ -244,12 +244,12 @@ class GlobalGenericParamSubstitution : public Substitutions // Check if these are equivalent substitutions to another set virtual bool equals(Substitutions* subst) override; - virtual int GetHashCode() const override + virtual HashCode getHashCode() const override { - int rs = actualType->GetHashCode(); + HashCode rs = actualType->getHashCode(); for (auto && a : constraintArgs) { - rs = combineHash(rs, a.val->GetHashCode()); + rs = combineHash(rs, a.val->getHashCode()); } return rs; } diff --git a/source/slang/slang-ast-decl.h b/source/slang/slang-ast-decl.h index 1e7287e56..54e8ac18b 100644 --- a/source/slang/slang-ast-decl.h +++ b/source/slang/slang-ast-decl.h @@ -155,7 +155,7 @@ class EnumCaseDecl : public Decl // type of the parent `enum` TypeExp type; - Type* getType() { return (Type*)type.type.Ptr(); } + Type* getType() { return type.type.Ptr(); } // Tag value RefPtr<Expr> tagExpr; diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h index fdcc34ea2..af5689a5c 100644 --- a/source/slang/slang-ast-support-types.h +++ b/source/slang/slang-ast-support-types.h @@ -606,8 +606,8 @@ namespace Slang : substitutions(subst) { } - bool Equals(const SubstitutionSet& substSet) const; - int GetHashCode() const; + bool equals(const SubstitutionSet& substSet) const; + HashCode getHashCode() const; }; template<typename T> @@ -663,10 +663,10 @@ namespace Slang DeclRef<T> as() const; // Check if this is an equivalent declaration reference to another - bool Equals(DeclRefBase const& declRef) const; + bool equals(DeclRefBase const& declRef) const; bool operator == (const DeclRefBase& other) const { - return Equals(other); + return equals(other); } // Convenience accessors for common properties of declarations @@ -674,7 +674,7 @@ namespace Slang SourceLoc getLoc() const; DeclRefBase GetParent() const; - int GetHashCode() const; + HashCode getHashCode() const; // Debugging: String toString() const; @@ -961,6 +961,8 @@ namespace Slang // We store both the original syntax and the resolved type here. struct TypeExp { + typedef TypeExp ThisType; + TypeExp() {} TypeExp(TypeExp const& other) : exp(other.exp) @@ -980,18 +982,8 @@ namespace Slang RefPtr<Expr> exp; RefPtr<Type> type; - bool Equals(Type* other); -#if 0 - { - return type->Equals(other); - } -#endif - bool Equals(RefPtr<Type> other); -#if 0 - { - return type->Equals(other.Ptr()); - } -#endif + bool equals(Type* other); + Type* Ptr() { return type.Ptr(); } operator Type*() { @@ -999,7 +991,9 @@ namespace Slang } Type* operator->() { return Ptr(); } - TypeExp Accept(SyntaxVisitor* visitor); + ThisType& operator=(const ThisType& rhs) = default; + + //TypeExp accept(SyntaxVisitor* visitor); /// A global immutable TypeExp, that has no type or exp set. static const TypeExp empty; diff --git a/source/slang/slang-ast-type.h b/source/slang/slang-ast-type.h index ccb3a3e0e..a1ed29b8a 100644 --- a/source/slang/slang-ast-type.h +++ b/source/slang/slang-ast-type.h @@ -18,8 +18,8 @@ public: protected: virtual bool equalsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual int GetHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; + virtual HashCode getHashCode() override; }; // The type of an initializer-list expression (before it has @@ -32,8 +32,8 @@ class InitializerListType : public Type protected: virtual bool equalsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual int GetHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; + virtual HashCode getHashCode() override; }; // The type of an expression that was erroneous @@ -47,8 +47,8 @@ public: protected: virtual bool equalsImpl(Type * type) override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int* ioDiff) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual int GetHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; + virtual HashCode getHashCode() override; }; // A type that takes the form of a reference to some declaration @@ -72,9 +72,9 @@ class DeclRefType : public Type : declRef(declRef) {} protected: - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; virtual bool equalsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; + virtual RefPtr<Type> createCanonicalType() override; }; // Base class for types that can be used in arithmetic expressions @@ -101,7 +101,7 @@ class BasicExpressionType : public ArithmeticExpressionType protected: virtual BasicExpressionType* GetScalarType() override; virtual bool equalsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; + virtual RefPtr<Type> createCanonicalType() override; }; @@ -397,9 +397,9 @@ class ArrayExpressionType : public Type protected: virtual bool equalsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; + virtual RefPtr<Type> createCanonicalType() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int* ioDiff) override; - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; }; // The "type" of an expression that resolves to a type. @@ -423,8 +423,8 @@ public: protected: virtual bool equalsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual int GetHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; + virtual HashCode getHashCode() override; }; // A vector type, e.g., `vector<T,N>` @@ -540,8 +540,8 @@ class NamedExpressionType : public Type protected: virtual bool equalsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual int GetHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; + virtual HashCode getHashCode() override; }; // A function type is defined by its parameter types @@ -570,8 +570,8 @@ class FuncType : public Type protected: virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int* ioDiff) override; virtual bool equalsImpl(Type * type) override; - virtual RefPtr<Type> CreateCanonicalType() override; - virtual int GetHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; + virtual HashCode getHashCode() override; }; // The "type" of an expression that names a generic declaration. @@ -594,8 +594,8 @@ class GenericDeclRefType : public Type protected: virtual bool equalsImpl(Type * type) override; - virtual int GetHashCode() override; - virtual RefPtr<Type> CreateCanonicalType() override; + virtual HashCode getHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; }; // The "type" of a reference to a module or namespace @@ -614,8 +614,8 @@ class NamespaceType : public Type protected: virtual bool equalsImpl(Type * type) override; - virtual int GetHashCode() override; - virtual RefPtr<Type> CreateCanonicalType() override; + virtual HashCode getHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; }; // The concrete type for a value wrapped in an existential, accessible @@ -628,8 +628,8 @@ class ExtractExistentialType : public Type virtual String toString() override; virtual bool equalsImpl(Type * type) override; - virtual int GetHashCode() override; - virtual RefPtr<Type> CreateCanonicalType() override; + virtual HashCode getHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int* ioDiff) override; }; @@ -647,8 +647,8 @@ class TaggedUnionType : public Type virtual String toString() override; virtual bool equalsImpl(Type * type) override; - virtual int GetHashCode() override; - virtual RefPtr<Type> CreateCanonicalType() override; + virtual HashCode getHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int* ioDiff) override; }; @@ -661,8 +661,8 @@ class ExistentialSpecializedType : public Type virtual String toString() override; virtual bool equalsImpl(Type * type) override; - virtual int GetHashCode() override; - virtual RefPtr<Type> CreateCanonicalType() override; + virtual HashCode getHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int* ioDiff) override; }; @@ -675,8 +675,8 @@ class ThisType : public Type virtual String toString() override; virtual bool equalsImpl(Type * type) override; - virtual int GetHashCode() override; - virtual RefPtr<Type> CreateCanonicalType() override; + virtual HashCode getHashCode() override; + virtual RefPtr<Type> createCanonicalType() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int* ioDiff) override; }; diff --git a/source/slang/slang-ast-val.h b/source/slang/slang-ast-val.h index dcfbb3833..a6425e060 100644 --- a/source/slang/slang-ast-val.h +++ b/source/slang/slang-ast-val.h @@ -29,7 +29,7 @@ class ConstantIntVal : public IntVal virtual bool equalsVal(Val* val) override; virtual String toString() override; - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; }; // The logical "value" of a rererence to a generic value parameter @@ -47,7 +47,7 @@ class GenericParamIntVal : public IntVal virtual bool equalsVal(Val* val) override; virtual String toString() override; - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int* ioDiff) override; }; @@ -65,7 +65,7 @@ class ErrorIntVal : public IntVal virtual bool equalsVal(Val* val) override; virtual String toString() override; - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int* ioDiff) override; }; @@ -127,7 +127,7 @@ class TypeEqualityWitness : public SubtypeWitness virtual bool equalsVal(Val* val) override; virtual String toString() override; - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int * ioDiff) override; }; @@ -141,7 +141,7 @@ class DeclaredSubtypeWitness : public SubtypeWitness virtual bool equalsVal(Val* val) override; virtual String toString() override; - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int * ioDiff) override; }; @@ -158,7 +158,7 @@ class TransitiveSubtypeWitness : public SubtypeWitness virtual bool equalsVal(Val* val) override; virtual String toString() override; - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int * ioDiff) override; }; @@ -173,7 +173,7 @@ class ExtractExistentialSubtypeWitness : public SubtypeWitness virtual bool equalsVal(Val* val) override; virtual String toString() override; - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int * ioDiff) override; }; @@ -192,7 +192,7 @@ class TaggedUnionSubtypeWitness : public SubtypeWitness virtual bool equalsVal(Val* val) override; virtual String toString() override; - virtual int GetHashCode() override; + virtual HashCode getHashCode() override; virtual RefPtr<Val> substituteImpl(SubstitutionSet subst, int * ioDiff) override; }; diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index e71ffc430..b69b3ad7d 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -803,7 +803,7 @@ namespace Slang TypeExp typeExp = CheckUsableType(varDecl->type); varDecl->type = typeExp; - if (varDecl->type.Equals(getSession()->getVoidType())) + if (varDecl->type.equals(getSession()->getVoidType())) { getSink()->diagnose(varDecl, Diagnostics::invalidTypeVoid); } diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index 8432322bb..fb55e5bef 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -72,9 +72,9 @@ namespace Slang bool isValid() const { return type1 != BasicTypeKey::Invalid && type2 != BasicTypeKey::Invalid; } - int GetHashCode() + HashCode getHashCode() { - return int(type1) << 16 | int(type2); + return HashCode(int(type1) << 16 | int(type2)); } }; @@ -86,9 +86,9 @@ namespace Slang { return operatorName == key.operatorName && args[0] == key.args[0] && args[1] == key.args[1]; } - int GetHashCode() + HashCode getHashCode() { - return ((int)(UInt64)(void*)(operatorName) << 16) ^ (int(args[0]) << 8) ^ (int(args[1])); + return HashCode(((int)(UInt64)(void*)(operatorName) << 16) ^ (int(args[0]) << 8) ^ (int(args[1]))); } bool fromOperatorExpr(OperatorExpr* opExpr) { diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 2d7c7635a..745597a76 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -664,7 +664,7 @@ namespace Slang { // HACK: if both items refer to the same declaration, // then arbitrarily pick one. - if(left.declRef.Equals(right.declRef)) + if(left.declRef.equals(right.declRef)) return -1; // There is a very general rule that we would like to enforce diff --git a/source/slang/slang-check-stmt.cpp b/source/slang/slang-check-stmt.cpp index 3de885a35..fa2eb59a0 100644 --- a/source/slang/slang-check-stmt.cpp +++ b/source/slang/slang-check-stmt.cpp @@ -250,7 +250,7 @@ namespace Slang auto function = getParentFunc(); if (!stmt->expression) { - if (function && !function->returnType.Equals(getSession()->getVoidType())) + if (function && !function->returnType.equals(getSession()->getVoidType())) { getSink()->diagnose(stmt, Diagnostics::returnNeedsExpression); } diff --git a/source/slang/slang-check-type.cpp b/source/slang/slang-check-type.cpp index 45443630b..e6c924be8 100644 --- a/source/slang/slang-check-type.cpp +++ b/source/slang/slang-check-type.cpp @@ -323,7 +323,7 @@ namespace Slang { if(auto rightVar = as<GenericParamIntVal>(right)) { - return leftVar->declRef.Equals(rightVar->declRef); + return leftVar->declRef.equals(rightVar->declRef); } } diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp index 275818614..5b2b2b132 100644 --- a/source/slang/slang-check.cpp +++ b/source/slang/slang-check.cpp @@ -234,7 +234,7 @@ namespace Slang { visitor.dispatch(stmt); } - catch(AbortCompilationException&) { throw; } + catch(const AbortCompilationException&) { throw; } catch(...) { getSink()->noteInternalErrorLoc(stmt->loc); @@ -249,7 +249,7 @@ namespace Slang { visitor.dispatch(expr); } - catch(AbortCompilationException&) { throw; } + catch(const AbortCompilationException&) { throw; } catch(...) { getSink()->noteInternalErrorLoc(expr->loc); diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 8a8017ef3..83f362ec7 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -2278,7 +2278,7 @@ SlangResult dissassembleDXILUsingDXC( { stream.write(m_containerBlob->getBufferPointer(), m_containerBlob->getBufferSize()); } - catch (IOException&) + catch (const IOException&) { // Unable to write return SLANG_FAIL; diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 9da7008b6..811036dc0 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -2259,7 +2259,7 @@ void CLikeSourceEmitter::emitInst(IRInst* inst) } // Don't emit any context message for an explicit `AbortCompilationException` // because it should only happen when an error is already emitted. - catch(AbortCompilationException&) { throw; } + catch(const AbortCompilationException&) { throw; } catch(...) { noteInternalErrorLoc(inst->sourceLoc); diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 00ce929d9..ef7e557f6 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -1358,7 +1358,8 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu case kIROp_StringLit: { IRStringLit* lit = cast<IRStringLit>(inst); - m_writer->emit(GetHashCode(lit->getStringSlice())); + const UnownedStringSlice slice = lit->getStringSlice(); + m_writer->emit(int32_t(getStableHashCode32(slice.begin(), slice.getLength()))); return true; } case kIROp_GetStringHash: diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index e48a166c5..338e99e68 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -520,7 +520,8 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu case kIROp_StringLit: { IRStringLit* lit = cast<IRStringLit>(inst); - m_writer->emit(GetHashCode(lit->getStringSlice())); + UnownedStringSlice slice = lit->getStringSlice(); + m_writer->emit(int32_t(getStableHashCode32(slice.begin(), slice.getLength()))); return true; } case kIROp_GetStringHash: diff --git a/source/slang/slang-file-system.cpp b/source/slang/slang-file-system.cpp index 29db71459..ebe1eeb61 100644 --- a/source/slang/slang-file-system.cpp +++ b/source/slang/slang-file-system.cpp @@ -144,7 +144,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL OSFileSystemExt::saveFile(const char* pat } } - catch (IOException&) + catch (const IOException&) { return SLANG_E_CANNOT_OPEN; } @@ -332,7 +332,7 @@ SlangResult CacheFileSystem::_calcUniqueIdentity(const String& path, String& out } // Calculate the hash on the contents - const uint64_t hash = GetHashCode64((const char*)outFileContents->getBufferPointer(), outFileContents->getBufferSize()); + const uint64_t hash = getHashCode64((const char*)outFileContents->getBufferPointer(), outFileContents->getBufferSize()); String hashString = Path::getFileName(path); hashString = hashString.toLower(); diff --git a/source/slang/slang-hlsl-intrinsic-set.h b/source/slang/slang-hlsl-intrinsic-set.h index ca3fced50..c19ab3a7c 100644 --- a/source/slang/slang-hlsl-intrinsic-set.h +++ b/source/slang/slang-hlsl-intrinsic-set.h @@ -119,7 +119,7 @@ struct HLSLIntrinsic return isTypeScalar(returnType); } - int GetHashCode() const { return combineHash(int(op), combineHash(Slang::GetHashCode(returnType), Slang::GetHashCode(signatureType))); } + HashCode getHashCode() const { return combineHash(int(op), combineHash(Slang::getHashCode(returnType), Slang::getHashCode(signatureType))); } static const Info& getInfo(Op op) { return s_operationInfos[Index(op)]; } static const Info s_operationInfos[]; @@ -134,7 +134,7 @@ struct HLSLIntrinsicRef { typedef HLSLIntrinsicRef ThisType; - int GetHashCode() const { return m_intrinsic->GetHashCode(); } + HashCode getHashCode() const { return m_intrinsic->getHashCode(); } bool operator==(const ThisType& rhs) const { return m_intrinsic == rhs.m_intrinsic || (*m_intrinsic == *rhs.m_intrinsic); } bool operator!=(const ThisType& rhs) const { return !(*this == rhs); } diff --git a/source/slang/slang-ir-clone.cpp b/source/slang/slang-ir-clone.cpp index 9f9349f99..8155a4d34 100644 --- a/source/slang/slang-ir-clone.cpp +++ b/source/slang/slang-ir-clone.cpp @@ -299,13 +299,13 @@ bool IRSimpleSpecializationKey::operator==(IRSimpleSpecializationKey const& othe return true; } -int IRSimpleSpecializationKey::GetHashCode() const +HashCode IRSimpleSpecializationKey::getHashCode() const { auto valCount = vals.getCount(); - int hash = Slang::GetHashCode(valCount); + HashCode hash = Slang::getHashCode(valCount); for( Index ii = 0; ii < valCount; ++ii ) { - hash = combineHash(hash, Slang::GetHashCode(vals[ii])); + hash = combineHash(hash, Slang::getHashCode(vals[ii])); } return hash; } diff --git a/source/slang/slang-ir-clone.h b/source/slang/slang-ir-clone.h index d2d3b1f55..b483b5fcb 100644 --- a/source/slang/slang-ir-clone.h +++ b/source/slang/slang-ir-clone.h @@ -173,11 +173,11 @@ struct IRSimpleSpecializationKey // In order to use this type as a `Dictionary` key we // need it to support equality and hashing. // - // TODO: honestly we might consider having `GetHashCode` + // TODO: honestly we might consider having `getHashCode` // and `operator==` defined for `List<T>`. bool operator==(IRSimpleSpecializationKey const& other) const; - int GetHashCode() const; + HashCode getHashCode() const; }; } diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index 957a53a0e..881d7a93b 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -1479,7 +1479,7 @@ struct IRInstKey { IRInst* inst; - int GetHashCode(); + HashCode getHashCode(); }; bool operator==(IRInstKey const& left, IRInstKey const& right); @@ -1489,7 +1489,7 @@ struct IRConstantKey IRConstant* inst; bool operator==(const IRConstantKey& rhs) const { return inst->equal(rhs.inst); } - int GetHashCode() const { return inst->getHashCode(); } + HashCode getHashCode() const { return inst->getHashCode(); } }; struct SharedIRBuilder diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 9fb966eba..0a52561c0 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -1651,17 +1651,17 @@ namespace Slang return true; } - int IRInstKey::GetHashCode() + HashCode IRInstKey::getHashCode() { - auto code = Slang::GetHashCode(inst->op); - code = combineHash(code, Slang::GetHashCode(inst->getFullType())); - code = combineHash(code, Slang::GetHashCode(inst->getOperandCount())); + auto code = Slang::getHashCode(inst->op); + code = combineHash(code, Slang::getHashCode(inst->getFullType())); + code = combineHash(code, Slang::getHashCode(inst->getOperandCount())); auto argCount = inst->getOperandCount(); auto args = inst->getOperands(); for( UInt aa = 0; aa < argCount; ++aa ) { - code = combineHash(code, Slang::GetHashCode(args[aa].get())); + code = combineHash(code, Slang::getHashCode(args[aa].get())); } return code; } @@ -1760,10 +1760,10 @@ namespace Slang return isValueEqual(rhs) && getFullType() == rhs->getFullType(); } - int IRConstant::getHashCode() + HashCode IRConstant::getHashCode() { - auto code = Slang::GetHashCode(op); - code = combineHash(code, Slang::GetHashCode(getFullType())); + auto code = Slang::getHashCode(op); + code = combineHash(code, Slang::getHashCode(getFullType())); switch (op) { @@ -1773,16 +1773,16 @@ namespace Slang { SLANG_COMPILE_TIME_ASSERT(sizeof(IRFloatingPointValue) == sizeof(IRIntegerValue)); // ... we can just compare as bits - return combineHash(code, Slang::GetHashCode(value.intVal)); + return combineHash(code, Slang::getHashCode(value.intVal)); } case kIROp_PtrLit: { - return combineHash(code, Slang::GetHashCode(value.ptrVal)); + return combineHash(code, Slang::getHashCode(value.ptrVal)); } case kIROp_StringLit: { const UnownedStringSlice slice = getStringSlice(); - return combineHash(code, Slang::GetHashCode(slice.begin(), slice.getLength())); + return combineHash(code, Slang::getHashCode(slice.begin(), slice.getLength())); } default: { @@ -4537,7 +4537,7 @@ namespace Slang { // TODO: This is contrived in that we want two types that are the same, but are different // pointers to match here. - // If we make GetHashCode for IRType* compatible with isTypeEqual, then we should probably use that. + // If we make getHashCode for IRType* compatible with isTypeEqual, then we should probably use that. return static_cast<IRConstant*>(a)->isValueEqual(static_cast<IRConstant*>(b)) && isTypeEqual(a->getFullType(), b->getFullType()); } diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h index f070f29c0..fbe05e8e8 100644 --- a/source/slang/slang-ir.h +++ b/source/slang/slang-ir.h @@ -689,7 +689,7 @@ struct IRConstant : IRInst bool isValueEqual(IRConstant* rhs); /// Get the hash - int getHashCode(); + HashCode getHashCode(); IR_PARENT_ISA(Constant) diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index 70e6a23ce..1a1d2e621 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -439,7 +439,7 @@ static void _lookUpMembersInSuperTypeDeclImpl( auto subDeclRefType = as<DeclRefType>(subType); if(!subDeclRefType) continue; - if(!subDeclRefType->declRef.Equals(genericTypeParamDeclRef)) + if(!subDeclRefType->declRef.equals(genericTypeParamDeclRef)) continue; _lookUpMembersInSuperType( diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 4c33ab172..5b4694d36 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -3854,7 +3854,7 @@ void lowerStmt( } // Don't emit any context message for an explicit `AbortCompilationException` // because it should only happen when an error is already emitted. - catch(AbortCompilationException&) { throw; } + catch(const AbortCompilationException&) { throw; } catch(...) { context->getSink()->noteInternalErrorLoc(stmt->loc); @@ -6332,7 +6332,7 @@ LoweredValInfo lowerDecl( } // Don't emit any context message for an explicit `AbortCompilationException` // because it should only happen when an error is already emitted. - catch(AbortCompilationException&) { throw; } + catch(const AbortCompilationException&) { throw; } catch(...) { context->getSink()->noteInternalErrorLoc(decl->loc); diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp index 0d12e2f69..0ecc12b45 100644 --- a/source/slang/slang-mangle.cpp +++ b/source/slang/slang-mangle.cpp @@ -489,11 +489,11 @@ namespace Slang String getHashedName(const UnownedStringSlice& mangledName) { - uint64_t hash = GetHashCode64(mangledName.begin(), mangledName.getLength()); + HashCode64 hash = getStableHashCode64(mangledName.begin(), mangledName.getLength()); StringBuilder builder; builder << "_Sh"; - builder.append(hash, 16); + builder.append(uint64_t(hash), 16); return builder; } diff --git a/source/slang/slang-reflection.cpp b/source/slang/slang-reflection.cpp index 72a20e932..1316efa5d 100644 --- a/source/slang/slang-reflection.cpp +++ b/source/slang/slang-reflection.cpp @@ -1571,6 +1571,5 @@ SLANG_API const char* spReflection_getHashedString( SLANG_API int spComputeStringHash(const char* chars, size_t count) { - UnownedStringSlice slice(chars, count); - return GetHashCode(slice); + return (int)getStableHashCode32(chars, count); } diff --git a/source/slang/slang-source-loc.h b/source/slang/slang-source-loc.h index db2dcc394..51d826108 100644 --- a/source/slang/slang-source-loc.h +++ b/source/slang/slang-source-loc.h @@ -79,6 +79,7 @@ struct PathInfo class SourceLoc { public: + typedef SourceLoc ThisType; typedef uint32_t RawValue; private: @@ -108,6 +109,7 @@ public: { return raw != 0; } + SourceLoc& operator=(const ThisType& rhs) = default; }; inline SourceLoc operator+(SourceLoc loc, Int offset) 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&) { } diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp index de3b4e2d7..70b8a4239 100644 --- a/source/slang/slang-syntax.cpp +++ b/source/slang/slang-syntax.cpp @@ -59,7 +59,7 @@ bool BasicExpressionType::equalsImpl(Type * type) return basicType && basicType->baseType == this->baseType; } -RefPtr<Type> BasicExpressionType::CreateCanonicalType() +RefPtr<Type> BasicExpressionType::createCanonicalType() { // A basic type is already canonical, in our setup return this; @@ -208,16 +208,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // TypeExp - bool TypeExp::Equals(Type* other) + bool TypeExp::equals(Type* other) { return type->equals(other); } - bool TypeExp::Equals(RefPtr<Type> other) - { - return type->equals(other.Ptr()); - } - // BasicExpressionType BasicExpressionType* BasicExpressionType::GetScalarType() @@ -270,7 +265,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if (!et->canonicalType) { // TODO(tfoley): worry about thread safety here? - auto canType = et->CreateCanonicalType(); + auto canType = et->createCanonicalType(); et->canonicalType = canType; // TODO(js): That this detachs when canType == this is a little surprising. It would seem @@ -471,7 +466,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return this; } - RefPtr<Type> ArrayExpressionType::CreateCanonicalType() + RefPtr<Type> ArrayExpressionType::createCanonicalType() { auto canonicalElementType = baseType->getCanonicalType(); auto canonicalArrayType = getArrayType( @@ -479,12 +474,12 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt arrayLength); return canonicalArrayType; } - int ArrayExpressionType::GetHashCode() + HashCode ArrayExpressionType::getHashCode() { if (arrayLength) - return (baseType->GetHashCode() * 16777619) ^ arrayLength->GetHashCode(); + return (baseType->getHashCode() * 16777619) ^ arrayLength->getHashCode(); else - return baseType->GetHashCode(); + return baseType->getHashCode(); } Slang::String ArrayExpressionType::toString() { @@ -501,21 +496,21 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return declRef.toString(); } - int DeclRefType::GetHashCode() + HashCode DeclRefType::getHashCode() { - return (declRef.GetHashCode() * 16777619) ^ (int)(typeid(this).hash_code()); + return (declRef.getHashCode() * 16777619) ^ (HashCode)(typeid(this).hash_code()); } bool DeclRefType::equalsImpl(Type * type) { if (auto declRefType = as<DeclRefType>(type)) { - return declRef.Equals(declRefType->declRef); + return declRef.equals(declRefType->declRef); } return false; } - RefPtr<Type> DeclRefType::CreateCanonicalType() + RefPtr<Type> DeclRefType::createCanonicalType() { // A declaration reference is already canonical return this; @@ -1038,14 +1033,14 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return false; } - RefPtr<Type> OverloadGroupType::CreateCanonicalType() + RefPtr<Type> OverloadGroupType::createCanonicalType() { return this; } - int OverloadGroupType::GetHashCode() + HashCode OverloadGroupType::getHashCode() { - return (int)(int64_t)(void*)this; + return (HashCode)(size_t(this)); } // InitializerListType @@ -1060,14 +1055,14 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return false; } - RefPtr<Type> InitializerListType::CreateCanonicalType() + RefPtr<Type> InitializerListType::createCanonicalType() { return this; } - int InitializerListType::GetHashCode() + HashCode InitializerListType::getHashCode() { - return (int)(int64_t)(void*)this; + return (HashCode)(size_t(this)); } // ErrorType @@ -1084,7 +1079,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return false; } - RefPtr<Type> ErrorType::CreateCanonicalType() + RefPtr<Type> ErrorType::createCanonicalType() { return this; } @@ -1094,9 +1089,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return this; } - int ErrorType::GetHashCode() + HashCode ErrorType::getHashCode() { - return (int)(int64_t)(void*)this; + return HashCode(size_t(this)); } @@ -1113,25 +1108,25 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt UNREACHABLE_RETURN(false); } - RefPtr<Type> NamedExpressionType::CreateCanonicalType() + RefPtr<Type> NamedExpressionType::createCanonicalType() { if (!innerType) innerType = GetType(declRef); return innerType->getCanonicalType(); } - int NamedExpressionType::GetHashCode() + HashCode NamedExpressionType::getHashCode() { // Type equality is based on comparing canonical types, // so the hash code for a type needs to come from the // canonical version of the type. This really means - // that `Type::GetHashCode()` should dispatch out to - // something like `Type::GetHashCodeImpl()` on the + // that `Type::getHashCode()` should dispatch out to + // something like `Type::getHashCodeImpl()` on the // canonical version of a type, but it is less invasive // for now (and hopefully equivalent) to just have any // named types automaticlaly route hash-code requests // to their canonical type. - return getCanonicalType()->GetHashCode(); + return getCanonicalType()->getHashCode(); } // FuncType @@ -1205,7 +1200,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return substType; } - RefPtr<Type> FuncType::CreateCanonicalType() + RefPtr<Type> FuncType::createCanonicalType() { // result type RefPtr<Type> canResultType = resultType->getCanonicalType(); @@ -1225,16 +1220,16 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return canType; } - int FuncType::GetHashCode() + HashCode FuncType::getHashCode() { - int hashCode = getResultType()->GetHashCode(); + HashCode hashCode = getResultType()->getHashCode(); UInt paramCount = getParamCount(); - hashCode = combineHash(hashCode, Slang::GetHashCode(paramCount)); + hashCode = combineHash(hashCode, Slang::getHashCode(paramCount)); for (UInt pp = 0; pp < paramCount; ++pp) { hashCode = combineHash( hashCode, - getParamType(pp)->GetHashCode()); + getParamType(pp)->getHashCode()); } return hashCode; } @@ -1257,13 +1252,13 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return false; } - RefPtr<Type> TypeType::CreateCanonicalType() + RefPtr<Type> TypeType::createCanonicalType() { auto canType = getTypeType(type->getCanonicalType()); return canType; } - int TypeType::GetHashCode() + HashCode TypeType::getHashCode() { SLANG_UNEXPECTED("unreachable"); UNREACHABLE_RETURN(0); @@ -1281,17 +1276,17 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt { if (auto genericDeclRefType = as<GenericDeclRefType>(type)) { - return declRef.Equals(genericDeclRefType->declRef); + return declRef.equals(genericDeclRefType->declRef); } return false; } - int GenericDeclRefType::GetHashCode() + HashCode GenericDeclRefType::getHashCode() { - return declRef.GetHashCode(); + return declRef.getHashCode(); } - RefPtr<Type> GenericDeclRefType::CreateCanonicalType() + RefPtr<Type> GenericDeclRefType::createCanonicalType() { return this; } @@ -1310,17 +1305,17 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt { if (auto namespaceType = as<NamespaceType>(type)) { - return declRef.Equals(namespaceType->declRef); + return declRef.equals(namespaceType->declRef); } return false; } - int NamespaceType::GetHashCode() + HashCode NamespaceType::getHashCode() { - return declRef.GetHashCode(); + return declRef.getHashCode(); } - RefPtr<Type> NamespaceType::CreateCanonicalType() + RefPtr<Type> NamespaceType::createCanonicalType() { return this; } @@ -1425,7 +1420,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt { if (auto genericParamVal = as<GenericParamIntVal>(val)) { - return declRef.Equals(genericParamVal->declRef); + return declRef.equals(genericParamVal->declRef); } return false; } @@ -1435,9 +1430,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return getText(declRef.GetName()); } - int GenericParamIntVal::GetHashCode() + HashCode GenericParamIntVal::getHashCode() { - return declRef.GetHashCode() ^ 0xFFFF; + return declRef.getHashCode() ^ HashCode(0xFFFF); } RefPtr<Val> GenericParamIntVal::substituteImpl(SubstitutionSet subst, int* ioDiff) @@ -1498,9 +1493,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return "<error>"; } - int ErrorIntVal::GetHashCode() + HashCode ErrorIntVal::getHashCode() { - return int(typeid(this).hash_code()); + return HashCode(typeid(this).hash_code()); } RefPtr<Val> ErrorIntVal::substituteImpl(SubstitutionSet subst, int* ioDiff) @@ -1609,9 +1604,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return false; } - int ThisTypeSubstitution::GetHashCode() const + HashCode ThisTypeSubstitution::getHashCode() const { - return witness->GetHashCode(); + return witness->getHashCode(); } RefPtr<Substitutions> GlobalGenericParamSubstitution::applySubstitutionsShallow(SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff) @@ -2064,11 +2059,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // Check if this is an equivalent declaration reference to another - bool DeclRefBase::Equals(DeclRefBase const& declRef) const + bool DeclRefBase::equals(DeclRefBase const& declRef) const { if (decl != declRef.decl) return false; - if (!substitutions.Equals(declRef.substitutions)) + if (!substitutions.equals(declRef.substitutions)) return false; return true; @@ -2136,9 +2131,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return DeclRefBase(parentDecl, substToApply); } - int DeclRefBase::GetHashCode() const + HashCode DeclRefBase::getHashCode() const { - return combineHash(PointerHash<1>::GetHashCode(decl), substitutions.GetHashCode()); + return combineHash(PointerHash<1>::getHashCode(decl), substitutions.getHashCode()); } // Val @@ -2182,9 +2177,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return String(value); } - int ConstantIntVal::GetHashCode() + HashCode ConstantIntVal::getHashCode() { - return (int) value; + return (HashCode) value; } // @@ -2387,9 +2382,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return "TypeEqualityWitness(" + sub->toString() + ")"; } - int TypeEqualityWitness::GetHashCode() + HashCode TypeEqualityWitness::getHashCode() { - return sub->GetHashCode(); + return sub->getHashCode(); } bool DeclaredSubtypeWitness::equalsVal(Val* val) @@ -2400,7 +2395,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return sub->equals(otherWitness->sub) && sup->equals(otherWitness->sup) - && declRef.Equals(otherWitness->declRef); + && declRef.equals(otherWitness->declRef); } RefPtr<ThisTypeSubstitution> findThisTypeSubstitution( @@ -2554,9 +2549,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return sb.ProduceString(); } - int DeclaredSubtypeWitness::GetHashCode() + HashCode DeclaredSubtypeWitness::getHashCode() { - return declRef.GetHashCode(); + return declRef.getHashCode(); } // TransitiveSubtypeWitness @@ -2570,7 +2565,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return sub->equals(otherWitness->sub) && sup->equals(otherWitness->sup) && subToMid->equalsVal(otherWitness->subToMid) - && midToSup.Equals(otherWitness->midToSup); + && midToSup.equals(otherWitness->midToSup); } RefPtr<Val> TransitiveSubtypeWitness::substituteImpl(SubstitutionSet subst, int * ioDiff) @@ -2628,12 +2623,12 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return sb.ProduceString(); } - int TransitiveSubtypeWitness::GetHashCode() + HashCode TransitiveSubtypeWitness::getHashCode() { - auto hash = sub->GetHashCode(); - hash = combineHash(hash, sup->GetHashCode()); - hash = combineHash(hash, subToMid->GetHashCode()); - hash = combineHash(hash, midToSup.GetHashCode()); + auto hash = sub->getHashCode(); + hash = combineHash(hash, sup->getHashCode()); + hash = combineHash(hash, subToMid->getHashCode()); + hash = combineHash(hash, midToSup.getHashCode()); return hash; } @@ -2650,7 +2645,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return name->text; } - bool SubstitutionSet::Equals(const SubstitutionSet& substSet) const + bool SubstitutionSet::equals(const SubstitutionSet& substSet) const { if (substitutions == substSet.substitutions) { @@ -2663,11 +2658,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return substitutions->equals(substSet.substitutions); } - int SubstitutionSet::GetHashCode() const + HashCode SubstitutionSet::getHashCode() const { - int rs = 0; + HashCode rs = 0; if (substitutions) - rs = combineHash(rs, substitutions->GetHashCode()); + rs = combineHash(rs, substitutions->getHashCode()); return rs; } @@ -2685,17 +2680,17 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt { if( auto extractExistential = as<ExtractExistentialType>(type) ) { - return declRef.Equals(extractExistential->declRef); + return declRef.equals(extractExistential->declRef); } return false; } - int ExtractExistentialType::GetHashCode() + HashCode ExtractExistentialType::getHashCode() { - return declRef.GetHashCode(); + return declRef.getHashCode(); } - RefPtr<Type> ExtractExistentialType::CreateCanonicalType() + RefPtr<Type> ExtractExistentialType::createCanonicalType() { return this; } @@ -2720,7 +2715,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt { if( auto extractWitness = as<ExtractExistentialSubtypeWitness>(val) ) { - return declRef.Equals(extractWitness->declRef); + return declRef.equals(extractWitness->declRef); } return false; } @@ -2734,9 +2729,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return result; } - int ExtractExistentialSubtypeWitness::GetHashCode() + HashCode ExtractExistentialSubtypeWitness::getHashCode() { - return declRef.GetHashCode(); + return declRef.getHashCode(); } RefPtr<Val> ExtractExistentialSubtypeWitness::substituteImpl(SubstitutionSet subst, int* ioDiff) @@ -2797,17 +2792,17 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return true; } - int TaggedUnionType::GetHashCode() + HashCode TaggedUnionType::getHashCode() { - int hashCode = 0; + HashCode hashCode = 0; for( auto caseType : caseTypes ) { - hashCode = combineHash(hashCode, caseType->GetHashCode()); + hashCode = combineHash(hashCode, caseType->getHashCode()); } return hashCode; } - RefPtr<Type> TaggedUnionType::CreateCanonicalType() + RefPtr<Type> TaggedUnionType::createCanonicalType() { RefPtr<TaggedUnionType> canType = new TaggedUnionType(); canType->setSession(getSession()); @@ -2880,12 +2875,12 @@ String TaggedUnionSubtypeWitness::toString() return result; } -int TaggedUnionSubtypeWitness::GetHashCode() +HashCode TaggedUnionSubtypeWitness::getHashCode() { - int hash = 0; + HashCode hash = 0; for( auto caseWitness : caseWitnesses ) { - hash = combineHash(hash, caseWitness->GetHashCode()); + hash = combineHash(hash, caseWitness->getHashCode()); } return hash; } @@ -3004,7 +2999,7 @@ bool ExistentialSpecializedType::equalsImpl(Type * type) return true; } -int ExistentialSpecializedType::GetHashCode() +HashCode ExistentialSpecializedType::getHashCode() { Hasher hasher; hasher.hashObject(baseType); @@ -3030,7 +3025,7 @@ RefPtr<Val> getCanonicalValue(Val* val) return val; } -RefPtr<Type> ExistentialSpecializedType::CreateCanonicalType() +RefPtr<Type> ExistentialSpecializedType::createCanonicalType() { RefPtr<ExistentialSpecializedType> canType = new ExistentialSpecializedType(); canType->setSession(getSession()); @@ -3097,20 +3092,20 @@ bool ThisType::equalsImpl(Type * type) if(!other) return false; - if(!interfaceDeclRef.Equals(other->interfaceDeclRef)) + if(!interfaceDeclRef.equals(other->interfaceDeclRef)) return false; return true; } -int ThisType::GetHashCode() +HashCode ThisType::getHashCode() { return combineHash( HashCode(typeid(*this).hash_code()), - interfaceDeclRef.GetHashCode()); + interfaceDeclRef.getHashCode()); } -RefPtr<Type> ThisType::CreateCanonicalType() +RefPtr<Type> ThisType::createCanonicalType() { RefPtr<ThisType> canType = new ThisType(); canType->setSession(getSession()); diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 82bc5e478..2c698eeaf 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -3255,13 +3255,13 @@ SLANG_API SlangResult spCompile( { res = req->executeActions(); } - catch (AbortCompilationException&) + catch (const AbortCompilationException&) { // This situation indicates a fatal (but not necessarily internal) error // that forced compilation to terminate. There should already have been // a diagnostic produced, so we don't need to add one here. } - catch (Exception& e) + catch (const Exception& e) { // The compiler failed due to an internal error that was detected. // We will print out information on the exception to help out the user diff --git a/source/slangc/main.cpp b/source/slangc/main.cpp index da9a21b7a..3074f3540 100644 --- a/source/slangc/main.cpp +++ b/source/slangc/main.cpp @@ -64,7 +64,7 @@ SLANG_TEST_TOOL_API SlangResult innerMain(StdWriters* stdWriters, SlangSession* res = SLANG_FAILED(res) ? SLANG_E_INTERNAL_FAIL : res; } #ifndef _DEBUG - catch (Exception & e) + catch (const Exception& e) { StdWriters::getOut().print("internal compiler error: %S\n", e.Message.toWString().begin()); res = SLANG_FAIL; |
