Skip to content
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

Merged
merged 6 commits into from
Aug 22, 2024

Conversation

brmataptos
Copy link
Contributor

@brmataptos brmataptos commented Aug 19, 2024

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

  • New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Other (specify)
    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

  • I have read and followed the CONTRIBUTING doc
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I identified and added all stakeholders and component owners affected by this change as reviewers
  • I tested both happy and unhappy path of the functionality
  • I have made corresponding changes to the documentation

Copy link

trunk-io bot commented Aug 19, 2024

⏱️ 6h 29m total CI duration on this PR
Job Cumulative Duration Recent Runs
execution-performance / single-node-performance 1h 4m 🟥🟩🟩
forge-framework-upgrade-test / forge 30m 🟩🟩
forge-e2e-test / forge 27m 🟩🟩
forge-compat-test / forge 27m 🟩🟩
general-lints 16m 🟩🟩🟩🟩 (+4 more)
rust-cargo-deny 15m 🟩🟩🟩🟩 (+4 more)
test-target-determinator 13m 🟩🟩🟩
execution-performance / test-target-determinator 13m 🟩🟩🟩
rust-move-unit-coverage 11m 🟩
check 11m 🟩🟩🟩
check-dynamic-deps 10m 🟩🟩🟩🟩🟩 (+4 more)
rust-move-unit-coverage 10m 🟩
rust-move-unit-coverage 10m 🟩
rust-move-tests 9m 🟩
rust-move-tests 9m 🟩
rust-move-tests 9m 🟩
rust-move-tests 9m 🟩
rust-move-tests 8m 🟩
rust-move-tests 8m 🟩
rust-move-tests 8m 🟩
rust-move-tests 8m
rust-move-unit-coverage 8m 🟩
rust-move-unit-coverage 8m
rust-move-unit-coverage 8m 🟩
rust-move-unit-coverage 8m 🟩
rust-move-unit-coverage 7m 🟩
rust-doc-tests 5m 🟩
rust-doc-tests 5m 🟩
rust-doc-tests 5m 🟩
semgrep/ci 4m 🟩🟩🟩🟩🟩 (+4 more)
file_change_determinator 2m 🟩🟩🟩🟩🟩 (+4 more)
file_change_determinator 2m 🟩🟩🟩🟩🟩 (+4 more)
rust-move-tests 1m
permission-check 40s 🟩🟩🟩🟩🟩 (+4 more)
permission-check 37s 🟩🟩🟩🟩🟩 (+4 more)
permission-check 36s 🟩🟩🟩🟩🟩 (+4 more)
file_change_determinator 35s 🟩🟩🟩
permission-check 31s 🟩🟩🟩🟩🟩 (+4 more)
permission-check 6s 🟩🟩🟩
Backport PR 6s 🟥
determine-docker-build-metadata 6s 🟩🟩🟩
permission-check 3s 🟩

settingsfeedbackdocs ⋅ learn more about trunk.io

@brmataptos brmataptos changed the title Fix #14329: Make code optional in assert!(cond, code) [move-compiler-v2] Fix #14329: Make code optional in assert!(cond, code) Aug 19, 2024
Copy link

codecov bot commented Aug 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.5%. Comparing base (996d51d) to head (b18245e).
Report is 3 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (996d51d) and HEAD (b18245e). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (996d51d) HEAD (b18245e)
2 1
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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@vineethk vineethk left a 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;
Copy link
Contributor

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!).

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #14343 to track.

Copy link
Contributor

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.

Copy link
Contributor

