Expand description
Standard-library type-invariant generation.
Type invariants are synthesized obligations that a value of a given type
must satisfy. Unlike user-written #[rapx::invariant] struct invariants,
these are generated automatically from the bundled std-type-invariants.json
database, keyed by a normalized type path (e.g. core::num::NonZero) or by
the built-in [T] slice key.
The results feed the type_invariants field of a [FunctionTarget]
(see super::target), whose entry facts are synthesized by the VMโs
init_parameters and re-proved at return by VerifyDriver::verify_type_invariants.
Constantsยง
- SLICE_
ELEM_ ๐PLACEHOLDER - Placeholder type name substituted for the
$elemtoken before parsing. The JSON$elemis a bare type argument (e.g.Align($self, $elem)), and the real element type โ which can be a composite like[T; N]that has no resolvable name โ is injected afterwards byreplace_ty_args. Any primitive placeholder resolves cleanly through the name-based type parser.
Functionsยง
- build_
type_ ๐invariants_ from_ params - For each function parameter (and the return type), look up the typeโs
invariants from
std-type-invariants.jsonand create preconditions. - collect_
type_ ๐invariants - Look up the type path in the DB and add instantiated invariants to
results. - instantiate_
entry ๐ - Instantiate a single (non-
any) type invariant entry. - instantiate_
type_ ๐invariant - Create properties from a type invariant entry, substituting the parameter
name (and, for the slice entry, the element type). An entry with an
anyfield expands to a single disjunctiveProperty::Or; otherwise it yields the properties denoted by its tag. - is_
numeric_ ๐field_ access - Check if a string looks like a numeric field access (e.g. โ0โ).
- replace_
expr_ ๐ty - Replace
size_of/align_oftype arguments inside a contract expression. - replace_
pred_ ๐ty - Replace
size_of/align_oftype arguments inside a numeric predicate. - replace_
ty_ ๐args - Replace every type argument in a property tree with the slice element type.
- type_
path_ ๐key - Generate a normalised type path key for lookups in the type-invariants DB, together with the element type for the built-in slice entry.