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§
Sourcefn is_subtype(&self, source: TypeId, target: TypeId) -> bool
fn is_subtype(&self, source: TypeId, target: TypeId) -> bool
Sourcefn evaluate(&self, type_id: TypeId) -> TypeId
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).
Sourcefn instantiate(&self, generic: TypeId, args: &[TypeId]) -> TypeId
fn instantiate(&self, generic: TypeId, args: &[TypeId]) -> TypeId
Sourcefn classify_iterable(&self, type_id: TypeId) -> IterableKind
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
Sourcefn classify_callable(&self, type_id: TypeId) -> CallableKind
fn classify_callable(&self, type_id: TypeId) -> CallableKind
Classify how a type can be called.
Used for:
- Call expressions
- new expressions
- Overload resolution
Sourcefn classify_primitive(&self, type_id: TypeId) -> PrimitiveFlags
fn classify_primitive(&self, type_id: TypeId) -> PrimitiveFlags
Get primitive-like behavior flags for a type.
Used for:
- Binary operator resolution
- Type coercion rules
Sourcefn classify_truthiness(&self, type_id: TypeId) -> TruthinessKind
fn classify_truthiness(&self, type_id: TypeId) -> TruthinessKind
Classify a type’s truthiness behavior.
Used for:
- Control flow narrowing
- Conditional expressions
Sourcefn apparent_type(&self, type_id: TypeId) -> TypeId
fn apparent_type(&self, type_id: TypeId) -> TypeId
Get the apparent type (unwrap type params, resolve constraints).
Sourcefn get_property(&self, type_id: TypeId, name: Atom) -> PropertyResult
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)
Sourcefn get_members(&self, type_id: TypeId) -> Arc<Vec<(Atom, TypeId)>>
fn get_members(&self, type_id: TypeId) -> Arc<Vec<(Atom, TypeId)>>
Get all members of a type as (name, type) pairs.
Sourcefn get_call_signatures(&self, type_id: TypeId) -> Arc<Vec<CallSignature>>
fn get_call_signatures(&self, type_id: TypeId) -> Arc<Vec<CallSignature>>
Get call signatures of a type.
Sourcefn get_construct_signatures(&self, type_id: TypeId) -> Arc<Vec<CallSignature>>
fn get_construct_signatures(&self, type_id: TypeId) -> Arc<Vec<CallSignature>>
Get construct signatures of a type.
Sourcefn get_index_type(&self, object: TypeId, key: TypeId) -> TypeId
fn get_index_type(&self, object: TypeId, key: TypeId) -> TypeId
Get the result of indexing: T[K]
Sourcefn get_index_signature(
&self,
type_id: TypeId,
kind: IndexKind,
) -> Option<TypeId>
fn get_index_signature( &self, type_id: TypeId, kind: IndexKind, ) -> Option<TypeId>
Get index signature type (string or number indexer).
Sourcefn config(&self) -> &JudgeConfig
fn config(&self) -> &JudgeConfig
Get the current configuration.
Provided Methods§
Sourcefn are_identical(&self, a: TypeId, b: TypeId) -> bool
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.