internal

package
v1.5.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package internal provides pure data structures for the type system.

HAMT (Hash Array Mapped Trie):

  • Get: O(log32 n) ≈ O(1) for practical sizes
  • Set: O(log32 n) with path copying
  • Delete: O(log32 n) with path copying
  • Memory: Unchanged subtrees are shared between versions.

Index

Constants

View Source
const (
	FnvOffset64 = 14695981039346656037
	FnvPrime64  = 1099511628211
)

FNV-1a constants.

View Source
const (
	// MaxShallowDepth for simple type checks (32).
	MaxShallowDepth = 32

	// MaxMediumDepth for type operations (64).
	MaxMediumDepth = 64

	// MaxDeepDepth for environment and control flow (256).
	MaxDeepDepth = 256

	// MaxHashDepth for structural hashing.
	MaxHashDepth = 50

	// MaxDistributionProduct caps the cartesian product size when distributing
	// intersection over unions to prevent exponential blowup.
	MaxDistributionProduct = 256
)

Depth limits for recursive type operations.

View Source
const (
	MinInt64 = math.MinInt64
	MaxInt64 = math.MaxInt64
)

Int64 bounds for overflow detection.

Variables

This section is empty.

Functions

func ComputeSCCs

func ComputeSCCs(adj map[uint64][]uint64) [][]uint64

ComputeSCCs computes strongly connected components using Tarjan's algorithm. Returns SCCs in topological order (dependencies resolved first).

func FnvString

func FnvString(s string) uint64

FnvString hashes a string using FNV-1a.

func HashCombine

func HashCombine(a, b uint64) uint64

HashCombine is an alias for MixHash.

func MixHash

func MixHash(h, v uint64) uint64

MixHash combines two hashes using FNV-1a style mixing.

func SafeAdd

func SafeAdd(a, b int64) (int64, bool)

SafeAdd returns (a + b, true) if no overflow, (0, false) otherwise.

func SafeMul

func SafeMul(a, b int64) (int64, bool)

SafeMul returns (a * b, true) if no overflow, (0, false) otherwise.

func SafeNeg

func SafeNeg(a int64) (int64, bool)

SafeNeg returns (-a, true) if no overflow, (0, false) otherwise.

func SafeSub

func SafeSub(a, b int64) (int64, bool)

SafeSub returns (a - b, true) if no overflow, (0, false) otherwise.

Types

type Equaler

type Equaler interface {
	Equals(other any) bool
}

Equaler is implemented by types that support typed equality comparison. Used by typ.Function to compare Effects, Spec, and Refinement fields without importing circular dependencies.

type HAMT

type HAMT[K comparable, V any] struct {
	// contains filtered or unexported fields
}

HAMT is an immutable hash array mapped trie. Zero value is an empty map.

func FromMap

func FromMap[K comparable, V any](m map[K]V) *HAMT[K, V]

FromMap creates a HAMT from a Go map.

func New

func New[K comparable, V any]() *HAMT[K, V]

New creates an empty HAMT.

func (*HAMT[K, V]) Delete

func (m *HAMT[K, V]) Delete(key K) *HAMT[K, V]

Delete returns a new map with the key removed.

func (*HAMT[K, V]) Get

func (m *HAMT[K, V]) Get(key K) (V, bool)

Get retrieves a value by key.

func (*HAMT[K, V]) IsEmpty

func (m *HAMT[K, V]) IsEmpty() bool

IsEmpty returns true if the map has no entries.

func (*HAMT[K, V]) Range

func (m *HAMT[K, V]) Range(fn func(K, V) bool)

Range iterates over all entries. Stops if fn returns false.

func (*HAMT[K, V]) Set

func (m *HAMT[K, V]) Set(key K, value V) *HAMT[K, V]

Set returns a new map with the key-value pair added or updated.

func (*HAMT[K, V]) Size

func (m *HAMT[K, V]) Size() int

Size returns the number of entries.

func (*HAMT[K, V]) ToMap

func (m *HAMT[K, V]) ToMap() map[K]V

ToMap converts HAMT to a Go map.

type Hashable

type Hashable interface {
	Hash() uint64
}

Hashable is a minimal interface for types that can be tracked by a hash. typ.Type satisfies this interface via Hash().

type RecursionGuard

type RecursionGuard struct {
	// contains filtered or unexported fields
}

RecursionGuard tracks recursion depth and optional cycle detection.

func NewRecursionGuard

func NewRecursionGuard(maxDepth int) RecursionGuard

NewRecursionGuard creates a guard with the given max depth.

func (RecursionGuard) Depth

func (g RecursionGuard) Depth() int

Depth returns the current recursion depth of the guard.

func (RecursionGuard) Enter

Enter advances the guard for a recursive step. Returns (nextGuard, true) if recursion should continue.

func (RecursionGuard) WithSeen

func (g RecursionGuard) WithSeen() RecursionGuard

WithSeen enables cycle detection using hashes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL