From 5de30755f3e7d6cbcd4d3cf7a35048dc51745758 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Tue, 27 Aug 2024 09:55:08 +1000 Subject: [PATCH 01/30] Add Rust test programs from prior repo to test data --- .../integration/data/run-rs/arrays/array.rs | 5 ++ .../data/run-rs/assert/assert_eq.rs | 6 ++ .../data/run-rs/closures/closure-args.rs | 5 ++ .../data/run-rs/closures/closure-no-args.rs | 5 ++ .../integration/data/run-rs/enums/enum.rs | 8 ++ .../integration/data/run-rs/floats/float.rs | 11 +++ .../data/run-rs/functions/sum-to-n.rs | 23 ++++++ .../data/run-rs/generics/generic.rs | 14 ++++ .../integration/data/run-rs/integers/binop.rs | 74 +++++++++++++++++++ .../run-rs/integers/const-arithm-simple.rs | 12 +++ .../integration/data/run-rs/integers/div.rs | 3 + .../data/run-rs/integers/modulo.rs | 3 + .../run-rs/integers/primitive-type-bounds.rs | 5 ++ .../data/run-rs/integers/shl_min.rs | 7 ++ .../integration/data/run-rs/memory/box.rs | 9 +++ .../data/run-rs/option/option-construction.rs | 5 ++ .../data/run-rs/recursion/fibonacci.rs | 13 ++++ .../data/run-rs/recursion/mutual_recursion.rs | 21 ++++++ .../recursion/recursion-simple-match.rs | 12 +++ .../data/run-rs/recursion/recursion-simple.rs | 13 ++++ .../data/run-rs/ref-deref/double-ref-deref.rs | 7 ++ .../data/run-rs/ref-deref/ref-deref.rs | 7 ++ .../run-rs/ref-deref/strange-ref-deref.rs | 7 ++ .../integration/data/run-rs/slices/slice.rs | 7 ++ .../data/run-rs/strings-chars/char-trivial.rs | 5 ++ .../run-rs/strings-chars/std-string-empty.rs | 4 + .../run-rs/strings-chars/std-to-string.rs | 4 + .../data/run-rs/strings-chars/str-empty.rs | 5 ++ .../data/run-rs/strings-chars/str-trivial.rs | 5 ++ .../integration/data/run-rs/structs/struct.rs | 10 +++ .../data/run-rs/traits/defined-trait.rs | 19 +++++ .../data/run-rs/traits/derive-copy-struct.rs | 19 +++++ .../data/run-rs/tuples/tuple-eq.rs | 5 ++ .../data/run-rs/tuples/tuples-simple.rs | 5 ++ 34 files changed, 363 insertions(+) create mode 100644 kmir/src/tests/integration/data/run-rs/arrays/array.rs create mode 100644 kmir/src/tests/integration/data/run-rs/assert/assert_eq.rs create mode 100644 kmir/src/tests/integration/data/run-rs/closures/closure-args.rs create mode 100644 kmir/src/tests/integration/data/run-rs/closures/closure-no-args.rs create mode 100644 kmir/src/tests/integration/data/run-rs/enums/enum.rs create mode 100644 kmir/src/tests/integration/data/run-rs/floats/float.rs create mode 100644 kmir/src/tests/integration/data/run-rs/functions/sum-to-n.rs create mode 100644 kmir/src/tests/integration/data/run-rs/generics/generic.rs create mode 100644 kmir/src/tests/integration/data/run-rs/integers/binop.rs create mode 100644 kmir/src/tests/integration/data/run-rs/integers/const-arithm-simple.rs create mode 100644 kmir/src/tests/integration/data/run-rs/integers/div.rs create mode 100644 kmir/src/tests/integration/data/run-rs/integers/modulo.rs create mode 100644 kmir/src/tests/integration/data/run-rs/integers/primitive-type-bounds.rs create mode 100644 kmir/src/tests/integration/data/run-rs/integers/shl_min.rs create mode 100644 kmir/src/tests/integration/data/run-rs/memory/box.rs create mode 100644 kmir/src/tests/integration/data/run-rs/option/option-construction.rs create mode 100644 kmir/src/tests/integration/data/run-rs/recursion/fibonacci.rs create mode 100644 kmir/src/tests/integration/data/run-rs/recursion/mutual_recursion.rs create mode 100644 kmir/src/tests/integration/data/run-rs/recursion/recursion-simple-match.rs create mode 100644 kmir/src/tests/integration/data/run-rs/recursion/recursion-simple.rs create mode 100644 kmir/src/tests/integration/data/run-rs/ref-deref/double-ref-deref.rs create mode 100644 kmir/src/tests/integration/data/run-rs/ref-deref/ref-deref.rs create mode 100644 kmir/src/tests/integration/data/run-rs/ref-deref/strange-ref-deref.rs create mode 100644 kmir/src/tests/integration/data/run-rs/slices/slice.rs create mode 100644 kmir/src/tests/integration/data/run-rs/strings-chars/char-trivial.rs create mode 100644 kmir/src/tests/integration/data/run-rs/strings-chars/std-string-empty.rs create mode 100644 kmir/src/tests/integration/data/run-rs/strings-chars/std-to-string.rs create mode 100644 kmir/src/tests/integration/data/run-rs/strings-chars/str-empty.rs create mode 100644 kmir/src/tests/integration/data/run-rs/strings-chars/str-trivial.rs create mode 100644 kmir/src/tests/integration/data/run-rs/structs/struct.rs create mode 100644 kmir/src/tests/integration/data/run-rs/traits/defined-trait.rs create mode 100644 kmir/src/tests/integration/data/run-rs/traits/derive-copy-struct.rs create mode 100644 kmir/src/tests/integration/data/run-rs/tuples/tuple-eq.rs create mode 100644 kmir/src/tests/integration/data/run-rs/tuples/tuples-simple.rs diff --git a/kmir/src/tests/integration/data/run-rs/arrays/array.rs b/kmir/src/tests/integration/data/run-rs/arrays/array.rs new file mode 100644 index 000000000..6c3102e37 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/arrays/array.rs @@ -0,0 +1,5 @@ +fn main() { + let a = [1, 2, 3, 4]; + + assert!(a == [1, 2, 3, 4]); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/assert/assert_eq.rs b/kmir/src/tests/integration/data/run-rs/assert/assert_eq.rs new file mode 100644 index 000000000..f4bb6f357 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/assert/assert_eq.rs @@ -0,0 +1,6 @@ +fn main() { + let a = 42; + let b = 3 + 39; + + assert_eq!(b, a); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/closures/closure-args.rs b/kmir/src/tests/integration/data/run-rs/closures/closure-args.rs new file mode 100644 index 000000000..cf91f52ee --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/closures/closure-args.rs @@ -0,0 +1,5 @@ +fn main() { + let sum = |x, y| -> i32 { x + y }; + + assert!(sum(20, 22) == 42); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/closures/closure-no-args.rs b/kmir/src/tests/integration/data/run-rs/closures/closure-no-args.rs new file mode 100644 index 000000000..7ec541c51 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/closures/closure-no-args.rs @@ -0,0 +1,5 @@ +fn main() { + let sum = || -> u32 { 42 }; + + assert!(sum() == 42); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/enums/enum.rs b/kmir/src/tests/integration/data/run-rs/enums/enum.rs new file mode 100644 index 000000000..f44e674ea --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/enums/enum.rs @@ -0,0 +1,8 @@ +enum Letter { + A, + B, +} + +fn main() { + let a = Letter::A; +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/floats/float.rs b/kmir/src/tests/integration/data/run-rs/floats/float.rs new file mode 100644 index 000000000..3e1c38b10 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/floats/float.rs @@ -0,0 +1,11 @@ +fn main() { + let a:f32 = 3.5; + let b:f32 = 1.2; + + assert!(a + b == 4.7); + + let c:f64 = 3.5; + let d:f64 = 1.2; + + assert!(c + d == 4.7); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/functions/sum-to-n.rs b/kmir/src/tests/integration/data/run-rs/functions/sum-to-n.rs new file mode 100644 index 000000000..5741aa36d --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/functions/sum-to-n.rs @@ -0,0 +1,23 @@ +fn sum_to_n(n:usize) -> usize { + let mut sum = 0; + let mut counter = n; + + while counter > 0 { + sum += counter; + counter = counter - 1; + } + return sum; +} + +fn test_sum_to_n() -> () { + let n = 10; + let golden = 55; + let sucess = sum_to_n(n) == golden; + assert!(sucess); +} + + +fn main() { + test_sum_to_n(); + return (); +} diff --git a/kmir/src/tests/integration/data/run-rs/generics/generic.rs b/kmir/src/tests/integration/data/run-rs/generics/generic.rs new file mode 100644 index 000000000..df71801fe --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/generics/generic.rs @@ -0,0 +1,14 @@ +fn index_slice(slice:&[T], index: usize) -> &T { + &(slice[index]) +} + +fn main() { + let numbers = [1, 2, 3, 4, 5]; + let letters = ['a', 'b', 'c', 'd', 'e']; + + let middle_number:&i32 = index_slice(&numbers[..], 2); + let middle_letter:&char = index_slice(&letters[..], 2); + + assert!(*middle_number == 3); + assert!(*middle_letter == 'c'); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/integers/binop.rs b/kmir/src/tests/integration/data/run-rs/integers/binop.rs new file mode 100644 index 000000000..c132e75ee --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/integers/binop.rs @@ -0,0 +1,74 @@ +fn test_binop(x:i32, y:i32) -> () { +// Arithmetic + // Addition + assert!(x + y == 52); + assert!(52 == x + y); + assert!(x + y == y + x); + + // Subtraction + assert!(x - y == 32); + assert!(y - x == -32); + assert!(y - x != x - y); + + // Multiplication + assert!(x * y == 420); + assert!(x * -y == -420); + assert!(-x * y == -420); + assert!(-x * -y == 420); + + // Division + // assert!(420 / 10 == 42); // FAILING SEE div.rs and div.mir + + // Modulo + // assert!(x % 10 == 2); // FAILING SEE modulo.rs and modulo.mir + +// Bitwise + // Xor + assert!(1 ^ 2 == 3); + assert!(1 ^ 3 == 2); + + // Or + assert!(1 | 2 == 3); + assert!(1 | 3 == 3); + + // And + assert!(1 & 2 == 0); + assert!(1 & 3 == 1); + + // // Shl + assert!(2 << 1 == 4); + // assert!(-128_i8 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir + // assert!(-32768_i16 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir + // assert!(-2147483648_i32 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir + // assert!(-9223372036854775808_i64 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir + // assert!(-17014118346046923173168730371588410572_i128 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir + + + // // Shr + assert!(2 >> 1 == 1); + assert!(3 >> 1 == 1); + assert!(1 >> 1 == 0); + +// Comparisions + // Less Then + assert!(x < x + y); + + // Less Then or Equal + assert!(x <= x + y); + assert!(x <= x + y - y); + + // Greater Then + assert!(x + y > x); + + // Greater Then or Equal + assert!(x + y >= x); + assert!(x + y - y >= x); +} + + +fn main() { + let x = 42; + let y = 10; + test_binop(x, y); + return (); +} diff --git a/kmir/src/tests/integration/data/run-rs/integers/const-arithm-simple.rs b/kmir/src/tests/integration/data/run-rs/integers/const-arithm-simple.rs new file mode 100644 index 000000000..251d6b675 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/integers/const-arithm-simple.rs @@ -0,0 +1,12 @@ +fn test(x: usize, y:usize) -> bool { + return x > y; +} + + +fn main() { + let x:usize = 42; + let y:usize = 0; + let z:bool = test(x, y); + assert!(z); + return (); +} diff --git a/kmir/src/tests/integration/data/run-rs/integers/div.rs b/kmir/src/tests/integration/data/run-rs/integers/div.rs new file mode 100644 index 000000000..616292cec --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/integers/div.rs @@ -0,0 +1,3 @@ +fn main() { + assert!(420 / 10 ==42); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/integers/modulo.rs b/kmir/src/tests/integration/data/run-rs/integers/modulo.rs new file mode 100644 index 000000000..e76b3efbe --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/integers/modulo.rs @@ -0,0 +1,3 @@ +fn main() { + assert!(42 % 10 == 2); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/integers/primitive-type-bounds.rs b/kmir/src/tests/integration/data/run-rs/integers/primitive-type-bounds.rs new file mode 100644 index 000000000..036fb2f5d --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/integers/primitive-type-bounds.rs @@ -0,0 +1,5 @@ +fn main () { + let a:u32 = 4294967295; + let b:u32 = 4294967294 + 1; + assert!(a == b) +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/integers/shl_min.rs b/kmir/src/tests/integration/data/run-rs/integers/shl_min.rs new file mode 100644 index 000000000..4f255e0d5 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/integers/shl_min.rs @@ -0,0 +1,7 @@ +fn main() { + assert!(-128_i32 << 1 == 0); + assert!(-32768_i16 << 1 == 0); + assert!(-2147483648_i32 << 1 == 0); + assert!(-9223372036854775808_i64 << 1 == 0); + assert!(-17014118346046923173168730371588410572_i128 << 1 == 0); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/memory/box.rs b/kmir/src/tests/integration/data/run-rs/memory/box.rs new file mode 100644 index 000000000..1e93f66b2 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/memory/box.rs @@ -0,0 +1,9 @@ +fn main() { + let a = Box::new(5); + let b = Box::new(5); + + assert!(a == b); + assert!(*a == *b); + assert!(*a == 5); + // assert!(a == 5); // Not possible to equate Box::(Type) with Type +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/option/option-construction.rs b/kmir/src/tests/integration/data/run-rs/option/option-construction.rs new file mode 100644 index 000000000..58e2bbcdb --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/option/option-construction.rs @@ -0,0 +1,5 @@ +fn main() { + let a:Option = Some(42); + let b:Option = None; + let c:u32 = a.unwrap(); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/recursion/fibonacci.rs b/kmir/src/tests/integration/data/run-rs/recursion/fibonacci.rs new file mode 100644 index 000000000..aa06798b3 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/recursion/fibonacci.rs @@ -0,0 +1,13 @@ +fn fibonacci(n:u32) -> u32 { + match n { + 0 => 0, + 1 => 1, + _ => fibonacci(n - 2) + fibonacci(n - 1), + } +} + +fn main() { + let ans = fibonacci(5); + + assert!(ans == 5); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/recursion/mutual_recursion.rs b/kmir/src/tests/integration/data/run-rs/recursion/mutual_recursion.rs new file mode 100644 index 000000000..7037bc803 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/recursion/mutual_recursion.rs @@ -0,0 +1,21 @@ +fn is_even(n:u32) -> bool { + if n == 0 { + true + } else { + is_odd(n - 1) + } +} + +fn is_odd(n:u32) -> bool { + if n == 0 { + false + } else { + is_even(n - 1) + } +} + +fn main() { + let ans = is_even(10); + + assert!(ans == true); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/recursion/recursion-simple-match.rs b/kmir/src/tests/integration/data/run-rs/recursion/recursion-simple-match.rs new file mode 100644 index 000000000..96b4086d2 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/recursion/recursion-simple-match.rs @@ -0,0 +1,12 @@ +fn sum_to_n_rec(n:u32) -> u32 { + match n { + 0 => 0, + _ => n + sum_to_n_rec(n - 1), + } +} + +fn main() { + let ans = sum_to_n_rec(10); + + assert!(ans == 55); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/recursion/recursion-simple.rs b/kmir/src/tests/integration/data/run-rs/recursion/recursion-simple.rs new file mode 100644 index 000000000..e15793f8c --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/recursion/recursion-simple.rs @@ -0,0 +1,13 @@ +fn sum_to_n_rec(n:u32) -> u32 { + if n == 0 { + 0 + } else { + n + sum_to_n_rec(n - 1) + } +} + +fn main() { + let ans = sum_to_n_rec(10); + + assert!(ans == 55); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/ref-deref/double-ref-deref.rs b/kmir/src/tests/integration/data/run-rs/ref-deref/double-ref-deref.rs new file mode 100644 index 000000000..a91f8ac11 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/ref-deref/double-ref-deref.rs @@ -0,0 +1,7 @@ +fn main() { + let a = 42; + let b = &a; + let c = &b; + + assert!(**c == 42); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/ref-deref/ref-deref.rs b/kmir/src/tests/integration/data/run-rs/ref-deref/ref-deref.rs new file mode 100644 index 000000000..d637a6ca5 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/ref-deref/ref-deref.rs @@ -0,0 +1,7 @@ +fn main() { + let a = 42; + let b = &a; + let c = *b; + + assert!(c == 42); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/ref-deref/strange-ref-deref.rs b/kmir/src/tests/integration/data/run-rs/ref-deref/strange-ref-deref.rs new file mode 100644 index 000000000..13e71d74e --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/ref-deref/strange-ref-deref.rs @@ -0,0 +1,7 @@ +fn main() { + let a = 42; + let mut b = &a; + b = &b; + + assert!(*b == 42); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/slices/slice.rs b/kmir/src/tests/integration/data/run-rs/slices/slice.rs new file mode 100644 index 000000000..bff6e82a4 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/slices/slice.rs @@ -0,0 +1,7 @@ +fn main() { + let a = [1, 2, 3, 4]; + + let b = &a[1..3]; + + assert!(b == [2, 3]); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/strings-chars/char-trivial.rs b/kmir/src/tests/integration/data/run-rs/strings-chars/char-trivial.rs new file mode 100644 index 000000000..78236fbd6 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/strings-chars/char-trivial.rs @@ -0,0 +1,5 @@ +fn main() { + let a:char = 'a'; + + assert!(a == 'a'); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/strings-chars/std-string-empty.rs b/kmir/src/tests/integration/data/run-rs/strings-chars/std-string-empty.rs new file mode 100644 index 000000000..be025d6b0 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/strings-chars/std-string-empty.rs @@ -0,0 +1,4 @@ +fn main() { + let a:String = String::new(); + assert!(a == ""); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/strings-chars/std-to-string.rs b/kmir/src/tests/integration/data/run-rs/strings-chars/std-to-string.rs new file mode 100644 index 000000000..5cbb4324f --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/strings-chars/std-to-string.rs @@ -0,0 +1,4 @@ +fn main() { + let a:String = "abcd".to_string(); + assert!(a == "abcd"); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/strings-chars/str-empty.rs b/kmir/src/tests/integration/data/run-rs/strings-chars/str-empty.rs new file mode 100644 index 000000000..a92a02e50 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/strings-chars/str-empty.rs @@ -0,0 +1,5 @@ +fn main() { + let a = ""; + + assert!(a == ""); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/strings-chars/str-trivial.rs b/kmir/src/tests/integration/data/run-rs/strings-chars/str-trivial.rs new file mode 100644 index 000000000..b9bd092bb --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/strings-chars/str-trivial.rs @@ -0,0 +1,5 @@ +fn main() { + let a = "a"; + + assert!(a == "a"); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/structs/struct.rs b/kmir/src/tests/integration/data/run-rs/structs/struct.rs new file mode 100644 index 000000000..c05abb55d --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/structs/struct.rs @@ -0,0 +1,10 @@ + struct St { + a:u32, + b:u32, + } + + fn main() { + let s:St = St { a:1, b:2 }; + + assert!(s.a + 1 == s.b); + } \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/traits/defined-trait.rs b/kmir/src/tests/integration/data/run-rs/traits/defined-trait.rs new file mode 100644 index 000000000..8a67116b5 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/traits/defined-trait.rs @@ -0,0 +1,19 @@ +trait Summary { + fn summarise(&self) -> String; +} + +#[allow(dead_code)] +struct Container { + number: u32, +} + +impl Summary for Container { + fn summarise(&self) -> String { + "The number is zero or more!".to_string() + } +} + +fn main() { + let con = Container { number:42 }; + assert!(con.summarise() == "The number is zero or more!"); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/traits/derive-copy-struct.rs b/kmir/src/tests/integration/data/run-rs/traits/derive-copy-struct.rs new file mode 100644 index 000000000..d1960f7b8 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/traits/derive-copy-struct.rs @@ -0,0 +1,19 @@ +#[derive(Copy, Clone)] +struct Container { + number:u32, +} + +fn take_first_container(containers: &[Container]) -> Container { + containers[0] +} + +fn main() { + let con1 = Container { number: 42 }; + let con2 = Container { number: 24 }; + + let cons = [con1, con2]; + + let first:Container = take_first_container(&cons[..]); + + assert!(first.number == 42); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/tuples/tuple-eq.rs b/kmir/src/tests/integration/data/run-rs/tuples/tuple-eq.rs new file mode 100644 index 000000000..0a79e18c7 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/tuples/tuple-eq.rs @@ -0,0 +1,5 @@ +fn main() { + let tup:(i32, i32) = (42, 99); + + assert!(tup == (42, 99)); +} \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/tuples/tuples-simple.rs b/kmir/src/tests/integration/data/run-rs/tuples/tuples-simple.rs new file mode 100644 index 000000000..9493bc4f5 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/tuples/tuples-simple.rs @@ -0,0 +1,5 @@ +fn main() { + let tup:(i32, i32) = (42, 99); + + assert!(tup.0 != tup.1); +} \ No newline at end of file From 97a6bace9ed6da2d89b59dec2a00247922b25259 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Tue, 27 Aug 2024 10:35:46 +1000 Subject: [PATCH 02/30] make all programs compile and run without errors/warnings/output --- kmir/src/tests/integration/data/run-rs/enums/enum.rs | 2 ++ kmir/src/tests/integration/data/run-rs/integers/shl_min.rs | 4 ++-- .../integration/data/run-rs/option/option-construction.rs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/kmir/src/tests/integration/data/run-rs/enums/enum.rs b/kmir/src/tests/integration/data/run-rs/enums/enum.rs index f44e674ea..8b020d200 100644 --- a/kmir/src/tests/integration/data/run-rs/enums/enum.rs +++ b/kmir/src/tests/integration/data/run-rs/enums/enum.rs @@ -1,3 +1,5 @@ +#![allow(unused)] +#![allow(dead_code)] enum Letter { A, B, diff --git a/kmir/src/tests/integration/data/run-rs/integers/shl_min.rs b/kmir/src/tests/integration/data/run-rs/integers/shl_min.rs index 4f255e0d5..d33c27188 100644 --- a/kmir/src/tests/integration/data/run-rs/integers/shl_min.rs +++ b/kmir/src/tests/integration/data/run-rs/integers/shl_min.rs @@ -1,7 +1,7 @@ fn main() { - assert!(-128_i32 << 1 == 0); + assert!(-128_i8 << 1 == 0); assert!(-32768_i16 << 1 == 0); assert!(-2147483648_i32 << 1 == 0); assert!(-9223372036854775808_i64 << 1 == 0); - assert!(-17014118346046923173168730371588410572_i128 << 1 == 0); + assert!(-170141183460469231731687303715884105728_i128 << 1 == 0); } \ No newline at end of file diff --git a/kmir/src/tests/integration/data/run-rs/option/option-construction.rs b/kmir/src/tests/integration/data/run-rs/option/option-construction.rs index 58e2bbcdb..e2b9b98cd 100644 --- a/kmir/src/tests/integration/data/run-rs/option/option-construction.rs +++ b/kmir/src/tests/integration/data/run-rs/option/option-construction.rs @@ -1,3 +1,4 @@ +#![allow(unused)] fn main() { let a:Option = Some(42); let b:Option = None; From c39bf1f4e6b48951858422b61c1fab855aa244e9 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Tue, 27 Aug 2024 11:51:01 +1000 Subject: [PATCH 03/30] Fix two typos in symbol names --- kmir/src/kmir/kdist/mir-semantics/body.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kmir/src/kmir/kdist/mir-semantics/body.md b/kmir/src/kmir/kdist/mir-semantics/body.md index 655ba31e9..3d40f3653 100644 --- a/kmir/src/kmir/kdist/mir-semantics/body.md +++ b/kmir/src/kmir/kdist/mir-semantics/body.md @@ -137,7 +137,7 @@ syntax BinOp ::= "binOpAdd" [group(mir-enum), symbol(BinOp::Add)] | "binOpOffset" [group(mir-enum), symbol(BinOp::Offset)] syntax UnOp ::= "unOpNot" [group(mir-enum), symbol(UnOp::Not)] - | "unOpNeg" [group(mir-enum), symbol(UnOp::Net)] + | "unOpNeg" [group(mir-enum), symbol(UnOp::Neg)] | "unOpPtrMetadata" [group(mir-enum), symbol(UnOp::PtrMetadata)] syntax NullOp ::= "nullOpSizeOf" [group(mir-enum), symbol(NullOp::SizeOf)] @@ -302,7 +302,7 @@ syntax AssertMessage ::= assertMessageBoundsCheck(len: Operand, index: Operand) | assertMessageResumedAfterPanic(CoroutineKind) [group(mir-enum), symbol(AssertMessage::ResumedAfterPanic)] | assertMessageMisalignedPointerDereference(required: Operand, found: Operand) - [group(mir-enum---required--found), symbol(AssertMessage::MisalignedPointerDerefence)] + [group(mir-enum---required--found), symbol(AssertMessage::MisalignedPointerDereference)] syntax InlineAsmOperand ::= inlineAsmOperand(inValue: MaybeOperand, outValue: MaybePlace, rawPtr: MIRString) [group(mir---in-value--out-place--raw-rpr)] From 33a71933df7d32673241da015cf903129db8144c Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Tue, 27 Aug 2024 11:53:50 +1000 Subject: [PATCH 04/30] Add error messages to some assertions in the parser --- kmir/src/kmir/convert_from_definition/v2parser.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kmir/src/kmir/convert_from_definition/v2parser.py b/kmir/src/kmir/convert_from_definition/v2parser.py index f71b47f55..96d3845b8 100644 --- a/kmir/src/kmir/convert_from_definition/v2parser.py +++ b/kmir/src/kmir/convert_from_definition/v2parser.py @@ -138,7 +138,8 @@ def _mir_productions_for_sort(self, sort: KSort) -> tuple[KProduction, ...]: # aiming for optimization (cache?) in the future. def _mir_production_for_symbol(self, sort: KSort, symbol: str) -> KProduction: prods = [p for p in self._mir_productions_for_sort(sort) if _get_label(p) == symbol] - assert len(prods) == 1 + assert len(prods) > 0, f"No production for `{symbol}' in sort `{sort.name}'" + assert len(prods) == 1, f"Expected a single production for `{symbol}' as sort `{sort.name}'" return prods[0] # Parse the provided json term, with expected Sort name sort. @@ -155,7 +156,7 @@ def _parse_mir_json(self, json: JSON, sort: KSort) -> ParseResult: # correct rule to apply. In the other cases there should only be one # production anyway, which is asserted as needed. prods = self._mir_productions_for_sort(sort) - assert len(prods) > 0 + assert len(prods) > 0, f"Don't know how to parse sort `{sort.name}'" prod = prods[0] assert prod in self._mir_productions From 02ec0088cddd0c6a2d9716337f44c6947ec85ab5 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Tue, 27 Aug 2024 17:59:50 +1000 Subject: [PATCH 05/30] submodule setup for smir_pretty, simple make target for parse tests --- .gitmodules | 3 +++ Makefile | 31 +++++++++++++++++++++++++++++++ deps/smir_pretty | 1 + 3 files changed, 35 insertions(+) create mode 100644 .gitmodules create mode 160000 deps/smir_pretty diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..4a7941504 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/smir_pretty"] + path = deps/smir_pretty + url = https://github.com/runtimeverification/smir_pretty diff --git a/Makefile b/Makefile index ee545380c..6d8640e04 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,34 @@ kmir: build: kmir $(POETRY) run kdist -v build mir-semantics.\* -j4 + +################################################## +# for integration tests: build smir_pretty in-tree + +################################################## +# this will change/go away as soon as we have a submodule setup in smir_pretty +smir-pretty-setup: deps/smir_pretty/deps/rust + +deps/smir_pretty/deps/rust: + cd deps/smir_pretty && make setup +################################################## + +smir-pretty: smir-pretty-setup deps/smir_pretty/target/debug/smir_pretty + +deps/smir_pretty/target/debug/smir_pretty: deps/smir_pretty + cd deps/smir_pretty && make build_all + +# generate smir and parse given test files (from parameter or run-rs subdirectory) +smir-parse-tests: TESTS = $(shell find kmir/src/tests/integration/data/run-rs -type f -name "*.rs") +smir-parse-tests: SMIR = deps/smir_pretty/run.sh +smir-parse-tests: build smir-pretty + for source in ${TESTS}; do \ + echo -n "$$source: "; \ + dir=$$(dirname $${source}); \ + target=$${dir}/$$(basename $${source%.rs}).smir.json; \ + ${SMIR} -Z no-codegen --out-dir $${dir} $$source \ + && (echo -n "smir-ed "; \ + ${POETRY_RUN} convert-from-definition $${target} Pgm > /dev/null \ + && (echo "and parsed!"; rm $${target}) || echo "PARSE ERROR!") \ + || echo "SMIR ERROR!" ; \ + done diff --git a/deps/smir_pretty b/deps/smir_pretty new file mode 160000 index 000000000..dcc656ac8 --- /dev/null +++ b/deps/smir_pretty @@ -0,0 +1 @@ +Subproject commit dcc656ac8591fbb284773071081745ef8026e0ad From 6bdd7ea94676deced0d62a68823fe12d3c3c9dab Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Wed, 28 Aug 2024 13:32:38 +1000 Subject: [PATCH 06/30] Add CI job to test integration with smir_pretty --- .github/workflows/test.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8c7ac1f4f..ee0c76dd0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,3 +76,29 @@ jobs: - name: 'Tear down Docker' if: always() run: docker stop --time 0 mir-semantics-ci-${GITHUB_SHA} + + smir-integration-tests: + needs: code-quality-checks + name: "Integration with smir_pretty" + runs-on: [self-hosted, linux, normal] + steps: + - name: 'Check out code' + uses: actions/checkout@v4 + with: + token: ${{ secrets.JENKINS_GITHUB_PAT }} + submodules: recursive + - name: 'Set up Docker' + uses: ./.github/actions/with-docker + with: + container-name: mir-semantics-ci-smir-${{ github.sha }} + - name: 'Build kmir' + run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make build + - name: 'Set up and build rust dependency of smir_pretty' + run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make smir-pretty-setup + - name: 'Build smir_pretty' + run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make smir-pretty + - name: 'Run parser tests' + run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make smir-parse-test + - name: 'Tear down Docker' + if: always() + run: docker stop --time 0 mir-semantics-ci-${GITHUB_SHA} From 342af6b370f5fec46851be719493519eadd0e95a Mon Sep 17 00:00:00 2001 From: devops Date: Wed, 28 Aug 2024 03:41:54 +0000 Subject: [PATCH 07/30] Set Version: 0.3.41 --- kmir/pyproject.toml | 2 +- kmir/src/kmir/__init__.py | 2 +- package/version | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kmir/pyproject.toml b/kmir/pyproject.toml index e9cb50999..f77e82798 100644 --- a/kmir/pyproject.toml +++ b/kmir/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "kmir" -version = "0.3.40" +version = "0.3.41" description = "" authors = [ "Runtime Verification, Inc. ", diff --git a/kmir/src/kmir/__init__.py b/kmir/src/kmir/__init__.py index c6d61979a..9bb1651e7 100644 --- a/kmir/src/kmir/__init__.py +++ b/kmir/src/kmir/__init__.py @@ -1,3 +1,3 @@ from typing import Final -VERSION: Final = '0.3.40' +VERSION: Final = '0.3.41' diff --git a/package/version b/package/version index a02af2417..b463c010a 100644 --- a/package/version +++ b/package/version @@ -1 +1 @@ -0.3.40 +0.3.41 From ad9bb8d705f59f6a7e6f3990e5e023317911af39 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Wed, 28 Aug 2024 14:28:26 +1000 Subject: [PATCH 08/30] rename container for smir integration test --- .github/workflows/test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ee0c76dd0..ea0668808 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -90,15 +90,15 @@ jobs: - name: 'Set up Docker' uses: ./.github/actions/with-docker with: - container-name: mir-semantics-ci-smir-${{ github.sha }} + container-name: mir-smir-ci-${{ github.sha }} - name: 'Build kmir' - run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make build + run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make build - name: 'Set up and build rust dependency of smir_pretty' - run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make smir-pretty-setup + run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make smir-pretty-setup - name: 'Build smir_pretty' - run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make smir-pretty + run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make smir-pretty - name: 'Run parser tests' - run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make smir-parse-test + run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make smir-parse-test - name: 'Tear down Docker' if: always() - run: docker stop --time 0 mir-semantics-ci-${GITHUB_SHA} + run: docker stop --time 0 mir-smir-ci-${GITHUB_SHA} From c121268aeb9ab15df965aef6cbc527110fdf5a5f Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Wed, 28 Aug 2024 15:32:17 +1000 Subject: [PATCH 09/30] tweak dependency on rust compiler source --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6d8640e04..c6964641a 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ build: kmir ################################################## # this will change/go away as soon as we have a submodule setup in smir_pretty -smir-pretty-setup: deps/smir_pretty/deps/rust +smir-pretty-setup: deps/smir_pretty/deps/rust/src deps/smir_pretty/deps/rust: cd deps/smir_pretty && make setup From c1820a52acfd452fe1e3e82b02b48a747b45a236 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Wed, 28 Aug 2024 15:40:11 +1000 Subject: [PATCH 10/30] tweak dependency on rust compiler source again, use github-native rust --- .github/workflows/test.yml | 12 ++++++------ Makefile | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ea0668808..9ce55ae33 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -93,12 +93,12 @@ jobs: container-name: mir-smir-ci-${{ github.sha }} - name: 'Build kmir' run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make build - - name: 'Set up and build rust dependency of smir_pretty' - run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make smir-pretty-setup - - name: 'Build smir_pretty' - run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make smir-pretty - - name: 'Run parser tests' - run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make smir-parse-test - name: 'Tear down Docker' if: always() run: docker stop --time 0 mir-smir-ci-${GITHUB_SHA} + - name: 'Set up and build rust dependency of smir_pretty' + run: make smir-pretty-setup + - name: 'Build smir_pretty' + run: make smir-pretty + - name: 'Run parser tests' + run: make smir-parse-test diff --git a/Makefile b/Makefile index c6964641a..dbfb9a385 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ build: kmir # this will change/go away as soon as we have a submodule setup in smir_pretty smir-pretty-setup: deps/smir_pretty/deps/rust/src -deps/smir_pretty/deps/rust: +deps/smir_pretty/deps/rust/src: cd deps/smir_pretty && make setup ################################################## From 2ec3f6e2ff67d5511de12e99db4f7f14b17a9647 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Wed, 28 Aug 2024 16:00:09 +1000 Subject: [PATCH 11/30] use 3rd-party rustc setup action (want nightly) --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ce55ae33..98d6a3ad2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -96,9 +96,11 @@ jobs: - name: 'Tear down Docker' if: always() run: docker stop --time 0 mir-smir-ci-${GITHUB_SHA} - - name: 'Set up and build rust dependency of smir_pretty' + - name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409 + uses: dtolnay/rust-toolchain@nightly + - name: 'Set up tree for rust dependency of smir_pretty' run: make smir-pretty-setup - - name: 'Build smir_pretty' + - name: 'Build smir_pretty and its rustc dependency' run: make smir-pretty - name: 'Run parser tests' run: make smir-parse-test From 1a46f6925c5412425aa7d4ad2ac0f4d37d727000 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 13:09:02 +1000 Subject: [PATCH 12/30] attempt to work around CI-build logic in rustc bootstrap --- Makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dbfb9a385..ec65cb886 100644 --- a/Makefile +++ b/Makefile @@ -14,11 +14,23 @@ build: kmir # for integration tests: build smir_pretty in-tree ################################################## -# this will change/go away as soon as we have a submodule setup in smir_pretty +# This will change when we set up rustc as a submodule in smir_pretty +# The config.toml is a kludge to work around CI-specific logic in the +# rustc bootstrap process that assumes we want a stage 2 build in CI. +smir-pretty-setup: CHANGE_ID = 120593 smir-pretty-setup: deps/smir_pretty/deps/rust/src + printf "%s\n" \ + "change-id = ${CHANGE_ID}" \ + "" \ + "[build]" \ + "build-stage = 1" \ + "docs = false" \ + 'tools = [ "cargo", "src" ]' \ + > $ Date: Thu, 29 Aug 2024 03:09:24 +0000 Subject: [PATCH 13/30] Set Version: 0.3.42 --- kmir/pyproject.toml | 2 +- kmir/src/kmir/__init__.py | 2 +- package/version | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kmir/pyproject.toml b/kmir/pyproject.toml index f77e82798..0fc61c197 100644 --- a/kmir/pyproject.toml +++ b/kmir/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "kmir" -version = "0.3.41" +version = "0.3.42" description = "" authors = [ "Runtime Verification, Inc. ", diff --git a/kmir/src/kmir/__init__.py b/kmir/src/kmir/__init__.py index 9bb1651e7..fe0e05aa6 100644 --- a/kmir/src/kmir/__init__.py +++ b/kmir/src/kmir/__init__.py @@ -1,3 +1,3 @@ from typing import Final -VERSION: Final = '0.3.41' +VERSION: Final = '0.3.42' diff --git a/package/version b/package/version index b463c010a..0bdfd66f8 100644 --- a/package/version +++ b/package/version @@ -1 +1 @@ -0.3.41 +0.3.42 From 243e2aeb93f4310cc098488f00b66dae840acf33 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 13:19:20 +1000 Subject: [PATCH 14/30] attempt to work around CI-build logic in rustc bootstrap - stage 2 --- Makefile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ec65cb886..a25be4f11 100644 --- a/Makefile +++ b/Makefile @@ -15,15 +15,19 @@ build: kmir ################################################## # This will change when we set up rustc as a submodule in smir_pretty +smir-pretty-setup: deps/smir_pretty/deps/rust/src rust-config.toml + +rust-config.toml: deps/smir_pretty/deps/rustc/src/config.toml + # The config.toml is a kludge to work around CI-specific logic in the # rustc bootstrap process that assumes we want a stage 2 build in CI. -smir-pretty-setup: CHANGE_ID = 120593 -smir-pretty-setup: deps/smir_pretty/deps/rust/src +deps/smir_pretty/deps/rustc/src/config.toml: CHANGE_ID = 120593 +deps/smir_pretty/deps/rustc/src/config.toml: printf "%s\n" \ "change-id = ${CHANGE_ID}" \ "" \ "[build]" \ - "build-stage = 1" \ + "build-stage = 2" \ "docs = false" \ 'tools = [ "cargo", "src" ]' \ > $ Date: Thu, 29 Aug 2024 03:24:56 +0000 Subject: [PATCH 15/30] Set Version: 0.3.42 --- kmir/pyproject.toml | 2 +- kmir/src/kmir/__init__.py | 2 +- package/version | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kmir/pyproject.toml b/kmir/pyproject.toml index 8da32fa8f..13cdbadb3 100644 --- a/kmir/pyproject.toml +++ b/kmir/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "kmir" -version = "0.3.41" +version = "0.3.42" description = "" authors = [ "Runtime Verification, Inc. ", diff --git a/kmir/src/kmir/__init__.py b/kmir/src/kmir/__init__.py index 9bb1651e7..fe0e05aa6 100644 --- a/kmir/src/kmir/__init__.py +++ b/kmir/src/kmir/__init__.py @@ -1,3 +1,3 @@ from typing import Final -VERSION: Final = '0.3.41' +VERSION: Final = '0.3.42' diff --git a/package/version b/package/version index b463c010a..0bdfd66f8 100644 --- a/package/version +++ b/package/version @@ -1 +1 @@ -0.3.41 +0.3.42 From 2683c37dd8de7c3d1d25575797ea47f1b595c4d7 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 13:39:48 +1000 Subject: [PATCH 16/30] remove config.toml experiment --- Makefile | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/Makefile b/Makefile index a25be4f11..8b58545ce 100644 --- a/Makefile +++ b/Makefile @@ -15,22 +15,7 @@ build: kmir ################################################## # This will change when we set up rustc as a submodule in smir_pretty -smir-pretty-setup: deps/smir_pretty/deps/rust/src rust-config.toml - -rust-config.toml: deps/smir_pretty/deps/rustc/src/config.toml - -# The config.toml is a kludge to work around CI-specific logic in the -# rustc bootstrap process that assumes we want a stage 2 build in CI. -deps/smir_pretty/deps/rustc/src/config.toml: CHANGE_ID = 120593 -deps/smir_pretty/deps/rustc/src/config.toml: - printf "%s\n" \ - "change-id = ${CHANGE_ID}" \ - "" \ - "[build]" \ - "build-stage = 2" \ - "docs = false" \ - 'tools = [ "cargo", "src" ]' \ - > $ Date: Thu, 29 Aug 2024 13:40:19 +1000 Subject: [PATCH 17/30] lie to rustc bootstrap that we are not in CI (modify GITHUB_ACTIONS variable) --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98d6a3ad2..9fcbe30cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -102,5 +102,7 @@ jobs: run: make smir-pretty-setup - name: 'Build smir_pretty and its rustc dependency' run: make smir-pretty + env: + GITHUB_ACTIONS: "in denial" # rustc bootstrap checks this and refuses stage 1 in "CI" - name: 'Run parser tests' run: make smir-parse-test From aaeda05be3f7c0a212ac2ffc0e10e9909dc36b27 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 13:47:14 +1000 Subject: [PATCH 18/30] another way to modify GITHUB_ACTIONS --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9fcbe30cd..88cbb9479 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -101,7 +101,8 @@ jobs: - name: 'Set up tree for rust dependency of smir_pretty' run: make smir-pretty-setup - name: 'Build smir_pretty and its rustc dependency' - run: make smir-pretty + run: + export GITHUB_ACTIONS="nope" && echo "GITHUB_ACTIONS = ${GITHUB_ACTIONS}" && make smir-pretty env: GITHUB_ACTIONS: "in denial" # rustc bootstrap checks this and refuses stage 1 in "CI" - name: 'Run parser tests' From b79f1db70fea43030e24770bd0c1511fe0ab32b0 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 14:02:11 +1000 Subject: [PATCH 19/30] tests not test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 88cbb9479..99aefcacf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -106,4 +106,4 @@ jobs: env: GITHUB_ACTIONS: "in denial" # rustc bootstrap checks this and refuses stage 1 in "CI" - name: 'Run parser tests' - run: make smir-parse-test + run: make smir-parse-tests From 8a3196cc4d81ef3c9baa6f1d3a8c8ed170081024 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 14:31:00 +1000 Subject: [PATCH 20/30] rearrange steps to run the tests within docker (with K available) --- .github/workflows/test.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 99aefcacf..4e5196ff5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,15 +87,6 @@ jobs: with: token: ${{ secrets.JENKINS_GITHUB_PAT }} submodules: recursive - - name: 'Set up Docker' - uses: ./.github/actions/with-docker - with: - container-name: mir-smir-ci-${{ github.sha }} - - name: 'Build kmir' - run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make build - - name: 'Tear down Docker' - if: always() - run: docker stop --time 0 mir-smir-ci-${GITHUB_SHA} - name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409 uses: dtolnay/rust-toolchain@nightly - name: 'Set up tree for rust dependency of smir_pretty' @@ -105,5 +96,14 @@ jobs: export GITHUB_ACTIONS="nope" && echo "GITHUB_ACTIONS = ${GITHUB_ACTIONS}" && make smir-pretty env: GITHUB_ACTIONS: "in denial" # rustc bootstrap checks this and refuses stage 1 in "CI" - - name: 'Run parser tests' - run: make smir-parse-tests + - name: 'Set up Docker' + uses: ./.github/actions/with-docker + with: + container-name: mir-smir-ci-${{ github.sha }} + - name: 'Build kmir (within docker)' + run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make build + - name: 'Run parser tests (within docker)' + run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make smir-parse-tests + - name: 'Tear down Docker' + if: always() + run: docker stop --time 0 mir-smir-ci-${GITHUB_SHA} From 770646f0554d242af6e5830fa93bf0ed28512c7b Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 15:35:33 +1000 Subject: [PATCH 21/30] pin nightly rustc to today's date --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4e5196ff5..6e6f296e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -88,7 +88,7 @@ jobs: token: ${{ secrets.JENKINS_GITHUB_PAT }} submodules: recursive - name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409 - uses: dtolnay/rust-toolchain@nightly + uses: dtolnay/rust-toolchain@nightly-2024-08-29 - name: 'Set up tree for rust dependency of smir_pretty' run: make smir-pretty-setup - name: 'Build smir_pretty and its rustc dependency' From 7a1c632c0c977d635bf82bd7f4b080037ebedf6d Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 15:36:04 +1000 Subject: [PATCH 22/30] add caching for rust artefacts --- .github/workflows/test.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e6f296e1..6eb9d40fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -91,6 +91,13 @@ jobs: uses: dtolnay/rust-toolchain@nightly-2024-08-29 - name: 'Set up tree for rust dependency of smir_pretty' run: make smir-pretty-setup + + - name: 'Cache smir_pretty and rustc' + uses: Swatinem/rust-cache@v2 + with: + workspaces: | + deps/smir_pretty + deps/smir_pretty/deps/rust/src - name: 'Build smir_pretty and its rustc dependency' run: export GITHUB_ACTIONS="nope" && echo "GITHUB_ACTIONS = ${GITHUB_ACTIONS}" && make smir-pretty From 0d35a8e7faf96aefd917fbc1cf4d34dc49dd56a0 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 15:36:54 +1000 Subject: [PATCH 23/30] Formatting of all steps --- .github/workflows/test.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6eb9d40fd..f1059c30b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,8 +87,10 @@ jobs: with: token: ${{ secrets.JENKINS_GITHUB_PAT }} submodules: recursive + - name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409 uses: dtolnay/rust-toolchain@nightly-2024-08-29 + - name: 'Set up tree for rust dependency of smir_pretty' run: make smir-pretty-setup @@ -98,19 +100,24 @@ jobs: workspaces: | deps/smir_pretty deps/smir_pretty/deps/rust/src + - name: 'Build smir_pretty and its rustc dependency' - run: - export GITHUB_ACTIONS="nope" && echo "GITHUB_ACTIONS = ${GITHUB_ACTIONS}" && make smir-pretty - env: - GITHUB_ACTIONS: "in denial" # rustc bootstrap checks this and refuses stage 1 in "CI" + run: | # rustc bootstrap checks this and refuses stage 1 in "CI" + export GITHUB_ACTIONS="in denial" && \ + echo "GITHUB_ACTIONS = ${GITHUB_ACTIONS}" && \ + make smir-pretty + - name: 'Set up Docker' uses: ./.github/actions/with-docker with: container-name: mir-smir-ci-${{ github.sha }} + - name: 'Build kmir (within docker)' run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make build + - name: 'Run parser tests (within docker)' run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make smir-parse-tests + - name: 'Tear down Docker' if: always() run: docker stop --time 0 mir-smir-ci-${GITHUB_SHA} From 116585e7539b909ad25a8710ef2f92cb6779426b Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 15:43:37 +1000 Subject: [PATCH 24/30] use yesterday's date, as I am ahead of the world --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f1059c30b..e206f138a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -89,7 +89,7 @@ jobs: submodules: recursive - name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409 - uses: dtolnay/rust-toolchain@nightly-2024-08-29 + uses: dtolnay/rust-toolchain@nightly-2024-08-28 - name: 'Set up tree for rust dependency of smir_pretty' run: make smir-pretty-setup From 529be01031cbc7d9de041d8c99fb634d908858b2 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 15:48:46 +1000 Subject: [PATCH 25/30] different syntax for pinned nightly toolchain See https://github.com/dtolnay/rust-toolchain/issues/76#issuecomment-1450344028 --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e206f138a..eadf9cb06 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -89,7 +89,9 @@ jobs: submodules: recursive - name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409 - uses: dtolnay/rust-toolchain@nightly-2024-08-28 + uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly-2024-08-28 - name: 'Set up tree for rust dependency of smir_pretty' run: make smir-pretty-setup From 731bdcc6e3a78c5b33af9b706f1cb5984569de9a Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 29 Aug 2024 16:17:36 +1000 Subject: [PATCH 26/30] add build dir to rust cache --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eadf9cb06..52d961717 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -102,6 +102,8 @@ jobs: workspaces: | deps/smir_pretty deps/smir_pretty/deps/rust/src + cache-directories: | + deps/smir_pretty/deps/rust/src/build - name: 'Build smir_pretty and its rustc dependency' run: | # rustc bootstrap checks this and refuses stage 1 in "CI" From 125cb5eee961d7c167433a41be083257e7af508d Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Fri, 30 Aug 2024 10:39:00 +1000 Subject: [PATCH 27/30] actually fail on smir errors or parse errors --- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8b58545ce..881d910f3 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,8 @@ deps/smir_pretty/target/debug/smir_pretty: deps/smir_pretty smir-parse-tests: TESTS = $(shell find kmir/src/tests/integration/data/run-rs -type f -name "*.rs") smir-parse-tests: SMIR = deps/smir_pretty/run.sh smir-parse-tests: build smir-pretty + errors=""; \ + report() { echo $$2; errors="$$errors $$1"; }; \ for source in ${TESTS}; do \ echo -n "$$source: "; \ dir=$$(dirname $${source}); \ @@ -38,6 +40,7 @@ smir-parse-tests: build smir-pretty ${SMIR} -Z no-codegen --out-dir $${dir} $$source \ && (echo -n "smir-ed "; \ ${POETRY_RUN} convert-from-definition $${target} Pgm > /dev/null \ - && (echo "and parsed!"; rm $${target}) || echo "PARSE ERROR!") \ - || echo "SMIR ERROR!" ; \ - done + && (echo "and parsed!"; rm $${target}) || report "$$source" "PARSE ERROR!") \ + || report "$$source" "SMIR ERROR!" ; \ + done; \ + [ -z "$$errors" ] || (echo "FAILING TESTS:"; printf ". %s\n" $${errors}; exit 1); \ From 3a1ddb38b35e3383545c98681f69207f69307acf Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Fri, 30 Aug 2024 11:53:27 +1000 Subject: [PATCH 28/30] HACK: patch rustc_arch.sh script in docker so we can run smir_pretty --- .github/workflows/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 52d961717..41c4134cb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -119,6 +119,14 @@ jobs: - name: 'Build kmir (within docker)' run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make build + - name: 'HACK: patch rustc_arch.sh script (within docker)' + run: | + arch=$(rustc -vV | sed -e 's/host: \(.*\)$/\1/') + docker exec --user user mir-smir-ci-${GITHUB_SHA} \ + bash -c "echo 'echo $arch' > deps/smir_pretty/rustc_arch.sh" + docker exec --user user mir-smir-ci-${GITHUB_SHA} \ + deps/smir_pretty/rustc_arch.sh + - name: 'Run parser tests (within docker)' run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make smir-parse-tests From ebac22735b359677789fc0c5ae4c49d701f0ca99 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Fri, 30 Aug 2024 12:12:51 +1000 Subject: [PATCH 29/30] patching the patch --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 41c4134cb..f8268babb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -121,9 +121,11 @@ jobs: - name: 'HACK: patch rustc_arch.sh script (within docker)' run: | - arch=$(rustc -vV | sed -e 's/host: \(.*\)$/\1/') + arch=$(rustc -vV | sed -n -e 's/host: \(.*\)$/\1/p') docker exec --user user mir-smir-ci-${GITHUB_SHA} \ - bash -c "echo 'echo $arch' > deps/smir_pretty/rustc_arch.sh" + bash -c "printf '#!/bin/sh\necho \"$arch\"\n' > deps/smir_pretty/rustc_arch.sh" + docker exec --user user mir-smir-ci-${GITHUB_SHA} \ + cat deps/smir_pretty/rustc_arch.sh docker exec --user user mir-smir-ci-${GITHUB_SHA} \ deps/smir_pretty/rustc_arch.sh From bee05d5f271ed4d53c19f1cbab8454a584bd817b Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Fri, 30 Aug 2024 17:01:22 +1000 Subject: [PATCH 30/30] correct symbols for MonoItems (kast requires use of append/empty) --- kmir/src/kmir/kdist/mir-semantics/mono.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmir/src/kmir/kdist/mir-semantics/mono.md b/kmir/src/kmir/kdist/mir-semantics/mono.md index 4ed946efd..a61a4ef8e 100644 --- a/kmir/src/kmir/kdist/mir-semantics/mono.md +++ b/kmir/src/kmir/kdist/mir-semantics/mono.md @@ -37,7 +37,7 @@ syntax MonoItemKind ::= monoItemFn(name: Symbol, id: DefId, body: Bodies) syntax MonoItem ::= monoItem(symbolName: Symbol, monoItemKind: MonoItemKind) [symbol(monoItemWrapper), group(mir---symbol-name--mono-item-kind)] syntax MonoItems ::= List {MonoItem, ""} - [symbol(monoItems), terminator-symbol(.monoItems), group(mir-list)] + [symbol(MonoItems::append), terminator-symbol(MonoItems::empty), group(mir-list)] ////////////////////////////////////////// unused for parsing?