Skip to content

Commit 06b91c7

Browse files
committed
feat: check json with output of kani list
1 parent 0e127b0 commit 06b91c7

File tree

5 files changed

+74
-4
lines changed

5 files changed

+74
-4
lines changed

src/functions/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ mod cache;
1111
pub use cache::{clear_rustc_ctx, set_rustc_ctx};
1212

1313
mod kani;
14+
1415
mod utils;
16+
pub use utils::vec_convertion;
1517

1618
mod serialization;
1719
pub use serialization::SerFunction;

src/functions/serialization.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,58 @@ impl Kind {
106106
panic!("{attrs:?} doesn't contain a proof kind.")
107107
}
108108
}
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+
}

src/functions/utils.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl SourceCode {
6161

6262
#[derive(Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord, Default)]
6363
pub struct MacroBacktrace {
64-
callsite: String,
65-
defsite: String,
64+
pub callsite: String,
65+
pub defsite: String,
6666
}
6767

6868
fn span_to_source(span: Span, src_map: &SourceMap) -> String {
@@ -123,3 +123,7 @@ pub fn source_code_with(
123123
let kind = format!("{:?}", inst.kind);
124124
SourceCode { name, mangled_name, kind, file, src, macro_backtrace_len, macro_backtrace }
125125
}
126+
127+
pub fn vec_convertion<U, T: From<U>>(vec: Vec<U>) -> Vec<T> {
128+
vec.into_iter().map(T::from).collect()
129+
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ pub struct SourceCode {
7474

7575
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
7676
pub struct MacroBacktrace {
77-
callsite: String,
78-
defsite: String,
77+
pub callsite: String,
78+
pub defsite: String,
7979
}
8080

8181
/// A local path to kani's artifacts.

src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern crate stable_mir;
1414

1515
use distributed_verification::kani_path;
1616
use functions::{clear_rustc_ctx, set_rustc_ctx};
17+
use rustc_middle::ty::TyCtxt;
1718
// FIXME: this is a bug for rustc_smir, because rustc_interface is used by
1819
// run_with_tcx! without being imported inside.
1920
use rustc_smir::rustc_internal;
@@ -78,10 +79,18 @@ fn main() {
7879
};
7980

8081
res().unwrap();
82+
check_kani_list(output, tcx);
8183

8284
// Stop emitting artifact for the source code being compiled.
8385
ControlFlow::<(), ()>::Break(())
8486
});
8587
// rustc_smir uses `Err(CompilerError::Interrupted)` to represent ControlFlow::Break.
8688
assert!(res == Err(stable_mir::CompilerError::Interrupted(())), "Unexpected {res:?}");
8789
}
90+
91+
fn check_kani_list(output: Vec<functions::SerFunction>, tcx: TyCtxt) {
92+
let output: Vec<distributed_verification::SerFunction> = functions::vec_convertion(output);
93+
let crate_file = tcx.sess.local_crate_source_file().expect("No real crate root file.");
94+
let crate_file = crate_file.local_path().unwrap().to_str().unwrap();
95+
distributed_verification::kani_list::check(crate_file, &output);
96+
}

0 commit comments

Comments
 (0)