Skip to content

Conversation

@calintat
Copy link
Contributor

@calintat calintat commented Jan 8, 2026

Description

This PR introduces new assertion macros built on top of the overloaded abort added in an earlier PR.

New assert! form

This now supports formatted messages with arguments:

assert!(cond, fmt, arg1, ..., argN)

// expands to
if (cond) {
    ()
} else {
    abort string::into_bytes(string_utils::format<N>(&fmt, arg1, ..., argN))
}

Example:

let x = 12;
assert!(x < 10, b"Expected x to be less than 10, but got {}", x)

which aborts with message:

Expected x to be less than 10, but got 12

New assert_eq! and assert_ne! macros

These macros mirror the behaviour and ergonomics of Rust’s assert_eq! and assert_ne!, including structured evaluation and rich error messages. There are three forms depending on the number of arguments.

Two arguments

assert_eq!(left, right)

// expands to
match ((left, right)) {
    (_left, _right) => {
        if (_left == _right) {
            ()
        } else {
            abort string::into_bytes(string_utils::format2(<assertion_failed_message>, _left, _right))
        }
    }
}

Three arguments (custom message)

assert_eq!(left, right, message)

// expands to
match ((left, right)) {
    (_left, _right) => {
        if (_left == _right) {
            ()
        } else {
            abort string::into_bytes(string_utils::format3(<assertion_failed_message>, string::utf8(message), _left, _right))
        }
    }
}

More than three arguments (formatted message)

assert_eq!(left, right, fmt, arg1, ..., argN)

// expands to
match ((left, right)) {
    (_left, _right) => {
        if (_left == _right) {
            ()
        } else {
            abort string::into_bytes(string_utils::format3(<assertion_failed_message>, string_utils::format<N>(&fmt, arg1, ..., argN), _left, _right))
        }
    }
}

Assertion failed message format

The assertion failure message format is inspired by Rust and shows both evaluated values:

assertion failed `left == right`
  left: <left>
 right: <right>

It can also include a custom message:

assertion failed `left == right`: <message>
  left: <left>
 right: <right>

Updated test files

Updated 15 existing test files with reordered items, adjusted function indices, and error message changes.

Item reordering

Functions, enums, and structs repositioned in module definitions, with corresponding function index adjustments:

  • move-compiler-v2/tests/bytecode-generator/matching_ok.exp
  • move-compiler-v2/tests/checking/abilities/v1/ability_constraints.exp
  • move-compiler-v2/tests/checking/typing/v1-examples/multi_pool_money_market_token.exp
  • move-compiler-v2/tests/checking/typing/vector_basic_cases.exp
  • move-compiler-v2/tests/file-format-generator/struct_variants.exp
  • move-compiler-v2/tests/file-format-generator/struct_variants.opt.exp
  • move-compiler-v2/tests/file-format-generator/unpack_generic_struct.exp
  • move-compiler-v2/tests/file-format-generator/unpack_generic_struct.opt.exp
  • move-compiler-v2/tests/file-format-generator/unpack_generic_struct_typed.exp
  • move-compiler-v2/tests/file-format-generator/unpack_generic_struct_typed.opt.exp
  • move-compiler-v2/tests/live-var/mut_ref.exp
  • move-compiler-v2/transactional-tests/tests/misc/round-trip/drop_ref_in_branch.decompiled
  • move-compiler-v2/transactional-tests/tests/misc/round-trip/drop_ref_in_branch.decompiled.baseline.exp
  • move-compiler-v2/transactional-tests/tests/no-v1-comparison/enum/round-trip/enum_matching.decompiled

Error message updates

Updated assert macro error message:

  • move-compiler-v2/tests/checking/naming/other_builtins_invalid.exp

How Has This Been Tested?

Added unit tests for all possible forms of assert!, assert_eq!, and assert_ne!.

Key Areas to Review

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
  • Move Compiler
  • Other (specify)

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

Note

Introduces built-in macros expanded pre-typecheck: assert!, assert_eq!, and assert_ne!, including formatted messages (via string_utils::formatN) and rich failure text. Adds version gates (Move ≥2.0/2.4) and structured evaluation to avoid double evaluation.

  • Implements macro expansion in move-model/src/builder/macros.rs, including helpers to call std::string::{utf8, into_bytes} and std::string_utils::formatN
  • Enhances implicit stdlib inclusion in model building to always pull vector, cmp, string, and string_utils; refactors closure collection
  • Adds string::into_bytes to stdlib
  • New tests: compiler-v2 macro suites (valid/invalid forms), transactional e2e tests asserting abort codes/messages; updates golden files (reordered items/function indices) and error text for assert!
  • Test infra tweaks: add "macros" runner; minor decompiler exclusion

Written by Cursor Bugbot for commit c420102. This will update automatically on new commits. Configure here.

Copy link
Contributor Author

calintat commented Jan 8, 2026

@calintat calintat force-pushed the calin/new-assert-macros branch 16 times, most recently from 6e4ed8d to a43331c Compare January 9, 2026 13:45
@calintat calintat force-pushed the calin/compiler-abort-message branch from 7c56a57 to bfd3c95 Compare January 9, 2026 13:45
@calintat calintat force-pushed the calin/new-assert-macros branch 3 times, most recently from cee2eb9 to 3eae191 Compare January 9, 2026 15:07
@calintat calintat marked this pull request as ready for review January 9, 2026 15:47
@calintat calintat requested review from junxzm1990 and wrwg January 9, 2026 15:47
Base automatically changed from calin/compiler-abort-message to main January 9, 2026 16:53
@calintat calintat force-pushed the calin/new-assert-macros branch from 830781c to 3a838c7 Compare January 9, 2026 17:56
@calintat calintat force-pushed the calin/new-assert-macros branch 2 times, most recently from 42b63b9 to 0dcd5e2 Compare January 26, 2026 13:42
@calintat calintat requested review from vineethk and wrwg January 26, 2026 13:58
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.

Very nice work! Couple of minor comments, then good to go.

@calintat calintat force-pushed the calin/new-assert-macros branch from b0e96be to c420102 Compare January 28, 2026 13:50
@calintat calintat enabled auto-merge (squash) January 28, 2026 18:44
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

✅ Forge suite compat success on dcd5ac23be8e137e424dea6371c04bc6bb1f2297 ==> c420102611922ac85e1a16103665764d7b077c8c

Compatibility test results for dcd5ac23be8e137e424dea6371c04bc6bb1f2297 ==> c420102611922ac85e1a16103665764d7b077c8c (PR)
1. Check liveness of validators at old version: dcd5ac23be8e137e424dea6371c04bc6bb1f2297
compatibility::simple-validator-upgrade::liveness-check : committed: 13373.17 txn/s, latency: 2591.33 ms, (p50: 2700 ms, p70: 2900, p90: 3300 ms, p99: 3600 ms), latency samples: 440720
2. Upgrading first Validator to new version: c420102611922ac85e1a16103665764d7b077c8c
compatibility::simple-validator-upgrade::single-validator-upgrade : committed: 5851.42 txn/s, latency: 5809.03 ms, (p50: 6400 ms, p70: 6500, p90: 6600 ms, p99: 6700 ms), latency samples: 202560
3. Upgrading rest of first batch to new version: c420102611922ac85e1a16103665764d7b077c8c
compatibility::simple-validator-upgrade::half-validator-upgrade : committed: 5887.23 txn/s, latency: 5768.23 ms, (p50: 6400 ms, p70: 6500, p90: 6600 ms, p99: 6800 ms), latency samples: 202040
4. upgrading second batch to new version: c420102611922ac85e1a16103665764d7b077c8c
compatibility::simple-validator-upgrade::rest-validator-upgrade : committed: 9651.16 txn/s, latency: 3432.70 ms, (p50: 3300 ms, p70: 4000, p90: 4700 ms, p99: 5500 ms), latency samples: 320100
5. check swarm health
Compatibility test for dcd5ac23be8e137e424dea6371c04bc6bb1f2297 ==> c420102611922ac85e1a16103665764d7b077c8c passed
Test Ok

