Skip to content

Commit 3497c86

Browse files
authored
[compiler-v2] Enable recent stack-optimizations by default (aptos-labs#15595)
1 parent 1c4f6ed commit 3497c86

File tree

82 files changed

+1764
-2080
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1764
-2080
lines changed

aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/diamond_clicker.v2_exp

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,45 @@ struct OuterStruct has key {
1515
}
1616

1717
entry public test_upgrade(Arg0: &signer) /* def_idx: 0 */ {
18-
L1: loc0: OuterStruct
19-
L2: loc1: &mut vector<InnerStruct>
18+
L1: loc0: &mut vector<InnerStruct>
19+
L2: loc1: u64
2020
L3: loc2: u64
21-
L4: loc3: u64
22-
L5: loc4: u64
2321
B0:
2422
0: CopyLoc[0](Arg0: &signer)
2523
1: Call signer::address_of(&signer): address
26-
2: VecPack(3, 0)
27-
3: Pack[1](OuterStruct)
28-
4: StLoc[1](loc0: OuterStruct)
29-
5: MoveLoc[0](Arg0: &signer)
30-
6: MoveLoc[1](loc0: OuterStruct)
31-
7: MoveTo[1](OuterStruct)
32-
8: MutBorrowGlobal[1](OuterStruct)
33-
9: MutBorrowField[0](OuterStruct.any_field: vector<InnerStruct>)
34-
10: StLoc[2](loc1: &mut vector<InnerStruct>)
35-
11: LdU64(0)
36-
12: StLoc[3](loc2: u64)
37-
13: CopyLoc[2](loc1: &mut vector<InnerStruct>)
38-
14: FreezeRef
39-
15: VecLen(3)
40-
16: StLoc[4](loc3: u64)
24+
2: MoveLoc[0](Arg0: &signer)
25+
3: VecPack(3, 0)
26+
4: Pack[1](OuterStruct)
27+
5: MoveTo[1](OuterStruct)
28+
6: MutBorrowGlobal[1](OuterStruct)
29+
7: MutBorrowField[0](OuterStruct.any_field: vector<InnerStruct>)
30+
8: StLoc[1](loc0: &mut vector<InnerStruct>)
31+
9: LdU64(0)
32+
10: StLoc[2](loc1: u64)
33+
11: CopyLoc[1](loc0: &mut vector<InnerStruct>)
34+
12: FreezeRef
35+
13: VecLen(3)
36+
14: StLoc[3](loc2: u64)
4137
B1:
42-
17: CopyLoc[3](loc2: u64)
43-
18: CopyLoc[4](loc3: u64)
44-
19: Lt
45-
20: BrFalse(31)
38+
15: CopyLoc[2](loc1: u64)
39+
16: CopyLoc[3](loc2: u64)
40+
17: Lt
41+
18: BrFalse(29)
4642
B2:
47-
21: CopyLoc[2](loc1: &mut vector<InnerStruct>)
48-
22: CopyLoc[3](loc2: u64)
49-
23: VecMutBorrow(3)
50-
24: FreezeRef
51-
25: Call debug::print<InnerStruct>(&InnerStruct)
52-
26: MoveLoc[3](loc2: u64)
53-
27: LdU64(1)
54-
28: Add
55-
29: StLoc[3](loc2: u64)
56-
30: Branch(17)
43+
19: CopyLoc[1](loc0: &mut vector<InnerStruct>)
44+
20: CopyLoc[2](loc1: u64)
45+
21: VecMutBorrow(3)
46+
22: FreezeRef
47+
23: Call debug::print<InnerStruct>(&InnerStruct)
48+
24: MoveLoc[2](loc1: u64)
49+
25: LdU64(1)
50+
26: Add
51+
27: StLoc[2](loc1: u64)
52+
28: Branch(15)
5753
B3:
58-
31: MoveLoc[2](loc1: &mut vector<InnerStruct>)
59-
32: Pop
60-
33: Ret
54+
29: MoveLoc[1](loc0: &mut vector<InnerStruct>)
55+
30: Pop
56+
31: Ret
6157
}
6258
}
6359

