Skip to content

Conversation

wrwg
Copy link
Contributor

@wrwg wrwg commented Oct 13, 2025

Description

Allow code to branch over a compile time constant __COMPILE_FOR_TESTING__. The non-reachable branch will be optimized (or at least turned into dead code.)

The name is under discussion. We should make the right decision here since any future compile time constants should be following this naming convention. I see compile constants as an equivalent to Rust attributes, at least if it comes to conditional compilation. This will allow code to mock execution environment dependency in the context of tests:

public fun some_state_dependent_fun(): Data {
    if (__COMPILE_FOR_TESTING__) mock_it() else run_it()
}

The unit tests must link to locally compiled code for this to work.

The design uses the existing concept of builtin constants which we already have for the spec language, used for MAX_U64 et. al. This PR also enables MAX_U64 et. all in the programming language. Builtin constants can be shadowed by the user, keeping existing programs unchanged.

How Has This Been Tested?

New tests

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)

Copy link
Contributor Author

wrwg commented Oct 13, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@wrwg wrwg force-pushed the wrwg/compile-for-testing branch from 0435463 to ca32913 Compare October 13, 2025 16:28
wrwg added 2 commits October 13, 2025 21:51
…__`.

Allow code to branch over a compile time constant `__COMPILE_FOR_TESTING__`. The non-reachable branch will be optimized (or at least turned into dead code.)

The name is under discussion. We should make the right decision here since any future compile time constants should be following this naming convention. I see compile constants as an equivalent to Rust attributes, at least if it comes to conditional compilation.

This falls into the categorie of builtin constants which we already have for the spec llanguage. At the same time, we would enable `MAX_U64` et. all as builtin constants in the language.

Builtin constants can be shadowed by the user, so no harm to existing move programs would be implied.
…of framework, because it may not compile with older compilers.
@wrwg wrwg force-pushed the wrwg/compile-for-testing branch from ca32913 to d46acdb Compare October 14, 2025 16:13
@wrwg wrwg enabled auto-merge (squash) October 14, 2025 16:16

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

✅ Forge suite compat success on 75cc050c2c35782fc994c2a7e61a7fb3ea88f71f ==> d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87

Compatibility test results for 75cc050c2c35782fc994c2a7e61a7fb3ea88f71f ==> d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87 (PR)
1. Check liveness of validators at old version: 75cc050c2c35782fc994c2a7e61a7fb3ea88f71f
compatibility::simple-validator-upgrade::liveness-check : committed: 14411.41 txn/s, latency: 2409.64 ms, (p50: 2500 ms, p70: 2700, p90: 2800 ms, p99: 3300 ms), latency samples: 467540
2. Upgrading first Validator to new version: d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87
compatibility::simple-validator-upgrade::single-validator-upgrade : committed: 5258.83 txn/s, latency: 6544.28 ms, (p50: 7300 ms, p70: 7400, p90: 7400 ms, p99: 7500 ms), latency samples: 182100
3. Upgrading rest of first batch to new version: d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87
compatibility::simple-validator-upgrade::half-validator-upgrade : committed: 5262.83 txn/s, latency: 6533.31 ms, (p50: 7300 ms, p70: 7400, p90: 7400 ms, p99: 7500 ms), latency samples: 181840
4. upgrading second batch to new version: d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87
compatibility::simple-validator-upgrade::rest-validator-upgrade : committed: 8258.06 txn/s, latency: 4131.84 ms, (p50: 4500 ms, p70: 4600, p90: 4700 ms, p99: 4800 ms), latency samples: 274680
5. check swarm health
Compatibility test for 75cc050c2c35782fc994c2a7e61a7fb3ea88f71f ==> d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87 passed
Test Ok

Copy link
Contributor

✅ Forge suite realistic_env_max_load success on d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87

two traffics test: inner traffic : committed: 14041.63 txn/s, latency: 2677.80 ms, (p50: 2600 ms, p70: 2700, p90: 3000 ms, p99: 4700 ms), latency samples: 5338980
two traffics test : committed: 100.00 txn/s, latency: 1122.38 ms, (p50: 900 ms, p70: 1200, p90: 1800 ms, p99: 3300 ms), latency samples: 1800
Latency breakdown for phase 0: ["MempoolToBlockCreation: max: 2.081, avg: 1.759", "ConsensusProposalToOrdered: max: 0.168, avg: 0.165", "ConsensusOrderedToCommit: max: 0.583, avg: 0.242", "ConsensusProposalToCommit: max: 0.751, avg: 0.406"]
Max non-epoch-change gap was: 2 rounds at version 72007 (avg 0.00) [limit 4], 2.24s no progress at version 5185616 (avg 0.07s) [limit 15].
Max epoch-change gap was: 0 rounds at version 0 (avg 0.00) [limit 4], 0.25s no progress at version 2159401 (avg 0.25s) [limit 16].
Test Ok

Copy link
Contributor

✅ Forge suite framework_upgrade success on 75cc050c2c35782fc994c2a7e61a7fb3ea88f71f ==> d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87

Compatibility test results for 75cc050c2c35782fc994c2a7e61a7fb3ea88f71f ==> d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87 (PR)
Upgrade the nodes to version: d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 2040.69 txn/s, submitted: 2045.97 txn/s, failed submission: 5.27 txn/s, expired: 5.27 txn/s, latency: 1453.38 ms, (p50: 1200 ms, p70: 1500, p90: 2100 ms, p99: 3300 ms), latency samples: 185741
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 2110.20 txn/s, submitted: 2117.26 txn/s, failed submission: 7.06 txn/s, expired: 7.06 txn/s, latency: 1388.12 ms, (p50: 1200 ms, p70: 1500, p90: 2000 ms, p99: 3300 ms), latency samples: 191301
5. check swarm health
Compatibility test for 75cc050c2c35782fc994c2a7e61a7fb3ea88f71f ==> d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87 passed
Upgrade the remaining nodes to version: d46acdbebcef98d7b7aeb7fc88215ca7e4ed0c87
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 2206.30 txn/s, submitted: 2211.86 txn/s, failed submission: 5.57 txn/s, expired: 5.57 txn/s, latency: 1363.99 ms, (p50: 1200 ms, p70: 1500, p90: 1800 ms, p99: 2100 ms), latency samples: 198221
Test Ok

@wrwg wrwg merged commit 52ae042 into main Oct 14, 2025
103 of 106 checks passed
@wrwg wrwg deleted the wrwg/compile-for-testing branch October 14, 2025 17:10
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.

3 participants