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,HashMapandHashSet. - int
- Lean’s
Int: an integer of any size. - math
- The C math library functions Lean’s
FloatandFloat32call 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:
ByteArrayandFloatArray. - scalar
- Fixed-width integers,
Booland 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.
- Parse
IntError - A string is not an integer in decimal digits.
- Parse
NatError - A string is not a natural number in decimal digits.
- TooLarge
- A
Natdoes 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 takesarityobjects and returns an object, with room fornum_fixedarguments thatclosure_setmust fill. - alloc_
ctor ⚠ - A constructor object with
num_objsobject fields,num_usizeword-sized scalar fields andscalar_sizebytes of other scalar fields, all uninitialized. - apply⚠
- Applies closure
ftoargs. Consumesfand the arguments. - box_
- A number in the pointer bits.
nmust fit in a word minus one bit. - box_
float ⚠ - box_
float32 ⚠ - box_
uint32 ⚠ - A
u32fits in the pointer bits of a 64-bit target only. - box_
uint64 ⚠ - box_
usize ⚠ - char_
of_ u32 - A Lean
Charas a Rustchar. Lean’sCharcarries 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
offsetbytes after the firstslotsword-sized fields. - ctor_
get_ ⚠float32 - Reads the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
get_ ⚠uint8 - Reads the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
get_ ⚠uint16 - Reads the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
get_ ⚠uint32 - Reads the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
get_ ⚠uint64 - Reads the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
get_ ⚠usize - ctor_
release ⚠ - Drops field
iof a constructor object that is about to be reused. - ctor_
set ⚠ - ctor_
set_ ⚠float - Writes the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
set_ ⚠float32 - Writes the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
set_ ⚠tag - ctor_
set_ ⚠uint8 - Writes the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
set_ ⚠uint16 - Writes the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
set_ ⚠uint32 - Writes the scalar
offsetbytes after the firstslotsword-sized fields. - ctor_
set_ ⚠uint64 - Writes the scalar
offsetbytes after the firstslotsword-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 hasnum_objsobject fields, for reuse: returns its memory if nothing else refers to it, and otherwise drops the reference and returnsbox_(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 asnat::nat_add. - reuse⚠
- A constructor object for the given constructor, in the memory
resetreturned if it returned any. - unbox
- unbox_
float ⚠ - unbox_
float32 ⚠ - unbox_
uint32 ⚠ - unbox_
uint64 ⚠ - unbox_
usize ⚠ - unreachable
- Lean’s
unreachableinstruction: a point the Lean compiler proved cannot be reached.