Skip to content

Commit f98ee31

Browse files
committed
fix: strip local path of kani in file path
close #21
1 parent 93ae1a8 commit f98ee31

File tree

8 files changed

+36
-25
lines changed

8 files changed

+36
-25
lines changed

src/functions/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Function {
7575
let attrs = KANI_TOOL_ATTRS.iter().flat_map(|v| inst_def.tool_attrs(v)).collect();
7676

7777
let span = inst_def.span();
78-
let file = span.get_filename();
78+
let file = file_path(&inst);
7979

8080
let fn_def = ty_to_fndef(inst.ty())?;
8181
let body = fn_def.body()?;
@@ -127,8 +127,8 @@ fn source_code_of_body(inst: &Instance, tcx: TyCtxt, src_map: &SourceMap) -> Opt
127127
}
128128

129129
fn cmp_callees(a: &Instance, b: &Instance, tcx: TyCtxt, src_map: &SourceMap) -> Ordering {
130-
let filename_a = a.def.span().get_filename();
131-
let filename_b = b.def.span().get_filename();
130+
let filename_a = file_path(a);
131+
let filename_b = file_path(b);
132132
match filename_a.cmp(&filename_b) {
133133
Ordering::Equal => (),
134134
ord => return ord,
@@ -138,3 +138,14 @@ fn cmp_callees(a: &Instance, b: &Instance, tcx: TyCtxt, src_map: &SourceMap) ->
138138
let body_b = source_code_of_body(b, tcx, src_map);
139139
body_a.cmp(&body_b)
140140
}
141+
142+
fn file_path(inst: &Instance) -> String {
143+
use std::sync::LazyLock;
144+
static PWD: LazyLock<String> = LazyLock::new(|| {
145+
let mut path = std::env::current_dir().unwrap().into_os_string().into_string().unwrap();
146+
path.push('/');
147+
path
148+
});
149+
let file = inst.def.span().get_filename();
150+
file.strip_prefix(&*PWD).map(String::from).unwrap_or(file)
151+
}

src/functions/serialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Callee {
7575
fn new(inst: &Instance, tcx: TyCtxt, src_map: &SourceMap) -> Self {
7676
let inst_def = &inst.def;
7777
let def_id = format_def_id(&inst_def.def_id());
78-
let file = inst_def.span().get_filename();
78+
let file = super::file_path(inst);
7979
let func = super::source_code_of_body(inst, tcx, src_map).unwrap_or_default();
8080
Callee { def_id, file, func }
8181
}

tests/snapshots/contract1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"hash": "1333061076946858250810580638840992453503",
3+
"hash": "115172008545498701307566340849891514113",
44
"def_id": "DefId { id: 13, name: \"verify::f\" }",
55
"file": "tests/compare/contract.rs",
66
"attrs": [
@@ -1220,7 +1220,7 @@
12201220
},
12211221
{
12221222
"def_id": "DefId { id: 14, name: \"kani::panic\" }",
1223-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
1223+
"file": "kani/library/kani_core/src/lib.rs",
12241224
"func": "pub const fn panic(message: &'static str) -> ! {\n panic!(\"{}\", message)\n }"
12251225
},
12261226
{

tests/snapshots/contract2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"hash": "1333061076946858250810580638840992453503",
3+
"hash": "115172008545498701307566340849891514113",
44
"def_id": "DefId { id: 13, name: \"verify::f\" }",
55
"file": "tests/compare/contract.rs",
66
"attrs": [
@@ -1220,7 +1220,7 @@
12201220
},
12211221
{
12221222
"def_id": "DefId { id: 27, name: \"kani::panic\" }",
1223-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
1223+
"file": "kani/library/kani_core/src/lib.rs",
12241224
"func": "pub const fn panic(message: &'static str) -> ! {\n panic!(\"{}\", message)\n }"
12251225
},
12261226
{

tests/snapshots/proof1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"hash": "1080390447388388208111011526646376797302",
3+
"hash": "323435775406490987911952280202009855384",
44
"def_id": "DefId { id: 0, name: \"verify::f\" }",
55
"file": "tests/compare/proof.rs",
66
"attrs": [
@@ -10,7 +10,7 @@
1010
"callees": [
1111
{
1212
"def_id": "DefId { id: 1, name: \"kani::assert\" }",
13-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
13+
"file": "kani/library/kani_core/src/lib.rs",
1414
"func": "pub const fn assert(cond: bool, msg: &'static str) {\n let _ = cond;\n let _ = msg;\n }"
1515
}
1616
]

tests/snapshots/proof2.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"hash": "1080390447388388208111011526646376797302",
3+
"hash": "323435775406490987911952280202009855384",
44
"def_id": "DefId { id: 0, name: \"verify::f\" }",
55
"file": "tests/compare/proof.rs",
66
"attrs": [
@@ -10,13 +10,13 @@
1010
"callees": [
1111
{
1212
"def_id": "DefId { id: 2, name: \"kani::assert\" }",
13-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
13+
"file": "kani/library/kani_core/src/lib.rs",
1414
"func": "pub const fn assert(cond: bool, msg: &'static str) {\n let _ = cond;\n let _ = msg;\n }"
1515
}
1616
]
1717
},
1818
{
19-
"hash": "111100297692849598313316231646472092130",
19+
"hash": "93182050081686602881562663240458408606",
2020
"def_id": "DefId { id: 1, name: \"verify::g\" }",
2121
"file": "tests/compare/proof.rs",
2222
"attrs": [
@@ -26,7 +26,7 @@
2626
"callees": [
2727
{
2828
"def_id": "DefId { id: 2, name: \"kani::assert\" }",
29-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
29+
"file": "kani/library/kani_core/src/lib.rs",
3030
"func": "pub const fn assert(cond: bool, msg: &'static str) {\n let _ = cond;\n let _ = msg;\n }"
3131
}
3232
]

tests/snapshots/standard_proofs.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"callees": []
1111
},
1212
{
13-
"hash": "598200882196848966016444482128164260930",
13+
"hash": "1326945528524461068796384134380740941",
1414
"def_id": "DefId { id: 0, name: \"verify::standard_proof\" }",
1515
"file": "tests/proofs/standard_proofs.rs",
1616
"attrs": [
@@ -20,32 +20,32 @@
2020
"callees": [
2121
{
2222
"def_id": "DefId { id: 8, name: \"<u8 as kani::Arbitrary>::any\" }",
23-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/arbitrary.rs",
23+
"file": "kani/library/kani_core/src/arbitrary.rs",
2424
"func": "fn any() -> Self {\n // This size_of call does not use generic_const_exprs feature. It's inside a macro, and Self isn't generic.\n unsafe { crate::kani::any_raw_internal::<Self>() }\n }"
2525
},
2626
{
2727
"def_id": "DefId { id: 10, name: \"kani::any_raw\" }",
28-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
28+
"file": "kani/library/kani_core/src/lib.rs",
2929
"func": "fn any_raw<T: Copy>() -> T {\n kani_intrinsic()\n }"
3030
},
3131
{
3232
"def_id": "DefId { id: 11, name: \"kani::kani_intrinsic\" }",
33-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
33+
"file": "kani/library/kani_core/src/lib.rs",
3434
"func": "fn kani_intrinsic<T>() -> T {\n #[allow(clippy::empty_loop)]\n loop {}\n }"
3535
},
3636
{
3737
"def_id": "DefId { id: 6, name: \"kani::assert\" }",
38-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
38+
"file": "kani/library/kani_core/src/lib.rs",
3939
"func": "pub const fn assert(cond: bool, msg: &'static str) {\n let _ = cond;\n let _ = msg;\n }"
4040
},
4141
{
4242
"def_id": "DefId { id: 5, name: \"kani::any\" }",
43-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
43+
"file": "kani/library/kani_core/src/lib.rs",
4444
"func": "pub fn any<T: Arbitrary>() -> T {\n T::any()\n }"
4545
},
4646
{
4747
"def_id": "DefId { id: 9, name: \"kani::any_raw_internal\" }",
48-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
48+
"file": "kani/library/kani_core/src/lib.rs",
4949
"func": "unsafe fn any_raw_internal<T: Copy>() -> T {\n any_raw::<T>()\n }"
5050
}
5151
]

tests/snapshots/standard_proofs_with_contracts.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"hash": "1025309838735755950413656814657831068918",
3+
"hash": "1720175471726112845615145613787907368267",
44
"def_id": "DefId { id: 13, name: \"verify::standard_proof_with_contract_requires\" }",
55
"file": "tests/proofs/standard_proofs_with_contracts.rs",
66
"attrs": [
@@ -1220,7 +1220,7 @@
12201220
},
12211221
{
12221222
"def_id": "DefId { id: 33, name: \"kani::panic\" }",
1223-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
1223+
"file": "kani/library/kani_core/src/lib.rs",
12241224
"func": "pub const fn panic(message: &'static str) -> ! {\n panic!(\"{}\", message)\n }"
12251225
},
12261226
{
@@ -1256,7 +1256,7 @@
12561256
]
12571257
},
12581258
{
1259-
"hash": "1317424779862856706714064197163667502053",
1259+
"hash": "176046216958037015626605244695592309696",
12601260
"def_id": "DefId { id: 32, name: \"verify::standard_proof_with_contract_ensures\" }",
12611261
"file": "tests/proofs/standard_proofs_with_contracts.rs",
12621262
"attrs": [
@@ -2476,7 +2476,7 @@
24762476
},
24772477
{
24782478
"def_id": "DefId { id: 33, name: \"kani::panic\" }",
2479-
"file": "/home/zjp/rust/distributed-verification/kani/library/kani_core/src/lib.rs",
2479+
"file": "kani/library/kani_core/src/lib.rs",
24802480
"func": "pub const fn panic(message: &'static str) -> ! {\n panic!(\"{}\", message)\n }"
24812481
},
24822482
{

0 commit comments

Comments
 (0)