Skip to content

Commit

Permalink
fix duplicate mutable references (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored May 13, 2024
1 parent 09ef47e commit dd272c7
Show file tree
Hide file tree
Showing 33 changed files with 224 additions and 192 deletions.
58 changes: 29 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,35 +106,35 @@ triomphe = "0.1.9"
# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
# BEGIN MOVE DEPENDENCIES

# move-abigen = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
# move-bytecode-utils = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
# move-errmapgen = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
# move-ir-compiler = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
# move-prover-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
# move-stackless-bytecode-interpreter = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
# move-transactional-test-runner = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
# read-write-set = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
# read-write-set-dynamic = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-binary-format = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-bytecode-verifier = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-cli = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-command-line-common = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-compiler = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-core-types = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-docgen = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-model = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-package = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-prover = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-prover-boogie-backend = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-prover-bytecode-pipeline = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-resource-viewer = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-stackless-bytecode = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-stdlib = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-symbol-pool = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-unit-test = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-vm-runtime = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-vm-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
move-vm-types = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" }
# move-abigen = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
# move-bytecode-utils = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
# move-errmapgen = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
# move-ir-compiler = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
# move-prover-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
# move-stackless-bytecode-interpreter = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
# move-transactional-test-runner = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
# read-write-set = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
# read-write-set-dynamic = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-binary-format = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-bytecode-verifier = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-cli = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-command-line-common = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-compiler = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-core-types = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-docgen = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-model = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-package = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-prover = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-prover-boogie-backend = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-prover-bytecode-pipeline = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-resource-viewer = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-stackless-bytecode = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-stdlib = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-symbol-pool = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-unit-test = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-vm-runtime = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-vm-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }
move-vm-types = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" }

# END MOVE DEPENDENCIES

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ module 0x2::TableTestData {

let keys = vector::empty<u64>();
let vals = vector::empty<u64>();
while(T::prepare<u64, u64>(&mut iter)) {
let (key, value) = T::next<u64, u64>(&mut iter);
while(T::prepare<u64, u64>(iter)) {
let (key, value) = T::next<u64, u64>(iter);

vector::push_back(&mut keys, key);
vector::push_back(&mut vals, *value);
Expand Down Expand Up @@ -83,27 +83,27 @@ module 0x2::TableTestData {

let i = 1;
while(i < 11) {
assert!(T::prepare<u64, u64>(&mut iter), 101);
let (key, value) = T::next<u64, u64>(&mut iter);
assert!(T::prepare<u64, u64>(iter), 101);
let (key, value) = T::next<u64, u64>(iter);
assert!(key == i, 101);
assert!(value == &i, 101);

i = i + 1;
};
assert!(!T::prepare<u64, u64>(&mut iter), 101);
assert!(!T::prepare<u64, u64>(iter), 101);

let iter = T::iter(t_ref, option::some(2), option::some(5), 1);

let i = 2;
while(i < 5) {
assert!(T::prepare<u64, u64>(&mut iter), 102);
let (key, value) = T::next(&mut iter);
assert!(T::prepare<u64, u64>(iter), 102);
let (key, value) = T::next(iter);
assert!(key == i, 102);
assert!(value == &i, 102);

i = i + 1;
};
assert!(!T::prepare<u64, u64>(&mut iter), 102);
assert!(!T::prepare<u64, u64>(iter), 102);
}

public entry fun iterate_descending(acc: address) acquires S {
Expand All @@ -113,26 +113,26 @@ module 0x2::TableTestData {

let i = 10;
while(i > 0) {
assert!(T::prepare<u64, u64>(&mut iter), 101);
let (key, value) = T::next(&mut iter);
assert!(T::prepare<u64, u64>(iter), 101);
let (key, value) = T::next(iter);
assert!(key == i, 101);
assert!(value == &i, 101);

i = i - 1;
};
assert!(!T::prepare<u64, u64>(&mut iter), 101);
assert!(!T::prepare<u64, u64>(iter), 101);

let iter = T::iter(t_ref, option::some(2), option::some(5), 2);

let i = 4;
while(i > 1) {
assert!(T::prepare<u64, u64>(&mut iter), 102);
let (key, value) = T::next(&mut iter);
assert!(T::prepare<u64, u64>(iter), 102);
let (key, value) = T::next(iter);
assert!(key == i, 102);
assert!(value == &i, 102);

i = i - 1;
};
assert!(!T::prepare<u64, u64>(&mut iter), 102);
assert!(!T::prepare<u64, u64>(iter), 102);
}
}
9 changes: 5 additions & 4 deletions crates/natives/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ fn native_new_table_iter(
order,
});

Ok(smallvec![Value::u64(context_iterator_id as u64)])
Ok(smallvec![Value::iter_reference(context_iterator_id as u64)])
}

/// Check the `next_key` exist or not and store
Expand Down Expand Up @@ -683,9 +683,10 @@ fn native_next_box(
let table_context = context.extensions().get::<NativeTableContext>();
let mut iterators = table_context.iterators.borrow_mut();
let iterator = iterators.get_mut(iterator_id).unwrap();
let (key, value) = iterator.next.take().ok_or_else(|| {
partial_extension_error("next_box called without prepare_box")
})?;
let (key, value) = iterator
.next
.take()
.ok_or_else(|| partial_extension_error("next_box called without prepare_box"))?;

iterator.next = None;

Expand Down
Binary file modified precompile/binaries/minlib/collection.mv
Binary file not shown.
Binary file modified precompile/binaries/minlib/dex.mv
Binary file not shown.
Binary file modified precompile/binaries/minlib/multisig.mv
Binary file not shown.
Binary file modified precompile/binaries/minlib/primary_fungible_store.mv
Binary file not shown.
Binary file modified precompile/binaries/minlib/table.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/collection.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/dex.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/multisig.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/primary_fungible_store.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/stableswap.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/staking.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/table.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/vip.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/vip_vesting.mv
Binary file not shown.
12 changes: 6 additions & 6 deletions precompile/modules/initia_stdlib/sources/dex.move
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ module initia_std::dex {
1,
);

while (vector::length(&res) < (limit as u64) && table::prepare<PairKey, PairResponse>(&mut pairs_iter)) {
let (key, value) = table::next<PairKey, PairResponse>(&mut pairs_iter);
while (vector::length(&res) < (limit as u64) && table::prepare<PairKey, PairResponse>(pairs_iter)) {
let (key, value) = table::next<PairKey, PairResponse>(pairs_iter);
if (&key != option::borrow(&start_after)) {
vector::push_back(&mut res, *value)
}
Expand Down Expand Up @@ -523,8 +523,8 @@ module initia_std::dex {
1,
);

while (vector::length(&res) < (limit as u64) && table::prepare<PairKey, PairResponse>(&mut pairs_iter)) {
let (key, value) = table::next<PairKey, PairResponse>(&mut pairs_iter);
while (vector::length(&res) < (limit as u64) && table::prepare<PairKey, PairResponse>(pairs_iter)) {
let (key, value) = table::next<PairKey, PairResponse>(pairs_iter);
if (&key != option::borrow(&start_after)) {
vector::push_back(&mut res, PairByDenomResponse {
coin_a: coin::metadata_to_denom(object::address_to_object(value.coin_a)),
Expand Down Expand Up @@ -576,8 +576,8 @@ module initia_std::dex {
1,
);

while (vector::length(&res) < (limit as u64) && table::prepare<PairKey, PairResponse>(&mut pairs_iter)) {
let (key, value) = table::next<PairKey, PairResponse>(&mut pairs_iter);
while (vector::length(&res) < (limit as u64) && table::prepare<PairKey, PairResponse>(pairs_iter)) {
let (key, value) = table::next<PairKey, PairResponse>(pairs_iter);
if (coin_a != key.coin_a || coin_b != key.coin_b) break;
if (&key != option::borrow(&start_after)) {
vector::push_back(&mut res, *value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ module initia_std::primary_fungible_store {
let metadata_vec: vector<Object<Metadata>> = vector[];
let balance_vec: vector<u64> = vector[];

while (table::prepare<address, address>(&mut iter) && vector::length(&balance_vec) < (limit as u64)) {
let (metadata_addr, store_addr) = table::next<address, address>(&mut iter);
while (table::prepare<address, address>(iter) && vector::length(&balance_vec) < (limit as u64)) {
let (metadata_addr, store_addr) = table::next<address, address>(iter);
let metadata = object::address_to_object<Metadata>(metadata_addr);
let store = object::address_to_object<FungibleStore>(*store_addr);

Expand Down
4 changes: 2 additions & 2 deletions precompile/modules/initia_stdlib/sources/multisig.move
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ module initia_std::multisig {
let multisig_wallet = borrow_global<MultisigWallet>(multisig_addr);
let iter = table::iter(&multisig_wallet.proposals, option::none(), start_after, 2);

while (vector::length(&res) < (limit as u64) && table::prepare<u64, Proposal>(&mut iter)) {
let (proposal_id, proposal) = table::next<u64, Proposal>(&mut iter);
while (vector::length(&res) < (limit as u64) && table::prepare<u64, Proposal>(iter)) {
let (proposal_id, proposal) = table::next<u64, Proposal>(iter);
vector::push_back(&mut res, proposal_to_proposal_response(multisig_wallet, multisig_addr, proposal_id, proposal));
};

Expand Down
4 changes: 2 additions & 2 deletions precompile/modules/initia_stdlib/sources/stableswap.move
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ module initia_std::stableswap {
2,
);

while (vector::length(&res) < (limit as u64) && table::prepare<address, bool>(&mut pools_iter)) {
let (key, _) = table::next<address, bool>(&mut pools_iter);
while (vector::length(&res) < (limit as u64) && table::prepare<address, bool>(pools_iter)) {
let (key, _) = table::next<address, bool>(pools_iter);
let pool_response = get_pool(object::address_to_object<Pool>(key));
vector::push_back(&mut res, pool_response)
};
Expand Down
12 changes: 5 additions & 7 deletions precompile/modules/initia_stdlib/sources/staking.move
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ module initia_std::staking {
2,
);

let prepare = table::prepare(&mut delegations_iter);
let prepare = table::prepare(delegations_iter);
let res: vector<DelegationResponse> = vector[];
while (vector::length(&res) < (limit as u64) && prepare) {
let (validator, delegation) = table::next(&mut delegations_iter);
let (validator, delegation) = table::next(delegations_iter);
let state = table::borrow(staking_states, validator);
let reward = calculate_reward(delegation, state);
vector::push_back(
Expand All @@ -356,7 +356,7 @@ module initia_std::staking {
unclaimed_reward: reward,
},
);
prepare = table::prepare(&mut delegations_iter);
prepare = table::prepare(delegations_iter);
};

res
Expand Down Expand Up @@ -431,10 +431,8 @@ module initia_std::staking {
);

let res: vector<UnbondingResponse> = vector[];
while (vector::length(&res) < (limit as u64) && table::prepare<UnbondingKey, Unbonding>(
&mut unbondings_iter
)) {
let (_, unbonding) = table::next<UnbondingKey, Unbonding>(&mut unbondings_iter);
while (vector::length(&res) < (limit as u64) && table::prepare<UnbondingKey, Unbonding>(unbondings_iter)) {
let (_, unbonding) = table::next<UnbondingKey, Unbonding>(unbondings_iter);
let unbonding_amount = get_unbonding_amount_from_unbonding(unbonding);
vector::push_back(
&mut res,
Expand Down
Loading

0 comments on commit dd272c7

Please sign in to comment.