-
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
Conversation
@@ -1,11 +1,11 @@ | |||
module 0x42::assign { | |||
|
|||
struct S { | |||
struct S has drop { |
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Made this fix because running checkers reported errors later.
@@ -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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Unused assignment warning is not yet implemented in v2 (tracked here: #11710)
|
||
|
||
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 comment
The 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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Made this fix because running checkers reported errors later.
|
||
|
||
Diagnostics: | ||
error: use of unassigned local `x` |
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.
We were missing this error before.
@@ -80,6 +80,8 @@ L1: loc1: u64 | |||
L2: loc2: u64 | |||
L3: loc3: u64 | |||
L4: loc4: u64 | |||
L5: loc5: u64 |
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.
Note that this is the unoptimized output (and therefore, it is worse due the change in this PR).
The optimized output is better than this, and does not change due to the fix.
@@ -222,11 +222,11 @@ const TEST_CONFIGS: Lazy<BTreeMap<&str, TestConfig>> = Lazy::new(|| { | |||
exclude: vec![], | |||
exp_suffix: None, | |||
options: opts.clone(), | |||
// Run the bytecode pipeline as well for double-checking the result |
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.
We were not running the bytecode pipeline, now we do.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #12818 +/- ##
=========================================
- Coverage 62.6% 62.6% -0.1%
=========================================
Files 823 821 -2
Lines 184343 184181 -162
=========================================
- Hits 115499 115393 -106
+ Misses 68844 68788 -56 ☔ View full report in Codecov by Sentry. |
Is it possible to have
and can we have a tuple with wildcards in an assignment as an example? It shouldn't be different, but who knows.j
and some variations:
etc. |
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.
Some questions about outputs. Also, need a few new test cases and to add the test cases to v1 for comparison.
} | ||
|
||
public fun bar() { | ||
let _ = tup(); |
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.
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -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 comment
The 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.
@@ -0,0 +1,7 @@ | |||
|
|||
Diagnostics: | |||
error: the left-hand side has 2 items but the right-hand side provided 1 |
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.
Other occurrences of this error message have the correct direction. Why does this one seem backwards? Let's fix it here.
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.
Also, V1 shows the type of tup() here, which is useful:
error[E04005]: expected a single type
┌─ tests/move_check/v2/wildcard1.move:7:13
│
2 │ fun tup(): (u64, u64) {
│ ---------- Expected a single type, but found expression list type: '(u64, u64)'
·
7 │ let _ = tup();
│ ^ Invalid type for local
Please make sure we have a bug filed to improve these sorts of error messages.
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.
Why does this one seem backwards? Let's fix it here.
It was a pre-existing bug in the exp builder, fixed it.
Nice catch.
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.
Please make sure we have a bug filed to improve these sorts of error messages.
There was another issue you filed that was close enough to this one, I added this test case to that issue (#12669).
┌─ tests/bytecode-generator/wildcard2.move:4:13 | ||
│ | ||
4 │ let _ = x; | ||
│ ^ |
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.
Why does the error point to _
instead of x
?
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.
Filed an issue for this: #12843
|
||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that V1 shows the reason for the error type again:
error[E05001]: ability constraint not satisfied
┌─ tests/move_check/v2/wildcard3.move:5:13
│
2 │ struct S {}
│ - To satisfy the constraint, the 'drop' ability would need to be added here
3 │
4 │ public fun foo(s: S) {
│ - The type '0xC0FFEE::m::S' does not have the ability 'drop'
5 │ let _ = s;
│ ^ Cannot ignore values without the 'drop' ability. The value must be used
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 comment
The 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 comment
The 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.
870f631
to
fdc19d3
Compare
@brmataptos Thank you for the test cases, I have added all these. Note that some of the error outputs have the same issue filed #12843, which I reference in that issue. |
fdc19d3
to
2207559
Compare
@brmataptos PTAL. |
8bcec3d
to
a414bf4
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
Description
Fixes #12475.
During stackless bytecode generation, if we have the code
let _ = rexp
, then we would skip this assignment (after evaluating any side-effects inrexp
). This would prevent any stackless-bytecode based error checkers from seeing this assignment, and potentially miss reporting an error based on it.We now preserve this assignment, because of which we can report some previously missing errors (or provide better error locations).
Additionally, we run the full compiler pipeline for
bytecode-generator
test folder (so that we can see all errors reported, rather than stop right after bytecode generation). The old comment claimed that we ran the bytecode pipeline, but we did not (which is fixed in this PR).The first commit showcases the issue, the second commit showcases the fix, and the final commit shows the test baseline changes.
Going back to comments made in #12475:
_
matching a tuple, as it is caught by the type checker.Tests have been added for both these cases.
Type of Change
Which Components or Systems Does This Change Impact?
How Has This Been Tested?
wildcard*.move
, and movedmoved_var_not_simplified3.move
(the OG test showing the issue which this PR fixes) fromno-simplifier
tobytecode-generator
(which is where I think is a better home).Key Areas to Review
The first two commits showcasing the issue and the fix.