@github-actions
Copy link
Contributor

✅ Forge suite realistic_env_max_load success on c420102611922ac85e1a16103665764d7b077c8c

two traffics test: inner traffic : committed: 13463.83 txn/s, submitted: 13463.94 txn/s, expired: 0.11 txn/s, latency: 2800.28 ms, (p50: 2700 ms, p70: 3000, p90: 3200 ms, p99: 3600 ms), latency samples: 5003420
two traffics test : committed: 99.98 txn/s, latency: 799.59 ms, (p50: 700 ms, p70: 800, p90: 900 ms, p99: 2500 ms), latency samples: 1720
Latency breakdown for phase 0: ["MempoolToBlockCreation: max: 2.313, avg: 2.176", "ConsensusProposalToOrdered: max: 0.169, avg: 0.166", "ConsensusOrderedToCommit: max: 0.052, avg: 0.047", "ConsensusProposalToCommit: max: 0.218, avg: 0.213"]
Max non-epoch-change gap was: 2 rounds at version 38816 (avg 0.00) [limit 4], 2.21s no progress at version 38816 (avg 0.07s) [limit 15].
Max epoch-change gap was: 0 rounds at version 0 (avg 0.00) [limit 4], 0.28s no progress at version 2397782 (avg 0.28s) [limit 16].
Test Ok

@github-actions
Copy link
Contributor

✅ Forge suite framework_upgrade success on dcd5ac23be8e137e424dea6371c04bc6bb1f2297 ==> c420102611922ac85e1a16103665764d7b077c8c