aptos-move/framework/aptos-framework/tests/compiler-v2-doc/aptos_governance.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ This function is private because it's called directly from the vm.
883883
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(aptos_framework);
884884

885885
<a href="voting.md#0x1_voting_register">voting::register</a>&lt;GovernanceProposal&gt;(aptos_framework);
886+
<a href="aptos_governance.md#0x1_aptos_governance_initialize_partial_voting">initialize_partial_voting</a>(aptos_framework);
886887
<b>move_to</b>(aptos_framework, <a href="aptos_governance.md#0x1_aptos_governance_GovernanceConfig">GovernanceConfig</a> {
887888
voting_duration_secs,
888889
min_voting_threshold,
@@ -2132,6 +2133,7 @@ Limit addition overflow.
21322133
<b>ensures</b> <b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_GovernanceEvents">GovernanceEvents</a>&gt;(addr);
21332134
<b>ensures</b> <b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_VotingRecords">VotingRecords</a>&gt;(addr);
21342135
<b>ensures</b> <b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_ApprovedExecutionHashes">ApprovedExecutionHashes</a>&gt;(addr);
2136+
<b>ensures</b> <b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_VotingRecordsV2">VotingRecordsV2</a>&gt;(addr);
21352137
</code></pre>
21362138

21372139

@@ -2204,6 +2206,7 @@ Abort if structs have already been created.
22042206
<b>aborts_if</b> <b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_VotingRecords">VotingRecords</a>&gt;(addr);
22052207
<b>aborts_if</b> <b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_ApprovedExecutionHashes">ApprovedExecutionHashes</a>&gt;(addr);
22062208
<b>aborts_if</b> !<b>exists</b>&lt;<a href="account.md#0x1_account_Account">account::Account</a>&gt;(addr);
2209+
<b>aborts_if</b> <b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_VotingRecordsV2">VotingRecordsV2</a>&gt;(addr);
22072210
}
22082211
</code></pre>
22092212

aptos-move/framework/aptos-framework/tests/compiler-v2-doc/coin.md

Lines changed: 93 additions & 73 deletions
Large diffs are not rendered by default.

aptos-move/framework/aptos-framework/tests/compiler-v2-doc/genesis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ Genesis step 1: Initialize aptos framework account and core modules on chain.
340340
<a href="execution_config.md#0x1_execution_config_set">execution_config::set</a>(&aptos_framework_account, <a href="execution_config.md#0x1_execution_config">execution_config</a>);
341341
<a href="version.md#0x1_version_initialize">version::initialize</a>(&aptos_framework_account, initial_version);
342342
<a href="stake.md#0x1_stake_initialize">stake::initialize</a>(&aptos_framework_account);
343+
<a href="timestamp.md#0x1_timestamp_set_time_has_started">timestamp::set_time_has_started</a>(&aptos_framework_account);
343344
<a href="staking_config.md#0x1_staking_config_initialize">staking_config::initialize</a>(
344345
&aptos_framework_account,
345346
minimum_stake,
@@ -360,7 +361,6 @@ Genesis step 1: Initialize aptos framework account and core modules on chain.
360361
<a href="reconfiguration.md#0x1_reconfiguration_initialize">reconfiguration::initialize</a>(&aptos_framework_account);
361362
<a href="block.md#0x1_block_initialize">block::initialize</a>(&aptos_framework_account, epoch_interval_microsecs);
362363
<a href="state_storage.md#0x1_state_storage_initialize">state_storage::initialize</a>(&aptos_framework_account);
363-
<a href="timestamp.md#0x1_timestamp_set_time_has_started">timestamp::set_time_has_started</a>(&aptos_framework_account);
364364
}
365365
</code></pre>
366366

aptos-move/framework/aptos-framework/tests/compiler-v2-doc/staking_config.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,17 @@ Only called during genesis.
386386
rewards_rate_denominator,
387387
voting_power_increase_limit,
388388
});
389+
390+
// Initialize <a href="staking_config.md#0x1_staking_config_StakingRewardsConfig">StakingRewardsConfig</a> <b>with</b> the given rewards_rate and rewards_rate_denominator,
391+
// <b>while</b> setting min_rewards_rate and rewards_rate_decrease_rate <b>to</b> 0.
392+
<a href="staking_config.md#0x1_staking_config_initialize_rewards">initialize_rewards</a>(
393+
aptos_framework,
394+
<a href="../../../aptos-stdlib/tests/compiler-v2-doc/fixed_point64.md#0x1_fixed_point64_create_from_rational">fixed_point64::create_from_rational</a>((rewards_rate <b>as</b> u128), (rewards_rate_denominator <b>as</b> u128)),
395+
<a href="../../../aptos-stdlib/tests/compiler-v2-doc/fixed_point64.md#0x1_fixed_point64_create_from_rational">fixed_point64::create_from_rational</a>(0, 1000),
396+
<a href="staking_config.md#0x1_staking_config_ONE_YEAR_IN_SECS">ONE_YEAR_IN_SECS</a>,
397+
0,
398+
<a href="../../../aptos-stdlib/tests/compiler-v2-doc/fixed_point64.md#0x1_fixed_point64_create_from_rational">fixed_point64::create_from_rational</a>(0, 1000),
399+
);
389400
}
390401
</code></pre>
391402

