From a01899ec15e436b8822b413546556b555fc5b713 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Thu, 6 Jun 2024 18:26:31 -0400 Subject: [PATCH] update tests --- .../move/move-compiler-v2/tests/testsuite.rs | 2 +- .../unused-assignment/unused_assignment.exp | 299 ------------------ .../unused_call_assign_shadow.exp | 57 ++++ .../unused_call_assign_shadow.move | 26 ++ .../v1-liveness/unused_assignment.exp | 57 ++++ .../{ => v1-liveness}/unused_assignment.move | 0 .../v1-locals/unused_copyable.exp | 27 ++ .../v1-locals/unused_copyable.move | 16 + .../v1-locals/unused_resource.exp | 45 +++ .../v1-locals/unused_resource.move | 39 +++ .../unused_resource_explicit_return.exp | 39 +++ .../unused_resource_explicit_return.move | 40 +++ .../v1-typing/unused_local.exp | 61 ++++ .../v1-typing/unused_local.move | 46 +++ .../move/move-compiler-v2/tests/v1.matched | 7 +- .../move/move-compiler-v2/tests/v1.unmatched | 5 +- .../tools/testdiff/src/main.rs | 3 + 17 files changed, 464 insertions(+), 305 deletions(-) delete mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/unused_assignment.exp create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/unused_call_assign_shadow.exp create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/unused_call_assign_shadow.move create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/v1-liveness/unused_assignment.exp rename third_party/move/move-compiler-v2/tests/unused-assignment/{ => v1-liveness}/unused_assignment.move (100%) create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.exp create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.move create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.exp create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.move create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.exp create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.move create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.exp create mode 100644 third_party/move/move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.move diff --git a/third_party/move/move-compiler-v2/tests/testsuite.rs b/third_party/move/move-compiler-v2/tests/testsuite.rs index af64a362a8b711..14d5be58213a7f 100644 --- a/third_party/move/move-compiler-v2/tests/testsuite.rs +++ b/third_party/move/move-compiler-v2/tests/testsuite.rs @@ -156,7 +156,7 @@ const TEST_CONFIGS: Lazy> = Lazy::new(|| { .set_experiment(Experiment::UNUSED_ASSIGNMENT_CHECK, true), stop_after: StopAfter::BytecodePipeline(Some("UnusedAssignmentChecker")), dump_ast: DumpLevel::None, - dump_bytecode: DumpLevel::EndStage, + dump_bytecode: DumpLevel::None, dump_bytecode_filter: None, }, // Tests for lambda lifting diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/unused_assignment.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/unused_assignment.exp deleted file mode 100644 index 3b0a98fff75216..00000000000000 --- a/third_party/move/move-compiler-v2/tests/unused-assignment/unused_assignment.exp +++ /dev/null @@ -1,299 +0,0 @@ - -Diagnostics: -warning: Unused local variable `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/unused-assignment/unused_assignment.move:3:13 - │ -3 │ let x = 0; - │ ^ - -warning: Unused local variable `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/unused-assignment/unused_assignment.move:13:17 - │ -13 │ let x = 0; - │ ^ - -============ initial bytecode ================ - -[variant baseline] -fun M::t0() { - 0: return () -} - - -[variant baseline] -fun M::t1() { - var $t0: u64 - var $t1: u64 - 0: $t0 := 0 - 1: $t1 := 0 - 2: $t0 := infer($t1) - 3: return () -} - - -[variant baseline] -fun M::t2($t0: bool) { - 0: if ($t0) goto 1 else goto 3 - 1: label L0 - 2: goto 4 - 3: label L1 - 4: label L2 - 5: return () -} - - -[variant baseline] -fun M::t3($t0: bool) { - var $t1: u64 - var $t2: u64 - var $t3: u64 - 0: $t1 := 0 - 1: $t2 := infer($t1) - 2: if ($t0) goto 3 else goto 7 - 3: label L0 - 4: $t3 := 0 - 5: $t1 := infer($t3) - 6: goto 8 - 7: label L1 - 8: label L2 - 9: return () -} - - -[variant baseline] -fun M::t4($t0: bool) { - var $t1: u64 - var $t2: u64 - var $t3: u64 - 0: $t1 := 0 - 1: if ($t0) goto 2 else goto 6 - 2: label L0 - 3: $t2 := 1 - 4: $t1 := infer($t2) - 5: goto 9 - 6: label L1 - 7: $t3 := 2 - 8: $t1 := infer($t3) - 9: label L2 - 10: return () -} - - -[variant baseline] -fun M::t5($t0: bool) { - var $t1: u64 - var $t2: u64 - var $t3: u64 - var $t4: u64 - 0: label L0 - 1: if ($t0) goto 2 else goto 14 - 2: label L2 - 3: $t2 := 0 - 4: $t1 := infer($t2) - 5: if ($t0) goto 6 else goto 9 - 6: label L5 - 7: $t3 := infer($t1) - 8: goto 10 - 9: label L6 - 10: label L7 - 11: $t4 := 1 - 12: $t1 := infer($t4) - 13: goto 16 - 14: label L3 - 15: goto 18 - 16: label L4 - 17: goto 0 - 18: label L1 - 19: return () -} - -============ after LiveVarAnalysisProcessor: ================ - -[variant baseline] -fun M::t0() { - # live vars: - 0: return () -} - - -[variant baseline] -fun M::t1() { - var $t0: u64 - var $t1: u64 - # live vars: - 0: $t0 := 0 - # live vars: - 1: $t1 := 0 - # live vars: $t1 - 2: $t0 := infer($t1) - # live vars: - 3: return () -} - - -[variant baseline] -fun M::t2($t0: bool) { - # live vars: $t0 - 0: if ($t0) goto 1 else goto 3 - # live vars: - 1: label L0 - # live vars: - 2: goto 4 - # live vars: - 3: label L1 - # live vars: - 4: label L2 - # live vars: - 5: return () -} - - -[variant baseline] -fun M::t3($t0: bool) { - var $t1: u64 - var $t2: u64 - var $t3: u64 - # live vars: $t0 - 0: $t1 := 0 - # live vars: $t0, $t1 - 1: $t2 := infer($t1) - # live vars: $t0 - 2: if ($t0) goto 3 else goto 7 - # live vars: - 3: label L0 - # live vars: - 4: $t3 := 0 - # live vars: $t3 - 5: $t1 := infer($t3) - # live vars: - 6: goto 8 - # live vars: - 7: label L1 - # live vars: - 8: label L2 - # live vars: - 9: return () -} - - -[variant baseline] -fun M::t4($t0: bool) { - var $t1: u64 - var $t2: u64 - var $t3: u64 - # live vars: $t0 - 0: $t1 := 0 - # live vars: $t0 - 1: if ($t0) goto 2 else goto 6 - # live vars: - 2: label L0 - # live vars: - 3: $t2 := 1 - # live vars: $t2 - 4: $t1 := infer($t2) - # live vars: - 5: goto 9 - # live vars: - 6: label L1 - # live vars: - 7: $t3 := 2 - # live vars: $t3 - 8: $t1 := infer($t3) - # live vars: - 9: label L2 - # live vars: - 10: return () -} - - -[variant baseline] -fun M::t5($t0: bool) { - var $t1: u64 - var $t2: u64 - var $t3: u64 - var $t4: u64 - # live vars: $t0 - 0: label L0 - # live vars: $t0 - 1: if ($t0) goto 2 else goto 14 - # live vars: $t0 - 2: label L2 - # live vars: $t0 - 3: $t2 := 0 - # live vars: $t0, $t2 - 4: $t1 := infer($t2) - # live vars: $t0, $t1 - 5: if ($t0) goto 6 else goto 9 - # live vars: $t0, $t1 - 6: label L5 - # live vars: $t0, $t1 - 7: $t3 := infer($t1) - # live vars: $t0 - 8: goto 10 - # live vars: $t0, $t1 - 9: label L6 - # live vars: $t0 - 10: label L7 - # live vars: $t0 - 11: $t4 := 1 - # live vars: $t0, $t4 - 12: $t1 := infer($t4) - # live vars: $t0 - 13: goto 16 - # live vars: $t0 - 14: label L3 - # live vars: - 15: goto 18 - # live vars: $t0 - 16: label L4 - # live vars: $t0 - 17: goto 0 - # live vars: - 18: label L1 - # live vars: - 19: return () -} - - -Diagnostics: -warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/unused-assignment/unused_assignment.move:7:17 - │ -7 │ let x = 0; - │ ^ - -warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/unused-assignment/unused_assignment.move:8:9 - │ -8 │ x = 0; - │ ^^^^^ - -warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/unused-assignment/unused_assignment.move:21:13 - │ -21 │ x = 0; - │ ^^^^^ - -warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/unused-assignment/unused_assignment.move:26:17 - │ -26 │ let x = 0; - │ ^ - -warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/unused-assignment/unused_assignment.move:28:13 - │ -28 │ x = 1; - │ ^^^^^ - -warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/unused-assignment/unused_assignment.move:30:13 - │ -30 │ x = 2; - │ ^^^^^ - -warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/unused-assignment/unused_assignment.move:41:13 - │ -41 │ x = 1; - │ ^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/unused_call_assign_shadow.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/unused_call_assign_shadow.exp new file mode 100644 index 00000000000000..6b733974dbdba7 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/unused_call_assign_shadow.exp @@ -0,0 +1,57 @@ + +Diagnostics: +warning: Unused parameter `a`. Consider removing or prefixing with an underscore: `_a` + ┌─ tests/unused-assignment/unused_call_assign_shadow.move:2:13 + │ +2 │ fun foo(a: u8, _b: u8) { + │ ^ + +warning: Unused local variable `y`. Consider removing or prefixing with an underscore: `_y` + ┌─ tests/unused-assignment/unused_call_assign_shadow.move:5:13 + │ +5 │ let y = 0; + │ ^ + +warning: Unused local variable `w`. Consider removing or prefixing with an underscore: `_w` + ┌─ tests/unused-assignment/unused_call_assign_shadow.move:8:13 + │ +8 │ let w = bar(false); + │ ^ + +warning: Unused local variable `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/unused_call_assign_shadow.move:22:13 + │ +22 │ let x = 0; + │ ^ + +warning: Unused local variable `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/unused_call_assign_shadow.move:24:13 + │ +24 │ let x = 1; + │ ^ + + +Diagnostics: +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/unused_call_assign_shadow.move:4:9 + │ +4 │ x = x + 1; + │ ^^^^^^^^^ + +warning: Unused assignment to `w`. Consider removing or prefixing with an underscore: `_w` + ┌─ tests/unused-assignment/unused_call_assign_shadow.move:8:17 + │ +8 │ let w = bar(false); + │ ^^^^^^^^^^ + +warning: Unused assignment to `y`. Consider removing or prefixing with an underscore: `_y` + ┌─ tests/unused-assignment/unused_call_assign_shadow.move:14:13 + │ +14 │ y = y + 1; + │ ^^^^^^^^^ + +warning: Unused assignment to `y`. Consider removing or prefixing with an underscore: `_y` + ┌─ tests/unused-assignment/unused_call_assign_shadow.move:16:13 + │ +16 │ y = y + 2; + │ ^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/unused_call_assign_shadow.move b/third_party/move/move-compiler-v2/tests/unused-assignment/unused_call_assign_shadow.move new file mode 100644 index 00000000000000..70e9688d98c364 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/unused_call_assign_shadow.move @@ -0,0 +1,26 @@ +module 0x42::test { + fun foo(a: u8, _b: u8) { + let x = 0; + x = x + 1; + let y = 0; + let _z = 42; + // unused call assignment + let w = bar(false); + } + + fun bar(x: bool): u8 { + let y = 0; + if (x) { + y = y + 1; + } else { + y = y + 2; + }; + 42 + } + + fun baz() { + let x = 0; + // shadowing + let x = 1; + } +} diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-liveness/unused_assignment.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-liveness/unused_assignment.exp new file mode 100644 index 00000000000000..8106befe7dad4d --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-liveness/unused_assignment.exp @@ -0,0 +1,57 @@ + +Diagnostics: +warning: Unused local variable `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-liveness/unused_assignment.move:3:13 + │ +3 │ let x = 0; + │ ^ + +warning: Unused local variable `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-liveness/unused_assignment.move:13:17 + │ +13 │ let x = 0; + │ ^ + + +Diagnostics: +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-liveness/unused_assignment.move:7:17 + │ +7 │ let x = 0; + │ ^ + +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-liveness/unused_assignment.move:8:9 + │ +8 │ x = 0; + │ ^^^^^ + +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-liveness/unused_assignment.move:21:13 + │ +21 │ x = 0; + │ ^^^^^ + +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-liveness/unused_assignment.move:26:17 + │ +26 │ let x = 0; + │ ^ + +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-liveness/unused_assignment.move:28:13 + │ +28 │ x = 1; + │ ^^^^^ + +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-liveness/unused_assignment.move:30:13 + │ +30 │ x = 2; + │ ^^^^^ + +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-liveness/unused_assignment.move:41:13 + │ +41 │ x = 1; + │ ^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/unused_assignment.move b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-liveness/unused_assignment.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/unused-assignment/unused_assignment.move rename to third_party/move/move-compiler-v2/tests/unused-assignment/v1-liveness/unused_assignment.move diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.exp new file mode 100644 index 00000000000000..2a79d71797f43c --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.exp @@ -0,0 +1,27 @@ + +Diagnostics: +warning: Unused parameter `i`. Consider removing or prefixing with an underscore: `_i` + ┌─ tests/unused-assignment/v1-locals/unused_copyable.move:5:12 + │ +5 │ fun t0(i: u64, s: S) { + │ ^ + +warning: Unused parameter `s`. Consider removing or prefixing with an underscore: `_s` + ┌─ tests/unused-assignment/v1-locals/unused_copyable.move:5:20 + │ +5 │ fun t0(i: u64, s: S) { + │ ^ + +warning: Unused local variable `s`. Consider removing or prefixing with an underscore: `_s` + ┌─ tests/unused-assignment/v1-locals/unused_copyable.move:9:13 + │ +9 │ let s = S{}; + │ ^ + + +Diagnostics: +warning: Unused assignment to `s`. Consider removing or prefixing with an underscore: `_s` + ┌─ tests/unused-assignment/v1-locals/unused_copyable.move:9:17 + │ +9 │ let s = S{}; + │ ^^^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.move b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.move new file mode 100644 index 00000000000000..db26cb54321f7d --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.move @@ -0,0 +1,16 @@ +module 0x8675309::M { + struct S has drop {} + + // this produces unused parameter warnings for i and s, but not unused resource warnings + fun t0(i: u64, s: S) { + } + + fun t1() { + let s = S{}; + } + + fun t2() { + // prefixing an unused non-resource with _ suppresses the warning + let _s = S{}; + } +} diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.exp new file mode 100644 index 00000000000000..13d05060d21fd3 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.exp @@ -0,0 +1,45 @@ + +Diagnostics: +warning: Unused local variable `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource.move:5:13 + │ +5 │ let r = R{}; + │ ^ + +warning: Unused local variable `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource.move:29:20 + │ +29 │ loop { let r = R{}; } + │ ^ + + +Diagnostics: +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource.move:5:17 + │ +5 │ let r = R{}; + │ ^^^ + +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource.move:15:21 + │ +15 │ if (cond) { r = R{}; }; + │ ^^^^^^^ + +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource.move:20:29 + │ +20 │ if (cond) {} else { r = R{}; }; + │ ^^^^^^^ + +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource.move:25:24 + │ +25 │ while (cond) { r = R{} }; + │ ^^^^^^^ + +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource.move:29:24 + │ +29 │ loop { let r = R{}; } + │ ^^^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.move b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.move new file mode 100644 index 00000000000000..4121a8c05ea11b --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.move @@ -0,0 +1,39 @@ +module 0x8675309::M { + struct R {} + + fun t0() { + let r = R{}; + } + + fun t1() { + // prefixing an unused resource with _ does not work + let _r = R{}; + } + + fun t2(cond: bool) { + let r; + if (cond) { r = R{}; }; + } + + fun t3(cond: bool) { + let r; + if (cond) {} else { r = R{}; }; + } + + fun t4(cond: bool) { + let r; + while (cond) { r = R{} }; + } + + fun t5() { + loop { let r = R{}; } + } + + fun t6() { + let _ = &R{}; + } + + fun t7(_x: R) { + } + +} diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.exp new file mode 100644 index 00000000000000..8d78b5a05aadb3 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.exp @@ -0,0 +1,39 @@ + +Diagnostics: +warning: Unused local variable `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource_explicit_return.move:5:13 + │ +5 │ let r = R{}; + │ ^ + +warning: Unused local variable `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource_explicit_return.move:28:13 + │ +28 │ let r = R{}; + │ ^ + +warning: Unused local variable `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-locals/unused_resource_explicit_return.move:33:13 + │ +33 │ let x = &R{}; + │ ^ + + +Diagnostics: +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource_explicit_return.move:5:17 + │ +5 │ let r = R{}; + │ ^^^ + +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/unused_resource_explicit_return.move:28:17 + │ +28 │ let r = R{}; + │ ^^^ + +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-locals/unused_resource_explicit_return.move:33:17 + │ +33 │ let x = &R{}; + │ ^^^^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.move b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.move new file mode 100644 index 00000000000000..cb70af3240e97d --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.move @@ -0,0 +1,40 @@ +module 0x8675309::M { + struct R {} + + fun t0() { + let r = R{}; + return () + } + + fun t1(cond: bool) { + let r = R {}; + if (cond) { return () }; + R {} = r; + } + + fun t2(cond: bool) { + let r = R{}; + if (cond) {} else { return () }; + R {} = r; + } + + fun t3(cond: bool) { + let r = R {}; + while (cond) { return () }; + R {} = r; + } + + fun t4() { + let r = R{}; + loop { return () } + } + + fun t5() { + let x = &R{}; + return () + } + + fun t6(_x: R) { + return () + } +} diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.exp new file mode 100644 index 00000000000000..02a5521f47ee43 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.exp @@ -0,0 +1,61 @@ + +Diagnostics: +warning: Unused local variable `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:5:13 + │ +5 │ let x: u64; + │ ^ + +warning: Unused local variable `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:9:14 + │ +9 │ let (x, y): (u64, u64); + │ ^ + +warning: Unused local variable `y`. Consider removing or prefixing with an underscore: `_y` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:9:17 + │ +9 │ let (x, y): (u64, u64); + │ ^ + +warning: Unused local variable `f`. Consider removing or prefixing with an underscore: `_f` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:13:16 + │ +13 │ let S{ f, g }: S; + │ ^ + +warning: Unused local variable `g`. Consider removing or prefixing with an underscore: `_g` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:13:19 + │ +13 │ let S{ f, g }: S; + │ ^ + +warning: Unused parameter `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:25:22 + │ +25 │ fun unused_param(x: u64) { + │ ^ + +warning: Unused parameter `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:28:20 + │ +28 │ fun two_unused(x: u64, y: bool) { + │ ^ + +warning: Unused parameter `y`. Consider removing or prefixing with an underscore: `_y` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:28:28 + │ +28 │ fun two_unused(x: u64, y: bool) { + │ ^ + +warning: Unused parameter `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:31:35 + │ +31 │ fun unused_param1_used_param2(x: u64, y: bool): bool { + │ ^ + +warning: Unused parameter `y`. Consider removing or prefixing with an underscore: `_y` + ┌─ tests/unused-assignment/v1-typing/unused_local.move:35:43 + │ +35 │ fun unused_param2_used_param1(x: u64, y: bool): u64 { + │ ^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.move b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.move new file mode 100644 index 00000000000000..f2c060a717fbe7 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.move @@ -0,0 +1,46 @@ +module 0x8675309::M { + struct S { f: u64, g: bool } + + fun t0() { + let x: u64; + } + + fun t1() { + let (x, y): (u64, u64); + } + + fun t2() { + let S{ f, g }: S; + } + + fun unused_local_suppressed1() { + let _x: u64; + } + + fun unused_local_suppressed2() { + let _: u64; + } + + + fun unused_param(x: u64) { + } + + fun two_unused(x: u64, y: bool) { + } + + fun unused_param1_used_param2(x: u64, y: bool): bool { + y + } + + fun unused_param2_used_param1(x: u64, y: bool): u64 { + x + } + + fun unused_param_suppressed1(_: u64) { + } + + fun unused_param_suppressed2(_x: u64) { + } + + native fun unused_native_ok(x: u64, y: bool); +} diff --git a/third_party/move/move-compiler-v2/tests/v1.matched b/third_party/move/move-compiler-v2/tests/v1.matched index 2d09eb45f2054c..e79253598e1ee3 100644 --- a/third_party/move/move-compiler-v2/tests/v1.matched +++ b/third_party/move/move-compiler-v2/tests/v1.matched @@ -1,3 +1,4 @@ +WARNING: test `move-compiler-v2/tests/checking/typing/unused_local.move` and `move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.move` share common key `typing/unused_local.move`, discarding former one move-compiler/tests/move_check/translated_ir_tests/move/borrow_tests/borrow_global_acquires_1.exp move-compiler-v2/tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_1.exp move-compiler/tests/move_check/translated_ir_tests/move/borrow_tests/borrow_global_acquires_2.exp move-compiler-v2/tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_2.exp move-compiler/tests/move_check/translated_ir_tests/move/borrow_tests/borrow_global_acquires_3.exp move-compiler-v2/tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_3.exp @@ -205,9 +206,13 @@ move-compiler/tests/move_check/translated_ir_tests/move/generics/instantiation_l move-compiler/tests/move_check/translated_ir_tests/move/generics/instantiation_loops/two_loops.exp move-compiler-v2/tests/cyclic-instantiation-checker/v1-tests/two_loops.exp move-compiler/tests/move_check/liveness/mut_inline.exp move-compiler-v2/tests/live-var/mut_inline.exp move-compiler/tests/move_check/liveness/mut_ref.exp move-compiler-v2/tests/live-var/mut_ref.exp +move-compiler/tests/move_check/liveness/unused_assignment.exp move-compiler-v2/tests/unused-assignment/v1-liveness/unused_assignment.exp move-compiler/tests/move_check/locals/drop_conditional.exp move-compiler-v2/tests/ability-check/v1-locals/drop_conditional.exp move-compiler/tests/move_check/locals/eliminate_temps.exp move-compiler-v2/tests/reference-safety/v1-locals/eliminate_temps.exp move-compiler/tests/move_check/locals/reassign_parameter.exp move-compiler-v2/tests/ability-check/v1-locals/reassign_parameter.exp +move-compiler/tests/move_check/locals/unused_copyable.exp move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.exp +move-compiler/tests/move_check/locals/unused_resource.exp move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.exp +move-compiler/tests/move_check/locals/unused_resource_explicit_return.exp move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.exp move-compiler/tests/move_check/locals/use_before_assign_if.exp move-compiler-v2/tests/uninit-use-checker/v1-locals/use_before_assign_if.exp move-compiler/tests/move_check/locals/use_before_assign_if_else.exp move-compiler-v2/tests/uninit-use-checker/v1-locals/use_before_assign_if_else.exp move-compiler/tests/move_check/locals/use_before_assign_loop.exp move-compiler-v2/tests/uninit-use-checker/v1-locals/use_before_assign_loop.exp @@ -542,7 +547,7 @@ move-compiler/tests/move_check/typing/uninferred_type_unpack_assign.exp move-c move-compiler/tests/move_check/typing/uninferred_type_unpack_bind.exp move-compiler-v2/tests/checking/typing/uninferred_type_unpack_bind.exp move-compiler/tests/move_check/typing/uninferred_type_unpack_decl.exp move-compiler-v2/tests/checking/typing/uninferred_type_unpack_decl.exp move-compiler/tests/move_check/typing/unit.exp move-compiler-v2/tests/checking/typing/unit.exp -move-compiler/tests/move_check/typing/unused_local.exp move-compiler-v2/tests/checking/typing/unused_local.exp +move-compiler/tests/move_check/typing/unused_local.exp move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.exp move-compiler/tests/move_check/typing/use_local.exp move-compiler-v2/tests/checking/typing/use_local.exp move-compiler/tests/move_check/typing/valid_acquire.exp move-compiler-v2/tests/acquires-checker/v1-tests/valid_acquire.exp move-compiler/tests/move_check/typing/values.exp move-compiler-v2/tests/checking/typing/values.exp diff --git a/third_party/move/move-compiler-v2/tests/v1.unmatched b/third_party/move/move-compiler-v2/tests/v1.unmatched index f30791f7fad7d2..a1472b008bfbe3 100644 --- a/third_party/move/move-compiler-v2/tests/v1.unmatched +++ b/third_party/move/move-compiler-v2/tests/v1.unmatched @@ -1,3 +1,4 @@ +WARNING: test `move-compiler-v2/tests/checking/typing/unused_local.move` and `move-compiler-v2/tests/unused-assignment/v1-typing/unused_local.move` share common key `typing/unused_local.move`, discarding former one move-compiler/tests/move_check/borrow_tests/{ borrow_global_acquires_duplicate_annotation.move, eq_bad.move, @@ -66,15 +67,11 @@ move-compiler/tests/move_check/liveness/{ move_in_infinite_loop_branched.move, trailing_semi.move, trailing_semi_loops.move, - unused_assignment.move, } move-compiler/tests/move_check/locals/{ assign_partial_resource.move, assign_resource.move, struct_use_before_assign.move, - unused_copyable.move, - unused_resource.move, - unused_resource_explicit_return.move, use_after_move_if.move, use_after_move_if_else.move, use_after_move_loop.move, diff --git a/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs b/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs index dd0e7a11037fa5..af8d2a5ee33e01 100644 --- a/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs +++ b/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs @@ -100,6 +100,9 @@ static UNIT_PATH_REMAP: Lazy> = Lazy::new(|| { // Map file v2../unit_test/test/foo.move // to file v1../unit_test/foo.unit_test.move. ("unit_test/test", "unit_test.unit_test"), + ("unused-assignment/v1-locals", "locals"), + ("unused-assignment/v1-liveness", "liveness"), + ("unused-assignment/v1-typing", "typing"), ("checking-lang-v1/v1-typing", "typing"), ("ability-check/v1-typing", "typing"), ("ability-check/v1-signer", "signer"),