pub struct TypeChecker<'env> { /* private fields */ }Expand description
Unified type checker state.
Owns WHNF reduction, definitional equality checking, and type inference.
Mirrors LEAN 4’s type_checker class.
Implementations§
Source§impl<'env> TypeChecker<'env>
impl<'env> TypeChecker<'env>
Sourcepub fn new(env: &'env Environment) -> Self
pub fn new(env: &'env Environment) -> Self
Create a new type checker for the given environment.
Sourcepub fn new_infer_only(env: &'env Environment) -> Self
pub fn new_infer_only(env: &'env Environment) -> Self
Create a type checker in infer-only mode (skips some checks).
Sourcepub fn set_transparency(&mut self, mode: TransparencyMode)
pub fn set_transparency(&mut self, mode: TransparencyMode)
Set the transparency mode.
Sourcepub fn env(&self) -> &Environment
pub fn env(&self) -> &Environment
Get the environment.
Sourcepub fn fresh_fvar(&mut self, name: Name, ty: Expr) -> FVarId
pub fn fresh_fvar(&mut self, name: Name, ty: Expr) -> FVarId
Generate a fresh free variable.
Sourcepub fn fresh_fvar_let(&mut self, name: Name, ty: Expr, val: Expr) -> FVarId
pub fn fresh_fvar_let(&mut self, name: Name, ty: Expr, val: Expr) -> FVarId
Generate a fresh free variable with a value (let-binding).
Sourcepub fn push_local(&mut self, decl: LocalDecl)
pub fn push_local(&mut self, decl: LocalDecl)
Push a local declaration onto the context.
Sourcepub fn ensure_sort(&mut self, expr: &Expr) -> Result<Level, KernelError>
pub fn ensure_sort(&mut self, expr: &Expr) -> Result<Level, KernelError>
Ensure an expression is a Sort, returning the level.
Infers the type, reduces to WHNF, and checks it’s a Sort.
Sourcepub fn ensure_pi(&mut self, expr: &Expr) -> Result<Expr, KernelError>
pub fn ensure_pi(&mut self, expr: &Expr) -> Result<Expr, KernelError>
Ensure an expression’s type is a Pi type, returning it.
Sourcepub fn is_def_eq(&mut self, t: &Expr, s: &Expr) -> bool
pub fn is_def_eq(&mut self, t: &Expr, s: &Expr) -> bool
Check if two expressions are definitionally equal.
Sourcepub fn check_type(
&mut self,
expr: &Expr,
inferred: &Expr,
expected: &Expr,
) -> Result<(), KernelError>
pub fn check_type( &mut self, expr: &Expr, inferred: &Expr, expected: &Expr, ) -> Result<(), KernelError>
Check that an expression has the expected type.
Sourcepub fn infer_type(&mut self, expr: &Expr) -> Result<Expr, KernelError>
pub fn infer_type(&mut self, expr: &Expr) -> Result<Expr, KernelError>
Infer the type of an expression.
Sourcepub fn is_prop(&mut self, expr: &Expr) -> bool
pub fn is_prop(&mut self, expr: &Expr) -> bool
Check if an expression is a proposition (has type Prop).
Sourcepub fn is_proof(&mut self, expr: &Expr) -> bool
pub fn is_proof(&mut self, expr: &Expr) -> bool
Check if an expression is a proof (its type is a proposition).
Sourcepub fn is_type(&mut self, expr: &Expr) -> bool
pub fn is_type(&mut self, expr: &Expr) -> bool
Check if an expression is a type (has type Sort u for some u).
Sourcepub fn get_level(&mut self, expr: &Expr) -> Result<Level, KernelError>
pub fn get_level(&mut self, expr: &Expr) -> Result<Level, KernelError>
Get the universe level of a type expression.
Sourcepub fn unfold_definition(&mut self, expr: &Expr) -> Option<Expr>
pub fn unfold_definition(&mut self, expr: &Expr) -> Option<Expr>
Try to unfold a constant definition.
Source§impl<'env> TypeChecker<'env>
impl<'env> TypeChecker<'env>
Sourcepub fn infer_app_chain(
&mut self,
f: &Expr,
args: &[Expr],
) -> Result<Expr, KernelError>
pub fn infer_app_chain( &mut self, f: &Expr, args: &[Expr], ) -> Result<Expr, KernelError>
Infer the type of a chain of applications at once.
Sourcepub fn telescope_type(
&mut self,
ty: &Expr,
max_pis: usize,
) -> (Vec<LocalDecl>, Expr)
pub fn telescope_type( &mut self, ty: &Expr, max_pis: usize, ) -> (Vec<LocalDecl>, Expr)
Telescope a type, instantiating leading Pi binders with fresh free variables.
Sourcepub fn close_type_over_fvars(&mut self, fvars: &[LocalDecl], ty: Expr) -> Expr
pub fn close_type_over_fvars(&mut self, fvars: &[LocalDecl], ty: Expr) -> Expr
Close a type over a list of free variables into Pi types.
Sourcepub fn close_term_over_fvars(&mut self, fvars: &[LocalDecl], term: Expr) -> Expr
pub fn close_term_over_fvars(&mut self, fvars: &[LocalDecl], term: Expr) -> Expr
Close a term over free variables into lambdas.
Sourcepub fn check(&mut self, expr: &Expr, expected: &Expr) -> Result<(), KernelError>
pub fn check(&mut self, expr: &Expr, expected: &Expr) -> Result<(), KernelError>
Check that expr has type expected.
Sourcepub fn try_check(&mut self, expr: &Expr, expected: &Expr) -> bool
pub fn try_check(&mut self, expr: &Expr, expected: &Expr) -> bool
Try to check; return true if the type matches.
Sourcepub fn count_pi_binders(&mut self, ty: &Expr) -> usize
pub fn count_pi_binders(&mut self, ty: &Expr) -> usize
Get the number of Pi binders in the WHNF of a type.
Sourcepub fn verify_declaration(
&mut self,
name: &Name,
ty: &Expr,
val: Option<&Expr>,
) -> Result<(), KernelError>
pub fn verify_declaration( &mut self, name: &Name, ty: &Expr, val: Option<&Expr>, ) -> Result<(), KernelError>
Verify a declaration’s type and optional value.
Sourcepub fn constant_arity(&mut self, name: &Name) -> Option<usize>
pub fn constant_arity(&mut self, name: &Name) -> Option<usize>
Return the arity (number of Pi binders) in the type of a constant.
Sourcepub fn is_level_eq(&self, l1: &Level, l2: &Level) -> bool
pub fn is_level_eq(&self, l1: &Level, l2: &Level) -> bool
Check if two universe levels are definitionally equal.