Skip to main content

Crate inlean_runtime

Crate inlean_runtime 

Source
Expand description

Runtime support for Rust code generated from Lean by inlean.

Generated code calls into this crate for every primitive that Lean implements in its C runtime. Each function here is a port of the C function of the same name in Lean’s lean.h, minus the lean_ prefix and split into one module per type: lean_uint32_shift_left is scalar::uint32::shift_left.

This crate is an implementation detail of inlean. Its API follows Lean’s runtime, not Rust conventions, and changes with the pinned Lean release.

The ported functions derive from Lean 4’s lean.h, Copyright (c) 2019 Microsoft Corporation, under the Apache License 2.0; the crate’s NOTICE file has the details.

Re-exports§

pub use codec::Codec;
pub use codec::Pass;
pub use codec::Primitive;
pub use codec::Repr;
pub use codec::Value;

Modules§

array
Lean’s Array: a growable sequence of objects, updated in place when nothing else refers to it.
codec
Conversions between Rust values and Lean values, chosen by the Lean type.
collections
The Rust functions behind the collections of inlean’s Lean library: the standard library’s Vec, VecDeque, HashMap and HashSet.
int
Lean’s Int: an integer of any size.
math
The C math library functions Lean’s Float and Float32 call directly, under their C names.
misc
Primitives that belong to no data type.
nat
Lean’s Nat: a natural number of any size.
sarray
Lean’s unboxed arrays: ByteArray and FloatArray.
scalar
Fixed-width integers, Bool and floats: Lean’s unboxed scalar types.
string
Lean’s String: UTF-8 text, addressed by byte position.

Structs§

Constant
A Lean constant that is an object: computed on first use, then persistent.
Function
A Lean function that a declaration bound to Rust was given: a closure, and a reference to it.
Generic
A Lean value of a type that a declaration bound to Rust is generic in.
Header
What every heap object starts with.
Int
An integer of any size: Lean’s Int.
Nat
A natural number of any size: Lean’s Nat.
Obj
A Lean value that is not an unboxed scalar.
ParseIntError
A string is not an integer in decimal digits.
ParseNatError
A string is not a natural number in decimal digits.
TooLarge
A Nat does not fit the integer type it was converted to.

Constants§

CLOSURE_MAX_ARGS
Most arguments a closure’s function takes as separate parameters.
MAX_CTOR_TAG
Largest tag of a constructor object. Larger tags are the kinds below.
TAG_ARRAY
TAG_CLOSURE
TAG_EXTERNAL
A value of a type the runtime does not know. Lean uses this tag for the same purpose.
TAG_LENT
An object that stands for an external value without holding it: see Lent. Lean uses this tag for a reference cell, which this runtime has no primitive to make.
TAG_MPZ
TAG_SARRAY
TAG_STRING

Functions§

alloc_closure⚠
A closure of function, which takes arity objects and returns an object, with room for num_fixed arguments that closure_set must fill.
alloc_ctor⚠
A constructor object with num_objs object fields, num_usize word-sized scalar fields and scalar_size bytes of other scalar fields, all uninitialized.
apply⚠
Applies closure f to args. Consumes f and the arguments.
box_
A number in the pointer bits. n must fit in a word minus one bit.
box_float⚠
box_float32⚠
box_uint32⚠
A u32 fits in the pointer bits of a 64-bit target only.
box_uint64⚠
box_usize⚠
char_of_u32
A Lean Char as a Rust char. Lean’s Char carries a proof that it is a Unicode scalar value, so a failure here is a bug in the translation, not in the caller.
closure_set⚠
ctor_get⚠
ctor_get_float⚠
Reads the scalar offset bytes after the first slots word-sized fields.
ctor_get_float32⚠
Reads the scalar offset bytes after the first slots word-sized fields.
ctor_get_uint8⚠
Reads the scalar offset bytes after the first slots word-sized fields.
ctor_get_uint16⚠
Reads the scalar offset bytes after the first slots word-sized fields.
ctor_get_uint32⚠
Reads the scalar offset bytes after the first slots word-sized fields.
ctor_get_uint64⚠
Reads the scalar offset bytes after the first slots word-sized fields.
ctor_get_usize⚠
ctor_release⚠
Drops field i of a constructor object that is about to be reused.
ctor_set⚠
ctor_set_float⚠
Writes the scalar offset bytes after the first slots word-sized fields.
ctor_set_float32⚠
Writes the scalar offset bytes after the first slots word-sized fields.
ctor_set_tag⚠
ctor_set_uint8⚠
Writes the scalar offset bytes after the first slots word-sized fields.
ctor_set_uint16⚠
Writes the scalar offset bytes after the first slots word-sized fields.
ctor_set_uint32⚠
Writes the scalar offset bytes after the first slots word-sized fields.
ctor_set_uint64⚠
Writes the scalar offset bytes after the first slots word-sized fields.
ctor_set_usize⚠
dec⚠
dec_ref⚠
free_object⚠
Releases the memory of an object without touching the objects it refers to.
inc⚠
inc_n⚠
inc_ref⚠
inc_ref_n⚠
is_exclusive⚠
Whether this is the only reference to the object, so that it may be updated in place.
is_scalar
live_objects
The number of heap objects this thread created and has not freed, for finding leaks in tests. Persistent objects, which are never freed, count. Always zero in a release build.
mark_persistent⚠
Makes an object and everything it refers to persistent: never counted, never freed, never updated in place, and therefore safe to read from any thread.
obj_tag⚠
The constructor index of a value of an inductive type.
ptr_tag⚠
The kind of a heap object.
reset⚠
Prepares constructor object o, which has num_objs object fields, for reuse: returns its memory if nothing else refers to it, and otherwise drops the reference and returns box_(0).
resolve
Resolves the name of a function of Lean’s C runtime, such as lean_nat_add, to the Rust path of its port relative to this crate, such as nat::nat_add.
reuse⚠
A constructor object for the given constructor, in the memory reset returned if it returned any.
unbox
unbox_float⚠
unbox_float32⚠
unbox_uint32⚠
unbox_uint64⚠
unbox_usize⚠
unreachable
Lean’s unreachable instruction: a point the Lean compiler proved cannot be reached.