Expand description
User-defined contract def layer.
Users (downloading a prebuilt rapx binary) can define new named safety
contracts as boolean combinations of the 21 primitive safety properties, and
reference them from #[rapx::requires(MyTag(...))] β without recompiling
rapx.
A def is a DNF macro over primitive property calls:
def MySafeRead(p: Target, T: Ty, n: Expr) =
NonNull(p) && Align(p, T) && Allocated(p, T, n);
def StrOrBytes(s: Target, 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Β§
- DefSpec
- A parsed
defdeclaration. - Subst π
- Substitute def 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Β§
- DefArg
- A single argument in a
defbody: a reference to a formal parameter, or a literal (kept as source text, re-parsed assyn::Exprat expansion time). - DefBody
- The body of a
def, structured as DNF (Or of And of calls).
FunctionsΒ§
- builtin_
defs π - Builtin defs shipped with
rapx: the standard compound safety properties (std-contracts.rs) plus user extensions (user-contracts.rs). - builtin_
defs_ πmap - Builtin defs shipped with
rapx: the standard compound safety properties (std-contracts.rs) plus user extensions (user-contracts.rs). Immutable and shared across every crate. - collect_
def_ πrefs - conv_
def_ πand - conv_
def_ πcall - conv_
def_ πleaf - conv_
def_ πor - def_
refs π - Collect the tag names referenced by a
DefBody, in left-to-right order. - def_
ty_ πmatches_ arg_ kind - Whether a def parameter annotation matches a primitive argument role.
- expand_
body π - Expand a
DefBodyinto the property list it denotes. - expand_
def - Expand a named def against concrete argument expressions.
- extract_
contract_ πdef_ string - Extract the string literal from a
#[rapx::def_contract("def ...")]attributeβs textual representation. - find_
cycle_ πin - find_
def - Look up a
defby name, in the given crateβs namespace first, then the builtin namespace. - find_
def_ cycle - Return a cycle path (e.g.
["A", "B", "A"]) if expandingstartcan reach itself again through def-to-def references,Noneotherwise. - is_
contract_ πdef_ attr - Whether an attribute path is
rapx::def_contract(or the bare form with the tool prefix stripped). - parse_
body π - Parse the body into a DNF tree.
||binds looser than&&. - parse_
defs - Parse a source fragment containing block-shaped contract definitions
(
Name(params) { body }) into a list ofDefSpecs. - parse_
equation_ πparams - parse_
one_ πdef_ block - Parse a single leading
Name(p: Ptr, T: Ty, ...) { body }block froms. Returns theDefSpec(without doc) and the number of bytes consumed through the closing}. - register_
contract_ defs - Scan the local crate for
#[rapx::def_contract("...")]tool attributes (emitted by therapx_macros::predproc-macro) and register each embeddeddefstring. Returns the number of defs registered. - register_
defs_ from_ source - Parse
defdeclarations fromsourceand insert them into the given crateβs namespace. Returns the number of defs 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
def parameterβs declared role so internal placeholders (e.g.
Arg_0from a JSON contract) render as the actual parameter name. - unknown_
property π - user_
defs_ πmap - Per-crate user defs, registered from
#[rapx::def_contract]attributes.