1// Copyright 2019 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5@abstract 6@generateCppClass 7extern class Name extends PrimitiveHeapObject { 8 hash_field: NameHash; 9} 10 11bitfield struct NameHash extends uint32 { 12 hash_not_computed: bool: 1 bit; 13 is_not_integer_index_mask: bool: 1 bit; 14 array_index_value: uint32: 24 bit; 15 array_index_length: uint32: 6 bit; 16} 17 18// This is the same as Name, but with the information that there are no other 19// kinds of names. 20type AnyName = PrivateSymbol|PublicSymbol|String; 21 22bitfield struct SymbolFlags extends uint32 { 23 is_private: bool: 1 bit; 24 is_well_known_symbol: bool: 1 bit; 25 is_in_public_symbol_table: bool: 1 bit; 26 is_interesting_symbol: bool: 1 bit; 27 is_private_name: bool: 1 bit; 28 is_private_brand: bool: 1 bit; 29} 30 31@generateCppClass 32extern class Symbol extends Name { 33 flags: SymbolFlags; 34 description: String|Undefined; 35} 36 37type PublicSymbol extends Symbol; 38type PrivateSymbol extends Symbol; 39 40const kNameEmptyHashField: NameHash = NameHash{ 41 hash_not_computed: true, 42 is_not_integer_index_mask: true, 43 array_index_value: 0, 44 array_index_length: 0 45}; 46 47const kMaxCachedArrayIndexLength: constexpr uint32 48 generates 'Name::kMaxCachedArrayIndexLength'; 49const kMaxArrayIndexSize: constexpr uint32 50 generates 'Name::kMaxArrayIndexSize'; 51const kNofHashBitFields: constexpr int31 52 generates 'Name::kNofHashBitFields'; 53const kArrayIndexValueBits: constexpr int31 54 generates 'Name::kArrayIndexValueBits'; 55const kDoesNotContainCachedArrayIndexMask: constexpr uint32 56 generates 'Name::kDoesNotContainCachedArrayIndexMask'; 57const kIsNotIntegerIndexMask: constexpr uint32 58 generates 'Name::kIsNotIntegerIndexMask'; 59 60macro ContainsCachedArrayIndex(hash: uint32): bool { 61 return (hash & kDoesNotContainCachedArrayIndexMask) == 0; 62} 63 64const kArrayIndexValueBitsShift: uint32 = kNofHashBitFields; 65const kArrayIndexLengthBitsShift: uint32 = 66 kNofHashBitFields + kArrayIndexValueBits; 67 68macro TenToThe(exponent: uint32): uint32 { 69 assert(exponent <= 9); 70 let answer: int32 = 1; 71 for (let i: int32 = 0; i < Signed(exponent); i++) { 72 answer = answer * 10; 73 } 74 return Unsigned(answer); 75} 76 77macro MakeArrayIndexHash(value: uint32, length: uint32): NameHash { 78 // This is in sync with StringHasher::MakeArrayIndexHash. 79 assert(length <= kMaxArrayIndexSize); 80 const one: uint32 = 1; 81 assert(TenToThe(kMaxCachedArrayIndexLength) < (one << kArrayIndexValueBits)); 82 let hash: uint32 = value; 83 hash = (hash << kArrayIndexValueBitsShift) | 84 (length << kArrayIndexLengthBitsShift); 85 assert((hash & kIsNotIntegerIndexMask) == 0); 86 assert( 87 (length <= kMaxCachedArrayIndexLength) == ContainsCachedArrayIndex(hash)); 88 return %RawDownCast<NameHash>(hash); 89} 90