@@ -1072,6 +1083,7 @@ Can only be called as part of the Aptos governance proposal process established
10721083

10731084

10741085
<pre><code><b>invariant</b> [suspendable] <a href="chain_status.md#0x1_chain_status_is_operating">chain_status::is_operating</a>() ==&gt; <b>exists</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingConfig">StakingConfig</a>&gt;(@aptos_framework);
1086+
<b>invariant</b> [suspendable] <a href="chain_status.md#0x1_chain_status_is_operating">chain_status::is_operating</a>() ==&gt; <b>exists</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingRewardsConfig">StakingRewardsConfig</a>&gt;(@aptos_framework);
10751087
<b>pragma</b> verify = <b>true</b>;
10761088
<b>pragma</b> aborts_if_is_strict;
10771089
</code></pre>
@@ -1223,6 +1235,7 @@ StakingConfig does not exist under the aptos_framework before creating it.
12231235

12241236

12251237
<pre><code><b>let</b> addr = <a href="../../../aptos-stdlib/../move-stdlib/tests/compiler-v2-doc/signer.md#0x1_signer_address_of">signer::address_of</a>(aptos_framework);
1238+
<b>requires</b> <b>exists</b>&lt;<a href="timestamp.md#0x1_timestamp_CurrentTimeMicroseconds">timestamp::CurrentTimeMicroseconds</a>&gt;(@aptos_framework);
12261239
// This enforces <a id="high-level-req-1.1" href="#high-level-req">high-level requirement 1</a>:
12271240
<b>aborts_if</b> addr != @aptos_framework;
12281241
<b>aborts_if</b> minimum_stake &gt; maximum_stake || maximum_stake == 0;
@@ -1234,7 +1247,9 @@ StakingConfig does not exist under the aptos_framework before creating it.
12341247
<b>aborts_if</b> rewards_rate &gt; <a href="staking_config.md#0x1_staking_config_MAX_REWARDS_RATE">MAX_REWARDS_RATE</a>;
12351248
<b>aborts_if</b> rewards_rate &gt; rewards_rate_denominator;
12361249
<b>aborts_if</b> <b>exists</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingConfig">StakingConfig</a>&gt;(addr);
1250+
<b>aborts_if</b> <b>exists</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingRewardsConfig">StakingRewardsConfig</a>&gt;(addr);
12371251
<b>ensures</b> <b>exists</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingConfig">StakingConfig</a>&gt;(addr);
1252+
<b>ensures</b> <b>exists</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingRewardsConfig">StakingRewardsConfig</a>&gt;(addr);
12381253
</code></pre>
12391254

12401255

