Skip to main content

Kernel

Struct Kernel 

Source
pub struct Kernel {
    pub s: Store,
    pub env: Env,
    pub wk: WellKnown,
    pub engine: Engine,
    pub probe_steps: u32,
    pub theory: Theory,
    /* private fields */
}
Expand description

A kernel is plain data (its only shared cells are immutable: interned strings and admitted constants), so a clone is an independent kernel; mirror keeps one as a snapshot to branch from.

Fields§

§s: Store§env: Env§wk: WellKnown§engine: Engine

Which judgment admits definitions, theorems, opaques and axioms.

§probe_steps: u32

The steps the value engine lets one argument pair of a same-head comparison take before it unfolds the definitions instead (see sem::conv): conversion steps and δ-unfolding steps both spend it. It changes what conversion costs, never what it answers.

§theory: Theory

The type theory this kernel checks.

Implementations§

Source§

impl Kernel

Source

pub fn check_name(&self, n: NameId, allow_primitive: bool) -> KResult<()>

Source

pub fn check_duplicate_lparams(&self, ps: &[NameId]) -> KResult<()>

Source

pub fn with_decl<T>( &mut self, lparams: Rc<[NameId]>, safety: Safety, f: impl FnOnce(&mut Kernel) -> KResult<T>, ) -> KResult<T>

Runs f as one declaration’s check: fresh caches and local context, scratch memory released afterwards whatever the outcome.

Source

pub fn may_trust(&self, d: &Decl) -> bool

Whether d may be admitted unchecked in a trusted-prefix run (see super::export::Observe::trust_before): anything but a primitive or the quotient.

Source

pub fn may_trust_block(&self, claimed: &[Const]) -> bool

Whether an inductive block declaring claimed may be admitted unchecked: none of its constants is a primitive.

Source

pub fn admit_trusted(&mut self, d: Decl)

Admits d as the export states it, without checking it (trusted-prefix runs only).

Source

pub fn admit_trusted_block(&mut self, claimed: Vec<Const>)

Admits an inductive block’s constants as the export states them, without checking them (trusted-prefix runs only).

Source

pub fn add_decl(&mut self, decl: Decl) -> KResult<()>

Source

pub fn const_levels_of(&mut self, ps: &[NameId]) -> LevelsId

Source

pub fn is_sort(&self, e: ExprId) -> bool

Source§

impl Kernel

Source

pub fn add_inductive( &mut self, decl: InductiveDecl, claimed: Vec<Const>, ) -> KResult<()>

Admits an inductive family whose declarations an export claims are claimed.

Source§

impl Kernel

Source

pub fn logos(ctx: &Context) -> Kernel

A kernel for LOGOS’s theory over the declarations of ctx.

Source§

impl Kernel

Source

pub fn check_primitive_def(&mut self, d: &DefnDecl) -> KResult<bool>

Returns whether d may take a primitive name (Lean’s checkPrimitiveDef), and records a primitive whose equations check as computed natively (validated_primitives).

In LOGOS’s theory a primitive’s name refuses nothing: a definition that does not check as the primitive is an ordinary one, computed by unfolding, and its literal rules read Zero and Succ only while they are Nat’s constructors (Kernel::reads_nat_literal). So a definition named Succ is admitted, and an impostor Nat.div is not computed natively.

Source§

impl Kernel

Source

pub fn ignorable_args(&mut self, c: NameId, ls: LevelsId) -> KResult<u64>

The argument positions of c.{ls} whose arguments need not be compared (see the module documentation). Zero for anything that is not a settled, unfoldable definition.

Source

pub fn absent_mask(&mut self, c: NameId, ls: LevelsId) -> Option<u64>

The positions c’s value never mentions, or None when c.{ls} is not a settled, unfoldable definition (whose arguments must then all be compared).

Source§

impl Kernel

Source

