Skip to content

Commit f124b25

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents 73067d8 + 2c38e95 commit f124b25

File tree

30 files changed

+400
-22
lines changed

30 files changed

+400
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ __pycache__/
33
.coverage
44
/deps/.stable-mir-json
55
/.vscode/
6+
kmir/src/tests/integration/data/**/target

kmir/src/kmir/cargo.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ def smir_for_project(self, clean: bool = False) -> SMIRInfo:
9090

9191
messages = [json.loads(line) for line in command_result.stdout.splitlines()]
9292

93+
if command_result.returncode != 0:
94+
_LOGGER.error('Cargo compilation failed!')
95+
for msg in [m['message'] for m in messages if m.get('reason') == 'compiler-message']:
96+
_LOGGER.error(msg['level'] + '\n' + msg['rendered'])
97+
raise Exception('Cargo compilation failed')
98+
9399
artifacts = [
94100
(Path(message['filenames'][0]), message['target']['kind'][0])
95101
for message in messages
@@ -100,7 +106,6 @@ def smir_for_project(self, clean: bool = False) -> SMIRInfo:
100106
exe = None
101107
for file, kind in artifacts:
102108
_LOGGER.debug(f'Artifact ({kind}) at ../{file.parent.name}/{file.name}')
103-
in_deps = file.parent.name == 'deps'
104109
if kind == 'bin':
105110
# we can only support a single executable at the moment
106111
if exe is not None:
@@ -109,14 +114,22 @@ def smir_for_project(self, clean: bool = False) -> SMIRInfo:
109114
'Several execuatbles not supported at the moment.'
110115
)
111116
exe = file.name
112-
# executables are in the target directory and do not have a suffix as in `deps`
113-
related_files = list((file.parent / 'deps').glob(f'{file.name}*.smir.json'))
114-
targets.append(related_files[0])
117+
glob = exe.replace('-', '_') + '-*.smir.json'
118+
# executables are in the target directory with the crate name and have a hex ID suffix in `deps`
119+
location = file.parent / 'deps'
115120
else:
116-
# lib, rlib, dylib, cdylib may be in `deps` or in target and have consistent names
117-
name = file.stem.removeprefix('lib') + '.smir.json'
121+
# lib, rlib, dylib, cdylib may be in `deps` or in target and have prefix 'lib'
122+
in_deps = file.parent.name == 'deps'
118123
location = file.parent if in_deps else file.parent / 'deps'
119-
targets.append(location / name)
124+
# files for lib and rlib require a hex ID suffix unless in `deps`, *.dylib (or *.so) ones don't
125+
is_rlib = file.suffix == '.rlib'
126+
glob = file.stem.removeprefix('lib') + ('' if in_deps or not is_rlib else '-*') + '.smir.json'
127+
128+
related_files = list(location.glob(glob))
129+
if not related_files:
130+
_LOGGER.error('SMIR JSON files not found after building, you must run `cargo clean` and rebuild.')
131+
raise FileNotFoundError(f'{location}/{glob}')
132+
targets.append(related_files[0])
120133

121134
_LOGGER.debug(f'Files: {targets}')
122135

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
┌─ 1 (root, init)
3+
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
4+
│ span: 0
5+
6+
│ (42 steps)
7+
├─ 3 (split)
8+
│ #expect ( typedValue ( BoolVal ( notBool ARG_UINT1:Int +Int ARG_UINT1:Int &Int 1
9+
10+
┃ (branch)
11+
┣━━┓ subst: .Subst
12+
┃ ┃ constraint:
13+
┃ ┃ notBool notBool ARG_UINT1:Int +Int ARG_UINT1:Int &Int 18446744073709551615 ==Int ARG_UINT1:Int +Int ARG_UINT1:Int ==Bool false
14+
┃ │
15+
┃ ├─ 4
16+
┃ │ #expect ( typedValue ( BoolVal ( notBool ARG_UINT1:Int +Int ARG_UINT1:Int &Int 1
17+
┃ │
18+
┃ │ (2 steps)
19+
┃ └─ 6 (stuck, leaf)
20+
┃ #ProgramError ( AssertError ( assertMessageOverflow ( binOpAdd , operandCopy ( p
21+
22+
┗━━┓ subst: .Subst
23+
┃ constraint:
24+
┃ notBool ARG_UINT1:Int +Int ARG_UINT1:Int &Int 18446744073709551615 ==Int ARG_UINT1:Int +Int ARG_UINT1:Int ==Bool false
25+
26+
├─ 5
27+
│ #expect ( typedValue ( BoolVal ( notBool ARG_UINT1:Int +Int ARG_UINT1:Int &Int 1
28+
29+
│ (21 steps)
30+
├─ 7 (terminal)
31+
│ #EndProgram ~> .K
32+
33+
┊ constraint: true
34+
┊ subst: ...
35+
└─ 2 (leaf, target, terminal)
36+
#EndProgram ~> .K
37+
38+
39+

