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 join declared invariants on a verification target. Their entry
facts are synthesized by the VMβs init_parameters and re-proved at return
by FunctionVerifier::verify_invariants.
Re-exportsΒ§
use crate::def_ids::type_ids;πuse crate::util::fn_info;πuse crate::util::mir_utils;πuse rustc_hir::def_id::DefId;πuse rustc_middle::ty;πuse rustc_middle::ty::Ty;πuse rustc_middle::ty::TyCtxt;πuse crate::contract::json::AnyItem;πuse crate::contract::ContractExpr;πuse crate::contract::ContractPlace;πuse crate::contract::ContractProjection;πuse crate::contract::NumericPredicate;πuse crate::contract::PlaceBase;πuse crate::contract::Property;πuse crate::contract::PropertyArg;πuse crate::contract::PropertyKind;π
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_ for_ ty - 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. - constructor_
result_ πhas_ invariant - Whether a constructor directly returns its owning ADT with a declared invariant.
- contract_
place_ πty - has_
json_ πtype_ invariants - has_
owner_ πptr_ invariant - Whether the containerβs pointer field has an
AllocatedorOwninginvariant. - 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_
vec_ πcapacity_ bound - 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.
- resolve_
pointer_ πwrapper_ target - transparent_
nonnull_ πpath - 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.