pub fn with_sem<T>( &mut self, f: impl FnOnce(&mut Sem<'_>) -> KResult<T>, ) -> KResult<T>

Runs the value engine on this kernel with its session state.

Source

pub fn sem_epoch(&self) -> u64

Changes whenever something already evaluated may now mean something else: the quotient reductions were switched on, or a primitive was validated (its literal extension switched on). The value engine’s session never spans two epochs.

A withdrawn declaration needs no epoch: only a provisional declaration is ever withdrawn, and a session that touches one is marked (scratch_seen) and ends with its declaration.

Source§

impl Kernel

Source

pub fn new() -> Kernel

Source

pub fn begin_decl(&mut self, lparams: Rc<[NameId]>, safety: Safety)

Starts checking one declaration: fresh local context, caches, and scratch region.

Source

pub fn end_decl(&mut self)

Source

pub fn memory_report(&self) -> Vec<(&'static str, usize)>

The store’s memory, plus the kernel’s own caches and environment.

Source

pub fn set_safety(&mut self, safety: Safety)

Source

pub fn push_local(&mut self, ty: ExprId, val: Option<ExprId>) -> ExprId

Source

pub fn fvar_index(&self, e: ExprId) -> u32

Source

pub fn mk_binding(&mut self, pi: bool, fvars: &[ExprId], body: ExprId) -> ExprId

mkForall/mkLambda over local declarations (lets become let).

Source

pub fn mk_pi(&mut self, fvars: &[ExprId], body: ExprId) -> ExprId

Source

pub fn mk_lambda(&mut self, fvars: &[ExprId], body: ExprId) -> ExprId

Source

pub fn get_const(&self, n: NameId) -> KResult<Rc<Const>>

Source

pub fn instantiate_type_lparams(&mut self, c: &Const, ls: LevelsId) -> ExprId

c’s type at universe arguments ls.

Source

pub fn infer(&mut self, e: ExprId, infer_only: bool) -> KResult<ExprId>

Source

pub fn sort_level(&self, s: ExprId) -> LevelId

Source

pub fn ensure_sort(&mut self, e: ExprId) -> KResult<ExprId>

Source

pub fn ensure_pi(&mut self, e: ExprId) -> KResult<ExprId>

Source

pub fn get_sort_level(&mut self, e: ExprId) -> KResult<LevelId>

Source

pub fn is_prop(&mut self, e: ExprId) -> KResult<bool>

e’s type is Prop.

Source

pub fn check(&mut self, e: ExprId) -> KResult<ExprId>

Infers e’s type with full checking.

Source

pub fn whnf_core(&mut self, e: ExprId, cheap_proj: bool) -> KResult<ExprId>

Source

pub fn is_app_of_arity(&self, e: ExprId, n: NameId, arity: usize) -> bool

Source

pub fn nat_lit_to_ctor(&mut self, n: &Nat) -> ExprId

Source

pub fn str_lit_to_ctor(&mut self, sid: StrId) -> ExprId

Source

pub fn unfold_definition(&mut self, e: ExprId) -> Option<ExprId>

Source

pub fn reduce_nat(&mut self, e: ExprId) -> KResult<Option<ExprId>>

Lean’s reduceNat: Nat.succ and the GMP-accelerated binary operations on literals.

Source

pub fn whnf(&mut self, e: ExprId) -> KResult<ExprId>

Source

pub fn conforms(&mut self, actual: ExprId, expected: ExprId) -> KResult<bool>

Whether a term of type actual may stand where expected is required: definitional equality in Lean’s theory, cumulative subtyping in LOGOS’s.

Source

pub fn is_def_eq(&mut self, t: ExprId, s: ExprId) -> KResult<bool>

Source

pub fn unfold_steps(&self) -> u64

The δ-unfoldings this kernel’s weak-head reduction has taken: a primitive at literals computed natively takes none.

Source

pub fn conversion_steps(&self) -> u64

The definitional-equality steps this kernel has taken (see conv_steps).

Source

pub fn show(&self, e: ExprId) -> String

Source

pub fn level_node(&self, l: LevelId) -> LevelNode

Source

pub fn quot_kind(&self, n: NameId) -> Option<QuotKind>

Trait Implementations§

Source§

impl Clone for Kernel

Source§

fn clone(&self) -> Kernel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Kernel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.