@wrwg wrwg left a 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);
Copy link
Contributor

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
Copy link
Contributor

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(
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@brmataptos brmataptos left a 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;
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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);
Copy link
Contributor Author

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
Copy link
Contributor Author

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(
Copy link
Contributor Author

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.

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.

Copy link
Contributor

✅ Forge suite realistic_env_max_load success on b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac

two traffics test: inner traffic : committed: 12641.58 txn/s, latency: 3148.58 ms, (p50: 3000 ms, p90: 3600 ms, p99: 4200 ms), latency samples: 4806620
two traffics test : committed: 99.98 txn/s, latency: 2594.05 ms, (p50: 2400 ms, p90: 2800 ms, p99: 6500 ms), latency samples: 1720
Latency breakdown for phase 0: ["QsBatchToPos: max: 0.251, avg: 0.224", "QsPosToProposal: max: 0.407, avg: 0.358", "ConsensusProposalToOrdered: max: 0.334, avg: 0.317", "ConsensusOrderedToCommit: max: 0.615, avg: 0.584", "ConsensusProposalToCommit: max: 0.939, avg: 0.901"]
Max non-epoch-change gap was: 0 rounds at version 0 (avg 0.00) [limit 4], 0.94s no progress at version 2609435 (avg 0.22s) [limit 15].
Max epoch-change gap was: 0 rounds at version 0 (avg 0.00) [limit 4], 7.80s no progress at version 2609433 (avg 7.80s) [limit 15].
Test Ok

Copy link
Contributor

✅ Forge suite compat success on d1bf834728a0cf166d993f4728dfca54f3086fb0 ==> b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac

Compatibility test results for d1bf834728a0cf166d993f4728dfca54f3086fb0 ==> b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac (PR)
1. Check liveness of validators at old version: d1bf834728a0cf166d993f4728dfca54f3086fb0
compatibility::simple-validator-upgrade::liveness-check : committed: 13548.16 txn/s, latency: 2497.08 ms, (p50: 2400 ms, p90: 3300 ms, p99: 4900 ms), latency samples: 442540
2. Upgrading first Validator to new version: b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac
compatibility::simple-validator-upgrade::single-validator-upgrading : committed: 7611.66 txn/s, latency: 3732.35 ms, (p50: 4200 ms, p90: 4600 ms, p99: 4800 ms), latency samples: 138080
compatibility::simple-validator-upgrade::single-validator-upgrade : committed: 6788.49 txn/s, latency: 4479.93 ms, (p50: 4600 ms, p90: 4900 ms, p99: 6200 ms), latency samples: 253720
3. Upgrading rest of first batch to new version: b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac
compatibility::simple-validator-upgrade::half-validator-upgrading : committed: 6184.06 txn/s, latency: 4267.95 ms, (p50: 4800 ms, p90: 5200 ms, p99: 5300 ms), latency samples: 127100
compatibility::simple-validator-upgrade::half-validator-upgrade : committed: 6709.70 txn/s, latency: 4763.59 ms, (p50: 4700 ms, p90: 7100 ms, p99: 7500 ms), latency samples: 230720
4. upgrading second batch to new version: b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac
compatibility::simple-validator-upgrade::rest-validator-upgrading : committed: 10992.71 txn/s, latency: 2452.35 ms, (p50: 2700 ms, p90: 2900 ms, p99: 3000 ms), latency samples: 192900
compatibility::simple-validator-upgrade::rest-validator-upgrade : committed: 11593.70 txn/s, latency: 2715.72 ms, (p50: 2600 ms, p90: 3200 ms, p99: 4200 ms), latency samples: 381100
5. check swarm health
Compatibility test for d1bf834728a0cf166d993f4728dfca54f3086fb0 ==> b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac passed
Test Ok

Copy link
Contributor

✅ Forge suite framework_upgrade success on d1bf834728a0cf166d993f4728dfca54f3086fb0 ==> b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac

Compatibility test results for d1bf834728a0cf166d993f4728dfca54f3086fb0 ==> b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac (PR)
Upgrade the nodes to version: b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 1271.49 txn/s, submitted: 1272.65 txn/s, failed submission: 1.16 txn/s, expired: 1.16 txn/s, latency: 2608.00 ms, (p50: 2400 ms, p90: 4200 ms, p99: 6400 ms), latency samples: 109820
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 1009.12 txn/s, submitted: 1011.56 txn/s, failed submission: 2.45 txn/s, expired: 2.45 txn/s, latency: 2921.22 ms, (p50: 2700 ms, p90: 4300 ms, p99: 6500 ms), latency samples: 90740
5. check swarm health
Compatibility test for d1bf834728a0cf166d993f4728dfca54f3086fb0 ==> b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac passed
Upgrade the remaining nodes to version: b18245e9acec2e1a5dc78759b2bcd1b88bcfdbac
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 1141.54 txn/s, submitted: 1143.96 txn/s, failed submission: 2.42 txn/s, expired: 2.42 txn/s, latency: 2769.11 ms, (p50: 2400 ms, p90: 4800 ms, p99: 6100 ms), latency samples: 103640
Test Ok

@brmataptos brmataptos merged commit 1a5d58a into main Aug 22, 2024
51 checks passed
@brmataptos brmataptos deleted the brm-issue-14329 branch August 22, 2024 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[compiler-v2][release] Make code optional in assert!(cond, code)
4 participants