@@ -4,7 +4,7 @@ use serde::Serialize;
44use stable_mir:: { CrateDef , mir:: mono:: Instance } ;
55use std:: { cmp:: Ordering , hash:: Hasher } ;
66
7- /// A Rust funtion with its file source, attributes, and raw function content.
7+ /// A kani proof with its file source, attributes, and raw function content.
88#[ derive( Debug , Serialize ) ]
99pub struct SerFunction {
1010 hash : String ,
@@ -13,6 +13,8 @@ pub struct SerFunction {
1313 /// Attributes are attached the function, but it seems that attributes
1414 /// and function must be separated to query.
1515 attrs : Vec < String > ,
16+ /// Proof kind
17+ kind : Kind ,
1618 /// Raw function string, including name, signature, and body.
1719 func : SourceCode ,
1820 /// Count of callees.
@@ -26,6 +28,7 @@ impl SerFunction {
2628 let inst = fun. instance ;
2729 let def_id = format_def_id ( & inst) ;
2830 let attrs: Vec < _ > = fun. attrs . iter ( ) . map ( |a| a. as_str ( ) . to_owned ( ) ) . collect ( ) ;
31+ let kind = Kind :: new ( & attrs) ;
2932 // Though this is from body span, fn name and signature are included.
3033 let func = cache:: get_source_code ( & inst) . unwrap_or_default ( ) ;
3134 let callees: Vec < _ > = fun. callees . iter ( ) . map ( Callee :: new) . collect ( ) ;
@@ -40,7 +43,7 @@ impl SerFunction {
4043 callees. iter ( ) . for_each ( |callee| callee. func . with_hasher ( & mut hasher) ) ;
4144 let Hash128 ( hash) = hasher. finish ( ) ;
4245
43- SerFunction { hash, def_id, attrs, func, callees_len, callees }
46+ SerFunction { hash, def_id, attrs, kind , func, callees_len, callees }
4447 }
4548
4649 /// Compare by file and func string.
@@ -78,3 +81,83 @@ impl Callee {
7881 Callee { def_id, func }
7982 }
8083}
84+
85+ /// kani proof kind
86+ #[ derive( Debug , Serialize ) ]
87+ pub enum Kind {
88+ /// `#[kani::proof]` (actually `kanitool::proof`)
89+ Standard ,
90+ /// `#[kani::proof_for_contract]` (actually `kanitool::proof_for_contract`)
91+ Contract ,
92+ }
93+
94+ impl Kind {
95+ /// ## Panic
96+ ///
97+ /// The given attributes must contain one of the proof kind macro.
98+ fn new ( attrs : & [ String ] ) -> Self {
99+ for attr in attrs {
100+ if attr. contains ( "kanitool::proof_for_contract" ) {
101+ return Kind :: Contract ;
102+ } else if attr. contains ( "kanitool::proof" ) {
103+ return Kind :: Standard ;
104+ }
105+ }
106+ panic ! ( "{attrs:?} doesn't contain a proof kind." )
107+ }
108+ }
109+
110+ /// Convertion from lib's SerFunction into the counterpart in main.rs
111+ mod conversion {
112+ use super :: * ;
113+ use crate :: functions:: utils:: { MacroBacktrace , vec_convertion} ;
114+ use distributed_verification as lib;
115+
116+ impl From < SerFunction > for lib:: SerFunction {
117+ fn from ( value : SerFunction ) -> Self {
118+ let SerFunction { hash, def_id, attrs, kind, func, callees_len, callees } = value;
119+ let func = func. into ( ) ;
120+ let kind = kind. into ( ) ;
121+ let callees = vec_convertion ( callees) ;
122+ Self { hash, def_id, attrs, kind, func, callees_len, callees }
123+ }
124+ }
125+
126+ impl From < Kind > for lib:: Kind {
127+ fn from ( value : Kind ) -> Self {
128+ match value {
129+ Kind :: Standard => Self :: Standard ,
130+ Kind :: Contract => Self :: Contract ,
131+ }
132+ }
133+ }
134+
135+ impl From < Callee > for lib:: Callee {
136+ fn from ( Callee { def_id, func } : Callee ) -> Self {
137+ let func = func. into ( ) ;
138+ Self { def_id, func }
139+ }
140+ }
141+
142+ impl From < SourceCode > for lib:: SourceCode {
143+ fn from ( value : SourceCode ) -> Self {
144+ let SourceCode {
145+ name,
146+ mangled_name,
147+ kind,
148+ file,
149+ src,
150+ macro_backtrace_len,
151+ macro_backtrace,
152+ } = value;
153+ let macro_backtrace = vec_convertion ( macro_backtrace) ;
154+ Self { name, mangled_name, kind, file, src, macro_backtrace_len, macro_backtrace }
155+ }
156+ }
157+
158+ impl From < MacroBacktrace > for lib:: MacroBacktrace {
159+ fn from ( MacroBacktrace { callsite, defsite } : MacroBacktrace ) -> Self {
160+ Self { callsite, defsite }
161+ }
162+ }
163+ }
0 commit comments