Skip to main content

Module type_invariants

Module type_invariants 

Source
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 $elem token before parsing. The JSON $elem is 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 by replace_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.json and 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 Allocated or Owning invariant.
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 any field expands to a single disjunctive Property::Or; otherwise it yields the properties denoted by its tag.
is_vec_capacity_bound πŸ”’
replace_expr_ty πŸ”’
Replace size_of/align_of type arguments inside a contract expression.
replace_pred_ty πŸ”’
Replace size_of/align_of type 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.