From 3e035250f5854aafaed56a7f6dee17b873910f48 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 20 Jan 2025 14:10:33 -0800 Subject: [PATCH] Make NodeId and SymbolId into uint64s, fix up KeyBuilder --- internal/ast/ast.go | 2 +- internal/ast/ids.go | 4 ++-- internal/ast/symbol.go | 2 +- internal/ast/utilities.go | 4 ++-- internal/checker/checker.go | 32 ++++++++++++++++++++++++-------- internal/checker/flow.go | 4 ++-- 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 3bf0d4167a..1004819bcb 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -97,7 +97,7 @@ type Node struct { Kind Kind Flags NodeFlags Loc core.TextRange - id atomic.Uint32 + id atomic.Uint64 Parent *Node data nodeData } diff --git a/internal/ast/ids.go b/internal/ast/ids.go index 435bf15ea3..63e415deba 100644 --- a/internal/ast/ids.go +++ b/internal/ast/ids.go @@ -1,6 +1,6 @@ package ast type ( - NodeId uint32 - SymbolId uint32 + NodeId uint64 + SymbolId uint64 ) diff --git a/internal/ast/symbol.go b/internal/ast/symbol.go index 3833d03955..5e04e76149 100644 --- a/internal/ast/symbol.go +++ b/internal/ast/symbol.go @@ -14,7 +14,7 @@ type Symbol struct { ValueDeclaration *Node Members SymbolTable Exports SymbolTable - id atomic.Uint32 + id atomic.Uint64 Parent *Symbol ExportSymbol *Symbol AssignmentDeclarationMembers map[NodeId]*Node // Set of detected assignment declarations diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 4514d8aae3..3ef45a5c0b 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -10,8 +10,8 @@ import ( // Atomic ids var ( - nextNodeId atomic.Uint32 - nextSymbolId atomic.Uint32 + nextNodeId atomic.Uint64 + nextSymbolId atomic.Uint64 ) func GetNodeId(node *Node) NodeId { diff --git a/internal/checker/checker.go b/internal/checker/checker.go index e07e5f510b..0fa25ae896 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -11211,19 +11211,31 @@ var base64chars = []byte{ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '$', '%', } -func (b *KeyBuilder) WriteInt(value int) { +func (b *KeyBuilder) WriteUint64(value uint64) { for value != 0 { b.WriteByte(base64chars[value&0x3F]) value >>= 6 } } +func (b *KeyBuilder) WriteInt(value int) { + b.WriteUint64(uint64(int64(value))) +} + +func (b *KeyBuilder) WriteSymbolId(id ast.SymbolId) { + b.WriteUint64(uint64(id)) +} + func (b *KeyBuilder) WriteSymbol(s *ast.Symbol) { - b.WriteInt(int(ast.GetSymbolId(s))) + b.WriteSymbolId(ast.GetSymbolId(s)) +} + +func (b *KeyBuilder) WriteTypeId(id TypeId) { + b.WriteUint64(uint64(id)) } func (b *KeyBuilder) WriteType(t *Type) { - b.WriteInt(int(t.id)) + b.WriteTypeId(t.id) } func (b *KeyBuilder) WriteTypes(types []*Type) { @@ -11238,7 +11250,7 @@ func (b *KeyBuilder) WriteTypes(types []*Type) { if tail { b.WriteByte(',') } - b.WriteInt(int(startId)) + b.WriteTypeId(startId) if count > 1 { b.WriteByte(':') b.WriteInt(count) @@ -11291,9 +11303,13 @@ func (b *KeyBuilder) WriteTypeReference(ref *Type, ignoreConstraints bool, depth return constrained } +func (b *KeyBuilder) WriteNodeId(id ast.NodeId) { + b.WriteUint64(uint64(id)) +} + func (b *KeyBuilder) WriteNode(node *ast.Node) { if node != nil { - b.WriteInt(int(ast.GetNodeId(node))) + b.WriteNodeId(ast.GetNodeId(node)) } } @@ -11358,7 +11374,7 @@ func getTupleKey(elementInfos []TupleElementInfo, readonly bool) string { b.WriteByte('*') } if e.labeledDeclaration != nil { - b.WriteInt(int(ast.GetNodeId(e.labeledDeclaration))) + b.WriteNode(e.labeledDeclaration) } } if readonly { @@ -11387,7 +11403,7 @@ func getIndexedAccessKey(objectType *Type, indexType *Type, accessFlags AccessFl b.WriteByte(',') b.WriteType(indexType) b.WriteByte(',') - b.WriteInt(int(accessFlags)) + b.WriteUint64(uint64(accessFlags)) b.WriteAlias(alias) return b.String() } @@ -11436,7 +11452,7 @@ func getRelationKey(source *Type, target *Type, intersectionState IntersectionSt } if intersectionState != IntersectionStateNone { b.WriteByte(':') - b.WriteInt(int(intersectionState)) + b.WriteUint64(uint64(intersectionState)) } if constrained { // We mark keys with type references that reference constrained type parameters such that we know diff --git a/internal/checker/flow.go b/internal/checker/flow.go index 106b6c8a05..c717f8f6e7 100644 --- a/internal/checker/flow.go +++ b/internal/checker/flow.go @@ -1606,7 +1606,7 @@ func (c *Checker) writeFlowCacheKey(b *KeyBuilder, node *ast.Node, declaredType } if flowContainer != nil { b.WriteByte('@') - b.WriteInt(int(ast.GetNodeId(flowContainer))) + b.WriteNode(flowContainer) } return true case ast.KindNonNullExpression, ast.KindParenthesizedExpression: @@ -1640,7 +1640,7 @@ func (c *Checker) writeFlowCacheKey(b *KeyBuilder, node *ast.Node, declaredType } case ast.KindObjectBindingPattern, ast.KindArrayBindingPattern, ast.KindFunctionDeclaration, ast.KindFunctionExpression, ast.KindArrowFunction, ast.KindMethodDeclaration: - b.WriteInt(int(ast.GetNodeId(node))) + b.WriteNode(node) b.WriteByte('#') b.WriteType(declaredType) return true