aptos-move/framework/move-stdlib/tests/compiler-v2-doc/features.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ return true.
133133
- [Function `transaction_simulation_enhancement_enabled`](#0x1_features_transaction_simulation_enhancement_enabled)
134134
- [Function `get_collection_owner_feature`](#0x1_features_get_collection_owner_feature)
135135
- [Function `is_collection_owner_enabled`](#0x1_features_is_collection_owner_enabled)
136+
- [Function `get_native_memory_operations_feature`](#0x1_features_get_native_memory_operations_feature)
137+
- [Function `is_native_memory_operations_enabled`](#0x1_features_is_native_memory_operations_enabled)
136138
- [Function `change_feature_flags`](#0x1_features_change_feature_flags)
137139
- [Function `change_feature_flags_internal`](#0x1_features_change_feature_flags_internal)
138140
- [Function `change_feature_flags_for_next_epoch`](#0x1_features_change_feature_flags_for_next_epoch)
@@ -670,6 +672,15 @@ Lifetime: transient
670672

671673

672674

675+
<a id="0x1_features_NATIVE_MEMORY_OPERATIONS"></a>
676+
677+
678+
679+
<pre><code><b>const</b> <a href="features.md#0x1_features_NATIVE_MEMORY_OPERATIONS">NATIVE_MEMORY_OPERATIONS</a>: u64 = 80;
680+
</code></pre>
681+
682+
683+
673684
<a id="0x1_features_NEW_ACCOUNTS_DEFAULT_TO_FA_APT_STORE"></a>
674685

675686
Lifetime: transient
@@ -3273,6 +3284,52 @@ Deprecated feature
32733284

32743285

32753286

3287+
</details>
3288+
3289+
<a id="0x1_features_get_native_memory_operations_feature"></a>
3290+
3291+
## Function `get_native_memory_operations_feature`
3292+
3293+
3294+
3295+
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_native_memory_operations_feature">get_native_memory_operations_feature</a>(): u64
3296+
</code></pre>
3297+
3298+
3299+
3300+
<details>
3301+
<summary>Implementation</summary>
3302+
3303+
3304+
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_native_memory_operations_feature">get_native_memory_operations_feature</a>(): u64 { <a href="features.md#0x1_features_NATIVE_MEMORY_OPERATIONS">NATIVE_MEMORY_OPERATIONS</a> }
3305+
</code></pre>
3306+
3307+
3308+
3309+
</details>
3310+
3311+
<a id="0x1_features_is_native_memory_operations_enabled"></a>
3312+
3313+
## Function `is_native_memory_operations_enabled`
3314+
3315+
3316+
3317+
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_is_native_memory_operations_enabled">is_native_memory_operations_enabled</a>(): bool
3318+
</code></pre>
3319+
3320+
3321+
3322+
<details>
3323+
<summary>Implementation</summary>
3324+
3325+
3326+
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_is_native_memory_operations_enabled">is_native_memory_operations_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
3327+
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_NATIVE_MEMORY_OPERATIONS">NATIVE_MEMORY_OPERATIONS</a>)
3328+
}
3329+
</code></pre>
3330+
3331+
3332+
32763333
</details>
32773334

32783335
<a id="0x1_features_change_feature_flags"></a>
@@ -3697,6 +3754,17 @@ Helper to check whether a feature flag is enabled.
36973754

36983755

36993756

3757+
<a id="0x1_features_spec_new_accounts_default_to_fa_apt_store_enabled"></a>
3758+
3759+
3760+
<pre><code><b>fun</b> <a href="features.md#0x1_features_spec_new_accounts_default_to_fa_apt_store_enabled">spec_new_accounts_default_to_fa_apt_store_enabled</a>(): bool {
3761+
<a href="features.md#0x1_features_spec_is_enabled">spec_is_enabled</a>(<a href="features.md#0x1_features_NEW_ACCOUNTS_DEFAULT_TO_FA_APT_STORE">NEW_ACCOUNTS_DEFAULT_TO_FA_APT_STORE</a>)
3762+
}
3763+
</code></pre>
3764+
3765+
3766+
3767+
37003768
<a id="0x1_features_spec_simulation_enhancement_enabled"></a>
37013769

37023770

0 commit comments

Comments
 (0)