Macro exec_spec_verified
exec_spec_verified!() { /* proc-macro */ }Expand description
Automatically compiles spec items to exec items, with proofs of functional correctness.
This macro takes a list of spec items, and generates a corresponding list of exec items:
- For every struct/enum
A, we generateExecA, which implementsDeepView<V = A> - For every spec function
spec fn f(T) -> U, we generateⓘwherefn exec_f(a: exec(T)) -> (r: exec(U)) ensures r.deep_view() == f(a.deep_view()) { ... }exec(T)maps a subset of supported spec types to exec types, includingSeq(translated toVec) andOption.
Below is a non-exhaustive list of supported spec expressions. Items marked with a * utilize unverified translations from spec to exec code internally.
- Basic arithmetic operations
- Logical operators (&&, ||, &&&, |||, not, ==>)
- If, match and “matches”
- Field expressions
- Bounded quantifiers of the form
forall |i: <type>| <lower> <op> i <op> <upper> ==> <expr>andexists |i: <type>| <lower> <op> i <op> <upper> && <expr>, where:<op>is either<=or<<type>is a Rust primitive integer (i<N>,isize,u<N>,usize)
SpecString(an alias toSeq<char>to syntactically indicate that we wantString/&str), equality*, indexing, len, string literalsOption<T>with these functions:- equality,
unwrap
- equality,
Seq<T>(compiled toVec<T>or&[T]depending on the context),seq!literals, and theseSeqfunctions:- equality*,
len, indexing,subrange*,add*,push*,update*,empty,to_multiset*,drop_first*,drop_last*,take*,skip*,first,last,is_suffix_of*,is_prefix_of*,contains*,index_of*,index_of_first*,index_of_last*
- equality*,
Map<K, V>(compiled toHashMap<K, V>), and theseMapfunctions:- equality*,
len*, indexing*,empty,dom*,insert*,remove*,get* - Note: indexing is only supported on
Map<K, V>whereKis a primitive type (e.g.usize); for other typesK, usegetinstead.
- equality*,
Set<T>(compiled toHashSet<T>), and theseSetfunctions:- equality*,
len*,empty,contains*,insert*,remove*,union*,intersect*,difference*
- equality*,
Multiset<T>(compiled toExecMultiset<T>, a type implemented invstd::contrib::exec_specwhose internal representation is aHashMap), and theseMultisetfunctions:- equality*,
len*,count*,empty*,singleton*,add*,sub*
- equality*,
- User-defined structs and enums. These types should be defined within the macro using spec-compatible types for the fields (e.g.
Seq). Such types are then compiled to theirExec-versions, which use the exec versions of each field’s type (e.g.Vec/slice). - Primitive integer/boolean types (
i<N>,isize,u<N>,usize,char, etc.). Note thatintandnatcannot be used inexec_spec_verified!.