Skip to content

Make NodeId and SymbolId into uint64s, fix up KeyBuilder #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type Node struct {
Kind Kind
Flags NodeFlags
Loc core.TextRange
id atomic.Uint32
id atomic.Uint64
Parent *Node
data nodeData
}
Expand Down
4 changes: 2 additions & 2 deletions internal/ast/ids.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ast

type (
NodeId uint32
SymbolId uint32
NodeId uint64
SymbolId uint64
)
2 changes: 1 addition & 1 deletion internal/ast/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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
Expand Down
4 changes: 2 additions & 2 deletions internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 24 additions & 8 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13825,19 +13825,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) {
Expand All @@ -13852,7 +13864,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)
Expand Down Expand Up @@ -13910,9 +13922,13 @@ func (b *KeyBuilder) WriteGenericTypeReferences(source *Type, target *Type, igno
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))
}
}

Expand Down Expand Up @@ -13977,7 +13993,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 {
Expand Down Expand Up @@ -14006,7 +14022,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()
}
Expand Down Expand Up @@ -14053,7 +14069,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
Expand Down
4 changes: 2 additions & 2 deletions internal/checker/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,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:
Expand Down Expand Up @@ -1656,7 +1656,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
Expand Down
Loading