kmir/src/tests/integration/data/crate-tests/single-bin/main-crate/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "single-exe"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub fn add(left: u64, right: u64) -> u64 {
2+
left + right
3+
}
4+
5+
pub mod a_module {
6+
use super::add;
7+
8+
pub fn twice(x: u64) -> u64{
9+
add(x, x)
10+
}
11+
}
12+
13+
pub fn main() {
14+
let x = 42;
15+
assert_eq!(a_module::twice(x), 2 * x);
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
┌─ 1 (root, init)
3+
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
4+
│ span: 0
5+
6+
│ (219 steps)
7+
├─ 3 (terminal)
8+
│ #EndProgram ~> .K
9+
│ function: main
10+
11+
┊ constraint: true
12+
┊ subst: ...
13+
└─ 2 (leaf, target, terminal)
14+
#EndProgram ~> .K
15+
16+
17+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
┌─ 1 (root, init)
3+
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
4+
│ span: 0
5+
6+
│ (34 steps)
7+
├─ 3 (split)
8+
│ #expect ( typedValue ( BoolVal ( notBool ARG_UINT1:Int +Int ARG_UINT2:Int &Int 1
9+
10+
┃ (branch)
11+
┣━━┓ subst: .Subst
12+
┃ ┃ constraint:
13+
┃ ┃ notBool notBool ARG_UINT1:Int +Int ARG_UINT2:Int &Int 18446744073709551615 ==Int ARG_UINT1:Int +Int ARG_UINT2:Int ==Bool false
14+
┃ │
15+
┃ ├─ 4
16+
┃ │ #expect ( typedValue ( BoolVal ( notBool ARG_UINT1:Int +Int ARG_UINT2:Int &Int 1
17+
┃ │
18+
┃ │ (2 steps)
19+
┃ └─ 6 (stuck, leaf)
20+
┃ #ProgramError ( AssertError ( assertMessageOverflow ( binOpAdd , operandCopy ( p
21+
22+
┗━━┓ subst: .Subst
23+
┃ constraint:
24+
┃ notBool ARG_UINT1:Int +Int ARG_UINT2:Int &Int 18446744073709551615 ==Int ARG_UINT1:Int +Int ARG_UINT2:Int ==Bool false
25+
26+
├─ 5
27+
│ #expect ( typedValue ( BoolVal ( notBool ARG_UINT1:Int +Int ARG_UINT2:Int &Int 1
28+
29+
│ (16 steps)
30+
├─ 7 (terminal)
31+
│ #EndProgram ~> .K
32+
33+
┊ constraint: true
34+
┊ subst: ...
35+
└─ 2 (leaf, target, terminal)
36+
#EndProgram ~> .K
37+
38+
39+

kmir/src/tests/integration/data/crate-tests/single-dylib/main-crate/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "small-test-dylib"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
name = "small_test_dylib"
8+
path = "src/lib.rs" # The source file of the target.
9+
test = false # Is tested by default.
10+
doctest = false # Documentation examples are tested by default.
11+
bench = false # Is benchmarked by default.
12+
doc = false # Is documented by default.
13+
crate-type = ["dylib"] # The crate types to generate.
14+
15+
[dependencies]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use std::process::exit;
2+
3+
pub fn add(left: u64, right: u64) -> u64 {
4+
left + right
5+
}
6+
7+
fn assume(cond: bool) {
8+
if !cond { exit(0); }
9+
}
10+
11+
// must call test_add_in_range for it to be discovered by linker
12+
pub fn expose_test() {
13+
testing::test_add_in_range(0, 0);
14+
}
15+
16+
17+
18+
pub mod testing {
19+
use super::*;
20+
21+
pub fn test_add_in_range(left: u64, right: u64) {
22+
let sum = left as u128 + right as u128;
23+
assume(sum <= u64::MAX as u128);
24+
let result = add(left, right);
25+
26+
assert_eq!(result as u128, sum)
27+
}
28+
}

kmir/src/tests/integration/data/crate-tests/single-lib/main-crate/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "small-test-lib"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use std::process::exit;
2+
3+
pub fn add(left: u64, right: u64) -> u64 {
4+
left + right
5+
}
6+
7+
fn assume(cond: bool) {
8+
if !cond { exit(0); }
9+
}
10+
11+
// must call test_add_in_range for it to be discovered by linker
12+
pub fn expose_test() {
13+
testing::test_add_in_range(0, 0);
14+
}
15+
16+
17+
18+
pub mod testing {
19+
use super::*;
20+
21+
pub fn test_add_in_range(left: u64, right: u64) {
22+
let sum = left as u128 + right as u128;
23+
assume(sum <= u64::MAX as u128);
24+
let result = add(left, right);
25+
26+
assert_eq!(result as u128, sum)
27+
}
28+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
┌─ 1 (root, init)
3+
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
4+
│ span: 0
5+
6+
│ (112 steps)
7+
├─ 3 (split)
8+
│ #selectBlock ( switchTargets ( ... branches: branch ( 0 , basicBlockIdx ( 1 ) )
9+
10+
┃ (branch)
11+
┣━━┓ subst: .Subst
12+
┃ ┃ constraint:
13+
┃ ┃ notBool ARG_UINT1:Int +Int 340282366920938463463374607431768211456 %Int 340282366920938463463374607431768211456 +Int ARG_UINT2:Int +Int 340282366920938463463374607431768211456 %Int 340282366920938463463374607431768211456 <=Int 18446744073709551615
14+
┃ │
15+
┃ ├─ 4
16+
┃ │ #selectBlock ( switchTargets ( ... branches: branch ( 0 , basicBlockIdx ( 1 ) )
17+
┃ │
18+
┃ │ (4 steps)
19+
┃ └─ 6 (stuck, leaf)
20+
┃ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
21+
┃ span: 72
22+
23+
┗━━┓ subst: .Subst
24+
┃ constraint:
25+
┃ ARG_UINT1:Int +Int 340282366920938463463374607431768211456 %Int 340282366920938463463374607431768211456 +Int ARG_UINT2:Int +Int 340282366920938463463374607431768211456 %Int 340282366920938463463374607431768211456 <=Int 18446744073709551615
26+
27+
├─ 5
28+
│ #selectBlock ( switchTargets ( ... branches: branch ( 0 , basicBlockIdx ( 1 ) )
29+
30+
│ (175 steps)
31+
├─ 7 (terminal)
32+
│ #EndProgram ~> .K
33+
34+
┊ constraint: true
35+
┊ subst: ...
36+
└─ 2 (leaf, target, terminal)
37+
#EndProgram ~> .K
38+
39+
40+

kmir/src/tests/integration/data/crate-tests/two-crate-dylib/crate1/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "crate1"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
pub fn add(left: isize, right: isize) -> isize {
2+
left + right
3+
}
4+
5+
#[derive(Clone, Copy)]
6+
pub struct MyStruct {
7+
pub int_field: isize,
8+
pub enum_field: MyEnum,
9+
pub option_field: Option<MyEnum>
10+
}
11+
12+
impl MyStruct {
13+
pub fn new(i: isize, e: Option<MyEnum>) -> Self {
14+
let enum_field = e.unwrap_or(MyEnum::Foo);
15+
MyStruct { int_field: add(i, 0), enum_field, option_field: e }
16+
}
17+
}
18+
19+
#[derive(Clone, Copy)]
20+
pub enum MyEnum {
21+
Foo,
22+
Bar(isize)
23+
}
24+
25+
impl MyEnum {
26+
pub fn default() -> Self { Self::Bar(42) }
27+
}
28+
29+
#[cfg(test)]
30+
mod tests {
31+
use super::*;
32+
33+
#[test]
34+
fn it_works() {
35+
let result = add(2, 2);
36+
assert_eq!(result, 4);
37+
}
38+
}

kmir/src/tests/integration/data/crate-tests/two-crate-dylib/main-crate/Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)