Expand description
Contract IR and type invariants.
Inline attributes, embedded JSON, and pred!-style compound properties
produce the contract IR defined here. Attribute and JSON arguments are parsed
as syn expressions; compound bodies use the pest grammar.
type_invariants synthesizes properties for known types.
§Layering
Contracts go through two stages, each with its own type:
attribute ──▶ AttrProperty ─┐
JSON ───────▶ JsonProperty ─┴──▶ builder.rs ──▶ Property (Atom | And | Or)
pred! ──────▶ CompoundSpec ─────▶ compound.rs ─▶ PropertyProperty::parse_list dispatches compound tags to compound::expand_compound;
their CompoundSpec bypasses the primitive property builder.
Within the resolved IR, the naming follows granularity rather than stage:
Property* names the formula level (Property, PropertyKind,
PropertyArg), while Contract* names the expression sub-language used by
PropertyArg::Expr and PropertyArg::ForEach (ContractPlace, ContractExpr,
ContractProjection).
Re-exports§
use rustc_hir::def_id::DefId;🔒use rustc_middle::mir::Local;🔒use rustc_middle::ty::Region;🔒use rustc_middle::ty::Ty;🔒
Modules§
- annotation 🔒
- Contract annotations on functions and structs.
- attr 🔒
- Parsing utilities for RAPx contract attributes.
- builder 🔒
- Assemble a safety tag into a
Propertyvia the declarative spec table. - compound 🔒
- User-defined compound-contract layer.
- ensures 🔒
- Trait-method and foreign-call postcondition lookup.
- json 🔒
- The bundled JSON contract front-end: loading, lookup, and conversion.
- pest 🔒
- pest parser and semantic converter for the contract DSL.
- place 🔒
- Place resolution:
syn::Expr→ContractPlace. - render 🔒
- User-facing rendering of contract data structures.
- resolve 🔒
- Expression / argument resolution:
syn::Expr→ semantic values. - spec 🔒
- Declaration table mapping tag names to their property specs.
- type_
invariants 🔒 - Standard-library type-invariant generation.
Structs§
- AndProperty 🔒
- A conjunction: every
conjunctsmember must hold. - Atom
Property 🔒 - Contract
Origin 🔒 - Display metadata for a property expanded from a compound property
(
pred!-style macro). Purely presentational: it lets reports render a macro-expanded contract as a singlename(args)entry with its doc-derived meaning, instead of the underlying primitives it expanded into. - Contract
Place 🔒 - A place a contract refers to: a
PlaceBaseroot plus a sequence ofContractProjectionsteps into it (e.g.self.next.value). - Numeric
Predicate 🔒 - OrProperty 🔒
- A disjunction: at least one
disjunctsmember must hold.
Enums§
- BinOp 🔒
- Contract
Expr 🔒 - Contract
Kind 🔒 - Contract
Projection 🔒 - A step into a place, from the base down to the value a contract talks
about (written as
.field,.unwrap_some(), or.iter()in the DSL). - Place
Base 🔒 - The root of a contract place: a function’s return value, an argument, or a
raw MIR local.
Return⇔Local(0);Arg(n)⇔Local(n + 1). - Property 🔒
- A safety property: a boolean formula over atomic predicates.
- Property
Arg 🔒 - One argument of a predicate call — what the property is applied to.
- Property
Kind 🔒 - The vocabulary of safety predicates a contract can assert.
- RelOp 🔒
- UnaryOp 🔒
Constants§
- STATIC_
LIFETIME_ 🔒IDENT - The
Identa contract uses for the'staticlifetime.'staticis a Rust keyword, so after the leading'is stripped it cannot be a plain ident token; the attribute and JSON parsers map it to this name.
Functions§
- is_
static_ 🔒lifetime_ ident - Whether a contract lifetime ident is the keyword-safe
'staticplaceholder.