-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[compiler-v2] Preserve wildcard assignments during stackless bytecode generation #12818
Changes from all commits
f0eef27
50f18b5
90a4f07
1999914
6be0e77
596d247
a414bf4
7ec123f
4fa81cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
module 0x42::assign { | ||
|
||
struct S { | ||
struct S has drop { | ||
f: u64, | ||
g: T | ||
} | ||
|
||
struct T { | ||
struct T has drop { | ||
h: u64 | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
module 0x42::fields { | ||
|
||
struct S { | ||
struct S has drop { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made this fix because running checkers reported errors later. |
||
f: u64, | ||
g: T | ||
} | ||
|
||
struct T { | ||
struct T has drop { | ||
h: u64 | ||
} | ||
|
||
struct G<X> { | ||
struct G<X> has drop { | ||
f: X | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,3 +292,16 @@ fun freeze_mut_ref::t8($t0: bool, $t1: &mut freeze_mut_ref::S, $t2: &freeze_mut_ | |
6: label L2 | ||
7: return () | ||
} | ||
|
||
|
||
Diagnostics: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought about fixing the error in the test file, but it changes the test a bit too much for my liking, so left it in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I note that v1 gives a bunch of warnings about "unused assignment or binding" for this file (58x2, 66, 69, 74x2). Are we suppressing such errors on this file or are we just not hitting it yet due to phase ordering? Btw, V1 doesn't have the borrow issue below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused assignment warning is not yet implemented in v2 (tracked here: #11710) |
||
error: mutable reference in local `s` requires exclusive access but is borrowed | ||
┌─ tests/bytecode-generator/freeze_mut_ref.move:66:35 | ||
│ | ||
65 │ let f = &mut ({x = x + 1; s}).f; | ||
│ ----------------------- previous mutable field borrow | ||
66 │ let g = &mut ({x = x + 1; s}).f; | ||
│ ^ requirement enforced here | ||
· | ||
69 │ *({*f = 0; z = y; g}) = 2; | ||
│ ------ conflicting reference `f` used here |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0xc0ffee::m { | ||
public fun test(): u8 { | ||
{ | ||
let x: u8 = 40; | ||
{ | ||
let y: u8 = Move(x); | ||
{ | ||
let _: u8 = x; | ||
y | ||
} | ||
} | ||
} | ||
} | ||
} // end 0xc0ffee::m | ||
|
||
============ initial bytecode ================ | ||
|
||
[variant baseline] | ||
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: $t3 := infer($t1) | ||
3: $t0 := infer($t2) | ||
4: return $t0 | ||
} | ||
|
||
|
||
Diagnostics: | ||
error: cannot move local `x` since it is still in use | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the new error we get, the main subject of the fix. |
||
┌─ 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 |
---|---|---|
|
@@ -11,11 +11,11 @@ module 0x42::operators { | |
x && y || x && !y || !x && y || !x && !y | ||
} | ||
|
||
fun equality<T>(x: T, y: T): bool { | ||
fun equality<T: drop>(x: T, y: T): bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made this fix because running checkers reported errors later. |
||
x == y | ||
} | ||
|
||
fun inequality<T>(x: T, y: T): bool { | ||
fun inequality<T: drop>(x: T, y: T): bool { | ||
x != y | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
Diagnostics: | ||
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(); | ||
│ ^ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module 0xc0ffee::m { | ||
fun tup(): (u64, u64) { | ||
(0, 0) | ||
} | ||
|
||
public fun bar() { | ||
let _ = tup(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be useful to add these new tests to v1 so we can compare the outputs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am bit confused as to where to add these tests back in v1 (unlike, say inlining, it is not obvious which pass/folder these wildcard tests belong to in v1). Suggestions would be appreciated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be ok with a v2/ directory. :-) We can always change it at some later point. As a compiler user, I don't care what pass finds the errors, just that they are found and make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0xc0ffee::m { | ||
public fun baz() { | ||
{ | ||
let x: u64; | ||
{ | ||
let _: u64 = x; | ||
Tuple() | ||
} | ||
} | ||
} | ||
} // end 0xc0ffee::m | ||
|
||
============ initial bytecode ================ | ||
|
||
[variant baseline] | ||
public fun m::baz() { | ||
var $t0: u64 | ||
var $t1: u64 | ||
0: $t1 := infer($t0) | ||
1: return () | ||
} | ||
|
||
|
||
Diagnostics: | ||
error: use of unassigned local `x` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were missing this error before. |
||
┌─ tests/bytecode-generator/wildcard2.move:4:13 | ||
│ | ||
4 │ let _ = x; | ||
│ ^ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the error point to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed an issue for this: #12843 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module 0xc0ffee::m { | ||
public fun baz() { | ||
let x: u64; | ||
let _ = x; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0xc0ffee::m { | ||
struct S { | ||
dummy_field: bool, | ||
} | ||
public fun bar() { | ||
{ | ||
let s: m::S = pack m::S(false); | ||
{ | ||
let _: m::S = s; | ||
Tuple() | ||
} | ||
} | ||
} | ||
public fun foo(s: m::S) { | ||
{ | ||
let _: m::S = s; | ||
Tuple() | ||
} | ||
} | ||
} // end 0xc0ffee::m | ||
|
||
============ initial bytecode ================ | ||
|
||
[variant baseline] | ||
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: $t2 := infer($t0) | ||
3: return () | ||
} | ||
|
||
|
||
[variant baseline] | ||
public fun m::foo($t0: m::S) { | ||
var $t1: m::S | ||
0: $t1 := infer($t0) | ||
1: return () | ||
} | ||
|
||
|
||
Diagnostics: | ||
error: value of type `m::S` does not have the `drop` ability | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice that V1 shows the reason for the error type again:
Please add this test case to existing bug (or file one) to improve the error message for such cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find what we are suggesting here pretty reasonable. We also show the reason (implicitly dropped here ...). This also has nothing to do with this PR (exact same error is reported with non-wildcard variable). Due to the above reasons, I am not filing a bug. But if you feel strongly about some aspect of this reporting, do feel free to file one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, in this case there is a declared type. It's the inferred types that can be nonobvious. |
||
┌─ tests/bytecode-generator/wildcard3.move:5:13 | ||
│ | ||
5 │ let _ = 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module 0xc0ffee::m { | ||
struct S {} | ||
|
||
public fun foo(s: S) { | ||
let _ = s; | ||
} | ||
|
||
public fun bar() { | ||
let s = S{}; | ||
let _ = s; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this fix because running checkers reported errors later.