Skip to content

Commit d508afb

Browse files
authored
Make NodeId and SymbolId into uint64s, fix up KeyBuilder (#243)
1 parent ec11a7f commit d508afb

File tree

6 files changed

+32
-16
lines changed

6 files changed

+32
-16
lines changed

internal/ast/ast.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ type Node struct {
175175
Kind Kind
176176
Flags NodeFlags
177177
Loc core.TextRange
178-
id atomic.Uint32
178+
id atomic.Uint64
179179
Parent *Node
180180
data nodeData
181181
}

internal/ast/ids.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ast
22

33
type (
4-
NodeId uint32
5-
SymbolId uint32
4+
NodeId uint64
5+
SymbolId uint64
66
)

internal/ast/symbol.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Symbol struct {
1616
ValueDeclaration *Node
1717
Members SymbolTable
1818
Exports SymbolTable
19-
id atomic.Uint32
19+
id atomic.Uint64
2020
Parent *Symbol
2121
ExportSymbol *Symbol
2222
AssignmentDeclarationMembers core.Set[*Node] // Set of detected assignment declarations

internal/ast/utilities.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
// Atomic ids
1414

1515
var (
16-
nextNodeId atomic.Uint32
17-
nextSymbolId atomic.Uint32
16+
nextNodeId atomic.Uint64
17+
nextSymbolId atomic.Uint64
1818
)
1919

2020
func GetNodeId(node *Node) NodeId {

internal/checker/checker.go

+24-8
Original file line numberDiff line numberDiff line change
@@ -15765,19 +15765,31 @@ var base64chars = []byte{
1576515765
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '$', '%',
1576615766
}
1576715767

15768-
func (b *KeyBuilder) WriteInt(value int) {
15768+
func (b *KeyBuilder) WriteUint64(value uint64) {
1576915769
for value != 0 {
1577015770
b.WriteByte(base64chars[value&0x3F])
1577115771
value >>= 6
1577215772
}
1577315773
}
1577415774

15775+
func (b *KeyBuilder) WriteInt(value int) {
15776+
b.WriteUint64(uint64(int64(value)))
15777+
}
15778+
15779+
func (b *KeyBuilder) WriteSymbolId(id ast.SymbolId) {
15780+
b.WriteUint64(uint64(id))
15781+
}
15782+
1577515783
func (b *KeyBuilder) WriteSymbol(s *ast.Symbol) {
15776-
b.WriteInt(int(ast.GetSymbolId(s)))
15784+
b.WriteSymbolId(ast.GetSymbolId(s))
15785+
}
15786+
15787+
func (b *KeyBuilder) WriteTypeId(id TypeId) {
15788+
b.WriteUint64(uint64(id))
1577715789
}
1577815790

1577915791
func (b *KeyBuilder) WriteType(t *Type) {
15780-
b.WriteInt(int(t.id))
15792+
b.WriteTypeId(t.id)
1578115793
}
1578215794

1578315795
func (b *KeyBuilder) WriteTypes(types []*Type) {
@@ -15792,7 +15804,7 @@ func (b *KeyBuilder) WriteTypes(types []*Type) {
1579215804
if tail {
1579315805
b.WriteByte(',')
1579415806
}
15795-
b.WriteInt(int(startId))
15807+
b.WriteTypeId(startId)
1579615808
if count > 1 {
1579715809
b.WriteByte(':')
1579815810
b.WriteInt(count)
@@ -15850,9 +15862,13 @@ func (b *KeyBuilder) WriteGenericTypeReferences(source *Type, target *Type, igno
1585015862
return constrained
1585115863
}
1585215864

15865+
func (b *KeyBuilder) WriteNodeId(id ast.NodeId) {
15866+
b.WriteUint64(uint64(id))
15867+
}
15868+
1585315869
func (b *KeyBuilder) WriteNode(node *ast.Node) {
1585415870
if node != nil {
15855-
b.WriteInt(int(ast.GetNodeId(node)))
15871+
b.WriteNodeId(ast.GetNodeId(node))
1585615872
}
1585715873
}
1585815874

@@ -15917,7 +15933,7 @@ func getTupleKey(elementInfos []TupleElementInfo, readonly bool) string {
1591715933
b.WriteByte('*')
1591815934
}
1591915935
if e.labeledDeclaration != nil {
15920-
b.WriteInt(int(ast.GetNodeId(e.labeledDeclaration)))
15936+
b.WriteNode(e.labeledDeclaration)
1592115937
}
1592215938
}
1592315939
if readonly {
@@ -15946,7 +15962,7 @@ func getIndexedAccessKey(objectType *Type, indexType *Type, accessFlags AccessFl
1594615962
b.WriteByte(',')
1594715963
b.WriteType(indexType)
1594815964
b.WriteByte(',')
15949-
b.WriteInt(int(accessFlags))
15965+
b.WriteUint64(uint64(accessFlags))
1595015966
b.WriteAlias(alias)
1595115967
return b.String()
1595215968
}
@@ -15993,7 +16009,7 @@ func getRelationKey(source *Type, target *Type, intersectionState IntersectionSt
1599316009
}
1599416010
if intersectionState != IntersectionStateNone {
1599516011
b.WriteByte(':')
15996-
b.WriteInt(int(intersectionState))
16012+
b.WriteUint64(uint64(intersectionState))
1599716013
}
1599816014
if constrained {
1599916015
// We mark keys with type references that reference constrained type parameters such that we know

internal/checker/flow.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ func (c *Checker) writeFlowCacheKey(b *KeyBuilder, node *ast.Node, declaredType
16221622
}
16231623
if flowContainer != nil {
16241624
b.WriteByte('@')
1625-
b.WriteInt(int(ast.GetNodeId(flowContainer)))
1625+
b.WriteNode(flowContainer)
16261626
}
16271627
return true
16281628
case ast.KindNonNullExpression, ast.KindParenthesizedExpression:
@@ -1656,7 +1656,7 @@ func (c *Checker) writeFlowCacheKey(b *KeyBuilder, node *ast.Node, declaredType
16561656
}
16571657
case ast.KindObjectBindingPattern, ast.KindArrayBindingPattern, ast.KindFunctionDeclaration,
16581658
ast.KindFunctionExpression, ast.KindArrowFunction, ast.KindMethodDeclaration:
1659-
b.WriteInt(int(ast.GetNodeId(node)))
1659+
b.WriteNode(node)
16601660
b.WriteByte('#')
16611661
b.WriteType(declaredType)
16621662
return true

0 commit comments

Comments
 (0)