Expand description
User-defined compound-contract layer.
Users (downloading a prebuilt rapx binary) can define new named safety
contracts as boolean combinations of the primitive safety properties, and
reference them from #[rapx::requires(MyTag(...))] β without recompiling
rapx.
A compound property is a DNF macro over primitive property calls:
MySafeRead(p: Ptr, T: Ty, n: Expr) {
NonNull(p) && Align(p, T) && Allocated(p, T, n)
}
StrOrBytes(s: Ptr, T: Ty, n: Expr) {
ValidCStr(s, n) || (Allocated(s, T, n) && Init(s, T, n))
}The DSL only composes existing primitives; it cannot invent new primitive
semantics (those live in property_checker.rs). Expansion is a pure
front-end that produces ordinary Property values consumed by the existing
checker.
StructsΒ§
- Compound
Spec π - A parsed compound-property declaration.
- Subst π
- Substitute compound formal parameters with the concrete call-site arguments inside
a literal expression (e.g. turn
size_of(T) * nintosize_of(u32) * len, orp.unwrap_some()intohead.unwrap_some()).
EnumsΒ§
- Compound
Arg π - A single argument in a compound body: a reference to a formal parameter, or a
literal (kept as source text, re-parsed as
syn::Exprat expansion time). - Compound
Body π - The body of a compound property: a boolean tree over primitive-property
calls (
Callleaves), freely nested viaAnd/Or. The DSL&&/||grammar permits arbitrary nesting (anAndmay contain anOrand vice versa), so this is not constrained to DNF;expand_compound_bodyrecurses over whatever shape was parsed.
FunctionsΒ§
- builtin_
compounds π - Builtin compounds shipped with
rapx: the standard compound safety properties (std-compound-properties.rs) plus user extensions (user-compound-properties.rs). - builtin_
compounds_ πmap - Cached, shared builtin compound map (see
builtin_compounds). - builtin_
subsumptions_ πmap - Cached builtin subsumption map (see
subsumption_closure). - collect_
compound_ πrefs - compound_
param_ πty_ matches_ arg_ kind - Whether a compound parameter annotation matches a primitive argument role.
- compound_
refs π - Collect the tag names referenced by a
CompoundBody, in left-to-right order. - expand_
compound π - Expand a named compound against concrete argument expressions.
- expand_
compound_ πbody - Expand a
CompoundBodyinto the property list it denotes. - extract_
def_ πproperty_ string - Extract the string literal from a
#[rapx::def_property("compound ...")]attributeβs textual representation. - find_
compound π - Look up a compound property by name, in the given crateβs namespace first, then the builtin namespace.
- find_
compound_ πcycle - Return a cycle path (e.g.
["A", "B", "A"]) if expandingstartcan reach itself again through compound-to-compound references,Noneotherwise. - find_
cycle_ πin - flatten_
subsumption_ πbody - Flatten a subsumption body (a pure conjunction of primitive calls) into a
list of
(tag, args)pairs. - is_
def_ πproperty_ attr - Whether an attribute path is
rapx::def_property(or the bare form with the tool prefix stripped). - parse_
compounds π - Parse a source fragment containing block-shaped contract definitions
(
Name(params) { body }) into a list ofCompoundSpecs. - parse_
equation_ πparams - parse_
one_ πcompound_ block - Parse a single leading
Name(p: Ptr, T: Ty, ...) { body }block froms. Returns theCompoundSpec(without doc) and the number of bytes consumed through the closing}. - register_
compound_ πproperties - Scan the local crate for
#[rapx::def_property("...")]tool attributes (emitted by therapx_macros::predproc-macro) and register each embedded compound-property string. Returns the number of compounds registered. - register_
compounds_ πfrom_ source - Parse compound-property declarations from
sourceand insert them into the given crateβs namespace. Returns the number of compounds registered. - render_
expr_ πsrc - Render a
syn::Exprback to source-like text.proc_macro2stringifies tokens space-separated (self . 0,size_of (T)), so collapse the spaces around punctuation for a readable form. - resolve_
arg_ πstring - Resolve a call-site argument expression to its display form, following the
compound parameterβs declared role so internal placeholders (e.g.
Arg_0from a JSON contract) render as the actual parameter name. - resolve_
subsumption_ πargs - Resolve a subsumption bodyβs
(tag, args)β whoseargsareParam(i)indices intoatomβs own arguments β into concretePropertyArgs. - subsumption_
closure π - Apply the builtin subsumption rules to an asserted fact: a stronger
primitive also asserts its weaker consequences β a one-way weakening, unlike
the
β‘compound equivalences above. The rules are declared declaratively instd-subsumption.rswith the sameName(params) { body }syntax; the head is an existing primitive tag and the body a pure conjunction of weaker primitive calls whose parameters map positionally to the headβs arguments (e.g.Init(p, T, n) β Typed(p, T)). Pointer-validity primitives (NonNull/Allocated/InBound) are deliberately not implied: they are orthogonal requirements stated explicitly by contracts. - unknown_
property π - user_
compounds_ πmap - Per-crate user compounds, registered from
#[rapx::def_property]attributes.