Skip to main content

Judge

Trait Judge 

Source
pub trait Judge {
Show 17 methods // Required methods fn is_subtype(&self, source: TypeId, target: TypeId) -> bool; fn evaluate(&self, type_id: TypeId) -> TypeId; fn instantiate(&self, generic: TypeId, args: &[TypeId]) -> TypeId; fn classify_iterable(&self, type_id: TypeId) -> IterableKind; fn classify_callable(&self, type_id: TypeId) -> CallableKind; fn classify_primitive(&self, type_id: TypeId) -> PrimitiveFlags; fn classify_truthiness(&self, type_id: TypeId) -> TruthinessKind; fn apparent_type(&self, type_id: TypeId) -> TypeId; fn get_property(&self, type_id: TypeId, name: Atom) -> PropertyResult; fn get_members(&self, type_id: TypeId) -> Arc<Vec<(Atom, TypeId)>>; fn get_call_signatures(&self, type_id: TypeId) -> Arc<Vec<CallSignature>>; fn get_construct_signatures( &self, type_id: TypeId, ) -> Arc<Vec<CallSignature>>; fn get_index_type(&self, object: TypeId, key: TypeId) -> TypeId; fn get_index_signature( &self, type_id: TypeId, kind: IndexKind, ) -> Option<TypeId>; fn get_keyof(&self, type_id: TypeId) -> TypeId; fn config(&self) -> &JudgeConfig; // Provided method fn are_identical(&self, a: TypeId, b: TypeId) -> bool { ... }
}
Expand description

The Judge trait: pure type algebra queries.

This trait defines the query interface for type checking operations. Implementations can provide different caching strategies (e.g., Salsa).

§Coinductive Semantics

Subtype checks use coinductive semantics for recursive types:

  • When a cycle is detected, assume true (greatest fixed point)
  • This correctly handles types like type List<T> = { head: T; tail: List<T> }

§Memoization

All methods are designed to be memoizable:

  • No side effects (diagnostics handled separately)
  • Deterministic results for same inputs
  • Configuration is explicit (not implicit state)

Required Methods§

Source

fn is_subtype(&self, source: TypeId, target: TypeId) -> bool

Check if source is a subtype of target.

Uses coinductive semantics: cycles assume true.

§Example
// number <: number | string
assert!(judge.is_subtype(TypeId::NUMBER, union_type));
Source

fn evaluate(&self, type_id: TypeId) -> TypeId

Evaluate a type, resolving meta-types (conditional, mapped, keyof, etc.).

Returns the evaluated type (may be the same if no evaluation needed).

§Cycle Recovery

Returns the input type on cycle (identity recovery).

Source

fn instantiate(&self, generic: TypeId, args: &[TypeId]) -> TypeId

Instantiate a generic type with type arguments.

§Example
// Array<number> from Array<T> with T=number
let array_number = judge.instantiate(array_generic, &[TypeId::NUMBER]);
Source

fn classify_iterable(&self, type_id: TypeId) -> IterableKind

Classify how a type can be iterated.

Used for:

  • for-of loop targets
  • Spread operators
  • Array.from() arguments
Source

fn classify_callable(&self, type_id: TypeId) -> CallableKind

Classify how a type can be called.

Used for:

  • Call expressions
  • new expressions
  • Overload resolution
Source

fn classify_primitive(&self, type_id: TypeId) -> PrimitiveFlags

Get primitive-like behavior flags for a type.

Used for:

  • Binary operator resolution
  • Type coercion rules
Source

fn classify_truthiness(&self, type_id: TypeId) -> TruthinessKind

Classify a type’s truthiness behavior.

Used for:

  • Control flow narrowing
  • Conditional expressions
Source

fn apparent_type(&self, type_id: TypeId) -> TypeId

Get the apparent type (unwrap type params, resolve constraints).

Source

fn get_property(&self, type_id: TypeId, name: Atom) -> PropertyResult

Get a specific property’s type from a type.

Returns PropertyResult which distinguishes between:

  • Property found
  • Property not found
  • Index signature match
  • Special types (any, unknown, error)
Source

fn get_members(&self, type_id: TypeId) -> Arc<Vec<(Atom, TypeId)>>

Get all members of a type as (name, type) pairs.

Source

fn get_call_signatures(&self, type_id: TypeId) -> Arc<Vec<CallSignature>>

Get call signatures of a type.

Source

fn get_construct_signatures(&self, type_id: TypeId) -> Arc<Vec<CallSignature>>

Get construct signatures of a type.

Source

fn get_index_type(&self, object: TypeId, key: TypeId) -> TypeId

Get the result of indexing: T[K]

Source

fn get_index_signature( &self, type_id: TypeId, kind: IndexKind, ) -> Option<TypeId>

Get index signature type (string or number indexer).

Source

fn get_keyof(&self, type_id: TypeId) -> TypeId

Get keyof: keyof T

Source

fn config(&self) -> &JudgeConfig

Get the current configuration.

Provided Methods§

Source

fn are_identical(&self, a: TypeId, b: TypeId) -> bool

Check if two types are identical (stricter than subtyping).

Identity requires both A <: B and B <: A.

Implementors§

Source§

impl<'a> Judge for DefaultJudge<'a>