Forge report malformed: Expecting ',' delimiter: line 1 column 6 (char 5)
'[2026-01-28T19:29:04Z INFO  aptos_forge::report] Test Ok\n{\n  "metrics": [\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "submitted_txn",\n      "value": 200401.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "expired_txn",\n      "value": 580.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "avg_tps",\n      "value": 2215.715572911121\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "avg_latency",\n      "value": 1329.3332682751063\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "p50_latency",\n      "value": 1200.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "p90_latency",\n      "value": 1800.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "p99_latency",\n      "value": 2400.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "submitted_txn",\n      "value": 189802.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "expired_txn",\n      "value": 380.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "avg_tps",\n      "value": 2186.7023604703545\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "avg_latency",\n      "value": 1418.2113482066497\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "p50_latency",\n      "value": 1400.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "p90_latency",\n      "value": 1800.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "p99_latency",\n      "value": 2500.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "submitted_txn",\n      "value": 138541.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "expired_txn",\n      "value": 540.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "avg_tps",\n      "value": 1552.2806739395808\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "avg_latency",\n      "value": 1918.8033130194708\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "p50_latency",\n      "value": 1200.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "p90_latency",\n      "value": 1800.0\n    },\n    {\n      "test_name": "framework_upgrade::framework-upgrade::full-framework-upgrade",\n      "metric": "p99_latency",\n      "value": 12100.0\n    }\n  ],\n  "text": "Compatibility test results for dcd5ac23be8e137e424dea6371c04bc6bb1f2297 ==> c420102611922ac85e1a16103665764d7b077c8c (PR)\\nUpgrade the nodes to version: c420102611922ac85e1a16103665764d7b077c8c\\nframework_upgrade::framework-upgrade::full-framework-upgrade : committed: 2215.72 txn/s, submitted: 2222.15 txn/s, failed submission: 6.43 txn/s, expired: 6.43 txn/s, latency: 1329.33 ms, (p50: 1200 ms, p70: 1500, p90: 1800 ms, p99: 2400 ms), latency samples: 199821\\nframework_upgrade::framework-upgrade::full-framework-upgrade : committed: 2186.70 txn/s, submitted: 2191.09 txn/s, failed submission: 4.39 txn/s, expired: 4.39 txn/s, latency: 1418.21 ms, (p50: 1400 ms, p70: 1500, p90: 1800 ms, p99: 2500 ms), latency samples: 189422\\n5. check swarm health\\nCompatibility test for dcd5ac23be8e137e424dea6371c04bc6bb1f2297 ==> c420102611922ac85e1a16103665764d7b077c8c passed\\nUpgrade the remaining nodes to version: c420102611922ac85e1a16103665764d7b077c8c\\nframework_upgrade::framework-upgrade::full-framework-upgrade : committed: 1552.28 txn/s, submitted: 1558.35 txn/s, failed submission: 6.07 txn/s, expired: 6.07 txn/s, latency: 1918.80 ms, (p50: 1200 ms, p70: 1200, p90: 1800 ms, p99: 12100 ms), latency samples: 138001\\nTest Ok"\n}'
Trailing Log Lines:
Compatibility test results for dcd5ac23be8e137e424dea6371c04bc6bb1f2297 ==> c420102611922ac85e1a16103665764d7b077c8c (PR)
Upgrade the nodes to version: c420102611922ac85e1a16103665764d7b077c8c
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 2215.72 txn/s, submitted: 2222.15 txn/s, failed submission: 6.43 txn/s, expired: 6.43 txn/s, latency: 1329.33 ms, (p50: 1200 ms, p70: 1500, p90: 1800 ms, p99: 2400 ms), latency samples: 199821
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 2186.70 txn/s, submitted: 2191.09 txn/s, failed submission: 4.39 txn/s, expired: 4.39 txn/s, latency: 1418.21 ms, (p50: 1400 ms, p70: 1500, p90: 1800 ms, p99: 2500 ms), latency samples: 189422
5. check swarm health
Compatibility test for dcd5ac23be8e137e424dea6371c04bc6bb1f2297 ==> c420102611922ac85e1a16103665764d7b077c8c passed
Upgrade the remaining nodes to version: c420102611922ac85e1a16103665764d7b077c8c
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 1552.28 txn/s, submitted: 1558.35 txn/s, failed submission: 6.07 txn/s, expired: 6.07 txn/s, latency: 1918.80 ms, (p50: 1200 ms, p70: 1200, p90: 1800 ms, p99: 12100 ms), latency samples: 138001
Test Ok

=== BEGIN JUNIT ===
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="forge" tests="1" failures="0" errors="0" uuid="bbda09c9-5f60-4c61-8954-f8be23909833">
    <testsuite name="local" tests="1" disabled="0" errors="0" failures="0">
        <testcase name="framework_upgrade::framework-upgrade">
        </testcase>
    </testsuite>
</testsuites>
=== END JUNIT ===
[2026-01-28T19:29:04Z INFO  aptos_forge::backend::k8s::cluster_helper] Deleting namespace forge-framework-upgrade-pr-18412: Some(NamespaceStatus { conditions: None, phase: Some("Terminating") })
[2026-01-28T19:29:04Z INFO  aptos_forge::backend::k8s::cluster_helper] aptos-node resources for Forge removed in namespace: forge-framework-upgrade-pr-18412

test result: ok. 1 passed; 0 soft failed; 0 hard failed; 0 filtered out

Debugging output:
NAME                                         READY   STATUS      RESTARTS   AGE
aptos-node-0-validator-0                     1/1     Running     0          11m
aptos-node-1-validator-0                     1/1     Running     0          10m
aptos-node-2-validator-0                     1/1     Running     0          3m3s
aptos-node-3-validator-0                     1/1     Running     0          2m26s
forge-testnet-deployer-zmrcg                 0/1     Completed   0          15m
genesis-aptos-genesis-eforge03148222-8qpl8   0/1     Completed   0          14m

@calintat calintat merged commit 3e33a2d into main Jan 28, 2026
102 of 103 checks passed
@calintat calintat deleted the calin/new-assert-macros branch January 28, 2026 20:14
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.

5 participants