/* * Copyright (C) 2026 Oven, Inc. All rights reserved. * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #if ENABLE(AOT) #include #include #include // Compacting a function gives its values other numbers, and whoever has kept a number from before names another value with it, or none. // With assertions on, the number of a value carries how often its function had been renumbered when the function handed it out, and the function asks for that where it is handed back. #define AOT_STAMPS_VALUE_IDS ASSERT_ENABLED namespace JSC { namespace AOT { namespace Typed { struct ValueIDTag; template class ID { public: static constexpr uint32_t hashTableDeletedIndex = UINT32_MAX - 1; static constexpr bool safeToCompareToHashTableEmptyOrDeletedValue = true; static constexpr bool carriesStamp = AOT_STAMPS_VALUE_IDS && std::is_same_v; static constexpr unsigned bitsOfIndex = carriesStamp ? 26 : 32; static constexpr uint32_t largestIndex = carriesStamp ? (1u << 26) - 1 : hashTableDeletedIndex - 1; // No stamp: the number was made from an integer, and nobody asks where it is from. The stamp of all ones is left to the two values that are no numbers. static constexpr unsigned numberOfStamps = 62; constexpr ID() = default; constexpr ID(std::nullptr_t) { } ID(int) = delete; constexpr explicit ID(uint32_t value) : m_value(value) { RELEASE_ASSERT_UNDER_CONSTEXPR_CONTEXT(value <= largestIndex || value >= hashTableDeletedIndex); } constexpr explicit ID(size_t value) : m_value(static_cast(value)) { RELEASE_ASSERT_UNDER_CONSTEXPR_CONTEXT(value <= largestIndex); } static constexpr ID withStamp(size_t index, unsigned stamp) { ID id(index); if constexpr (carriesStamp) id.m_value |= stamp << bitsOfIndex; return id; } // For whoever keeps numbers in words of its own. static constexpr ID fromBits(uint32_t bits) { ID id; id.m_value = bits; return id; } constexpr uint32_t bits() const { return m_value; } constexpr explicit operator bool() const { return m_value != UINT32_MAX; } constexpr uint32_t index() const { if constexpr (carriesStamp) return m_value >= hashTableDeletedIndex ? m_value : m_value & largestIndex; return m_value; } constexpr unsigned stamp() const { if constexpr (carriesStamp) return m_value >= hashTableDeletedIndex ? 0 : m_value >> bitsOfIndex; return 0; } unsigned hash() const { return intHash(index()); } friend constexpr bool operator==(ID a, ID b) { return a.index() == b.index(); } friend constexpr auto operator<=>(ID a, ID b) { return a.index() <=> b.index(); } private: uint32_t m_value { UINT32_MAX }; }; template inline void add(Hasher& hasher, ID id) { add(hasher, id.index()); } using ValueID = ID; using BlockID = ID; class RootThroughCasts { public: RootThroughCasts() = default; explicit RootThroughCasts(ValueID root) : m_root(root) { } explicit operator bool() const { return !!m_root; } friend bool operator==(RootThroughCasts, RootThroughCasts) = default; friend bool operator==(RootThroughCasts root, ValueID value) { return root.m_root == value; } ValueID valueInFrontOfFacts() const { return m_root; } private: ValueID m_root; }; using StringID = ID; using PropertyKeyID = ID; using FunctionID = ID; using LayoutID = ID; using VariableID = ID; using ModuleID = ID; using ModuleFailureID = ID; using TypeID = ID; using TypeSiteID = ID; using EvalScopeID = ID; using DataID = ID; using ExpectedResultID = ID; using LayoutSetID = ID; using CalleeSetID = ID; using AccessSiteID = ID; using AllocationSiteID = ID; using AllocationClassID = ID; using FieldAccessID = ID; using AllocationID = ID; using RegExpRecordID = ID; using SiteCacheID = ID; using GlobalBindingID = ID; using GuardBitID = ID; } } } // namespace JSC::AOT::Typed namespace WTF { template struct HashTraits> : GenericHashTraits> { using ID = JSC::AOT::Typed::ID; static void constructDeletedValue(ID& slot) { slot = ID(ID::hashTableDeletedIndex); } static bool isDeletedValue(ID id) { return id.index() == ID::hashTableDeletedIndex; } }; } // namespace WTF #endif // ENABLE(AOT)