-
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
[move-compiler-v2] Fix #14329: Make code optional in assert!(cond, code)
#14334
Conversation
assert!(cond, code)
assert!(cond, code)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #14334 +/- ##
===========================================
- Coverage 70.7% 59.5% -11.2%
===========================================
Files 2370 838 -1532
Lines 475443 205043 -270400
===========================================
- Hits 336456 122163 -214293
+ Misses 138987 82880 -56107 ☔ View full report in Codecov by Sentry. |
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.
Looks good so far - minor comments.
I think we should make this a Move 2 language behavior (and produce errors for Move 1, like compiler v1).
@@ -51,4 +51,5 @@ pub const RECEIVER_PARAM_NAME: &str = "self"; | |||
/// TODO: add a check at runtime that user is not clashing with reserved | |||
/// codes? | |||
pub const WELL_KNOWN_ABORT_CODE_BASE: u64 = 0xD8CA26CBD9BE << 16; | |||
pub const UNSPECIFIED_ABORT_CODE: u64 = WELL_KNOWN_ABORT_CODE_BASE; |
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.
Maybe add a brief note on what this unspecified abort code is? (i.e., the abort code used when user does not explicitly specify one in an assert!
).
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.
Ok.
@@ -5,7 +5,7 @@ | |||
//! Module for expanding macros, as `assert!(cond, code)`. This are expanded to |
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.
Maybe add a note here that assert!(cond)
is also allowed?
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.
|
||
let i = 0; | ||
while (i < Test::len(&x)) { | ||
assert!(Test::modify(&mut x) == i + 1); // this will fail |
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.
So currently, this behavior (of allowing 1 arg to assert!
) is compiler v2 only? In that case, I think we should make this a Move 2 language change. If not, depending on the compiler used, we can have differing behavior for Move 1, without any warning or indication.
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.
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 is a Move 2 feature. Lets add a test to checking-lang-v1 directory to verify we get the right error message for v1
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.
error: assert macro must have two arguments | ||
┌─ tests/checking/naming/assert_one_arg.move:5:16 | ||
error: undeclared `y` | ||
┌─ tests/checking/naming/assert_one_arg.move:5:22 | ||
│ | ||
5 │ assert!(x != y); |
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 should also document this change in the Move book, given that it is fairly commonly used everywhere.
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 #14343 to track.
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'll take care of this in next PR.
20a0b3b
to
d3ea6cf
Compare
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.
Nice!
error: assert macro must have two arguments | ||
┌─ tests/checking/naming/assert_one_arg.move:5:16 | ||
error: undeclared `y` | ||
┌─ tests/checking/naming/assert_one_arg.move:5:22 | ||
│ | ||
5 │ assert!(x != y); |
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'll take care of this in next PR.
|
||
let i = 0; | ||
while (i < Test::len(&x)) { | ||
assert!(Test::modify(&mut x) == i + 1); // this will fail |
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 is a Move 2 feature. Lets add a test to checking-lang-v1 directory to verify we get the right error message for v1
let abort_code = args.value[1].clone(); | ||
let (cond, abort_code) = match args.value.len() { | ||
1 => { | ||
self.check_language_version( |
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.
Can we add a test in third_party/move/move-compiler/tests/move_check/parser
to see this is guarded for V1? Does the V1 compiler use the move model for compilation?
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 already have a test in third_party/move/move-compiler/tests/move_check/naming/assert_one_arg.move. I've added a separate warning in the V1 code to clarify that this is not supported in that compiler.
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.
Addressed all comments.
@@ -51,4 +51,5 @@ pub const RECEIVER_PARAM_NAME: &str = "self"; | |||
/// TODO: add a check at runtime that user is not clashing with reserved | |||
/// codes? | |||
pub const WELL_KNOWN_ABORT_CODE_BASE: u64 = 0xD8CA26CBD9BE << 16; | |||
pub const UNSPECIFIED_ABORT_CODE: u64 = WELL_KNOWN_ABORT_CODE_BASE; |
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.
Ok.
@@ -5,7 +5,7 @@ | |||
//! Module for expanding macros, as `assert!(cond, code)`. This are expanded to |
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.
|
||
let i = 0; | ||
while (i < Test::len(&x)) { | ||
assert!(Test::modify(&mut x) == i + 1); // this will fail |
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.
error: assert macro must have two arguments | ||
┌─ tests/checking/naming/assert_one_arg.move:5:16 | ||
error: undeclared `y` | ||
┌─ tests/checking/naming/assert_one_arg.move:5:22 | ||
│ | ||
5 │ assert!(x != y); |
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 #14343 to track.
|
||
let i = 0; | ||
while (i < Test::len(&x)) { | ||
assert!(Test::modify(&mut x) == i + 1); // this will fail |
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.
let abort_code = args.value[1].clone(); | ||
let (cond, abort_code) = match args.value.len() { | ||
1 => { | ||
self.check_language_version( |
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 already have a test in third_party/move/move-compiler/tests/move_check/naming/assert_one_arg.move. I've added a separate warning in the V1 code to clarify that this is not supported in that compiler.
49bc685
to
213f7c0
Compare
213f7c0
to
d2afa8f
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.
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
|
✅ Forge suite
|
Description
Fix #14329 by making code optional in
assert!(cond, code)
.We use the code
well_known::UNSPECIFIED_ABORT_CODE
value by default,which is set to
WELL_KNOWN_ABORT_CODE_BASE = 0xD8CA26CBD9BE << 16
,which is 15621340914461310976 in decimal.
Type of Change
Which Components or Systems Does This Change Impact?
Move compiler
How Has This Been Tested?
Existing and new tests.
Key Areas to Review
Should we get this on Language v2? I don't think it's necessary, but...
Checklist