Skip to content

Commit

Permalink
Showcase fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethk committed Apr 10, 2024
1 parent 586f77e commit f1a4351
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
9 changes: 7 additions & 2 deletions third_party/move/move-compiler-v2/src/bytecode_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,8 +1271,13 @@ impl<'env> Generator<'env> {
) {
match pat {
Pattern::Wildcard(_) => {
// Nothing to do
// TODO(#12475) Should we copy to a temp here?
let ty = self.temp_type(arg).to_owned();
let temp = self.new_temp(ty);
// Assign to a temporary to allow stackless bytecode checkers to report any errors
// due to the assignment.
self.emit_with(id, |attr| {
Bytecode::Assign(attr, temp, arg, AssignKind::Inferred)
})
},
Pattern::Var(var_id, sym) => {
let local = self.find_local_for_pattern(*var_id, *sym, next_scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ public fun m::test(): u8 {
var $t0: u8
var $t1: u8
var $t2: u8
var $t3: u8
0: $t1 := 40
1: $t2 := move($t1)
2: $t0 := infer($t2)
3: return $t0
2: $t3 := infer($t1)
3: $t0 := infer($t2)
4: return $t0
}


============ bytecode verification succeeded ========
Diagnostics:
error: cannot move local `x` since it is still in use
┌─ tests/bytecode-generator/moved_var_not_simplified3.move:4:17
4 │ let y = move x;
│ ^^^^^^ attempted to move here
5 │ let _ = x;
│ - used here
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ module 0xc0ffee::m {

[variant baseline]
public fun m::baz() {
var $t0: u64 [unused]
0: return ()
var $t0: u64
var $t1: u64
0: $t1 := infer($t0)
1: return ()
}


============ bytecode verification succeeded ========
Diagnostics:
error: use of unassigned local `x`
┌─ tests/bytecode-generator/wildcard2.move:4:13
4 │ let _ = x;
│ ^
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,31 @@ module 0xc0ffee::m {
public fun m::bar() {
var $t0: m::S
var $t1: bool
var $t2: m::S
0: $t1 := false
1: $t0 := pack m::S($t1)
2: return ()
2: $t2 := infer($t0)
3: return ()
}


[variant baseline]
public fun m::foo($t0: m::S) {
0: return ()
var $t1: m::S
0: $t1 := infer($t0)
1: return ()
}


Diagnostics:
error: local `s` of type `m::S` does not have the `drop` ability
┌─ tests/bytecode-generator/wildcard3.move:5:18
error: value of type `m::S` does not have the `drop` ability
┌─ tests/bytecode-generator/wildcard3.move:5:13
5 │ let _ = s;
^ implicitly dropped here since it is no longer used
│ ^ implicitly dropped here since it is no longer used

error: local `s` of type `m::S` does not have the `drop` ability
┌─ tests/bytecode-generator/wildcard3.move:9:17
9 │ let s = S{};
^^^ implicitly dropped here since it is no longer used
error: value of type `m::S` does not have the `drop` ability
┌─ tests/bytecode-generator/wildcard3.move:10:13
10 │ let _ = s;
│ ^ implicitly dropped here since it is no longer used
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ fun m::test() {
var $t1: &mut u64
var $t2: &mut u64
var $t3: &u64
var $t4: u64
var $t4: &u64
var $t5: u64
0: $t0 := 3
1: $t1 := borrow_local($t0)
2: $t2 := borrow_local($t0)
3: $t3 := freeze_ref($t2)
4: $t4 := 4
5: write_ref($t1, $t4)
6: return ()
4: $t4 := infer($t3)
5: $t5 := 4
6: write_ref($t1, $t5)
7: return ()
}


Expand Down

0 comments on commit f1a4351

Please sign in to comment.