From ed003136cf4e00938bde04aced9165b8af587315 Mon Sep 17 00:00:00 2001 From: Vineeth Kashyap Date: Wed, 10 Apr 2024 12:31:20 -0400 Subject: [PATCH] Addressing code review comments. --- .../tests/bytecode-generator/wildcard1.exp | 2 +- .../tests/bytecode-generator/wildcard5.exp | 35 +++++++++++++ .../tests/bytecode-generator/wildcard5.move | 11 ++++ .../tests/bytecode-generator/wildcard6.exp | 39 ++++++++++++++ .../tests/bytecode-generator/wildcard6.move | 7 +++ .../tests/bytecode-generator/wildcard7.exp | 52 +++++++++++++++++++ .../tests/bytecode-generator/wildcard7.move | 9 ++++ .../checking/typing/v1-commands/pop_weird.exp | 2 +- .../move-model/src/builder/exp_builder.rs | 2 +- 9 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard5.exp create mode 100644 third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard5.move create mode 100644 third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard6.exp create mode 100644 third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard6.move create mode 100644 third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard7.exp create mode 100644 third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard7.move diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard1.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard1.exp index 50c25a1cc25c91..413cd6c8f2ca30 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard1.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard1.exp @@ -1,6 +1,6 @@ Diagnostics: -error: the left-hand side has 2 items but the right-hand side provided 1 +error: the left-hand side has 1 item but the right-hand side provided 2 ┌─ tests/bytecode-generator/wildcard1.move:7:13 │ 7 │ let _ = tup(); diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard5.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard5.exp new file mode 100644 index 00000000000000..5964ecaf52dfde --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard5.exp @@ -0,0 +1,35 @@ +// -- Model dump before bytecode pipeline +module 0xc0ffee::m { + struct S { + x: u64, + y: u64, + } + public fun test() { + { + let s: m::S = pack m::S(3, 4); + { + let m::S{ x: _, y: _ }: m::S = s; + Tuple() + } + } + } +} // end 0xc0ffee::m + +============ initial bytecode ================ + +[variant baseline] +public fun m::test() { + var $t0: m::S + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + 0: $t1 := 3 + 1: $t2 := 4 + 2: $t0 := pack m::S($t1, $t2) + 3: ($t3, $t4) := unpack m::S($t0) + 4: return () +} + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard5.move b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard5.move new file mode 100644 index 00000000000000..b322385c1a16c0 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard5.move @@ -0,0 +1,11 @@ +module 0xc0ffee::m { + struct S { + x: u64, + y: u64 + } + + public fun test() { + let s = S {x: 3, y: 4}; + let S {x: _, y: _} = s; + } +} diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard6.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard6.exp new file mode 100644 index 00000000000000..a2fcf0f8df3e32 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard6.exp @@ -0,0 +1,39 @@ +// -- Model dump before bytecode pipeline +module 0xc0ffee::m { + public fun test2(): u64 { + { + let x: u64 = 40; + { + let (y: u64, _): (u64, u64) = Tuple(Move(x), x); + y + } + } + } +} // end 0xc0ffee::m + +============ initial bytecode ================ + +[variant baseline] +public fun m::test2(): u64 { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + 0: $t1 := 40 + 1: $t3 := move($t1) + 2: $t2 := infer($t3) + 3: $t4 := infer($t1) + 4: $t0 := infer($t2) + 5: return $t0 +} + + +Diagnostics: +error: cannot move local `x` since it is still in use + ┌─ tests/bytecode-generator/wildcard6.move:4:23 + │ +4 │ let (y, _) = (move x, x); + │ ------ ^^^^^^ attempted to move here + │ │ + │ used here diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard6.move b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard6.move new file mode 100644 index 00000000000000..99334951cf2bf2 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard6.move @@ -0,0 +1,7 @@ +module 0xc0ffee::m { + public fun test2(): u64 { + let x = 40; + let (y, _) = (move x, x); + y + } +} diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard7.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard7.exp new file mode 100644 index 00000000000000..1e6874b74166b3 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard7.exp @@ -0,0 +1,52 @@ + +Diagnostics: +warning: Unused local variable `q`. Consider removing or prefixing with an underscore: `_q` + ┌─ tests/bytecode-generator/wildcard7.move:6:17 + │ +6 │ let (_, q) = (x, z); + │ ^ + +// -- Model dump before bytecode pipeline +module 0xc0ffee::m { + public fun test(): u8 { + { + let x: u8 = 40; + { + let y: u8 = Move(x); + { + let (_, q: u64): (u8, u64) = Tuple(x, 30); + y + } + } + } + } +} // end 0xc0ffee::m + +============ initial bytecode ================ + +[variant baseline] +public fun m::test(): u8 { + var $t0: u8 + var $t1: u8 + var $t2: u8 + var $t3: u64 + var $t4: u8 + var $t5: u64 + 0: $t1 := 40 + 1: $t2 := move($t1) + 2: $t4 := infer($t1) + 3: $t5 := 30 + 4: $t3 := infer($t5) + 5: $t0 := infer($t2) + 6: return $t0 +} + + +Diagnostics: +error: cannot move local `x` since it is still in use + ┌─ tests/bytecode-generator/wildcard7.move:5:17 + │ +5 │ let y = move x; + │ ^^^^^^ attempted to move here +6 │ let (_, q) = (x, z); + │ ------ used here diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard7.move b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard7.move new file mode 100644 index 00000000000000..9cc04703832cf1 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard7.move @@ -0,0 +1,9 @@ +module 0xc0ffee::m { + public fun test(): u8 { + let x = 40; + let z = 30; + let y = move x; + let (_, q) = (x, z); + y + } +} diff --git a/third_party/move/move-compiler-v2/tests/checking/typing/v1-commands/pop_weird.exp b/third_party/move/move-compiler-v2/tests/checking/typing/v1-commands/pop_weird.exp index a0e8f74d54ae28..b79b50668a2bd0 100644 --- a/third_party/move/move-compiler-v2/tests/checking/typing/v1-commands/pop_weird.exp +++ b/third_party/move/move-compiler-v2/tests/checking/typing/v1-commands/pop_weird.exp @@ -6,7 +6,7 @@ error: the left-hand side has 2 items but the right-hand side provided 0 13 │ (_, _) = (); │ ^^^^^^ -error: the left-hand side has 0 items but the right-hand side provided 1 +error: the left-hand side has 1 item but the right-hand side provided 0 ┌─ tests/checking/typing/v1-commands/pop_weird.move:14:9 │ 14 │ (_) = (); diff --git a/third_party/move/move-model/src/builder/exp_builder.rs b/third_party/move/move-model/src/builder/exp_builder.rs index 4e26c600126998..8af828fb31c873 100644 --- a/third_party/move/move-model/src/builder/exp_builder.rs +++ b/third_party/move/move-model/src/builder/exp_builder.rs @@ -2214,7 +2214,7 @@ impl<'env, 'translator, 'module_translator> ExpTranslator<'env, 'translator, 'mo let specialized_expected_type = self.subs.specialize(expected_type); if let Type::Tuple(tys) = specialized_expected_type { if tys.len() != 1 { - self.error(loc, &context.arity_mismatch(false, 1, tys.len())); + self.error(loc, &context.arity_mismatch(false, tys.len(), 1)); return self.new_error_pat(loc); } }