diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8c7ac1f4f..f8268babb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,3 +76,62 @@ 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 nightly Rust" # https://github.com/rust-lang/rustup/issues/3409 + 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 + + - name: 'Cache smir_pretty and rustc' + uses: Swatinem/rust-cache@v2 + with: + 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" + 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: 'HACK: patch rustc_arch.sh script (within docker)' + run: | + arch=$(rustc -vV | sed -n -e 's/host: \(.*\)$/\1/p') + docker exec --user user mir-smir-ci-${GITHUB_SHA} \ + 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 + + - 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} 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..881d910f3 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,38 @@ kmir: build: kmir $(POETRY) run kdist -v build mir-semantics.\* -j4 + +################################################## +# for integration tests: build smir_pretty in-tree + +################################################## +# This will change when we set up rustc as a submodule in smir_pretty +smir-pretty-setup: deps/smir_pretty/deps/rust/src + +deps/smir_pretty/deps/rust/src: + 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 + errors=""; \ + report() { echo $$2; errors="$$errors $$1"; }; \ + 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}) || report "$$source" "PARSE ERROR!") \ + || report "$$source" "SMIR ERROR!" ; \ + done; \ + [ -z "$$errors" ] || (echo "FAILING TESTS:"; printf ". %s\n" $${errors}; exit 1); \ 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 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/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 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)] 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? 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..8b020d200 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/enums/enum.rs @@ -0,0 +1,10 @@ +#![allow(unused)] +#![allow(dead_code)] +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..d33c27188 --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/integers/shl_min.rs @@ -0,0 +1,7 @@ +fn main() { + assert!(-128_i8 << 1 == 0); + assert!(-32768_i16 << 1 == 0); + assert!(-2147483648_i32 << 1 == 0); + assert!(-9223372036854775808_i64 << 1 == 0); + assert!(-170141183460469231731687303715884105728_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..e2b9b98cd --- /dev/null +++ b/kmir/src/tests/integration/data/run-rs/option/option-construction.rs @@ -0,0 +1,6 @@ +#![allow(unused)] +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 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