From eb55624e7a5decda7f4946fe86d2b96b3aed6fb1 Mon Sep 17 00:00:00 2001 From: Todd Nowacki Date: Sun, 28 Jul 2024 13:56:41 -0700 Subject: [PATCH] [move] Copy Sui's Move stdlib into external-crates. Bump the default package version to 2024 beta. (#18827) ## Description - Copied Sui's stdlib over to external-crates - Changed the default edition for package-less files in the compiler to 2024 beta. ## Test plan - Ran tests, updated where necessary --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: --- bridge/move/tokens/btc/Move.toml | 2 +- bridge/move/tokens/eth/Move.toml | 2 +- bridge/move/tokens/mock/ka/Move.toml | 2 +- bridge/move/tokens/usdc/Move.toml | 2 +- bridge/move/tokens/usdt/Move.toml | 2 +- .../tests/size_limits/event_limits_tests.exp | 4 +- .../size_limits/move_object_size_limit.exp | 4 +- .../move_package_management_tests.rs | 6 +- crates/sui-move/src/unit_test.rs | 5 +- crates/sui-open-rpc/spec/openrpc.json | 31 +- crates/sui-protocol-config/src/lib.rs | 96 + ...ocol_config__test__Mainnet_version_53.snap | 29 + ...ocol_config__test__Testnet_version_53.snap | 29 + ...sui_protocol_config__test__version_53.snap | 30 + .../reference_safety/imm_borrow_loc.mvir | 1 - .../imm_borrow_loc_valid.mvir | 1 - .../reference_safety/imm_borrow_on_mut.mvir | 1 - .../tests/type_safety/cant_deref_resource.exp | 8 +- .../type_safety/cant_deref_resource.mvir | 18 +- .../mut_call_from_get_resource.mvir | 18 +- .../crates/language-benchmarks/src/move_vm.rs | 1 + .../move-analyzer/tests/completion/Move.toml | 1 - .../move-analyzer/tests/dot_completion.exp | 92 + .../move-analyzer/tests/enums/Move.toml | 1 - .../move-analyzer/tests/implicit_uses.exp | 6 +- .../move-analyzer/tests/inlay-hints/Move.toml | 1 - .../crates/move-analyzer/tests/macros.exp | 74 +- .../crates/move-analyzer/tests/macros.ide | 6 +- .../tests/mod-ident-uniform/Move.toml | 2 +- .../move-analyzer/tests/move-2024/Move.toml | 1 - .../tests/parse-error-dep/Move.toml | 2 +- .../move-analyzer/tests/parse-error/Move.toml | 2 +- .../move-analyzer/tests/partial-dot/Move.toml | 2 +- .../tests/partial-function/Move.toml | 2 +- .../tests/pkg-naming-error/Move.toml | 2 +- .../tests/pre-type-error-dep/Move.toml | 2 +- .../tests/pre-type-error/Move.toml | 2 +- .../move-analyzer/tests/symbols/Move.toml | 2 +- .../move/crates/move-cli/src/main.rs | 11 +- .../build_with_bytecode/B/Move.toml | 1 + .../build_with_bytecode/C/Move.toml | 1 + .../build_tests/build_with_bytecode/Move.toml | 1 + .../build_with_dep_warnings/Move.toml | 1 + .../build_with_dep_warnings/dep/Move.toml | 1 + .../build_tests/build_with_warnings/Move.toml | 1 + .../build_tests/canonicalize_module/Move.toml | 1 + .../canonicalize_module/sources/m.move | 8 +- .../circular_dependencies/Move.toml | 1 + .../circular_dependencies/bar/Move.toml | 1 + .../build_tests/dependency_chain/Move.toml | 1 + .../dependency_chain/bar/Move.toml | 1 + .../dependency_chain/foo/Move.toml | 1 + .../tests/build_tests/dev_address/Move.toml | 1 + .../build_tests/disassemble_module/Move.toml | 1 + .../disassemble_module/sources/m.move | 7 +- .../empty_module_no_deps/Move.toml | 1 + .../include_exclude_stdlib/Move.toml | 1 + .../include_exclude_stdlib/args.exp | 22 +- .../sources/UseSigner.move | 8 +- .../tests/build_tests/json_errors/Move.toml | 1 + .../tests/build_tests/migration/Move.toml | 1 + .../rebuild_after_adding_new_source/Move.toml | 1 + .../Move.toml | 1 + .../rebuild_after_touching_manifest/Move.toml | 1 + .../rebuild_after_touching_source/Move.toml | 1 + .../rebuild_no_modification/Move.toml | 1 + .../build_tests/unbound_address/Move.toml | 1 + .../build_tests/unbound_dependency/Move.toml | 1 + .../tests/metatests/cov/plain/Move.toml | 1 + .../cov/two-runs-diff-module/Move.toml | 1 + .../cov/two-runs-diff-module/sources/M1.move | 4 +- .../cov/two-runs-diff-module/sources/M2.move | 4 +- .../cov/two-runs-same-module/Move.toml | 1 + .../cov/two-runs-same-module/sources/M.move | 4 +- .../assign_dev_addr_for_dep/Move.toml | 1 + .../assign_dev_addr_for_dep/dep/Move.toml | 1 + .../Move.toml | 1 + .../Move.toml | 1 + .../build_modules_and_scripts/Move.toml | 1 + .../build_modules_and_scripts/sources/M.move | 4 +- .../doctor_with_stdlib/Move.toml | 3 +- .../doctor_with_stdlib/sources/M.move | 4 +- .../explain_arithmetic_failure/Move.toml | 1 + .../explain_stdlib_abort/Move.toml | 1 + .../sources/bad_borrow.move | 1 - .../explain_user_module_abort/Move.toml | 1 + .../sources/Fail.move | 4 +- .../sandbox_tests/gas_metering/Move.toml | 1 + .../generate_struct_layout/Move.toml | 1 + .../generate_struct_layout/sources/M1.move | 8 +- .../generate_struct_layout/sources/M2.move | 2 +- .../sources/phantoms.move | 10 +- .../module_disassemble/Move.toml | 1 + .../module_disassemble/deps1/Move.toml | 1 + .../module_disassemble/deps2/Move.toml | 1 + .../module_disassemble/sources/M1.move | 3 +- .../module_publish_view/Move.toml | 1 + .../module_publish_view/sources/Module.move | 6 +- .../multi_module_publish/Move.toml | 1 + .../sources/GoodFriends.move | 3 +- .../Move.toml | 1 + .../dep/Move.toml | 1 + .../dep/sources/m.move | 4 +- .../sandbox_tests/package_basics/Move.toml | 1 + .../sandbox_tests/package_basics/args.exp | 13 +- .../sandbox_tests/package_basics/args.txt | 2 +- .../sandbox_tests/print_stack_trace/Move.toml | 3 +- .../print_stack_trace/sources/M.move | 4 +- .../print_stack_trace/sources/N.move | 6 +- .../sources/print_stack_trace.move | 3 +- .../sandbox_tests/print_values/Move.toml | 3 +- .../tests/sandbox_tests/print_values/args.exp | 7 - .../sandbox_tests/print_values/sources/M.move | 40 +- .../sandbox_tests/publish_then_run/Move.toml | 1 + .../publish_then_run/sources/M.move | 4 +- .../random_test_flag_correctness/Move.toml | 1 + .../sandbox_tests/use_named_address/Move.toml | 1 + .../Move.toml | 1 + .../Move.toml | 1 + .../no_git_remote_package/Move.toml | 1 + .../upload_tests/valid_package1/Move.toml | 1 + .../upload_tests/valid_package2/Move.toml | 1 + .../upload_tests/valid_package3/Move.toml | 1 + .../crates/move-compiler/src/editions/mod.rs | 2 +- .../move_2024/typing/dot_call_non_struct.exp | 2 +- .../typing/duplicate_defines_primitive.exp | 4 +- .../typing/duplicate_defines_primitive.move | 4 +- .../tests/move_check_testsuite.rs | 2 +- .../tests/sources/different_visbilities.move | 4 +- ...t_template_AnotherTypeOfScript.notest_move | 4 +- .../root_template_OneTypeOfScript.notest_move | 4 +- .../src/resolution/resolution_graph.rs | 3 +- .../tests/borrow/basic_test.move | 22 +- .../tests/borrow/function_call.exp | 4192 +++++++++++-- .../tests/borrow/function_call.move | 10 +- .../tests/borrow/hyper_edge.exp | 4194 +++++++++++-- .../tests/borrow/hyper_edge.move | 13 +- .../tests/borrow_strong/basic_test.move | 28 +- .../tests/eliminate_imm_refs/basic_test.move | 4 +- .../escape_analysis/return_internal_refs.move | 4 +- .../escape_analysis/return_refs_into_vec.exp | 5250 +++++++++++++++-- .../escape_analysis/return_refs_into_vec.move | 6 +- .../tests/escape_analysis/struct_eq.exp | 7 - .../tests/escape_analysis/struct_eq.move | 4 +- .../tests/from_move/smoke_test.exp | 16 +- .../tests/from_move/smoke_test.move | 8 +- .../tests/livevar/basic_test.move | 6 +- .../tests/memory_instr/basic_test.move | 22 +- .../mut_ref_instrumentation/basic_test.move | 22 +- .../crates/move-stdlib-natives/src/lib.rs | 89 +- .../move/crates/move-stdlib/Move.toml | 1 + .../move/crates/move-stdlib/docs/address.md | 44 + .../move/crates/move-stdlib/docs/ascii.md | 372 +- .../move/crates/move-stdlib/docs/bcs.md | 4 +- .../crates/move-stdlib/docs/bit_vector.md | 81 +- .../move-stdlib/{nursery => }/docs/debug.md | 5 +- .../move/crates/move-stdlib/docs/error.md | 475 -- .../crates/move-stdlib/docs/fixed_point32.md | 235 +- .../move/crates/move-stdlib/docs/hash.md | 8 +- .../move/crates/move-stdlib/docs/macros.md | 14 + .../move/crates/move-stdlib/docs/option.md | 62 +- .../move/crates/move-stdlib/docs/overview.md | 11 +- .../move/crates/move-stdlib/docs/signer.md | 63 - .../move/crates/move-stdlib/docs/string.md | 268 +- .../move/crates/move-stdlib/docs/type_name.md | 222 +- .../move/crates/move-stdlib/docs/u128.md | 195 + .../move/crates/move-stdlib/docs/u16.md | 195 + .../move/crates/move-stdlib/docs/u256.md | 145 + .../move/crates/move-stdlib/docs/u32.md | 195 + .../move/crates/move-stdlib/docs/u64.md | 195 + .../move/crates/move-stdlib/docs/u8.md | 195 + .../move/crates/move-stdlib/docs/vector.md | 100 +- .../move-stdlib/error_description.errmap | Bin 1310 -> 0 bytes .../move/crates/move-stdlib/nursery/Move.toml | 8 - .../move-stdlib/nursery/docs/compare.md | 167 - .../move-stdlib/nursery/sources/compare.move | 70 - .../move-stdlib/nursery/sources/debug.move | 18 - .../nursery/tests/compare_tests.move | 86 - .../crates/move-stdlib/sources/address.move | 12 + .../crates/move-stdlib/sources/ascii.move | 167 +- .../move/crates/move-stdlib/sources/bcs.move | 3 + .../move-stdlib/sources/bit_vector.move | 45 +- .../crates/move-stdlib/sources/debug.move | 9 + .../crates/move-stdlib/sources/error.move | 82 - .../move-stdlib/sources/fixed_point32.move | 70 +- .../move/crates/move-stdlib/sources/hash.move | 3 + .../crates/move-stdlib/sources/macros.move | 102 + .../crates/move-stdlib/sources/option.move | 162 +- .../crates/move-stdlib/sources/signer.move | 15 - .../crates/move-stdlib/sources/string.move | 118 +- .../crates/move-stdlib/sources/type_name.move | 97 +- .../move/crates/move-stdlib/sources/u128.move | 79 + .../move/crates/move-stdlib/sources/u16.move | 79 + .../move/crates/move-stdlib/sources/u256.move | 50 + .../move/crates/move-stdlib/sources/u32.move | 79 + .../move/crates/move-stdlib/sources/u64.move | 79 + .../move/crates/move-stdlib/sources/u8.move | 79 + .../crates/move-stdlib/sources/unit_test.move | 22 + .../crates/move-stdlib/sources/vector.move | 300 +- .../move/crates/move-stdlib/src/lib.rs | 24 - .../move/crates/move-stdlib/src/main.rs | 5 - .../crates/move-stdlib/tests/ascii_tests.move | 188 +- .../crates/move-stdlib/tests/bcs_tests.move | 44 +- .../move-stdlib/tests/bit_vector_tests.move | 133 +- .../move-stdlib/tests/fixedpoint32_tests.move | 100 +- .../crates/move-stdlib/tests/hash_tests.move | 9 +- .../move-stdlib/tests/integer_tests.move | 220 + .../move-stdlib/tests/move_unit_test.rs | 50 - .../tests/move_verification_test.rs | 13 - .../move-stdlib/tests/option_tests.move | 156 +- .../move-stdlib/tests/string_tests.move | 80 +- .../move-stdlib/tests/type_name_tests.move | 103 +- .../crates/move-stdlib/tests/u128_tests.move | 78 + .../crates/move-stdlib/tests/u16_tests.move | 78 + .../crates/move-stdlib/tests/u256_tests.move | 72 + .../crates/move-stdlib/tests/u32_tests.move | 78 + .../crates/move-stdlib/tests/u64_tests.move | 79 + .../crates/move-stdlib/tests/u8_tests.move | 77 + .../move-stdlib/tests/vector_tests.move | 840 ++- .../src/vm_test_harness.rs | 1 + .../crates/move-unit-test/src/test_runner.rs | 1 + .../tests/test_sources/address_args.move | 4 +- .../tests/test_sources/arithmetic_errors.move | 4 +- .../tests/test_sources/construct_data.move | 8 +- .../test_sources/cross_module_aborts.exp | 8 +- .../test_sources/cross_module_aborts.move | 6 +- .../tests/test_sources/do_nothing.move | 4 +- .../test_sources/expected_abort_no_abort.move | 4 +- .../tests/test_sources/native_abort.exp | 12 +- .../tests/test_sources/native_abort.move | 1 - .../test_sources/non_exsistent_native.move | 4 +- .../tests/test_sources/proposal_test.move | 8 +- .../tests/test_sources/signer_args.exp | 6 +- .../tests/test_sources/signer_args.move | 10 +- .../tests/test_sources/timeout.exp | 4 +- .../tests/test_sources/timeout.move | 6 +- .../tests/test_sources/unexpected_abort.exp | 38 +- .../tests/test_sources/unexpected_abort.move | 4 +- .../move-vm-integration-tests/Cargo.toml | 2 +- .../src/tests/binary_format_version.rs | 2 + .../src/tests/depth_tests_modules.move | 66 +- .../src/tests/function_arg_tests.rs | 4 +- .../src/tests/loader_tests_modules.move | 268 +- .../src/tests/nested_loop_tests.rs | 6 +- .../src/tests/relinking_tests_b_v1.move | 2 +- .../src/tests/relinking_tests_c_v0.move | 2 +- .../src/tests/relinking_tests_c_v1.move | 4 +- .../src/tests/relinking_tests_c_v2.move | 6 +- .../tests/builtins/get_txn_sender.exp | 4 + .../tests/builtins/get_txn_sender.mvir | 10 +- .../tests/entry_points/call_native.exp | 4 +- .../tests/entry_points/call_native.move | 2 +- .../move/crates/test-generation/src/lib.rs | 1 + .../sui-adapter/src/execution_engine.rs | 2 +- .../latest/sui-move-natives/src/lib.rs | 116 +- sui-execution/src/latest.rs | 2 +- 256 files changed, 18603 insertions(+), 4224 deletions(-) create mode 100644 external-crates/move/crates/move-stdlib/docs/address.md rename external-crates/move/crates/move-stdlib/{nursery => }/docs/debug.md (86%) delete mode 100644 external-crates/move/crates/move-stdlib/docs/error.md create mode 100644 external-crates/move/crates/move-stdlib/docs/macros.md delete mode 100644 external-crates/move/crates/move-stdlib/docs/signer.md create mode 100644 external-crates/move/crates/move-stdlib/docs/u128.md create mode 100644 external-crates/move/crates/move-stdlib/docs/u16.md create mode 100644 external-crates/move/crates/move-stdlib/docs/u256.md create mode 100644 external-crates/move/crates/move-stdlib/docs/u32.md create mode 100644 external-crates/move/crates/move-stdlib/docs/u64.md create mode 100644 external-crates/move/crates/move-stdlib/docs/u8.md delete mode 100644 external-crates/move/crates/move-stdlib/error_description.errmap delete mode 100644 external-crates/move/crates/move-stdlib/nursery/Move.toml delete mode 100644 external-crates/move/crates/move-stdlib/nursery/docs/compare.md delete mode 100644 external-crates/move/crates/move-stdlib/nursery/sources/compare.move delete mode 100644 external-crates/move/crates/move-stdlib/nursery/sources/debug.move delete mode 100644 external-crates/move/crates/move-stdlib/nursery/tests/compare_tests.move create mode 100644 external-crates/move/crates/move-stdlib/sources/address.move create mode 100644 external-crates/move/crates/move-stdlib/sources/debug.move delete mode 100644 external-crates/move/crates/move-stdlib/sources/error.move create mode 100644 external-crates/move/crates/move-stdlib/sources/macros.move delete mode 100644 external-crates/move/crates/move-stdlib/sources/signer.move create mode 100644 external-crates/move/crates/move-stdlib/sources/u128.move create mode 100644 external-crates/move/crates/move-stdlib/sources/u16.move create mode 100644 external-crates/move/crates/move-stdlib/sources/u256.move create mode 100644 external-crates/move/crates/move-stdlib/sources/u32.move create mode 100644 external-crates/move/crates/move-stdlib/sources/u64.move create mode 100644 external-crates/move/crates/move-stdlib/sources/u8.move create mode 100644 external-crates/move/crates/move-stdlib/tests/integer_tests.move delete mode 100644 external-crates/move/crates/move-stdlib/tests/move_unit_test.rs delete mode 100644 external-crates/move/crates/move-stdlib/tests/move_verification_test.rs create mode 100644 external-crates/move/crates/move-stdlib/tests/u128_tests.move create mode 100644 external-crates/move/crates/move-stdlib/tests/u16_tests.move create mode 100644 external-crates/move/crates/move-stdlib/tests/u256_tests.move create mode 100644 external-crates/move/crates/move-stdlib/tests/u32_tests.move create mode 100644 external-crates/move/crates/move-stdlib/tests/u64_tests.move create mode 100644 external-crates/move/crates/move-stdlib/tests/u8_tests.move diff --git a/bridge/move/tokens/btc/Move.toml b/bridge/move/tokens/btc/Move.toml index cbd69d8556431..47824231423d3 100644 --- a/bridge/move/tokens/btc/Move.toml +++ b/bridge/move/tokens/btc/Move.toml @@ -1,6 +1,7 @@ [package] name = "BridgedBTC" version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../../crates/sui-framework/packages/move-stdlib" } @@ -8,4 +9,3 @@ Sui = { local = "../../../../crates/sui-framework/packages/sui-framework" } [addresses] bridged_btc = "0x0" - diff --git a/bridge/move/tokens/eth/Move.toml b/bridge/move/tokens/eth/Move.toml index 215aa37ce8687..1a21898cc0355 100644 --- a/bridge/move/tokens/eth/Move.toml +++ b/bridge/move/tokens/eth/Move.toml @@ -1,6 +1,7 @@ [package] name = "BridgedETH" version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../../crates/sui-framework/packages/move-stdlib" } @@ -8,4 +9,3 @@ Sui = { local = "../../../../crates/sui-framework/packages/sui-framework" } [addresses] bridged_eth = "0x0" - diff --git a/bridge/move/tokens/mock/ka/Move.toml b/bridge/move/tokens/mock/ka/Move.toml index ad08496bd39e1..1fbdf04ca2975 100644 --- a/bridge/move/tokens/mock/ka/Move.toml +++ b/bridge/move/tokens/mock/ka/Move.toml @@ -1,6 +1,7 @@ [package] name = "BridgedKa" version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../../../crates/sui-framework/packages/move-stdlib" } @@ -8,4 +9,3 @@ Sui = { local = "../../../../../crates/sui-framework/packages/sui-framework" } [addresses] bridged_ka = "0x0" - diff --git a/bridge/move/tokens/usdc/Move.toml b/bridge/move/tokens/usdc/Move.toml index e98ae4d71c621..a956409c0839f 100644 --- a/bridge/move/tokens/usdc/Move.toml +++ b/bridge/move/tokens/usdc/Move.toml @@ -1,6 +1,7 @@ [package] name = "BridgedUSDC" version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../../crates/sui-framework/packages/move-stdlib" } @@ -8,4 +9,3 @@ Sui = { local = "../../../../crates/sui-framework/packages/sui-framework" } [addresses] bridged_usdc = "0x0" - diff --git a/bridge/move/tokens/usdt/Move.toml b/bridge/move/tokens/usdt/Move.toml index 699123ddb0325..1d86a908fdd8e 100644 --- a/bridge/move/tokens/usdt/Move.toml +++ b/bridge/move/tokens/usdt/Move.toml @@ -1,6 +1,7 @@ [package] name = "BridgedUSDT" version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../../crates/sui-framework/packages/move-stdlib" } @@ -8,4 +9,3 @@ Sui = { local = "../../../../crates/sui-framework/packages/sui-framework" } [addresses] bridged_usdt = "0x0" - diff --git a/crates/sui-adapter-transactional-tests/tests/size_limits/event_limits_tests.exp b/crates/sui-adapter-transactional-tests/tests/size_limits/event_limits_tests.exp index 4b2c0d8cf17e2..bddf4a6d99846 100644 --- a/crates/sui-adapter-transactional-tests/tests/size_limits/event_limits_tests.exp +++ b/crates/sui-adapter-transactional-tests/tests/size_limits/event_limits_tests.exp @@ -32,13 +32,13 @@ task 6, lines 68-70: //# run Test::M1::emit_event_with_size --args 200000 --gas-budget 100000000000000 --summarize events: 1 mutated: 1 -gas summary: computation_cost: 1393000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880 +gas summary: computation_cost: 1394000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880 task 7, lines 71-73: //# run Test::M1::emit_event_with_size --args 256000 --gas-budget 100000000000000 --summarize events: 1 mutated: 1 -gas summary: computation_cost: 1814000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880 +gas summary: computation_cost: 1815000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880 task 8, lines 74-76: //# run Test::M1::emit_event_with_size --args 256001 --gas-budget 100000000000000 --summarize diff --git a/crates/sui-adapter-transactional-tests/tests/size_limits/move_object_size_limit.exp b/crates/sui-adapter-transactional-tests/tests/size_limits/move_object_size_limit.exp index dfa9be123b60f..7767e2f318584 100644 --- a/crates/sui-adapter-transactional-tests/tests/size_limits/move_object_size_limit.exp +++ b/crates/sui-adapter-transactional-tests/tests/size_limits/move_object_size_limit.exp @@ -18,10 +18,10 @@ task 3, lines 82-84: //# run Test::M1::transfer_object_with_size --args 255999 --sender A --gas-budget 100000000000000 created: object(3,0) mutated: object(0,0) -gas summary: computation_cost: 1863000000, storage_cost: 1947553200, storage_rebate: 978120, non_refundable_storage_fee: 9880 +gas summary: computation_cost: 1864000000, storage_cost: 1947553200, storage_rebate: 978120, non_refundable_storage_fee: 9880 task 4, line 85: //# run Test::M1::transfer_object_with_size --args 256000 --sender A --gas-budget 100000000000000 created: object(4,0) mutated: object(0,0) -gas summary: computation_cost: 1863000000, storage_cost: 1947560800, storage_rebate: 978120, non_refundable_storage_fee: 9880 +gas summary: computation_cost: 1864000000, storage_cost: 1947560800, storage_rebate: 978120, non_refundable_storage_fee: 9880 diff --git a/crates/sui-core/src/unit_tests/move_package_management_tests.rs b/crates/sui-core/src/unit_tests/move_package_management_tests.rs index e3c4dd8df6344..feb538ca0fb32 100644 --- a/crates/sui-core/src/unit_tests/move_package_management_tests.rs +++ b/crates/sui-core/src/unit_tests/move_package_management_tests.rs @@ -46,7 +46,7 @@ async fn test_manage_package_update() { .read_to_string(&mut lock_file_contents) .expect("Error reading Move.lock file"); - let expected = expect![[r#" + let expected = expect![[r##" # @generated by Move, please check-in and do not edit manually. [move] @@ -56,7 +56,7 @@ async fn test_manage_package_update() { [move.toolchain-version] compiler-version = "0.0.1" - edition = "legacy" + edition = "2024.beta" flavor = "sui" [env] @@ -66,6 +66,6 @@ async fn test_manage_package_update() { original-published-id = "0x000000000000000000000000000000000000000000000000000000000000000a" latest-published-id = "0x000000000000000000000000000000000000000000000000000000000000000b" published-version = "5" - "#]]; + "##]]; expected.assert_eq(lock_file_contents.as_str()); } diff --git a/crates/sui-move/src/unit_test.rs b/crates/sui-move/src/unit_test.rs index a5d0bf3b192ef..3bb4da1f2da0f 100644 --- a/crates/sui-move/src/unit_test.rs +++ b/crates/sui-move/src/unit_test.rs @@ -114,7 +114,10 @@ pub fn run_move_unit_tests( report_stacktrace_on_abort: true, ..config }, - sui_move_natives::all_natives(/* silent */ false), + sui_move_natives::all_natives( + /* silent */ false, + &ProtocolConfig::get_for_max_version_UNSAFE(), + ), Some(initial_cost_schedule_for_unit_tests()), compute_coverage, &mut std::io::stdout(), diff --git a/crates/sui-open-rpc/spec/openrpc.json b/crates/sui-open-rpc/spec/openrpc.json index 8a50f8f5a8cf5..438c4b2332f02 100644 --- a/crates/sui-open-rpc/spec/openrpc.json +++ b/crates/sui-open-rpc/spec/openrpc.json @@ -1368,6 +1368,9 @@ "base_tx_cost_per_byte": { "u64": "0" }, + "bcs_failure_cost": null, + "bcs_legacy_min_output_size_cost": null, + "bcs_per_byte_serialized_cost": null, "binary_address_identifiers": null, "binary_constant_pool": null, "binary_enum_def_instantiations": null, @@ -1419,6 +1422,8 @@ "crypto_invalid_arguments_cost": { "u64": "100" }, + "debug_print_base_cost": null, + "debug_print_stack_trace_base_cost": null, "dynamic_field_add_child_object_cost_base": { "u64": "100" }, @@ -1652,6 +1657,12 @@ "hash_keccak256_data_cost_per_byte": { "u64": "2" }, + "hash_sha2_256_base_cost": null, + "hash_sha2_256_legacy_min_input_len_cost": null, + "hash_sha2_256_per_byte_cost": null, + "hash_sha3_256_base_cost": null, + "hash_sha3_256_legacy_min_input_len_cost": null, + "hash_sha3_256_per_byte_cost": null, "hmac_hmac_sha3_256_cost_base": { "u64": "52" }, @@ -1875,6 +1886,14 @@ "storage_rebate_rate": { "u64": "9900" }, + "string_check_utf8_base_cost": null, + "string_check_utf8_per_byte_cost": null, + "string_index_of_base_cost": null, + "string_index_of_per_byte_pattern_cost": null, + "string_index_of_per_byte_searched_cost": null, + "string_is_char_boundary_base_cost": null, + "string_sub_string_base_cost": null, + "string_sub_string_per_byte_cost": null, "transfer_freeze_object_cost_base": { "u64": "52" }, @@ -1888,6 +1907,8 @@ "tx_context_derive_id_cost_base": { "u64": "52" }, + "type_name_get_base_cost": null, + "type_name_get_per_byte_cost": null, "types_is_one_time_witness_cost_base": { "u64": "52" }, @@ -1904,7 +1925,15 @@ "u64": "2" }, "vdf_hash_to_input_cost": null, - "vdf_verify_vdf_cost": null + "vdf_verify_vdf_cost": null, + "vector_borrow_base_cost": null, + "vector_destroy_empty_base_cost": null, + "vector_empty_base_cost": null, + "vector_length_base_cost": null, + "vector_pop_back_base_cost": null, + "vector_push_back_base_cost": null, + "vector_push_back_legacy_per_abstract_memory_unit_cost": null, + "vector_swap_base_cost": null } } } diff --git a/crates/sui-protocol-config/src/lib.rs b/crates/sui-protocol-config/src/lib.rs index 0a630e7a87b44..0a1ddec049c8b 100644 --- a/crates/sui-protocol-config/src/lib.rs +++ b/crates/sui-protocol-config/src/lib.rs @@ -164,6 +164,7 @@ const MAX_PROTOCOL_VERSION: u64 = 53; // Version 53: Add feature flag to decide whether to attempt to finalize bridge committee // Enable consensus commit prologue V3 on testnet. // Turn on shared object congestion control in testnet. +// Update stdlib natives costs #[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub struct ProtocolVersion(u64); @@ -1101,6 +1102,40 @@ pub struct ProtocolConfig { vdf_verify_vdf_cost: Option, vdf_hash_to_input_cost: Option, + // Stdlib costs + bcs_per_byte_serialized_cost: Option, + bcs_legacy_min_output_size_cost: Option, + bcs_failure_cost: Option, + + hash_sha2_256_base_cost: Option, + hash_sha2_256_per_byte_cost: Option, + hash_sha2_256_legacy_min_input_len_cost: Option, + hash_sha3_256_base_cost: Option, + hash_sha3_256_per_byte_cost: Option, + hash_sha3_256_legacy_min_input_len_cost: Option, + type_name_get_base_cost: Option, + type_name_get_per_byte_cost: Option, + + string_check_utf8_base_cost: Option, + string_check_utf8_per_byte_cost: Option, + string_is_char_boundary_base_cost: Option, + string_sub_string_base_cost: Option, + string_sub_string_per_byte_cost: Option, + string_index_of_base_cost: Option, + string_index_of_per_byte_pattern_cost: Option, + string_index_of_per_byte_searched_cost: Option, + + vector_empty_base_cost: Option, + vector_length_base_cost: Option, + vector_push_back_base_cost: Option, + vector_push_back_legacy_per_abstract_memory_unit_cost: Option, + vector_borrow_base_cost: Option, + vector_pop_back_base_cost: Option, + vector_destroy_empty_base_cost: Option, + vector_swap_base_cost: Option, + debug_print_base_cost: Option, + debug_print_stack_trace_base_cost: Option, + // ==== Ephemeral (consensus only) params deleted ==== // // Const params for consensus scoring decision @@ -1909,6 +1944,36 @@ impl ProtocolConfig { vdf_verify_vdf_cost: None, vdf_hash_to_input_cost: None, + bcs_per_byte_serialized_cost: None, + bcs_legacy_min_output_size_cost: None, + bcs_failure_cost: None, + hash_sha2_256_base_cost: None, + hash_sha2_256_per_byte_cost: None, + hash_sha2_256_legacy_min_input_len_cost: None, + hash_sha3_256_base_cost: None, + hash_sha3_256_per_byte_cost: None, + hash_sha3_256_legacy_min_input_len_cost: None, + type_name_get_base_cost: None, + type_name_get_per_byte_cost: None, + string_check_utf8_base_cost: None, + string_check_utf8_per_byte_cost: None, + string_is_char_boundary_base_cost: None, + string_sub_string_base_cost: None, + string_sub_string_per_byte_cost: None, + string_index_of_base_cost: None, + string_index_of_per_byte_pattern_cost: None, + string_index_of_per_byte_searched_cost: None, + vector_empty_base_cost: None, + vector_length_base_cost: None, + vector_push_back_base_cost: None, + vector_push_back_legacy_per_abstract_memory_unit_cost: None, + vector_borrow_base_cost: None, + vector_pop_back_base_cost: None, + vector_destroy_empty_base_cost: None, + vector_swap_base_cost: None, + debug_print_base_cost: None, + debug_print_stack_trace_base_cost: None, + max_size_written_objects: None, max_size_written_objects_system_tx: None, @@ -2536,6 +2601,37 @@ impl ProtocolConfig { cfg.feature_flags.per_object_congestion_control_mode = PerObjectCongestionControlMode::TotalTxCount; } + + // Adjust stdlib gas costs + cfg.bcs_per_byte_serialized_cost = Some(2); + cfg.bcs_legacy_min_output_size_cost = Some(1); + cfg.bcs_failure_cost = Some(52); + cfg.debug_print_base_cost = Some(52); + cfg.debug_print_stack_trace_base_cost = Some(52); + cfg.hash_sha2_256_base_cost = Some(52); + cfg.hash_sha2_256_per_byte_cost = Some(2); + cfg.hash_sha2_256_legacy_min_input_len_cost = Some(1); + cfg.hash_sha3_256_base_cost = Some(52); + cfg.hash_sha3_256_per_byte_cost = Some(2); + cfg.hash_sha3_256_legacy_min_input_len_cost = Some(1); + cfg.type_name_get_base_cost = Some(52); + cfg.type_name_get_per_byte_cost = Some(2); + cfg.string_check_utf8_base_cost = Some(52); + cfg.string_check_utf8_per_byte_cost = Some(2); + cfg.string_is_char_boundary_base_cost = Some(52); + cfg.string_sub_string_base_cost = Some(52); + cfg.string_sub_string_per_byte_cost = Some(2); + cfg.string_index_of_base_cost = Some(52); + cfg.string_index_of_per_byte_pattern_cost = Some(2); + cfg.string_index_of_per_byte_searched_cost = Some(2); + cfg.vector_empty_base_cost = Some(52); + cfg.vector_length_base_cost = Some(52); + cfg.vector_push_back_base_cost = Some(52); + cfg.vector_push_back_legacy_per_abstract_memory_unit_cost = Some(2); + cfg.vector_borrow_base_cost = Some(52); + cfg.vector_pop_back_base_cost = Some(52); + cfg.vector_destroy_empty_base_cost = Some(52); + cfg.vector_swap_base_cost = Some(52); } // Use this template when making changes: // diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_53.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_53.snap index 2761b97f0f926..5317182e71a72 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_53.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_53.snap @@ -268,6 +268,35 @@ hmac_hmac_sha3_256_input_cost_per_byte: 2 hmac_hmac_sha3_256_input_cost_per_block: 2 check_zklogin_id_cost_base: 200 check_zklogin_issuer_cost_base: 200 +bcs_per_byte_serialized_cost: 2 +bcs_legacy_min_output_size_cost: 1 +bcs_failure_cost: 52 +hash_sha2_256_base_cost: 52 +hash_sha2_256_per_byte_cost: 2 +hash_sha2_256_legacy_min_input_len_cost: 1 +hash_sha3_256_base_cost: 52 +hash_sha3_256_per_byte_cost: 2 +hash_sha3_256_legacy_min_input_len_cost: 1 +type_name_get_base_cost: 52 +type_name_get_per_byte_cost: 2 +string_check_utf8_base_cost: 52 +string_check_utf8_per_byte_cost: 2 +string_is_char_boundary_base_cost: 52 +string_sub_string_base_cost: 52 +string_sub_string_per_byte_cost: 2 +string_index_of_base_cost: 52 +string_index_of_per_byte_pattern_cost: 2 +string_index_of_per_byte_searched_cost: 2 +vector_empty_base_cost: 52 +vector_length_base_cost: 52 +vector_push_back_base_cost: 52 +vector_push_back_legacy_per_abstract_memory_unit_cost: 2 +vector_borrow_base_cost: 52 +vector_pop_back_base_cost: 52 +vector_destroy_empty_base_cost: 52 +vector_swap_base_cost: 52 +debug_print_base_cost: 52 +debug_print_stack_trace_base_cost: 52 execution_version: 3 consensus_bad_nodes_stake_threshold: 20 max_jwk_votes_per_validator_per_epoch: 240 diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_53.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_53.snap index 0419b3548b467..671eb71756050 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_53.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_53.snap @@ -272,6 +272,35 @@ hmac_hmac_sha3_256_input_cost_per_byte: 2 hmac_hmac_sha3_256_input_cost_per_block: 2 check_zklogin_id_cost_base: 200 check_zklogin_issuer_cost_base: 200 +bcs_per_byte_serialized_cost: 2 +bcs_legacy_min_output_size_cost: 1 +bcs_failure_cost: 52 +hash_sha2_256_base_cost: 52 +hash_sha2_256_per_byte_cost: 2 +hash_sha2_256_legacy_min_input_len_cost: 1 +hash_sha3_256_base_cost: 52 +hash_sha3_256_per_byte_cost: 2 +hash_sha3_256_legacy_min_input_len_cost: 1 +type_name_get_base_cost: 52 +type_name_get_per_byte_cost: 2 +string_check_utf8_base_cost: 52 +string_check_utf8_per_byte_cost: 2 +string_is_char_boundary_base_cost: 52 +string_sub_string_base_cost: 52 +string_sub_string_per_byte_cost: 2 +string_index_of_base_cost: 52 +string_index_of_per_byte_pattern_cost: 2 +string_index_of_per_byte_searched_cost: 2 +vector_empty_base_cost: 52 +vector_length_base_cost: 52 +vector_push_back_base_cost: 52 +vector_push_back_legacy_per_abstract_memory_unit_cost: 2 +vector_borrow_base_cost: 52 +vector_pop_back_base_cost: 52 +vector_destroy_empty_base_cost: 52 +vector_swap_base_cost: 52 +debug_print_base_cost: 52 +debug_print_stack_trace_base_cost: 52 execution_version: 3 consensus_bad_nodes_stake_threshold: 20 max_jwk_votes_per_validator_per_epoch: 240 diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_53.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_53.snap index 095c918715c91..b686158e23286 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_53.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_53.snap @@ -281,6 +281,35 @@ check_zklogin_id_cost_base: 200 check_zklogin_issuer_cost_base: 200 vdf_verify_vdf_cost: 1500 vdf_hash_to_input_cost: 100 +bcs_per_byte_serialized_cost: 2 +bcs_legacy_min_output_size_cost: 1 +bcs_failure_cost: 52 +hash_sha2_256_base_cost: 52 +hash_sha2_256_per_byte_cost: 2 +hash_sha2_256_legacy_min_input_len_cost: 1 +hash_sha3_256_base_cost: 52 +hash_sha3_256_per_byte_cost: 2 +hash_sha3_256_legacy_min_input_len_cost: 1 +type_name_get_base_cost: 52 +type_name_get_per_byte_cost: 2 +string_check_utf8_base_cost: 52 +string_check_utf8_per_byte_cost: 2 +string_is_char_boundary_base_cost: 52 +string_sub_string_base_cost: 52 +string_sub_string_per_byte_cost: 2 +string_index_of_base_cost: 52 +string_index_of_per_byte_pattern_cost: 2 +string_index_of_per_byte_searched_cost: 2 +vector_empty_base_cost: 52 +vector_length_base_cost: 52 +vector_push_back_base_cost: 52 +vector_push_back_legacy_per_abstract_memory_unit_cost: 2 +vector_borrow_base_cost: 52 +vector_pop_back_base_cost: 52 +vector_destroy_empty_base_cost: 52 +vector_swap_base_cost: 52 +debug_print_base_cost: 52 +debug_print_stack_trace_base_cost: 52 execution_version: 3 consensus_bad_nodes_stake_threshold: 20 max_jwk_votes_per_validator_per_epoch: 240 @@ -299,3 +328,4 @@ checkpoint_summary_version_specific_data: 1 max_soft_bundle_size: 5 bridge_should_try_to_finalize_committee: true max_accumulated_txn_cost_per_object_in_mysticeti_commit: 10 + diff --git a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_loc.mvir b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_loc.mvir index ba1630fa4c4be..1e66a269fd30c 100644 --- a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_loc.mvir +++ b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_loc.mvir @@ -1,6 +1,5 @@ //# publish module 0x1.Tester { - import 0x1.signer; struct Data has key { v1: u64, v2: u64 } struct Box has key { f: u64 } diff --git a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_loc_valid.mvir b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_loc_valid.mvir index c7bef57b0cf67..1721acce33997 100644 --- a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_loc_valid.mvir +++ b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_loc_valid.mvir @@ -1,6 +1,5 @@ //# publish module 0x1.Tester { - import 0x1.signer; struct Data has key { v1: u64, v2: u64 } struct Box has key { f: u64 } diff --git a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_on_mut.mvir b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_on_mut.mvir index a3e85b9b6bb64..17f91c9d54e84 100644 --- a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_on_mut.mvir +++ b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_on_mut.mvir @@ -1,6 +1,5 @@ //# publish module 0x1.Tester { - import 0x1.signer; struct Initializer has key { x: u64, y: u64 } struct Point { x: u64, y: u64 } diff --git a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/cant_deref_resource.exp b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/cant_deref_resource.exp index b435375c82a0f..e121d67ab237c 100644 --- a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/cant_deref_resource.exp +++ b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/cant_deref_resource.exp @@ -1,21 +1,21 @@ processed 2 tasks -task 0, lines 1-42: +task 0, lines 1-39: //# publish Error: Unable to publish module '0000000000000000000000000000000000000000000000000000000000000001::Token'. Got VMError: { major_status: READREF_WITHOUT_COPY_ABILITY, sub_status: None, location: 0x1::Token, indices: [(FunctionDefinition, 4)], - offsets: [(FunctionDefinitionIndex(4), 13)], + offsets: [(FunctionDefinitionIndex(4), 10)], } -task 1, lines 44-85: +task 1, lines 41-79: //# publish Error: Unable to publish module '0000000000000000000000000000000000000000000000000000000000000002::Token'. Got VMError: { major_status: READREF_WITHOUT_COPY_ABILITY, sub_status: None, location: 0x2::Token, indices: [(FunctionDefinition, 4)], - offsets: [(FunctionDefinitionIndex(4), 13)], + offsets: [(FunctionDefinitionIndex(4), 10)], } diff --git a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/cant_deref_resource.mvir b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/cant_deref_resource.mvir index 92835730f53c6..dcd42a7d76848 100644 --- a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/cant_deref_resource.mvir +++ b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/cant_deref_resource.mvir @@ -1,6 +1,5 @@ //# publish module 0x1.Token { - import 0x1.signer; struct T has key {v: u64} @@ -19,23 +18,21 @@ module 0x1.Token { return move(res); } - public publish(account: &signer, t: Self.T) { + public publish(account: address, t: Self.T) { label b0: abort(0); } fake(addr: address): &mut Self.T { label b0: abort(0); } - public test(account: &signer) { - let addr: address; + public test(account: address) { let t: Self.T; let tref: &mut Self.T; let y: Self.T; label b0: - addr = signer.address_of(copy(account)); t = Self.new(0); Self.publish(copy(account), move(t)); - tref = Self.fake(move(addr)); + tref = Self.fake(move(account)); y = *move(tref); return; } @@ -43,7 +40,6 @@ module 0x1.Token { //# publish module 0x2.Token { - import 0x1.signer; enum T has key { V{v: u64}} @@ -62,23 +58,21 @@ module 0x2.Token { return move(res); } - public publish(account: &signer, t: Self.T) { + public publish(account: address, t: Self.T) { label b0: abort(0); } fake(addr: address): &mut Self.T { label b0: abort(0); } - public test(account: &signer) { - let addr: address; + public test(account: address) { let t: Self.T; let tref: &mut Self.T; let y: Self.T; label b0: - addr = signer.address_of(copy(account)); t = Self.new(0); Self.publish(copy(account), move(t)); - tref = Self.fake(move(addr)); + tref = Self.fake(move(account)); y = *move(tref); return; } diff --git a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/mut_call_from_get_resource.mvir b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/mut_call_from_get_resource.mvir index b953092719047..75bacb56d4435 100644 --- a/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/mut_call_from_get_resource.mvir +++ b/external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/mut_call_from_get_resource.mvir @@ -1,6 +1,5 @@ //# publish module 0x42.Token { - import 0x1.signer; struct T has key {balance: u64} @@ -28,16 +27,15 @@ module 0x42.Token { return; } - public publish(account: &signer, t: Self.T) { + public publish(account: address, t: Self.T) { label b0: abort(0); } fake(addr: address): &mut Self.T { label b0: abort(0); } - public test(account: &signer) { + public test(account: address) { let z: Self.T; - let addr1: address; let struct1: &mut Self.T; let imm_struct1: &Self.T; let struct1_original_balance: u64; @@ -46,9 +44,8 @@ module 0x42.Token { z = Self.new(0); Self.publish(copy(account), move(z)); - addr1 = signer.address_of(move(account)); // returns mut reference, test its usage - struct1 = Self.fake(copy(addr1)); + struct1 = Self.fake(copy(account)); imm_struct1 = freeze(copy(struct1)); struct1_original_balance = Self.value(move(imm_struct1)); @@ -66,7 +63,6 @@ module 0x42.Token { //# publish module 0x43.Token { - import 0x1.signer; enum T has key {V { balance: u64} } @@ -94,16 +90,15 @@ module 0x43.Token { return; } - public publish(account: &signer, t: Self.T) { + public publish(account: address, t: Self.T) { label b0: abort(0); } fake(addr: address): &mut Self.T { label b0: abort(0); } - public test(account: &signer) { + public test(account: address) { let z: Self.T; - let addr1: address; let struct1: &mut Self.T; let imm_struct1: &Self.T; let struct1_original_balance: u64; @@ -112,9 +107,8 @@ module 0x43.Token { z = Self.new(0); Self.publish(copy(account), move(z)); - addr1 = signer.address_of(move(account)); // returns mut reference, test its usage - struct1 = Self.fake(copy(addr1)); + struct1 = Self.fake(copy(account)); imm_struct1 = freeze(copy(struct1)); struct1_original_balance = Self.value(move(imm_struct1)); diff --git a/external-crates/move/crates/language-benchmarks/src/move_vm.rs b/external-crates/move/crates/language-benchmarks/src/move_vm.rs index 2927af76b9acc..68cdeca91dc0f 100644 --- a/external-crates/move/crates/language-benchmarks/src/move_vm.rs +++ b/external-crates/move/crates/language-benchmarks/src/move_vm.rs @@ -28,6 +28,7 @@ pub fn bench(c: &mut Criterion, fun: &str) { let move_vm = MoveVM::new(move_stdlib_natives::all_natives( AccountAddress::from_hex_literal("0x1").unwrap(), move_stdlib_natives::GasParameters::zeros(), + /* silent debug */ true, )) .unwrap(); execute(c, &move_vm, modules, fun); diff --git a/external-crates/move/crates/move-analyzer/tests/completion/Move.toml b/external-crates/move/crates/move-analyzer/tests/completion/Move.toml index c2c82541db7ae..cddaad6938c8e 100644 --- a/external-crates/move/crates/move-analyzer/tests/completion/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/completion/Move.toml @@ -1,6 +1,5 @@ [package] name = "Completion" -version = "0.0.1" edition = "2024.beta" [dependencies] diff --git a/external-crates/move/crates/move-analyzer/tests/dot_completion.exp b/external-crates/move/crates/move-analyzer/tests/dot_completion.exp index e0e9e954c6635..ad426b6f92568 100644 --- a/external-crates/move/crates/move-analyzer/tests/dot_completion.exp +++ b/external-crates/move/crates/move-analyzer/tests/dot_completion.exp @@ -52,6 +52,14 @@ Method 'test()' == other_mod_dot.move ======================================================== -- test 0 ------------------- use line: 4, use_col: 10 +Method 'all!()' + INSERT TEXT: 'all!(|${1}| ${2})' + TARGET : '(std::vector::all)' + TYPE : 'fun <$T>(&vector<$T>, |&$T| -> bool): bool' +Method 'any!()' + INSERT TEXT: 'any!(|${1}| ${2})' + TARGET : '(std::vector::any)' + TYPE : 'fun <$T>(&vector<$T>, |&$T| -> bool): bool' Method 'append()' INSERT TEXT: 'append(${1:other})' TARGET : '(std::vector::append)' @@ -68,10 +76,42 @@ Method 'contains()' INSERT TEXT: 'contains(${1:e})' TARGET : '(std::vector::contains)' TYPE : 'fun (&vector, &Element): bool' +Method 'count!()' + INSERT TEXT: 'count!(|${1}| ${2})' + TARGET : '(std::vector::count)' + TYPE : 'fun <$T>(&vector<$T>, |&$T| -> bool): u64' +Method 'destroy!()' + INSERT TEXT: 'destroy!(|${1}| ${2})' + TARGET : '(std::vector::destroy)' + TYPE : 'fun <$T>(vector<$T>, |$T| -> ())' Method 'destroy_empty()' INSERT TEXT: 'destroy_empty()' TARGET : '(std::vector::destroy_empty)' TYPE : 'fun (vector)' +Method 'do!()' + INSERT TEXT: 'do!(|${1}| ${2})' + TARGET : '(std::vector::do)' + TYPE : 'fun <$T>(vector<$T>, |$T| -> ())' +Method 'do_mut!()' + INSERT TEXT: 'do_mut!(|${1}| ${2})' + TARGET : '(std::vector::do_mut)' + TYPE : 'fun <$T>(&mut vector<$T>, |&mut $T| -> ())' +Method 'do_ref!()' + INSERT TEXT: 'do_ref!(|${1}| ${2})' + TARGET : '(std::vector::do_ref)' + TYPE : 'fun <$T>(&vector<$T>, |&$T| -> ())' +Method 'filter!()' + INSERT TEXT: 'filter!(|${1}| ${2})' + TARGET : '(std::vector::filter)' + TYPE : 'fun <$T>(vector<$T>, |&$T| -> bool): vector<$T>' +Method 'find_index!()' + INSERT TEXT: 'find_index!(|${1}| ${2})' + TARGET : '(std::vector::find_index)' + TYPE : 'fun <$T>(vector<$T>, |&$T| -> bool): Option' +Method 'fold!()' + INSERT TEXT: 'fold!(${1:init}, |${2}, ${3}| ${4})' + TARGET : '(std::vector::fold)' + TYPE : 'fun <$T, $Acc>(vector<$T>, $Acc, |$Acc, $T| -> $Acc): $Acc' Method 'index_of()' INSERT TEXT: 'index_of(${1:e})' TARGET : '(std::vector::index_of)' @@ -88,6 +128,18 @@ Method 'length()' INSERT TEXT: 'length()' TARGET : '(std::vector::length)' TYPE : 'fun (&vector): u64' +Method 'map!()' + INSERT TEXT: 'map!(|${1}| ${2})' + TARGET : '(std::vector::map)' + TYPE : 'fun <$T, $U>(vector<$T>, |$T| -> $U): vector<$U>' +Method 'map_ref!()' + INSERT TEXT: 'map_ref!(|${1}| ${2})' + TARGET : '(std::vector::map_ref)' + TYPE : 'fun <$T, $U>(&vector<$T>, |&$T| -> $U): vector<$U>' +Method 'partition!()' + INSERT TEXT: 'partition!(|${1}| ${2})' + TARGET : '(std::vector::partition)' + TYPE : 'fun <$T>(vector<$T>, |&$T| -> bool): (vector<$T>, vector<$T>)' Method 'pop_back()' INSERT TEXT: 'pop_back()' TARGET : '(std::vector::pop_back)' @@ -112,4 +164,44 @@ Method 'swap_remove()' INSERT TEXT: 'swap_remove(${1:i})' TARGET : '(std::vector::swap_remove)' TYPE : 'fun (&mut vector, u64): Element' +Method 'to_ascii_string()' + INSERT TEXT: 'to_ascii_string()' + TARGET : '(std::ascii::string)' + TYPE : 'fun (vector): String' +Method 'to_string()' + INSERT TEXT: 'to_string()' + TARGET : '(std::string::utf8)' + TYPE : 'fun (vector): String' +Method 'try_to_ascii_string()' + INSERT TEXT: 'try_to_ascii_string()' + TARGET : '(std::ascii::try_string)' + TYPE : 'fun (vector): Option' +Method 'try_to_string()' + INSERT TEXT: 'try_to_string()' + TARGET : '(std::string::try_utf8)' + TYPE : 'fun (vector): Option' +Method 'zip_do!()' + INSERT TEXT: 'zip_do!(${1:v2}, |${2}, ${3}| ${4})' + TARGET : '(std::vector::zip_do)' + TYPE : 'fun <$T1, $T2>(vector<$T1>, vector<$T2>, |$T1, $T2| -> ())' +Method 'zip_do_mut!()' + INSERT TEXT: 'zip_do_mut!(${1:v2}, |${2}, ${3}| ${4})' + TARGET : '(std::vector::zip_do_mut)' + TYPE : 'fun <$T1, $T2>(&mut vector<$T1>, &mut vector<$T2>, |&mut $T1, &mut $T2| -> ())' +Method 'zip_do_ref!()' + INSERT TEXT: 'zip_do_ref!(${1:v2}, |${2}, ${3}| ${4})' + TARGET : '(std::vector::zip_do_ref)' + TYPE : 'fun <$T1, $T2>(&vector<$T1>, &vector<$T2>, |&$T1, &$T2| -> ())' +Method 'zip_do_reverse!()' + INSERT TEXT: 'zip_do_reverse!(${1:v2}, |${2}, ${3}| ${4})' + TARGET : '(std::vector::zip_do_reverse)' + TYPE : 'fun <$T1, $T2>(vector<$T1>, vector<$T2>, |$T1, $T2| -> ())' +Method 'zip_map!()' + INSERT TEXT: 'zip_map!(${1:v2}, |${2}, ${3}| ${4})' + TARGET : '(std::vector::zip_map)' + TYPE : 'fun <$T1, $T2, $U>(vector<$T1>, vector<$T2>, |$T1, $T2| -> $U): vector<$U>' +Method 'zip_map_ref!()' + INSERT TEXT: 'zip_map_ref!(${1:v2}, |${2}, ${3}| ${4})' + TARGET : '(std::vector::zip_map_ref)' + TYPE : 'fun <$T1, $T2, $U>(&vector<$T1>, &vector<$T2>, |&$T1, &$T2| -> $U): vector<$U>' diff --git a/external-crates/move/crates/move-analyzer/tests/enums/Move.toml b/external-crates/move/crates/move-analyzer/tests/enums/Move.toml index f1a3c05aaa2cf..0fa60b5d2ecf3 100644 --- a/external-crates/move/crates/move-analyzer/tests/enums/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/enums/Move.toml @@ -1,6 +1,5 @@ [package] name = "Enums" -version = "0.0.1" edition = "2024.alpha" [dependencies] diff --git a/external-crates/move/crates/move-analyzer/tests/implicit_uses.exp b/external-crates/move/crates/move-analyzer/tests/implicit_uses.exp index 71a24a5239fe0..1ae18e4ecb1c0 100644 --- a/external-crates/move/crates/move-analyzer/tests/implicit_uses.exp +++ b/external-crates/move/crates/move-analyzer/tests/implicit_uses.exp @@ -2,8 +2,8 @@ -- test 0 ------------------- use line: 4, use_ndx: 1 Use: 'Option', start: 13, end: 19 -Def: 'Option', line: 6, def char: 11 -TypeDef: 'Option', line: 6, char: 11 +Def: 'Option', line: 7, def char: 18 +TypeDef: 'Option', line: 7, char: 18 On Hover: public struct std::option::Option has copy, drop, store { vec: vector @@ -16,7 +16,7 @@ zero or one because Move bytecode does not have ADTs. -- test 1 ------------------- use line: 8, use_ndx: 2 Use: 'option', start: 26, end: 32 -Def: 'option', line: 1, def char: 12 +Def: 'option', line: 4, def char: 12 TypeDef: no info On Hover: module std::option diff --git a/external-crates/move/crates/move-analyzer/tests/inlay-hints/Move.toml b/external-crates/move/crates/move-analyzer/tests/inlay-hints/Move.toml index f5aa6ee913e03..7920464fd5d5a 100644 --- a/external-crates/move/crates/move-analyzer/tests/inlay-hints/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/inlay-hints/Move.toml @@ -1,6 +1,5 @@ [package] name = "InlayHints" -version = "0.0.1" edition = "2024.beta" [dependencies] diff --git a/external-crates/move/crates/move-analyzer/tests/macros.exp b/external-crates/move/crates/move-analyzer/tests/macros.exp index 10f0e3341fc97..d0e0324404abf 100644 --- a/external-crates/move/crates/move-analyzer/tests/macros.exp +++ b/external-crates/move/crates/move-analyzer/tests/macros.exp @@ -34,29 +34,41 @@ macro fun Macros::fun_type::macro_fun() == macros.move ======================================================== -- test 0 ------------------- use line: 7, use_ndx: 0 +Use: 'n foo(', start: 12, end: 18 +Def: 'vector', line: 6, def char: 12 +TypeDef: no info +On Hover: +module std::vector + +A variable-sized container that can hold any type. Indexing is 0-based, and +vectors are growable. This module has many native functions. + + +-- test 1 ------------------- +use line: 7, use_ndx: 1 Use: 'foo', start: 14, end: 17 Def: 'foo', line: 6, def char: 14 TypeDef: no info On Hover: macro fun Macros::macros::foo($i: u64, $body: |u64| -> u64): u64 --- test 1 ------------------- -use line: 7, use_ndx: 1 +-- test 2 ------------------- +use line: 7, use_ndx: 2 Use: '$i', start: 18, end: 20 Def: '$i', line: 6, def char: 18 TypeDef: no info On Hover: $i: u64 --- test 2 ------------------- -use line: 7, use_ndx: 2 +-- test 3 ------------------- +use line: 7, use_ndx: 3 Use: '$body', start: 27, end: 32 Def: '$body', line: 6, def char: 27 TypeDef: no info On Hover: $body: |u64| -> u64 --- test 3 ------------------- +-- test 4 ------------------- use line: 15, use_ndx: 0 Use: 'bar', start: 14, end: 17 Def: 'bar', line: 14, def char: 14 @@ -64,7 +76,7 @@ TypeDef: no info On Hover: macro fun Macros::macros::bar($i: Macros::macros::SomeStruct, $body: |Macros::macros::SomeStruct| -> Macros::macros::SomeStruct): Macros::macros::SomeStruct --- test 4 ------------------- +-- test 5 ------------------- use line: 15, use_ndx: 1 Use: '$i', start: 18, end: 20 Def: '$i', line: 14, def char: 18 @@ -72,7 +84,7 @@ TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: $i: Macros::macros::SomeStruct --- test 5 ------------------- +-- test 6 ------------------- use line: 15, use_ndx: 2 Use: 'SomeStruct', start: 22, end: 32 Def: 'SomeStruct', line: 2, def char: 18 @@ -82,7 +94,7 @@ public struct Macros::macros::SomeStruct has drop { some_field: u64 } --- test 6 ------------------- +-- test 7 ------------------- use line: 15, use_ndx: 3 Use: '$body', start: 34, end: 39 Def: '$body', line: 14, def char: 34 @@ -90,7 +102,7 @@ TypeDef: no info On Hover: $body: |Macros::macros::SomeStruct| -> Macros::macros::SomeStruct --- test 7 ------------------- +-- test 8 ------------------- use line: 15, use_ndx: 4 Use: 'SomeStruct', start: 42, end: 52 Def: 'SomeStruct', line: 2, def char: 18 @@ -100,7 +112,7 @@ public struct Macros::macros::SomeStruct has drop { some_field: u64 } --- test 8 ------------------- +-- test 9 ------------------- use line: 15, use_ndx: 5 Use: 'SomeStruct', start: 57, end: 67 Def: 'SomeStruct', line: 2, def char: 18 @@ -110,7 +122,7 @@ public struct Macros::macros::SomeStruct has drop { some_field: u64 } --- test 9 ------------------- +-- test 10 ------------------- use line: 15, use_ndx: 6 Use: 'SomeStruct', start: 70, end: 80 Def: 'SomeStruct', line: 2, def char: 18 @@ -120,7 +132,7 @@ public struct Macros::macros::SomeStruct has drop { some_field: u64 } --- test 10 ------------------- +-- test 11 ------------------- use line: 19, use_ndx: 0 Use: 'for_each', start: 14, end: 22 Def: 'for_each', line: 18, def char: 14 @@ -128,7 +140,7 @@ TypeDef: no info On Hover: macro fun Macros::macros::for_each<$T>($v: &vector<$T>, $body: |&$T| -> ()) --- test 11 ------------------- +-- test 12 ------------------- use line: 19, use_ndx: 1 Use: '$T', start: 23, end: 25 Def: '$T', line: 18, def char: 23 @@ -136,7 +148,7 @@ TypeDef: no info On Hover: $T --- test 12 ------------------- +-- test 13 ------------------- use line: 19, use_ndx: 2 Use: '$v', start: 27, end: 29 Def: '$v', line: 18, def char: 27 @@ -144,7 +156,7 @@ TypeDef: no info On Hover: let $v: &vector --- test 13 ------------------- +-- test 14 ------------------- use line: 19, use_ndx: 3 Use: '$T', start: 39, end: 41 Def: '$T', line: 18, def char: 23 @@ -152,7 +164,7 @@ TypeDef: no info On Hover: $T --- test 14 ------------------- +-- test 15 ------------------- use line: 19, use_ndx: 4 Use: '$body', start: 44, end: 49 Def: '$body', line: 18, def char: 44 @@ -160,7 +172,7 @@ TypeDef: no info On Hover: $body: |&$T| -> () --- test 15 ------------------- +-- test 16 ------------------- use line: 19, use_ndx: 5 Use: '$T', start: 53, end: 55 Def: '$T', line: 18, def char: 23 @@ -168,7 +180,7 @@ TypeDef: no info On Hover: $T --- test 16 ------------------- +-- test 17 ------------------- use line: 33, use_ndx: 0 Use: 'macros', start: 16, end: 22 Def: 'macros', line: 0, def char: 15 @@ -176,7 +188,7 @@ TypeDef: no info On Hover: module Macros::macros --- test 17 ------------------- +-- test 18 ------------------- use line: 33, use_ndx: 1 Use: 'foo', start: 24, end: 27 Def: 'foo', line: 6, def char: 14 @@ -184,7 +196,7 @@ TypeDef: no info On Hover: macro fun Macros::macros::foo($i: u64, $body: |u64| -> u64): u64 --- test 18 ------------------- +-- test 19 ------------------- use line: 33, use_ndx: 2 Use: 'p', start: 29, end: 30 Def: 'p', line: 31, def char: 12 @@ -192,7 +204,7 @@ TypeDef: no info On Hover: let p: u64 --- test 19 ------------------- +-- test 20 ------------------- use line: 33, use_ndx: 3 Use: 'x', start: 33, end: 34 Def: 'x', line: 32, def char: 33 @@ -200,7 +212,7 @@ TypeDef: no info On Hover: let x: u64 --- test 20 ------------------- +-- test 21 ------------------- use line: 33, use_ndx: 4 Use: 'x', start: 36, end: 37 Def: 'x', line: 32, def char: 33 @@ -208,7 +220,7 @@ TypeDef: no info On Hover: let x: u64 --- test 21 ------------------- +-- test 22 ------------------- use line: 38, use_ndx: 5 Use: 'y', start: 49, end: 50 Def: 'y', line: 37, def char: 49 @@ -216,7 +228,7 @@ TypeDef: no info On Hover: let y: u64 --- test 22 ------------------- +-- test 23 ------------------- use line: 38, use_ndx: 7 Use: 'foo', start: 68, end: 71 Def: 'foo', line: 6, def char: 14 @@ -224,7 +236,7 @@ TypeDef: no info On Hover: macro fun Macros::macros::foo($i: u64, $body: |u64| -> u64): u64 --- test 23 ------------------- +-- test 24 ------------------- use line: 38, use_ndx: 8 Use: 'y', start: 73, end: 74 Def: 'y', line: 37, def char: 49 @@ -232,7 +244,7 @@ TypeDef: no info On Hover: let y: u64 --- test 24 ------------------- +-- test 25 ------------------- use line: 38, use_ndx: 9 Use: 'z', start: 77, end: 78 Def: 'z', line: 37, def char: 77 @@ -240,7 +252,7 @@ TypeDef: no info On Hover: let z: u64 --- test 25 ------------------- +-- test 26 ------------------- use line: 38, use_ndx: 10 Use: 'z', start: 80, end: 81 Def: 'z', line: 37, def char: 77 @@ -248,7 +260,7 @@ TypeDef: no info On Hover: let z: u64 --- test 26 ------------------- +-- test 27 ------------------- use line: 44, use_ndx: 4 Use: 'sum', start: 48, end: 51 Def: 'sum', line: 42, def char: 16 @@ -256,7 +268,7 @@ TypeDef: no info On Hover: let mut sum: u64 --- test 27 ------------------- +-- test 28 ------------------- use line: 45, use_ndx: 0 Use: 'es', start: 8, end: 10 Def: 'es', line: 41, def char: 12 @@ -264,7 +276,7 @@ TypeDef: no info On Hover: let es: vector --- test 28 ------------------- +-- test 29 ------------------- use line: 45, use_ndx: 1 Use: 'feach', start: 11, end: 16 Def: 'for_each', line: 18, def char: 14 @@ -272,7 +284,7 @@ TypeDef: no info On Hover: macro fun Macros::macros::for_each<$T>($v: &vector<$T>, $body: |&$T| -> ()) --- test 29 ------------------- +-- test 30 ------------------- use line: 52, use_ndx: 2 Use: 'SomeStruct', start: 34, end: 44 Def: 'SomeStruct', line: 2, def char: 18 diff --git a/external-crates/move/crates/move-analyzer/tests/macros.ide b/external-crates/move/crates/move-analyzer/tests/macros.ide index 76471b5f246f1..2a2dc12a448e5 100644 --- a/external-crates/move/crates/move-analyzer/tests/macros.ide +++ b/external-crates/move/crates/move-analyzer/tests/macros.ide @@ -35,6 +35,10 @@ "use_line": 7, "use_ndx": 2 }, + { + "use_line": 7, + "use_ndx": 3 + }, { "use_line": 15, "use_ndx": 0 @@ -146,4 +150,4 @@ ] } } -} \ No newline at end of file +} diff --git a/external-crates/move/crates/move-analyzer/tests/mod-ident-uniform/Move.toml b/external-crates/move/crates/move-analyzer/tests/mod-ident-uniform/Move.toml index 4d4ae972dec2a..4c87e222272d8 100644 --- a/external-crates/move/crates/move-analyzer/tests/mod-ident-uniform/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/mod-ident-uniform/Move.toml @@ -1,6 +1,6 @@ [package] name = "ModIdentUniform" -version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../move-stdlib/", addr_subst = { "std" = "0x1" } } diff --git a/external-crates/move/crates/move-analyzer/tests/move-2024/Move.toml b/external-crates/move/crates/move-analyzer/tests/move-2024/Move.toml index 6e8e5c1001331..0d679d0771239 100644 --- a/external-crates/move/crates/move-analyzer/tests/move-2024/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/move-2024/Move.toml @@ -1,6 +1,5 @@ [package] name = "Move2024" -version = "0.0.1" edition = "2024.beta" [dependencies] diff --git a/external-crates/move/crates/move-analyzer/tests/parse-error-dep/Move.toml b/external-crates/move/crates/move-analyzer/tests/parse-error-dep/Move.toml index bd210e0806f65..1149112ed88b1 100644 --- a/external-crates/move/crates/move-analyzer/tests/parse-error-dep/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/parse-error-dep/Move.toml @@ -1,6 +1,6 @@ [package] name = "ParseErrorDep" -version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../move-stdlib/", addr_subst = { "std" = "0x1" } } diff --git a/external-crates/move/crates/move-analyzer/tests/parse-error/Move.toml b/external-crates/move/crates/move-analyzer/tests/parse-error/Move.toml index d0dd5b9d61241..a27b40aaebcb9 100644 --- a/external-crates/move/crates/move-analyzer/tests/parse-error/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/parse-error/Move.toml @@ -1,6 +1,6 @@ [package] name = "ParseError" -version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../move-stdlib/", addr_subst = { "std" = "0x1" } } diff --git a/external-crates/move/crates/move-analyzer/tests/partial-dot/Move.toml b/external-crates/move/crates/move-analyzer/tests/partial-dot/Move.toml index 66aeb5dcdcfa7..da0955faa0d8e 100644 --- a/external-crates/move/crates/move-analyzer/tests/partial-dot/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/partial-dot/Move.toml @@ -1,6 +1,6 @@ [package] name = "PartialDot" -version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../move-stdlib/", addr_subst = { "std" = "0x1" } } diff --git a/external-crates/move/crates/move-analyzer/tests/partial-function/Move.toml b/external-crates/move/crates/move-analyzer/tests/partial-function/Move.toml index 917b1f61cf461..b9876d64b3a67 100644 --- a/external-crates/move/crates/move-analyzer/tests/partial-function/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/partial-function/Move.toml @@ -1,6 +1,6 @@ [package] name = "PartialFunction" -version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../move-stdlib/", addr_subst = { "std" = "0x1" } } diff --git a/external-crates/move/crates/move-analyzer/tests/pkg-naming-error/Move.toml b/external-crates/move/crates/move-analyzer/tests/pkg-naming-error/Move.toml index f8feb6145014d..9463d76e478b3 100644 --- a/external-crates/move/crates/move-analyzer/tests/pkg-naming-error/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/pkg-naming-error/Move.toml @@ -1,6 +1,6 @@ [package] name = "PkgNamingError" -version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../move-stdlib/", addr_subst = { "std" = "0x1" } } diff --git a/external-crates/move/crates/move-analyzer/tests/pre-type-error-dep/Move.toml b/external-crates/move/crates/move-analyzer/tests/pre-type-error-dep/Move.toml index 7b2f8dce30660..b9ebf9b55b5bf 100644 --- a/external-crates/move/crates/move-analyzer/tests/pre-type-error-dep/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/pre-type-error-dep/Move.toml @@ -1,6 +1,6 @@ [package] name = "PreTypeErrorDep" -version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../move-stdlib/", addr_subst = { "std" = "0x1" } } diff --git a/external-crates/move/crates/move-analyzer/tests/pre-type-error/Move.toml b/external-crates/move/crates/move-analyzer/tests/pre-type-error/Move.toml index 8ff3b2be186ee..05bd4a4a6a41d 100644 --- a/external-crates/move/crates/move-analyzer/tests/pre-type-error/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/pre-type-error/Move.toml @@ -1,6 +1,6 @@ [package] name = "PreTypeError" -version = "0.0.1" +edition = "legacy" [addresses] PreTypeError = "0xCAFE" diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/Move.toml b/external-crates/move/crates/move-analyzer/tests/symbols/Move.toml index ddd0a6d3582c2..858e952648a42 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/symbols/Move.toml @@ -1,6 +1,6 @@ [package] name = "Symbols" -version = "0.0.1" +edition = "legacy" [dependencies] MoveStdlib = { local = "../../../move-stdlib/", addr_subst = { "std" = "0x1" } } diff --git a/external-crates/move/crates/move-cli/src/main.rs b/external-crates/move/crates/move-cli/src/main.rs index acbbbe6d23a8d..11eb3d0699814 100644 --- a/external-crates/move/crates/move-cli/src/main.rs +++ b/external-crates/move/crates/move-cli/src/main.rs @@ -4,19 +4,12 @@ use anyhow::Result; use move_core_types::account_address::AccountAddress; -use move_stdlib_natives::{all_natives, nursery_natives, GasParameters, NurseryGasParameters}; +use move_stdlib_natives::{all_natives, GasParameters}; fn main() -> Result<()> { let cost_table = &move_vm_test_utils::gas_schedule::INITIAL_COST_SCHEDULE; let addr = AccountAddress::from_hex_literal("0x1").unwrap(); - let natives = all_natives(addr, GasParameters::zeros()) - .into_iter() - .chain(nursery_natives( - /* silent */ false, - addr, - NurseryGasParameters::zeros(), - )) - .collect(); + let natives = all_natives(addr, GasParameters::zeros(), /* silent */ false); move_cli::move_cli(natives, cost_table) } diff --git a/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/B/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/B/Move.toml index a6ad126c76313..cd03254de0669 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/B/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/B/Move.toml @@ -1,5 +1,6 @@ [package] name = "Bar" +edition = "2024.beta" [addresses] B = "0x2" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/C/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/C/Move.toml index db95e4a84a73b..6f2a8b5a3aa38 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/C/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/C/Move.toml @@ -1,5 +1,6 @@ [package] name = "Foo" +edition = "2024.beta" [addresses] C = "0x3" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/Move.toml index 3b41905ce8d07..959dd1966ec1f 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/build_with_bytecode/Move.toml @@ -1,5 +1,6 @@ [package] name = "A" +edition = "2024.beta" [addresses] A = "0x2" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/build_with_dep_warnings/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/build_with_dep_warnings/Move.toml index 18ae248f3b8c4..92679a7fff084 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/build_with_dep_warnings/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/build_with_dep_warnings/Move.toml @@ -1,5 +1,6 @@ [package] name = "Test" +edition = "2024.beta" [dependencies] SomeDep = { local = "dep" } diff --git a/external-crates/move/crates/move-cli/tests/build_tests/build_with_dep_warnings/dep/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/build_with_dep_warnings/dep/Move.toml index a03576b363c0b..2d3274e227456 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/build_with_dep_warnings/dep/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/build_with_dep_warnings/dep/Move.toml @@ -1,2 +1,3 @@ [package] name = "SomeDep" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/build_with_warnings/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/build_with_warnings/Move.toml index cb7453ae43828..c8f2665caf8cb 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/build_with_warnings/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/build_with_warnings/Move.toml @@ -1,2 +1,3 @@ [package] name = "Test" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/Move.toml index 799d21da627c2..eb51a49a36279 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/Move.toml @@ -1,5 +1,6 @@ [package] name = "Test" +edition = "2024.beta" [addresses] foo = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/sources/m.move b/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/sources/m.move index 0947c77107c1c..f055c1d054ec4 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/sources/m.move +++ b/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/sources/m.move @@ -12,9 +12,9 @@ module bar::b { module bar::c { #[allow(unused_field)] - struct B { x: u64 } + public struct B { x: u64 } #[allow(unused_field)] - struct A { b: vector } + public struct A { b: vector } public fun g(): u64 { foo::a::f() + @@ -35,8 +35,8 @@ module baz::d { } module qux::e { - struct B has drop { x: u64 } - struct A has drop { x: u64 } + public struct B has drop { x: u64 } + public struct A has drop { x: u64 } public fun a(): A { A { x: 46 } diff --git a/external-crates/move/crates/move-cli/tests/build_tests/circular_dependencies/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/circular_dependencies/Move.toml index 6aaff66ce5b5a..d0203b9635df7 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/circular_dependencies/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/circular_dependencies/Move.toml @@ -1,5 +1,6 @@ [package] name = "Foo" +edition = "2024.beta" [dependencies] Bar = { local = "bar" } diff --git a/external-crates/move/crates/move-cli/tests/build_tests/circular_dependencies/bar/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/circular_dependencies/bar/Move.toml index 4dba0ffcdc0b3..765a6cfe26577 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/circular_dependencies/bar/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/circular_dependencies/bar/Move.toml @@ -1,5 +1,6 @@ [package] name = "Bar" +edition = "2024.beta" [dependencies] Foo = { local = ".." } diff --git a/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/Move.toml index 9555addf395da..074036f200787 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/Move.toml @@ -1,5 +1,6 @@ [package] name = "A" +edition = "2024.beta" [addresses] A = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/bar/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/bar/Move.toml index b1a9789ad67de..55f3cce59b4b1 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/bar/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/bar/Move.toml @@ -1,5 +1,6 @@ [package] name = "Bar" +edition = "2024.beta" [addresses] A = "_" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/foo/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/foo/Move.toml index 54db278827612..1d171931f5650 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/foo/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/dependency_chain/foo/Move.toml @@ -1,5 +1,6 @@ [package] name = "Foo" +edition = "2024.beta" [addresses] A = "_" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/dev_address/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/dev_address/Move.toml index bf79537d599bd..1fe668353dcbf 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/dev_address/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/dev_address/Move.toml @@ -1,5 +1,6 @@ [package] name = "A" +edition = "2024.beta" [addresses] A = "_" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/disassemble_module/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/disassemble_module/Move.toml index cb7453ae43828..c8f2665caf8cb 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/disassemble_module/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/disassemble_module/Move.toml @@ -1,2 +1,3 @@ [package] name = "Test" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/disassemble_module/sources/m.move b/external-crates/move/crates/move-cli/tests/build_tests/disassemble_module/sources/m.move index 35af0da97addc..b8b8c95c001ae 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/disassemble_module/sources/m.move +++ b/external-crates/move/crates/move-cli/tests/build_tests/disassemble_module/sources/m.move @@ -1,7 +1,7 @@ -module 0x42::m { +module 0x42::m; -struct Zs {} -struct As {} +public struct Zs {} +public struct As {} const Zc: u64 = 1; const Ac: u32 = 0; @@ -12,4 +12,3 @@ public fun zf(): u64 { Zc } public fun af(): u32 { Ac } public fun sf(): vector { AString } public fun nf(): vector { NotAString } -} diff --git a/external-crates/move/crates/move-cli/tests/build_tests/empty_module_no_deps/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/empty_module_no_deps/Move.toml index 1cf5dd8272d40..c3f61cd7e71ad 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/empty_module_no_deps/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/empty_module_no_deps/Move.toml @@ -1,2 +1,3 @@ [package] name = "A" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/Move.toml index 4fe19dd013e56..6e3fa396834c9 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/Move.toml @@ -1,5 +1,6 @@ [package] name = "build_include_exclude_stdlib" +edition = "2024.beta" [addresses] std = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/args.exp b/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/args.exp index 5620f9e5d8cf6..2089ac58027a6 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/args.exp +++ b/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/args.exp @@ -1,24 +1,16 @@ Command `build -v`: BUILDING build_include_exclude_stdlib error[E03002]: unbound module - ┌─ ./sources/UseSigner.move:2:7 + ┌─ ./sources/UseSigner.move:2:9 │ -2 │ use std::signer; - │ ^^^^^^^^^^^ Invalid 'use'. Unbound module: 'std::signer' +2 │ use std::address; + │ ^^^^^^^^^^^^ Invalid 'use'. Unbound module: 'std::address' -warning[W09002]: unused variable - ┌─ ./sources/UseSigner.move:4:16 +error[E03006]: unexpected name in this position + ┌─ ./sources/UseSigner.move:5:9 │ -4 │ public fun f(account: &signer): address { - │ ^^^^^^^ Unused parameter 'account'. Consider removing or prefixing with an underscore: '_account' - │ - = This warning can be suppressed with '#[allow(unused_variable)]' applied to the 'module' or module member ('const', 'fun', or 'struct') - -error[E03002]: unbound module - ┌─ ./sources/UseSigner.move:5:5 - │ -5 │ signer::address_of(account) - │ ^^^^^^ Unbound module alias 'signer' +5 │ address::length() + │ ^^^^^^^ Could not resolve the name 'address' Command `-d -v build`: INCLUDING DEPENDENCY MoveStdlib diff --git a/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/sources/UseSigner.move b/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/sources/UseSigner.move index fdec0d78b1d5b..471e9ac62e941 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/sources/UseSigner.move +++ b/external-crates/move/crates/move-cli/tests/build_tests/include_exclude_stdlib/sources/UseSigner.move @@ -1,7 +1,7 @@ module 0x1::Example { - use std::signer; + use std::address; - public fun f(account: &signer): address { - signer::address_of(account) - } + public fun f(): u64 { + address::length() + } } diff --git a/external-crates/move/crates/move-cli/tests/build_tests/json_errors/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/json_errors/Move.toml index cb7453ae43828..c8f2665caf8cb 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/json_errors/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/json_errors/Move.toml @@ -1,2 +1,3 @@ [package] name = "Test" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/migration/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/migration/Move.toml index a1c46ce0fd4e6..dba667925d24a 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/migration/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/migration/Move.toml @@ -3,6 +3,7 @@ [package] name = "A" +edition = "2024.beta" # this is a comment [addresses] diff --git a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_adding_new_source/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_adding_new_source/Move.toml index 38c8578e70c5d..fb502b9d63a8b 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_adding_new_source/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_adding_new_source/Move.toml @@ -1,2 +1,3 @@ [package] name = "Foo" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_deleting_output_artifact/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_deleting_output_artifact/Move.toml index 38c8578e70c5d..fb502b9d63a8b 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_deleting_output_artifact/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_deleting_output_artifact/Move.toml @@ -1,2 +1,3 @@ [package] name = "Foo" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_touching_manifest/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_touching_manifest/Move.toml index 38c8578e70c5d..fb502b9d63a8b 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_touching_manifest/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_touching_manifest/Move.toml @@ -1,2 +1,3 @@ [package] name = "Foo" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_touching_source/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_touching_source/Move.toml index 38c8578e70c5d..fb502b9d63a8b 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_touching_source/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_after_touching_source/Move.toml @@ -1,2 +1,3 @@ [package] name = "Foo" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_no_modification/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_no_modification/Move.toml index 38c8578e70c5d..fb502b9d63a8b 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/rebuild_no_modification/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/rebuild_no_modification/Move.toml @@ -1,2 +1,3 @@ [package] name = "Foo" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/unbound_address/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/unbound_address/Move.toml index eb004df99fa61..d3b1acf0e1ca2 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/unbound_address/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/unbound_address/Move.toml @@ -1,5 +1,6 @@ [package] name = "A" +edition = "2024.beta" [addresses] A = "_" diff --git a/external-crates/move/crates/move-cli/tests/build_tests/unbound_dependency/Move.toml b/external-crates/move/crates/move-cli/tests/build_tests/unbound_dependency/Move.toml index 34150a5abc8c8..72e580593a81d 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/unbound_dependency/Move.toml +++ b/external-crates/move/crates/move-cli/tests/build_tests/unbound_dependency/Move.toml @@ -1,5 +1,6 @@ [package] name = "A" +edition = "2024.beta" [dependencies] Foo = { local = "foo" } diff --git a/external-crates/move/crates/move-cli/tests/metatests/cov/plain/Move.toml b/external-crates/move/crates/move-cli/tests/metatests/cov/plain/Move.toml index 22033b4afee83..1a5af0edcf304 100644 --- a/external-crates/move/crates/move-cli/tests/metatests/cov/plain/Move.toml +++ b/external-crates/move/crates/move-cli/tests/metatests/cov/plain/Move.toml @@ -1,2 +1,3 @@ [package] name = "plain" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/Move.toml b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/Move.toml index 4e912138c202f..c338346e40e39 100644 --- a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/Move.toml +++ b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/Move.toml @@ -1,2 +1,3 @@ [package] name = "two-runs-diff-module" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/sources/M1.move b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/sources/M1.move index 1bd0d579ed22c..9fd7c6bce4215 100644 --- a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/sources/M1.move +++ b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/sources/M1.move @@ -1,5 +1,3 @@ -address 0x42 { -module M1 { +module 0x42::M1 { public entry fun test() {} } -} diff --git a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/sources/M2.move b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/sources/M2.move index efe2e57019bd7..9b7708349de42 100644 --- a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/sources/M2.move +++ b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-diff-module/sources/M2.move @@ -1,5 +1,3 @@ -address 0x42 { -module M2 { +module 0x42::M2 { public entry fun test() {} } -} diff --git a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-same-module/Move.toml b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-same-module/Move.toml index 5b3ff32dba14f..e2281d4558338 100644 --- a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-same-module/Move.toml +++ b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-same-module/Move.toml @@ -1,2 +1,3 @@ [package] name = "two-runs-same-module" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-same-module/sources/M.move b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-same-module/sources/M.move index 2bf7c4f6e69ff..63bfb22fe0cfc 100644 --- a/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-same-module/sources/M.move +++ b/external-crates/move/crates/move-cli/tests/metatests/cov/two-runs-same-module/sources/M.move @@ -1,5 +1,4 @@ -address 0x42 { -module M { +module 0x42::M { public entry fun test(x: u8) { if (x == 0) { return () @@ -8,4 +7,3 @@ module M { } } } -} diff --git a/external-crates/move/crates/move-cli/tests/move_unit_tests/assign_dev_addr_for_dep/Move.toml b/external-crates/move/crates/move-cli/tests/move_unit_tests/assign_dev_addr_for_dep/Move.toml index 9807273047ad1..de9900102115b 100644 --- a/external-crates/move/crates/move-cli/tests/move_unit_tests/assign_dev_addr_for_dep/Move.toml +++ b/external-crates/move/crates/move-cli/tests/move_unit_tests/assign_dev_addr_for_dep/Move.toml @@ -1,5 +1,6 @@ [package] name = "Foo" +edition = "2024.beta" [addresses] A = "_" diff --git a/external-crates/move/crates/move-cli/tests/move_unit_tests/assign_dev_addr_for_dep/dep/Move.toml b/external-crates/move/crates/move-cli/tests/move_unit_tests/assign_dev_addr_for_dep/dep/Move.toml index 504a96e8b969e..b2e5ff722fc15 100644 --- a/external-crates/move/crates/move-cli/tests/move_unit_tests/assign_dev_addr_for_dep/dep/Move.toml +++ b/external-crates/move/crates/move-cli/tests/move_unit_tests/assign_dev_addr_for_dep/dep/Move.toml @@ -1,5 +1,6 @@ [package] name = "Bar" +edition = "2024.beta" [addresses] B = "_" diff --git a/external-crates/move/crates/move-cli/tests/move_unit_tests/standalone_module_with_dev_addr_assignment/Move.toml b/external-crates/move/crates/move-cli/tests/move_unit_tests/standalone_module_with_dev_addr_assignment/Move.toml index 9eda613c2785f..ec94f223d05ea 100644 --- a/external-crates/move/crates/move-cli/tests/move_unit_tests/standalone_module_with_dev_addr_assignment/Move.toml +++ b/external-crates/move/crates/move-cli/tests/move_unit_tests/standalone_module_with_dev_addr_assignment/Move.toml @@ -1,5 +1,6 @@ [package] name = "StandaloneModule" +edition = "2024.beta" [addresses] A = "_" diff --git a/external-crates/move/crates/move-cli/tests/move_unit_tests/standalone_module_with_regular_addr_assignment/Move.toml b/external-crates/move/crates/move-cli/tests/move_unit_tests/standalone_module_with_regular_addr_assignment/Move.toml index b9d25c351bf5d..125b57dc7e2c4 100644 --- a/external-crates/move/crates/move-cli/tests/move_unit_tests/standalone_module_with_regular_addr_assignment/Move.toml +++ b/external-crates/move/crates/move-cli/tests/move_unit_tests/standalone_module_with_regular_addr_assignment/Move.toml @@ -1,5 +1,6 @@ [package] name = "StandaloneModule" +edition = "2024.beta" [addresses] A = "0x2" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/build_modules_and_scripts/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/build_modules_and_scripts/Move.toml index 227421ece9413..213deb0302a27 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/build_modules_and_scripts/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/build_modules_and_scripts/Move.toml @@ -1,2 +1,3 @@ [package] name = "build_modules_and_scripts" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/build_modules_and_scripts/sources/M.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/build_modules_and_scripts/sources/M.move index 323f521c5fa9b..9b26c6106d495 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/build_modules_and_scripts/sources/M.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/build_modules_and_scripts/sources/M.move @@ -1,4 +1,2 @@ -address 0x42 { -module M { -} +module 0x42::M { } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/doctor_with_stdlib/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/doctor_with_stdlib/Move.toml index 54d0c7b5cf984..2e8f58e6a36bd 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/doctor_with_stdlib/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/doctor_with_stdlib/Move.toml @@ -1,8 +1,9 @@ [package] name = "doctor_with_stdlib" +edition = "2024.beta" [addresses] std = "0x1" [dependencies] -MoveNursery = { local = "../../../../move-stdlib/nursery" } +MoveStdlib = { local = "../../../../move-stdlib" } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/doctor_with_stdlib/sources/M.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/doctor_with_stdlib/sources/M.move index 2a3b4679e1879..8d8f2c2eec2a6 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/doctor_with_stdlib/sources/M.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/doctor_with_stdlib/sources/M.move @@ -1,5 +1,4 @@ -address 0x2 { -module M { +module 0x42::M { use std::debug; #[allow(unused_function)] @@ -7,4 +6,3 @@ module M { debug::print(&7); } } -} diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_arithmetic_failure/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_arithmetic_failure/Move.toml index 82f9ed8591dc3..19fb61793939a 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_arithmetic_failure/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_arithmetic_failure/Move.toml @@ -1,2 +1,3 @@ [package] name = "explain_arithmetic_failure" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_stdlib_abort/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_stdlib_abort/Move.toml index 30d499f2e0e75..0997e9909a1ed 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_stdlib_abort/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_stdlib_abort/Move.toml @@ -1,5 +1,6 @@ [package] name = "explain_stdlib_abort" +edition = "2024.beta" [addresses] std = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_stdlib_abort/sources/bad_borrow.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_stdlib_abort/sources/bad_borrow.move index a88ee72f325ca..4305fd427223b 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_stdlib_abort/sources/bad_borrow.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_stdlib_abort/sources/bad_borrow.move @@ -1,5 +1,4 @@ module 0x42::m { - use std::vector; entry fun bad_borrow() { let v = vector::empty(); let _ref = vector::borrow(&v, 0); diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_user_module_abort/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_user_module_abort/Move.toml index 59b849a5b413c..af4f2f265a5db 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_user_module_abort/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_user_module_abort/Move.toml @@ -1,2 +1,3 @@ [package] name = "explain_user_module_abort" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_user_module_abort/sources/Fail.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_user_module_abort/sources/Fail.move index ca5da8df3229e..a60f498cb193a 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_user_module_abort/sources/Fail.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/explain_user_module_abort/sources/Fail.move @@ -1,7 +1,5 @@ -address 0x2 { -module Fail { +module 0x2::Fail { public entry fun f() { abort 77 } } -} diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/gas_metering/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/gas_metering/Move.toml index f712729a5a34a..2a77d599f217f 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/gas_metering/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/gas_metering/Move.toml @@ -1,2 +1,3 @@ [package] name = "gas_metering" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/Move.toml index a504af284913b..4113037316681 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/Move.toml @@ -1,2 +1,3 @@ [package] name = "generate_struct_layout" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/M1.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/M1.move index 7c6f5a31f98c8..c171a80fb3ccf 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/M1.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/M1.move @@ -2,11 +2,11 @@ module 0x1::M1 { use 0x1::M2::C; - struct A { f: u64, v: vector, b: B } + public struct A { f: u64, v: vector, b: B } - struct B { a: address, c: C, t: T } + public struct B { a: address, c: C, t: T } - struct S { t: T } + public struct S { t: T } - struct G { x: u64, s: S } + public struct G { x: u64, s: S } } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/M2.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/M2.move index 8e8baa58fe0e4..f3cc297417d58 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/M2.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/M2.move @@ -1,5 +1,5 @@ module 0x1::M2 { #[allow(unused_field)] - struct C { t: T, b: bool } + public struct C { t: T, b: bool } } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/phantoms.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/phantoms.move index 36c04fd66ca1b..6c177ab6c6454 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/phantoms.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/generate_struct_layout/sources/phantoms.move @@ -1,19 +1,19 @@ #[allow(unused_field)] module 0x1::phantoms { - struct A {} + public struct A {} - struct B {} + public struct B {} - struct C { + public struct C { a: A, b: B } - struct D { + public struct D { v: vector } - struct E { + public struct E { v1: vector, v2: vector } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/Move.toml index c2cd982ee3515..2d1699293e385 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/Move.toml @@ -1,5 +1,6 @@ [package] name = "module_publish_view" +edition = "2024.beta" [addresses] std = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/deps1/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/deps1/Move.toml index c0a24ac0f10be..295dd96c2e4cf 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/deps1/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/deps1/Move.toml @@ -1,2 +1,3 @@ [package] name = "Deps1" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/deps2/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/deps2/Move.toml index 75c9ff86ecfa0..a34d60f2624e0 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/deps2/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/deps2/Move.toml @@ -1,2 +1,3 @@ [package] name = "Deps2" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/sources/M1.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/sources/M1.move index f5aed00e50400..7c289c5e51e5d 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/sources/M1.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_disassemble/sources/M1.move @@ -1,8 +1,7 @@ module 0xa::M1 { - use std::vector; #[allow(unused_field)] - struct S { i: u64 } + public struct S { i: u64 } public fun foo(x: u64): vector { let y = bar(); diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_publish_view/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_publish_view/Move.toml index a9da3b168aaf4..fb820c1d04de9 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_publish_view/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_publish_view/Move.toml @@ -1,2 +1,3 @@ [package] name = "module_publish_view" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_publish_view/sources/Module.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_publish_view/sources/Module.move index 3bde7f18c916b..0dc254cd9b2ae 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/module_publish_view/sources/Module.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/module_publish_view/sources/Module.move @@ -1,9 +1,7 @@ -address 0x42 { -module Module { - struct S { i: u64 } +module 0x42::Module { + public struct S { i: u64 } public fun foo(i: u64): S { S { i } } } -} diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/multi_module_publish/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/multi_module_publish/Move.toml index ce353a9bdb159..584de0746e044 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/multi_module_publish/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/multi_module_publish/Move.toml @@ -1,2 +1,3 @@ [package] name = "multi_module_publish" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/multi_module_publish/sources/GoodFriends.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/multi_module_publish/sources/GoodFriends.move index c96b84ac900bc..74c3ff22d4e9b 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/multi_module_publish/sources/GoodFriends.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/multi_module_publish/sources/GoodFriends.move @@ -1,6 +1,5 @@ module 0x2::A { - friend 0x2::B; - public(friend) fun foo() {} + public(package) fun foo() {} } module 0x2::B { diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/Move.toml index 387bb7c90102f..5cd377a29dca2 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/Move.toml @@ -1,5 +1,6 @@ [package] name = "use_named_address" +edition = "2024.beta" [addresses] a = "0x42" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/dep/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/dep/Move.toml index 0c63f88d75992..c13bafbb000c8 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/dep/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/dep/Move.toml @@ -1,5 +1,6 @@ [package] name = "Dep" +edition = "2024.beta" [addresses] a = "0x41" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/dep/sources/m.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/dep/sources/m.move index 51a295bafbfbf..276a1997bf484 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/dep/sources/m.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/named_address_conflicts_in_error/dep/sources/m.move @@ -1,6 +1,6 @@ module a::m { - struct X {} - struct Y {} + public struct X {} + public struct Y {} public fun x(): X { X {} } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/Move.toml index cba2b427b2f55..e1714b99487c0 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/Move.toml @@ -1,5 +1,6 @@ [package] name = "PackageBasics" +edition = "2024.beta" [addresses] std = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/args.exp b/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/args.exp index a46298ad88699..f036924fe828f 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/args.exp +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/args.exp @@ -77,20 +77,17 @@ Constants [ 0 => u64: 0 ] } -Command `disassemble --package MoveStdlib --name signer`: +Command `disassemble --package MoveStdlib --name address`: // Move bytecode v6 -module 1.signer { +module 1.address { -native public borrow_address(s#0#0: &signer): &address -public address_of(s#0#0: &signer): address { +public length(): u64 { B0: - 0: MoveLoc[0](s#0#0: &signer) - 1: Call borrow_address(&signer): &address - 2: ReadRef - 3: Ret + 0: LdU64(32) + 1: Ret } } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/args.txt b/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/args.txt index a80887c977c7f..803155024e873 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/args.txt +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/package_basics/args.txt @@ -3,7 +3,7 @@ test --coverage --threads 1 coverage summary --summarize-functions coverage source --module AModule coverage bytecode --module AModule -disassemble --package MoveStdlib --name signer +disassemble --package MoveStdlib --name address info test double_two test one_one diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/Move.toml index 446c3c961dab2..fcc74b457f32b 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/Move.toml @@ -1,8 +1,9 @@ [package] name = "print_stack_trace" +edition = "2024.beta" [addresses] std = "0x1" [dependencies] -MoveNursery = { local = "../../../../move-stdlib/nursery" } +MoveStdlib = { local = "../../../../move-stdlib" } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/M.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/M.move index 3cc1425e225a1..978efd65b36a7 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/M.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/M.move @@ -1,5 +1,4 @@ -address 0x2 { -module M { +module 0x2::M { use std::debug; public fun sum(n: u64): u64 { @@ -11,4 +10,3 @@ module M { } } } -} diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/N.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/N.move index 24f61a218d635..08e2467602b16 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/N.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/N.move @@ -1,14 +1,12 @@ -address 0x2 { #[allow(unused_type_parameter, unused_mut_ref)] -module N { +module 0x2::N { use 0x2::M; public fun foo(): u64 { - let x = 3; + let mut x = 3; let y = &mut x; let z = M::sum(4); _ = y; z } } -} diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/print_stack_trace.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/print_stack_trace.move index 6cc01bb23aa7c..cda19d634c1e7 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/print_stack_trace.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_stack_trace/sources/print_stack_trace.move @@ -1,11 +1,10 @@ module 0x42::print_stack_trace { use std::debug; - use std::vector; use 0x2::N; #[allow(unused_mut_ref)] entry fun print_stack_trace() { - let v = vector::empty(); + let mut v = vector::empty(); vector::push_back(&mut v, true); vector::push_back(&mut v, false); let r = vector::borrow(&mut v, 1); diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/Move.toml index 1f13306640b9f..32e1a378ac3a8 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/Move.toml @@ -1,8 +1,9 @@ [package] name = "print_values" +edition = "2024.beta" [addresses] std = "0x1" [dependencies] -MoveNursery = { local = "../../../../move-stdlib/nursery" } +MoveStdlib = { local = "../../../../move-stdlib" } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/args.exp b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/args.exp index c6d94de4f98f7..327546f02d9de 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/args.exp +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/args.exp @@ -1,6 +1,5 @@ Command `sandbox publish`: Command `test`: -INCLUDING DEPENDENCY MoveNursery INCLUDING DEPENDENCY MoveStdlib BUILDING print_values Running Move unit tests @@ -38,7 +37,6 @@ Running Move unit tests [debug] false [debug] true [debug] @0x1234c0ffee -[debug] signer(0x0) [debug] "test_print_struct" [debug] 0x2::M::TestInner { val: 100, @@ -62,7 +60,6 @@ Running Move unit tests [debug] [ 256, 257, 258, 259 ] [debug] [ true, false ] [debug] [ @0x1234, @0x5678, @0xabcdef ] -[debug] [ signer(0x0), signer(0x100000000000000000000000000000000000000000000000000000000000000), signer(0x200000000000000000000000000000000000000000000000000000000000000), signer(0x300000000000000000000000000000000000000000000000000000000000000) ] [debug] [ 0x2::M::TestInner { val: 4, @@ -113,10 +110,6 @@ Running Move unit tests [ @0x1234, @0x5678 ], [ @0xabcdef, @0x9999 ] ] -[debug] [ - [ signer(0x0), signer(0x100000000000000000000000000000000000000000000000000000000000000) ], - [ signer(0x0), signer(0x100000000000000000000000000000000000000000000000000000000000000) ] -] [debug] [ [ 0x2::M::TestInner { diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/sources/M.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/sources/M.move index e4c8ba1f3b1c2..cb661dfb65ad2 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/sources/M.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/print_values/sources/M.move @@ -1,33 +1,26 @@ -address 0x2 { #[allow(unused_field)] -module M { +module 0x2::M { #[test_only] use std::ascii; #[test_only] use std::debug::print; - #[test_only] - use std::debug::print_string; use std::string; - #[test_only] - use std::unit_test::create_signers_for_testing; - #[test_only] - use std::vector; - struct Foo has drop {} - struct Bar has drop { x: u128, y: Foo, z: bool } - struct Box has drop { x: T } + public struct Foo has drop {} + public struct Bar has drop { x: u128, y: Foo, z: bool } + public struct Box has drop { x: T } - struct GenericStruct has drop { + public struct GenericStruct has drop { val: u64, } - struct TestInner has drop { + public struct TestInner has drop { val: u128, vec: vector, msgs: vector> } - struct TestStruct has drop { + public struct TestStruct has drop { addr: address, number: u8, bytes: vector, @@ -40,7 +33,7 @@ module M { let x = 42; print(&x); - let v = vector::empty(); + let mut v = vector::empty(); vector::push_back(&mut v, 100); vector::push_back(&mut v, 200); vector::push_back(&mut v, 300); @@ -124,11 +117,6 @@ module M { let a = @0x1234c0ffee; print(&a); - - // print a signer - let senders = create_signers_for_testing(1); - let sender = vector::pop_back(&mut senders); - print(&sender); } #[allow(unused_const)] @@ -185,9 +173,6 @@ module M { let v_addr = vector[@0x1234, @0x5678, @0xabcdef]; print(&v_addr); - let v_signer = create_signers_for_testing(4); - print(&v_signer); - let v = vector[ TestInner { val: 4u128, @@ -231,9 +216,6 @@ module M { let v_addr = vector[vector[@0x1234, @0x5678], vector[@0xabcdef, @0x9999]]; print(&v_addr); - let v_signer = vector[create_signers_for_testing(2), create_signers_for_testing(2)]; - print(&v_signer); - let v = vector[ vector[ TestInner { val: 4u128, vec: vector[127u128, 128u128], msgs: vector[] }, @@ -275,5 +257,9 @@ module M { print(&obj); } -} + + #[test_only] + public fun print_string(utf8_bytes: vector) { + print(&string::utf8(utf8_bytes)); + } } diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/publish_then_run/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/publish_then_run/Move.toml index e6ea5df3aeac9..2c09426b415c0 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/publish_then_run/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/publish_then_run/Move.toml @@ -1,2 +1,3 @@ [package] name = "publish_then_run" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/publish_then_run/sources/M.move b/external-crates/move/crates/move-cli/tests/sandbox_tests/publish_then_run/sources/M.move index f25c55efc332b..7dd1a97c43805 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/publish_then_run/sources/M.move +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/publish_then_run/sources/M.move @@ -1,5 +1,3 @@ -address 0x2 { -module M { +module 0x2::M { public entry fun f() {} } -} diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/random_test_flag_correctness/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/random_test_flag_correctness/Move.toml index c88176fe599b1..ec5322a2c6e18 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/random_test_flag_correctness/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/random_test_flag_correctness/Move.toml @@ -1,5 +1,6 @@ [package] name = "random_test_flag_correctness" +edition = "2024.beta" [addresses] std = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/use_named_address/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/use_named_address/Move.toml index cbec350b0c2ea..076d820a22706 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/use_named_address/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/use_named_address/Move.toml @@ -1,5 +1,6 @@ [package] name = "use_named_address" +edition = "2024.beta" [addresses] A = "0x42" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/verify_native_functions_in_multi_module_publish/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/verify_native_functions_in_multi_module_publish/Move.toml index e162affa0e604..939bd5cabd656 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/verify_native_functions_in_multi_module_publish/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/verify_native_functions_in_multi_module_publish/Move.toml @@ -1,2 +1,3 @@ [package] name = "verify_native_functions_in_publish" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/sandbox_tests/verify_native_functions_in_publish/Move.toml b/external-crates/move/crates/move-cli/tests/sandbox_tests/verify_native_functions_in_publish/Move.toml index e162affa0e604..939bd5cabd656 100644 --- a/external-crates/move/crates/move-cli/tests/sandbox_tests/verify_native_functions_in_publish/Move.toml +++ b/external-crates/move/crates/move-cli/tests/sandbox_tests/verify_native_functions_in_publish/Move.toml @@ -1,2 +1,3 @@ [package] name = "verify_native_functions_in_publish" +edition = "2024.beta" diff --git a/external-crates/move/crates/move-cli/tests/upload_tests/no_git_remote_package/Move.toml b/external-crates/move/crates/move-cli/tests/upload_tests/no_git_remote_package/Move.toml index 56dceb553f5b5..8d8563b904bcf 100644 --- a/external-crates/move/crates/move-cli/tests/upload_tests/no_git_remote_package/Move.toml +++ b/external-crates/move/crates/move-cli/tests/upload_tests/no_git_remote_package/Move.toml @@ -1,5 +1,6 @@ [package] name = "Package1" +edition = "2024.beta" [addresses] Std = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/upload_tests/valid_package1/Move.toml b/external-crates/move/crates/move-cli/tests/upload_tests/valid_package1/Move.toml index 56dceb553f5b5..8d8563b904bcf 100644 --- a/external-crates/move/crates/move-cli/tests/upload_tests/valid_package1/Move.toml +++ b/external-crates/move/crates/move-cli/tests/upload_tests/valid_package1/Move.toml @@ -1,5 +1,6 @@ [package] name = "Package1" +edition = "2024.beta" [addresses] Std = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/upload_tests/valid_package2/Move.toml b/external-crates/move/crates/move-cli/tests/upload_tests/valid_package2/Move.toml index 56dceb553f5b5..8d8563b904bcf 100644 --- a/external-crates/move/crates/move-cli/tests/upload_tests/valid_package2/Move.toml +++ b/external-crates/move/crates/move-cli/tests/upload_tests/valid_package2/Move.toml @@ -1,5 +1,6 @@ [package] name = "Package1" +edition = "2024.beta" [addresses] Std = "0x1" diff --git a/external-crates/move/crates/move-cli/tests/upload_tests/valid_package3/Move.toml b/external-crates/move/crates/move-cli/tests/upload_tests/valid_package3/Move.toml index 56dceb553f5b5..8d8563b904bcf 100644 --- a/external-crates/move/crates/move-cli/tests/upload_tests/valid_package3/Move.toml +++ b/external-crates/move/crates/move-cli/tests/upload_tests/valid_package3/Move.toml @@ -1,5 +1,6 @@ [package] name = "Package1" +edition = "2024.beta" [addresses] Std = "0x1" diff --git a/external-crates/move/crates/move-compiler/src/editions/mod.rs b/external-crates/move/crates/move-compiler/src/editions/mod.rs index 7793a573480e9..5cfea4d99d59d 100644 --- a/external-crates/move/crates/move-compiler/src/editions/mod.rs +++ b/external-crates/move/crates/move-compiler/src/editions/mod.rs @@ -397,6 +397,6 @@ impl Serialize for Flavor { impl Default for Edition { fn default() -> Self { - Edition::LEGACY + Edition::E2024_BETA } } diff --git a/external-crates/move/crates/move-compiler/tests/move_2024/typing/dot_call_non_struct.exp b/external-crates/move/crates/move-compiler/tests/move_2024/typing/dot_call_non_struct.exp index 494f2b8aa3740..72686085d4c6e 100644 --- a/external-crates/move/crates/move-compiler/tests/move_2024/typing/dot_call_non_struct.exp +++ b/external-crates/move/crates/move-compiler/tests/move_2024/typing/dot_call_non_struct.exp @@ -25,7 +25,7 @@ error[E04023]: invalid method call 10 │ 0u64.f(); │ ^^^^^^^^ │ │ │ - │ │ No local 'use fun' alias was found for 'u64.f' + │ │ No local 'use fun' alias was found for 'u64.f', and no function 'f' was found in the defining module 'std::u64' │ Invalid method call. No known method 'f' on type 'u64' error[E04023]: invalid method call diff --git a/external-crates/move/crates/move-compiler/tests/move_2024/typing/duplicate_defines_primitive.exp b/external-crates/move/crates/move-compiler/tests/move_2024/typing/duplicate_defines_primitive.exp index 2a0680e60c94a..8d45aad08e11a 100644 --- a/external-crates/move/crates/move-compiler/tests/move_2024/typing/duplicate_defines_primitive.exp +++ b/external-crates/move/crates/move-compiler/tests/move_2024/typing/duplicate_defines_primitive.exp @@ -4,6 +4,6 @@ error[E10004]: invalid usage of known attribute 2 │ module a::m {} │ - Previously declared here 3 │ -4 │ #[defines_primitive(u64)] - │ ^^^^^^^^^^^^^^^^^^^^^^ Duplicate definer annotated for primitive type 'u64' +4 │ #[defines_primitive(signer)] + │ ^^^^^^^^^^^^^^^^^^^^^^^^^ Duplicate definer annotated for primitive type 'signer' diff --git a/external-crates/move/crates/move-compiler/tests/move_2024/typing/duplicate_defines_primitive.move b/external-crates/move/crates/move-compiler/tests/move_2024/typing/duplicate_defines_primitive.move index f2f7f25da2bd9..565d0fdeae2e4 100644 --- a/external-crates/move/crates/move-compiler/tests/move_2024/typing/duplicate_defines_primitive.move +++ b/external-crates/move/crates/move-compiler/tests/move_2024/typing/duplicate_defines_primitive.move @@ -1,5 +1,5 @@ -#[defines_primitive(u64)] +#[defines_primitive(signer)] module a::m {} -#[defines_primitive(u64)] +#[defines_primitive(signer)] module a::n {} diff --git a/external-crates/move/crates/move-compiler/tests/move_check_testsuite.rs b/external-crates/move/crates/move-compiler/tests/move_check_testsuite.rs index 1296da8588f72..104ea80dd79f8 100644 --- a/external-crates/move/crates/move-compiler/tests/move_check_testsuite.rs +++ b/external-crates/move/crates/move-compiler/tests/move_check_testsuite.rs @@ -64,7 +64,7 @@ fn move_check_testsuite(path: &Path) -> datatest_stable::Result<()> { } else if path_contains(DEV_DIR) { Edition::DEVELOPMENT } else { - Edition::default() + Edition::LEGACY }; let config = PackageConfig { flavor, diff --git a/external-crates/move/crates/move-docgen/tests/sources/different_visbilities.move b/external-crates/move/crates/move-docgen/tests/sources/different_visbilities.move index 3d1aaad29ed34..0bb17bf6ad845 100644 --- a/external-crates/move/crates/move-docgen/tests/sources/different_visbilities.move +++ b/external-crates/move/crates/move-docgen/tests/sources/different_visbilities.move @@ -1,5 +1,4 @@ -address 0x2 { -module TestViz { +module 0x2::TestViz { /// This is a public function public fun this_is_a_public_fun() { } @@ -13,4 +12,3 @@ module TestViz { /// This is a private function fun this_is_a_private_fun() {} } -} diff --git a/external-crates/move/crates/move-docgen/tests/sources/root_template_AnotherTypeOfScript.notest_move b/external-crates/move/crates/move-docgen/tests/sources/root_template_AnotherTypeOfScript.notest_move index eb7dbd3b1d754..aeeb87e9a1268 100644 --- a/external-crates/move/crates/move-docgen/tests/sources/root_template_AnotherTypeOfScript.notest_move +++ b/external-crates/move/crates/move-docgen/tests/sources/root_template_AnotherTypeOfScript.notest_move @@ -1,5 +1,4 @@ -address 0x1 { -module AnotherTypeOfScript { +module 0x1::AnotherTypeOfScript { /// This is a script entry fun script3() {} @@ -7,4 +6,3 @@ module AnotherTypeOfScript { /// This is another script entry fun script4() {} } -} diff --git a/external-crates/move/crates/move-docgen/tests/sources/root_template_OneTypeOfScript.notest_move b/external-crates/move/crates/move-docgen/tests/sources/root_template_OneTypeOfScript.notest_move index e793028b23b20..2de14cdce79fd 100644 --- a/external-crates/move/crates/move-docgen/tests/sources/root_template_OneTypeOfScript.notest_move +++ b/external-crates/move/crates/move-docgen/tests/sources/root_template_OneTypeOfScript.notest_move @@ -1,5 +1,4 @@ -address 0x1 { -module OneTypeOfScript { +module 0x1::OneTypeOfScript { /// This is a script entry fun script1() {} @@ -7,4 +6,3 @@ module OneTypeOfScript { /// This is another script entry fun script2() {} } -} diff --git a/external-crates/move/crates/move-package/src/resolution/resolution_graph.rs b/external-crates/move/crates/move-package/src/resolution/resolution_graph.rs index 8b8e45ca8a0ec..603d4c07f7493 100644 --- a/external-crates/move/crates/move-package/src/resolution/resolution_graph.rs +++ b/external-crates/move/crates/move-package/src/resolution/resolution_graph.rs @@ -7,6 +7,7 @@ use move_command_line_common::files::{ extension_equals, find_filenames, find_move_filenames, FileHash, MOVE_COMPILED_EXTENSION, }; use move_compiler::command_line::DEFAULT_OUTPUT_DIR; +use move_compiler::editions::Edition; use move_compiler::{diagnostics::WarningFilters, shared::PackageConfig}; use move_core_types::account_address::AccountAddress; use move_symbol_pool::Symbol; @@ -574,7 +575,7 @@ impl Package { .package .edition .or(config.default_edition) - .unwrap_or_default(), + .unwrap_or(Edition::LEGACY), // TODO require edition warning_filter: WarningFilters::new_for_source(), } } diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/basic_test.move b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/basic_test.move index 49592ecd81250..f4c8062d09456 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/basic_test.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/basic_test.move @@ -1,10 +1,10 @@ module 0x42::TestBorrow { - struct R has copy, drop { + public struct R has copy, drop { x: u64 } fun test1() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; let x_ref = &mut r_ref.x; *x_ref = 0; @@ -21,7 +21,7 @@ module 0x42::TestBorrow { } fun test4() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; test3(r_ref, 0); r @@ -32,7 +32,7 @@ module 0x42::TestBorrow { } fun test6() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; let x_ref = test5(r_ref); test2(x_ref, 0); @@ -40,19 +40,19 @@ module 0x42::TestBorrow { } fun test7(b: bool) { - let r1 = R {x: 3}; - let r2 = R {x: 4}; - let r_ref = &mut r1; + let mut r1 = R {x: 3}; + let mut r2 = R {x: 4}; + let mut r_ref = &mut r1; if (b) { r_ref = &mut r2; }; test3(r_ref, 0) } - fun test8(b: bool, n: u64, r_ref: &mut R) { - let r1 = R {x: 3}; - let r2 = R {x: 4}; - let t_ref = &mut r2; + fun test8(b: bool, mut n: u64, r_ref: &mut R) { + let mut r1 = R {x: 3}; + let mut r2 = R {x: 4}; + let mut t_ref = &mut r2; while (0 < n) { if (n/2 == 0) { t_ref = &mut r1 diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/function_call.exp b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/function_call.exp index 30226bd8972fb..0559d22411800 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/function_call.exp +++ b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/function_call.exp @@ -1,5 +1,339 @@ ============ initial translation from Move ================ +[variant baseline] +public fun u64::diff($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := >($t7, $t8) + 7: if ($t9) goto 8 else goto 14 + 8: label L1 + 9: $t10 := move($t3) + 10: $t11 := move($t4) + 11: $t12 := -($t10, $t11) + 12: $t2 := $t12 + 13: goto 20 + 14: label L0 + 15: $t13 := move($t4) + 16: $t14 := move($t3) + 17: $t15 := -($t13, $t14) + 18: $t2 := $t15 + 19: goto 20 + 20: label L2 + 21: $t16 := move($t2) + 22: return $t16 +} + + +[variant baseline] +public fun u64::divide_and_round_up($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: u64 + var $t10: u64 + var $t11: bool + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := %($t7, $t8) + 7: $t10 := 0 + 8: $t11 := ==($t9, $t10) + 9: if ($t11) goto 10 else goto 16 + 10: label L1 + 11: $t12 := move($t3) + 12: $t13 := move($t4) + 13: $t14 := /($t12, $t13) + 14: $t2 := $t14 + 15: goto 24 + 16: label L0 + 17: $t15 := move($t3) + 18: $t16 := move($t4) + 19: $t17 := /($t15, $t16) + 20: $t18 := 1 + 21: $t19 := +($t17, $t18) + 22: $t2 := $t19 + 23: goto 24 + 24: label L2 + 25: $t20 := move($t2) + 26: return $t20 +} + + +[variant baseline] +public fun u64::max($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := >($t7, $t8) + 7: if ($t9) goto 8 else goto 12 + 8: label L1 + 9: $t10 := move($t3) + 10: $t2 := $t10 + 11: goto 16 + 12: label L0 + 13: $t11 := move($t4) + 14: $t2 := $t11 + 15: goto 16 + 16: label L2 + 17: $t12 := move($t2) + 18: return $t12 +} + + +[variant baseline] +public fun u64::min($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := <($t7, $t8) + 7: if ($t9) goto 8 else goto 12 + 8: label L1 + 9: $t10 := move($t3) + 10: $t2 := $t10 + 11: goto 16 + 12: label L0 + 13: $t11 := move($t4) + 14: $t2 := $t11 + 15: goto 16 + 16: label L2 + 17: $t12 := move($t2) + 18: return $t12 +} + + +[variant baseline] +public fun u64::pow($t0|base: u64, $t1|exponent: u8): u64 { + var $t2|base#1#1: u64 + var $t3|exponent#1#1: u8 + var $t4|res#1#1: u64 + var $t5: u64 + var $t6: u8 + var $t7: u64 + var $t8: u8 + var $t9: u8 + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: bool + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u8 + var $t20: u8 + var $t21: u8 + var $t22: u64 + var $t23: u64 + var $t24: u64 + var $t25: u8 + var $t26: u8 + var $t27: u8 + var $t28: u64 + 0: $t5 := move($t0) + 1: $t2 := $t5 + 2: $t6 := move($t1) + 3: $t3 := $t6 + 4: $t7 := 1 + 5: $t4 := $t7 + 6: goto 7 + 7: label L5 + 8: $t8 := copy($t3) + 9: $t9 := 1 + 10: $t10 := >=($t8, $t9) + 11: if ($t10) goto 12 else goto 41 + 12: label L1 + 13: goto 14 + 14: label L2 + 15: $t11 := copy($t3) + 16: $t12 := 2 + 17: $t13 := %($t11, $t12) + 18: $t14 := 0 + 19: $t15 := ==($t13, $t14) + 20: if ($t15) goto 21 else goto 31 + 21: label L4 + 22: $t16 := copy($t2) + 23: $t17 := move($t2) + 24: $t18 := *($t16, $t17) + 25: $t2 := $t18 + 26: $t19 := move($t3) + 27: $t20 := 2 + 28: $t21 := /($t19, $t20) + 29: $t3 := $t21 + 30: goto 7 + 31: label L3 + 32: $t22 := move($t4) + 33: $t23 := copy($t2) + 34: $t24 := *($t22, $t23) + 35: $t4 := $t24 + 36: $t25 := move($t3) + 37: $t26 := 1 + 38: $t27 := -($t25, $t26) + 39: $t3 := $t27 + 40: goto 7 + 41: label L0 + 42: $t28 := move($t4) + 43: return $t28 +} + + +[variant baseline] +public fun u64::sqrt($t0|x: u64): u64 { + var $t1|bit#1#1: u128 + var $t2|res#1#1: u128 + var $t3|x#1#1: u64 + var $t4|x#2#1: u128 + var $t5: u64 + var $t6: u128 + var $t7: u128 + var $t8: u64 + var $t9: u128 + var $t10: u128 + var $t11: u128 + var $t12: bool + var $t13: u128 + var $t14: u128 + var $t15: u128 + var $t16: u128 + var $t17: bool + var $t18: u128 + var $t19: u128 + var $t20: u128 + var $t21: u128 + var $t22: u128 + var $t23: u128 + var $t24: u8 + var $t25: u128 + var $t26: u128 + var $t27: u128 + var $t28: u128 + var $t29: u8 + var $t30: u128 + var $t31: u128 + var $t32: u8 + var $t33: u128 + var $t34: u128 + var $t35: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := 18446744073709551616 + 3: $t1 := $t6 + 4: $t7 := 0 + 5: $t2 := $t7 + 6: $t8 := move($t3) + 7: $t9 := (u128)($t8) + 8: $t4 := $t9 + 9: goto 10 + 10: label L6 + 11: $t10 := copy($t1) + 12: $t11 := 0 + 13: $t12 := !=($t10, $t11) + 14: if ($t12) goto 15 else goto 50 + 15: label L1 + 16: goto 17 + 17: label L2 + 18: $t13 := copy($t4) + 19: $t14 := copy($t2) + 20: $t15 := copy($t1) + 21: $t16 := +($t14, $t15) + 22: $t17 := >=($t13, $t16) + 23: if ($t17) goto 24 else goto 38 + 24: label L4 + 25: $t18 := move($t4) + 26: $t19 := copy($t2) + 27: $t20 := copy($t1) + 28: $t21 := +($t19, $t20) + 29: $t22 := -($t18, $t21) + 30: $t4 := $t22 + 31: $t23 := move($t2) + 32: $t24 := 1 + 33: $t25 := >>($t23, $t24) + 34: $t26 := copy($t1) + 35: $t27 := +($t25, $t26) + 36: $t2 := $t27 + 37: goto 44 + 38: label L3 + 39: $t28 := move($t2) + 40: $t29 := 1 + 41: $t30 := >>($t28, $t29) + 42: $t2 := $t30 + 43: goto 44 + 44: label L5 + 45: $t31 := move($t1) + 46: $t32 := 2 + 47: $t33 := >>($t31, $t32) + 48: $t1 := $t33 + 49: goto 10 + 50: label L0 + 51: $t34 := move($t2) + 52: $t35 := (u64)($t34) + 53: return $t35 +} + + [variant baseline] public fun vector::append<#0>($t0|lhs: &mut vector<#0>, $t1|other: vector<#0>) { var $t2: &mut vector<#0> @@ -231,27 +565,25 @@ public fun vector::insert<#0>($t0|v: &mut vector<#0>, $t1|e: #0, $t2|i: u64) { 15: $t13 := move($t1) 16: vector::push_back<#0>($t12, $t13) 17: goto 18 - 18: label L5 + 18: label L4 19: $t14 := copy($t2) 20: $t15 := copy($t3) 21: $t16 := <($t14, $t15) - 22: if ($t16) goto 23 else goto 35 + 22: if ($t16) goto 23 else goto 33 23: label L3 - 24: goto 25 - 25: label L4 - 26: $t17 := copy($t0) - 27: $t18 := copy($t2) - 28: $t19 := copy($t3) - 29: vector::swap<#0>($t17, $t18, $t19) - 30: $t20 := move($t2) - 31: $t21 := 1 - 32: $t22 := +($t20, $t21) - 33: $t2 := $t22 - 34: goto 18 - 35: label L2 - 36: $t23 := move($t0) - 37: destroy($t23) - 38: return () + 24: $t17 := copy($t0) + 25: $t18 := copy($t2) + 26: $t19 := copy($t3) + 27: vector::swap<#0>($t17, $t18, $t19) + 28: $t20 := move($t2) + 29: $t21 := 1 + 30: $t22 := +($t20, $t21) + 31: $t2 := $t22 + 32: goto 18 + 33: label L2 + 34: $t23 := move($t0) + 35: destroy($t23) + 36: return () } @@ -329,31 +661,29 @@ public fun vector::remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { 16: $t15 := -($t13, $t14) 17: $t4 := $t15 18: goto 19 - 19: label L5 + 19: label L4 20: $t16 := copy($t1) 21: $t17 := copy($t4) 22: $t18 := <($t16, $t17) - 23: if ($t18) goto 24 else goto 40 + 23: if ($t18) goto 24 else goto 38 24: label L3 - 25: goto 26 - 26: label L4 - 27: $t19 := copy($t0) - 28: $t3 := $t19 - 29: $t20 := copy($t1) - 30: $t2 := $t20 - 31: $t21 := move($t1) - 32: $t22 := 1 - 33: $t23 := +($t21, $t22) - 34: $t1 := $t23 - 35: $t24 := move($t3) - 36: $t25 := move($t2) - 37: $t26 := copy($t1) - 38: vector::swap<#0>($t24, $t25, $t26) - 39: goto 19 - 40: label L2 - 41: $t27 := move($t0) - 42: $t28 := vector::pop_back<#0>($t27) - 43: return $t28 + 25: $t19 := copy($t0) + 26: $t3 := $t19 + 27: $t20 := copy($t1) + 28: $t2 := $t20 + 29: $t21 := move($t1) + 30: $t22 := 1 + 31: $t23 := +($t21, $t22) + 32: $t1 := $t23 + 33: $t24 := move($t3) + 34: $t25 := move($t2) + 35: $t26 := copy($t1) + 36: vector::swap<#0>($t24, $t25, $t26) + 37: goto 19 + 38: label L2 + 39: $t27 := move($t0) + 40: $t28 := vector::pop_back<#0>($t27) + 41: return $t28 } @@ -406,31 +736,29 @@ public fun vector::reverse<#0>($t0|v: &mut vector<#0>) { 17: $t14 := -($t12, $t13) 18: $t1 := $t14 19: goto 20 - 20: label L5 + 20: label L4 21: $t15 := copy($t2) 22: $t16 := copy($t1) 23: $t17 := <($t15, $t16) - 24: if ($t17) goto 25 else goto 41 + 24: if ($t17) goto 25 else goto 39 25: label L3 - 26: goto 27 - 27: label L4 - 28: $t18 := copy($t0) - 29: $t19 := copy($t2) - 30: $t20 := copy($t1) - 31: vector::swap<#0>($t18, $t19, $t20) - 32: $t21 := move($t2) - 33: $t22 := 1 - 34: $t23 := +($t21, $t22) - 35: $t2 := $t23 - 36: $t24 := move($t1) - 37: $t25 := 1 - 38: $t26 := -($t24, $t25) - 39: $t1 := $t26 - 40: goto 20 - 41: label L2 - 42: $t27 := move($t0) - 43: destroy($t27) - 44: return () + 26: $t18 := copy($t0) + 27: $t19 := copy($t2) + 28: $t20 := copy($t1) + 29: vector::swap<#0>($t18, $t19, $t20) + 30: $t21 := move($t2) + 31: $t22 := 1 + 32: $t23 := +($t21, $t22) + 33: $t2 := $t23 + 34: $t24 := move($t1) + 35: $t25 := 1 + 36: $t26 := -($t24, $t25) + 37: $t1 := $t26 + 38: goto 20 + 39: label L2 + 40: $t27 := move($t0) + 41: destroy($t27) + 42: return () } @@ -504,364 +832,3550 @@ public fun vector::swap_remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { [variant baseline] -fun MultiLayerCalling::inner($t0|has_vector: &mut MultiLayerCalling::HasVector): &mut MultiLayerCalling::HasAnotherVector { - var $t1: &mut MultiLayerCalling::HasVector - var $t2: &mut vector - var $t3: u64 - var $t4: &mut MultiLayerCalling::HasAnotherVector - 0: $t1 := move($t0) - 1: $t2 := borrow_field.v($t1) - 2: $t3 := 7 - 3: $t4 := vector::borrow_mut($t2, $t3) - 4: return $t4 +public fun option::borrow<#0>($t0|t: &option::Option<#0>): � { + var $t1: &option::Option<#0> + var $t2: bool + var $t3: &option::Option<#0> + var $t4: u64 + var $t5: &option::Option<#0> + var $t6: &vector<#0> + var $t7: u64 + var $t8: � + 0: $t1 := copy($t0) + 1: $t2 := option::is_some<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 10 + 5: label L0 + 6: $t3 := move($t0) + 7: destroy($t3) + 8: $t4 := 262145 + 9: abort($t4) + 10: label L2 + 11: $t5 := move($t0) + 12: $t6 := borrow_field>.vec($t5) + 13: $t7 := 0 + 14: $t8 := vector::borrow<#0>($t6, $t7) + 15: return $t8 } [variant baseline] -fun MultiLayerCalling::mid($t0|has_vector: &mut MultiLayerCalling::HasVector): &mut MultiLayerCalling::HasAnotherVector { - var $t1: &mut MultiLayerCalling::HasVector - var $t2: &mut MultiLayerCalling::HasAnotherVector - 0: $t1 := move($t0) - 1: $t2 := MultiLayerCalling::inner($t1) - 2: return $t2 +public fun option::borrow_mut<#0>($t0|t: &mut option::Option<#0>): &mut #0 { + var $t1: &mut option::Option<#0> + var $t2: &option::Option<#0> + var $t3: bool + var $t4: &mut option::Option<#0> + var $t5: u64 + var $t6: &mut option::Option<#0> + var $t7: &mut vector<#0> + var $t8: u64 + var $t9: &mut #0 + 0: $t1 := copy($t0) + 1: $t2 := freeze_ref($t1) + 2: $t3 := option::is_some<#0>($t2) + 3: if ($t3) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t4 := move($t0) + 8: destroy($t4) + 9: $t5 := 262145 + 10: abort($t5) + 11: label L2 + 12: $t6 := move($t0) + 13: $t7 := borrow_field>.vec($t6) + 14: $t8 := 0 + 15: $t9 := vector::borrow_mut<#0>($t7, $t8) + 16: return $t9 } [variant baseline] -fun MultiLayerCalling::outer($t0|has_vector: &mut MultiLayerCalling::HasVector) { - var $t1: &mut MultiLayerCalling::HasVector - var $t2: &mut MultiLayerCalling::HasAnotherVector - var $t3: &mut vector - var $t4: u8 - 0: $t1 := move($t0) - 1: $t2 := MultiLayerCalling::mid($t1) - 2: $t3 := borrow_field.v($t2) - 3: $t4 := 42 - 4: vector::push_back($t3, $t4) - 5: return () +public fun option::contains<#0>($t0|t: &option::Option<#0>, $t1|e_ref: �): bool { + var $t2: &option::Option<#0> + var $t3: &vector<#0> + var $t4: � + var $t5: bool + 0: $t2 := move($t0) + 1: $t3 := borrow_field>.vec($t2) + 2: $t4 := move($t1) + 3: $t5 := vector::contains<#0>($t3, $t4) + 4: return $t5 } -============ after pipeline `borrow` ================ [variant baseline] -public fun vector::append<#0>($t0|lhs: &mut vector<#0>, $t1|other: vector<#0>) { - var $t2: &mut vector<#0> - var $t3: vector<#0> - var $t4: bool - var $t5: bool - var $t6: &mut vector<#0> - var $t7: #0 - var $t8: vector<#0> - 0: $t2 := borrow_local($t1) - 1: vector::reverse<#0>($t2) - 2: label L3 - 3: $t3 := copy($t1) - 4: $t4 := vector::is_empty<#0>($t3) - 5: $t5 := !($t4) - 6: if ($t5) goto 7 else goto 13 - 7: label L1 - 8: label L2 - 9: $t6 := borrow_local($t1) - 10: $t7 := vector::pop_back<#0>($t6) - 11: vector::push_back<#0>($t0, $t7) - 12: goto 2 - 13: label L0 - 14: destroy($t0) - 15: $t8 := move($t1) - 16: vector::destroy_empty<#0>($t8) - 17: trace_local[lhs]($t0) - 18: return () +public fun option::swap<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): #0 { + var $t2|old_value#1#0: #0 + var $t3|vec_ref#1#0: &mut vector<#0> + var $t4: &mut option::Option<#0> + var $t5: &option::Option<#0> + var $t6: bool + var $t7: &mut option::Option<#0> + var $t8: u64 + var $t9: &mut option::Option<#0> + var $t10: &mut vector<#0> + var $t11: &mut vector<#0> + var $t12: #0 + var $t13: &mut vector<#0> + var $t14: #0 + var $t15: #0 + 0: $t4 := copy($t0) + 1: $t5 := freeze_ref($t4) + 2: $t6 := option::is_some<#0>($t5) + 3: if ($t6) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t7 := move($t0) + 8: destroy($t7) + 9: $t8 := 262145 + 10: abort($t8) + 11: label L2 + 12: $t9 := move($t0) + 13: $t10 := borrow_field>.vec($t9) + 14: $t3 := $t10 + 15: $t11 := copy($t3) + 16: $t12 := vector::pop_back<#0>($t11) + 17: $t2 := $t12 + 18: $t13 := move($t3) + 19: $t14 := move($t1) + 20: vector::push_back<#0>($t13, $t14) + 21: $t15 := move($t2) + 22: return $t15 } [variant baseline] -public native fun vector::borrow<#0>($t0|v: vector<#0>, $t1|i: u64): #0; +public fun option::borrow_with_default<#0>($t0|t: &option::Option<#0>, $t1|default_ref: �): � { + var $t2|tmp#$2: � + var $t3|vec_ref#1#0: &vector<#0> + var $t4: &option::Option<#0> + var $t5: &vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &vector<#0> + var $t9: � + var $t10: � + var $t11: &vector<#0> + var $t12: u64 + var $t13: � + var $t14: � + 0: $t4 := move($t0) + 1: $t5 := borrow_field>.vec($t4) + 2: $t3 := $t5 + 3: $t6 := copy($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 12 + 6: label L1 + 7: $t8 := move($t3) + 8: destroy($t8) + 9: $t9 := move($t1) + 10: $t2 := $t9 + 11: goto 20 + 12: label L0 + 13: $t10 := move($t1) + 14: destroy($t10) + 15: $t11 := move($t3) + 16: $t12 := 0 + 17: $t13 := vector::borrow<#0>($t11, $t12) + 18: $t2 := $t13 + 19: goto 20 + 20: label L2 + 21: $t14 := move($t2) + 22: return $t14 +} [variant baseline] -public native fun vector::borrow_mut<#0>($t0|v: &mut vector<#0>, $t1|i: u64): &mut #0; +public fun option::destroy_none<#0>($t0|t: option::Option<#0>) { + var $t1: &option::Option<#0> + var $t2: bool + var $t3: u64 + var $t4: option::Option<#0> + var $t5: vector<#0> + 0: $t1 := borrow_local($t0) + 1: $t2 := option::is_none<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 262144 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := unpack option::Option<#0>($t4) + 11: vector::destroy_empty<#0>($t5) + 12: return () +} [variant baseline] -public fun vector::contains<#0>($t0|v: vector<#0>, $t1|e: #0): bool { - var $t2|i#1#0: u64 - var $t3|len#1#0: u64 - var $t4: u64 +public fun option::destroy_some<#0>($t0|t: option::Option<#0>): #0 { + var $t1|elem#1#0: #0 + var $t2|vec#1#0: vector<#0> + var $t3: &option::Option<#0> + var $t4: bool var $t5: u64 - var $t6: bool - var $t7: #0 - var $t8: bool - var $t9: bool - var $t10: u64 - var $t11: bool - 0: $t4 := 0 - 1: $t2 := $t4 - 2: $t5 := vector::length<#0>($t0) - 3: label L5 - 4: $t6 := <($t2, $t5) - 5: if ($t6) goto 6 else goto 18 - 6: label L1 - 7: label L2 - 8: $t7 := vector::borrow<#0>($t0, $t2) - 9: $t8 := ==($t7, $t1) - 10: if ($t8) goto 11 else goto 14 - 11: label L4 - 12: $t9 := true - 13: return $t9 - 14: label L3 - 15: $t10 := 1 - 16: $t2 := +($t2, $t10) - 17: goto 3 - 18: label L0 - 19: $t11 := false - 20: return $t11 + var $t6: option::Option<#0> + var $t7: vector<#0> + var $t8: &mut vector<#0> + var $t9: #0 + var $t10: vector<#0> + var $t11: #0 + 0: $t3 := borrow_local($t0) + 1: $t4 := option::is_some<#0>($t3) + 2: if ($t4) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t5 := 262145 + 7: abort($t5) + 8: label L2 + 9: $t6 := move($t0) + 10: $t7 := unpack option::Option<#0>($t6) + 11: $t2 := $t7 + 12: $t8 := borrow_local($t2) + 13: $t9 := vector::pop_back<#0>($t8) + 14: $t1 := $t9 + 15: $t10 := move($t2) + 16: vector::destroy_empty<#0>($t10) + 17: $t11 := move($t1) + 18: return $t11 } [variant baseline] -public native fun vector::destroy_empty<#0>($t0|v: vector<#0>); +public fun option::destroy_with_default<#0>($t0|t: option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec#1#0: vector<#0> + var $t4: option::Option<#0> + var $t5: vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: #0 + var $t9: &mut vector<#0> + var $t10: #0 + var $t11: #0 + 0: $t4 := move($t0) + 1: $t5 := unpack option::Option<#0>($t4) + 2: $t3 := $t5 + 3: $t6 := borrow_local($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 10 + 6: label L1 + 7: $t8 := move($t1) + 8: $t2 := $t8 + 9: goto 15 + 10: label L0 + 11: $t9 := borrow_local($t3) + 12: $t10 := vector::pop_back<#0>($t9) + 13: $t2 := $t10 + 14: goto 15 + 15: label L2 + 16: $t11 := move($t2) + 17: return $t11 +} [variant baseline] -public native fun vector::empty<#0>(): vector<#0>; - +public fun option::extract<#0>($t0|t: &mut option::Option<#0>): #0 { + var $t1: &mut option::Option<#0> + var $t2: &option::Option<#0> + var $t3: bool + var $t4: &mut option::Option<#0> + var $t5: u64 + var $t6: &mut option::Option<#0> + var $t7: &mut vector<#0> + var $t8: #0 + 0: $t1 := copy($t0) + 1: $t2 := freeze_ref($t1) + 2: $t3 := option::is_some<#0>($t2) + 3: if ($t3) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t4 := move($t0) + 8: destroy($t4) + 9: $t5 := 262145 + 10: abort($t5) + 11: label L2 + 12: $t6 := move($t0) + 13: $t7 := borrow_field>.vec($t6) + 14: $t8 := vector::pop_back<#0>($t7) + 15: return $t8 +} + + +[variant baseline] +public fun option::fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0) { + var $t2|vec_ref#1#0: &mut vector<#0> + var $t3: &mut option::Option<#0> + var $t4: &mut vector<#0> + var $t5: &mut vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &mut vector<#0> + var $t9: u64 + var $t10: &mut vector<#0> + var $t11: #0 + 0: $t3 := move($t0) + 1: $t4 := borrow_field>.vec($t3) + 2: $t2 := $t4 + 3: $t5 := copy($t2) + 4: $t6 := freeze_ref($t5) + 5: $t7 := vector::is_empty<#0>($t6) + 6: if ($t7) goto 7 else goto 9 + 7: label L1 + 8: goto 14 + 9: label L0 + 10: $t8 := move($t2) + 11: destroy($t8) + 12: $t9 := 262144 + 13: abort($t9) + 14: label L2 + 15: $t10 := move($t2) + 16: $t11 := move($t1) + 17: vector::push_back<#0>($t10, $t11) + 18: return () +} + + +[variant baseline] +public fun option::get_with_default<#0>($t0|t: &option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec_ref#1#0: &vector<#0> + var $t4: &option::Option<#0> + var $t5: &vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &vector<#0> + var $t9: #0 + var $t10: &vector<#0> + var $t11: u64 + var $t12: � + var $t13: #0 + var $t14: #0 + 0: $t4 := move($t0) + 1: $t5 := borrow_field>.vec($t4) + 2: $t3 := $t5 + 3: $t6 := copy($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 12 + 6: label L1 + 7: $t8 := move($t3) + 8: destroy($t8) + 9: $t9 := move($t1) + 10: $t2 := $t9 + 11: goto 19 + 12: label L0 + 13: $t10 := move($t3) + 14: $t11 := 0 + 15: $t12 := vector::borrow<#0>($t10, $t11) + 16: $t13 := read_ref($t12) + 17: $t2 := $t13 + 18: goto 19 + 19: label L2 + 20: $t14 := move($t2) + 21: return $t14 +} + + +[variant baseline] +public fun option::is_none<#0>($t0|t: &option::Option<#0>): bool { + var $t1: &option::Option<#0> + var $t2: &vector<#0> + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field>.vec($t1) + 2: $t3 := vector::is_empty<#0>($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::is_some<#0>($t0|t: &option::Option<#0>): bool { + var $t1: &option::Option<#0> + var $t2: &vector<#0> + var $t3: bool + var $t4: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field>.vec($t1) + 2: $t3 := vector::is_empty<#0>($t2) + 3: $t4 := !($t3) + 4: return $t4 +} + + +[variant baseline] +public fun option::none<#0>(): option::Option<#0> { + var $t0: vector<#0> + var $t1: option::Option<#0> + 0: $t0 := vector::empty<#0>() + 1: $t1 := pack option::Option<#0>($t0) + 2: return $t1 +} + + +[variant baseline] +public fun option::some<#0>($t0|e: #0): option::Option<#0> { + var $t1: #0 + var $t2: vector<#0> + var $t3: option::Option<#0> + 0: $t1 := move($t0) + 1: $t2 := vector::singleton<#0>($t1) + 2: $t3 := pack option::Option<#0>($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::swap_or_fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): option::Option<#0> { + var $t2|tmp#$2: option::Option<#0> + var $t3|old_value#1#0: option::Option<#0> + var $t4|vec_ref#1#0: &mut vector<#0> + var $t5: &mut option::Option<#0> + var $t6: &mut vector<#0> + var $t7: &mut vector<#0> + var $t8: &vector<#0> + var $t9: bool + var $t10: option::Option<#0> + var $t11: &mut vector<#0> + var $t12: #0 + var $t13: option::Option<#0> + var $t14: option::Option<#0> + var $t15: &mut vector<#0> + var $t16: #0 + var $t17: option::Option<#0> + 0: $t5 := move($t0) + 1: $t6 := borrow_field>.vec($t5) + 2: $t4 := $t6 + 3: $t7 := copy($t4) + 4: $t8 := freeze_ref($t7) + 5: $t9 := vector::is_empty<#0>($t8) + 6: if ($t9) goto 7 else goto 11 + 7: label L1 + 8: $t10 := option::none<#0>() + 9: $t2 := $t10 + 10: goto 17 + 11: label L0 + 12: $t11 := copy($t4) + 13: $t12 := vector::pop_back<#0>($t11) + 14: $t13 := option::some<#0>($t12) + 15: $t2 := $t13 + 16: goto 17 + 17: label L2 + 18: $t14 := move($t2) + 19: $t3 := $t14 + 20: $t15 := move($t4) + 21: $t16 := move($t1) + 22: vector::push_back<#0>($t15, $t16) + 23: $t17 := move($t3) + 24: return $t17 +} + + +[variant baseline] +public fun option::to_vec<#0>($t0|t: option::Option<#0>): vector<#0> { + var $t1: option::Option<#0> + var $t2: vector<#0> + 0: $t1 := move($t0) + 1: $t2 := unpack option::Option<#0>($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::append($t0|string: &mut ascii::String, $t1|other: ascii::String) { + var $t2: &mut ascii::String + var $t3: &mut vector + var $t4: ascii::String + var $t5: vector + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := move($t1) + 3: $t5 := ascii::into_bytes($t4) + 4: vector::append($t3, $t5) + 5: return () +} + + +[variant baseline] +public fun ascii::index_of($t0|string: &ascii::String, $t1|substr: &ascii::String): u64 { + var $t2|tmp#$2: bool + var $t3|i#1#0: u64 + var $t4|j#1#0: u64 + var $t5|m#1#0: u64 + var $t6|n#1#0: u64 + var $t7: u64 + var $t8: &ascii::String + var $t9: u64 + var $t10: &ascii::String + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: bool + var $t15: &ascii::String + var $t16: &ascii::String + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: u64 + var $t22: bool + var $t23: u64 + var $t24: u64 + var $t25: u64 + var $t26: bool + var $t27: &ascii::String + var $t28: &vector + var $t29: u64 + var $t30: u64 + var $t31: u64 + var $t32: &u8 + var $t33: u8 + var $t34: &ascii::String + var $t35: &vector + var $t36: u64 + var $t37: &u8 + var $t38: u8 + var $t39: bool + var $t40: bool + var $t41: bool + var $t42: u64 + var $t43: u64 + var $t44: u64 + var $t45: u64 + var $t46: u64 + var $t47: bool + var $t48: &ascii::String + var $t49: &ascii::String + var $t50: u64 + var $t51: u64 + var $t52: u64 + var $t53: u64 + var $t54: &ascii::String + var $t55: &ascii::String + var $t56: u64 + 0: $t7 := 0 + 1: $t3 := $t7 + 2: $t8 := copy($t0) + 3: $t9 := ascii::length($t8) + 4: $t10 := copy($t1) + 5: $t11 := ascii::length($t10) + 6: $t5 := $t11 + 7: $t6 := $t9 + 8: $t12 := copy($t6) + 9: $t13 := copy($t5) + 10: $t14 := <($t12, $t13) + 11: if ($t14) goto 12 else goto 19 + 12: label L1 + 13: $t15 := move($t1) + 14: destroy($t15) + 15: $t16 := move($t0) + 16: destroy($t16) + 17: $t17 := move($t6) + 18: return $t17 + 19: label L0 + 20: $t18 := copy($t3) + 21: $t19 := copy($t6) + 22: $t20 := copy($t5) + 23: $t21 := -($t19, $t20) + 24: $t22 := <=($t18, $t21) + 25: if ($t22) goto 26 else goto 84 + 26: label L3 + 27: $t23 := 0 + 28: $t4 := $t23 + 29: goto 30 + 30: label L10 + 31: $t24 := copy($t4) + 32: $t25 := copy($t5) + 33: $t26 := <($t24, $t25) + 34: if ($t26) goto 35 else goto 53 + 35: label L5 + 36: goto 37 + 37: label L6 + 38: $t27 := copy($t0) + 39: $t28 := borrow_field.bytes($t27) + 40: $t29 := copy($t3) + 41: $t30 := copy($t4) + 42: $t31 := +($t29, $t30) + 43: $t32 := vector::borrow($t28, $t31) + 44: $t33 := read_ref($t32) + 45: $t34 := copy($t1) + 46: $t35 := borrow_field.bytes($t34) + 47: $t36 := copy($t4) + 48: $t37 := vector::borrow($t35, $t36) + 49: $t38 := read_ref($t37) + 50: $t39 := ==($t33, $t38) + 51: $t2 := $t39 + 52: goto 57 + 53: label L4 + 54: $t40 := false + 55: $t2 := $t40 + 56: goto 57 + 57: label L7 + 58: $t41 := move($t2) + 59: if ($t41) goto 60 else goto 66 + 60: label L9 + 61: $t42 := move($t4) + 62: $t43 := 1 + 63: $t44 := +($t42, $t43) + 64: $t4 := $t44 + 65: goto 30 + 66: label L8 + 67: $t45 := move($t4) + 68: $t46 := copy($t5) + 69: $t47 := ==($t45, $t46) + 70: if ($t47) goto 71 else goto 78 + 71: label L12 + 72: $t48 := move($t1) + 73: destroy($t48) + 74: $t49 := move($t0) + 75: destroy($t49) + 76: $t50 := move($t3) + 77: return $t50 + 78: label L11 + 79: $t51 := move($t3) + 80: $t52 := 1 + 81: $t53 := +($t51, $t52) + 82: $t3 := $t53 + 83: goto 19 + 84: label L2 + 85: $t54 := move($t1) + 86: destroy($t54) + 87: $t55 := move($t0) + 88: destroy($t55) + 89: $t56 := move($t6) + 90: return $t56 +} + + +[variant baseline] +public fun ascii::insert($t0|s: &mut ascii::String, $t1|at: u64, $t2|o: ascii::String) { + var $t3|e#1#2: u8 + var $t4|v#1#1: vector + var $t5: u64 + var $t6: &mut ascii::String + var $t7: &ascii::String + var $t8: u64 + var $t9: bool + var $t10: &mut ascii::String + var $t11: u64 + var $t12: ascii::String + var $t13: vector + var $t14: &vector + var $t15: bool + var $t16: bool + var $t17: &mut vector + var $t18: u8 + var $t19: &mut ascii::String + var $t20: &mut vector + var $t21: u8 + var $t22: u64 + var $t23: &mut ascii::String + var $t24: vector + 0: $t5 := copy($t1) + 1: $t6 := copy($t0) + 2: $t7 := freeze_ref($t6) + 3: $t8 := ascii::length($t7) + 4: $t9 := <=($t5, $t8) + 5: if ($t9) goto 6 else goto 8 + 6: label L1 + 7: goto 13 + 8: label L0 + 9: $t10 := move($t0) + 10: destroy($t10) + 11: $t11 := 65537 + 12: abort($t11) + 13: label L2 + 14: $t12 := move($t2) + 15: $t13 := ascii::into_bytes($t12) + 16: $t4 := $t13 + 17: goto 18 + 18: label L5 + 19: $t14 := borrow_local($t4) + 20: $t15 := vector::is_empty($t14) + 21: $t16 := !($t15) + 22: if ($t16) goto 23 else goto 33 + 23: label L4 + 24: $t17 := borrow_local($t4) + 25: $t18 := vector::pop_back($t17) + 26: $t3 := $t18 + 27: $t19 := copy($t0) + 28: $t20 := borrow_field.bytes($t19) + 29: $t21 := move($t3) + 30: $t22 := copy($t1) + 31: vector::insert($t20, $t21, $t22) + 32: goto 18 + 33: label L3 + 34: $t23 := move($t0) + 35: destroy($t23) + 36: $t24 := move($t4) + 37: vector::destroy_empty($t24) + 38: return () +} + + +[variant baseline] +public fun ascii::is_empty($t0|string: &ascii::String): bool { + var $t1: &ascii::String + var $t2: &vector + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::is_empty($t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::length($t0|string: &ascii::String): u64 { + var $t1: &ascii::String + var $t2: &vector + var $t3: u64 + 0: $t1 := move($t0) + 1: $t2 := ascii::as_bytes($t1) + 2: $t3 := vector::length($t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::all_characters_printable($t0|string: &ascii::String): bool { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|i#1#12: u64 + var $t4|i#1#9: u64 + var $t5|stop#1#9: u64 + var $t6|v#1#3: &vector + var $t7: &ascii::String + var $t8: &vector + var $t9: &vector + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u64 + var $t17: &vector + var $t18: u64 + var $t19: &u8 + var $t20: u8 + var $t21: bool + var $t22: bool + var $t23: &vector + var $t24: bool + var $t25: u64 + var $t26: u64 + var $t27: u64 + var $t28: &vector + var $t29: bool + var $t30: bool + 0: $t7 := move($t0) + 1: $t8 := borrow_field.bytes($t7) + 2: $t6 := $t8 + 3: $t9 := copy($t6) + 4: $t10 := vector::length($t9) + 5: $t1 := $t10 + 6: $t11 := 0 + 7: $t4 := $t11 + 8: $t12 := move($t1) + 9: $t5 := $t12 + 10: goto 11 + 11: label L5 + 12: $t13 := copy($t4) + 13: $t14 := copy($t5) + 14: $t15 := <($t13, $t14) + 15: if ($t15) goto 16 else goto 38 + 16: label L1 + 17: $t16 := copy($t4) + 18: $t3 := $t16 + 19: $t17 := copy($t6) + 20: $t18 := move($t3) + 21: $t19 := vector::borrow($t17, $t18) + 22: $t20 := read_ref($t19) + 23: $t21 := ascii::is_printable_char($t20) + 24: $t22 := !($t21) + 25: if ($t22) goto 26 else goto 32 + 26: label L3 + 27: $t23 := move($t6) + 28: destroy($t23) + 29: $t24 := false + 30: $t2 := $t24 + 31: goto 44 + 32: label L2 + 33: $t25 := move($t4) + 34: $t26 := 1 + 35: $t27 := +($t25, $t26) + 36: $t4 := $t27 + 37: goto 11 + 38: label L0 + 39: $t28 := move($t6) + 40: destroy($t28) + 41: $t29 := true + 42: $t2 := $t29 + 43: goto 44 + 44: label L4 + 45: $t30 := move($t2) + 46: return $t30 +} + + +[variant baseline] +public fun ascii::string($t0|bytes: vector): ascii::String { + var $t1|x#1#0: option::Option + var $t2: vector + var $t3: option::Option + var $t4: &option::Option + var $t5: bool + var $t6: u64 + var $t7: option::Option + var $t8: ascii::String + 0: $t2 := move($t0) + 1: $t3 := ascii::try_string($t2) + 2: $t1 := $t3 + 3: $t4 := borrow_local($t1) + 4: $t5 := option::is_some($t4) + 5: if ($t5) goto 6 else goto 8 + 6: label L1 + 7: goto 11 + 8: label L0 + 9: $t6 := 65536 + 10: abort($t6) + 11: label L2 + 12: $t7 := move($t1) + 13: $t8 := option::destroy_some($t7) + 14: return $t8 +} + + +[variant baseline] +public fun ascii::as_bytes($t0|string: &ascii::String): &vector { + var $t1: &ascii::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::byte($t0|char: ascii::Char): u8 { + var $t1: ascii::Char + var $t2: u8 + 0: $t1 := move($t0) + 1: $t2 := unpack ascii::Char($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::char($t0|byte: u8): ascii::Char { + var $t1: u8 + var $t2: bool + var $t3: u64 + var $t4: u8 + var $t5: ascii::Char + 0: $t1 := copy($t0) + 1: $t2 := ascii::is_valid_char($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 65536 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := pack ascii::Char($t4) + 11: return $t5 +} + + +[variant baseline] +fun ascii::char_to_lowercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: u8 + var $t5: bool + var $t6: u8 + var $t7: u8 + var $t8: bool + var $t9: bool + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: u8 + 0: $t3 := copy($t0) + 1: $t4 := 65 + 2: $t5 := >=($t3, $t4) + 3: if ($t5) goto 4 else goto 10 + 4: label L1 + 5: $t6 := copy($t0) + 6: $t7 := 90 + 7: $t8 := <=($t6, $t7) + 8: $t1 := $t8 + 9: goto 14 + 10: label L0 + 11: $t9 := false + 12: $t1 := $t9 + 13: goto 14 + 14: label L2 + 15: $t10 := move($t1) + 16: if ($t10) goto 17 else goto 23 + 17: label L4 + 18: $t11 := move($t0) + 19: $t12 := 32 + 20: $t13 := +($t11, $t12) + 21: $t2 := $t13 + 22: goto 27 + 23: label L3 + 24: $t14 := move($t0) + 25: $t2 := $t14 + 26: goto 27 + 27: label L5 + 28: $t15 := move($t2) + 29: return $t15 +} + + +[variant baseline] +fun ascii::char_to_uppercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: u8 + var $t5: bool + var $t6: u8 + var $t7: u8 + var $t8: bool + var $t9: bool + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: u8 + 0: $t3 := copy($t0) + 1: $t4 := 97 + 2: $t5 := >=($t3, $t4) + 3: if ($t5) goto 4 else goto 10 + 4: label L1 + 5: $t6 := copy($t0) + 6: $t7 := 122 + 7: $t8 := <=($t6, $t7) + 8: $t1 := $t8 + 9: goto 14 + 10: label L0 + 11: $t9 := false + 12: $t1 := $t9 + 13: goto 14 + 14: label L2 + 15: $t10 := move($t1) + 16: if ($t10) goto 17 else goto 23 + 17: label L4 + 18: $t11 := move($t0) + 19: $t12 := 32 + 20: $t13 := -($t11, $t12) + 21: $t2 := $t13 + 22: goto 27 + 23: label L3 + 24: $t14 := move($t0) + 25: $t2 := $t14 + 26: goto 27 + 27: label L5 + 28: $t15 := move($t2) + 29: return $t15 +} + + +[variant baseline] +public fun ascii::into_bytes($t0|string: ascii::String): vector { + var $t1: ascii::String + var $t2: vector + 0: $t1 := move($t0) + 1: $t2 := unpack ascii::String($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::is_printable_char($t0|byte: u8): bool { + var $t1|tmp#$1: bool + var $t2: u8 + var $t3: u8 + var $t4: bool + var $t5: u8 + var $t6: u8 + var $t7: bool + var $t8: bool + var $t9: bool + 0: $t2 := copy($t0) + 1: $t3 := 32 + 2: $t4 := >=($t2, $t3) + 3: if ($t4) goto 4 else goto 10 + 4: label L1 + 5: $t5 := move($t0) + 6: $t6 := 126 + 7: $t7 := <=($t5, $t6) + 8: $t1 := $t7 + 9: goto 14 + 10: label L0 + 11: $t8 := false + 12: $t1 := $t8 + 13: goto 14 + 14: label L2 + 15: $t9 := move($t1) + 16: return $t9 +} + + +[variant baseline] +public fun ascii::is_valid_char($t0|b: u8): bool { + var $t1: u8 + var $t2: u8 + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := 127 + 2: $t3 := <=($t1, $t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::pop_char($t0|string: &mut ascii::String): ascii::Char { + var $t1: &mut ascii::String + var $t2: &mut vector + var $t3: u8 + var $t4: ascii::Char + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::pop_back($t2) + 3: $t4 := pack ascii::Char($t3) + 4: return $t4 +} + + +[variant baseline] +public fun ascii::push_char($t0|string: &mut ascii::String, $t1|char: ascii::Char) { + var $t2: &mut ascii::String + var $t3: &mut vector + var $t4: &ascii::Char + var $t5: &u8 + var $t6: u8 + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := borrow_local($t1) + 3: $t5 := borrow_field.byte($t4) + 4: $t6 := read_ref($t5) + 5: vector::push_back($t3, $t6) + 6: return () +} + + +[variant baseline] +public fun ascii::substring($t0|string: &ascii::String, $t1|i: u64, $t2|j: u64): ascii::String { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: vector + var $t5|i#1#3: u64 + var $t6|i#1#6: u64 + var $t7|stop#1#3: u64 + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u64 + var $t12: &ascii::String + var $t13: u64 + var $t14: bool + var $t15: bool + var $t16: bool + var $t17: &ascii::String + var $t18: u64 + var $t19: vector + var $t20: u64 + var $t21: u64 + var $t22: u64 + var $t23: u64 + var $t24: bool + var $t25: u64 + var $t26: &mut vector + var $t27: &ascii::String + var $t28: &vector + var $t29: u64 + var $t30: &u8 + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &ascii::String + var $t36: vector + var $t37: ascii::String + 0: $t8 := copy($t1) + 1: $t9 := copy($t2) + 2: $t10 := <=($t8, $t9) + 3: if ($t10) goto 4 else goto 11 + 4: label L1 + 5: $t11 := copy($t2) + 6: $t12 := copy($t0) + 7: $t13 := ascii::length($t12) + 8: $t14 := <=($t11, $t13) + 9: $t3 := $t14 + 10: goto 15 + 11: label L0 + 12: $t15 := false + 13: $t3 := $t15 + 14: goto 15 + 15: label L2 + 16: $t16 := move($t3) + 17: if ($t16) goto 18 else goto 20 + 18: label L4 + 19: goto 25 + 20: label L3 + 21: $t17 := move($t0) + 22: destroy($t17) + 23: $t18 := 65537 + 24: abort($t18) + 25: label L5 + 26: $t19 := [] + 27: $t4 := $t19 + 28: $t20 := move($t1) + 29: $t5 := $t20 + 30: $t21 := move($t2) + 31: $t7 := $t21 + 32: goto 33 + 33: label L8 + 34: $t22 := copy($t5) + 35: $t23 := copy($t7) + 36: $t24 := <($t22, $t23) + 37: if ($t24) goto 38 else goto 53 + 38: label L7 + 39: $t25 := copy($t5) + 40: $t6 := $t25 + 41: $t26 := borrow_local($t4) + 42: $t27 := copy($t0) + 43: $t28 := borrow_field.bytes($t27) + 44: $t29 := move($t6) + 45: $t30 := vector::borrow($t28, $t29) + 46: $t31 := read_ref($t30) + 47: vector::push_back($t26, $t31) + 48: $t32 := move($t5) + 49: $t33 := 1 + 50: $t34 := +($t32, $t33) + 51: $t5 := $t34 + 52: goto 33 + 53: label L6 + 54: $t35 := move($t0) + 55: destroy($t35) + 56: $t36 := move($t4) + 57: $t37 := pack ascii::String($t36) + 58: return $t37 +} + + +[variant baseline] +public fun ascii::to_lowercase($t0|string: &ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: &u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: &vector + var $t10|v#1#3: &vector + var $t11: &ascii::String + var $t12: &vector + var $t13: vector + var $t14: &vector + var $t15: &vector + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: bool + var $t22: u64 + var $t23: &vector + var $t24: u64 + var $t25: &u8 + var $t26: &mut vector + var $t27: &u8 + var $t28: u8 + var $t29: u8 + var $t30: &mut vector + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &vector + var $t36: vector + var $t37: ascii::String + 0: $t11 := move($t0) + 1: $t12 := ascii::as_bytes($t11) + 2: $t9 := $t12 + 3: $t13 := [] + 4: $t7 := $t13 + 5: $t14 := move($t9) + 6: $t10 := $t14 + 7: $t15 := copy($t10) + 8: $t16 := vector::length($t15) + 9: $t1 := $t16 + 10: $t17 := 0 + 11: $t6 := $t17 + 12: $t18 := move($t1) + 13: $t8 := $t18 + 14: goto 15 + 15: label L2 + 16: $t19 := copy($t6) + 17: $t20 := copy($t8) + 18: $t21 := <($t19, $t20) + 19: if ($t21) goto 20 else goto 41 + 20: label L1 + 21: $t22 := copy($t6) + 22: $t5 := $t22 + 23: $t23 := copy($t10) + 24: $t24 := move($t5) + 25: $t25 := vector::borrow($t23, $t24) + 26: $t4 := $t25 + 27: $t26 := borrow_local($t7) + 28: $t3 := $t26 + 29: $t27 := move($t4) + 30: $t28 := read_ref($t27) + 31: $t29 := ascii::char_to_lowercase($t28) + 32: $t2 := $t29 + 33: $t30 := move($t3) + 34: $t31 := move($t2) + 35: vector::push_back($t30, $t31) + 36: $t32 := move($t6) + 37: $t33 := 1 + 38: $t34 := +($t32, $t33) + 39: $t6 := $t34 + 40: goto 15 + 41: label L0 + 42: $t35 := move($t10) + 43: destroy($t35) + 44: $t36 := move($t7) + 45: $t37 := pack ascii::String($t36) + 46: return $t37 +} + + +[variant baseline] +public fun ascii::to_uppercase($t0|string: &ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: &u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: &vector + var $t10|v#1#3: &vector + var $t11: &ascii::String + var $t12: &vector + var $t13: vector + var $t14: &vector + var $t15: &vector + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: bool + var $t22: u64 + var $t23: &vector + var $t24: u64 + var $t25: &u8 + var $t26: &mut vector + var $t27: &u8 + var $t28: u8 + var $t29: u8 + var $t30: &mut vector + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &vector + var $t36: vector + var $t37: ascii::String + 0: $t11 := move($t0) + 1: $t12 := ascii::as_bytes($t11) + 2: $t9 := $t12 + 3: $t13 := [] + 4: $t7 := $t13 + 5: $t14 := move($t9) + 6: $t10 := $t14 + 7: $t15 := copy($t10) + 8: $t16 := vector::length($t15) + 9: $t1 := $t16 + 10: $t17 := 0 + 11: $t6 := $t17 + 12: $t18 := move($t1) + 13: $t8 := $t18 + 14: goto 15 + 15: label L2 + 16: $t19 := copy($t6) + 17: $t20 := copy($t8) + 18: $t21 := <($t19, $t20) + 19: if ($t21) goto 20 else goto 41 + 20: label L1 + 21: $t22 := copy($t6) + 22: $t5 := $t22 + 23: $t23 := copy($t10) + 24: $t24 := move($t5) + 25: $t25 := vector::borrow($t23, $t24) + 26: $t4 := $t25 + 27: $t26 := borrow_local($t7) + 28: $t3 := $t26 + 29: $t27 := move($t4) + 30: $t28 := read_ref($t27) + 31: $t29 := ascii::char_to_uppercase($t28) + 32: $t2 := $t29 + 33: $t30 := move($t3) + 34: $t31 := move($t2) + 35: vector::push_back($t30, $t31) + 36: $t32 := move($t6) + 37: $t33 := 1 + 38: $t34 := +($t32, $t33) + 39: $t6 := $t34 + 40: goto 15 + 41: label L0 + 42: $t35 := move($t10) + 43: destroy($t35) + 44: $t36 := move($t7) + 45: $t37 := pack ascii::String($t36) + 46: return $t37 +} + + +[variant baseline] +public fun ascii::try_string($t0|bytes: vector): option::Option { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|tmp#$3: option::Option + var $t4|i#1#12: u64 + var $t5|i#1#9: u64 + var $t6|stop#1#9: u64 + var $t7|v#1#3: &vector + var $t8: &vector + var $t9: &vector + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u64 + var $t17: &vector + var $t18: u64 + var $t19: &u8 + var $t20: u8 + var $t21: bool + var $t22: bool + var $t23: &vector + var $t24: bool + var $t25: u64 + var $t26: u64 + var $t27: u64 + var $t28: &vector + var $t29: bool + var $t30: bool + var $t31: vector + var $t32: ascii::String + var $t33: option::Option + var $t34: option::Option + var $t35: option::Option + 0: $t8 := borrow_local($t0) + 1: $t7 := $t8 + 2: $t9 := copy($t7) + 3: $t10 := vector::length($t9) + 4: $t1 := $t10 + 5: $t11 := 0 + 6: $t5 := $t11 + 7: $t12 := move($t1) + 8: $t6 := $t12 + 9: goto 10 + 10: label L5 + 11: $t13 := copy($t5) + 12: $t14 := copy($t6) + 13: $t15 := <($t13, $t14) + 14: if ($t15) goto 15 else goto 37 + 15: label L1 + 16: $t16 := copy($t5) + 17: $t4 := $t16 + 18: $t17 := copy($t7) + 19: $t18 := move($t4) + 20: $t19 := vector::borrow($t17, $t18) + 21: $t20 := read_ref($t19) + 22: $t21 := ascii::is_valid_char($t20) + 23: $t22 := !($t21) + 24: if ($t22) goto 25 else goto 31 + 25: label L3 + 26: $t23 := move($t7) + 27: destroy($t23) + 28: $t24 := false + 29: $t2 := $t24 + 30: goto 43 + 31: label L2 + 32: $t25 := move($t5) + 33: $t26 := 1 + 34: $t27 := +($t25, $t26) + 35: $t5 := $t27 + 36: goto 10 + 37: label L0 + 38: $t28 := move($t7) + 39: destroy($t28) + 40: $t29 := true + 41: $t2 := $t29 + 42: goto 43 + 43: label L4 + 44: $t30 := move($t2) + 45: if ($t30) goto 46 else goto 52 + 46: label L7 + 47: $t31 := move($t0) + 48: $t32 := pack ascii::String($t31) + 49: $t33 := option::some($t32) + 50: $t3 := $t33 + 51: goto 56 + 52: label L6 + 53: $t34 := option::none() + 54: $t3 := $t34 + 55: goto 56 + 56: label L8 + 57: $t35 := move($t3) + 58: return $t35 +} + + +[variant baseline] +public fun string::append($t0|s: &mut string::String, $t1|r: string::String) { + var $t2: &mut string::String + var $t3: &mut vector + var $t4: &string::String + var $t5: &vector + var $t6: vector + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := borrow_local($t1) + 3: $t5 := borrow_field.bytes($t4) + 4: $t6 := read_ref($t5) + 5: vector::append($t3, $t6) + 6: return () +} + + +[variant baseline] +public fun string::index_of($t0|s: &string::String, $t1|r: &string::String): u64 { + var $t2: &string::String + var $t3: &vector + var $t4: &string::String + var $t5: &vector + var $t6: u64 + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := move($t1) + 3: $t5 := borrow_field.bytes($t4) + 4: $t6 := string::internal_index_of($t3, $t5) + 5: return $t6 +} + + +[variant baseline] +public fun string::insert($t0|s: &mut string::String, $t1|at: u64, $t2|o: string::String) { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: &vector + var $t5|end#1#0: string::String + var $t6|front#1#0: string::String + var $t7|l#1#0: u64 + var $t8: &mut string::String + var $t9: &vector + var $t10: u64 + var $t11: &vector + var $t12: u64 + var $t13: bool + var $t14: &vector + var $t15: u64 + var $t16: bool + var $t17: &vector + var $t18: bool + var $t19: bool + var $t20: &mut string::String + var $t21: u64 + var $t22: &mut string::String + var $t23: &string::String + var $t24: u64 + var $t25: &mut string::String + var $t26: &string::String + var $t27: u64 + var $t28: u64 + var $t29: string::String + var $t30: &mut string::String + var $t31: &string::String + var $t32: u64 + var $t33: u64 + var $t34: string::String + var $t35: &mut string::String + var $t36: string::String + var $t37: &mut string::String + var $t38: string::String + var $t39: string::String + var $t40: &mut string::String + 0: $t8 := copy($t0) + 1: $t9 := borrow_field.bytes($t8) + 2: $t4 := $t9 + 3: $t10 := copy($t1) + 4: $t11 := copy($t4) + 5: $t12 := vector::length($t11) + 6: $t13 := <=($t10, $t12) + 7: if ($t13) goto 8 else goto 14 + 8: label L1 + 9: $t14 := move($t4) + 10: $t15 := copy($t1) + 11: $t16 := string::internal_is_char_boundary($t14, $t15) + 12: $t3 := $t16 + 13: goto 20 + 14: label L0 + 15: $t17 := move($t4) + 16: destroy($t17) + 17: $t18 := false + 18: $t3 := $t18 + 19: goto 20 + 20: label L2 + 21: $t19 := move($t3) + 22: if ($t19) goto 23 else goto 25 + 23: label L4 + 24: goto 30 + 25: label L3 + 26: $t20 := move($t0) + 27: destroy($t20) + 28: $t21 := 2 + 29: abort($t21) + 30: label L5 + 31: $t22 := copy($t0) + 32: $t23 := freeze_ref($t22) + 33: $t24 := string::length($t23) + 34: $t7 := $t24 + 35: $t25 := copy($t0) + 36: $t26 := freeze_ref($t25) + 37: $t27 := 0 + 38: $t28 := copy($t1) + 39: $t29 := string::substring($t26, $t27, $t28) + 40: $t6 := $t29 + 41: $t30 := copy($t0) + 42: $t31 := freeze_ref($t30) + 43: $t32 := move($t1) + 44: $t33 := move($t7) + 45: $t34 := string::substring($t31, $t32, $t33) + 46: $t5 := $t34 + 47: $t35 := borrow_local($t6) + 48: $t36 := move($t2) + 49: string::append($t35, $t36) + 50: $t37 := borrow_local($t6) + 51: $t38 := move($t5) + 52: string::append($t37, $t38) + 53: $t39 := move($t6) + 54: $t40 := move($t0) + 55: write_ref($t40, $t39) + 56: return () +} + + +[variant baseline] +public fun string::is_empty($t0|s: &string::String): bool { + var $t1: &string::String + var $t2: &vector + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::is_empty($t2) + 3: return $t3 +} + + +[variant baseline] +public fun string::length($t0|s: &string::String): u64 { + var $t1: &string::String + var $t2: &vector + var $t3: u64 + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::length($t2) + 3: return $t3 +} + + +[variant baseline] +public fun string::as_bytes($t0|s: &string::String): &vector { + var $t1: &string::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::into_bytes($t0|s: string::String): vector { + var $t1: string::String + var $t2: vector + 0: $t1 := move($t0) + 1: $t2 := unpack string::String($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::bytes($t0|s: &string::String): &vector { + var $t1: &string::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := string::as_bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::substring($t0|s: &string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3|tmp#$3: bool + var $t4|tmp#$4: bool + var $t5|tmp#$5: bool + var $t6|bytes#1#0: &vector + var $t7|l#1#0: u64 + var $t8: &string::String + var $t9: &vector + var $t10: &vector + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: bool + var $t15: u64 + var $t16: u64 + var $t17: bool + var $t18: bool + var $t19: bool + var $t20: &vector + var $t21: u64 + var $t22: bool + var $t23: bool + var $t24: bool + var $t25: &vector + var $t26: u64 + var $t27: bool + var $t28: bool + var $t29: bool + var $t30: &vector + var $t31: u64 + var $t32: &vector + var $t33: u64 + var $t34: u64 + var $t35: vector + var $t36: string::String + 0: $t8 := move($t0) + 1: $t9 := borrow_field.bytes($t8) + 2: $t6 := $t9 + 3: $t10 := copy($t6) + 4: $t11 := vector::length($t10) + 5: $t7 := $t11 + 6: $t12 := copy($t2) + 7: $t13 := move($t7) + 8: $t14 := <=($t12, $t13) + 9: if ($t14) goto 10 else goto 16 + 10: label L1 + 11: $t15 := copy($t1) + 12: $t16 := copy($t2) + 13: $t17 := <=($t15, $t16) + 14: $t3 := $t17 + 15: goto 20 + 16: label L0 + 17: $t18 := false + 18: $t3 := $t18 + 19: goto 20 + 20: label L2 + 21: $t19 := move($t3) + 22: if ($t19) goto 23 else goto 29 + 23: label L4 + 24: $t20 := copy($t6) + 25: $t21 := copy($t1) + 26: $t22 := string::internal_is_char_boundary($t20, $t21) + 27: $t4 := $t22 + 28: goto 33 + 29: label L3 + 30: $t23 := false + 31: $t4 := $t23 + 32: goto 33 + 33: label L5 + 34: $t24 := move($t4) + 35: if ($t24) goto 36 else goto 42 + 36: label L7 + 37: $t25 := copy($t6) + 38: $t26 := copy($t2) + 39: $t27 := string::internal_is_char_boundary($t25, $t26) + 40: $t5 := $t27 + 41: goto 46 + 42: label L6 + 43: $t28 := false + 44: $t5 := $t28 + 45: goto 46 + 46: label L8 + 47: $t29 := move($t5) + 48: if ($t29) goto 49 else goto 51 + 49: label L10 + 50: goto 56 + 51: label L9 + 52: $t30 := move($t6) + 53: destroy($t30) + 54: $t31 := 2 + 55: abort($t31) + 56: label L11 + 57: $t32 := move($t6) + 58: $t33 := move($t1) + 59: $t34 := move($t2) + 60: $t35 := string::internal_sub_string($t32, $t33, $t34) + 61: $t36 := pack string::String($t35) + 62: return $t36 +} + + +[variant baseline] +public fun string::append_utf8($t0|s: &mut string::String, $t1|bytes: vector) { + var $t2: &mut string::String + var $t3: vector + var $t4: string::String + 0: $t2 := move($t0) + 1: $t3 := move($t1) + 2: $t4 := string::utf8($t3) + 3: string::append($t2, $t4) + 4: return () +} + + +[variant baseline] +public fun string::from_ascii($t0|s: ascii::String): string::String { + var $t1: ascii::String + var $t2: vector + var $t3: string::String + 0: $t1 := move($t0) + 1: $t2 := ascii::into_bytes($t1) + 2: $t3 := pack string::String($t2) + 3: return $t3 +} + + +[variant baseline] +native fun string::internal_check_utf8($t0|v: &vector): bool; + + +[variant baseline] +native fun string::internal_index_of($t0|v: &vector, $t1|r: &vector): u64; + + +[variant baseline] +native fun string::internal_is_char_boundary($t0|v: &vector, $t1|i: u64): bool; + + +[variant baseline] +native fun string::internal_sub_string($t0|v: &vector, $t1|i: u64, $t2|j: u64): vector; + + +[variant baseline] +public fun string::sub_string($t0|s: &string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3: &string::String + var $t4: u64 + var $t5: u64 + var $t6: string::String + 0: $t3 := move($t0) + 1: $t4 := move($t1) + 2: $t5 := move($t2) + 3: $t6 := string::substring($t3, $t4, $t5) + 4: return $t6 +} + + +[variant baseline] +public fun string::to_ascii($t0|s: string::String): ascii::String { + var $t1: string::String + var $t2: vector + var $t3: ascii::String + 0: $t1 := move($t0) + 1: $t2 := unpack string::String($t1) + 2: $t3 := ascii::string($t2) + 3: return $t3 +} + + +[variant baseline] +public fun string::try_utf8($t0|bytes: vector): option::Option { + var $t1|tmp#$1: option::Option + var $t2: &vector + var $t3: bool + var $t4: vector + var $t5: string::String + var $t6: option::Option + var $t7: option::Option + var $t8: option::Option + 0: $t2 := borrow_local($t0) + 1: $t3 := string::internal_check_utf8($t2) + 2: if ($t3) goto 3 else goto 9 + 3: label L1 + 4: $t4 := move($t0) + 5: $t5 := pack string::String($t4) + 6: $t6 := option::some($t5) + 7: $t1 := $t6 + 8: goto 13 + 9: label L0 + 10: $t7 := option::none() + 11: $t1 := $t7 + 12: goto 13 + 13: label L2 + 14: $t8 := move($t1) + 15: return $t8 +} + + +[variant baseline] +public fun string::utf8($t0|bytes: vector): string::String { + var $t1: &vector + var $t2: bool + var $t3: u64 + var $t4: vector + var $t5: string::String + 0: $t1 := borrow_local($t0) + 1: $t2 := string::internal_check_utf8($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 1 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := pack string::String($t4) + 11: return $t5 +} + + +[variant baseline] +fun MultiLayerCalling::inner($t0|has_vector: &mut MultiLayerCalling::HasVector): &mut MultiLayerCalling::HasAnotherVector { + var $t1: &mut MultiLayerCalling::HasVector + var $t2: &mut vector + var $t3: u64 + var $t4: &mut MultiLayerCalling::HasAnotherVector + 0: $t1 := move($t0) + 1: $t2 := borrow_field.v($t1) + 2: $t3 := 7 + 3: $t4 := vector::borrow_mut($t2, $t3) + 4: return $t4 +} + + +[variant baseline] +fun MultiLayerCalling::mid($t0|has_vector: &mut MultiLayerCalling::HasVector): &mut MultiLayerCalling::HasAnotherVector { + var $t1: &mut MultiLayerCalling::HasVector + var $t2: &mut MultiLayerCalling::HasAnotherVector + 0: $t1 := move($t0) + 1: $t2 := MultiLayerCalling::inner($t1) + 2: return $t2 +} + + +[variant baseline] +fun MultiLayerCalling::outer($t0|has_vector: &mut MultiLayerCalling::HasVector) { + var $t1: &mut MultiLayerCalling::HasVector + var $t2: &mut MultiLayerCalling::HasAnotherVector + var $t3: &mut vector + var $t4: u8 + 0: $t1 := move($t0) + 1: $t2 := MultiLayerCalling::mid($t1) + 2: $t3 := borrow_field.v($t2) + 3: $t4 := 42 + 4: vector::push_back($t3, $t4) + 5: return () +} + +============ after pipeline `borrow` ================ + +[variant baseline] +public fun u64::diff($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: bool + 0: $t5 := >($t0, $t1) + 1: if ($t5) goto 2 else goto 5 + 2: label L1 + 3: $t2 := -($t0, $t1) + 4: goto 7 + 5: label L0 + 6: $t2 := -($t1, $t0) + 7: label L2 + 8: return $t2 +} + + +[variant baseline] +public fun u64::divide_and_round_up($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: bool + var $t8: u64 + var $t9: u64 + 0: $t5 := %($t0, $t1) + 1: $t6 := 0 + 2: $t7 := ==($t5, $t6) + 3: if ($t7) goto 4 else goto 7 + 4: label L1 + 5: $t2 := /($t0, $t1) + 6: goto 11 + 7: label L0 + 8: $t8 := /($t0, $t1) + 9: $t9 := 1 + 10: $t2 := +($t8, $t9) + 11: label L2 + 12: return $t2 +} + + +[variant baseline] +public fun u64::max($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: bool + 0: $t5 := >($t0, $t1) + 1: if ($t5) goto 2 else goto 5 + 2: label L1 + 3: $t2 := $t0 + 4: goto 7 + 5: label L0 + 6: $t2 := $t1 + 7: label L2 + 8: return $t2 +} + + +[variant baseline] +public fun u64::min($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: bool + 0: $t5 := <($t0, $t1) + 1: if ($t5) goto 2 else goto 5 + 2: label L1 + 3: $t2 := $t0 + 4: goto 7 + 5: label L0 + 6: $t2 := $t1 + 7: label L2 + 8: return $t2 +} + + +[variant baseline] +public fun u64::pow($t0|base: u64, $t1|exponent: u8): u64 { + var $t2|base#1#1: u64 + var $t3|exponent#1#1: u8 + var $t4|res#1#1: u64 + var $t5: u64 + var $t6: u8 + var $t7: bool + var $t8: u8 + var $t9: u8 + var $t10: u8 + var $t11: bool + var $t12: u8 + var $t13: u8 + 0: $t2 := $t0 + 1: $t3 := $t1 + 2: $t5 := 1 + 3: $t4 := $t5 + 4: label L5 + 5: $t6 := 1 + 6: $t7 := >=($t3, $t6) + 7: if ($t7) goto 8 else goto 25 + 8: label L1 + 9: label L2 + 10: $t8 := 2 + 11: $t9 := %($t3, $t8) + 12: $t10 := 0 + 13: $t11 := ==($t9, $t10) + 14: if ($t11) goto 15 else goto 20 + 15: label L4 + 16: $t2 := *($t2, $t2) + 17: $t12 := 2 + 18: $t3 := /($t3, $t12) + 19: goto 4 + 20: label L3 + 21: $t4 := *($t4, $t2) + 22: $t13 := 1 + 23: $t3 := -($t3, $t13) + 24: goto 4 + 25: label L0 + 26: return $t4 +} + + +[variant baseline] +public fun u64::sqrt($t0|x: u64): u64 { + var $t1|bit#1#1: u128 + var $t2|res#1#1: u128 + var $t3|x#1#1: u64 + var $t4|x#2#1: u128 + var $t5: u128 + var $t6: u128 + var $t7: u128 + var $t8: bool + var $t9: u128 + var $t10: bool + var $t11: u128 + var $t12: u8 + var $t13: u128 + var $t14: u8 + var $t15: u8 + var $t16: u64 + 0: $t5 := 18446744073709551616 + 1: $t1 := $t5 + 2: $t6 := 0 + 3: $t2 := $t6 + 4: $t4 := (u128)($t0) + 5: label L6 + 6: $t7 := 0 + 7: $t8 := !=($t1, $t7) + 8: if ($t8) goto 9 else goto 28 + 9: label L1 + 10: label L2 + 11: $t9 := +($t2, $t1) + 12: $t10 := >=($t4, $t9) + 13: if ($t10) goto 14 else goto 21 + 14: label L4 + 15: $t11 := +($t2, $t1) + 16: $t4 := -($t4, $t11) + 17: $t12 := 1 + 18: $t13 := >>($t2, $t12) + 19: $t2 := +($t13, $t1) + 20: goto 24 + 21: label L3 + 22: $t14 := 1 + 23: $t2 := >>($t2, $t14) + 24: label L5 + 25: $t15 := 2 + 26: $t1 := >>($t1, $t15) + 27: goto 5 + 28: label L0 + 29: $t16 := (u64)($t2) + 30: return $t16 +} + + +[variant baseline] +public fun vector::append<#0>($t0|lhs: &mut vector<#0>, $t1|other: vector<#0>) { + var $t2: &mut vector<#0> + var $t3: vector<#0> + var $t4: bool + var $t5: bool + var $t6: &mut vector<#0> + var $t7: #0 + var $t8: vector<#0> + 0: $t2 := borrow_local($t1) + 1: vector::reverse<#0>($t2) + 2: label L3 + 3: $t3 := copy($t1) + 4: $t4 := vector::is_empty<#0>($t3) + 5: $t5 := !($t4) + 6: if ($t5) goto 7 else goto 13 + 7: label L1 + 8: label L2 + 9: $t6 := borrow_local($t1) + 10: $t7 := vector::pop_back<#0>($t6) + 11: vector::push_back<#0>($t0, $t7) + 12: goto 2 + 13: label L0 + 14: destroy($t0) + 15: $t8 := move($t1) + 16: vector::destroy_empty<#0>($t8) + 17: trace_local[lhs]($t0) + 18: return () +} + + +[variant baseline] +public native fun vector::borrow<#0>($t0|v: vector<#0>, $t1|i: u64): #0; + + +[variant baseline] +public native fun vector::borrow_mut<#0>($t0|v: &mut vector<#0>, $t1|i: u64): &mut #0; + + +[variant baseline] +public fun vector::contains<#0>($t0|v: vector<#0>, $t1|e: #0): bool { + var $t2|i#1#0: u64 + var $t3|len#1#0: u64 + var $t4: u64 + var $t5: u64 + var $t6: bool + var $t7: #0 + var $t8: bool + var $t9: bool + var $t10: u64 + var $t11: bool + 0: $t4 := 0 + 1: $t2 := $t4 + 2: $t5 := vector::length<#0>($t0) + 3: label L5 + 4: $t6 := <($t2, $t5) + 5: if ($t6) goto 6 else goto 18 + 6: label L1 + 7: label L2 + 8: $t7 := vector::borrow<#0>($t0, $t2) + 9: $t8 := ==($t7, $t1) + 10: if ($t8) goto 11 else goto 14 + 11: label L4 + 12: $t9 := true + 13: return $t9 + 14: label L3 + 15: $t10 := 1 + 16: $t2 := +($t2, $t10) + 17: goto 3 + 18: label L0 + 19: $t11 := false + 20: return $t11 +} + + +[variant baseline] +public native fun vector::destroy_empty<#0>($t0|v: vector<#0>); + + +[variant baseline] +public native fun vector::empty<#0>(): vector<#0>; + + +[variant baseline] +public fun vector::index_of<#0>($t0|v: vector<#0>, $t1|e: #0): (bool, u64) { + var $t2|i#1#0: u64 + var $t3|len#1#0: u64 + var $t4: u64 + var $t5: u64 + var $t6: bool + var $t7: #0 + var $t8: bool + var $t9: bool + var $t10: u64 + var $t11: bool + var $t12: u64 + 0: $t4 := 0 + 1: $t2 := $t4 + 2: $t5 := vector::length<#0>($t0) + 3: label L5 + 4: $t6 := <($t2, $t5) + 5: if ($t6) goto 6 else goto 18 + 6: label L1 + 7: label L2 + 8: $t7 := vector::borrow<#0>($t0, $t2) + 9: $t8 := ==($t7, $t1) + 10: if ($t8) goto 11 else goto 14 + 11: label L4 + 12: $t9 := true + 13: return ($t9, $t2) + 14: label L3 + 15: $t10 := 1 + 16: $t2 := +($t2, $t10) + 17: goto 3 + 18: label L0 + 19: $t11 := false + 20: $t12 := 0 + 21: return ($t11, $t12) +} + + +[variant baseline] +public fun vector::insert<#0>($t0|v: &mut vector<#0>, $t1|e: #0, $t2|i: u64) { + var $t3|len#1#0: u64 + var $t4: vector<#0> + var $t5: u64 + var $t6: bool + var $t7: u64 + var $t8: bool + var $t9: u64 + 0: $t4 := read_ref($t0) + 1: $t5 := vector::length<#0>($t4) + 2: $t6 := >($t2, $t5) + 3: if ($t6) goto 4 else goto 8 + 4: label L1 + 5: destroy($t0) + 6: $t7 := 131072 + 7: abort($t7) + 8: label L0 + 9: vector::push_back<#0>($t0, $t1) + 10: label L4 + 11: $t8 := <($t2, $t5) + 12: if ($t8) goto 13 else goto 18 + 13: label L3 + 14: vector::swap<#0>($t0, $t2, $t5) + 15: $t9 := 1 + 16: $t2 := +($t2, $t9) + 17: goto 10 + 18: label L2 + 19: destroy($t0) + 20: trace_local[v]($t0) + 21: return () +} + + +[variant baseline] +public fun vector::is_empty<#0>($t0|v: vector<#0>): bool { + var $t1: u64 + var $t2: u64 + var $t3: bool + 0: $t1 := vector::length<#0>($t0) + 1: $t2 := 0 + 2: $t3 := ==($t1, $t2) + 3: return $t3 +} + + +[variant baseline] +public native fun vector::length<#0>($t0|v: vector<#0>): u64; + + +[variant baseline] +public native fun vector::pop_back<#0>($t0|v: &mut vector<#0>): #0; + + +[variant baseline] +public native fun vector::push_back<#0>($t0|v: &mut vector<#0>, $t1|e: #0); + + +[variant baseline] +public fun vector::remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { + var $t2|tmp#$2: u64 + var $t3|tmp#$3: &mut vector<#0> + var $t4|len#1#0: u64 + var $t5: vector<#0> + var $t6: u64 + var $t7: bool + var $t8: u64 + var $t9: u64 + var $t10: u64 + var $t11: bool + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: #0 + 0: $t5 := read_ref($t0) + 1: $t6 := vector::length<#0>($t5) + 2: $t7 := >=($t1, $t6) + 3: if ($t7) goto 4 else goto 8 + 4: label L1 + 5: destroy($t0) + 6: $t8 := 131072 + 7: abort($t8) + 8: label L0 + 9: $t9 := 1 + 10: $t10 := -($t6, $t9) + 11: label L4 + 12: $t11 := <($t1, $t10) + 13: if ($t11) goto 14 else goto 21 + 14: label L3 + 15: $t12 := copy($t1) + 16: $t13 := 1 + 17: $t14 := +($t1, $t13) + 18: $t1 := $t14 + 19: vector::swap<#0>($t0, $t12, $t14) + 20: goto 11 + 21: label L2 + 22: $t15 := vector::pop_back<#0>($t0) + 23: trace_local[v]($t0) + 24: return $t15 +} + + +[variant baseline] +public fun vector::reverse<#0>($t0|v: &mut vector<#0>) { + var $t1|back_index#1#0: u64 + var $t2|front_index#1#0: u64 + var $t3|len#1#0: u64 + var $t4: vector<#0> + var $t5: u64 + var $t6: u64 + var $t7: bool + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u64 + var $t12: u64 + 0: $t4 := read_ref($t0) + 1: $t5 := vector::length<#0>($t4) + 2: $t6 := 0 + 3: $t7 := ==($t5, $t6) + 4: if ($t7) goto 5 else goto 9 + 5: label L1 + 6: destroy($t0) + 7: trace_local[v]($t0) + 8: return () + 9: label L0 + 10: $t8 := 0 + 11: $t2 := $t8 + 12: $t9 := 1 + 13: $t1 := -($t5, $t9) + 14: label L4 + 15: $t10 := <($t2, $t1) + 16: if ($t10) goto 17 else goto 24 + 17: label L3 + 18: vector::swap<#0>($t0, $t2, $t1) + 19: $t11 := 1 + 20: $t2 := +($t2, $t11) + 21: $t12 := 1 + 22: $t1 := -($t1, $t12) + 23: goto 14 + 24: label L2 + 25: destroy($t0) + 26: trace_local[v]($t0) + 27: return () +} + + +[variant baseline] +public fun vector::singleton<#0>($t0|e: #0): vector<#0> { + var $t1|v#1#0: vector<#0> + var $t2: &mut vector<#0> + var $t3: vector<#0> + 0: $t1 := vector::empty<#0>() + 1: $t2 := borrow_local($t1) + 2: vector::push_back<#0>($t2, $t0) + 3: $t3 := move($t1) + 4: return $t3 +} + + +[variant baseline] +public native fun vector::swap<#0>($t0|v: &mut vector<#0>, $t1|i: u64, $t2|j: u64); + + +[variant baseline] +public fun vector::swap_remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { + var $t2|last_idx#1#0: u64 + var $t3: vector<#0> + var $t4: bool + var $t5: bool + var $t6: u64 + var $t7: vector<#0> + var $t8: u64 + var $t9: u64 + var $t10: u64 + var $t11: #0 + 0: $t3 := read_ref($t0) + 1: $t4 := vector::is_empty<#0>($t3) + 2: $t5 := !($t4) + 3: if ($t5) goto 4 else goto 6 + 4: label L1 + 5: goto 10 + 6: label L0 + 7: destroy($t0) + 8: $t6 := 131072 + 9: abort($t6) + 10: label L2 + 11: $t7 := read_ref($t0) + 12: $t8 := vector::length<#0>($t7) + 13: $t9 := 1 + 14: $t10 := -($t8, $t9) + 15: vector::swap<#0>($t0, $t1, $t10) + 16: $t11 := vector::pop_back<#0>($t0) + 17: trace_local[v]($t0) + 18: return $t11 +} + + +[variant baseline] +public fun option::borrow<#0>($t0|t: option::Option<#0>): #0 { + var $t1: bool + var $t2: u64 + var $t3: vector<#0> + var $t4: u64 + var $t5: #0 + 0: $t1 := option::is_some<#0>($t0) + 1: if ($t1) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t2 := 262145 + 6: abort($t2) + 7: label L2 + 8: $t3 := get_field>.vec($t0) + 9: $t4 := 0 + 10: $t5 := vector::borrow<#0>($t3, $t4) + 11: return $t5 +} + + +[variant baseline] +public fun option::borrow_mut<#0>($t0|t: &mut option::Option<#0>): &mut #0 { + var $t1: option::Option<#0> + var $t2: bool + var $t3: u64 + var $t4: &mut vector<#0> + var $t5: u64 + var $t6: &mut #0 + 0: $t1 := read_ref($t0) + 1: $t2 := option::is_some<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 9 + 5: label L0 + 6: destroy($t0) + 7: $t3 := 262145 + 8: abort($t3) + 9: label L2 + 10: $t4 := borrow_field>.vec($t0) + 11: $t5 := 0 + 12: $t6 := vector::borrow_mut<#0>($t4, $t5) + 13: trace_local[t]($t0) + 14: return $t6 +} + + +[variant baseline] +public fun option::contains<#0>($t0|t: option::Option<#0>, $t1|e_ref: #0): bool { + var $t2: vector<#0> + var $t3: bool + 0: $t2 := get_field>.vec($t0) + 1: $t3 := vector::contains<#0>($t2, $t1) + 2: return $t3 +} + + +[variant baseline] +public fun option::swap<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): #0 { + var $t2|old_value#1#0: #0 + var $t3|vec_ref#1#0: &mut vector<#0> + var $t4: option::Option<#0> + var $t5: bool + var $t6: u64 + var $t7: &mut vector<#0> + var $t8: #0 + 0: $t4 := read_ref($t0) + 1: $t5 := option::is_some<#0>($t4) + 2: if ($t5) goto 3 else goto 5 + 3: label L1 + 4: goto 9 + 5: label L0 + 6: destroy($t0) + 7: $t6 := 262145 + 8: abort($t6) + 9: label L2 + 10: $t7 := borrow_field>.vec($t0) + 11: $t8 := vector::pop_back<#0>($t7) + 12: vector::push_back<#0>($t7, $t1) + 13: trace_local[t]($t0) + 14: return $t8 +} + + +[variant baseline] +public fun option::borrow_with_default<#0>($t0|t: option::Option<#0>, $t1|default_ref: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec_ref#1#0: vector<#0> + var $t4: vector<#0> + var $t5: bool + var $t6: u64 + 0: $t4 := get_field>.vec($t0) + 1: $t5 := vector::is_empty<#0>($t4) + 2: if ($t5) goto 3 else goto 6 + 3: label L1 + 4: $t2 := $t1 + 5: goto 9 + 6: label L0 + 7: $t6 := 0 + 8: $t2 := vector::borrow<#0>($t4, $t6) + 9: label L2 + 10: return $t2 +} + + +[variant baseline] +public fun option::destroy_none<#0>($t0|t: option::Option<#0>) { + var $t1: bool + var $t2: u64 + var $t3: vector<#0> + 0: $t1 := option::is_none<#0>($t0) + 1: if ($t1) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t2 := 262144 + 6: abort($t2) + 7: label L2 + 8: $t3 := unpack option::Option<#0>($t0) + 9: vector::destroy_empty<#0>($t3) + 10: return () +} + + +[variant baseline] +public fun option::destroy_some<#0>($t0|t: option::Option<#0>): #0 { + var $t1|elem#1#0: #0 + var $t2|vec#1#0: vector<#0> + var $t3: bool + var $t4: u64 + var $t5: &mut vector<#0> + var $t6: #0 + var $t7: vector<#0> + 0: $t3 := option::is_some<#0>($t0) + 1: if ($t3) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t4 := 262145 + 6: abort($t4) + 7: label L2 + 8: $t2 := unpack option::Option<#0>($t0) + 9: $t5 := borrow_local($t2) + 10: $t6 := vector::pop_back<#0>($t5) + 11: $t7 := move($t2) + 12: vector::destroy_empty<#0>($t7) + 13: return $t6 +} + + +[variant baseline] +public fun option::destroy_with_default<#0>($t0|t: option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec#1#0: vector<#0> + var $t4: vector<#0> + var $t5: bool + var $t6: &mut vector<#0> + 0: $t3 := unpack option::Option<#0>($t0) + 1: $t4 := copy($t3) + 2: $t5 := vector::is_empty<#0>($t4) + 3: if ($t5) goto 4 else goto 7 + 4: label L1 + 5: $t2 := $t1 + 6: goto 10 + 7: label L0 + 8: $t6 := borrow_local($t3) + 9: $t2 := vector::pop_back<#0>($t6) + 10: label L2 + 11: return $t2 +} + + +[variant baseline] +public fun option::extract<#0>($t0|t: &mut option::Option<#0>): #0 { + var $t1: option::Option<#0> + var $t2: bool + var $t3: u64 + var $t4: &mut vector<#0> + var $t5: #0 + 0: $t1 := read_ref($t0) + 1: $t2 := option::is_some<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 9 + 5: label L0 + 6: destroy($t0) + 7: $t3 := 262145 + 8: abort($t3) + 9: label L2 + 10: $t4 := borrow_field>.vec($t0) + 11: $t5 := vector::pop_back<#0>($t4) + 12: trace_local[t]($t0) + 13: return $t5 +} + + +[variant baseline] +public fun option::fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0) { + var $t2|vec_ref#1#0: &mut vector<#0> + var $t3: &mut vector<#0> + var $t4: vector<#0> + var $t5: bool + var $t6: u64 + 0: $t3 := borrow_field>.vec($t0) + 1: $t4 := read_ref($t3) + 2: $t5 := vector::is_empty<#0>($t4) + 3: if ($t5) goto 4 else goto 14 + 4: label L1 + 5: goto 10 + 6: label L0 + 7: destroy($t3) + 8: $t6 := 262144 + 9: abort($t6) + 10: label L2 + 11: vector::push_back<#0>($t3, $t1) + 12: trace_local[t]($t0) + 13: return () + 14: label L3 + 15: destroy($t0) + 16: goto 6 +} + + +[variant baseline] +public fun option::get_with_default<#0>($t0|t: option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec_ref#1#0: vector<#0> + var $t4: vector<#0> + var $t5: bool + var $t6: u64 + var $t7: #0 + 0: $t4 := get_field>.vec($t0) + 1: $t5 := vector::is_empty<#0>($t4) + 2: if ($t5) goto 3 else goto 6 + 3: label L1 + 4: $t2 := $t1 + 5: goto 10 + 6: label L0 + 7: $t6 := 0 + 8: $t7 := vector::borrow<#0>($t4, $t6) + 9: $t2 := $t7 + 10: label L2 + 11: return $t2 +} + + +[variant baseline] +public fun option::is_none<#0>($t0|t: option::Option<#0>): bool { + var $t1: vector<#0> + var $t2: bool + 0: $t1 := get_field>.vec($t0) + 1: $t2 := vector::is_empty<#0>($t1) + 2: return $t2 +} + + +[variant baseline] +public fun option::is_some<#0>($t0|t: option::Option<#0>): bool { + var $t1: vector<#0> + var $t2: bool + var $t3: bool + 0: $t1 := get_field>.vec($t0) + 1: $t2 := vector::is_empty<#0>($t1) + 2: $t3 := !($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::none<#0>(): option::Option<#0> { + var $t0: vector<#0> + var $t1: option::Option<#0> + 0: $t0 := vector::empty<#0>() + 1: $t1 := pack option::Option<#0>($t0) + 2: return $t1 +} + + +[variant baseline] +public fun option::some<#0>($t0|e: #0): option::Option<#0> { + var $t1: vector<#0> + var $t2: option::Option<#0> + 0: $t1 := vector::singleton<#0>($t0) + 1: $t2 := pack option::Option<#0>($t1) + 2: return $t2 +} + + +[variant baseline] +public fun option::swap_or_fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): option::Option<#0> { + var $t2|tmp#$2: option::Option<#0> + var $t3|old_value#1#0: option::Option<#0> + var $t4|vec_ref#1#0: &mut vector<#0> + var $t5: &mut vector<#0> + var $t6: vector<#0> + var $t7: bool + var $t8: #0 + 0: $t5 := borrow_field>.vec($t0) + 1: $t6 := read_ref($t5) + 2: $t7 := vector::is_empty<#0>($t6) + 3: if ($t7) goto 4 else goto 7 + 4: label L1 + 5: $t2 := option::none<#0>() + 6: goto 10 + 7: label L0 + 8: $t8 := vector::pop_back<#0>($t5) + 9: $t2 := option::some<#0>($t8) + 10: label L2 + 11: vector::push_back<#0>($t5, $t1) + 12: trace_local[t]($t0) + 13: return $t2 +} + + +[variant baseline] +public fun option::to_vec<#0>($t0|t: option::Option<#0>): vector<#0> { + var $t1: vector<#0> + 0: $t1 := unpack option::Option<#0>($t0) + 1: return $t1 +} + + +[variant baseline] +public fun ascii::append($t0|string: &mut ascii::String, $t1|other: ascii::String) { + var $t2: &mut vector + var $t3: vector + 0: $t2 := borrow_field.bytes($t0) + 1: $t3 := ascii::into_bytes($t1) + 2: vector::append($t2, $t3) + 3: trace_local[string]($t0) + 4: return () +} + + +[variant baseline] +public fun ascii::index_of($t0|string: ascii::String, $t1|substr: ascii::String): u64 { + var $t2|tmp#$2: bool + var $t3|i#1#0: u64 + var $t4|j#1#0: u64 + var $t5|m#1#0: u64 + var $t6|n#1#0: u64 + var $t7: u64 + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u64 + var $t12: bool + var $t13: u64 + var $t14: bool + var $t15: vector + var $t16: u64 + var $t17: u8 + var $t18: vector + var $t19: u8 + var $t20: bool + var $t21: u64 + var $t22: bool + var $t23: u64 + 0: $t7 := 0 + 1: $t3 := $t7 + 2: $t8 := ascii::length($t0) + 3: $t9 := ascii::length($t1) + 4: $t10 := <($t8, $t9) + 5: if ($t10) goto 6 else goto 8 + 6: label L1 + 7: return $t8 + 8: label L0 + 9: $t11 := -($t8, $t9) + 10: $t12 := <=($t3, $t11) + 11: if ($t12) goto 12 else goto 45 + 12: label L3 + 13: $t13 := 0 + 14: $t4 := $t13 + 15: label L10 + 16: $t14 := <($t4, $t9) + 17: if ($t14) goto 18 else goto 27 + 18: label L5 + 19: label L6 + 20: $t15 := get_field.bytes($t0) + 21: $t16 := +($t3, $t4) + 22: $t17 := vector::borrow($t15, $t16) + 23: $t18 := get_field.bytes($t1) + 24: $t19 := vector::borrow($t18, $t4) + 25: $t2 := ==($t17, $t19) + 26: goto 30 + 27: label L4 + 28: $t20 := false + 29: $t2 := $t20 + 30: label L7 + 31: if ($t2) goto 32 else goto 36 + 32: label L9 + 33: $t21 := 1 + 34: $t4 := +($t4, $t21) + 35: goto 15 + 36: label L8 + 37: $t22 := ==($t4, $t9) + 38: if ($t22) goto 39 else goto 41 + 39: label L12 + 40: return $t3 + 41: label L11 + 42: $t23 := 1 + 43: $t3 := +($t3, $t23) + 44: goto 8 + 45: label L2 + 46: return $t8 +} + + +[variant baseline] +public fun ascii::insert($t0|s: &mut ascii::String, $t1|at: u64, $t2|o: ascii::String) { + var $t3|e#1#2: u8 + var $t4|v#1#1: vector + var $t5: ascii::String + var $t6: u64 + var $t7: bool + var $t8: u64 + var $t9: vector + var $t10: bool + var $t11: bool + var $t12: &mut vector + var $t13: u8 + var $t14: &mut vector + var $t15: vector + 0: $t5 := read_ref($t0) + 1: $t6 := ascii::length($t5) + 2: $t7 := <=($t1, $t6) + 3: if ($t7) goto 4 else goto 6 + 4: label L1 + 5: goto 10 + 6: label L0 + 7: destroy($t0) + 8: $t8 := 65537 + 9: abort($t8) + 10: label L2 + 11: $t4 := ascii::into_bytes($t2) + 12: label L5 + 13: $t9 := copy($t4) + 14: $t10 := vector::is_empty($t9) + 15: $t11 := !($t10) + 16: if ($t11) goto 17 else goto 23 + 17: label L4 + 18: $t12 := borrow_local($t4) + 19: $t13 := vector::pop_back($t12) + 20: $t14 := borrow_field.bytes($t0) + 21: vector::insert($t14, $t13, $t1) + 22: goto 12 + 23: label L3 + 24: destroy($t0) + 25: $t15 := move($t4) + 26: vector::destroy_empty($t15) + 27: trace_local[s]($t0) + 28: return () +} + + +[variant baseline] +public fun ascii::is_empty($t0|string: ascii::String): bool { + var $t1: vector + var $t2: bool + 0: $t1 := get_field.bytes($t0) + 1: $t2 := vector::is_empty($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::length($t0|string: ascii::String): u64 { + var $t1: vector + var $t2: u64 + 0: $t1 := ascii::as_bytes($t0) + 1: $t2 := vector::length($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::all_characters_printable($t0|string: ascii::String): bool { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|i#1#12: u64 + var $t4|i#1#9: u64 + var $t5|stop#1#9: u64 + var $t6|v#1#3: vector + var $t7: vector + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u8 + var $t12: bool + var $t13: bool + var $t14: bool + var $t15: u64 + var $t16: bool + 0: $t7 := get_field.bytes($t0) + 1: $t8 := vector::length($t7) + 2: $t9 := 0 + 3: $t4 := $t9 + 4: label L5 + 5: $t10 := <($t4, $t8) + 6: if ($t10) goto 7 else goto 20 + 7: label L1 + 8: $t11 := vector::borrow($t7, $t4) + 9: $t12 := ascii::is_printable_char($t11) + 10: $t13 := !($t12) + 11: if ($t13) goto 12 else goto 16 + 12: label L3 + 13: $t14 := false + 14: $t2 := $t14 + 15: goto 23 + 16: label L2 + 17: $t15 := 1 + 18: $t4 := +($t4, $t15) + 19: goto 4 + 20: label L0 + 21: $t16 := true + 22: $t2 := $t16 + 23: label L4 + 24: return $t2 +} + + +[variant baseline] +public fun ascii::string($t0|bytes: vector): ascii::String { + var $t1|x#1#0: option::Option + var $t2: option::Option + var $t3: bool + var $t4: u64 + var $t5: ascii::String + 0: $t2 := ascii::try_string($t0) + 1: $t3 := option::is_some($t2) + 2: if ($t3) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t4 := 65536 + 7: abort($t4) + 8: label L2 + 9: $t5 := option::destroy_some($t2) + 10: return $t5 +} + + +[variant baseline] +public fun ascii::as_bytes($t0|string: ascii::String): vector { + var $t1: vector + 0: $t1 := get_field.bytes($t0) + 1: return $t1 +} + + +[variant baseline] +public fun ascii::byte($t0|char: ascii::Char): u8 { + var $t1: u8 + 0: $t1 := unpack ascii::Char($t0) + 1: return $t1 +} + + +[variant baseline] +public fun ascii::char($t0|byte: u8): ascii::Char { + var $t1: bool + var $t2: u64 + var $t3: ascii::Char + 0: $t1 := ascii::is_valid_char($t0) + 1: if ($t1) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t2 := 65536 + 6: abort($t2) + 7: label L2 + 8: $t3 := pack ascii::Char($t0) + 9: return $t3 +} + + +[variant baseline] +fun ascii::char_to_lowercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: bool + var $t5: u8 + var $t6: bool + var $t7: u8 + 0: $t3 := 65 + 1: $t4 := >=($t0, $t3) + 2: if ($t4) goto 3 else goto 7 + 3: label L1 + 4: $t5 := 90 + 5: $t1 := <=($t0, $t5) + 6: goto 10 + 7: label L0 + 8: $t6 := false + 9: $t1 := $t6 + 10: label L2 + 11: if ($t1) goto 12 else goto 16 + 12: label L4 + 13: $t7 := 32 + 14: $t2 := +($t0, $t7) + 15: goto 18 + 16: label L3 + 17: $t2 := $t0 + 18: label L5 + 19: return $t2 +} + + +[variant baseline] +fun ascii::char_to_uppercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: bool + var $t5: u8 + var $t6: bool + var $t7: u8 + 0: $t3 := 97 + 1: $t4 := >=($t0, $t3) + 2: if ($t4) goto 3 else goto 7 + 3: label L1 + 4: $t5 := 122 + 5: $t1 := <=($t0, $t5) + 6: goto 10 + 7: label L0 + 8: $t6 := false + 9: $t1 := $t6 + 10: label L2 + 11: if ($t1) goto 12 else goto 16 + 12: label L4 + 13: $t7 := 32 + 14: $t2 := -($t0, $t7) + 15: goto 18 + 16: label L3 + 17: $t2 := $t0 + 18: label L5 + 19: return $t2 +} + + +[variant baseline] +public fun ascii::into_bytes($t0|string: ascii::String): vector { + var $t1: vector + 0: $t1 := unpack ascii::String($t0) + 1: return $t1 +} + + +[variant baseline] +public fun ascii::is_printable_char($t0|byte: u8): bool { + var $t1|tmp#$1: bool + var $t2: u8 + var $t3: bool + var $t4: u8 + var $t5: bool + 0: $t2 := 32 + 1: $t3 := >=($t0, $t2) + 2: if ($t3) goto 3 else goto 7 + 3: label L1 + 4: $t4 := 126 + 5: $t1 := <=($t0, $t4) + 6: goto 10 + 7: label L0 + 8: $t5 := false + 9: $t1 := $t5 + 10: label L2 + 11: return $t1 +} + + +[variant baseline] +public fun ascii::is_valid_char($t0|b: u8): bool { + var $t1: u8 + var $t2: bool + 0: $t1 := 127 + 1: $t2 := <=($t0, $t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::pop_char($t0|string: &mut ascii::String): ascii::Char { + var $t1: &mut vector + var $t2: u8 + var $t3: ascii::Char + 0: $t1 := borrow_field.bytes($t0) + 1: $t2 := vector::pop_back($t1) + 2: $t3 := pack ascii::Char($t2) + 3: trace_local[string]($t0) + 4: return $t3 +} + [variant baseline] -public fun vector::index_of<#0>($t0|v: vector<#0>, $t1|e: #0): (bool, u64) { - var $t2|i#1#0: u64 - var $t3|len#1#0: u64 - var $t4: u64 - var $t5: u64 - var $t6: bool - var $t7: #0 - var $t8: bool - var $t9: bool - var $t10: u64 - var $t11: bool - var $t12: u64 - 0: $t4 := 0 - 1: $t2 := $t4 - 2: $t5 := vector::length<#0>($t0) - 3: label L5 - 4: $t6 := <($t2, $t5) - 5: if ($t6) goto 6 else goto 18 - 6: label L1 - 7: label L2 - 8: $t7 := vector::borrow<#0>($t0, $t2) - 9: $t8 := ==($t7, $t1) - 10: if ($t8) goto 11 else goto 14 - 11: label L4 - 12: $t9 := true - 13: return ($t9, $t2) - 14: label L3 - 15: $t10 := 1 - 16: $t2 := +($t2, $t10) - 17: goto 3 - 18: label L0 - 19: $t11 := false - 20: $t12 := 0 - 21: return ($t11, $t12) +public fun ascii::push_char($t0|string: &mut ascii::String, $t1|char: ascii::Char) { + var $t2: &mut vector + var $t3: u8 + 0: $t2 := borrow_field.bytes($t0) + 1: $t3 := get_field.byte($t1) + 2: vector::push_back($t2, $t3) + 3: trace_local[string]($t0) + 4: return () } [variant baseline] -public fun vector::insert<#0>($t0|v: &mut vector<#0>, $t1|e: #0, $t2|i: u64) { - var $t3|len#1#0: u64 - var $t4: vector<#0> - var $t5: u64 - var $t6: bool - var $t7: u64 +public fun ascii::substring($t0|string: ascii::String, $t1|i: u64, $t2|j: u64): ascii::String { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: vector + var $t5|i#1#3: u64 + var $t6|i#1#6: u64 + var $t7|stop#1#3: u64 var $t8: bool var $t9: u64 - 0: $t4 := read_ref($t0) - 1: $t5 := vector::length<#0>($t4) - 2: $t6 := >($t2, $t5) - 3: if ($t6) goto 4 else goto 8 - 4: label L1 - 5: destroy($t0) - 6: $t7 := 131072 - 7: abort($t7) - 8: label L0 - 9: vector::push_back<#0>($t0, $t1) - 10: label L5 - 11: $t8 := <($t2, $t5) - 12: if ($t8) goto 13 else goto 19 + var $t10: bool + var $t11: u64 + var $t12: vector + var $t13: bool + var $t14: &mut vector + var $t15: vector + var $t16: u8 + var $t17: u64 + var $t18: vector + var $t19: ascii::String + 0: $t8 := <=($t1, $t2) + 1: if ($t8) goto 2 else goto 6 + 2: label L1 + 3: $t9 := ascii::length($t0) + 4: $t3 := <=($t2, $t9) + 5: goto 9 + 6: label L0 + 7: $t10 := false + 8: $t3 := $t10 + 9: label L2 + 10: if ($t3) goto 11 else goto 13 + 11: label L4 + 12: goto 16 13: label L3 - 14: label L4 - 15: vector::swap<#0>($t0, $t2, $t5) - 16: $t9 := 1 - 17: $t2 := +($t2, $t9) - 18: goto 10 - 19: label L2 - 20: destroy($t0) - 21: trace_local[v]($t0) - 22: return () + 14: $t11 := 65537 + 15: abort($t11) + 16: label L5 + 17: $t12 := [] + 18: $t4 := $t12 + 19: $t5 := $t1 + 20: label L8 + 21: $t13 := <($t5, $t2) + 22: if ($t13) goto 23 else goto 31 + 23: label L7 + 24: $t14 := borrow_local($t4) + 25: $t15 := get_field.bytes($t0) + 26: $t16 := vector::borrow($t15, $t5) + 27: vector::push_back($t14, $t16) + 28: $t17 := 1 + 29: $t5 := +($t5, $t17) + 30: goto 20 + 31: label L6 + 32: $t18 := move($t4) + 33: $t19 := pack ascii::String($t18) + 34: return $t19 } [variant baseline] -public fun vector::is_empty<#0>($t0|v: vector<#0>): bool { - var $t1: u64 - var $t2: u64 - var $t3: bool - 0: $t1 := vector::length<#0>($t0) - 1: $t2 := 0 - 2: $t3 := ==($t1, $t2) - 3: return $t3 +public fun ascii::to_lowercase($t0|string: ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: vector + var $t10|v#1#3: vector + var $t11: vector + var $t12: vector + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u8 + var $t17: &mut vector + var $t18: u8 + var $t19: u64 + var $t20: vector + var $t21: ascii::String + 0: $t11 := ascii::as_bytes($t0) + 1: $t12 := [] + 2: $t7 := $t12 + 3: $t13 := vector::length($t11) + 4: $t14 := 0 + 5: $t6 := $t14 + 6: label L2 + 7: $t15 := <($t6, $t13) + 8: if ($t15) goto 9 else goto 17 + 9: label L1 + 10: $t16 := vector::borrow($t11, $t6) + 11: $t17 := borrow_local($t7) + 12: $t18 := ascii::char_to_lowercase($t16) + 13: vector::push_back($t17, $t18) + 14: $t19 := 1 + 15: $t6 := +($t6, $t19) + 16: goto 6 + 17: label L0 + 18: $t20 := move($t7) + 19: $t21 := pack ascii::String($t20) + 20: return $t21 } [variant baseline] -public native fun vector::length<#0>($t0|v: vector<#0>): u64; +public fun ascii::to_uppercase($t0|string: ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: vector + var $t10|v#1#3: vector + var $t11: vector + var $t12: vector + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u8 + var $t17: &mut vector + var $t18: u8 + var $t19: u64 + var $t20: vector + var $t21: ascii::String + 0: $t11 := ascii::as_bytes($t0) + 1: $t12 := [] + 2: $t7 := $t12 + 3: $t13 := vector::length($t11) + 4: $t14 := 0 + 5: $t6 := $t14 + 6: label L2 + 7: $t15 := <($t6, $t13) + 8: if ($t15) goto 9 else goto 17 + 9: label L1 + 10: $t16 := vector::borrow($t11, $t6) + 11: $t17 := borrow_local($t7) + 12: $t18 := ascii::char_to_uppercase($t16) + 13: vector::push_back($t17, $t18) + 14: $t19 := 1 + 15: $t6 := +($t6, $t19) + 16: goto 6 + 17: label L0 + 18: $t20 := move($t7) + 19: $t21 := pack ascii::String($t20) + 20: return $t21 +} [variant baseline] -public native fun vector::pop_back<#0>($t0|v: &mut vector<#0>): #0; +public fun ascii::try_string($t0|bytes: vector): option::Option { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|tmp#$3: option::Option + var $t4|i#1#12: u64 + var $t5|i#1#9: u64 + var $t6|stop#1#9: u64 + var $t7|v#1#3: vector + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u8 + var $t12: bool + var $t13: bool + var $t14: bool + var $t15: u64 + var $t16: bool + var $t17: ascii::String + 0: $t8 := vector::length($t0) + 1: $t9 := 0 + 2: $t5 := $t9 + 3: label L5 + 4: $t10 := <($t5, $t8) + 5: if ($t10) goto 6 else goto 19 + 6: label L1 + 7: $t11 := vector::borrow($t0, $t5) + 8: $t12 := ascii::is_valid_char($t11) + 9: $t13 := !($t12) + 10: if ($t13) goto 11 else goto 15 + 11: label L3 + 12: $t14 := false + 13: $t2 := $t14 + 14: goto 22 + 15: label L2 + 16: $t15 := 1 + 17: $t5 := +($t5, $t15) + 18: goto 3 + 19: label L0 + 20: $t16 := true + 21: $t2 := $t16 + 22: label L4 + 23: if ($t2) goto 24 else goto 28 + 24: label L7 + 25: $t17 := pack ascii::String($t0) + 26: $t3 := option::some($t17) + 27: goto 30 + 28: label L6 + 29: $t3 := option::none() + 30: label L8 + 31: return $t3 +} [variant baseline] -public native fun vector::push_back<#0>($t0|v: &mut vector<#0>, $t1|e: #0); +public fun string::append($t0|s: &mut string::String, $t1|r: string::String) { + var $t2: &mut vector + var $t3: vector + 0: $t2 := borrow_field.bytes($t0) + 1: $t3 := get_field.bytes($t1) + 2: vector::append($t2, $t3) + 3: trace_local[s]($t0) + 4: return () +} [variant baseline] -public fun vector::remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { - var $t2|tmp#$2: u64 - var $t3|tmp#$3: &mut vector<#0> - var $t4|len#1#0: u64 - var $t5: vector<#0> - var $t6: u64 - var $t7: bool - var $t8: u64 +public fun string::index_of($t0|s: string::String, $t1|r: string::String): u64 { + var $t2: vector + var $t3: vector + var $t4: u64 + 0: $t2 := get_field.bytes($t0) + 1: $t3 := get_field.bytes($t1) + 2: $t4 := string::internal_index_of($t2, $t3) + 3: return $t4 +} + + +[variant baseline] +public fun string::insert($t0|s: &mut string::String, $t1|at: u64, $t2|o: string::String) { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: vector + var $t5|end#1#0: string::String + var $t6|front#1#0: string::String + var $t7|l#1#0: u64 + var $t8: vector var $t9: u64 - var $t10: u64 + var $t10: bool var $t11: bool var $t12: u64 - var $t13: u64 + var $t13: string::String var $t14: u64 - var $t15: #0 - 0: $t5 := read_ref($t0) - 1: $t6 := vector::length<#0>($t5) - 2: $t7 := >=($t1, $t6) - 3: if ($t7) goto 4 else goto 8 + var $t15: string::String + var $t16: u64 + var $t17: string::String + var $t18: string::String + var $t19: &mut string::String + var $t20: &mut string::String + var $t21: string::String + 0: $t8 := get_field.bytes($t0) + 1: $t9 := vector::length($t8) + 2: $t10 := <=($t1, $t9) + 3: if ($t10) goto 4 else goto 7 4: label L1 - 5: destroy($t0) - 6: $t8 := 131072 - 7: abort($t8) - 8: label L0 - 9: $t9 := 1 - 10: $t10 := -($t6, $t9) - 11: label L5 - 12: $t11 := <($t1, $t10) - 13: if ($t11) goto 14 else goto 22 + 5: $t3 := string::internal_is_char_boundary($t8, $t1) + 6: goto 10 + 7: label L0 + 8: $t11 := false + 9: $t3 := $t11 + 10: label L2 + 11: if ($t3) goto 12 else goto 14 + 12: label L4 + 13: goto 18 14: label L3 - 15: label L4 - 16: $t12 := copy($t1) - 17: $t13 := 1 - 18: $t14 := +($t1, $t13) - 19: $t1 := $t14 - 20: vector::swap<#0>($t0, $t12, $t14) - 21: goto 11 - 22: label L2 - 23: $t15 := vector::pop_back<#0>($t0) - 24: trace_local[v]($t0) - 25: return $t15 + 15: destroy($t0) + 16: $t12 := 2 + 17: abort($t12) + 18: label L5 + 19: $t13 := read_ref($t0) + 20: $t14 := string::length($t13) + 21: $t15 := read_ref($t0) + 22: $t16 := 0 + 23: $t6 := string::substring($t15, $t16, $t1) + 24: $t17 := read_ref($t0) + 25: $t18 := string::substring($t17, $t1, $t14) + 26: $t19 := borrow_local($t6) + 27: string::append($t19, $t2) + 28: $t20 := borrow_local($t6) + 29: string::append($t20, $t18) + 30: $t21 := move($t6) + 31: write_ref($t0, $t21) + 32: trace_local[s]($t0) + 33: return () } [variant baseline] -public fun vector::reverse<#0>($t0|v: &mut vector<#0>) { - var $t1|back_index#1#0: u64 - var $t2|front_index#1#0: u64 - var $t3|len#1#0: u64 - var $t4: vector<#0> - var $t5: u64 - var $t6: u64 - var $t7: bool - var $t8: u64 - var $t9: u64 - var $t10: bool - var $t11: u64 - var $t12: u64 - 0: $t4 := read_ref($t0) - 1: $t5 := vector::length<#0>($t4) - 2: $t6 := 0 - 3: $t7 := ==($t5, $t6) - 4: if ($t7) goto 5 else goto 9 - 5: label L1 - 6: destroy($t0) - 7: trace_local[v]($t0) - 8: return () - 9: label L0 - 10: $t8 := 0 - 11: $t2 := $t8 - 12: $t9 := 1 - 13: $t1 := -($t5, $t9) - 14: label L5 - 15: $t10 := <($t2, $t1) - 16: if ($t10) goto 17 else goto 25 - 17: label L3 - 18: label L4 - 19: vector::swap<#0>($t0, $t2, $t1) - 20: $t11 := 1 - 21: $t2 := +($t2, $t11) - 22: $t12 := 1 - 23: $t1 := -($t1, $t12) - 24: goto 14 - 25: label L2 - 26: destroy($t0) - 27: trace_local[v]($t0) - 28: return () +public fun string::is_empty($t0|s: string::String): bool { + var $t1: vector + var $t2: bool + 0: $t1 := get_field.bytes($t0) + 1: $t2 := vector::is_empty($t1) + 2: return $t2 } [variant baseline] -public fun vector::singleton<#0>($t0|e: #0): vector<#0> { - var $t1|v#1#0: vector<#0> - var $t2: &mut vector<#0> - var $t3: vector<#0> - 0: $t1 := vector::empty<#0>() - 1: $t2 := borrow_local($t1) - 2: vector::push_back<#0>($t2, $t0) - 3: $t3 := move($t1) - 4: return $t3 +public fun string::length($t0|s: string::String): u64 { + var $t1: vector + var $t2: u64 + 0: $t1 := get_field.bytes($t0) + 1: $t2 := vector::length($t1) + 2: return $t2 } [variant baseline] -public native fun vector::swap<#0>($t0|v: &mut vector<#0>, $t1|i: u64, $t2|j: u64); +public fun string::as_bytes($t0|s: string::String): vector { + var $t1: vector + 0: $t1 := get_field.bytes($t0) + 1: return $t1 +} [variant baseline] -public fun vector::swap_remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { - var $t2|last_idx#1#0: u64 - var $t3: vector<#0> - var $t4: bool - var $t5: bool - var $t6: u64 - var $t7: vector<#0> - var $t8: u64 +public fun string::into_bytes($t0|s: string::String): vector { + var $t1: vector + 0: $t1 := unpack string::String($t0) + 1: return $t1 +} + + +[variant baseline] +public fun string::bytes($t0|s: string::String): vector { + var $t1: vector + 0: $t1 := string::as_bytes($t0) + 1: return $t1 +} + + +[variant baseline] +public fun string::substring($t0|s: string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3|tmp#$3: bool + var $t4|tmp#$4: bool + var $t5|tmp#$5: bool + var $t6|bytes#1#0: vector + var $t7|l#1#0: u64 + var $t8: vector var $t9: u64 - var $t10: u64 - var $t11: #0 - 0: $t3 := read_ref($t0) - 1: $t4 := vector::is_empty<#0>($t3) - 2: $t5 := !($t4) - 3: if ($t5) goto 4 else goto 6 + var $t10: bool + var $t11: bool + var $t12: bool + var $t13: bool + var $t14: u64 + var $t15: vector + var $t16: string::String + 0: $t8 := get_field.bytes($t0) + 1: $t9 := vector::length($t8) + 2: $t10 := <=($t2, $t9) + 3: if ($t10) goto 4 else goto 7 4: label L1 - 5: goto 10 - 6: label L0 - 7: destroy($t0) - 8: $t6 := 131072 - 9: abort($t6) + 5: $t3 := <=($t1, $t2) + 6: goto 10 + 7: label L0 + 8: $t11 := false + 9: $t3 := $t11 10: label L2 - 11: $t7 := read_ref($t0) - 12: $t8 := vector::length<#0>($t7) - 13: $t9 := 1 - 14: $t10 := -($t8, $t9) - 15: vector::swap<#0>($t0, $t1, $t10) - 16: $t11 := vector::pop_back<#0>($t0) - 17: trace_local[v]($t0) - 18: return $t11 + 11: if ($t3) goto 12 else goto 15 + 12: label L4 + 13: $t4 := string::internal_is_char_boundary($t8, $t1) + 14: goto 18 + 15: label L3 + 16: $t12 := false + 17: $t4 := $t12 + 18: label L5 + 19: if ($t4) goto 20 else goto 23 + 20: label L7 + 21: $t5 := string::internal_is_char_boundary($t8, $t2) + 22: goto 26 + 23: label L6 + 24: $t13 := false + 25: $t5 := $t13 + 26: label L8 + 27: if ($t5) goto 28 else goto 30 + 28: label L10 + 29: goto 33 + 30: label L9 + 31: $t14 := 2 + 32: abort($t14) + 33: label L11 + 34: $t15 := string::internal_sub_string($t8, $t1, $t2) + 35: $t16 := pack string::String($t15) + 36: return $t16 +} + + +[variant baseline] +public fun string::append_utf8($t0|s: &mut string::String, $t1|bytes: vector) { + var $t2: string::String + 0: $t2 := string::utf8($t1) + 1: string::append($t0, $t2) + 2: trace_local[s]($t0) + 3: return () +} + + +[variant baseline] +public fun string::from_ascii($t0|s: ascii::String): string::String { + var $t1: vector + var $t2: string::String + 0: $t1 := ascii::into_bytes($t0) + 1: $t2 := pack string::String($t1) + 2: return $t2 +} + + +[variant baseline] +native fun string::internal_check_utf8($t0|v: vector): bool; + + +[variant baseline] +native fun string::internal_index_of($t0|v: vector, $t1|r: vector): u64; + + +[variant baseline] +native fun string::internal_is_char_boundary($t0|v: vector, $t1|i: u64): bool; + + +[variant baseline] +native fun string::internal_sub_string($t0|v: vector, $t1|i: u64, $t2|j: u64): vector; + + +[variant baseline] +public fun string::sub_string($t0|s: string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3: string::String + 0: $t3 := string::substring($t0, $t1, $t2) + 1: return $t3 +} + + +[variant baseline] +public fun string::to_ascii($t0|s: string::String): ascii::String { + var $t1: vector + var $t2: ascii::String + 0: $t1 := unpack string::String($t0) + 1: $t2 := ascii::string($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::try_utf8($t0|bytes: vector): option::Option { + var $t1|tmp#$1: option::Option + var $t2: bool + var $t3: string::String + 0: $t2 := string::internal_check_utf8($t0) + 1: if ($t2) goto 2 else goto 6 + 2: label L1 + 3: $t3 := pack string::String($t0) + 4: $t1 := option::some($t3) + 5: goto 8 + 6: label L0 + 7: $t1 := option::none() + 8: label L2 + 9: return $t1 +} + + +[variant baseline] +public fun string::utf8($t0|bytes: vector): string::String { + var $t1: bool + var $t2: u64 + var $t3: string::String + 0: $t1 := string::internal_check_utf8($t0) + 1: if ($t1) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t2 := 1 + 6: abort($t2) + 7: label L2 + 8: $t3 := pack string::String($t0) + 9: return $t3 } @@ -908,6 +4422,10 @@ fun vector::borrow_mut[baseline] borrowed_by: Reference($t0) -> {([], Return(0))} borrows_from: Return(0) -> {([], Reference($t0))} +fun option::borrow_mut[baseline] +borrowed_by: Reference($t0) -> {(.vec (vector<#0>)/[], Return(0))} +borrows_from: Return(0) -> {(.vec (vector<#0>)/[], Reference($t0))} + fun MultiLayerCalling::inner[baseline] borrowed_by: Reference($t0) -> {(.v (vector)/[], Return(0))} borrows_from: Return(0) -> {(.v (vector)/[], Reference($t0))} diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/function_call.move b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/function_call.move index 003dbbcee8dab..b2f766c47e846 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/function_call.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/function_call.move @@ -1,13 +1,17 @@ +// dep: ../move-stdlib/sources/macros.move +// dep: ../move-stdlib/sources/u64.move +// dep: ../move-stdlib/sources/option.move +// dep: ../move-stdlib/sources/ascii.move +// dep: ../move-stdlib/sources/string.move // dep: ../move-stdlib/sources/vector.move module 0x2::MultiLayerCalling { - use std::vector; - struct HasVector { + public struct HasVector { v: vector, } - struct HasAnotherVector { + public struct HasAnotherVector { v: vector, } diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/hyper_edge.exp b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/hyper_edge.exp index e367f9ebff288..f3986a7ff742b 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/hyper_edge.exp +++ b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/hyper_edge.exp @@ -1,5 +1,339 @@ ============ initial translation from Move ================ +[variant baseline] +public fun u64::diff($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := >($t7, $t8) + 7: if ($t9) goto 8 else goto 14 + 8: label L1 + 9: $t10 := move($t3) + 10: $t11 := move($t4) + 11: $t12 := -($t10, $t11) + 12: $t2 := $t12 + 13: goto 20 + 14: label L0 + 15: $t13 := move($t4) + 16: $t14 := move($t3) + 17: $t15 := -($t13, $t14) + 18: $t2 := $t15 + 19: goto 20 + 20: label L2 + 21: $t16 := move($t2) + 22: return $t16 +} + + +[variant baseline] +public fun u64::divide_and_round_up($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: u64 + var $t10: u64 + var $t11: bool + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := %($t7, $t8) + 7: $t10 := 0 + 8: $t11 := ==($t9, $t10) + 9: if ($t11) goto 10 else goto 16 + 10: label L1 + 11: $t12 := move($t3) + 12: $t13 := move($t4) + 13: $t14 := /($t12, $t13) + 14: $t2 := $t14 + 15: goto 24 + 16: label L0 + 17: $t15 := move($t3) + 18: $t16 := move($t4) + 19: $t17 := /($t15, $t16) + 20: $t18 := 1 + 21: $t19 := +($t17, $t18) + 22: $t2 := $t19 + 23: goto 24 + 24: label L2 + 25: $t20 := move($t2) + 26: return $t20 +} + + +[variant baseline] +public fun u64::max($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := >($t7, $t8) + 7: if ($t9) goto 8 else goto 12 + 8: label L1 + 9: $t10 := move($t3) + 10: $t2 := $t10 + 11: goto 16 + 12: label L0 + 13: $t11 := move($t4) + 14: $t2 := $t11 + 15: goto 16 + 16: label L2 + 17: $t12 := move($t2) + 18: return $t12 +} + + +[variant baseline] +public fun u64::min($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := <($t7, $t8) + 7: if ($t9) goto 8 else goto 12 + 8: label L1 + 9: $t10 := move($t3) + 10: $t2 := $t10 + 11: goto 16 + 12: label L0 + 13: $t11 := move($t4) + 14: $t2 := $t11 + 15: goto 16 + 16: label L2 + 17: $t12 := move($t2) + 18: return $t12 +} + + +[variant baseline] +public fun u64::pow($t0|base: u64, $t1|exponent: u8): u64 { + var $t2|base#1#1: u64 + var $t3|exponent#1#1: u8 + var $t4|res#1#1: u64 + var $t5: u64 + var $t6: u8 + var $t7: u64 + var $t8: u8 + var $t9: u8 + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: bool + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u8 + var $t20: u8 + var $t21: u8 + var $t22: u64 + var $t23: u64 + var $t24: u64 + var $t25: u8 + var $t26: u8 + var $t27: u8 + var $t28: u64 + 0: $t5 := move($t0) + 1: $t2 := $t5 + 2: $t6 := move($t1) + 3: $t3 := $t6 + 4: $t7 := 1 + 5: $t4 := $t7 + 6: goto 7 + 7: label L5 + 8: $t8 := copy($t3) + 9: $t9 := 1 + 10: $t10 := >=($t8, $t9) + 11: if ($t10) goto 12 else goto 41 + 12: label L1 + 13: goto 14 + 14: label L2 + 15: $t11 := copy($t3) + 16: $t12 := 2 + 17: $t13 := %($t11, $t12) + 18: $t14 := 0 + 19: $t15 := ==($t13, $t14) + 20: if ($t15) goto 21 else goto 31 + 21: label L4 + 22: $t16 := copy($t2) + 23: $t17 := move($t2) + 24: $t18 := *($t16, $t17) + 25: $t2 := $t18 + 26: $t19 := move($t3) + 27: $t20 := 2 + 28: $t21 := /($t19, $t20) + 29: $t3 := $t21 + 30: goto 7 + 31: label L3 + 32: $t22 := move($t4) + 33: $t23 := copy($t2) + 34: $t24 := *($t22, $t23) + 35: $t4 := $t24 + 36: $t25 := move($t3) + 37: $t26 := 1 + 38: $t27 := -($t25, $t26) + 39: $t3 := $t27 + 40: goto 7 + 41: label L0 + 42: $t28 := move($t4) + 43: return $t28 +} + + +[variant baseline] +public fun u64::sqrt($t0|x: u64): u64 { + var $t1|bit#1#1: u128 + var $t2|res#1#1: u128 + var $t3|x#1#1: u64 + var $t4|x#2#1: u128 + var $t5: u64 + var $t6: u128 + var $t7: u128 + var $t8: u64 + var $t9: u128 + var $t10: u128 + var $t11: u128 + var $t12: bool + var $t13: u128 + var $t14: u128 + var $t15: u128 + var $t16: u128 + var $t17: bool + var $t18: u128 + var $t19: u128 + var $t20: u128 + var $t21: u128 + var $t22: u128 + var $t23: u128 + var $t24: u8 + var $t25: u128 + var $t26: u128 + var $t27: u128 + var $t28: u128 + var $t29: u8 + var $t30: u128 + var $t31: u128 + var $t32: u8 + var $t33: u128 + var $t34: u128 + var $t35: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := 18446744073709551616 + 3: $t1 := $t6 + 4: $t7 := 0 + 5: $t2 := $t7 + 6: $t8 := move($t3) + 7: $t9 := (u128)($t8) + 8: $t4 := $t9 + 9: goto 10 + 10: label L6 + 11: $t10 := copy($t1) + 12: $t11 := 0 + 13: $t12 := !=($t10, $t11) + 14: if ($t12) goto 15 else goto 50 + 15: label L1 + 16: goto 17 + 17: label L2 + 18: $t13 := copy($t4) + 19: $t14 := copy($t2) + 20: $t15 := copy($t1) + 21: $t16 := +($t14, $t15) + 22: $t17 := >=($t13, $t16) + 23: if ($t17) goto 24 else goto 38 + 24: label L4 + 25: $t18 := move($t4) + 26: $t19 := copy($t2) + 27: $t20 := copy($t1) + 28: $t21 := +($t19, $t20) + 29: $t22 := -($t18, $t21) + 30: $t4 := $t22 + 31: $t23 := move($t2) + 32: $t24 := 1 + 33: $t25 := >>($t23, $t24) + 34: $t26 := copy($t1) + 35: $t27 := +($t25, $t26) + 36: $t2 := $t27 + 37: goto 44 + 38: label L3 + 39: $t28 := move($t2) + 40: $t29 := 1 + 41: $t30 := >>($t28, $t29) + 42: $t2 := $t30 + 43: goto 44 + 44: label L5 + 45: $t31 := move($t1) + 46: $t32 := 2 + 47: $t33 := >>($t31, $t32) + 48: $t1 := $t33 + 49: goto 10 + 50: label L0 + 51: $t34 := move($t2) + 52: $t35 := (u64)($t34) + 53: return $t35 +} + + [variant baseline] public fun vector::append<#0>($t0|lhs: &mut vector<#0>, $t1|other: vector<#0>) { var $t2: &mut vector<#0> @@ -231,27 +565,25 @@ public fun vector::insert<#0>($t0|v: &mut vector<#0>, $t1|e: #0, $t2|i: u64) { 15: $t13 := move($t1) 16: vector::push_back<#0>($t12, $t13) 17: goto 18 - 18: label L5 + 18: label L4 19: $t14 := copy($t2) 20: $t15 := copy($t3) 21: $t16 := <($t14, $t15) - 22: if ($t16) goto 23 else goto 35 + 22: if ($t16) goto 23 else goto 33 23: label L3 - 24: goto 25 - 25: label L4 - 26: $t17 := copy($t0) - 27: $t18 := copy($t2) - 28: $t19 := copy($t3) - 29: vector::swap<#0>($t17, $t18, $t19) - 30: $t20 := move($t2) - 31: $t21 := 1 - 32: $t22 := +($t20, $t21) - 33: $t2 := $t22 - 34: goto 18 - 35: label L2 - 36: $t23 := move($t0) - 37: destroy($t23) - 38: return () + 24: $t17 := copy($t0) + 25: $t18 := copy($t2) + 26: $t19 := copy($t3) + 27: vector::swap<#0>($t17, $t18, $t19) + 28: $t20 := move($t2) + 29: $t21 := 1 + 30: $t22 := +($t20, $t21) + 31: $t2 := $t22 + 32: goto 18 + 33: label L2 + 34: $t23 := move($t0) + 35: destroy($t23) + 36: return () } @@ -329,31 +661,29 @@ public fun vector::remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { 16: $t15 := -($t13, $t14) 17: $t4 := $t15 18: goto 19 - 19: label L5 + 19: label L4 20: $t16 := copy($t1) 21: $t17 := copy($t4) 22: $t18 := <($t16, $t17) - 23: if ($t18) goto 24 else goto 40 + 23: if ($t18) goto 24 else goto 38 24: label L3 - 25: goto 26 - 26: label L4 - 27: $t19 := copy($t0) - 28: $t3 := $t19 - 29: $t20 := copy($t1) - 30: $t2 := $t20 - 31: $t21 := move($t1) - 32: $t22 := 1 - 33: $t23 := +($t21, $t22) - 34: $t1 := $t23 - 35: $t24 := move($t3) - 36: $t25 := move($t2) - 37: $t26 := copy($t1) - 38: vector::swap<#0>($t24, $t25, $t26) - 39: goto 19 - 40: label L2 - 41: $t27 := move($t0) - 42: $t28 := vector::pop_back<#0>($t27) - 43: return $t28 + 25: $t19 := copy($t0) + 26: $t3 := $t19 + 27: $t20 := copy($t1) + 28: $t2 := $t20 + 29: $t21 := move($t1) + 30: $t22 := 1 + 31: $t23 := +($t21, $t22) + 32: $t1 := $t23 + 33: $t24 := move($t3) + 34: $t25 := move($t2) + 35: $t26 := copy($t1) + 36: vector::swap<#0>($t24, $t25, $t26) + 37: goto 19 + 38: label L2 + 39: $t27 := move($t0) + 40: $t28 := vector::pop_back<#0>($t27) + 41: return $t28 } @@ -406,31 +736,29 @@ public fun vector::reverse<#0>($t0|v: &mut vector<#0>) { 17: $t14 := -($t12, $t13) 18: $t1 := $t14 19: goto 20 - 20: label L5 + 20: label L4 21: $t15 := copy($t2) 22: $t16 := copy($t1) 23: $t17 := <($t15, $t16) - 24: if ($t17) goto 25 else goto 41 + 24: if ($t17) goto 25 else goto 39 25: label L3 - 26: goto 27 - 27: label L4 - 28: $t18 := copy($t0) - 29: $t19 := copy($t2) - 30: $t20 := copy($t1) - 31: vector::swap<#0>($t18, $t19, $t20) - 32: $t21 := move($t2) - 33: $t22 := 1 - 34: $t23 := +($t21, $t22) - 35: $t2 := $t23 - 36: $t24 := move($t1) - 37: $t25 := 1 - 38: $t26 := -($t24, $t25) - 39: $t1 := $t26 - 40: goto 20 - 41: label L2 - 42: $t27 := move($t0) - 43: destroy($t27) - 44: return () + 26: $t18 := copy($t0) + 27: $t19 := copy($t2) + 28: $t20 := copy($t1) + 29: vector::swap<#0>($t18, $t19, $t20) + 30: $t21 := move($t2) + 31: $t22 := 1 + 32: $t23 := +($t21, $t22) + 33: $t2 := $t23 + 34: $t24 := move($t1) + 35: $t25 := 1 + 36: $t26 := -($t24, $t25) + 37: $t1 := $t26 + 38: goto 20 + 39: label L2 + 40: $t27 := move($t0) + 41: destroy($t27) + 42: return () } @@ -504,376 +832,3562 @@ public fun vector::swap_remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { [variant baseline] -public fun Collection::borrow_mut<#0>($t0|c: &mut Collection::Collection<#0>, $t1|i: u64): &mut #0 { - var $t2: &mut Collection::Collection<#0> - var $t3: &mut vector<#0> +public fun option::borrow<#0>($t0|t: &option::Option<#0>): � { + var $t1: &option::Option<#0> + var $t2: bool + var $t3: &option::Option<#0> var $t4: u64 - var $t5: &mut #0 + var $t5: &option::Option<#0> + var $t6: &vector<#0> + var $t7: u64 + var $t8: � + 0: $t1 := copy($t0) + 1: $t2 := option::is_some<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 10 + 5: label L0 + 6: $t3 := move($t0) + 7: destroy($t3) + 8: $t4 := 262145 + 9: abort($t4) + 10: label L2 + 11: $t5 := move($t0) + 12: $t6 := borrow_field>.vec($t5) + 13: $t7 := 0 + 14: $t8 := vector::borrow<#0>($t6, $t7) + 15: return $t8 +} + + +[variant baseline] +public fun option::borrow_mut<#0>($t0|t: &mut option::Option<#0>): &mut #0 { + var $t1: &mut option::Option<#0> + var $t2: &option::Option<#0> + var $t3: bool + var $t4: &mut option::Option<#0> + var $t5: u64 + var $t6: &mut option::Option<#0> + var $t7: &mut vector<#0> + var $t8: u64 + var $t9: &mut #0 + 0: $t1 := copy($t0) + 1: $t2 := freeze_ref($t1) + 2: $t3 := option::is_some<#0>($t2) + 3: if ($t3) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t4 := move($t0) + 8: destroy($t4) + 9: $t5 := 262145 + 10: abort($t5) + 11: label L2 + 12: $t6 := move($t0) + 13: $t7 := borrow_field>.vec($t6) + 14: $t8 := 0 + 15: $t9 := vector::borrow_mut<#0>($t7, $t8) + 16: return $t9 +} + + +[variant baseline] +public fun option::contains<#0>($t0|t: &option::Option<#0>, $t1|e_ref: �): bool { + var $t2: &option::Option<#0> + var $t3: &vector<#0> + var $t4: � + var $t5: bool 0: $t2 := move($t0) - 1: $t3 := borrow_field>.items($t2) + 1: $t3 := borrow_field>.vec($t2) 2: $t4 := move($t1) - 3: $t5 := vector::borrow_mut<#0>($t3, $t4) + 3: $t5 := vector::contains<#0>($t3, $t4) 4: return $t5 } [variant baseline] -public fun Collection::make_collection<#0>(): Collection::Collection<#0> { - var $t0: vector<#0> - var $t1: address - var $t2: Collection::Collection<#0> - 0: $t0 := vector::empty<#0>() - 1: $t1 := 0x2 - 2: $t2 := pack Collection::Collection<#0>($t0, $t1) - 3: return $t2 +public fun option::swap<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): #0 { + var $t2|old_value#1#0: #0 + var $t3|vec_ref#1#0: &mut vector<#0> + var $t4: &mut option::Option<#0> + var $t5: &option::Option<#0> + var $t6: bool + var $t7: &mut option::Option<#0> + var $t8: u64 + var $t9: &mut option::Option<#0> + var $t10: &mut vector<#0> + var $t11: &mut vector<#0> + var $t12: #0 + var $t13: &mut vector<#0> + var $t14: #0 + var $t15: #0 + 0: $t4 := copy($t0) + 1: $t5 := freeze_ref($t4) + 2: $t6 := option::is_some<#0>($t5) + 3: if ($t6) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t7 := move($t0) + 8: destroy($t7) + 9: $t8 := 262145 + 10: abort($t8) + 11: label L2 + 12: $t9 := move($t0) + 13: $t10 := borrow_field>.vec($t9) + 14: $t3 := $t10 + 15: $t11 := copy($t3) + 16: $t12 := vector::pop_back<#0>($t11) + 17: $t2 := $t12 + 18: $t13 := move($t3) + 19: $t14 := move($t1) + 20: vector::push_back<#0>($t13, $t14) + 21: $t15 := move($t2) + 22: return $t15 } [variant baseline] -public fun Test::foo<#0>($t0|i: u64) { - var $t1|c#1#0: Collection::Collection> - var $t2|t#1#0: &mut Test::Token<#0> - var $t3: Collection::Collection> - var $t4: &mut Collection::Collection> - var $t5: u64 - var $t6: &mut Test::Token<#0> - var $t7: u64 - var $t8: &mut Test::Token<#0> - var $t9: &mut u64 - 0: $t3 := Collection::make_collection>() - 1: $t1 := $t3 - 2: $t4 := borrow_local($t1) - 3: $t5 := move($t0) - 4: $t6 := Collection::borrow_mut>($t4, $t5) - 5: $t2 := $t6 - 6: $t7 := 0 - 7: $t8 := move($t2) - 8: $t9 := borrow_field>.value($t8) - 9: write_ref($t9, $t7) - 10: return () +public fun option::borrow_with_default<#0>($t0|t: &option::Option<#0>, $t1|default_ref: �): � { + var $t2|tmp#$2: � + var $t3|vec_ref#1#0: &vector<#0> + var $t4: &option::Option<#0> + var $t5: &vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &vector<#0> + var $t9: � + var $t10: � + var $t11: &vector<#0> + var $t12: u64 + var $t13: � + var $t14: � + 0: $t4 := move($t0) + 1: $t5 := borrow_field>.vec($t4) + 2: $t3 := $t5 + 3: $t6 := copy($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 12 + 6: label L1 + 7: $t8 := move($t3) + 8: destroy($t8) + 9: $t9 := move($t1) + 10: $t2 := $t9 + 11: goto 20 + 12: label L0 + 13: $t10 := move($t1) + 14: destroy($t10) + 15: $t11 := move($t3) + 16: $t12 := 0 + 17: $t13 := vector::borrow<#0>($t11, $t12) + 18: $t2 := $t13 + 19: goto 20 + 20: label L2 + 21: $t14 := move($t2) + 22: return $t14 } -============ after pipeline `borrow` ================ [variant baseline] -public fun vector::append<#0>($t0|lhs: &mut vector<#0>, $t1|other: vector<#0>) { - var $t2: &mut vector<#0> - var $t3: vector<#0> - var $t4: bool - var $t5: bool - var $t6: &mut vector<#0> - var $t7: #0 - var $t8: vector<#0> - 0: $t2 := borrow_local($t1) - 1: vector::reverse<#0>($t2) - 2: label L3 - 3: $t3 := copy($t1) - 4: $t4 := vector::is_empty<#0>($t3) - 5: $t5 := !($t4) - 6: if ($t5) goto 7 else goto 13 - 7: label L1 +public fun option::destroy_none<#0>($t0|t: option::Option<#0>) { + var $t1: &option::Option<#0> + var $t2: bool + var $t3: u64 + var $t4: option::Option<#0> + var $t5: vector<#0> + 0: $t1 := borrow_local($t0) + 1: $t2 := option::is_none<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 262144 + 7: abort($t3) 8: label L2 - 9: $t6 := borrow_local($t1) - 10: $t7 := vector::pop_back<#0>($t6) - 11: vector::push_back<#0>($t0, $t7) - 12: goto 2 - 13: label L0 - 14: destroy($t0) - 15: $t8 := move($t1) - 16: vector::destroy_empty<#0>($t8) - 17: trace_local[lhs]($t0) - 18: return () + 9: $t4 := move($t0) + 10: $t5 := unpack option::Option<#0>($t4) + 11: vector::destroy_empty<#0>($t5) + 12: return () } [variant baseline] -public native fun vector::borrow<#0>($t0|v: vector<#0>, $t1|i: u64): #0; +public fun option::destroy_some<#0>($t0|t: option::Option<#0>): #0 { + var $t1|elem#1#0: #0 + var $t2|vec#1#0: vector<#0> + var $t3: &option::Option<#0> + var $t4: bool + var $t5: u64 + var $t6: option::Option<#0> + var $t7: vector<#0> + var $t8: &mut vector<#0> + var $t9: #0 + var $t10: vector<#0> + var $t11: #0 + 0: $t3 := borrow_local($t0) + 1: $t4 := option::is_some<#0>($t3) + 2: if ($t4) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t5 := 262145 + 7: abort($t5) + 8: label L2 + 9: $t6 := move($t0) + 10: $t7 := unpack option::Option<#0>($t6) + 11: $t2 := $t7 + 12: $t8 := borrow_local($t2) + 13: $t9 := vector::pop_back<#0>($t8) + 14: $t1 := $t9 + 15: $t10 := move($t2) + 16: vector::destroy_empty<#0>($t10) + 17: $t11 := move($t1) + 18: return $t11 +} [variant baseline] -public native fun vector::borrow_mut<#0>($t0|v: &mut vector<#0>, $t1|i: u64): &mut #0; +public fun option::destroy_with_default<#0>($t0|t: option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec#1#0: vector<#0> + var $t4: option::Option<#0> + var $t5: vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: #0 + var $t9: &mut vector<#0> + var $t10: #0 + var $t11: #0 + 0: $t4 := move($t0) + 1: $t5 := unpack option::Option<#0>($t4) + 2: $t3 := $t5 + 3: $t6 := borrow_local($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 10 + 6: label L1 + 7: $t8 := move($t1) + 8: $t2 := $t8 + 9: goto 15 + 10: label L0 + 11: $t9 := borrow_local($t3) + 12: $t10 := vector::pop_back<#0>($t9) + 13: $t2 := $t10 + 14: goto 15 + 15: label L2 + 16: $t11 := move($t2) + 17: return $t11 +} [variant baseline] -public fun vector::contains<#0>($t0|v: vector<#0>, $t1|e: #0): bool { - var $t2|i#1#0: u64 - var $t3|len#1#0: u64 - var $t4: u64 +public fun option::extract<#0>($t0|t: &mut option::Option<#0>): #0 { + var $t1: &mut option::Option<#0> + var $t2: &option::Option<#0> + var $t3: bool + var $t4: &mut option::Option<#0> var $t5: u64 - var $t6: bool - var $t7: #0 - var $t8: bool - var $t9: bool - var $t10: u64 - var $t11: bool - 0: $t4 := 0 - 1: $t2 := $t4 - 2: $t5 := vector::length<#0>($t0) - 3: label L5 - 4: $t6 := <($t2, $t5) - 5: if ($t6) goto 6 else goto 18 - 6: label L1 - 7: label L2 - 8: $t7 := vector::borrow<#0>($t0, $t2) - 9: $t8 := ==($t7, $t1) + var $t6: &mut option::Option<#0> + var $t7: &mut vector<#0> + var $t8: #0 + 0: $t1 := copy($t0) + 1: $t2 := freeze_ref($t1) + 2: $t3 := option::is_some<#0>($t2) + 3: if ($t3) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t4 := move($t0) + 8: destroy($t4) + 9: $t5 := 262145 + 10: abort($t5) + 11: label L2 + 12: $t6 := move($t0) + 13: $t7 := borrow_field>.vec($t6) + 14: $t8 := vector::pop_back<#0>($t7) + 15: return $t8 +} + + +[variant baseline] +public fun option::fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0) { + var $t2|vec_ref#1#0: &mut vector<#0> + var $t3: &mut option::Option<#0> + var $t4: &mut vector<#0> + var $t5: &mut vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &mut vector<#0> + var $t9: u64 + var $t10: &mut vector<#0> + var $t11: #0 + 0: $t3 := move($t0) + 1: $t4 := borrow_field>.vec($t3) + 2: $t2 := $t4 + 3: $t5 := copy($t2) + 4: $t6 := freeze_ref($t5) + 5: $t7 := vector::is_empty<#0>($t6) + 6: if ($t7) goto 7 else goto 9 + 7: label L1 + 8: goto 14 + 9: label L0 + 10: $t8 := move($t2) + 11: destroy($t8) + 12: $t9 := 262144 + 13: abort($t9) + 14: label L2 + 15: $t10 := move($t2) + 16: $t11 := move($t1) + 17: vector::push_back<#0>($t10, $t11) + 18: return () +} + + +[variant baseline] +public fun option::get_with_default<#0>($t0|t: &option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec_ref#1#0: &vector<#0> + var $t4: &option::Option<#0> + var $t5: &vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &vector<#0> + var $t9: #0 + var $t10: &vector<#0> + var $t11: u64 + var $t12: � + var $t13: #0 + var $t14: #0 + 0: $t4 := move($t0) + 1: $t5 := borrow_field>.vec($t4) + 2: $t3 := $t5 + 3: $t6 := copy($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 12 + 6: label L1 + 7: $t8 := move($t3) + 8: destroy($t8) + 9: $t9 := move($t1) + 10: $t2 := $t9 + 11: goto 19 + 12: label L0 + 13: $t10 := move($t3) + 14: $t11 := 0 + 15: $t12 := vector::borrow<#0>($t10, $t11) + 16: $t13 := read_ref($t12) + 17: $t2 := $t13 + 18: goto 19 + 19: label L2 + 20: $t14 := move($t2) + 21: return $t14 +} + + +[variant baseline] +public fun option::is_none<#0>($t0|t: &option::Option<#0>): bool { + var $t1: &option::Option<#0> + var $t2: &vector<#0> + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field>.vec($t1) + 2: $t3 := vector::is_empty<#0>($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::is_some<#0>($t0|t: &option::Option<#0>): bool { + var $t1: &option::Option<#0> + var $t2: &vector<#0> + var $t3: bool + var $t4: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field>.vec($t1) + 2: $t3 := vector::is_empty<#0>($t2) + 3: $t4 := !($t3) + 4: return $t4 +} + + +[variant baseline] +public fun option::none<#0>(): option::Option<#0> { + var $t0: vector<#0> + var $t1: option::Option<#0> + 0: $t0 := vector::empty<#0>() + 1: $t1 := pack option::Option<#0>($t0) + 2: return $t1 +} + + +[variant baseline] +public fun option::some<#0>($t0|e: #0): option::Option<#0> { + var $t1: #0 + var $t2: vector<#0> + var $t3: option::Option<#0> + 0: $t1 := move($t0) + 1: $t2 := vector::singleton<#0>($t1) + 2: $t3 := pack option::Option<#0>($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::swap_or_fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): option::Option<#0> { + var $t2|tmp#$2: option::Option<#0> + var $t3|old_value#1#0: option::Option<#0> + var $t4|vec_ref#1#0: &mut vector<#0> + var $t5: &mut option::Option<#0> + var $t6: &mut vector<#0> + var $t7: &mut vector<#0> + var $t8: &vector<#0> + var $t9: bool + var $t10: option::Option<#0> + var $t11: &mut vector<#0> + var $t12: #0 + var $t13: option::Option<#0> + var $t14: option::Option<#0> + var $t15: &mut vector<#0> + var $t16: #0 + var $t17: option::Option<#0> + 0: $t5 := move($t0) + 1: $t6 := borrow_field>.vec($t5) + 2: $t4 := $t6 + 3: $t7 := copy($t4) + 4: $t8 := freeze_ref($t7) + 5: $t9 := vector::is_empty<#0>($t8) + 6: if ($t9) goto 7 else goto 11 + 7: label L1 + 8: $t10 := option::none<#0>() + 9: $t2 := $t10 + 10: goto 17 + 11: label L0 + 12: $t11 := copy($t4) + 13: $t12 := vector::pop_back<#0>($t11) + 14: $t13 := option::some<#0>($t12) + 15: $t2 := $t13 + 16: goto 17 + 17: label L2 + 18: $t14 := move($t2) + 19: $t3 := $t14 + 20: $t15 := move($t4) + 21: $t16 := move($t1) + 22: vector::push_back<#0>($t15, $t16) + 23: $t17 := move($t3) + 24: return $t17 +} + + +[variant baseline] +public fun option::to_vec<#0>($t0|t: option::Option<#0>): vector<#0> { + var $t1: option::Option<#0> + var $t2: vector<#0> + 0: $t1 := move($t0) + 1: $t2 := unpack option::Option<#0>($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::append($t0|string: &mut ascii::String, $t1|other: ascii::String) { + var $t2: &mut ascii::String + var $t3: &mut vector + var $t4: ascii::String + var $t5: vector + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := move($t1) + 3: $t5 := ascii::into_bytes($t4) + 4: vector::append($t3, $t5) + 5: return () +} + + +[variant baseline] +public fun ascii::index_of($t0|string: &ascii::String, $t1|substr: &ascii::String): u64 { + var $t2|tmp#$2: bool + var $t3|i#1#0: u64 + var $t4|j#1#0: u64 + var $t5|m#1#0: u64 + var $t6|n#1#0: u64 + var $t7: u64 + var $t8: &ascii::String + var $t9: u64 + var $t10: &ascii::String + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: bool + var $t15: &ascii::String + var $t16: &ascii::String + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: u64 + var $t22: bool + var $t23: u64 + var $t24: u64 + var $t25: u64 + var $t26: bool + var $t27: &ascii::String + var $t28: &vector + var $t29: u64 + var $t30: u64 + var $t31: u64 + var $t32: &u8 + var $t33: u8 + var $t34: &ascii::String + var $t35: &vector + var $t36: u64 + var $t37: &u8 + var $t38: u8 + var $t39: bool + var $t40: bool + var $t41: bool + var $t42: u64 + var $t43: u64 + var $t44: u64 + var $t45: u64 + var $t46: u64 + var $t47: bool + var $t48: &ascii::String + var $t49: &ascii::String + var $t50: u64 + var $t51: u64 + var $t52: u64 + var $t53: u64 + var $t54: &ascii::String + var $t55: &ascii::String + var $t56: u64 + 0: $t7 := 0 + 1: $t3 := $t7 + 2: $t8 := copy($t0) + 3: $t9 := ascii::length($t8) + 4: $t10 := copy($t1) + 5: $t11 := ascii::length($t10) + 6: $t5 := $t11 + 7: $t6 := $t9 + 8: $t12 := copy($t6) + 9: $t13 := copy($t5) + 10: $t14 := <($t12, $t13) + 11: if ($t14) goto 12 else goto 19 + 12: label L1 + 13: $t15 := move($t1) + 14: destroy($t15) + 15: $t16 := move($t0) + 16: destroy($t16) + 17: $t17 := move($t6) + 18: return $t17 + 19: label L0 + 20: $t18 := copy($t3) + 21: $t19 := copy($t6) + 22: $t20 := copy($t5) + 23: $t21 := -($t19, $t20) + 24: $t22 := <=($t18, $t21) + 25: if ($t22) goto 26 else goto 84 + 26: label L3 + 27: $t23 := 0 + 28: $t4 := $t23 + 29: goto 30 + 30: label L10 + 31: $t24 := copy($t4) + 32: $t25 := copy($t5) + 33: $t26 := <($t24, $t25) + 34: if ($t26) goto 35 else goto 53 + 35: label L5 + 36: goto 37 + 37: label L6 + 38: $t27 := copy($t0) + 39: $t28 := borrow_field.bytes($t27) + 40: $t29 := copy($t3) + 41: $t30 := copy($t4) + 42: $t31 := +($t29, $t30) + 43: $t32 := vector::borrow($t28, $t31) + 44: $t33 := read_ref($t32) + 45: $t34 := copy($t1) + 46: $t35 := borrow_field.bytes($t34) + 47: $t36 := copy($t4) + 48: $t37 := vector::borrow($t35, $t36) + 49: $t38 := read_ref($t37) + 50: $t39 := ==($t33, $t38) + 51: $t2 := $t39 + 52: goto 57 + 53: label L4 + 54: $t40 := false + 55: $t2 := $t40 + 56: goto 57 + 57: label L7 + 58: $t41 := move($t2) + 59: if ($t41) goto 60 else goto 66 + 60: label L9 + 61: $t42 := move($t4) + 62: $t43 := 1 + 63: $t44 := +($t42, $t43) + 64: $t4 := $t44 + 65: goto 30 + 66: label L8 + 67: $t45 := move($t4) + 68: $t46 := copy($t5) + 69: $t47 := ==($t45, $t46) + 70: if ($t47) goto 71 else goto 78 + 71: label L12 + 72: $t48 := move($t1) + 73: destroy($t48) + 74: $t49 := move($t0) + 75: destroy($t49) + 76: $t50 := move($t3) + 77: return $t50 + 78: label L11 + 79: $t51 := move($t3) + 80: $t52 := 1 + 81: $t53 := +($t51, $t52) + 82: $t3 := $t53 + 83: goto 19 + 84: label L2 + 85: $t54 := move($t1) + 86: destroy($t54) + 87: $t55 := move($t0) + 88: destroy($t55) + 89: $t56 := move($t6) + 90: return $t56 +} + + +[variant baseline] +public fun ascii::insert($t0|s: &mut ascii::String, $t1|at: u64, $t2|o: ascii::String) { + var $t3|e#1#2: u8 + var $t4|v#1#1: vector + var $t5: u64 + var $t6: &mut ascii::String + var $t7: &ascii::String + var $t8: u64 + var $t9: bool + var $t10: &mut ascii::String + var $t11: u64 + var $t12: ascii::String + var $t13: vector + var $t14: &vector + var $t15: bool + var $t16: bool + var $t17: &mut vector + var $t18: u8 + var $t19: &mut ascii::String + var $t20: &mut vector + var $t21: u8 + var $t22: u64 + var $t23: &mut ascii::String + var $t24: vector + 0: $t5 := copy($t1) + 1: $t6 := copy($t0) + 2: $t7 := freeze_ref($t6) + 3: $t8 := ascii::length($t7) + 4: $t9 := <=($t5, $t8) + 5: if ($t9) goto 6 else goto 8 + 6: label L1 + 7: goto 13 + 8: label L0 + 9: $t10 := move($t0) + 10: destroy($t10) + 11: $t11 := 65537 + 12: abort($t11) + 13: label L2 + 14: $t12 := move($t2) + 15: $t13 := ascii::into_bytes($t12) + 16: $t4 := $t13 + 17: goto 18 + 18: label L5 + 19: $t14 := borrow_local($t4) + 20: $t15 := vector::is_empty($t14) + 21: $t16 := !($t15) + 22: if ($t16) goto 23 else goto 33 + 23: label L4 + 24: $t17 := borrow_local($t4) + 25: $t18 := vector::pop_back($t17) + 26: $t3 := $t18 + 27: $t19 := copy($t0) + 28: $t20 := borrow_field.bytes($t19) + 29: $t21 := move($t3) + 30: $t22 := copy($t1) + 31: vector::insert($t20, $t21, $t22) + 32: goto 18 + 33: label L3 + 34: $t23 := move($t0) + 35: destroy($t23) + 36: $t24 := move($t4) + 37: vector::destroy_empty($t24) + 38: return () +} + + +[variant baseline] +public fun ascii::is_empty($t0|string: &ascii::String): bool { + var $t1: &ascii::String + var $t2: &vector + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::is_empty($t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::length($t0|string: &ascii::String): u64 { + var $t1: &ascii::String + var $t2: &vector + var $t3: u64 + 0: $t1 := move($t0) + 1: $t2 := ascii::as_bytes($t1) + 2: $t3 := vector::length($t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::all_characters_printable($t0|string: &ascii::String): bool { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|i#1#12: u64 + var $t4|i#1#9: u64 + var $t5|stop#1#9: u64 + var $t6|v#1#3: &vector + var $t7: &ascii::String + var $t8: &vector + var $t9: &vector + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u64 + var $t17: &vector + var $t18: u64 + var $t19: &u8 + var $t20: u8 + var $t21: bool + var $t22: bool + var $t23: &vector + var $t24: bool + var $t25: u64 + var $t26: u64 + var $t27: u64 + var $t28: &vector + var $t29: bool + var $t30: bool + 0: $t7 := move($t0) + 1: $t8 := borrow_field.bytes($t7) + 2: $t6 := $t8 + 3: $t9 := copy($t6) + 4: $t10 := vector::length($t9) + 5: $t1 := $t10 + 6: $t11 := 0 + 7: $t4 := $t11 + 8: $t12 := move($t1) + 9: $t5 := $t12 + 10: goto 11 + 11: label L5 + 12: $t13 := copy($t4) + 13: $t14 := copy($t5) + 14: $t15 := <($t13, $t14) + 15: if ($t15) goto 16 else goto 38 + 16: label L1 + 17: $t16 := copy($t4) + 18: $t3 := $t16 + 19: $t17 := copy($t6) + 20: $t18 := move($t3) + 21: $t19 := vector::borrow($t17, $t18) + 22: $t20 := read_ref($t19) + 23: $t21 := ascii::is_printable_char($t20) + 24: $t22 := !($t21) + 25: if ($t22) goto 26 else goto 32 + 26: label L3 + 27: $t23 := move($t6) + 28: destroy($t23) + 29: $t24 := false + 30: $t2 := $t24 + 31: goto 44 + 32: label L2 + 33: $t25 := move($t4) + 34: $t26 := 1 + 35: $t27 := +($t25, $t26) + 36: $t4 := $t27 + 37: goto 11 + 38: label L0 + 39: $t28 := move($t6) + 40: destroy($t28) + 41: $t29 := true + 42: $t2 := $t29 + 43: goto 44 + 44: label L4 + 45: $t30 := move($t2) + 46: return $t30 +} + + +[variant baseline] +public fun ascii::string($t0|bytes: vector): ascii::String { + var $t1|x#1#0: option::Option + var $t2: vector + var $t3: option::Option + var $t4: &option::Option + var $t5: bool + var $t6: u64 + var $t7: option::Option + var $t8: ascii::String + 0: $t2 := move($t0) + 1: $t3 := ascii::try_string($t2) + 2: $t1 := $t3 + 3: $t4 := borrow_local($t1) + 4: $t5 := option::is_some($t4) + 5: if ($t5) goto 6 else goto 8 + 6: label L1 + 7: goto 11 + 8: label L0 + 9: $t6 := 65536 + 10: abort($t6) + 11: label L2 + 12: $t7 := move($t1) + 13: $t8 := option::destroy_some($t7) + 14: return $t8 +} + + +[variant baseline] +public fun ascii::as_bytes($t0|string: &ascii::String): &vector { + var $t1: &ascii::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::byte($t0|char: ascii::Char): u8 { + var $t1: ascii::Char + var $t2: u8 + 0: $t1 := move($t0) + 1: $t2 := unpack ascii::Char($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::char($t0|byte: u8): ascii::Char { + var $t1: u8 + var $t2: bool + var $t3: u64 + var $t4: u8 + var $t5: ascii::Char + 0: $t1 := copy($t0) + 1: $t2 := ascii::is_valid_char($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 65536 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := pack ascii::Char($t4) + 11: return $t5 +} + + +[variant baseline] +fun ascii::char_to_lowercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: u8 + var $t5: bool + var $t6: u8 + var $t7: u8 + var $t8: bool + var $t9: bool + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: u8 + 0: $t3 := copy($t0) + 1: $t4 := 65 + 2: $t5 := >=($t3, $t4) + 3: if ($t5) goto 4 else goto 10 + 4: label L1 + 5: $t6 := copy($t0) + 6: $t7 := 90 + 7: $t8 := <=($t6, $t7) + 8: $t1 := $t8 + 9: goto 14 + 10: label L0 + 11: $t9 := false + 12: $t1 := $t9 + 13: goto 14 + 14: label L2 + 15: $t10 := move($t1) + 16: if ($t10) goto 17 else goto 23 + 17: label L4 + 18: $t11 := move($t0) + 19: $t12 := 32 + 20: $t13 := +($t11, $t12) + 21: $t2 := $t13 + 22: goto 27 + 23: label L3 + 24: $t14 := move($t0) + 25: $t2 := $t14 + 26: goto 27 + 27: label L5 + 28: $t15 := move($t2) + 29: return $t15 +} + + +[variant baseline] +fun ascii::char_to_uppercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: u8 + var $t5: bool + var $t6: u8 + var $t7: u8 + var $t8: bool + var $t9: bool + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: u8 + 0: $t3 := copy($t0) + 1: $t4 := 97 + 2: $t5 := >=($t3, $t4) + 3: if ($t5) goto 4 else goto 10 + 4: label L1 + 5: $t6 := copy($t0) + 6: $t7 := 122 + 7: $t8 := <=($t6, $t7) + 8: $t1 := $t8 + 9: goto 14 + 10: label L0 + 11: $t9 := false + 12: $t1 := $t9 + 13: goto 14 + 14: label L2 + 15: $t10 := move($t1) + 16: if ($t10) goto 17 else goto 23 + 17: label L4 + 18: $t11 := move($t0) + 19: $t12 := 32 + 20: $t13 := -($t11, $t12) + 21: $t2 := $t13 + 22: goto 27 + 23: label L3 + 24: $t14 := move($t0) + 25: $t2 := $t14 + 26: goto 27 + 27: label L5 + 28: $t15 := move($t2) + 29: return $t15 +} + + +[variant baseline] +public fun ascii::into_bytes($t0|string: ascii::String): vector { + var $t1: ascii::String + var $t2: vector + 0: $t1 := move($t0) + 1: $t2 := unpack ascii::String($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::is_printable_char($t0|byte: u8): bool { + var $t1|tmp#$1: bool + var $t2: u8 + var $t3: u8 + var $t4: bool + var $t5: u8 + var $t6: u8 + var $t7: bool + var $t8: bool + var $t9: bool + 0: $t2 := copy($t0) + 1: $t3 := 32 + 2: $t4 := >=($t2, $t3) + 3: if ($t4) goto 4 else goto 10 + 4: label L1 + 5: $t5 := move($t0) + 6: $t6 := 126 + 7: $t7 := <=($t5, $t6) + 8: $t1 := $t7 + 9: goto 14 + 10: label L0 + 11: $t8 := false + 12: $t1 := $t8 + 13: goto 14 + 14: label L2 + 15: $t9 := move($t1) + 16: return $t9 +} + + +[variant baseline] +public fun ascii::is_valid_char($t0|b: u8): bool { + var $t1: u8 + var $t2: u8 + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := 127 + 2: $t3 := <=($t1, $t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::pop_char($t0|string: &mut ascii::String): ascii::Char { + var $t1: &mut ascii::String + var $t2: &mut vector + var $t3: u8 + var $t4: ascii::Char + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::pop_back($t2) + 3: $t4 := pack ascii::Char($t3) + 4: return $t4 +} + + +[variant baseline] +public fun ascii::push_char($t0|string: &mut ascii::String, $t1|char: ascii::Char) { + var $t2: &mut ascii::String + var $t3: &mut vector + var $t4: &ascii::Char + var $t5: &u8 + var $t6: u8 + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := borrow_local($t1) + 3: $t5 := borrow_field.byte($t4) + 4: $t6 := read_ref($t5) + 5: vector::push_back($t3, $t6) + 6: return () +} + + +[variant baseline] +public fun ascii::substring($t0|string: &ascii::String, $t1|i: u64, $t2|j: u64): ascii::String { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: vector + var $t5|i#1#3: u64 + var $t6|i#1#6: u64 + var $t7|stop#1#3: u64 + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u64 + var $t12: &ascii::String + var $t13: u64 + var $t14: bool + var $t15: bool + var $t16: bool + var $t17: &ascii::String + var $t18: u64 + var $t19: vector + var $t20: u64 + var $t21: u64 + var $t22: u64 + var $t23: u64 + var $t24: bool + var $t25: u64 + var $t26: &mut vector + var $t27: &ascii::String + var $t28: &vector + var $t29: u64 + var $t30: &u8 + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &ascii::String + var $t36: vector + var $t37: ascii::String + 0: $t8 := copy($t1) + 1: $t9 := copy($t2) + 2: $t10 := <=($t8, $t9) + 3: if ($t10) goto 4 else goto 11 + 4: label L1 + 5: $t11 := copy($t2) + 6: $t12 := copy($t0) + 7: $t13 := ascii::length($t12) + 8: $t14 := <=($t11, $t13) + 9: $t3 := $t14 + 10: goto 15 + 11: label L0 + 12: $t15 := false + 13: $t3 := $t15 + 14: goto 15 + 15: label L2 + 16: $t16 := move($t3) + 17: if ($t16) goto 18 else goto 20 + 18: label L4 + 19: goto 25 + 20: label L3 + 21: $t17 := move($t0) + 22: destroy($t17) + 23: $t18 := 65537 + 24: abort($t18) + 25: label L5 + 26: $t19 := [] + 27: $t4 := $t19 + 28: $t20 := move($t1) + 29: $t5 := $t20 + 30: $t21 := move($t2) + 31: $t7 := $t21 + 32: goto 33 + 33: label L8 + 34: $t22 := copy($t5) + 35: $t23 := copy($t7) + 36: $t24 := <($t22, $t23) + 37: if ($t24) goto 38 else goto 53 + 38: label L7 + 39: $t25 := copy($t5) + 40: $t6 := $t25 + 41: $t26 := borrow_local($t4) + 42: $t27 := copy($t0) + 43: $t28 := borrow_field.bytes($t27) + 44: $t29 := move($t6) + 45: $t30 := vector::borrow($t28, $t29) + 46: $t31 := read_ref($t30) + 47: vector::push_back($t26, $t31) + 48: $t32 := move($t5) + 49: $t33 := 1 + 50: $t34 := +($t32, $t33) + 51: $t5 := $t34 + 52: goto 33 + 53: label L6 + 54: $t35 := move($t0) + 55: destroy($t35) + 56: $t36 := move($t4) + 57: $t37 := pack ascii::String($t36) + 58: return $t37 +} + + +[variant baseline] +public fun ascii::to_lowercase($t0|string: &ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: &u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: &vector + var $t10|v#1#3: &vector + var $t11: &ascii::String + var $t12: &vector + var $t13: vector + var $t14: &vector + var $t15: &vector + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: bool + var $t22: u64 + var $t23: &vector + var $t24: u64 + var $t25: &u8 + var $t26: &mut vector + var $t27: &u8 + var $t28: u8 + var $t29: u8 + var $t30: &mut vector + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &vector + var $t36: vector + var $t37: ascii::String + 0: $t11 := move($t0) + 1: $t12 := ascii::as_bytes($t11) + 2: $t9 := $t12 + 3: $t13 := [] + 4: $t7 := $t13 + 5: $t14 := move($t9) + 6: $t10 := $t14 + 7: $t15 := copy($t10) + 8: $t16 := vector::length($t15) + 9: $t1 := $t16 + 10: $t17 := 0 + 11: $t6 := $t17 + 12: $t18 := move($t1) + 13: $t8 := $t18 + 14: goto 15 + 15: label L2 + 16: $t19 := copy($t6) + 17: $t20 := copy($t8) + 18: $t21 := <($t19, $t20) + 19: if ($t21) goto 20 else goto 41 + 20: label L1 + 21: $t22 := copy($t6) + 22: $t5 := $t22 + 23: $t23 := copy($t10) + 24: $t24 := move($t5) + 25: $t25 := vector::borrow($t23, $t24) + 26: $t4 := $t25 + 27: $t26 := borrow_local($t7) + 28: $t3 := $t26 + 29: $t27 := move($t4) + 30: $t28 := read_ref($t27) + 31: $t29 := ascii::char_to_lowercase($t28) + 32: $t2 := $t29 + 33: $t30 := move($t3) + 34: $t31 := move($t2) + 35: vector::push_back($t30, $t31) + 36: $t32 := move($t6) + 37: $t33 := 1 + 38: $t34 := +($t32, $t33) + 39: $t6 := $t34 + 40: goto 15 + 41: label L0 + 42: $t35 := move($t10) + 43: destroy($t35) + 44: $t36 := move($t7) + 45: $t37 := pack ascii::String($t36) + 46: return $t37 +} + + +[variant baseline] +public fun ascii::to_uppercase($t0|string: &ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: &u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: &vector + var $t10|v#1#3: &vector + var $t11: &ascii::String + var $t12: &vector + var $t13: vector + var $t14: &vector + var $t15: &vector + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: bool + var $t22: u64 + var $t23: &vector + var $t24: u64 + var $t25: &u8 + var $t26: &mut vector + var $t27: &u8 + var $t28: u8 + var $t29: u8 + var $t30: &mut vector + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &vector + var $t36: vector + var $t37: ascii::String + 0: $t11 := move($t0) + 1: $t12 := ascii::as_bytes($t11) + 2: $t9 := $t12 + 3: $t13 := [] + 4: $t7 := $t13 + 5: $t14 := move($t9) + 6: $t10 := $t14 + 7: $t15 := copy($t10) + 8: $t16 := vector::length($t15) + 9: $t1 := $t16 + 10: $t17 := 0 + 11: $t6 := $t17 + 12: $t18 := move($t1) + 13: $t8 := $t18 + 14: goto 15 + 15: label L2 + 16: $t19 := copy($t6) + 17: $t20 := copy($t8) + 18: $t21 := <($t19, $t20) + 19: if ($t21) goto 20 else goto 41 + 20: label L1 + 21: $t22 := copy($t6) + 22: $t5 := $t22 + 23: $t23 := copy($t10) + 24: $t24 := move($t5) + 25: $t25 := vector::borrow($t23, $t24) + 26: $t4 := $t25 + 27: $t26 := borrow_local($t7) + 28: $t3 := $t26 + 29: $t27 := move($t4) + 30: $t28 := read_ref($t27) + 31: $t29 := ascii::char_to_uppercase($t28) + 32: $t2 := $t29 + 33: $t30 := move($t3) + 34: $t31 := move($t2) + 35: vector::push_back($t30, $t31) + 36: $t32 := move($t6) + 37: $t33 := 1 + 38: $t34 := +($t32, $t33) + 39: $t6 := $t34 + 40: goto 15 + 41: label L0 + 42: $t35 := move($t10) + 43: destroy($t35) + 44: $t36 := move($t7) + 45: $t37 := pack ascii::String($t36) + 46: return $t37 +} + + +[variant baseline] +public fun ascii::try_string($t0|bytes: vector): option::Option { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|tmp#$3: option::Option + var $t4|i#1#12: u64 + var $t5|i#1#9: u64 + var $t6|stop#1#9: u64 + var $t7|v#1#3: &vector + var $t8: &vector + var $t9: &vector + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u64 + var $t17: &vector + var $t18: u64 + var $t19: &u8 + var $t20: u8 + var $t21: bool + var $t22: bool + var $t23: &vector + var $t24: bool + var $t25: u64 + var $t26: u64 + var $t27: u64 + var $t28: &vector + var $t29: bool + var $t30: bool + var $t31: vector + var $t32: ascii::String + var $t33: option::Option + var $t34: option::Option + var $t35: option::Option + 0: $t8 := borrow_local($t0) + 1: $t7 := $t8 + 2: $t9 := copy($t7) + 3: $t10 := vector::length($t9) + 4: $t1 := $t10 + 5: $t11 := 0 + 6: $t5 := $t11 + 7: $t12 := move($t1) + 8: $t6 := $t12 + 9: goto 10 + 10: label L5 + 11: $t13 := copy($t5) + 12: $t14 := copy($t6) + 13: $t15 := <($t13, $t14) + 14: if ($t15) goto 15 else goto 37 + 15: label L1 + 16: $t16 := copy($t5) + 17: $t4 := $t16 + 18: $t17 := copy($t7) + 19: $t18 := move($t4) + 20: $t19 := vector::borrow($t17, $t18) + 21: $t20 := read_ref($t19) + 22: $t21 := ascii::is_valid_char($t20) + 23: $t22 := !($t21) + 24: if ($t22) goto 25 else goto 31 + 25: label L3 + 26: $t23 := move($t7) + 27: destroy($t23) + 28: $t24 := false + 29: $t2 := $t24 + 30: goto 43 + 31: label L2 + 32: $t25 := move($t5) + 33: $t26 := 1 + 34: $t27 := +($t25, $t26) + 35: $t5 := $t27 + 36: goto 10 + 37: label L0 + 38: $t28 := move($t7) + 39: destroy($t28) + 40: $t29 := true + 41: $t2 := $t29 + 42: goto 43 + 43: label L4 + 44: $t30 := move($t2) + 45: if ($t30) goto 46 else goto 52 + 46: label L7 + 47: $t31 := move($t0) + 48: $t32 := pack ascii::String($t31) + 49: $t33 := option::some($t32) + 50: $t3 := $t33 + 51: goto 56 + 52: label L6 + 53: $t34 := option::none() + 54: $t3 := $t34 + 55: goto 56 + 56: label L8 + 57: $t35 := move($t3) + 58: return $t35 +} + + +[variant baseline] +public fun string::append($t0|s: &mut string::String, $t1|r: string::String) { + var $t2: &mut string::String + var $t3: &mut vector + var $t4: &string::String + var $t5: &vector + var $t6: vector + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := borrow_local($t1) + 3: $t5 := borrow_field.bytes($t4) + 4: $t6 := read_ref($t5) + 5: vector::append($t3, $t6) + 6: return () +} + + +[variant baseline] +public fun string::index_of($t0|s: &string::String, $t1|r: &string::String): u64 { + var $t2: &string::String + var $t3: &vector + var $t4: &string::String + var $t5: &vector + var $t6: u64 + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := move($t1) + 3: $t5 := borrow_field.bytes($t4) + 4: $t6 := string::internal_index_of($t3, $t5) + 5: return $t6 +} + + +[variant baseline] +public fun string::insert($t0|s: &mut string::String, $t1|at: u64, $t2|o: string::String) { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: &vector + var $t5|end#1#0: string::String + var $t6|front#1#0: string::String + var $t7|l#1#0: u64 + var $t8: &mut string::String + var $t9: &vector + var $t10: u64 + var $t11: &vector + var $t12: u64 + var $t13: bool + var $t14: &vector + var $t15: u64 + var $t16: bool + var $t17: &vector + var $t18: bool + var $t19: bool + var $t20: &mut string::String + var $t21: u64 + var $t22: &mut string::String + var $t23: &string::String + var $t24: u64 + var $t25: &mut string::String + var $t26: &string::String + var $t27: u64 + var $t28: u64 + var $t29: string::String + var $t30: &mut string::String + var $t31: &string::String + var $t32: u64 + var $t33: u64 + var $t34: string::String + var $t35: &mut string::String + var $t36: string::String + var $t37: &mut string::String + var $t38: string::String + var $t39: string::String + var $t40: &mut string::String + 0: $t8 := copy($t0) + 1: $t9 := borrow_field.bytes($t8) + 2: $t4 := $t9 + 3: $t10 := copy($t1) + 4: $t11 := copy($t4) + 5: $t12 := vector::length($t11) + 6: $t13 := <=($t10, $t12) + 7: if ($t13) goto 8 else goto 14 + 8: label L1 + 9: $t14 := move($t4) + 10: $t15 := copy($t1) + 11: $t16 := string::internal_is_char_boundary($t14, $t15) + 12: $t3 := $t16 + 13: goto 20 + 14: label L0 + 15: $t17 := move($t4) + 16: destroy($t17) + 17: $t18 := false + 18: $t3 := $t18 + 19: goto 20 + 20: label L2 + 21: $t19 := move($t3) + 22: if ($t19) goto 23 else goto 25 + 23: label L4 + 24: goto 30 + 25: label L3 + 26: $t20 := move($t0) + 27: destroy($t20) + 28: $t21 := 2 + 29: abort($t21) + 30: label L5 + 31: $t22 := copy($t0) + 32: $t23 := freeze_ref($t22) + 33: $t24 := string::length($t23) + 34: $t7 := $t24 + 35: $t25 := copy($t0) + 36: $t26 := freeze_ref($t25) + 37: $t27 := 0 + 38: $t28 := copy($t1) + 39: $t29 := string::substring($t26, $t27, $t28) + 40: $t6 := $t29 + 41: $t30 := copy($t0) + 42: $t31 := freeze_ref($t30) + 43: $t32 := move($t1) + 44: $t33 := move($t7) + 45: $t34 := string::substring($t31, $t32, $t33) + 46: $t5 := $t34 + 47: $t35 := borrow_local($t6) + 48: $t36 := move($t2) + 49: string::append($t35, $t36) + 50: $t37 := borrow_local($t6) + 51: $t38 := move($t5) + 52: string::append($t37, $t38) + 53: $t39 := move($t6) + 54: $t40 := move($t0) + 55: write_ref($t40, $t39) + 56: return () +} + + +[variant baseline] +public fun string::is_empty($t0|s: &string::String): bool { + var $t1: &string::String + var $t2: &vector + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::is_empty($t2) + 3: return $t3 +} + + +[variant baseline] +public fun string::length($t0|s: &string::String): u64 { + var $t1: &string::String + var $t2: &vector + var $t3: u64 + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::length($t2) + 3: return $t3 +} + + +[variant baseline] +public fun string::as_bytes($t0|s: &string::String): &vector { + var $t1: &string::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::into_bytes($t0|s: string::String): vector { + var $t1: string::String + var $t2: vector + 0: $t1 := move($t0) + 1: $t2 := unpack string::String($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::bytes($t0|s: &string::String): &vector { + var $t1: &string::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := string::as_bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::substring($t0|s: &string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3|tmp#$3: bool + var $t4|tmp#$4: bool + var $t5|tmp#$5: bool + var $t6|bytes#1#0: &vector + var $t7|l#1#0: u64 + var $t8: &string::String + var $t9: &vector + var $t10: &vector + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: bool + var $t15: u64 + var $t16: u64 + var $t17: bool + var $t18: bool + var $t19: bool + var $t20: &vector + var $t21: u64 + var $t22: bool + var $t23: bool + var $t24: bool + var $t25: &vector + var $t26: u64 + var $t27: bool + var $t28: bool + var $t29: bool + var $t30: &vector + var $t31: u64 + var $t32: &vector + var $t33: u64 + var $t34: u64 + var $t35: vector + var $t36: string::String + 0: $t8 := move($t0) + 1: $t9 := borrow_field.bytes($t8) + 2: $t6 := $t9 + 3: $t10 := copy($t6) + 4: $t11 := vector::length($t10) + 5: $t7 := $t11 + 6: $t12 := copy($t2) + 7: $t13 := move($t7) + 8: $t14 := <=($t12, $t13) + 9: if ($t14) goto 10 else goto 16 + 10: label L1 + 11: $t15 := copy($t1) + 12: $t16 := copy($t2) + 13: $t17 := <=($t15, $t16) + 14: $t3 := $t17 + 15: goto 20 + 16: label L0 + 17: $t18 := false + 18: $t3 := $t18 + 19: goto 20 + 20: label L2 + 21: $t19 := move($t3) + 22: if ($t19) goto 23 else goto 29 + 23: label L4 + 24: $t20 := copy($t6) + 25: $t21 := copy($t1) + 26: $t22 := string::internal_is_char_boundary($t20, $t21) + 27: $t4 := $t22 + 28: goto 33 + 29: label L3 + 30: $t23 := false + 31: $t4 := $t23 + 32: goto 33 + 33: label L5 + 34: $t24 := move($t4) + 35: if ($t24) goto 36 else goto 42 + 36: label L7 + 37: $t25 := copy($t6) + 38: $t26 := copy($t2) + 39: $t27 := string::internal_is_char_boundary($t25, $t26) + 40: $t5 := $t27 + 41: goto 46 + 42: label L6 + 43: $t28 := false + 44: $t5 := $t28 + 45: goto 46 + 46: label L8 + 47: $t29 := move($t5) + 48: if ($t29) goto 49 else goto 51 + 49: label L10 + 50: goto 56 + 51: label L9 + 52: $t30 := move($t6) + 53: destroy($t30) + 54: $t31 := 2 + 55: abort($t31) + 56: label L11 + 57: $t32 := move($t6) + 58: $t33 := move($t1) + 59: $t34 := move($t2) + 60: $t35 := string::internal_sub_string($t32, $t33, $t34) + 61: $t36 := pack string::String($t35) + 62: return $t36 +} + + +[variant baseline] +public fun string::append_utf8($t0|s: &mut string::String, $t1|bytes: vector) { + var $t2: &mut string::String + var $t3: vector + var $t4: string::String + 0: $t2 := move($t0) + 1: $t3 := move($t1) + 2: $t4 := string::utf8($t3) + 3: string::append($t2, $t4) + 4: return () +} + + +[variant baseline] +public fun string::from_ascii($t0|s: ascii::String): string::String { + var $t1: ascii::String + var $t2: vector + var $t3: string::String + 0: $t1 := move($t0) + 1: $t2 := ascii::into_bytes($t1) + 2: $t3 := pack string::String($t2) + 3: return $t3 +} + + +[variant baseline] +native fun string::internal_check_utf8($t0|v: &vector): bool; + + +[variant baseline] +native fun string::internal_index_of($t0|v: &vector, $t1|r: &vector): u64; + + +[variant baseline] +native fun string::internal_is_char_boundary($t0|v: &vector, $t1|i: u64): bool; + + +[variant baseline] +native fun string::internal_sub_string($t0|v: &vector, $t1|i: u64, $t2|j: u64): vector; + + +[variant baseline] +public fun string::sub_string($t0|s: &string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3: &string::String + var $t4: u64 + var $t5: u64 + var $t6: string::String + 0: $t3 := move($t0) + 1: $t4 := move($t1) + 2: $t5 := move($t2) + 3: $t6 := string::substring($t3, $t4, $t5) + 4: return $t6 +} + + +[variant baseline] +public fun string::to_ascii($t0|s: string::String): ascii::String { + var $t1: string::String + var $t2: vector + var $t3: ascii::String + 0: $t1 := move($t0) + 1: $t2 := unpack string::String($t1) + 2: $t3 := ascii::string($t2) + 3: return $t3 +} + + +[variant baseline] +public fun string::try_utf8($t0|bytes: vector): option::Option { + var $t1|tmp#$1: option::Option + var $t2: &vector + var $t3: bool + var $t4: vector + var $t5: string::String + var $t6: option::Option + var $t7: option::Option + var $t8: option::Option + 0: $t2 := borrow_local($t0) + 1: $t3 := string::internal_check_utf8($t2) + 2: if ($t3) goto 3 else goto 9 + 3: label L1 + 4: $t4 := move($t0) + 5: $t5 := pack string::String($t4) + 6: $t6 := option::some($t5) + 7: $t1 := $t6 + 8: goto 13 + 9: label L0 + 10: $t7 := option::none() + 11: $t1 := $t7 + 12: goto 13 + 13: label L2 + 14: $t8 := move($t1) + 15: return $t8 +} + + +[variant baseline] +public fun string::utf8($t0|bytes: vector): string::String { + var $t1: &vector + var $t2: bool + var $t3: u64 + var $t4: vector + var $t5: string::String + 0: $t1 := borrow_local($t0) + 1: $t2 := string::internal_check_utf8($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 1 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := pack string::String($t4) + 11: return $t5 +} + + +[variant baseline] +public fun Collection::borrow_mut<#0>($t0|c: &mut Collection::Collection<#0>, $t1|i: u64): &mut #0 { + var $t2: &mut Collection::Collection<#0> + var $t3: &mut vector<#0> + var $t4: u64 + var $t5: &mut #0 + 0: $t2 := move($t0) + 1: $t3 := borrow_field>.items($t2) + 2: $t4 := move($t1) + 3: $t5 := vector::borrow_mut<#0>($t3, $t4) + 4: return $t5 +} + + +[variant baseline] +public fun Collection::make_collection<#0>(): Collection::Collection<#0> { + var $t0: vector<#0> + var $t1: address + var $t2: Collection::Collection<#0> + 0: $t0 := vector::empty<#0>() + 1: $t1 := 0x2 + 2: $t2 := pack Collection::Collection<#0>($t0, $t1) + 3: return $t2 +} + + +[variant baseline] +public fun Test::foo<#0>($t0|i: u64) { + var $t1|c#1#0: Collection::Collection> + var $t2|t#1#0: &mut Test::Token<#0> + var $t3: Collection::Collection> + var $t4: &mut Collection::Collection> + var $t5: u64 + var $t6: &mut Test::Token<#0> + var $t7: u64 + var $t8: &mut Test::Token<#0> + var $t9: &mut u64 + 0: $t3 := Collection::make_collection>() + 1: $t1 := $t3 + 2: $t4 := borrow_local($t1) + 3: $t5 := move($t0) + 4: $t6 := Collection::borrow_mut>($t4, $t5) + 5: $t2 := $t6 + 6: $t7 := 0 + 7: $t8 := move($t2) + 8: $t9 := borrow_field>.value($t8) + 9: write_ref($t9, $t7) + 10: return () +} + +============ after pipeline `borrow` ================ + +[variant baseline] +public fun u64::diff($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: bool + 0: $t5 := >($t0, $t1) + 1: if ($t5) goto 2 else goto 5 + 2: label L1 + 3: $t2 := -($t0, $t1) + 4: goto 7 + 5: label L0 + 6: $t2 := -($t1, $t0) + 7: label L2 + 8: return $t2 +} + + +[variant baseline] +public fun u64::divide_and_round_up($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: bool + var $t8: u64 + var $t9: u64 + 0: $t5 := %($t0, $t1) + 1: $t6 := 0 + 2: $t7 := ==($t5, $t6) + 3: if ($t7) goto 4 else goto 7 + 4: label L1 + 5: $t2 := /($t0, $t1) + 6: goto 11 + 7: label L0 + 8: $t8 := /($t0, $t1) + 9: $t9 := 1 + 10: $t2 := +($t8, $t9) + 11: label L2 + 12: return $t2 +} + + +[variant baseline] +public fun u64::max($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: bool + 0: $t5 := >($t0, $t1) + 1: if ($t5) goto 2 else goto 5 + 2: label L1 + 3: $t2 := $t0 + 4: goto 7 + 5: label L0 + 6: $t2 := $t1 + 7: label L2 + 8: return $t2 +} + + +[variant baseline] +public fun u64::min($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: bool + 0: $t5 := <($t0, $t1) + 1: if ($t5) goto 2 else goto 5 + 2: label L1 + 3: $t2 := $t0 + 4: goto 7 + 5: label L0 + 6: $t2 := $t1 + 7: label L2 + 8: return $t2 +} + + +[variant baseline] +public fun u64::pow($t0|base: u64, $t1|exponent: u8): u64 { + var $t2|base#1#1: u64 + var $t3|exponent#1#1: u8 + var $t4|res#1#1: u64 + var $t5: u64 + var $t6: u8 + var $t7: bool + var $t8: u8 + var $t9: u8 + var $t10: u8 + var $t11: bool + var $t12: u8 + var $t13: u8 + 0: $t2 := $t0 + 1: $t3 := $t1 + 2: $t5 := 1 + 3: $t4 := $t5 + 4: label L5 + 5: $t6 := 1 + 6: $t7 := >=($t3, $t6) + 7: if ($t7) goto 8 else goto 25 + 8: label L1 + 9: label L2 + 10: $t8 := 2 + 11: $t9 := %($t3, $t8) + 12: $t10 := 0 + 13: $t11 := ==($t9, $t10) + 14: if ($t11) goto 15 else goto 20 + 15: label L4 + 16: $t2 := *($t2, $t2) + 17: $t12 := 2 + 18: $t3 := /($t3, $t12) + 19: goto 4 + 20: label L3 + 21: $t4 := *($t4, $t2) + 22: $t13 := 1 + 23: $t3 := -($t3, $t13) + 24: goto 4 + 25: label L0 + 26: return $t4 +} + + +[variant baseline] +public fun u64::sqrt($t0|x: u64): u64 { + var $t1|bit#1#1: u128 + var $t2|res#1#1: u128 + var $t3|x#1#1: u64 + var $t4|x#2#1: u128 + var $t5: u128 + var $t6: u128 + var $t7: u128 + var $t8: bool + var $t9: u128 + var $t10: bool + var $t11: u128 + var $t12: u8 + var $t13: u128 + var $t14: u8 + var $t15: u8 + var $t16: u64 + 0: $t5 := 18446744073709551616 + 1: $t1 := $t5 + 2: $t6 := 0 + 3: $t2 := $t6 + 4: $t4 := (u128)($t0) + 5: label L6 + 6: $t7 := 0 + 7: $t8 := !=($t1, $t7) + 8: if ($t8) goto 9 else goto 28 + 9: label L1 + 10: label L2 + 11: $t9 := +($t2, $t1) + 12: $t10 := >=($t4, $t9) + 13: if ($t10) goto 14 else goto 21 + 14: label L4 + 15: $t11 := +($t2, $t1) + 16: $t4 := -($t4, $t11) + 17: $t12 := 1 + 18: $t13 := >>($t2, $t12) + 19: $t2 := +($t13, $t1) + 20: goto 24 + 21: label L3 + 22: $t14 := 1 + 23: $t2 := >>($t2, $t14) + 24: label L5 + 25: $t15 := 2 + 26: $t1 := >>($t1, $t15) + 27: goto 5 + 28: label L0 + 29: $t16 := (u64)($t2) + 30: return $t16 +} + + +[variant baseline] +public fun vector::append<#0>($t0|lhs: &mut vector<#0>, $t1|other: vector<#0>) { + var $t2: &mut vector<#0> + var $t3: vector<#0> + var $t4: bool + var $t5: bool + var $t6: &mut vector<#0> + var $t7: #0 + var $t8: vector<#0> + 0: $t2 := borrow_local($t1) + 1: vector::reverse<#0>($t2) + 2: label L3 + 3: $t3 := copy($t1) + 4: $t4 := vector::is_empty<#0>($t3) + 5: $t5 := !($t4) + 6: if ($t5) goto 7 else goto 13 + 7: label L1 + 8: label L2 + 9: $t6 := borrow_local($t1) + 10: $t7 := vector::pop_back<#0>($t6) + 11: vector::push_back<#0>($t0, $t7) + 12: goto 2 + 13: label L0 + 14: destroy($t0) + 15: $t8 := move($t1) + 16: vector::destroy_empty<#0>($t8) + 17: trace_local[lhs]($t0) + 18: return () +} + + +[variant baseline] +public native fun vector::borrow<#0>($t0|v: vector<#0>, $t1|i: u64): #0; + + +[variant baseline] +public native fun vector::borrow_mut<#0>($t0|v: &mut vector<#0>, $t1|i: u64): &mut #0; + + +[variant baseline] +public fun vector::contains<#0>($t0|v: vector<#0>, $t1|e: #0): bool { + var $t2|i#1#0: u64 + var $t3|len#1#0: u64 + var $t4: u64 + var $t5: u64 + var $t6: bool + var $t7: #0 + var $t8: bool + var $t9: bool + var $t10: u64 + var $t11: bool + 0: $t4 := 0 + 1: $t2 := $t4 + 2: $t5 := vector::length<#0>($t0) + 3: label L5 + 4: $t6 := <($t2, $t5) + 5: if ($t6) goto 6 else goto 18 + 6: label L1 + 7: label L2 + 8: $t7 := vector::borrow<#0>($t0, $t2) + 9: $t8 := ==($t7, $t1) 10: if ($t8) goto 11 else goto 14 11: label L4 12: $t9 := true 13: return $t9 14: label L3 - 15: $t10 := 1 - 16: $t2 := +($t2, $t10) - 17: goto 3 - 18: label L0 - 19: $t11 := false - 20: return $t11 + 15: $t10 := 1 + 16: $t2 := +($t2, $t10) + 17: goto 3 + 18: label L0 + 19: $t11 := false + 20: return $t11 +} + + +[variant baseline] +public native fun vector::destroy_empty<#0>($t0|v: vector<#0>); + + +[variant baseline] +public native fun vector::empty<#0>(): vector<#0>; + + +[variant baseline] +public fun vector::index_of<#0>($t0|v: vector<#0>, $t1|e: #0): (bool, u64) { + var $t2|i#1#0: u64 + var $t3|len#1#0: u64 + var $t4: u64 + var $t5: u64 + var $t6: bool + var $t7: #0 + var $t8: bool + var $t9: bool + var $t10: u64 + var $t11: bool + var $t12: u64 + 0: $t4 := 0 + 1: $t2 := $t4 + 2: $t5 := vector::length<#0>($t0) + 3: label L5 + 4: $t6 := <($t2, $t5) + 5: if ($t6) goto 6 else goto 18 + 6: label L1 + 7: label L2 + 8: $t7 := vector::borrow<#0>($t0, $t2) + 9: $t8 := ==($t7, $t1) + 10: if ($t8) goto 11 else goto 14 + 11: label L4 + 12: $t9 := true + 13: return ($t9, $t2) + 14: label L3 + 15: $t10 := 1 + 16: $t2 := +($t2, $t10) + 17: goto 3 + 18: label L0 + 19: $t11 := false + 20: $t12 := 0 + 21: return ($t11, $t12) +} + + +[variant baseline] +public fun vector::insert<#0>($t0|v: &mut vector<#0>, $t1|e: #0, $t2|i: u64) { + var $t3|len#1#0: u64 + var $t4: vector<#0> + var $t5: u64 + var $t6: bool + var $t7: u64 + var $t8: bool + var $t9: u64 + 0: $t4 := read_ref($t0) + 1: $t5 := vector::length<#0>($t4) + 2: $t6 := >($t2, $t5) + 3: if ($t6) goto 4 else goto 8 + 4: label L1 + 5: destroy($t0) + 6: $t7 := 131072 + 7: abort($t7) + 8: label L0 + 9: vector::push_back<#0>($t0, $t1) + 10: label L4 + 11: $t8 := <($t2, $t5) + 12: if ($t8) goto 13 else goto 18 + 13: label L3 + 14: vector::swap<#0>($t0, $t2, $t5) + 15: $t9 := 1 + 16: $t2 := +($t2, $t9) + 17: goto 10 + 18: label L2 + 19: destroy($t0) + 20: trace_local[v]($t0) + 21: return () +} + + +[variant baseline] +public fun vector::is_empty<#0>($t0|v: vector<#0>): bool { + var $t1: u64 + var $t2: u64 + var $t3: bool + 0: $t1 := vector::length<#0>($t0) + 1: $t2 := 0 + 2: $t3 := ==($t1, $t2) + 3: return $t3 +} + + +[variant baseline] +public native fun vector::length<#0>($t0|v: vector<#0>): u64; + + +[variant baseline] +public native fun vector::pop_back<#0>($t0|v: &mut vector<#0>): #0; + + +[variant baseline] +public native fun vector::push_back<#0>($t0|v: &mut vector<#0>, $t1|e: #0); + + +[variant baseline] +public fun vector::remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { + var $t2|tmp#$2: u64 + var $t3|tmp#$3: &mut vector<#0> + var $t4|len#1#0: u64 + var $t5: vector<#0> + var $t6: u64 + var $t7: bool + var $t8: u64 + var $t9: u64 + var $t10: u64 + var $t11: bool + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: #0 + 0: $t5 := read_ref($t0) + 1: $t6 := vector::length<#0>($t5) + 2: $t7 := >=($t1, $t6) + 3: if ($t7) goto 4 else goto 8 + 4: label L1 + 5: destroy($t0) + 6: $t8 := 131072 + 7: abort($t8) + 8: label L0 + 9: $t9 := 1 + 10: $t10 := -($t6, $t9) + 11: label L4 + 12: $t11 := <($t1, $t10) + 13: if ($t11) goto 14 else goto 21 + 14: label L3 + 15: $t12 := copy($t1) + 16: $t13 := 1 + 17: $t14 := +($t1, $t13) + 18: $t1 := $t14 + 19: vector::swap<#0>($t0, $t12, $t14) + 20: goto 11 + 21: label L2 + 22: $t15 := vector::pop_back<#0>($t0) + 23: trace_local[v]($t0) + 24: return $t15 +} + + +[variant baseline] +public fun vector::reverse<#0>($t0|v: &mut vector<#0>) { + var $t1|back_index#1#0: u64 + var $t2|front_index#1#0: u64 + var $t3|len#1#0: u64 + var $t4: vector<#0> + var $t5: u64 + var $t6: u64 + var $t7: bool + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u64 + var $t12: u64 + 0: $t4 := read_ref($t0) + 1: $t5 := vector::length<#0>($t4) + 2: $t6 := 0 + 3: $t7 := ==($t5, $t6) + 4: if ($t7) goto 5 else goto 9 + 5: label L1 + 6: destroy($t0) + 7: trace_local[v]($t0) + 8: return () + 9: label L0 + 10: $t8 := 0 + 11: $t2 := $t8 + 12: $t9 := 1 + 13: $t1 := -($t5, $t9) + 14: label L4 + 15: $t10 := <($t2, $t1) + 16: if ($t10) goto 17 else goto 24 + 17: label L3 + 18: vector::swap<#0>($t0, $t2, $t1) + 19: $t11 := 1 + 20: $t2 := +($t2, $t11) + 21: $t12 := 1 + 22: $t1 := -($t1, $t12) + 23: goto 14 + 24: label L2 + 25: destroy($t0) + 26: trace_local[v]($t0) + 27: return () +} + + +[variant baseline] +public fun vector::singleton<#0>($t0|e: #0): vector<#0> { + var $t1|v#1#0: vector<#0> + var $t2: &mut vector<#0> + var $t3: vector<#0> + 0: $t1 := vector::empty<#0>() + 1: $t2 := borrow_local($t1) + 2: vector::push_back<#0>($t2, $t0) + 3: $t3 := move($t1) + 4: return $t3 +} + + +[variant baseline] +public native fun vector::swap<#0>($t0|v: &mut vector<#0>, $t1|i: u64, $t2|j: u64); + + +[variant baseline] +public fun vector::swap_remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { + var $t2|last_idx#1#0: u64 + var $t3: vector<#0> + var $t4: bool + var $t5: bool + var $t6: u64 + var $t7: vector<#0> + var $t8: u64 + var $t9: u64 + var $t10: u64 + var $t11: #0 + 0: $t3 := read_ref($t0) + 1: $t4 := vector::is_empty<#0>($t3) + 2: $t5 := !($t4) + 3: if ($t5) goto 4 else goto 6 + 4: label L1 + 5: goto 10 + 6: label L0 + 7: destroy($t0) + 8: $t6 := 131072 + 9: abort($t6) + 10: label L2 + 11: $t7 := read_ref($t0) + 12: $t8 := vector::length<#0>($t7) + 13: $t9 := 1 + 14: $t10 := -($t8, $t9) + 15: vector::swap<#0>($t0, $t1, $t10) + 16: $t11 := vector::pop_back<#0>($t0) + 17: trace_local[v]($t0) + 18: return $t11 +} + + +[variant baseline] +public fun option::borrow<#0>($t0|t: option::Option<#0>): #0 { + var $t1: bool + var $t2: u64 + var $t3: vector<#0> + var $t4: u64 + var $t5: #0 + 0: $t1 := option::is_some<#0>($t0) + 1: if ($t1) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t2 := 262145 + 6: abort($t2) + 7: label L2 + 8: $t3 := get_field>.vec($t0) + 9: $t4 := 0 + 10: $t5 := vector::borrow<#0>($t3, $t4) + 11: return $t5 +} + + +[variant baseline] +public fun option::borrow_mut<#0>($t0|t: &mut option::Option<#0>): &mut #0 { + var $t1: option::Option<#0> + var $t2: bool + var $t3: u64 + var $t4: &mut vector<#0> + var $t5: u64 + var $t6: &mut #0 + 0: $t1 := read_ref($t0) + 1: $t2 := option::is_some<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 9 + 5: label L0 + 6: destroy($t0) + 7: $t3 := 262145 + 8: abort($t3) + 9: label L2 + 10: $t4 := borrow_field>.vec($t0) + 11: $t5 := 0 + 12: $t6 := vector::borrow_mut<#0>($t4, $t5) + 13: trace_local[t]($t0) + 14: return $t6 +} + + +[variant baseline] +public fun option::contains<#0>($t0|t: option::Option<#0>, $t1|e_ref: #0): bool { + var $t2: vector<#0> + var $t3: bool + 0: $t2 := get_field>.vec($t0) + 1: $t3 := vector::contains<#0>($t2, $t1) + 2: return $t3 +} + + +[variant baseline] +public fun option::swap<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): #0 { + var $t2|old_value#1#0: #0 + var $t3|vec_ref#1#0: &mut vector<#0> + var $t4: option::Option<#0> + var $t5: bool + var $t6: u64 + var $t7: &mut vector<#0> + var $t8: #0 + 0: $t4 := read_ref($t0) + 1: $t5 := option::is_some<#0>($t4) + 2: if ($t5) goto 3 else goto 5 + 3: label L1 + 4: goto 9 + 5: label L0 + 6: destroy($t0) + 7: $t6 := 262145 + 8: abort($t6) + 9: label L2 + 10: $t7 := borrow_field>.vec($t0) + 11: $t8 := vector::pop_back<#0>($t7) + 12: vector::push_back<#0>($t7, $t1) + 13: trace_local[t]($t0) + 14: return $t8 +} + + +[variant baseline] +public fun option::borrow_with_default<#0>($t0|t: option::Option<#0>, $t1|default_ref: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec_ref#1#0: vector<#0> + var $t4: vector<#0> + var $t5: bool + var $t6: u64 + 0: $t4 := get_field>.vec($t0) + 1: $t5 := vector::is_empty<#0>($t4) + 2: if ($t5) goto 3 else goto 6 + 3: label L1 + 4: $t2 := $t1 + 5: goto 9 + 6: label L0 + 7: $t6 := 0 + 8: $t2 := vector::borrow<#0>($t4, $t6) + 9: label L2 + 10: return $t2 +} + + +[variant baseline] +public fun option::destroy_none<#0>($t0|t: option::Option<#0>) { + var $t1: bool + var $t2: u64 + var $t3: vector<#0> + 0: $t1 := option::is_none<#0>($t0) + 1: if ($t1) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t2 := 262144 + 6: abort($t2) + 7: label L2 + 8: $t3 := unpack option::Option<#0>($t0) + 9: vector::destroy_empty<#0>($t3) + 10: return () +} + + +[variant baseline] +public fun option::destroy_some<#0>($t0|t: option::Option<#0>): #0 { + var $t1|elem#1#0: #0 + var $t2|vec#1#0: vector<#0> + var $t3: bool + var $t4: u64 + var $t5: &mut vector<#0> + var $t6: #0 + var $t7: vector<#0> + 0: $t3 := option::is_some<#0>($t0) + 1: if ($t3) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t4 := 262145 + 6: abort($t4) + 7: label L2 + 8: $t2 := unpack option::Option<#0>($t0) + 9: $t5 := borrow_local($t2) + 10: $t6 := vector::pop_back<#0>($t5) + 11: $t7 := move($t2) + 12: vector::destroy_empty<#0>($t7) + 13: return $t6 +} + + +[variant baseline] +public fun option::destroy_with_default<#0>($t0|t: option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec#1#0: vector<#0> + var $t4: vector<#0> + var $t5: bool + var $t6: &mut vector<#0> + 0: $t3 := unpack option::Option<#0>($t0) + 1: $t4 := copy($t3) + 2: $t5 := vector::is_empty<#0>($t4) + 3: if ($t5) goto 4 else goto 7 + 4: label L1 + 5: $t2 := $t1 + 6: goto 10 + 7: label L0 + 8: $t6 := borrow_local($t3) + 9: $t2 := vector::pop_back<#0>($t6) + 10: label L2 + 11: return $t2 +} + + +[variant baseline] +public fun option::extract<#0>($t0|t: &mut option::Option<#0>): #0 { + var $t1: option::Option<#0> + var $t2: bool + var $t3: u64 + var $t4: &mut vector<#0> + var $t5: #0 + 0: $t1 := read_ref($t0) + 1: $t2 := option::is_some<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 9 + 5: label L0 + 6: destroy($t0) + 7: $t3 := 262145 + 8: abort($t3) + 9: label L2 + 10: $t4 := borrow_field>.vec($t0) + 11: $t5 := vector::pop_back<#0>($t4) + 12: trace_local[t]($t0) + 13: return $t5 +} + + +[variant baseline] +public fun option::fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0) { + var $t2|vec_ref#1#0: &mut vector<#0> + var $t3: &mut vector<#0> + var $t4: vector<#0> + var $t5: bool + var $t6: u64 + 0: $t3 := borrow_field>.vec($t0) + 1: $t4 := read_ref($t3) + 2: $t5 := vector::is_empty<#0>($t4) + 3: if ($t5) goto 4 else goto 14 + 4: label L1 + 5: goto 10 + 6: label L0 + 7: destroy($t3) + 8: $t6 := 262144 + 9: abort($t6) + 10: label L2 + 11: vector::push_back<#0>($t3, $t1) + 12: trace_local[t]($t0) + 13: return () + 14: label L3 + 15: destroy($t0) + 16: goto 6 +} + + +[variant baseline] +public fun option::get_with_default<#0>($t0|t: option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec_ref#1#0: vector<#0> + var $t4: vector<#0> + var $t5: bool + var $t6: u64 + var $t7: #0 + 0: $t4 := get_field>.vec($t0) + 1: $t5 := vector::is_empty<#0>($t4) + 2: if ($t5) goto 3 else goto 6 + 3: label L1 + 4: $t2 := $t1 + 5: goto 10 + 6: label L0 + 7: $t6 := 0 + 8: $t7 := vector::borrow<#0>($t4, $t6) + 9: $t2 := $t7 + 10: label L2 + 11: return $t2 +} + + +[variant baseline] +public fun option::is_none<#0>($t0|t: option::Option<#0>): bool { + var $t1: vector<#0> + var $t2: bool + 0: $t1 := get_field>.vec($t0) + 1: $t2 := vector::is_empty<#0>($t1) + 2: return $t2 +} + + +[variant baseline] +public fun option::is_some<#0>($t0|t: option::Option<#0>): bool { + var $t1: vector<#0> + var $t2: bool + var $t3: bool + 0: $t1 := get_field>.vec($t0) + 1: $t2 := vector::is_empty<#0>($t1) + 2: $t3 := !($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::none<#0>(): option::Option<#0> { + var $t0: vector<#0> + var $t1: option::Option<#0> + 0: $t0 := vector::empty<#0>() + 1: $t1 := pack option::Option<#0>($t0) + 2: return $t1 +} + + +[variant baseline] +public fun option::some<#0>($t0|e: #0): option::Option<#0> { + var $t1: vector<#0> + var $t2: option::Option<#0> + 0: $t1 := vector::singleton<#0>($t0) + 1: $t2 := pack option::Option<#0>($t1) + 2: return $t2 +} + + +[variant baseline] +public fun option::swap_or_fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): option::Option<#0> { + var $t2|tmp#$2: option::Option<#0> + var $t3|old_value#1#0: option::Option<#0> + var $t4|vec_ref#1#0: &mut vector<#0> + var $t5: &mut vector<#0> + var $t6: vector<#0> + var $t7: bool + var $t8: #0 + 0: $t5 := borrow_field>.vec($t0) + 1: $t6 := read_ref($t5) + 2: $t7 := vector::is_empty<#0>($t6) + 3: if ($t7) goto 4 else goto 7 + 4: label L1 + 5: $t2 := option::none<#0>() + 6: goto 10 + 7: label L0 + 8: $t8 := vector::pop_back<#0>($t5) + 9: $t2 := option::some<#0>($t8) + 10: label L2 + 11: vector::push_back<#0>($t5, $t1) + 12: trace_local[t]($t0) + 13: return $t2 +} + + +[variant baseline] +public fun option::to_vec<#0>($t0|t: option::Option<#0>): vector<#0> { + var $t1: vector<#0> + 0: $t1 := unpack option::Option<#0>($t0) + 1: return $t1 +} + + +[variant baseline] +public fun ascii::append($t0|string: &mut ascii::String, $t1|other: ascii::String) { + var $t2: &mut vector + var $t3: vector + 0: $t2 := borrow_field.bytes($t0) + 1: $t3 := ascii::into_bytes($t1) + 2: vector::append($t2, $t3) + 3: trace_local[string]($t0) + 4: return () +} + + +[variant baseline] +public fun ascii::index_of($t0|string: ascii::String, $t1|substr: ascii::String): u64 { + var $t2|tmp#$2: bool + var $t3|i#1#0: u64 + var $t4|j#1#0: u64 + var $t5|m#1#0: u64 + var $t6|n#1#0: u64 + var $t7: u64 + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u64 + var $t12: bool + var $t13: u64 + var $t14: bool + var $t15: vector + var $t16: u64 + var $t17: u8 + var $t18: vector + var $t19: u8 + var $t20: bool + var $t21: u64 + var $t22: bool + var $t23: u64 + 0: $t7 := 0 + 1: $t3 := $t7 + 2: $t8 := ascii::length($t0) + 3: $t9 := ascii::length($t1) + 4: $t10 := <($t8, $t9) + 5: if ($t10) goto 6 else goto 8 + 6: label L1 + 7: return $t8 + 8: label L0 + 9: $t11 := -($t8, $t9) + 10: $t12 := <=($t3, $t11) + 11: if ($t12) goto 12 else goto 45 + 12: label L3 + 13: $t13 := 0 + 14: $t4 := $t13 + 15: label L10 + 16: $t14 := <($t4, $t9) + 17: if ($t14) goto 18 else goto 27 + 18: label L5 + 19: label L6 + 20: $t15 := get_field.bytes($t0) + 21: $t16 := +($t3, $t4) + 22: $t17 := vector::borrow($t15, $t16) + 23: $t18 := get_field.bytes($t1) + 24: $t19 := vector::borrow($t18, $t4) + 25: $t2 := ==($t17, $t19) + 26: goto 30 + 27: label L4 + 28: $t20 := false + 29: $t2 := $t20 + 30: label L7 + 31: if ($t2) goto 32 else goto 36 + 32: label L9 + 33: $t21 := 1 + 34: $t4 := +($t4, $t21) + 35: goto 15 + 36: label L8 + 37: $t22 := ==($t4, $t9) + 38: if ($t22) goto 39 else goto 41 + 39: label L12 + 40: return $t3 + 41: label L11 + 42: $t23 := 1 + 43: $t3 := +($t3, $t23) + 44: goto 8 + 45: label L2 + 46: return $t8 +} + + +[variant baseline] +public fun ascii::insert($t0|s: &mut ascii::String, $t1|at: u64, $t2|o: ascii::String) { + var $t3|e#1#2: u8 + var $t4|v#1#1: vector + var $t5: ascii::String + var $t6: u64 + var $t7: bool + var $t8: u64 + var $t9: vector + var $t10: bool + var $t11: bool + var $t12: &mut vector + var $t13: u8 + var $t14: &mut vector + var $t15: vector + 0: $t5 := read_ref($t0) + 1: $t6 := ascii::length($t5) + 2: $t7 := <=($t1, $t6) + 3: if ($t7) goto 4 else goto 6 + 4: label L1 + 5: goto 10 + 6: label L0 + 7: destroy($t0) + 8: $t8 := 65537 + 9: abort($t8) + 10: label L2 + 11: $t4 := ascii::into_bytes($t2) + 12: label L5 + 13: $t9 := copy($t4) + 14: $t10 := vector::is_empty($t9) + 15: $t11 := !($t10) + 16: if ($t11) goto 17 else goto 23 + 17: label L4 + 18: $t12 := borrow_local($t4) + 19: $t13 := vector::pop_back($t12) + 20: $t14 := borrow_field.bytes($t0) + 21: vector::insert($t14, $t13, $t1) + 22: goto 12 + 23: label L3 + 24: destroy($t0) + 25: $t15 := move($t4) + 26: vector::destroy_empty($t15) + 27: trace_local[s]($t0) + 28: return () +} + + +[variant baseline] +public fun ascii::is_empty($t0|string: ascii::String): bool { + var $t1: vector + var $t2: bool + 0: $t1 := get_field.bytes($t0) + 1: $t2 := vector::is_empty($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::length($t0|string: ascii::String): u64 { + var $t1: vector + var $t2: u64 + 0: $t1 := ascii::as_bytes($t0) + 1: $t2 := vector::length($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::all_characters_printable($t0|string: ascii::String): bool { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|i#1#12: u64 + var $t4|i#1#9: u64 + var $t5|stop#1#9: u64 + var $t6|v#1#3: vector + var $t7: vector + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u8 + var $t12: bool + var $t13: bool + var $t14: bool + var $t15: u64 + var $t16: bool + 0: $t7 := get_field.bytes($t0) + 1: $t8 := vector::length($t7) + 2: $t9 := 0 + 3: $t4 := $t9 + 4: label L5 + 5: $t10 := <($t4, $t8) + 6: if ($t10) goto 7 else goto 20 + 7: label L1 + 8: $t11 := vector::borrow($t7, $t4) + 9: $t12 := ascii::is_printable_char($t11) + 10: $t13 := !($t12) + 11: if ($t13) goto 12 else goto 16 + 12: label L3 + 13: $t14 := false + 14: $t2 := $t14 + 15: goto 23 + 16: label L2 + 17: $t15 := 1 + 18: $t4 := +($t4, $t15) + 19: goto 4 + 20: label L0 + 21: $t16 := true + 22: $t2 := $t16 + 23: label L4 + 24: return $t2 +} + + +[variant baseline] +public fun ascii::string($t0|bytes: vector): ascii::String { + var $t1|x#1#0: option::Option + var $t2: option::Option + var $t3: bool + var $t4: u64 + var $t5: ascii::String + 0: $t2 := ascii::try_string($t0) + 1: $t3 := option::is_some($t2) + 2: if ($t3) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t4 := 65536 + 7: abort($t4) + 8: label L2 + 9: $t5 := option::destroy_some($t2) + 10: return $t5 +} + + +[variant baseline] +public fun ascii::as_bytes($t0|string: ascii::String): vector { + var $t1: vector + 0: $t1 := get_field.bytes($t0) + 1: return $t1 +} + + +[variant baseline] +public fun ascii::byte($t0|char: ascii::Char): u8 { + var $t1: u8 + 0: $t1 := unpack ascii::Char($t0) + 1: return $t1 +} + + +[variant baseline] +public fun ascii::char($t0|byte: u8): ascii::Char { + var $t1: bool + var $t2: u64 + var $t3: ascii::Char + 0: $t1 := ascii::is_valid_char($t0) + 1: if ($t1) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t2 := 65536 + 6: abort($t2) + 7: label L2 + 8: $t3 := pack ascii::Char($t0) + 9: return $t3 +} + + +[variant baseline] +fun ascii::char_to_lowercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: bool + var $t5: u8 + var $t6: bool + var $t7: u8 + 0: $t3 := 65 + 1: $t4 := >=($t0, $t3) + 2: if ($t4) goto 3 else goto 7 + 3: label L1 + 4: $t5 := 90 + 5: $t1 := <=($t0, $t5) + 6: goto 10 + 7: label L0 + 8: $t6 := false + 9: $t1 := $t6 + 10: label L2 + 11: if ($t1) goto 12 else goto 16 + 12: label L4 + 13: $t7 := 32 + 14: $t2 := +($t0, $t7) + 15: goto 18 + 16: label L3 + 17: $t2 := $t0 + 18: label L5 + 19: return $t2 +} + + +[variant baseline] +fun ascii::char_to_uppercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: bool + var $t5: u8 + var $t6: bool + var $t7: u8 + 0: $t3 := 97 + 1: $t4 := >=($t0, $t3) + 2: if ($t4) goto 3 else goto 7 + 3: label L1 + 4: $t5 := 122 + 5: $t1 := <=($t0, $t5) + 6: goto 10 + 7: label L0 + 8: $t6 := false + 9: $t1 := $t6 + 10: label L2 + 11: if ($t1) goto 12 else goto 16 + 12: label L4 + 13: $t7 := 32 + 14: $t2 := -($t0, $t7) + 15: goto 18 + 16: label L3 + 17: $t2 := $t0 + 18: label L5 + 19: return $t2 +} + + +[variant baseline] +public fun ascii::into_bytes($t0|string: ascii::String): vector { + var $t1: vector + 0: $t1 := unpack ascii::String($t0) + 1: return $t1 +} + + +[variant baseline] +public fun ascii::is_printable_char($t0|byte: u8): bool { + var $t1|tmp#$1: bool + var $t2: u8 + var $t3: bool + var $t4: u8 + var $t5: bool + 0: $t2 := 32 + 1: $t3 := >=($t0, $t2) + 2: if ($t3) goto 3 else goto 7 + 3: label L1 + 4: $t4 := 126 + 5: $t1 := <=($t0, $t4) + 6: goto 10 + 7: label L0 + 8: $t5 := false + 9: $t1 := $t5 + 10: label L2 + 11: return $t1 } [variant baseline] -public native fun vector::destroy_empty<#0>($t0|v: vector<#0>); +public fun ascii::is_valid_char($t0|b: u8): bool { + var $t1: u8 + var $t2: bool + 0: $t1 := 127 + 1: $t2 := <=($t0, $t1) + 2: return $t2 +} [variant baseline] -public native fun vector::empty<#0>(): vector<#0>; +public fun ascii::pop_char($t0|string: &mut ascii::String): ascii::Char { + var $t1: &mut vector + var $t2: u8 + var $t3: ascii::Char + 0: $t1 := borrow_field.bytes($t0) + 1: $t2 := vector::pop_back($t1) + 2: $t3 := pack ascii::Char($t2) + 3: trace_local[string]($t0) + 4: return $t3 +} [variant baseline] -public fun vector::index_of<#0>($t0|v: vector<#0>, $t1|e: #0): (bool, u64) { - var $t2|i#1#0: u64 - var $t3|len#1#0: u64 - var $t4: u64 - var $t5: u64 - var $t6: bool - var $t7: #0 - var $t8: bool - var $t9: bool - var $t10: u64 - var $t11: bool - var $t12: u64 - 0: $t4 := 0 - 1: $t2 := $t4 - 2: $t5 := vector::length<#0>($t0) - 3: label L5 - 4: $t6 := <($t2, $t5) - 5: if ($t6) goto 6 else goto 18 - 6: label L1 - 7: label L2 - 8: $t7 := vector::borrow<#0>($t0, $t2) - 9: $t8 := ==($t7, $t1) - 10: if ($t8) goto 11 else goto 14 - 11: label L4 - 12: $t9 := true - 13: return ($t9, $t2) - 14: label L3 - 15: $t10 := 1 - 16: $t2 := +($t2, $t10) - 17: goto 3 - 18: label L0 - 19: $t11 := false - 20: $t12 := 0 - 21: return ($t11, $t12) +public fun ascii::push_char($t0|string: &mut ascii::String, $t1|char: ascii::Char) { + var $t2: &mut vector + var $t3: u8 + 0: $t2 := borrow_field.bytes($t0) + 1: $t3 := get_field.byte($t1) + 2: vector::push_back($t2, $t3) + 3: trace_local[string]($t0) + 4: return () } [variant baseline] -public fun vector::insert<#0>($t0|v: &mut vector<#0>, $t1|e: #0, $t2|i: u64) { - var $t3|len#1#0: u64 - var $t4: vector<#0> - var $t5: u64 - var $t6: bool - var $t7: u64 +public fun ascii::substring($t0|string: ascii::String, $t1|i: u64, $t2|j: u64): ascii::String { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: vector + var $t5|i#1#3: u64 + var $t6|i#1#6: u64 + var $t7|stop#1#3: u64 var $t8: bool var $t9: u64 - 0: $t4 := read_ref($t0) - 1: $t5 := vector::length<#0>($t4) - 2: $t6 := >($t2, $t5) - 3: if ($t6) goto 4 else goto 8 - 4: label L1 - 5: destroy($t0) - 6: $t7 := 131072 - 7: abort($t7) - 8: label L0 - 9: vector::push_back<#0>($t0, $t1) - 10: label L5 - 11: $t8 := <($t2, $t5) - 12: if ($t8) goto 13 else goto 19 + var $t10: bool + var $t11: u64 + var $t12: vector + var $t13: bool + var $t14: &mut vector + var $t15: vector + var $t16: u8 + var $t17: u64 + var $t18: vector + var $t19: ascii::String + 0: $t8 := <=($t1, $t2) + 1: if ($t8) goto 2 else goto 6 + 2: label L1 + 3: $t9 := ascii::length($t0) + 4: $t3 := <=($t2, $t9) + 5: goto 9 + 6: label L0 + 7: $t10 := false + 8: $t3 := $t10 + 9: label L2 + 10: if ($t3) goto 11 else goto 13 + 11: label L4 + 12: goto 16 13: label L3 - 14: label L4 - 15: vector::swap<#0>($t0, $t2, $t5) - 16: $t9 := 1 - 17: $t2 := +($t2, $t9) - 18: goto 10 - 19: label L2 - 20: destroy($t0) - 21: trace_local[v]($t0) - 22: return () + 14: $t11 := 65537 + 15: abort($t11) + 16: label L5 + 17: $t12 := [] + 18: $t4 := $t12 + 19: $t5 := $t1 + 20: label L8 + 21: $t13 := <($t5, $t2) + 22: if ($t13) goto 23 else goto 31 + 23: label L7 + 24: $t14 := borrow_local($t4) + 25: $t15 := get_field.bytes($t0) + 26: $t16 := vector::borrow($t15, $t5) + 27: vector::push_back($t14, $t16) + 28: $t17 := 1 + 29: $t5 := +($t5, $t17) + 30: goto 20 + 31: label L6 + 32: $t18 := move($t4) + 33: $t19 := pack ascii::String($t18) + 34: return $t19 } [variant baseline] -public fun vector::is_empty<#0>($t0|v: vector<#0>): bool { - var $t1: u64 - var $t2: u64 - var $t3: bool - 0: $t1 := vector::length<#0>($t0) - 1: $t2 := 0 - 2: $t3 := ==($t1, $t2) - 3: return $t3 +public fun ascii::to_lowercase($t0|string: ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: vector + var $t10|v#1#3: vector + var $t11: vector + var $t12: vector + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u8 + var $t17: &mut vector + var $t18: u8 + var $t19: u64 + var $t20: vector + var $t21: ascii::String + 0: $t11 := ascii::as_bytes($t0) + 1: $t12 := [] + 2: $t7 := $t12 + 3: $t13 := vector::length($t11) + 4: $t14 := 0 + 5: $t6 := $t14 + 6: label L2 + 7: $t15 := <($t6, $t13) + 8: if ($t15) goto 9 else goto 17 + 9: label L1 + 10: $t16 := vector::borrow($t11, $t6) + 11: $t17 := borrow_local($t7) + 12: $t18 := ascii::char_to_lowercase($t16) + 13: vector::push_back($t17, $t18) + 14: $t19 := 1 + 15: $t6 := +($t6, $t19) + 16: goto 6 + 17: label L0 + 18: $t20 := move($t7) + 19: $t21 := pack ascii::String($t20) + 20: return $t21 } [variant baseline] -public native fun vector::length<#0>($t0|v: vector<#0>): u64; +public fun ascii::to_uppercase($t0|string: ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: vector + var $t10|v#1#3: vector + var $t11: vector + var $t12: vector + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u8 + var $t17: &mut vector + var $t18: u8 + var $t19: u64 + var $t20: vector + var $t21: ascii::String + 0: $t11 := ascii::as_bytes($t0) + 1: $t12 := [] + 2: $t7 := $t12 + 3: $t13 := vector::length($t11) + 4: $t14 := 0 + 5: $t6 := $t14 + 6: label L2 + 7: $t15 := <($t6, $t13) + 8: if ($t15) goto 9 else goto 17 + 9: label L1 + 10: $t16 := vector::borrow($t11, $t6) + 11: $t17 := borrow_local($t7) + 12: $t18 := ascii::char_to_uppercase($t16) + 13: vector::push_back($t17, $t18) + 14: $t19 := 1 + 15: $t6 := +($t6, $t19) + 16: goto 6 + 17: label L0 + 18: $t20 := move($t7) + 19: $t21 := pack ascii::String($t20) + 20: return $t21 +} [variant baseline] -public native fun vector::pop_back<#0>($t0|v: &mut vector<#0>): #0; +public fun ascii::try_string($t0|bytes: vector): option::Option { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|tmp#$3: option::Option + var $t4|i#1#12: u64 + var $t5|i#1#9: u64 + var $t6|stop#1#9: u64 + var $t7|v#1#3: vector + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u8 + var $t12: bool + var $t13: bool + var $t14: bool + var $t15: u64 + var $t16: bool + var $t17: ascii::String + 0: $t8 := vector::length($t0) + 1: $t9 := 0 + 2: $t5 := $t9 + 3: label L5 + 4: $t10 := <($t5, $t8) + 5: if ($t10) goto 6 else goto 19 + 6: label L1 + 7: $t11 := vector::borrow($t0, $t5) + 8: $t12 := ascii::is_valid_char($t11) + 9: $t13 := !($t12) + 10: if ($t13) goto 11 else goto 15 + 11: label L3 + 12: $t14 := false + 13: $t2 := $t14 + 14: goto 22 + 15: label L2 + 16: $t15 := 1 + 17: $t5 := +($t5, $t15) + 18: goto 3 + 19: label L0 + 20: $t16 := true + 21: $t2 := $t16 + 22: label L4 + 23: if ($t2) goto 24 else goto 28 + 24: label L7 + 25: $t17 := pack ascii::String($t0) + 26: $t3 := option::some($t17) + 27: goto 30 + 28: label L6 + 29: $t3 := option::none() + 30: label L8 + 31: return $t3 +} [variant baseline] -public native fun vector::push_back<#0>($t0|v: &mut vector<#0>, $t1|e: #0); +public fun string::append($t0|s: &mut string::String, $t1|r: string::String) { + var $t2: &mut vector + var $t3: vector + 0: $t2 := borrow_field.bytes($t0) + 1: $t3 := get_field.bytes($t1) + 2: vector::append($t2, $t3) + 3: trace_local[s]($t0) + 4: return () +} [variant baseline] -public fun vector::remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { - var $t2|tmp#$2: u64 - var $t3|tmp#$3: &mut vector<#0> - var $t4|len#1#0: u64 - var $t5: vector<#0> - var $t6: u64 - var $t7: bool - var $t8: u64 +public fun string::index_of($t0|s: string::String, $t1|r: string::String): u64 { + var $t2: vector + var $t3: vector + var $t4: u64 + 0: $t2 := get_field.bytes($t0) + 1: $t3 := get_field.bytes($t1) + 2: $t4 := string::internal_index_of($t2, $t3) + 3: return $t4 +} + + +[variant baseline] +public fun string::insert($t0|s: &mut string::String, $t1|at: u64, $t2|o: string::String) { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: vector + var $t5|end#1#0: string::String + var $t6|front#1#0: string::String + var $t7|l#1#0: u64 + var $t8: vector var $t9: u64 - var $t10: u64 + var $t10: bool var $t11: bool var $t12: u64 - var $t13: u64 + var $t13: string::String var $t14: u64 - var $t15: #0 - 0: $t5 := read_ref($t0) - 1: $t6 := vector::length<#0>($t5) - 2: $t7 := >=($t1, $t6) - 3: if ($t7) goto 4 else goto 8 + var $t15: string::String + var $t16: u64 + var $t17: string::String + var $t18: string::String + var $t19: &mut string::String + var $t20: &mut string::String + var $t21: string::String + 0: $t8 := get_field.bytes($t0) + 1: $t9 := vector::length($t8) + 2: $t10 := <=($t1, $t9) + 3: if ($t10) goto 4 else goto 7 4: label L1 - 5: destroy($t0) - 6: $t8 := 131072 - 7: abort($t8) - 8: label L0 - 9: $t9 := 1 - 10: $t10 := -($t6, $t9) - 11: label L5 - 12: $t11 := <($t1, $t10) - 13: if ($t11) goto 14 else goto 22 + 5: $t3 := string::internal_is_char_boundary($t8, $t1) + 6: goto 10 + 7: label L0 + 8: $t11 := false + 9: $t3 := $t11 + 10: label L2 + 11: if ($t3) goto 12 else goto 14 + 12: label L4 + 13: goto 18 14: label L3 - 15: label L4 - 16: $t12 := copy($t1) - 17: $t13 := 1 - 18: $t14 := +($t1, $t13) - 19: $t1 := $t14 - 20: vector::swap<#0>($t0, $t12, $t14) - 21: goto 11 - 22: label L2 - 23: $t15 := vector::pop_back<#0>($t0) - 24: trace_local[v]($t0) - 25: return $t15 + 15: destroy($t0) + 16: $t12 := 2 + 17: abort($t12) + 18: label L5 + 19: $t13 := read_ref($t0) + 20: $t14 := string::length($t13) + 21: $t15 := read_ref($t0) + 22: $t16 := 0 + 23: $t6 := string::substring($t15, $t16, $t1) + 24: $t17 := read_ref($t0) + 25: $t18 := string::substring($t17, $t1, $t14) + 26: $t19 := borrow_local($t6) + 27: string::append($t19, $t2) + 28: $t20 := borrow_local($t6) + 29: string::append($t20, $t18) + 30: $t21 := move($t6) + 31: write_ref($t0, $t21) + 32: trace_local[s]($t0) + 33: return () } [variant baseline] -public fun vector::reverse<#0>($t0|v: &mut vector<#0>) { - var $t1|back_index#1#0: u64 - var $t2|front_index#1#0: u64 - var $t3|len#1#0: u64 - var $t4: vector<#0> - var $t5: u64 - var $t6: u64 - var $t7: bool - var $t8: u64 - var $t9: u64 - var $t10: bool - var $t11: u64 - var $t12: u64 - 0: $t4 := read_ref($t0) - 1: $t5 := vector::length<#0>($t4) - 2: $t6 := 0 - 3: $t7 := ==($t5, $t6) - 4: if ($t7) goto 5 else goto 9 - 5: label L1 - 6: destroy($t0) - 7: trace_local[v]($t0) - 8: return () - 9: label L0 - 10: $t8 := 0 - 11: $t2 := $t8 - 12: $t9 := 1 - 13: $t1 := -($t5, $t9) - 14: label L5 - 15: $t10 := <($t2, $t1) - 16: if ($t10) goto 17 else goto 25 - 17: label L3 - 18: label L4 - 19: vector::swap<#0>($t0, $t2, $t1) - 20: $t11 := 1 - 21: $t2 := +($t2, $t11) - 22: $t12 := 1 - 23: $t1 := -($t1, $t12) - 24: goto 14 - 25: label L2 - 26: destroy($t0) - 27: trace_local[v]($t0) - 28: return () +public fun string::is_empty($t0|s: string::String): bool { + var $t1: vector + var $t2: bool + 0: $t1 := get_field.bytes($t0) + 1: $t2 := vector::is_empty($t1) + 2: return $t2 } [variant baseline] -public fun vector::singleton<#0>($t0|e: #0): vector<#0> { - var $t1|v#1#0: vector<#0> - var $t2: &mut vector<#0> - var $t3: vector<#0> - 0: $t1 := vector::empty<#0>() - 1: $t2 := borrow_local($t1) - 2: vector::push_back<#0>($t2, $t0) - 3: $t3 := move($t1) - 4: return $t3 +public fun string::length($t0|s: string::String): u64 { + var $t1: vector + var $t2: u64 + 0: $t1 := get_field.bytes($t0) + 1: $t2 := vector::length($t1) + 2: return $t2 } [variant baseline] -public native fun vector::swap<#0>($t0|v: &mut vector<#0>, $t1|i: u64, $t2|j: u64); +public fun string::as_bytes($t0|s: string::String): vector { + var $t1: vector + 0: $t1 := get_field.bytes($t0) + 1: return $t1 +} [variant baseline] -public fun vector::swap_remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { - var $t2|last_idx#1#0: u64 - var $t3: vector<#0> - var $t4: bool - var $t5: bool - var $t6: u64 - var $t7: vector<#0> - var $t8: u64 +public fun string::into_bytes($t0|s: string::String): vector { + var $t1: vector + 0: $t1 := unpack string::String($t0) + 1: return $t1 +} + + +[variant baseline] +public fun string::bytes($t0|s: string::String): vector { + var $t1: vector + 0: $t1 := string::as_bytes($t0) + 1: return $t1 +} + + +[variant baseline] +public fun string::substring($t0|s: string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3|tmp#$3: bool + var $t4|tmp#$4: bool + var $t5|tmp#$5: bool + var $t6|bytes#1#0: vector + var $t7|l#1#0: u64 + var $t8: vector var $t9: u64 - var $t10: u64 - var $t11: #0 - 0: $t3 := read_ref($t0) - 1: $t4 := vector::is_empty<#0>($t3) - 2: $t5 := !($t4) - 3: if ($t5) goto 4 else goto 6 + var $t10: bool + var $t11: bool + var $t12: bool + var $t13: bool + var $t14: u64 + var $t15: vector + var $t16: string::String + 0: $t8 := get_field.bytes($t0) + 1: $t9 := vector::length($t8) + 2: $t10 := <=($t2, $t9) + 3: if ($t10) goto 4 else goto 7 4: label L1 - 5: goto 10 - 6: label L0 - 7: destroy($t0) - 8: $t6 := 131072 - 9: abort($t6) + 5: $t3 := <=($t1, $t2) + 6: goto 10 + 7: label L0 + 8: $t11 := false + 9: $t3 := $t11 10: label L2 - 11: $t7 := read_ref($t0) - 12: $t8 := vector::length<#0>($t7) - 13: $t9 := 1 - 14: $t10 := -($t8, $t9) - 15: vector::swap<#0>($t0, $t1, $t10) - 16: $t11 := vector::pop_back<#0>($t0) - 17: trace_local[v]($t0) - 18: return $t11 + 11: if ($t3) goto 12 else goto 15 + 12: label L4 + 13: $t4 := string::internal_is_char_boundary($t8, $t1) + 14: goto 18 + 15: label L3 + 16: $t12 := false + 17: $t4 := $t12 + 18: label L5 + 19: if ($t4) goto 20 else goto 23 + 20: label L7 + 21: $t5 := string::internal_is_char_boundary($t8, $t2) + 22: goto 26 + 23: label L6 + 24: $t13 := false + 25: $t5 := $t13 + 26: label L8 + 27: if ($t5) goto 28 else goto 30 + 28: label L10 + 29: goto 33 + 30: label L9 + 31: $t14 := 2 + 32: abort($t14) + 33: label L11 + 34: $t15 := string::internal_sub_string($t8, $t1, $t2) + 35: $t16 := pack string::String($t15) + 36: return $t16 +} + + +[variant baseline] +public fun string::append_utf8($t0|s: &mut string::String, $t1|bytes: vector) { + var $t2: string::String + 0: $t2 := string::utf8($t1) + 1: string::append($t0, $t2) + 2: trace_local[s]($t0) + 3: return () +} + + +[variant baseline] +public fun string::from_ascii($t0|s: ascii::String): string::String { + var $t1: vector + var $t2: string::String + 0: $t1 := ascii::into_bytes($t0) + 1: $t2 := pack string::String($t1) + 2: return $t2 +} + + +[variant baseline] +native fun string::internal_check_utf8($t0|v: vector): bool; + + +[variant baseline] +native fun string::internal_index_of($t0|v: vector, $t1|r: vector): u64; + + +[variant baseline] +native fun string::internal_is_char_boundary($t0|v: vector, $t1|i: u64): bool; + + +[variant baseline] +native fun string::internal_sub_string($t0|v: vector, $t1|i: u64, $t2|j: u64): vector; + + +[variant baseline] +public fun string::sub_string($t0|s: string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3: string::String + 0: $t3 := string::substring($t0, $t1, $t2) + 1: return $t3 +} + + +[variant baseline] +public fun string::to_ascii($t0|s: string::String): ascii::String { + var $t1: vector + var $t2: ascii::String + 0: $t1 := unpack string::String($t0) + 1: $t2 := ascii::string($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::try_utf8($t0|bytes: vector): option::Option { + var $t1|tmp#$1: option::Option + var $t2: bool + var $t3: string::String + 0: $t2 := string::internal_check_utf8($t0) + 1: if ($t2) goto 2 else goto 6 + 2: label L1 + 3: $t3 := pack string::String($t0) + 4: $t1 := option::some($t3) + 5: goto 8 + 6: label L0 + 7: $t1 := option::none() + 8: label L2 + 9: return $t1 +} + + +[variant baseline] +public fun string::utf8($t0|bytes: vector): string::String { + var $t1: bool + var $t2: u64 + var $t3: string::String + 0: $t1 := string::internal_check_utf8($t0) + 1: if ($t1) goto 2 else goto 4 + 2: label L1 + 3: goto 7 + 4: label L0 + 5: $t2 := 1 + 6: abort($t2) + 7: label L2 + 8: $t3 := pack string::String($t0) + 9: return $t3 } @@ -925,6 +4439,10 @@ fun vector::borrow_mut[baseline] borrowed_by: Reference($t0) -> {([], Return(0))} borrows_from: Return(0) -> {([], Reference($t0))} +fun option::borrow_mut[baseline] +borrowed_by: Reference($t0) -> {(.vec (vector<#0>)/[], Return(0))} +borrows_from: Return(0) -> {(.vec (vector<#0>)/[], Reference($t0))} + fun Collection::borrow_mut[baseline] borrowed_by: Reference($t0) -> {(.items (vector<#0>)/[], Return(0))} borrows_from: Return(0) -> {(.items (vector<#0>)/[], Reference($t0))} diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/hyper_edge.move b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/hyper_edge.move index 9aee1d251b47c..a0f97ccdc06d9 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/borrow/hyper_edge.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/borrow/hyper_edge.move @@ -1,9 +1,12 @@ +// dep: ../move-stdlib/sources/macros.move +// dep: ../move-stdlib/sources/u64.move +// dep: ../move-stdlib/sources/option.move +// dep: ../move-stdlib/sources/ascii.move +// dep: ../move-stdlib/sources/string.move // dep: ../move-stdlib/sources/vector.move module 0x2::Collection { - use std::vector; - - struct Collection has drop { + public struct Collection has drop { items: vector, owner: address, } @@ -23,10 +26,10 @@ module 0x2::Collection { module 0x2::Test { use 0x2::Collection; - struct Token has drop { value: u64 } + public struct Token has drop { value: u64 } public fun foo(i: u64) { - let c = Collection::make_collection>(); + let mut c = Collection::make_collection>(); let t = Collection::borrow_mut(&mut c, i); t.value = 0; } diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/borrow_strong/basic_test.move b/external-crates/move/crates/move-stackless-bytecode/tests/borrow_strong/basic_test.move index 9b530c7ebec2f..0582dcc24b1c3 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/borrow_strong/basic_test.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/borrow_strong/basic_test.move @@ -1,11 +1,11 @@ module 0x42::TestBorrow { - struct R has copy, drop { + public struct R has copy, drop { x: u64, y: u64 } fun test1() : R { - let r = R {x: 3, y: 4}; + let mut r = R {x: 3, y: 4}; let r_ref = &mut r; let x_ref = &mut r_ref.x; *x_ref = 0; @@ -22,7 +22,7 @@ module 0x42::TestBorrow { } fun test4() : R { - let r = R {x: 3, y: 4}; + let mut r = R {x: 3, y: 4}; let r_ref = &mut r; test3(r_ref, 0); r @@ -33,7 +33,7 @@ module 0x42::TestBorrow { } fun test6() : R { - let r = R {x: 3, y: 4}; + let mut r = R {x: 3, y: 4}; let r_ref = &mut r; let x_ref = test5(r_ref); test2(x_ref, 0); @@ -41,19 +41,19 @@ module 0x42::TestBorrow { } fun test7(b: bool) { - let r1 = R {x: 3, y: 4}; - let r2 = R {x: 4, y: 5}; - let r_ref = &mut r1; + let mut r1 = R {x: 3, y: 4}; + let mut r2 = R {x: 4, y: 5}; + let mut r_ref = &mut r1; if (b) { r_ref = &mut r2; }; test3(r_ref, 0) } - fun test8(b: bool, n: u64, r_ref: &mut R) { - let r1 = R {x: 3, y: 4}; - let r2 = R {x: 4, y: 5}; - let t_ref = &mut r2; + fun test8(b: bool, mut n: u64, r_ref: &mut R) { + let mut r1 = R {x: 3, y: 4}; + let mut r2 = R {x: 4, y: 5}; + let mut t_ref = &mut r2; while (0 < n) { if (n/2 == 0) { t_ref = &mut r1 @@ -70,7 +70,7 @@ module 0x42::TestBorrow { } fun test9(b : bool, r_ref: &mut R) : &mut u64 { - let r_field = &mut r_ref.x; + let mut r_field = &mut r_ref.x; if(b) { r_field = &mut r_ref.y; }; @@ -79,9 +79,9 @@ module 0x42::TestBorrow { } fun test10(b : bool) : R { - let r = R {x: 3, y: 4}; + let mut r = R {x: 3, y: 4}; let r_ref = &mut r; - let r_field = &mut r_ref.x; + let mut r_field = &mut r_ref.x; if(b) { r_field = test9(b, r_ref); }; diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/eliminate_imm_refs/basic_test.move b/external-crates/move/crates/move-stackless-bytecode/tests/eliminate_imm_refs/basic_test.move index 8dada99bc3612..82065de503a20 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/eliminate_imm_refs/basic_test.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/eliminate_imm_refs/basic_test.move @@ -1,11 +1,11 @@ module 0x42::TestEliminateImmRefs { - struct R has copy, drop { + public struct R has copy, drop { x: u64 } fun test1() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; let x_ref = &mut r_ref.x; *x_ref = 0; diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_internal_refs.move b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_internal_refs.move index 9d5d2663d9850..15df8e2cbee95 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_internal_refs.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_internal_refs.move @@ -1,6 +1,6 @@ module 0x1::LeakInternalRefs { - struct S { f: u64, g: u64 } + public struct S { f: u64, g: u64 } fun leak_mut_ref(s: &mut S): &mut u64 { &mut s.f @@ -23,7 +23,7 @@ module 0x1::LeakInternalRefs { } fun leak_in_loop(x: &mut u64, s: &mut S): &mut u64 { - let i = 0; + let mut i = 0; while (i < 10) { if (i == 7) { return &mut s.f diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_refs_into_vec.exp b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_refs_into_vec.exp index a5e235909a205..30333879c28e8 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_refs_into_vec.exp +++ b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_refs_into_vec.exp @@ -1,5 +1,339 @@ ============ initial translation from Move ================ +[variant baseline] +public fun u64::diff($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := >($t7, $t8) + 7: if ($t9) goto 8 else goto 14 + 8: label L1 + 9: $t10 := move($t3) + 10: $t11 := move($t4) + 11: $t12 := -($t10, $t11) + 12: $t2 := $t12 + 13: goto 20 + 14: label L0 + 15: $t13 := move($t4) + 16: $t14 := move($t3) + 17: $t15 := -($t13, $t14) + 18: $t2 := $t15 + 19: goto 20 + 20: label L2 + 21: $t16 := move($t2) + 22: return $t16 +} + + +[variant baseline] +public fun u64::divide_and_round_up($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: u64 + var $t10: u64 + var $t11: bool + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := %($t7, $t8) + 7: $t10 := 0 + 8: $t11 := ==($t9, $t10) + 9: if ($t11) goto 10 else goto 16 + 10: label L1 + 11: $t12 := move($t3) + 12: $t13 := move($t4) + 13: $t14 := /($t12, $t13) + 14: $t2 := $t14 + 15: goto 24 + 16: label L0 + 17: $t15 := move($t3) + 18: $t16 := move($t4) + 19: $t17 := /($t15, $t16) + 20: $t18 := 1 + 21: $t19 := +($t17, $t18) + 22: $t2 := $t19 + 23: goto 24 + 24: label L2 + 25: $t20 := move($t2) + 26: return $t20 +} + + +[variant baseline] +public fun u64::max($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := >($t7, $t8) + 7: if ($t9) goto 8 else goto 12 + 8: label L1 + 9: $t10 := move($t3) + 10: $t2 := $t10 + 11: goto 16 + 12: label L0 + 13: $t11 := move($t4) + 14: $t2 := $t11 + 15: goto 16 + 16: label L2 + 17: $t12 := move($t2) + 18: return $t12 +} + + +[variant baseline] +public fun u64::min($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := <($t7, $t8) + 7: if ($t9) goto 8 else goto 12 + 8: label L1 + 9: $t10 := move($t3) + 10: $t2 := $t10 + 11: goto 16 + 12: label L0 + 13: $t11 := move($t4) + 14: $t2 := $t11 + 15: goto 16 + 16: label L2 + 17: $t12 := move($t2) + 18: return $t12 +} + + +[variant baseline] +public fun u64::pow($t0|base: u64, $t1|exponent: u8): u64 { + var $t2|base#1#1: u64 + var $t3|exponent#1#1: u8 + var $t4|res#1#1: u64 + var $t5: u64 + var $t6: u8 + var $t7: u64 + var $t8: u8 + var $t9: u8 + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: bool + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u8 + var $t20: u8 + var $t21: u8 + var $t22: u64 + var $t23: u64 + var $t24: u64 + var $t25: u8 + var $t26: u8 + var $t27: u8 + var $t28: u64 + 0: $t5 := move($t0) + 1: $t2 := $t5 + 2: $t6 := move($t1) + 3: $t3 := $t6 + 4: $t7 := 1 + 5: $t4 := $t7 + 6: goto 7 + 7: label L5 + 8: $t8 := copy($t3) + 9: $t9 := 1 + 10: $t10 := >=($t8, $t9) + 11: if ($t10) goto 12 else goto 41 + 12: label L1 + 13: goto 14 + 14: label L2 + 15: $t11 := copy($t3) + 16: $t12 := 2 + 17: $t13 := %($t11, $t12) + 18: $t14 := 0 + 19: $t15 := ==($t13, $t14) + 20: if ($t15) goto 21 else goto 31 + 21: label L4 + 22: $t16 := copy($t2) + 23: $t17 := move($t2) + 24: $t18 := *($t16, $t17) + 25: $t2 := $t18 + 26: $t19 := move($t3) + 27: $t20 := 2 + 28: $t21 := /($t19, $t20) + 29: $t3 := $t21 + 30: goto 7 + 31: label L3 + 32: $t22 := move($t4) + 33: $t23 := copy($t2) + 34: $t24 := *($t22, $t23) + 35: $t4 := $t24 + 36: $t25 := move($t3) + 37: $t26 := 1 + 38: $t27 := -($t25, $t26) + 39: $t3 := $t27 + 40: goto 7 + 41: label L0 + 42: $t28 := move($t4) + 43: return $t28 +} + + +[variant baseline] +public fun u64::sqrt($t0|x: u64): u64 { + var $t1|bit#1#1: u128 + var $t2|res#1#1: u128 + var $t3|x#1#1: u64 + var $t4|x#2#1: u128 + var $t5: u64 + var $t6: u128 + var $t7: u128 + var $t8: u64 + var $t9: u128 + var $t10: u128 + var $t11: u128 + var $t12: bool + var $t13: u128 + var $t14: u128 + var $t15: u128 + var $t16: u128 + var $t17: bool + var $t18: u128 + var $t19: u128 + var $t20: u128 + var $t21: u128 + var $t22: u128 + var $t23: u128 + var $t24: u8 + var $t25: u128 + var $t26: u128 + var $t27: u128 + var $t28: u128 + var $t29: u8 + var $t30: u128 + var $t31: u128 + var $t32: u8 + var $t33: u128 + var $t34: u128 + var $t35: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := 18446744073709551616 + 3: $t1 := $t6 + 4: $t7 := 0 + 5: $t2 := $t7 + 6: $t8 := move($t3) + 7: $t9 := (u128)($t8) + 8: $t4 := $t9 + 9: goto 10 + 10: label L6 + 11: $t10 := copy($t1) + 12: $t11 := 0 + 13: $t12 := !=($t10, $t11) + 14: if ($t12) goto 15 else goto 50 + 15: label L1 + 16: goto 17 + 17: label L2 + 18: $t13 := copy($t4) + 19: $t14 := copy($t2) + 20: $t15 := copy($t1) + 21: $t16 := +($t14, $t15) + 22: $t17 := >=($t13, $t16) + 23: if ($t17) goto 24 else goto 38 + 24: label L4 + 25: $t18 := move($t4) + 26: $t19 := copy($t2) + 27: $t20 := copy($t1) + 28: $t21 := +($t19, $t20) + 29: $t22 := -($t18, $t21) + 30: $t4 := $t22 + 31: $t23 := move($t2) + 32: $t24 := 1 + 33: $t25 := >>($t23, $t24) + 34: $t26 := copy($t1) + 35: $t27 := +($t25, $t26) + 36: $t2 := $t27 + 37: goto 44 + 38: label L3 + 39: $t28 := move($t2) + 40: $t29 := 1 + 41: $t30 := >>($t28, $t29) + 42: $t2 := $t30 + 43: goto 44 + 44: label L5 + 45: $t31 := move($t1) + 46: $t32 := 2 + 47: $t33 := >>($t31, $t32) + 48: $t1 := $t33 + 49: goto 10 + 50: label L0 + 51: $t34 := move($t2) + 52: $t35 := (u64)($t34) + 53: return $t35 +} + + [variant baseline] public fun vector::append<#0>($t0|lhs: &mut vector<#0>, $t1|other: vector<#0>) { var $t2: &mut vector<#0> @@ -231,27 +565,25 @@ public fun vector::insert<#0>($t0|v: &mut vector<#0>, $t1|e: #0, $t2|i: u64) { 15: $t13 := move($t1) 16: vector::push_back<#0>($t12, $t13) 17: goto 18 - 18: label L5 + 18: label L4 19: $t14 := copy($t2) 20: $t15 := copy($t3) 21: $t16 := <($t14, $t15) - 22: if ($t16) goto 23 else goto 35 + 22: if ($t16) goto 23 else goto 33 23: label L3 - 24: goto 25 - 25: label L4 - 26: $t17 := copy($t0) - 27: $t18 := copy($t2) - 28: $t19 := copy($t3) - 29: vector::swap<#0>($t17, $t18, $t19) - 30: $t20 := move($t2) - 31: $t21 := 1 - 32: $t22 := +($t20, $t21) - 33: $t2 := $t22 - 34: goto 18 - 35: label L2 - 36: $t23 := move($t0) - 37: destroy($t23) - 38: return () + 24: $t17 := copy($t0) + 25: $t18 := copy($t2) + 26: $t19 := copy($t3) + 27: vector::swap<#0>($t17, $t18, $t19) + 28: $t20 := move($t2) + 29: $t21 := 1 + 30: $t22 := +($t20, $t21) + 31: $t2 := $t22 + 32: goto 18 + 33: label L2 + 34: $t23 := move($t0) + 35: destroy($t23) + 36: return () } @@ -329,31 +661,29 @@ public fun vector::remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { 16: $t15 := -($t13, $t14) 17: $t4 := $t15 18: goto 19 - 19: label L5 + 19: label L4 20: $t16 := copy($t1) 21: $t17 := copy($t4) 22: $t18 := <($t16, $t17) - 23: if ($t18) goto 24 else goto 40 + 23: if ($t18) goto 24 else goto 38 24: label L3 - 25: goto 26 - 26: label L4 - 27: $t19 := copy($t0) - 28: $t3 := $t19 - 29: $t20 := copy($t1) - 30: $t2 := $t20 - 31: $t21 := move($t1) - 32: $t22 := 1 - 33: $t23 := +($t21, $t22) - 34: $t1 := $t23 - 35: $t24 := move($t3) - 36: $t25 := move($t2) - 37: $t26 := copy($t1) - 38: vector::swap<#0>($t24, $t25, $t26) - 39: goto 19 - 40: label L2 - 41: $t27 := move($t0) - 42: $t28 := vector::pop_back<#0>($t27) - 43: return $t28 + 25: $t19 := copy($t0) + 26: $t3 := $t19 + 27: $t20 := copy($t1) + 28: $t2 := $t20 + 29: $t21 := move($t1) + 30: $t22 := 1 + 31: $t23 := +($t21, $t22) + 32: $t1 := $t23 + 33: $t24 := move($t3) + 34: $t25 := move($t2) + 35: $t26 := copy($t1) + 36: vector::swap<#0>($t24, $t25, $t26) + 37: goto 19 + 38: label L2 + 39: $t27 := move($t0) + 40: $t28 := vector::pop_back<#0>($t27) + 41: return $t28 } @@ -406,31 +736,29 @@ public fun vector::reverse<#0>($t0|v: &mut vector<#0>) { 17: $t14 := -($t12, $t13) 18: $t1 := $t14 19: goto 20 - 20: label L5 + 20: label L4 21: $t15 := copy($t2) 22: $t16 := copy($t1) 23: $t17 := <($t15, $t16) - 24: if ($t17) goto 25 else goto 41 + 24: if ($t17) goto 25 else goto 39 25: label L3 - 26: goto 27 - 27: label L4 - 28: $t18 := copy($t0) - 29: $t19 := copy($t2) - 30: $t20 := copy($t1) - 31: vector::swap<#0>($t18, $t19, $t20) - 32: $t21 := move($t2) - 33: $t22 := 1 - 34: $t23 := +($t21, $t22) - 35: $t2 := $t23 - 36: $t24 := move($t1) - 37: $t25 := 1 - 38: $t26 := -($t24, $t25) - 39: $t1 := $t26 - 40: goto 20 - 41: label L2 - 42: $t27 := move($t0) - 43: destroy($t27) - 44: return () + 26: $t18 := copy($t0) + 27: $t19 := copy($t2) + 28: $t20 := copy($t1) + 29: vector::swap<#0>($t18, $t19, $t20) + 30: $t21 := move($t2) + 31: $t22 := 1 + 32: $t23 := +($t21, $t22) + 33: $t2 := $t23 + 34: $t24 := move($t1) + 35: $t25 := 1 + 36: $t26 := -($t24, $t25) + 37: $t1 := $t26 + 38: goto 20 + 39: label L2 + 40: $t27 := move($t0) + 41: destroy($t27) + 42: return () } @@ -526,530 +854,4518 @@ fun ReturnRefsIntoVec::return_vec_index_mut($t0|v: &mut vector): &mut u64 { 3: return $t3 } -============ after pipeline `escape_analysis` ================ [variant baseline] -public fun vector::append<#0>($t0|lhs: &mut vector<#0>, $t1|other: vector<#0>) { - var $t2: &mut vector<#0> - var $t3: &vector<#0> - var $t4: bool - var $t5: bool - var $t6: &mut vector<#0> - var $t7: &mut vector<#0> - var $t8: #0 - var $t9: &mut vector<#0> - var $t10: vector<#0> - 0: $t2 := borrow_local($t1) - 1: vector::reverse<#0>($t2) - 2: goto 3 - 3: label L3 - 4: $t3 := borrow_local($t1) - 5: $t4 := vector::is_empty<#0>($t3) - 6: $t5 := !($t4) - 7: if ($t5) goto 8 else goto 16 - 8: label L1 - 9: goto 10 +public fun option::borrow<#0>($t0|t: &option::Option<#0>): � { + var $t1: &option::Option<#0> + var $t2: bool + var $t3: &option::Option<#0> + var $t4: u64 + var $t5: &option::Option<#0> + var $t6: &vector<#0> + var $t7: u64 + var $t8: � + 0: $t1 := copy($t0) + 1: $t2 := option::is_some<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 10 + 5: label L0 + 6: $t3 := move($t0) + 7: destroy($t3) + 8: $t4 := 262145 + 9: abort($t4) 10: label L2 - 11: $t6 := copy($t0) - 12: $t7 := borrow_local($t1) - 13: $t8 := vector::pop_back<#0>($t7) - 14: vector::push_back<#0>($t6, $t8) - 15: goto 3 - 16: label L0 - 17: $t9 := move($t0) - 18: destroy($t9) - 19: $t10 := move($t1) - 20: vector::destroy_empty<#0>($t10) - 21: return () + 11: $t5 := move($t0) + 12: $t6 := borrow_field>.vec($t5) + 13: $t7 := 0 + 14: $t8 := vector::borrow<#0>($t6, $t7) + 15: return $t8 } [variant baseline] -public native fun vector::borrow<#0>($t0|v: &vector<#0>, $t1|i: u64): � +public fun option::borrow_mut<#0>($t0|t: &mut option::Option<#0>): &mut #0 { + var $t1: &mut option::Option<#0> + var $t2: &option::Option<#0> + var $t3: bool + var $t4: &mut option::Option<#0> + var $t5: u64 + var $t6: &mut option::Option<#0> + var $t7: &mut vector<#0> + var $t8: u64 + var $t9: &mut #0 + 0: $t1 := copy($t0) + 1: $t2 := freeze_ref($t1) + 2: $t3 := option::is_some<#0>($t2) + 3: if ($t3) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t4 := move($t0) + 8: destroy($t4) + 9: $t5 := 262145 + 10: abort($t5) + 11: label L2 + 12: $t6 := move($t0) + 13: $t7 := borrow_field>.vec($t6) + 14: $t8 := 0 + 15: $t9 := vector::borrow_mut<#0>($t7, $t8) + 16: return $t9 +} [variant baseline] -public native fun vector::borrow_mut<#0>($t0|v: &mut vector<#0>, $t1|i: u64): &mut #0; +public fun option::contains<#0>($t0|t: &option::Option<#0>, $t1|e_ref: �): bool { + var $t2: &option::Option<#0> + var $t3: &vector<#0> + var $t4: � + var $t5: bool + 0: $t2 := move($t0) + 1: $t3 := borrow_field>.vec($t2) + 2: $t4 := move($t1) + 3: $t5 := vector::contains<#0>($t3, $t4) + 4: return $t5 +} [variant baseline] -public fun vector::contains<#0>($t0|v: &vector<#0>, $t1|e: �): bool { - var $t2|i#1#0: u64 - var $t3|len#1#0: u64 - var $t4: u64 - var $t5: &vector<#0> - var $t6: u64 - var $t7: u64 +public fun option::swap<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): #0 { + var $t2|old_value#1#0: #0 + var $t3|vec_ref#1#0: &mut vector<#0> + var $t4: &mut option::Option<#0> + var $t5: &option::Option<#0> + var $t6: bool + var $t7: &mut option::Option<#0> var $t8: u64 - var $t9: bool - var $t10: &vector<#0> - var $t11: u64 - var $t12: � + var $t9: &mut option::Option<#0> + var $t10: &mut vector<#0> + var $t11: &mut vector<#0> + var $t12: #0 + var $t13: &mut vector<#0> + var $t14: #0 + var $t15: #0 + 0: $t4 := copy($t0) + 1: $t5 := freeze_ref($t4) + 2: $t6 := option::is_some<#0>($t5) + 3: if ($t6) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t7 := move($t0) + 8: destroy($t7) + 9: $t8 := 262145 + 10: abort($t8) + 11: label L2 + 12: $t9 := move($t0) + 13: $t10 := borrow_field>.vec($t9) + 14: $t3 := $t10 + 15: $t11 := copy($t3) + 16: $t12 := vector::pop_back<#0>($t11) + 17: $t2 := $t12 + 18: $t13 := move($t3) + 19: $t14 := move($t1) + 20: vector::push_back<#0>($t13, $t14) + 21: $t15 := move($t2) + 22: return $t15 +} + + +[variant baseline] +public fun option::borrow_with_default<#0>($t0|t: &option::Option<#0>, $t1|default_ref: �): � { + var $t2|tmp#$2: � + var $t3|vec_ref#1#0: &vector<#0> + var $t4: &option::Option<#0> + var $t5: &vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &vector<#0> + var $t9: � + var $t10: � + var $t11: &vector<#0> + var $t12: u64 var $t13: � - var $t14: bool - var $t15: &vector<#0> - var $t16: � - var $t17: bool - var $t18: u64 - var $t19: u64 - var $t20: u64 - var $t21: &vector<#0> - var $t22: � - var $t23: bool - 0: $t4 := 0 - 1: $t2 := $t4 - 2: $t5 := copy($t0) - 3: $t6 := vector::length<#0>($t5) - 4: $t3 := $t6 - 5: goto 6 - 6: label L5 - 7: $t7 := copy($t2) - 8: $t8 := copy($t3) - 9: $t9 := <($t7, $t8) - 10: if ($t9) goto 11 else goto 33 - 11: label L1 - 12: goto 13 - 13: label L2 - 14: $t10 := copy($t0) - 15: $t11 := copy($t2) - 16: $t12 := vector::borrow<#0>($t10, $t11) - 17: $t13 := copy($t1) - 18: $t14 := ==($t12, $t13) - 19: if ($t14) goto 20 else goto 27 - 20: label L4 - 21: $t15 := move($t0) - 22: destroy($t15) - 23: $t16 := move($t1) - 24: destroy($t16) - 25: $t17 := true - 26: return $t17 - 27: label L3 - 28: $t18 := move($t2) - 29: $t19 := 1 - 30: $t20 := +($t18, $t19) - 31: $t2 := $t20 - 32: goto 6 - 33: label L0 - 34: $t21 := move($t0) - 35: destroy($t21) - 36: $t22 := move($t1) - 37: destroy($t22) - 38: $t23 := false - 39: return $t23 + var $t14: � + 0: $t4 := move($t0) + 1: $t5 := borrow_field>.vec($t4) + 2: $t3 := $t5 + 3: $t6 := copy($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 12 + 6: label L1 + 7: $t8 := move($t3) + 8: destroy($t8) + 9: $t9 := move($t1) + 10: $t2 := $t9 + 11: goto 20 + 12: label L0 + 13: $t10 := move($t1) + 14: destroy($t10) + 15: $t11 := move($t3) + 16: $t12 := 0 + 17: $t13 := vector::borrow<#0>($t11, $t12) + 18: $t2 := $t13 + 19: goto 20 + 20: label L2 + 21: $t14 := move($t2) + 22: return $t14 } [variant baseline] -public native fun vector::destroy_empty<#0>($t0|v: vector<#0>); +public fun option::destroy_none<#0>($t0|t: option::Option<#0>) { + var $t1: &option::Option<#0> + var $t2: bool + var $t3: u64 + var $t4: option::Option<#0> + var $t5: vector<#0> + 0: $t1 := borrow_local($t0) + 1: $t2 := option::is_none<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 262144 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := unpack option::Option<#0>($t4) + 11: vector::destroy_empty<#0>($t5) + 12: return () +} [variant baseline] -public native fun vector::empty<#0>(): vector<#0>; +public fun option::destroy_some<#0>($t0|t: option::Option<#0>): #0 { + var $t1|elem#1#0: #0 + var $t2|vec#1#0: vector<#0> + var $t3: &option::Option<#0> + var $t4: bool + var $t5: u64 + var $t6: option::Option<#0> + var $t7: vector<#0> + var $t8: &mut vector<#0> + var $t9: #0 + var $t10: vector<#0> + var $t11: #0 + 0: $t3 := borrow_local($t0) + 1: $t4 := option::is_some<#0>($t3) + 2: if ($t4) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t5 := 262145 + 7: abort($t5) + 8: label L2 + 9: $t6 := move($t0) + 10: $t7 := unpack option::Option<#0>($t6) + 11: $t2 := $t7 + 12: $t8 := borrow_local($t2) + 13: $t9 := vector::pop_back<#0>($t8) + 14: $t1 := $t9 + 15: $t10 := move($t2) + 16: vector::destroy_empty<#0>($t10) + 17: $t11 := move($t1) + 18: return $t11 +} [variant baseline] -public fun vector::index_of<#0>($t0|v: &vector<#0>, $t1|e: �): (bool, u64) { - var $t2|i#1#0: u64 - var $t3|len#1#0: u64 - var $t4: u64 +public fun option::destroy_with_default<#0>($t0|t: option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec#1#0: vector<#0> + var $t4: option::Option<#0> + var $t5: vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: #0 + var $t9: &mut vector<#0> + var $t10: #0 + var $t11: #0 + 0: $t4 := move($t0) + 1: $t5 := unpack option::Option<#0>($t4) + 2: $t3 := $t5 + 3: $t6 := borrow_local($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 10 + 6: label L1 + 7: $t8 := move($t1) + 8: $t2 := $t8 + 9: goto 15 + 10: label L0 + 11: $t9 := borrow_local($t3) + 12: $t10 := vector::pop_back<#0>($t9) + 13: $t2 := $t10 + 14: goto 15 + 15: label L2 + 16: $t11 := move($t2) + 17: return $t11 +} + + +[variant baseline] +public fun option::extract<#0>($t0|t: &mut option::Option<#0>): #0 { + var $t1: &mut option::Option<#0> + var $t2: &option::Option<#0> + var $t3: bool + var $t4: &mut option::Option<#0> + var $t5: u64 + var $t6: &mut option::Option<#0> + var $t7: &mut vector<#0> + var $t8: #0 + 0: $t1 := copy($t0) + 1: $t2 := freeze_ref($t1) + 2: $t3 := option::is_some<#0>($t2) + 3: if ($t3) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t4 := move($t0) + 8: destroy($t4) + 9: $t5 := 262145 + 10: abort($t5) + 11: label L2 + 12: $t6 := move($t0) + 13: $t7 := borrow_field>.vec($t6) + 14: $t8 := vector::pop_back<#0>($t7) + 15: return $t8 +} + + +[variant baseline] +public fun option::fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0) { + var $t2|vec_ref#1#0: &mut vector<#0> + var $t3: &mut option::Option<#0> + var $t4: &mut vector<#0> + var $t5: &mut vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &mut vector<#0> + var $t9: u64 + var $t10: &mut vector<#0> + var $t11: #0 + 0: $t3 := move($t0) + 1: $t4 := borrow_field>.vec($t3) + 2: $t2 := $t4 + 3: $t5 := copy($t2) + 4: $t6 := freeze_ref($t5) + 5: $t7 := vector::is_empty<#0>($t6) + 6: if ($t7) goto 7 else goto 9 + 7: label L1 + 8: goto 14 + 9: label L0 + 10: $t8 := move($t2) + 11: destroy($t8) + 12: $t9 := 262144 + 13: abort($t9) + 14: label L2 + 15: $t10 := move($t2) + 16: $t11 := move($t1) + 17: vector::push_back<#0>($t10, $t11) + 18: return () +} + + +[variant baseline] +public fun option::get_with_default<#0>($t0|t: &option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec_ref#1#0: &vector<#0> + var $t4: &option::Option<#0> + var $t5: &vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &vector<#0> + var $t9: #0 + var $t10: &vector<#0> + var $t11: u64 + var $t12: � + var $t13: #0 + var $t14: #0 + 0: $t4 := move($t0) + 1: $t5 := borrow_field>.vec($t4) + 2: $t3 := $t5 + 3: $t6 := copy($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 12 + 6: label L1 + 7: $t8 := move($t3) + 8: destroy($t8) + 9: $t9 := move($t1) + 10: $t2 := $t9 + 11: goto 19 + 12: label L0 + 13: $t10 := move($t3) + 14: $t11 := 0 + 15: $t12 := vector::borrow<#0>($t10, $t11) + 16: $t13 := read_ref($t12) + 17: $t2 := $t13 + 18: goto 19 + 19: label L2 + 20: $t14 := move($t2) + 21: return $t14 +} + + +[variant baseline] +public fun option::is_none<#0>($t0|t: &option::Option<#0>): bool { + var $t1: &option::Option<#0> + var $t2: &vector<#0> + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field>.vec($t1) + 2: $t3 := vector::is_empty<#0>($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::is_some<#0>($t0|t: &option::Option<#0>): bool { + var $t1: &option::Option<#0> + var $t2: &vector<#0> + var $t3: bool + var $t4: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field>.vec($t1) + 2: $t3 := vector::is_empty<#0>($t2) + 3: $t4 := !($t3) + 4: return $t4 +} + + +[variant baseline] +public fun option::none<#0>(): option::Option<#0> { + var $t0: vector<#0> + var $t1: option::Option<#0> + 0: $t0 := vector::empty<#0>() + 1: $t1 := pack option::Option<#0>($t0) + 2: return $t1 +} + + +[variant baseline] +public fun option::some<#0>($t0|e: #0): option::Option<#0> { + var $t1: #0 + var $t2: vector<#0> + var $t3: option::Option<#0> + 0: $t1 := move($t0) + 1: $t2 := vector::singleton<#0>($t1) + 2: $t3 := pack option::Option<#0>($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::swap_or_fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): option::Option<#0> { + var $t2|tmp#$2: option::Option<#0> + var $t3|old_value#1#0: option::Option<#0> + var $t4|vec_ref#1#0: &mut vector<#0> + var $t5: &mut option::Option<#0> + var $t6: &mut vector<#0> + var $t7: &mut vector<#0> + var $t8: &vector<#0> + var $t9: bool + var $t10: option::Option<#0> + var $t11: &mut vector<#0> + var $t12: #0 + var $t13: option::Option<#0> + var $t14: option::Option<#0> + var $t15: &mut vector<#0> + var $t16: #0 + var $t17: option::Option<#0> + 0: $t5 := move($t0) + 1: $t6 := borrow_field>.vec($t5) + 2: $t4 := $t6 + 3: $t7 := copy($t4) + 4: $t8 := freeze_ref($t7) + 5: $t9 := vector::is_empty<#0>($t8) + 6: if ($t9) goto 7 else goto 11 + 7: label L1 + 8: $t10 := option::none<#0>() + 9: $t2 := $t10 + 10: goto 17 + 11: label L0 + 12: $t11 := copy($t4) + 13: $t12 := vector::pop_back<#0>($t11) + 14: $t13 := option::some<#0>($t12) + 15: $t2 := $t13 + 16: goto 17 + 17: label L2 + 18: $t14 := move($t2) + 19: $t3 := $t14 + 20: $t15 := move($t4) + 21: $t16 := move($t1) + 22: vector::push_back<#0>($t15, $t16) + 23: $t17 := move($t3) + 24: return $t17 +} + + +[variant baseline] +public fun option::to_vec<#0>($t0|t: option::Option<#0>): vector<#0> { + var $t1: option::Option<#0> + var $t2: vector<#0> + 0: $t1 := move($t0) + 1: $t2 := unpack option::Option<#0>($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::append($t0|string: &mut ascii::String, $t1|other: ascii::String) { + var $t2: &mut ascii::String + var $t3: &mut vector + var $t4: ascii::String + var $t5: vector + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := move($t1) + 3: $t5 := ascii::into_bytes($t4) + 4: vector::append($t3, $t5) + 5: return () +} + + +[variant baseline] +public fun ascii::index_of($t0|string: &ascii::String, $t1|substr: &ascii::String): u64 { + var $t2|tmp#$2: bool + var $t3|i#1#0: u64 + var $t4|j#1#0: u64 + var $t5|m#1#0: u64 + var $t6|n#1#0: u64 + var $t7: u64 + var $t8: &ascii::String + var $t9: u64 + var $t10: &ascii::String + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: bool + var $t15: &ascii::String + var $t16: &ascii::String + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: u64 + var $t22: bool + var $t23: u64 + var $t24: u64 + var $t25: u64 + var $t26: bool + var $t27: &ascii::String + var $t28: &vector + var $t29: u64 + var $t30: u64 + var $t31: u64 + var $t32: &u8 + var $t33: u8 + var $t34: &ascii::String + var $t35: &vector + var $t36: u64 + var $t37: &u8 + var $t38: u8 + var $t39: bool + var $t40: bool + var $t41: bool + var $t42: u64 + var $t43: u64 + var $t44: u64 + var $t45: u64 + var $t46: u64 + var $t47: bool + var $t48: &ascii::String + var $t49: &ascii::String + var $t50: u64 + var $t51: u64 + var $t52: u64 + var $t53: u64 + var $t54: &ascii::String + var $t55: &ascii::String + var $t56: u64 + 0: $t7 := 0 + 1: $t3 := $t7 + 2: $t8 := copy($t0) + 3: $t9 := ascii::length($t8) + 4: $t10 := copy($t1) + 5: $t11 := ascii::length($t10) + 6: $t5 := $t11 + 7: $t6 := $t9 + 8: $t12 := copy($t6) + 9: $t13 := copy($t5) + 10: $t14 := <($t12, $t13) + 11: if ($t14) goto 12 else goto 19 + 12: label L1 + 13: $t15 := move($t1) + 14: destroy($t15) + 15: $t16 := move($t0) + 16: destroy($t16) + 17: $t17 := move($t6) + 18: return $t17 + 19: label L0 + 20: $t18 := copy($t3) + 21: $t19 := copy($t6) + 22: $t20 := copy($t5) + 23: $t21 := -($t19, $t20) + 24: $t22 := <=($t18, $t21) + 25: if ($t22) goto 26 else goto 84 + 26: label L3 + 27: $t23 := 0 + 28: $t4 := $t23 + 29: goto 30 + 30: label L10 + 31: $t24 := copy($t4) + 32: $t25 := copy($t5) + 33: $t26 := <($t24, $t25) + 34: if ($t26) goto 35 else goto 53 + 35: label L5 + 36: goto 37 + 37: label L6 + 38: $t27 := copy($t0) + 39: $t28 := borrow_field.bytes($t27) + 40: $t29 := copy($t3) + 41: $t30 := copy($t4) + 42: $t31 := +($t29, $t30) + 43: $t32 := vector::borrow($t28, $t31) + 44: $t33 := read_ref($t32) + 45: $t34 := copy($t1) + 46: $t35 := borrow_field.bytes($t34) + 47: $t36 := copy($t4) + 48: $t37 := vector::borrow($t35, $t36) + 49: $t38 := read_ref($t37) + 50: $t39 := ==($t33, $t38) + 51: $t2 := $t39 + 52: goto 57 + 53: label L4 + 54: $t40 := false + 55: $t2 := $t40 + 56: goto 57 + 57: label L7 + 58: $t41 := move($t2) + 59: if ($t41) goto 60 else goto 66 + 60: label L9 + 61: $t42 := move($t4) + 62: $t43 := 1 + 63: $t44 := +($t42, $t43) + 64: $t4 := $t44 + 65: goto 30 + 66: label L8 + 67: $t45 := move($t4) + 68: $t46 := copy($t5) + 69: $t47 := ==($t45, $t46) + 70: if ($t47) goto 71 else goto 78 + 71: label L12 + 72: $t48 := move($t1) + 73: destroy($t48) + 74: $t49 := move($t0) + 75: destroy($t49) + 76: $t50 := move($t3) + 77: return $t50 + 78: label L11 + 79: $t51 := move($t3) + 80: $t52 := 1 + 81: $t53 := +($t51, $t52) + 82: $t3 := $t53 + 83: goto 19 + 84: label L2 + 85: $t54 := move($t1) + 86: destroy($t54) + 87: $t55 := move($t0) + 88: destroy($t55) + 89: $t56 := move($t6) + 90: return $t56 +} + + +[variant baseline] +public fun ascii::insert($t0|s: &mut ascii::String, $t1|at: u64, $t2|o: ascii::String) { + var $t3|e#1#2: u8 + var $t4|v#1#1: vector + var $t5: u64 + var $t6: &mut ascii::String + var $t7: &ascii::String + var $t8: u64 + var $t9: bool + var $t10: &mut ascii::String + var $t11: u64 + var $t12: ascii::String + var $t13: vector + var $t14: &vector + var $t15: bool + var $t16: bool + var $t17: &mut vector + var $t18: u8 + var $t19: &mut ascii::String + var $t20: &mut vector + var $t21: u8 + var $t22: u64 + var $t23: &mut ascii::String + var $t24: vector + 0: $t5 := copy($t1) + 1: $t6 := copy($t0) + 2: $t7 := freeze_ref($t6) + 3: $t8 := ascii::length($t7) + 4: $t9 := <=($t5, $t8) + 5: if ($t9) goto 6 else goto 8 + 6: label L1 + 7: goto 13 + 8: label L0 + 9: $t10 := move($t0) + 10: destroy($t10) + 11: $t11 := 65537 + 12: abort($t11) + 13: label L2 + 14: $t12 := move($t2) + 15: $t13 := ascii::into_bytes($t12) + 16: $t4 := $t13 + 17: goto 18 + 18: label L5 + 19: $t14 := borrow_local($t4) + 20: $t15 := vector::is_empty($t14) + 21: $t16 := !($t15) + 22: if ($t16) goto 23 else goto 33 + 23: label L4 + 24: $t17 := borrow_local($t4) + 25: $t18 := vector::pop_back($t17) + 26: $t3 := $t18 + 27: $t19 := copy($t0) + 28: $t20 := borrow_field.bytes($t19) + 29: $t21 := move($t3) + 30: $t22 := copy($t1) + 31: vector::insert($t20, $t21, $t22) + 32: goto 18 + 33: label L3 + 34: $t23 := move($t0) + 35: destroy($t23) + 36: $t24 := move($t4) + 37: vector::destroy_empty($t24) + 38: return () +} + + +[variant baseline] +public fun ascii::is_empty($t0|string: &ascii::String): bool { + var $t1: &ascii::String + var $t2: &vector + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::is_empty($t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::length($t0|string: &ascii::String): u64 { + var $t1: &ascii::String + var $t2: &vector + var $t3: u64 + 0: $t1 := move($t0) + 1: $t2 := ascii::as_bytes($t1) + 2: $t3 := vector::length($t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::all_characters_printable($t0|string: &ascii::String): bool { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|i#1#12: u64 + var $t4|i#1#9: u64 + var $t5|stop#1#9: u64 + var $t6|v#1#3: &vector + var $t7: &ascii::String + var $t8: &vector + var $t9: &vector + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u64 + var $t17: &vector + var $t18: u64 + var $t19: &u8 + var $t20: u8 + var $t21: bool + var $t22: bool + var $t23: &vector + var $t24: bool + var $t25: u64 + var $t26: u64 + var $t27: u64 + var $t28: &vector + var $t29: bool + var $t30: bool + 0: $t7 := move($t0) + 1: $t8 := borrow_field.bytes($t7) + 2: $t6 := $t8 + 3: $t9 := copy($t6) + 4: $t10 := vector::length($t9) + 5: $t1 := $t10 + 6: $t11 := 0 + 7: $t4 := $t11 + 8: $t12 := move($t1) + 9: $t5 := $t12 + 10: goto 11 + 11: label L5 + 12: $t13 := copy($t4) + 13: $t14 := copy($t5) + 14: $t15 := <($t13, $t14) + 15: if ($t15) goto 16 else goto 38 + 16: label L1 + 17: $t16 := copy($t4) + 18: $t3 := $t16 + 19: $t17 := copy($t6) + 20: $t18 := move($t3) + 21: $t19 := vector::borrow($t17, $t18) + 22: $t20 := read_ref($t19) + 23: $t21 := ascii::is_printable_char($t20) + 24: $t22 := !($t21) + 25: if ($t22) goto 26 else goto 32 + 26: label L3 + 27: $t23 := move($t6) + 28: destroy($t23) + 29: $t24 := false + 30: $t2 := $t24 + 31: goto 44 + 32: label L2 + 33: $t25 := move($t4) + 34: $t26 := 1 + 35: $t27 := +($t25, $t26) + 36: $t4 := $t27 + 37: goto 11 + 38: label L0 + 39: $t28 := move($t6) + 40: destroy($t28) + 41: $t29 := true + 42: $t2 := $t29 + 43: goto 44 + 44: label L4 + 45: $t30 := move($t2) + 46: return $t30 +} + + +[variant baseline] +public fun ascii::string($t0|bytes: vector): ascii::String { + var $t1|x#1#0: option::Option + var $t2: vector + var $t3: option::Option + var $t4: &option::Option + var $t5: bool + var $t6: u64 + var $t7: option::Option + var $t8: ascii::String + 0: $t2 := move($t0) + 1: $t3 := ascii::try_string($t2) + 2: $t1 := $t3 + 3: $t4 := borrow_local($t1) + 4: $t5 := option::is_some($t4) + 5: if ($t5) goto 6 else goto 8 + 6: label L1 + 7: goto 11 + 8: label L0 + 9: $t6 := 65536 + 10: abort($t6) + 11: label L2 + 12: $t7 := move($t1) + 13: $t8 := option::destroy_some($t7) + 14: return $t8 +} + + +[variant baseline] +public fun ascii::as_bytes($t0|string: &ascii::String): &vector { + var $t1: &ascii::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::byte($t0|char: ascii::Char): u8 { + var $t1: ascii::Char + var $t2: u8 + 0: $t1 := move($t0) + 1: $t2 := unpack ascii::Char($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::char($t0|byte: u8): ascii::Char { + var $t1: u8 + var $t2: bool + var $t3: u64 + var $t4: u8 + var $t5: ascii::Char + 0: $t1 := copy($t0) + 1: $t2 := ascii::is_valid_char($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 65536 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := pack ascii::Char($t4) + 11: return $t5 +} + + +[variant baseline] +fun ascii::char_to_lowercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: u8 + var $t5: bool + var $t6: u8 + var $t7: u8 + var $t8: bool + var $t9: bool + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: u8 + 0: $t3 := copy($t0) + 1: $t4 := 65 + 2: $t5 := >=($t3, $t4) + 3: if ($t5) goto 4 else goto 10 + 4: label L1 + 5: $t6 := copy($t0) + 6: $t7 := 90 + 7: $t8 := <=($t6, $t7) + 8: $t1 := $t8 + 9: goto 14 + 10: label L0 + 11: $t9 := false + 12: $t1 := $t9 + 13: goto 14 + 14: label L2 + 15: $t10 := move($t1) + 16: if ($t10) goto 17 else goto 23 + 17: label L4 + 18: $t11 := move($t0) + 19: $t12 := 32 + 20: $t13 := +($t11, $t12) + 21: $t2 := $t13 + 22: goto 27 + 23: label L3 + 24: $t14 := move($t0) + 25: $t2 := $t14 + 26: goto 27 + 27: label L5 + 28: $t15 := move($t2) + 29: return $t15 +} + + +[variant baseline] +fun ascii::char_to_uppercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: u8 + var $t5: bool + var $t6: u8 + var $t7: u8 + var $t8: bool + var $t9: bool + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: u8 + 0: $t3 := copy($t0) + 1: $t4 := 97 + 2: $t5 := >=($t3, $t4) + 3: if ($t5) goto 4 else goto 10 + 4: label L1 + 5: $t6 := copy($t0) + 6: $t7 := 122 + 7: $t8 := <=($t6, $t7) + 8: $t1 := $t8 + 9: goto 14 + 10: label L0 + 11: $t9 := false + 12: $t1 := $t9 + 13: goto 14 + 14: label L2 + 15: $t10 := move($t1) + 16: if ($t10) goto 17 else goto 23 + 17: label L4 + 18: $t11 := move($t0) + 19: $t12 := 32 + 20: $t13 := -($t11, $t12) + 21: $t2 := $t13 + 22: goto 27 + 23: label L3 + 24: $t14 := move($t0) + 25: $t2 := $t14 + 26: goto 27 + 27: label L5 + 28: $t15 := move($t2) + 29: return $t15 +} + + +[variant baseline] +public fun ascii::into_bytes($t0|string: ascii::String): vector { + var $t1: ascii::String + var $t2: vector + 0: $t1 := move($t0) + 1: $t2 := unpack ascii::String($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::is_printable_char($t0|byte: u8): bool { + var $t1|tmp#$1: bool + var $t2: u8 + var $t3: u8 + var $t4: bool + var $t5: u8 + var $t6: u8 + var $t7: bool + var $t8: bool + var $t9: bool + 0: $t2 := copy($t0) + 1: $t3 := 32 + 2: $t4 := >=($t2, $t3) + 3: if ($t4) goto 4 else goto 10 + 4: label L1 + 5: $t5 := move($t0) + 6: $t6 := 126 + 7: $t7 := <=($t5, $t6) + 8: $t1 := $t7 + 9: goto 14 + 10: label L0 + 11: $t8 := false + 12: $t1 := $t8 + 13: goto 14 + 14: label L2 + 15: $t9 := move($t1) + 16: return $t9 +} + + +[variant baseline] +public fun ascii::is_valid_char($t0|b: u8): bool { + var $t1: u8 + var $t2: u8 + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := 127 + 2: $t3 := <=($t1, $t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::pop_char($t0|string: &mut ascii::String): ascii::Char { + var $t1: &mut ascii::String + var $t2: &mut vector + var $t3: u8 + var $t4: ascii::Char + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::pop_back($t2) + 3: $t4 := pack ascii::Char($t3) + 4: return $t4 +} + + +[variant baseline] +public fun ascii::push_char($t0|string: &mut ascii::String, $t1|char: ascii::Char) { + var $t2: &mut ascii::String + var $t3: &mut vector + var $t4: &ascii::Char + var $t5: &u8 + var $t6: u8 + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := borrow_local($t1) + 3: $t5 := borrow_field.byte($t4) + 4: $t6 := read_ref($t5) + 5: vector::push_back($t3, $t6) + 6: return () +} + + +[variant baseline] +public fun ascii::substring($t0|string: &ascii::String, $t1|i: u64, $t2|j: u64): ascii::String { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: vector + var $t5|i#1#3: u64 + var $t6|i#1#6: u64 + var $t7|stop#1#3: u64 + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u64 + var $t12: &ascii::String + var $t13: u64 + var $t14: bool + var $t15: bool + var $t16: bool + var $t17: &ascii::String + var $t18: u64 + var $t19: vector + var $t20: u64 + var $t21: u64 + var $t22: u64 + var $t23: u64 + var $t24: bool + var $t25: u64 + var $t26: &mut vector + var $t27: &ascii::String + var $t28: &vector + var $t29: u64 + var $t30: &u8 + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &ascii::String + var $t36: vector + var $t37: ascii::String + 0: $t8 := copy($t1) + 1: $t9 := copy($t2) + 2: $t10 := <=($t8, $t9) + 3: if ($t10) goto 4 else goto 11 + 4: label L1 + 5: $t11 := copy($t2) + 6: $t12 := copy($t0) + 7: $t13 := ascii::length($t12) + 8: $t14 := <=($t11, $t13) + 9: $t3 := $t14 + 10: goto 15 + 11: label L0 + 12: $t15 := false + 13: $t3 := $t15 + 14: goto 15 + 15: label L2 + 16: $t16 := move($t3) + 17: if ($t16) goto 18 else goto 20 + 18: label L4 + 19: goto 25 + 20: label L3 + 21: $t17 := move($t0) + 22: destroy($t17) + 23: $t18 := 65537 + 24: abort($t18) + 25: label L5 + 26: $t19 := [] + 27: $t4 := $t19 + 28: $t20 := move($t1) + 29: $t5 := $t20 + 30: $t21 := move($t2) + 31: $t7 := $t21 + 32: goto 33 + 33: label L8 + 34: $t22 := copy($t5) + 35: $t23 := copy($t7) + 36: $t24 := <($t22, $t23) + 37: if ($t24) goto 38 else goto 53 + 38: label L7 + 39: $t25 := copy($t5) + 40: $t6 := $t25 + 41: $t26 := borrow_local($t4) + 42: $t27 := copy($t0) + 43: $t28 := borrow_field.bytes($t27) + 44: $t29 := move($t6) + 45: $t30 := vector::borrow($t28, $t29) + 46: $t31 := read_ref($t30) + 47: vector::push_back($t26, $t31) + 48: $t32 := move($t5) + 49: $t33 := 1 + 50: $t34 := +($t32, $t33) + 51: $t5 := $t34 + 52: goto 33 + 53: label L6 + 54: $t35 := move($t0) + 55: destroy($t35) + 56: $t36 := move($t4) + 57: $t37 := pack ascii::String($t36) + 58: return $t37 +} + + +[variant baseline] +public fun ascii::to_lowercase($t0|string: &ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: &u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: &vector + var $t10|v#1#3: &vector + var $t11: &ascii::String + var $t12: &vector + var $t13: vector + var $t14: &vector + var $t15: &vector + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: bool + var $t22: u64 + var $t23: &vector + var $t24: u64 + var $t25: &u8 + var $t26: &mut vector + var $t27: &u8 + var $t28: u8 + var $t29: u8 + var $t30: &mut vector + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &vector + var $t36: vector + var $t37: ascii::String + 0: $t11 := move($t0) + 1: $t12 := ascii::as_bytes($t11) + 2: $t9 := $t12 + 3: $t13 := [] + 4: $t7 := $t13 + 5: $t14 := move($t9) + 6: $t10 := $t14 + 7: $t15 := copy($t10) + 8: $t16 := vector::length($t15) + 9: $t1 := $t16 + 10: $t17 := 0 + 11: $t6 := $t17 + 12: $t18 := move($t1) + 13: $t8 := $t18 + 14: goto 15 + 15: label L2 + 16: $t19 := copy($t6) + 17: $t20 := copy($t8) + 18: $t21 := <($t19, $t20) + 19: if ($t21) goto 20 else goto 41 + 20: label L1 + 21: $t22 := copy($t6) + 22: $t5 := $t22 + 23: $t23 := copy($t10) + 24: $t24 := move($t5) + 25: $t25 := vector::borrow($t23, $t24) + 26: $t4 := $t25 + 27: $t26 := borrow_local($t7) + 28: $t3 := $t26 + 29: $t27 := move($t4) + 30: $t28 := read_ref($t27) + 31: $t29 := ascii::char_to_lowercase($t28) + 32: $t2 := $t29 + 33: $t30 := move($t3) + 34: $t31 := move($t2) + 35: vector::push_back($t30, $t31) + 36: $t32 := move($t6) + 37: $t33 := 1 + 38: $t34 := +($t32, $t33) + 39: $t6 := $t34 + 40: goto 15 + 41: label L0 + 42: $t35 := move($t10) + 43: destroy($t35) + 44: $t36 := move($t7) + 45: $t37 := pack ascii::String($t36) + 46: return $t37 +} + + +[variant baseline] +public fun ascii::to_uppercase($t0|string: &ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: &u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: &vector + var $t10|v#1#3: &vector + var $t11: &ascii::String + var $t12: &vector + var $t13: vector + var $t14: &vector + var $t15: &vector + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: bool + var $t22: u64 + var $t23: &vector + var $t24: u64 + var $t25: &u8 + var $t26: &mut vector + var $t27: &u8 + var $t28: u8 + var $t29: u8 + var $t30: &mut vector + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &vector + var $t36: vector + var $t37: ascii::String + 0: $t11 := move($t0) + 1: $t12 := ascii::as_bytes($t11) + 2: $t9 := $t12 + 3: $t13 := [] + 4: $t7 := $t13 + 5: $t14 := move($t9) + 6: $t10 := $t14 + 7: $t15 := copy($t10) + 8: $t16 := vector::length($t15) + 9: $t1 := $t16 + 10: $t17 := 0 + 11: $t6 := $t17 + 12: $t18 := move($t1) + 13: $t8 := $t18 + 14: goto 15 + 15: label L2 + 16: $t19 := copy($t6) + 17: $t20 := copy($t8) + 18: $t21 := <($t19, $t20) + 19: if ($t21) goto 20 else goto 41 + 20: label L1 + 21: $t22 := copy($t6) + 22: $t5 := $t22 + 23: $t23 := copy($t10) + 24: $t24 := move($t5) + 25: $t25 := vector::borrow($t23, $t24) + 26: $t4 := $t25 + 27: $t26 := borrow_local($t7) + 28: $t3 := $t26 + 29: $t27 := move($t4) + 30: $t28 := read_ref($t27) + 31: $t29 := ascii::char_to_uppercase($t28) + 32: $t2 := $t29 + 33: $t30 := move($t3) + 34: $t31 := move($t2) + 35: vector::push_back($t30, $t31) + 36: $t32 := move($t6) + 37: $t33 := 1 + 38: $t34 := +($t32, $t33) + 39: $t6 := $t34 + 40: goto 15 + 41: label L0 + 42: $t35 := move($t10) + 43: destroy($t35) + 44: $t36 := move($t7) + 45: $t37 := pack ascii::String($t36) + 46: return $t37 +} + + +[variant baseline] +public fun ascii::try_string($t0|bytes: vector): option::Option { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|tmp#$3: option::Option + var $t4|i#1#12: u64 + var $t5|i#1#9: u64 + var $t6|stop#1#9: u64 + var $t7|v#1#3: &vector + var $t8: &vector + var $t9: &vector + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u64 + var $t17: &vector + var $t18: u64 + var $t19: &u8 + var $t20: u8 + var $t21: bool + var $t22: bool + var $t23: &vector + var $t24: bool + var $t25: u64 + var $t26: u64 + var $t27: u64 + var $t28: &vector + var $t29: bool + var $t30: bool + var $t31: vector + var $t32: ascii::String + var $t33: option::Option + var $t34: option::Option + var $t35: option::Option + 0: $t8 := borrow_local($t0) + 1: $t7 := $t8 + 2: $t9 := copy($t7) + 3: $t10 := vector::length($t9) + 4: $t1 := $t10 + 5: $t11 := 0 + 6: $t5 := $t11 + 7: $t12 := move($t1) + 8: $t6 := $t12 + 9: goto 10 + 10: label L5 + 11: $t13 := copy($t5) + 12: $t14 := copy($t6) + 13: $t15 := <($t13, $t14) + 14: if ($t15) goto 15 else goto 37 + 15: label L1 + 16: $t16 := copy($t5) + 17: $t4 := $t16 + 18: $t17 := copy($t7) + 19: $t18 := move($t4) + 20: $t19 := vector::borrow($t17, $t18) + 21: $t20 := read_ref($t19) + 22: $t21 := ascii::is_valid_char($t20) + 23: $t22 := !($t21) + 24: if ($t22) goto 25 else goto 31 + 25: label L3 + 26: $t23 := move($t7) + 27: destroy($t23) + 28: $t24 := false + 29: $t2 := $t24 + 30: goto 43 + 31: label L2 + 32: $t25 := move($t5) + 33: $t26 := 1 + 34: $t27 := +($t25, $t26) + 35: $t5 := $t27 + 36: goto 10 + 37: label L0 + 38: $t28 := move($t7) + 39: destroy($t28) + 40: $t29 := true + 41: $t2 := $t29 + 42: goto 43 + 43: label L4 + 44: $t30 := move($t2) + 45: if ($t30) goto 46 else goto 52 + 46: label L7 + 47: $t31 := move($t0) + 48: $t32 := pack ascii::String($t31) + 49: $t33 := option::some($t32) + 50: $t3 := $t33 + 51: goto 56 + 52: label L6 + 53: $t34 := option::none() + 54: $t3 := $t34 + 55: goto 56 + 56: label L8 + 57: $t35 := move($t3) + 58: return $t35 +} + + +[variant baseline] +public fun string::append($t0|s: &mut string::String, $t1|r: string::String) { + var $t2: &mut string::String + var $t3: &mut vector + var $t4: &string::String + var $t5: &vector + var $t6: vector + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := borrow_local($t1) + 3: $t5 := borrow_field.bytes($t4) + 4: $t6 := read_ref($t5) + 5: vector::append($t3, $t6) + 6: return () +} + + +[variant baseline] +public fun string::index_of($t0|s: &string::String, $t1|r: &string::String): u64 { + var $t2: &string::String + var $t3: &vector + var $t4: &string::String + var $t5: &vector + var $t6: u64 + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := move($t1) + 3: $t5 := borrow_field.bytes($t4) + 4: $t6 := string::internal_index_of($t3, $t5) + 5: return $t6 +} + + +[variant baseline] +public fun string::insert($t0|s: &mut string::String, $t1|at: u64, $t2|o: string::String) { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: &vector + var $t5|end#1#0: string::String + var $t6|front#1#0: string::String + var $t7|l#1#0: u64 + var $t8: &mut string::String + var $t9: &vector + var $t10: u64 + var $t11: &vector + var $t12: u64 + var $t13: bool + var $t14: &vector + var $t15: u64 + var $t16: bool + var $t17: &vector + var $t18: bool + var $t19: bool + var $t20: &mut string::String + var $t21: u64 + var $t22: &mut string::String + var $t23: &string::String + var $t24: u64 + var $t25: &mut string::String + var $t26: &string::String + var $t27: u64 + var $t28: u64 + var $t29: string::String + var $t30: &mut string::String + var $t31: &string::String + var $t32: u64 + var $t33: u64 + var $t34: string::String + var $t35: &mut string::String + var $t36: string::String + var $t37: &mut string::String + var $t38: string::String + var $t39: string::String + var $t40: &mut string::String + 0: $t8 := copy($t0) + 1: $t9 := borrow_field.bytes($t8) + 2: $t4 := $t9 + 3: $t10 := copy($t1) + 4: $t11 := copy($t4) + 5: $t12 := vector::length($t11) + 6: $t13 := <=($t10, $t12) + 7: if ($t13) goto 8 else goto 14 + 8: label L1 + 9: $t14 := move($t4) + 10: $t15 := copy($t1) + 11: $t16 := string::internal_is_char_boundary($t14, $t15) + 12: $t3 := $t16 + 13: goto 20 + 14: label L0 + 15: $t17 := move($t4) + 16: destroy($t17) + 17: $t18 := false + 18: $t3 := $t18 + 19: goto 20 + 20: label L2 + 21: $t19 := move($t3) + 22: if ($t19) goto 23 else goto 25 + 23: label L4 + 24: goto 30 + 25: label L3 + 26: $t20 := move($t0) + 27: destroy($t20) + 28: $t21 := 2 + 29: abort($t21) + 30: label L5 + 31: $t22 := copy($t0) + 32: $t23 := freeze_ref($t22) + 33: $t24 := string::length($t23) + 34: $t7 := $t24 + 35: $t25 := copy($t0) + 36: $t26 := freeze_ref($t25) + 37: $t27 := 0 + 38: $t28 := copy($t1) + 39: $t29 := string::substring($t26, $t27, $t28) + 40: $t6 := $t29 + 41: $t30 := copy($t0) + 42: $t31 := freeze_ref($t30) + 43: $t32 := move($t1) + 44: $t33 := move($t7) + 45: $t34 := string::substring($t31, $t32, $t33) + 46: $t5 := $t34 + 47: $t35 := borrow_local($t6) + 48: $t36 := move($t2) + 49: string::append($t35, $t36) + 50: $t37 := borrow_local($t6) + 51: $t38 := move($t5) + 52: string::append($t37, $t38) + 53: $t39 := move($t6) + 54: $t40 := move($t0) + 55: write_ref($t40, $t39) + 56: return () +} + + +[variant baseline] +public fun string::is_empty($t0|s: &string::String): bool { + var $t1: &string::String + var $t2: &vector + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::is_empty($t2) + 3: return $t3 +} + + +[variant baseline] +public fun string::length($t0|s: &string::String): u64 { + var $t1: &string::String + var $t2: &vector + var $t3: u64 + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::length($t2) + 3: return $t3 +} + + +[variant baseline] +public fun string::as_bytes($t0|s: &string::String): &vector { + var $t1: &string::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::into_bytes($t0|s: string::String): vector { + var $t1: string::String + var $t2: vector + 0: $t1 := move($t0) + 1: $t2 := unpack string::String($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::bytes($t0|s: &string::String): &vector { + var $t1: &string::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := string::as_bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::substring($t0|s: &string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3|tmp#$3: bool + var $t4|tmp#$4: bool + var $t5|tmp#$5: bool + var $t6|bytes#1#0: &vector + var $t7|l#1#0: u64 + var $t8: &string::String + var $t9: &vector + var $t10: &vector + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: bool + var $t15: u64 + var $t16: u64 + var $t17: bool + var $t18: bool + var $t19: bool + var $t20: &vector + var $t21: u64 + var $t22: bool + var $t23: bool + var $t24: bool + var $t25: &vector + var $t26: u64 + var $t27: bool + var $t28: bool + var $t29: bool + var $t30: &vector + var $t31: u64 + var $t32: &vector + var $t33: u64 + var $t34: u64 + var $t35: vector + var $t36: string::String + 0: $t8 := move($t0) + 1: $t9 := borrow_field.bytes($t8) + 2: $t6 := $t9 + 3: $t10 := copy($t6) + 4: $t11 := vector::length($t10) + 5: $t7 := $t11 + 6: $t12 := copy($t2) + 7: $t13 := move($t7) + 8: $t14 := <=($t12, $t13) + 9: if ($t14) goto 10 else goto 16 + 10: label L1 + 11: $t15 := copy($t1) + 12: $t16 := copy($t2) + 13: $t17 := <=($t15, $t16) + 14: $t3 := $t17 + 15: goto 20 + 16: label L0 + 17: $t18 := false + 18: $t3 := $t18 + 19: goto 20 + 20: label L2 + 21: $t19 := move($t3) + 22: if ($t19) goto 23 else goto 29 + 23: label L4 + 24: $t20 := copy($t6) + 25: $t21 := copy($t1) + 26: $t22 := string::internal_is_char_boundary($t20, $t21) + 27: $t4 := $t22 + 28: goto 33 + 29: label L3 + 30: $t23 := false + 31: $t4 := $t23 + 32: goto 33 + 33: label L5 + 34: $t24 := move($t4) + 35: if ($t24) goto 36 else goto 42 + 36: label L7 + 37: $t25 := copy($t6) + 38: $t26 := copy($t2) + 39: $t27 := string::internal_is_char_boundary($t25, $t26) + 40: $t5 := $t27 + 41: goto 46 + 42: label L6 + 43: $t28 := false + 44: $t5 := $t28 + 45: goto 46 + 46: label L8 + 47: $t29 := move($t5) + 48: if ($t29) goto 49 else goto 51 + 49: label L10 + 50: goto 56 + 51: label L9 + 52: $t30 := move($t6) + 53: destroy($t30) + 54: $t31 := 2 + 55: abort($t31) + 56: label L11 + 57: $t32 := move($t6) + 58: $t33 := move($t1) + 59: $t34 := move($t2) + 60: $t35 := string::internal_sub_string($t32, $t33, $t34) + 61: $t36 := pack string::String($t35) + 62: return $t36 +} + + +[variant baseline] +public fun string::append_utf8($t0|s: &mut string::String, $t1|bytes: vector) { + var $t2: &mut string::String + var $t3: vector + var $t4: string::String + 0: $t2 := move($t0) + 1: $t3 := move($t1) + 2: $t4 := string::utf8($t3) + 3: string::append($t2, $t4) + 4: return () +} + + +[variant baseline] +public fun string::from_ascii($t0|s: ascii::String): string::String { + var $t1: ascii::String + var $t2: vector + var $t3: string::String + 0: $t1 := move($t0) + 1: $t2 := ascii::into_bytes($t1) + 2: $t3 := pack string::String($t2) + 3: return $t3 +} + + +[variant baseline] +native fun string::internal_check_utf8($t0|v: &vector): bool; + + +[variant baseline] +native fun string::internal_index_of($t0|v: &vector, $t1|r: &vector): u64; + + +[variant baseline] +native fun string::internal_is_char_boundary($t0|v: &vector, $t1|i: u64): bool; + + +[variant baseline] +native fun string::internal_sub_string($t0|v: &vector, $t1|i: u64, $t2|j: u64): vector; + + +[variant baseline] +public fun string::sub_string($t0|s: &string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3: &string::String + var $t4: u64 + var $t5: u64 + var $t6: string::String + 0: $t3 := move($t0) + 1: $t4 := move($t1) + 2: $t5 := move($t2) + 3: $t6 := string::substring($t3, $t4, $t5) + 4: return $t6 +} + + +[variant baseline] +public fun string::to_ascii($t0|s: string::String): ascii::String { + var $t1: string::String + var $t2: vector + var $t3: ascii::String + 0: $t1 := move($t0) + 1: $t2 := unpack string::String($t1) + 2: $t3 := ascii::string($t2) + 3: return $t3 +} + + +[variant baseline] +public fun string::try_utf8($t0|bytes: vector): option::Option { + var $t1|tmp#$1: option::Option + var $t2: &vector + var $t3: bool + var $t4: vector + var $t5: string::String + var $t6: option::Option + var $t7: option::Option + var $t8: option::Option + 0: $t2 := borrow_local($t0) + 1: $t3 := string::internal_check_utf8($t2) + 2: if ($t3) goto 3 else goto 9 + 3: label L1 + 4: $t4 := move($t0) + 5: $t5 := pack string::String($t4) + 6: $t6 := option::some($t5) + 7: $t1 := $t6 + 8: goto 13 + 9: label L0 + 10: $t7 := option::none() + 11: $t1 := $t7 + 12: goto 13 + 13: label L2 + 14: $t8 := move($t1) + 15: return $t8 +} + + +[variant baseline] +public fun string::utf8($t0|bytes: vector): string::String { + var $t1: &vector + var $t2: bool + var $t3: u64 + var $t4: vector + var $t5: string::String + 0: $t1 := borrow_local($t0) + 1: $t2 := string::internal_check_utf8($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 1 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := pack string::String($t4) + 11: return $t5 +} + +============ after pipeline `escape_analysis` ================ + +[variant baseline] +public fun u64::diff($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := >($t7, $t8) + 7: if ($t9) goto 8 else goto 14 + 8: label L1 + 9: $t10 := move($t3) + 10: $t11 := move($t4) + 11: $t12 := -($t10, $t11) + 12: $t2 := $t12 + 13: goto 20 + 14: label L0 + 15: $t13 := move($t4) + 16: $t14 := move($t3) + 17: $t15 := -($t13, $t14) + 18: $t2 := $t15 + 19: goto 20 + 20: label L2 + 21: $t16 := move($t2) + 22: return $t16 +} + + +[variant baseline] +public fun u64::divide_and_round_up($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: u64 + var $t10: u64 + var $t11: bool + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := %($t7, $t8) + 7: $t10 := 0 + 8: $t11 := ==($t9, $t10) + 9: if ($t11) goto 10 else goto 16 + 10: label L1 + 11: $t12 := move($t3) + 12: $t13 := move($t4) + 13: $t14 := /($t12, $t13) + 14: $t2 := $t14 + 15: goto 24 + 16: label L0 + 17: $t15 := move($t3) + 18: $t16 := move($t4) + 19: $t17 := /($t15, $t16) + 20: $t18 := 1 + 21: $t19 := +($t17, $t18) + 22: $t2 := $t19 + 23: goto 24 + 24: label L2 + 25: $t20 := move($t2) + 26: return $t20 +} + + +[variant baseline] +public fun u64::max($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := >($t7, $t8) + 7: if ($t9) goto 8 else goto 12 + 8: label L1 + 9: $t10 := move($t3) + 10: $t2 := $t10 + 11: goto 16 + 12: label L0 + 13: $t11 := move($t4) + 14: $t2 := $t11 + 15: goto 16 + 16: label L2 + 17: $t12 := move($t2) + 18: return $t12 +} + + +[variant baseline] +public fun u64::min($t0|x: u64, $t1|y: u64): u64 { + var $t2|tmp#$2: u64 + var $t3|x#1#1: u64 + var $t4|y#1#1: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: u64 + var $t11: u64 + var $t12: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := move($t1) + 3: $t4 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := copy($t4) + 6: $t9 := <($t7, $t8) + 7: if ($t9) goto 8 else goto 12 + 8: label L1 + 9: $t10 := move($t3) + 10: $t2 := $t10 + 11: goto 16 + 12: label L0 + 13: $t11 := move($t4) + 14: $t2 := $t11 + 15: goto 16 + 16: label L2 + 17: $t12 := move($t2) + 18: return $t12 +} + + +[variant baseline] +public fun u64::pow($t0|base: u64, $t1|exponent: u8): u64 { + var $t2|base#1#1: u64 + var $t3|exponent#1#1: u8 + var $t4|res#1#1: u64 + var $t5: u64 + var $t6: u8 + var $t7: u64 + var $t8: u8 + var $t9: u8 + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: bool + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u8 + var $t20: u8 + var $t21: u8 + var $t22: u64 + var $t23: u64 + var $t24: u64 + var $t25: u8 + var $t26: u8 + var $t27: u8 + var $t28: u64 + 0: $t5 := move($t0) + 1: $t2 := $t5 + 2: $t6 := move($t1) + 3: $t3 := $t6 + 4: $t7 := 1 + 5: $t4 := $t7 + 6: goto 7 + 7: label L5 + 8: $t8 := copy($t3) + 9: $t9 := 1 + 10: $t10 := >=($t8, $t9) + 11: if ($t10) goto 12 else goto 41 + 12: label L1 + 13: goto 14 + 14: label L2 + 15: $t11 := copy($t3) + 16: $t12 := 2 + 17: $t13 := %($t11, $t12) + 18: $t14 := 0 + 19: $t15 := ==($t13, $t14) + 20: if ($t15) goto 21 else goto 31 + 21: label L4 + 22: $t16 := copy($t2) + 23: $t17 := move($t2) + 24: $t18 := *($t16, $t17) + 25: $t2 := $t18 + 26: $t19 := move($t3) + 27: $t20 := 2 + 28: $t21 := /($t19, $t20) + 29: $t3 := $t21 + 30: goto 7 + 31: label L3 + 32: $t22 := move($t4) + 33: $t23 := copy($t2) + 34: $t24 := *($t22, $t23) + 35: $t4 := $t24 + 36: $t25 := move($t3) + 37: $t26 := 1 + 38: $t27 := -($t25, $t26) + 39: $t3 := $t27 + 40: goto 7 + 41: label L0 + 42: $t28 := move($t4) + 43: return $t28 +} + + +[variant baseline] +public fun u64::sqrt($t0|x: u64): u64 { + var $t1|bit#1#1: u128 + var $t2|res#1#1: u128 + var $t3|x#1#1: u64 + var $t4|x#2#1: u128 + var $t5: u64 + var $t6: u128 + var $t7: u128 + var $t8: u64 + var $t9: u128 + var $t10: u128 + var $t11: u128 + var $t12: bool + var $t13: u128 + var $t14: u128 + var $t15: u128 + var $t16: u128 + var $t17: bool + var $t18: u128 + var $t19: u128 + var $t20: u128 + var $t21: u128 + var $t22: u128 + var $t23: u128 + var $t24: u8 + var $t25: u128 + var $t26: u128 + var $t27: u128 + var $t28: u128 + var $t29: u8 + var $t30: u128 + var $t31: u128 + var $t32: u8 + var $t33: u128 + var $t34: u128 + var $t35: u64 + 0: $t5 := move($t0) + 1: $t3 := $t5 + 2: $t6 := 18446744073709551616 + 3: $t1 := $t6 + 4: $t7 := 0 + 5: $t2 := $t7 + 6: $t8 := move($t3) + 7: $t9 := (u128)($t8) + 8: $t4 := $t9 + 9: goto 10 + 10: label L6 + 11: $t10 := copy($t1) + 12: $t11 := 0 + 13: $t12 := !=($t10, $t11) + 14: if ($t12) goto 15 else goto 50 + 15: label L1 + 16: goto 17 + 17: label L2 + 18: $t13 := copy($t4) + 19: $t14 := copy($t2) + 20: $t15 := copy($t1) + 21: $t16 := +($t14, $t15) + 22: $t17 := >=($t13, $t16) + 23: if ($t17) goto 24 else goto 38 + 24: label L4 + 25: $t18 := move($t4) + 26: $t19 := copy($t2) + 27: $t20 := copy($t1) + 28: $t21 := +($t19, $t20) + 29: $t22 := -($t18, $t21) + 30: $t4 := $t22 + 31: $t23 := move($t2) + 32: $t24 := 1 + 33: $t25 := >>($t23, $t24) + 34: $t26 := copy($t1) + 35: $t27 := +($t25, $t26) + 36: $t2 := $t27 + 37: goto 44 + 38: label L3 + 39: $t28 := move($t2) + 40: $t29 := 1 + 41: $t30 := >>($t28, $t29) + 42: $t2 := $t30 + 43: goto 44 + 44: label L5 + 45: $t31 := move($t1) + 46: $t32 := 2 + 47: $t33 := >>($t31, $t32) + 48: $t1 := $t33 + 49: goto 10 + 50: label L0 + 51: $t34 := move($t2) + 52: $t35 := (u64)($t34) + 53: return $t35 +} + + +[variant baseline] +public fun vector::append<#0>($t0|lhs: &mut vector<#0>, $t1|other: vector<#0>) { + var $t2: &mut vector<#0> + var $t3: &vector<#0> + var $t4: bool + var $t5: bool + var $t6: &mut vector<#0> + var $t7: &mut vector<#0> + var $t8: #0 + var $t9: &mut vector<#0> + var $t10: vector<#0> + 0: $t2 := borrow_local($t1) + 1: vector::reverse<#0>($t2) + 2: goto 3 + 3: label L3 + 4: $t3 := borrow_local($t1) + 5: $t4 := vector::is_empty<#0>($t3) + 6: $t5 := !($t4) + 7: if ($t5) goto 8 else goto 16 + 8: label L1 + 9: goto 10 + 10: label L2 + 11: $t6 := copy($t0) + 12: $t7 := borrow_local($t1) + 13: $t8 := vector::pop_back<#0>($t7) + 14: vector::push_back<#0>($t6, $t8) + 15: goto 3 + 16: label L0 + 17: $t9 := move($t0) + 18: destroy($t9) + 19: $t10 := move($t1) + 20: vector::destroy_empty<#0>($t10) + 21: return () +} + + +[variant baseline] +public native fun vector::borrow<#0>($t0|v: &vector<#0>, $t1|i: u64): � + + +[variant baseline] +public native fun vector::borrow_mut<#0>($t0|v: &mut vector<#0>, $t1|i: u64): &mut #0; + + +[variant baseline] +public fun vector::contains<#0>($t0|v: &vector<#0>, $t1|e: �): bool { + var $t2|i#1#0: u64 + var $t3|len#1#0: u64 + var $t4: u64 + var $t5: &vector<#0> + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: &vector<#0> + var $t11: u64 + var $t12: � + var $t13: � + var $t14: bool + var $t15: &vector<#0> + var $t16: � + var $t17: bool + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: &vector<#0> + var $t22: � + var $t23: bool + 0: $t4 := 0 + 1: $t2 := $t4 + 2: $t5 := copy($t0) + 3: $t6 := vector::length<#0>($t5) + 4: $t3 := $t6 + 5: goto 6 + 6: label L5 + 7: $t7 := copy($t2) + 8: $t8 := copy($t3) + 9: $t9 := <($t7, $t8) + 10: if ($t9) goto 11 else goto 33 + 11: label L1 + 12: goto 13 + 13: label L2 + 14: $t10 := copy($t0) + 15: $t11 := copy($t2) + 16: $t12 := vector::borrow<#0>($t10, $t11) + 17: $t13 := copy($t1) + 18: $t14 := ==($t12, $t13) + 19: if ($t14) goto 20 else goto 27 + 20: label L4 + 21: $t15 := move($t0) + 22: destroy($t15) + 23: $t16 := move($t1) + 24: destroy($t16) + 25: $t17 := true + 26: return $t17 + 27: label L3 + 28: $t18 := move($t2) + 29: $t19 := 1 + 30: $t20 := +($t18, $t19) + 31: $t2 := $t20 + 32: goto 6 + 33: label L0 + 34: $t21 := move($t0) + 35: destroy($t21) + 36: $t22 := move($t1) + 37: destroy($t22) + 38: $t23 := false + 39: return $t23 +} + + +[variant baseline] +public native fun vector::destroy_empty<#0>($t0|v: vector<#0>); + + +[variant baseline] +public native fun vector::empty<#0>(): vector<#0>; + + +[variant baseline] +public fun vector::index_of<#0>($t0|v: &vector<#0>, $t1|e: �): (bool, u64) { + var $t2|i#1#0: u64 + var $t3|len#1#0: u64 + var $t4: u64 + var $t5: &vector<#0> + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: &vector<#0> + var $t11: u64 + var $t12: � + var $t13: � + var $t14: bool + var $t15: &vector<#0> + var $t16: � + var $t17: bool + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: u64 + var $t22: &vector<#0> + var $t23: � + var $t24: bool + var $t25: u64 + 0: $t4 := 0 + 1: $t2 := $t4 + 2: $t5 := copy($t0) + 3: $t6 := vector::length<#0>($t5) + 4: $t3 := $t6 + 5: goto 6 + 6: label L5 + 7: $t7 := copy($t2) + 8: $t8 := copy($t3) + 9: $t9 := <($t7, $t8) + 10: if ($t9) goto 11 else goto 34 + 11: label L1 + 12: goto 13 + 13: label L2 + 14: $t10 := copy($t0) + 15: $t11 := copy($t2) + 16: $t12 := vector::borrow<#0>($t10, $t11) + 17: $t13 := copy($t1) + 18: $t14 := ==($t12, $t13) + 19: if ($t14) goto 20 else goto 28 + 20: label L4 + 21: $t15 := move($t0) + 22: destroy($t15) + 23: $t16 := move($t1) + 24: destroy($t16) + 25: $t17 := true + 26: $t18 := move($t2) + 27: return ($t17, $t18) + 28: label L3 + 29: $t19 := move($t2) + 30: $t20 := 1 + 31: $t21 := +($t19, $t20) + 32: $t2 := $t21 + 33: goto 6 + 34: label L0 + 35: $t22 := move($t0) + 36: destroy($t22) + 37: $t23 := move($t1) + 38: destroy($t23) + 39: $t24 := false + 40: $t25 := 0 + 41: return ($t24, $t25) +} + + +[variant baseline] +public fun vector::insert<#0>($t0|v: &mut vector<#0>, $t1|e: #0, $t2|i: u64) { + var $t3|len#1#0: u64 + var $t4: &mut vector<#0> + var $t5: &vector<#0> + var $t6: u64 + var $t7: u64 + var $t8: u64 + var $t9: bool + var $t10: &mut vector<#0> + var $t11: u64 + var $t12: &mut vector<#0> + var $t13: #0 + var $t14: u64 + var $t15: u64 + var $t16: bool + var $t17: &mut vector<#0> + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: u64 + var $t22: u64 + var $t23: &mut vector<#0> + 0: $t4 := copy($t0) + 1: $t5 := freeze_ref($t4) + 2: $t6 := vector::length<#0>($t5) + 3: $t3 := $t6 + 4: $t7 := copy($t2) + 5: $t8 := copy($t3) + 6: $t9 := >($t7, $t8) + 7: if ($t9) goto 8 else goto 13 + 8: label L1 + 9: $t10 := move($t0) + 10: destroy($t10) + 11: $t11 := 131072 + 12: abort($t11) + 13: label L0 + 14: $t12 := copy($t0) + 15: $t13 := move($t1) + 16: vector::push_back<#0>($t12, $t13) + 17: goto 18 + 18: label L4 + 19: $t14 := copy($t2) + 20: $t15 := copy($t3) + 21: $t16 := <($t14, $t15) + 22: if ($t16) goto 23 else goto 33 + 23: label L3 + 24: $t17 := copy($t0) + 25: $t18 := copy($t2) + 26: $t19 := copy($t3) + 27: vector::swap<#0>($t17, $t18, $t19) + 28: $t20 := move($t2) + 29: $t21 := 1 + 30: $t22 := +($t20, $t21) + 31: $t2 := $t22 + 32: goto 18 + 33: label L2 + 34: $t23 := move($t0) + 35: destroy($t23) + 36: return () +} + + +[variant baseline] +public fun vector::is_empty<#0>($t0|v: &vector<#0>): bool { + var $t1: &vector<#0> + var $t2: u64 + var $t3: u64 + var $t4: bool + 0: $t1 := move($t0) + 1: $t2 := vector::length<#0>($t1) + 2: $t3 := 0 + 3: $t4 := ==($t2, $t3) + 4: return $t4 +} + + +[variant baseline] +public native fun vector::length<#0>($t0|v: &vector<#0>): u64; + + +[variant baseline] +public native fun vector::pop_back<#0>($t0|v: &mut vector<#0>): #0; + + +[variant baseline] +public native fun vector::push_back<#0>($t0|v: &mut vector<#0>, $t1|e: #0); + + +[variant baseline] +public fun vector::remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { + var $t2|tmp#$2: u64 + var $t3|tmp#$3: &mut vector<#0> + var $t4|len#1#0: u64 + var $t5: &mut vector<#0> + var $t6: &vector<#0> + var $t7: u64 + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: &mut vector<#0> + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + var $t17: u64 + var $t18: bool + var $t19: &mut vector<#0> + var $t20: u64 + var $t21: u64 + var $t22: u64 + var $t23: u64 + var $t24: &mut vector<#0> + var $t25: u64 + var $t26: u64 + var $t27: &mut vector<#0> + var $t28: #0 + 0: $t5 := copy($t0) + 1: $t6 := freeze_ref($t5) + 2: $t7 := vector::length<#0>($t6) + 3: $t4 := $t7 + 4: $t8 := copy($t1) + 5: $t9 := copy($t4) + 6: $t10 := >=($t8, $t9) + 7: if ($t10) goto 8 else goto 13 + 8: label L1 + 9: $t11 := move($t0) + 10: destroy($t11) + 11: $t12 := 131072 + 12: abort($t12) + 13: label L0 + 14: $t13 := move($t4) + 15: $t14 := 1 + 16: $t15 := -($t13, $t14) + 17: $t4 := $t15 + 18: goto 19 + 19: label L4 + 20: $t16 := copy($t1) + 21: $t17 := copy($t4) + 22: $t18 := <($t16, $t17) + 23: if ($t18) goto 24 else goto 38 + 24: label L3 + 25: $t19 := copy($t0) + 26: $t3 := $t19 + 27: $t20 := copy($t1) + 28: $t2 := $t20 + 29: $t21 := move($t1) + 30: $t22 := 1 + 31: $t23 := +($t21, $t22) + 32: $t1 := $t23 + 33: $t24 := move($t3) + 34: $t25 := move($t2) + 35: $t26 := copy($t1) + 36: vector::swap<#0>($t24, $t25, $t26) + 37: goto 19 + 38: label L2 + 39: $t27 := move($t0) + 40: $t28 := vector::pop_back<#0>($t27) + 41: return $t28 +} + + +[variant baseline] +public fun vector::reverse<#0>($t0|v: &mut vector<#0>) { + var $t1|back_index#1#0: u64 + var $t2|front_index#1#0: u64 + var $t3|len#1#0: u64 + var $t4: &mut vector<#0> var $t5: &vector<#0> var $t6: u64 var $t7: u64 var $t8: u64 var $t9: bool + var $t10: &mut vector<#0> + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: u64 + var $t16: u64 + var $t17: bool + var $t18: &mut vector<#0> + var $t19: u64 + var $t20: u64 + var $t21: u64 + var $t22: u64 + var $t23: u64 + var $t24: u64 + var $t25: u64 + var $t26: u64 + var $t27: &mut vector<#0> + 0: $t4 := copy($t0) + 1: $t5 := freeze_ref($t4) + 2: $t6 := vector::length<#0>($t5) + 3: $t3 := $t6 + 4: $t7 := copy($t3) + 5: $t8 := 0 + 6: $t9 := ==($t7, $t8) + 7: if ($t9) goto 8 else goto 12 + 8: label L1 + 9: $t10 := move($t0) + 10: destroy($t10) + 11: return () + 12: label L0 + 13: $t11 := 0 + 14: $t2 := $t11 + 15: $t12 := move($t3) + 16: $t13 := 1 + 17: $t14 := -($t12, $t13) + 18: $t1 := $t14 + 19: goto 20 + 20: label L4 + 21: $t15 := copy($t2) + 22: $t16 := copy($t1) + 23: $t17 := <($t15, $t16) + 24: if ($t17) goto 25 else goto 39 + 25: label L3 + 26: $t18 := copy($t0) + 27: $t19 := copy($t2) + 28: $t20 := copy($t1) + 29: vector::swap<#0>($t18, $t19, $t20) + 30: $t21 := move($t2) + 31: $t22 := 1 + 32: $t23 := +($t21, $t22) + 33: $t2 := $t23 + 34: $t24 := move($t1) + 35: $t25 := 1 + 36: $t26 := -($t24, $t25) + 37: $t1 := $t26 + 38: goto 20 + 39: label L2 + 40: $t27 := move($t0) + 41: destroy($t27) + 42: return () +} + + +[variant baseline] +public fun vector::singleton<#0>($t0|e: #0): vector<#0> { + var $t1|v#1#0: vector<#0> + var $t2: vector<#0> + var $t3: &mut vector<#0> + var $t4: #0 + var $t5: vector<#0> + 0: $t2 := vector::empty<#0>() + 1: $t1 := $t2 + 2: $t3 := borrow_local($t1) + 3: $t4 := move($t0) + 4: vector::push_back<#0>($t3, $t4) + 5: $t5 := move($t1) + 6: return $t5 +} + + +[variant baseline] +public native fun vector::swap<#0>($t0|v: &mut vector<#0>, $t1|i: u64, $t2|j: u64); + + +[variant baseline] +public fun vector::swap_remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { + var $t2|last_idx#1#0: u64 + var $t3: &mut vector<#0> + var $t4: &vector<#0> + var $t5: bool + var $t6: bool + var $t7: &mut vector<#0> + var $t8: u64 + var $t9: &mut vector<#0> + var $t10: &vector<#0> + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: &mut vector<#0> + var $t15: u64 + var $t16: u64 + var $t17: &mut vector<#0> + var $t18: #0 + 0: $t3 := copy($t0) + 1: $t4 := freeze_ref($t3) + 2: $t5 := vector::is_empty<#0>($t4) + 3: $t6 := !($t5) + 4: if ($t6) goto 5 else goto 7 + 5: label L1 + 6: goto 12 + 7: label L0 + 8: $t7 := move($t0) + 9: destroy($t7) + 10: $t8 := 131072 + 11: abort($t8) + 12: label L2 + 13: $t9 := copy($t0) + 14: $t10 := freeze_ref($t9) + 15: $t11 := vector::length<#0>($t10) + 16: $t12 := 1 + 17: $t13 := -($t11, $t12) + 18: $t2 := $t13 + 19: $t14 := copy($t0) + 20: $t15 := move($t1) + 21: $t16 := move($t2) + 22: vector::swap<#0>($t14, $t15, $t16) + 23: $t17 := move($t0) + 24: $t18 := vector::pop_back<#0>($t17) + 25: return $t18 +} + + +[variant baseline] +fun ReturnRefsIntoVec::return_vec_index_immut($t0|v: &vector): &u64 { + var $t1: &vector + var $t2: u64 + var $t3: &u64 + 0: $t1 := move($t0) + 1: $t2 := 0 + 2: $t3 := vector::borrow($t1, $t2) + 3: return $t3 +} + + +[variant baseline] +fun ReturnRefsIntoVec::return_vec_index_mut($t0|v: &mut vector): &mut u64 { + var $t1: &mut vector + var $t2: u64 + var $t3: &mut u64 + 0: $t1 := move($t0) + 1: $t2 := 0 + 2: $t3 := vector::borrow_mut($t1, $t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::borrow<#0>($t0|t: &option::Option<#0>): � { + var $t1: &option::Option<#0> + var $t2: bool + var $t3: &option::Option<#0> + var $t4: u64 + var $t5: &option::Option<#0> + var $t6: &vector<#0> + var $t7: u64 + var $t8: � + 0: $t1 := copy($t0) + 1: $t2 := option::is_some<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 10 + 5: label L0 + 6: $t3 := move($t0) + 7: destroy($t3) + 8: $t4 := 262145 + 9: abort($t4) + 10: label L2 + 11: $t5 := move($t0) + 12: $t6 := borrow_field>.vec($t5) + 13: $t7 := 0 + 14: $t8 := vector::borrow<#0>($t6, $t7) + 15: return $t8 +} + + +[variant baseline] +public fun option::borrow_mut<#0>($t0|t: &mut option::Option<#0>): &mut #0 { + var $t1: &mut option::Option<#0> + var $t2: &option::Option<#0> + var $t3: bool + var $t4: &mut option::Option<#0> + var $t5: u64 + var $t6: &mut option::Option<#0> + var $t7: &mut vector<#0> + var $t8: u64 + var $t9: &mut #0 + 0: $t1 := copy($t0) + 1: $t2 := freeze_ref($t1) + 2: $t3 := option::is_some<#0>($t2) + 3: if ($t3) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t4 := move($t0) + 8: destroy($t4) + 9: $t5 := 262145 + 10: abort($t5) + 11: label L2 + 12: $t6 := move($t0) + 13: $t7 := borrow_field>.vec($t6) + 14: $t8 := 0 + 15: $t9 := vector::borrow_mut<#0>($t7, $t8) + 16: return $t9 +} + + +[variant baseline] +public fun option::contains<#0>($t0|t: &option::Option<#0>, $t1|e_ref: �): bool { + var $t2: &option::Option<#0> + var $t3: &vector<#0> + var $t4: � + var $t5: bool + 0: $t2 := move($t0) + 1: $t3 := borrow_field>.vec($t2) + 2: $t4 := move($t1) + 3: $t5 := vector::contains<#0>($t3, $t4) + 4: return $t5 +} + + +[variant baseline] +public fun option::swap<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): #0 { + var $t2|old_value#1#0: #0 + var $t3|vec_ref#1#0: &mut vector<#0> + var $t4: &mut option::Option<#0> + var $t5: &option::Option<#0> + var $t6: bool + var $t7: &mut option::Option<#0> + var $t8: u64 + var $t9: &mut option::Option<#0> + var $t10: &mut vector<#0> + var $t11: &mut vector<#0> + var $t12: #0 + var $t13: &mut vector<#0> + var $t14: #0 + var $t15: #0 + 0: $t4 := copy($t0) + 1: $t5 := freeze_ref($t4) + 2: $t6 := option::is_some<#0>($t5) + 3: if ($t6) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t7 := move($t0) + 8: destroy($t7) + 9: $t8 := 262145 + 10: abort($t8) + 11: label L2 + 12: $t9 := move($t0) + 13: $t10 := borrow_field>.vec($t9) + 14: $t3 := $t10 + 15: $t11 := copy($t3) + 16: $t12 := vector::pop_back<#0>($t11) + 17: $t2 := $t12 + 18: $t13 := move($t3) + 19: $t14 := move($t1) + 20: vector::push_back<#0>($t13, $t14) + 21: $t15 := move($t2) + 22: return $t15 +} + + +[variant baseline] +public fun option::borrow_with_default<#0>($t0|t: &option::Option<#0>, $t1|default_ref: �): � { + var $t2|tmp#$2: � + var $t3|vec_ref#1#0: &vector<#0> + var $t4: &option::Option<#0> + var $t5: &vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &vector<#0> + var $t9: � + var $t10: � + var $t11: &vector<#0> + var $t12: u64 + var $t13: � + var $t14: � + 0: $t4 := move($t0) + 1: $t5 := borrow_field>.vec($t4) + 2: $t3 := $t5 + 3: $t6 := copy($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 12 + 6: label L1 + 7: $t8 := move($t3) + 8: destroy($t8) + 9: $t9 := move($t1) + 10: $t2 := $t9 + 11: goto 20 + 12: label L0 + 13: $t10 := move($t1) + 14: destroy($t10) + 15: $t11 := move($t3) + 16: $t12 := 0 + 17: $t13 := vector::borrow<#0>($t11, $t12) + 18: $t2 := $t13 + 19: goto 20 + 20: label L2 + 21: $t14 := move($t2) + 22: return $t14 +} + + +[variant baseline] +public fun option::destroy_none<#0>($t0|t: option::Option<#0>) { + var $t1: &option::Option<#0> + var $t2: bool + var $t3: u64 + var $t4: option::Option<#0> + var $t5: vector<#0> + 0: $t1 := borrow_local($t0) + 1: $t2 := option::is_none<#0>($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 262144 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := unpack option::Option<#0>($t4) + 11: vector::destroy_empty<#0>($t5) + 12: return () +} + + +[variant baseline] +public fun option::destroy_some<#0>($t0|t: option::Option<#0>): #0 { + var $t1|elem#1#0: #0 + var $t2|vec#1#0: vector<#0> + var $t3: &option::Option<#0> + var $t4: bool + var $t5: u64 + var $t6: option::Option<#0> + var $t7: vector<#0> + var $t8: &mut vector<#0> + var $t9: #0 + var $t10: vector<#0> + var $t11: #0 + 0: $t3 := borrow_local($t0) + 1: $t4 := option::is_some<#0>($t3) + 2: if ($t4) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t5 := 262145 + 7: abort($t5) + 8: label L2 + 9: $t6 := move($t0) + 10: $t7 := unpack option::Option<#0>($t6) + 11: $t2 := $t7 + 12: $t8 := borrow_local($t2) + 13: $t9 := vector::pop_back<#0>($t8) + 14: $t1 := $t9 + 15: $t10 := move($t2) + 16: vector::destroy_empty<#0>($t10) + 17: $t11 := move($t1) + 18: return $t11 +} + + +[variant baseline] +public fun option::destroy_with_default<#0>($t0|t: option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec#1#0: vector<#0> + var $t4: option::Option<#0> + var $t5: vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: #0 + var $t9: &mut vector<#0> + var $t10: #0 + var $t11: #0 + 0: $t4 := move($t0) + 1: $t5 := unpack option::Option<#0>($t4) + 2: $t3 := $t5 + 3: $t6 := borrow_local($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 10 + 6: label L1 + 7: $t8 := move($t1) + 8: $t2 := $t8 + 9: goto 15 + 10: label L0 + 11: $t9 := borrow_local($t3) + 12: $t10 := vector::pop_back<#0>($t9) + 13: $t2 := $t10 + 14: goto 15 + 15: label L2 + 16: $t11 := move($t2) + 17: return $t11 +} + + +[variant baseline] +public fun option::extract<#0>($t0|t: &mut option::Option<#0>): #0 { + var $t1: &mut option::Option<#0> + var $t2: &option::Option<#0> + var $t3: bool + var $t4: &mut option::Option<#0> + var $t5: u64 + var $t6: &mut option::Option<#0> + var $t7: &mut vector<#0> + var $t8: #0 + 0: $t1 := copy($t0) + 1: $t2 := freeze_ref($t1) + 2: $t3 := option::is_some<#0>($t2) + 3: if ($t3) goto 4 else goto 6 + 4: label L1 + 5: goto 11 + 6: label L0 + 7: $t4 := move($t0) + 8: destroy($t4) + 9: $t5 := 262145 + 10: abort($t5) + 11: label L2 + 12: $t6 := move($t0) + 13: $t7 := borrow_field>.vec($t6) + 14: $t8 := vector::pop_back<#0>($t7) + 15: return $t8 +} + + +[variant baseline] +public fun option::fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0) { + var $t2|vec_ref#1#0: &mut vector<#0> + var $t3: &mut option::Option<#0> + var $t4: &mut vector<#0> + var $t5: &mut vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &mut vector<#0> + var $t9: u64 + var $t10: &mut vector<#0> + var $t11: #0 + 0: $t3 := move($t0) + 1: $t4 := borrow_field>.vec($t3) + 2: $t2 := $t4 + 3: $t5 := copy($t2) + 4: $t6 := freeze_ref($t5) + 5: $t7 := vector::is_empty<#0>($t6) + 6: if ($t7) goto 7 else goto 9 + 7: label L1 + 8: goto 14 + 9: label L0 + 10: $t8 := move($t2) + 11: destroy($t8) + 12: $t9 := 262144 + 13: abort($t9) + 14: label L2 + 15: $t10 := move($t2) + 16: $t11 := move($t1) + 17: vector::push_back<#0>($t10, $t11) + 18: return () +} + + +[variant baseline] +public fun option::get_with_default<#0>($t0|t: &option::Option<#0>, $t1|default: #0): #0 { + var $t2|tmp#$2: #0 + var $t3|vec_ref#1#0: &vector<#0> + var $t4: &option::Option<#0> + var $t5: &vector<#0> + var $t6: &vector<#0> + var $t7: bool + var $t8: &vector<#0> + var $t9: #0 var $t10: &vector<#0> var $t11: u64 var $t12: � - var $t13: � + var $t13: #0 + var $t14: #0 + 0: $t4 := move($t0) + 1: $t5 := borrow_field>.vec($t4) + 2: $t3 := $t5 + 3: $t6 := copy($t3) + 4: $t7 := vector::is_empty<#0>($t6) + 5: if ($t7) goto 6 else goto 12 + 6: label L1 + 7: $t8 := move($t3) + 8: destroy($t8) + 9: $t9 := move($t1) + 10: $t2 := $t9 + 11: goto 19 + 12: label L0 + 13: $t10 := move($t3) + 14: $t11 := 0 + 15: $t12 := vector::borrow<#0>($t10, $t11) + 16: $t13 := read_ref($t12) + 17: $t2 := $t13 + 18: goto 19 + 19: label L2 + 20: $t14 := move($t2) + 21: return $t14 +} + + +[variant baseline] +public fun option::is_none<#0>($t0|t: &option::Option<#0>): bool { + var $t1: &option::Option<#0> + var $t2: &vector<#0> + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field>.vec($t1) + 2: $t3 := vector::is_empty<#0>($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::is_some<#0>($t0|t: &option::Option<#0>): bool { + var $t1: &option::Option<#0> + var $t2: &vector<#0> + var $t3: bool + var $t4: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field>.vec($t1) + 2: $t3 := vector::is_empty<#0>($t2) + 3: $t4 := !($t3) + 4: return $t4 +} + + +[variant baseline] +public fun option::none<#0>(): option::Option<#0> { + var $t0: vector<#0> + var $t1: option::Option<#0> + 0: $t0 := vector::empty<#0>() + 1: $t1 := pack option::Option<#0>($t0) + 2: return $t1 +} + + +[variant baseline] +public fun option::some<#0>($t0|e: #0): option::Option<#0> { + var $t1: #0 + var $t2: vector<#0> + var $t3: option::Option<#0> + 0: $t1 := move($t0) + 1: $t2 := vector::singleton<#0>($t1) + 2: $t3 := pack option::Option<#0>($t2) + 3: return $t3 +} + + +[variant baseline] +public fun option::swap_or_fill<#0>($t0|t: &mut option::Option<#0>, $t1|e: #0): option::Option<#0> { + var $t2|tmp#$2: option::Option<#0> + var $t3|old_value#1#0: option::Option<#0> + var $t4|vec_ref#1#0: &mut vector<#0> + var $t5: &mut option::Option<#0> + var $t6: &mut vector<#0> + var $t7: &mut vector<#0> + var $t8: &vector<#0> + var $t9: bool + var $t10: option::Option<#0> + var $t11: &mut vector<#0> + var $t12: #0 + var $t13: option::Option<#0> + var $t14: option::Option<#0> + var $t15: &mut vector<#0> + var $t16: #0 + var $t17: option::Option<#0> + 0: $t5 := move($t0) + 1: $t6 := borrow_field>.vec($t5) + 2: $t4 := $t6 + 3: $t7 := copy($t4) + 4: $t8 := freeze_ref($t7) + 5: $t9 := vector::is_empty<#0>($t8) + 6: if ($t9) goto 7 else goto 11 + 7: label L1 + 8: $t10 := option::none<#0>() + 9: $t2 := $t10 + 10: goto 17 + 11: label L0 + 12: $t11 := copy($t4) + 13: $t12 := vector::pop_back<#0>($t11) + 14: $t13 := option::some<#0>($t12) + 15: $t2 := $t13 + 16: goto 17 + 17: label L2 + 18: $t14 := move($t2) + 19: $t3 := $t14 + 20: $t15 := move($t4) + 21: $t16 := move($t1) + 22: vector::push_back<#0>($t15, $t16) + 23: $t17 := move($t3) + 24: return $t17 +} + + +[variant baseline] +public fun option::to_vec<#0>($t0|t: option::Option<#0>): vector<#0> { + var $t1: option::Option<#0> + var $t2: vector<#0> + 0: $t1 := move($t0) + 1: $t2 := unpack option::Option<#0>($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::append($t0|string: &mut ascii::String, $t1|other: ascii::String) { + var $t2: &mut ascii::String + var $t3: &mut vector + var $t4: ascii::String + var $t5: vector + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := move($t1) + 3: $t5 := ascii::into_bytes($t4) + 4: vector::append($t3, $t5) + 5: return () +} + + +[variant baseline] +public fun ascii::index_of($t0|string: &ascii::String, $t1|substr: &ascii::String): u64 { + var $t2|tmp#$2: bool + var $t3|i#1#0: u64 + var $t4|j#1#0: u64 + var $t5|m#1#0: u64 + var $t6|n#1#0: u64 + var $t7: u64 + var $t8: &ascii::String + var $t9: u64 + var $t10: &ascii::String + var $t11: u64 + var $t12: u64 + var $t13: u64 var $t14: bool - var $t15: &vector<#0> - var $t16: � - var $t17: bool + var $t15: &ascii::String + var $t16: &ascii::String + var $t17: u64 var $t18: u64 var $t19: u64 var $t20: u64 var $t21: u64 - var $t22: &vector<#0> - var $t23: � - var $t24: bool + var $t22: bool + var $t23: u64 + var $t24: u64 var $t25: u64 - 0: $t4 := 0 - 1: $t2 := $t4 - 2: $t5 := copy($t0) - 3: $t6 := vector::length<#0>($t5) - 4: $t3 := $t6 - 5: goto 6 - 6: label L5 - 7: $t7 := copy($t2) - 8: $t8 := copy($t3) - 9: $t9 := <($t7, $t8) - 10: if ($t9) goto 11 else goto 34 - 11: label L1 - 12: goto 13 - 13: label L2 - 14: $t10 := copy($t0) - 15: $t11 := copy($t2) - 16: $t12 := vector::borrow<#0>($t10, $t11) - 17: $t13 := copy($t1) - 18: $t14 := ==($t12, $t13) - 19: if ($t14) goto 20 else goto 28 - 20: label L4 - 21: $t15 := move($t0) - 22: destroy($t15) - 23: $t16 := move($t1) - 24: destroy($t16) - 25: $t17 := true - 26: $t18 := move($t2) - 27: return ($t17, $t18) - 28: label L3 - 29: $t19 := move($t2) - 30: $t20 := 1 - 31: $t21 := +($t19, $t20) - 32: $t2 := $t21 - 33: goto 6 - 34: label L0 - 35: $t22 := move($t0) - 36: destroy($t22) - 37: $t23 := move($t1) - 38: destroy($t23) - 39: $t24 := false - 40: $t25 := 0 - 41: return ($t24, $t25) + var $t26: bool + var $t27: &ascii::String + var $t28: &vector + var $t29: u64 + var $t30: u64 + var $t31: u64 + var $t32: &u8 + var $t33: u8 + var $t34: &ascii::String + var $t35: &vector + var $t36: u64 + var $t37: &u8 + var $t38: u8 + var $t39: bool + var $t40: bool + var $t41: bool + var $t42: u64 + var $t43: u64 + var $t44: u64 + var $t45: u64 + var $t46: u64 + var $t47: bool + var $t48: &ascii::String + var $t49: &ascii::String + var $t50: u64 + var $t51: u64 + var $t52: u64 + var $t53: u64 + var $t54: &ascii::String + var $t55: &ascii::String + var $t56: u64 + 0: $t7 := 0 + 1: $t3 := $t7 + 2: $t8 := copy($t0) + 3: $t9 := ascii::length($t8) + 4: $t10 := copy($t1) + 5: $t11 := ascii::length($t10) + 6: $t5 := $t11 + 7: $t6 := $t9 + 8: $t12 := copy($t6) + 9: $t13 := copy($t5) + 10: $t14 := <($t12, $t13) + 11: if ($t14) goto 12 else goto 19 + 12: label L1 + 13: $t15 := move($t1) + 14: destroy($t15) + 15: $t16 := move($t0) + 16: destroy($t16) + 17: $t17 := move($t6) + 18: return $t17 + 19: label L0 + 20: $t18 := copy($t3) + 21: $t19 := copy($t6) + 22: $t20 := copy($t5) + 23: $t21 := -($t19, $t20) + 24: $t22 := <=($t18, $t21) + 25: if ($t22) goto 26 else goto 84 + 26: label L3 + 27: $t23 := 0 + 28: $t4 := $t23 + 29: goto 30 + 30: label L10 + 31: $t24 := copy($t4) + 32: $t25 := copy($t5) + 33: $t26 := <($t24, $t25) + 34: if ($t26) goto 35 else goto 53 + 35: label L5 + 36: goto 37 + 37: label L6 + 38: $t27 := copy($t0) + 39: $t28 := borrow_field.bytes($t27) + 40: $t29 := copy($t3) + 41: $t30 := copy($t4) + 42: $t31 := +($t29, $t30) + 43: $t32 := vector::borrow($t28, $t31) + 44: $t33 := read_ref($t32) + 45: $t34 := copy($t1) + 46: $t35 := borrow_field.bytes($t34) + 47: $t36 := copy($t4) + 48: $t37 := vector::borrow($t35, $t36) + 49: $t38 := read_ref($t37) + 50: $t39 := ==($t33, $t38) + 51: $t2 := $t39 + 52: goto 57 + 53: label L4 + 54: $t40 := false + 55: $t2 := $t40 + 56: goto 57 + 57: label L7 + 58: $t41 := move($t2) + 59: if ($t41) goto 60 else goto 66 + 60: label L9 + 61: $t42 := move($t4) + 62: $t43 := 1 + 63: $t44 := +($t42, $t43) + 64: $t4 := $t44 + 65: goto 30 + 66: label L8 + 67: $t45 := move($t4) + 68: $t46 := copy($t5) + 69: $t47 := ==($t45, $t46) + 70: if ($t47) goto 71 else goto 78 + 71: label L12 + 72: $t48 := move($t1) + 73: destroy($t48) + 74: $t49 := move($t0) + 75: destroy($t49) + 76: $t50 := move($t3) + 77: return $t50 + 78: label L11 + 79: $t51 := move($t3) + 80: $t52 := 1 + 81: $t53 := +($t51, $t52) + 82: $t3 := $t53 + 83: goto 19 + 84: label L2 + 85: $t54 := move($t1) + 86: destroy($t54) + 87: $t55 := move($t0) + 88: destroy($t55) + 89: $t56 := move($t6) + 90: return $t56 } [variant baseline] -public fun vector::insert<#0>($t0|v: &mut vector<#0>, $t1|e: #0, $t2|i: u64) { - var $t3|len#1#0: u64 - var $t4: &mut vector<#0> - var $t5: &vector<#0> - var $t6: u64 - var $t7: u64 +public fun ascii::insert($t0|s: &mut ascii::String, $t1|at: u64, $t2|o: ascii::String) { + var $t3|e#1#2: u8 + var $t4|v#1#1: vector + var $t5: u64 + var $t6: &mut ascii::String + var $t7: &ascii::String var $t8: u64 var $t9: bool - var $t10: &mut vector<#0> + var $t10: &mut ascii::String var $t11: u64 - var $t12: &mut vector<#0> - var $t13: #0 - var $t14: u64 - var $t15: u64 + var $t12: ascii::String + var $t13: vector + var $t14: &vector + var $t15: bool var $t16: bool - var $t17: &mut vector<#0> - var $t18: u64 - var $t19: u64 - var $t20: u64 - var $t21: u64 + var $t17: &mut vector + var $t18: u8 + var $t19: &mut ascii::String + var $t20: &mut vector + var $t21: u8 var $t22: u64 - var $t23: &mut vector<#0> - 0: $t4 := copy($t0) - 1: $t5 := freeze_ref($t4) - 2: $t6 := vector::length<#0>($t5) - 3: $t3 := $t6 - 4: $t7 := copy($t2) - 5: $t8 := copy($t3) - 6: $t9 := >($t7, $t8) - 7: if ($t9) goto 8 else goto 13 - 8: label L1 + var $t23: &mut ascii::String + var $t24: vector + 0: $t5 := copy($t1) + 1: $t6 := copy($t0) + 2: $t7 := freeze_ref($t6) + 3: $t8 := ascii::length($t7) + 4: $t9 := <=($t5, $t8) + 5: if ($t9) goto 6 else goto 8 + 6: label L1 + 7: goto 13 + 8: label L0 9: $t10 := move($t0) 10: destroy($t10) - 11: $t11 := 131072 + 11: $t11 := 65537 12: abort($t11) - 13: label L0 - 14: $t12 := copy($t0) - 15: $t13 := move($t1) - 16: vector::push_back<#0>($t12, $t13) + 13: label L2 + 14: $t12 := move($t2) + 15: $t13 := ascii::into_bytes($t12) + 16: $t4 := $t13 17: goto 18 18: label L5 - 19: $t14 := copy($t2) - 20: $t15 := copy($t3) - 21: $t16 := <($t14, $t15) - 22: if ($t16) goto 23 else goto 35 - 23: label L3 - 24: goto 25 - 25: label L4 - 26: $t17 := copy($t0) - 27: $t18 := copy($t2) - 28: $t19 := copy($t3) - 29: vector::swap<#0>($t17, $t18, $t19) - 30: $t20 := move($t2) - 31: $t21 := 1 - 32: $t22 := +($t20, $t21) - 33: $t2 := $t22 - 34: goto 18 - 35: label L2 - 36: $t23 := move($t0) - 37: destroy($t23) + 19: $t14 := borrow_local($t4) + 20: $t15 := vector::is_empty($t14) + 21: $t16 := !($t15) + 22: if ($t16) goto 23 else goto 33 + 23: label L4 + 24: $t17 := borrow_local($t4) + 25: $t18 := vector::pop_back($t17) + 26: $t3 := $t18 + 27: $t19 := copy($t0) + 28: $t20 := borrow_field.bytes($t19) + 29: $t21 := move($t3) + 30: $t22 := copy($t1) + 31: vector::insert($t20, $t21, $t22) + 32: goto 18 + 33: label L3 + 34: $t23 := move($t0) + 35: destroy($t23) + 36: $t24 := move($t4) + 37: vector::destroy_empty($t24) 38: return () } [variant baseline] -public fun vector::is_empty<#0>($t0|v: &vector<#0>): bool { - var $t1: &vector<#0> - var $t2: u64 +public fun ascii::is_empty($t0|string: &ascii::String): bool { + var $t1: &ascii::String + var $t2: &vector + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::is_empty($t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::length($t0|string: &ascii::String): u64 { + var $t1: &ascii::String + var $t2: &vector + var $t3: u64 + 0: $t1 := move($t0) + 1: $t2 := ascii::as_bytes($t1) + 2: $t3 := vector::length($t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::all_characters_printable($t0|string: &ascii::String): bool { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|i#1#12: u64 + var $t4|i#1#9: u64 + var $t5|stop#1#9: u64 + var $t6|v#1#3: &vector + var $t7: &ascii::String + var $t8: &vector + var $t9: &vector + var $t10: u64 + var $t11: u64 + var $t12: u64 + var $t13: u64 + var $t14: u64 + var $t15: bool + var $t16: u64 + var $t17: &vector + var $t18: u64 + var $t19: &u8 + var $t20: u8 + var $t21: bool + var $t22: bool + var $t23: &vector + var $t24: bool + var $t25: u64 + var $t26: u64 + var $t27: u64 + var $t28: &vector + var $t29: bool + var $t30: bool + 0: $t7 := move($t0) + 1: $t8 := borrow_field.bytes($t7) + 2: $t6 := $t8 + 3: $t9 := copy($t6) + 4: $t10 := vector::length($t9) + 5: $t1 := $t10 + 6: $t11 := 0 + 7: $t4 := $t11 + 8: $t12 := move($t1) + 9: $t5 := $t12 + 10: goto 11 + 11: label L5 + 12: $t13 := copy($t4) + 13: $t14 := copy($t5) + 14: $t15 := <($t13, $t14) + 15: if ($t15) goto 16 else goto 38 + 16: label L1 + 17: $t16 := copy($t4) + 18: $t3 := $t16 + 19: $t17 := copy($t6) + 20: $t18 := move($t3) + 21: $t19 := vector::borrow($t17, $t18) + 22: $t20 := read_ref($t19) + 23: $t21 := ascii::is_printable_char($t20) + 24: $t22 := !($t21) + 25: if ($t22) goto 26 else goto 32 + 26: label L3 + 27: $t23 := move($t6) + 28: destroy($t23) + 29: $t24 := false + 30: $t2 := $t24 + 31: goto 44 + 32: label L2 + 33: $t25 := move($t4) + 34: $t26 := 1 + 35: $t27 := +($t25, $t26) + 36: $t4 := $t27 + 37: goto 11 + 38: label L0 + 39: $t28 := move($t6) + 40: destroy($t28) + 41: $t29 := true + 42: $t2 := $t29 + 43: goto 44 + 44: label L4 + 45: $t30 := move($t2) + 46: return $t30 +} + + +[variant baseline] +public fun ascii::string($t0|bytes: vector): ascii::String { + var $t1|x#1#0: option::Option + var $t2: vector + var $t3: option::Option + var $t4: &option::Option + var $t5: bool + var $t6: u64 + var $t7: option::Option + var $t8: ascii::String + 0: $t2 := move($t0) + 1: $t3 := ascii::try_string($t2) + 2: $t1 := $t3 + 3: $t4 := borrow_local($t1) + 4: $t5 := option::is_some($t4) + 5: if ($t5) goto 6 else goto 8 + 6: label L1 + 7: goto 11 + 8: label L0 + 9: $t6 := 65536 + 10: abort($t6) + 11: label L2 + 12: $t7 := move($t1) + 13: $t8 := option::destroy_some($t7) + 14: return $t8 +} + + +[variant baseline] +public fun ascii::as_bytes($t0|string: &ascii::String): &vector { + var $t1: &ascii::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::byte($t0|char: ascii::Char): u8 { + var $t1: ascii::Char + var $t2: u8 + 0: $t1 := move($t0) + 1: $t2 := unpack ascii::Char($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::char($t0|byte: u8): ascii::Char { + var $t1: u8 + var $t2: bool var $t3: u64 + var $t4: u8 + var $t5: ascii::Char + 0: $t1 := copy($t0) + 1: $t2 := ascii::is_valid_char($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 65536 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := pack ascii::Char($t4) + 11: return $t5 +} + + +[variant baseline] +fun ascii::char_to_lowercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: u8 + var $t5: bool + var $t6: u8 + var $t7: u8 + var $t8: bool + var $t9: bool + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: u8 + 0: $t3 := copy($t0) + 1: $t4 := 65 + 2: $t5 := >=($t3, $t4) + 3: if ($t5) goto 4 else goto 10 + 4: label L1 + 5: $t6 := copy($t0) + 6: $t7 := 90 + 7: $t8 := <=($t6, $t7) + 8: $t1 := $t8 + 9: goto 14 + 10: label L0 + 11: $t9 := false + 12: $t1 := $t9 + 13: goto 14 + 14: label L2 + 15: $t10 := move($t1) + 16: if ($t10) goto 17 else goto 23 + 17: label L4 + 18: $t11 := move($t0) + 19: $t12 := 32 + 20: $t13 := +($t11, $t12) + 21: $t2 := $t13 + 22: goto 27 + 23: label L3 + 24: $t14 := move($t0) + 25: $t2 := $t14 + 26: goto 27 + 27: label L5 + 28: $t15 := move($t2) + 29: return $t15 +} + + +[variant baseline] +fun ascii::char_to_uppercase($t0|byte: u8): u8 { + var $t1|tmp#$1: bool + var $t2|tmp#$2: u8 + var $t3: u8 + var $t4: u8 + var $t5: bool + var $t6: u8 + var $t7: u8 + var $t8: bool + var $t9: bool + var $t10: bool + var $t11: u8 + var $t12: u8 + var $t13: u8 + var $t14: u8 + var $t15: u8 + 0: $t3 := copy($t0) + 1: $t4 := 97 + 2: $t5 := >=($t3, $t4) + 3: if ($t5) goto 4 else goto 10 + 4: label L1 + 5: $t6 := copy($t0) + 6: $t7 := 122 + 7: $t8 := <=($t6, $t7) + 8: $t1 := $t8 + 9: goto 14 + 10: label L0 + 11: $t9 := false + 12: $t1 := $t9 + 13: goto 14 + 14: label L2 + 15: $t10 := move($t1) + 16: if ($t10) goto 17 else goto 23 + 17: label L4 + 18: $t11 := move($t0) + 19: $t12 := 32 + 20: $t13 := -($t11, $t12) + 21: $t2 := $t13 + 22: goto 27 + 23: label L3 + 24: $t14 := move($t0) + 25: $t2 := $t14 + 26: goto 27 + 27: label L5 + 28: $t15 := move($t2) + 29: return $t15 +} + + +[variant baseline] +public fun ascii::into_bytes($t0|string: ascii::String): vector { + var $t1: ascii::String + var $t2: vector + 0: $t1 := move($t0) + 1: $t2 := unpack ascii::String($t1) + 2: return $t2 +} + + +[variant baseline] +public fun ascii::is_printable_char($t0|byte: u8): bool { + var $t1|tmp#$1: bool + var $t2: u8 + var $t3: u8 var $t4: bool + var $t5: u8 + var $t6: u8 + var $t7: bool + var $t8: bool + var $t9: bool + 0: $t2 := copy($t0) + 1: $t3 := 32 + 2: $t4 := >=($t2, $t3) + 3: if ($t4) goto 4 else goto 10 + 4: label L1 + 5: $t5 := move($t0) + 6: $t6 := 126 + 7: $t7 := <=($t5, $t6) + 8: $t1 := $t7 + 9: goto 14 + 10: label L0 + 11: $t8 := false + 12: $t1 := $t8 + 13: goto 14 + 14: label L2 + 15: $t9 := move($t1) + 16: return $t9 +} + + +[variant baseline] +public fun ascii::is_valid_char($t0|b: u8): bool { + var $t1: u8 + var $t2: u8 + var $t3: bool 0: $t1 := move($t0) - 1: $t2 := vector::length<#0>($t1) - 2: $t3 := 0 - 3: $t4 := ==($t2, $t3) + 1: $t2 := 127 + 2: $t3 := <=($t1, $t2) + 3: return $t3 +} + + +[variant baseline] +public fun ascii::pop_char($t0|string: &mut ascii::String): ascii::Char { + var $t1: &mut ascii::String + var $t2: &mut vector + var $t3: u8 + var $t4: ascii::Char + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::pop_back($t2) + 3: $t4 := pack ascii::Char($t3) 4: return $t4 } [variant baseline] -public native fun vector::length<#0>($t0|v: &vector<#0>): u64; - - -[variant baseline] -public native fun vector::pop_back<#0>($t0|v: &mut vector<#0>): #0; +public fun ascii::push_char($t0|string: &mut ascii::String, $t1|char: ascii::Char) { + var $t2: &mut ascii::String + var $t3: &mut vector + var $t4: &ascii::Char + var $t5: &u8 + var $t6: u8 + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := borrow_local($t1) + 3: $t5 := borrow_field.byte($t4) + 4: $t6 := read_ref($t5) + 5: vector::push_back($t3, $t6) + 6: return () +} + + +[variant baseline] +public fun ascii::substring($t0|string: &ascii::String, $t1|i: u64, $t2|j: u64): ascii::String { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: vector + var $t5|i#1#3: u64 + var $t6|i#1#6: u64 + var $t7|stop#1#3: u64 + var $t8: u64 + var $t9: u64 + var $t10: bool + var $t11: u64 + var $t12: &ascii::String + var $t13: u64 + var $t14: bool + var $t15: bool + var $t16: bool + var $t17: &ascii::String + var $t18: u64 + var $t19: vector + var $t20: u64 + var $t21: u64 + var $t22: u64 + var $t23: u64 + var $t24: bool + var $t25: u64 + var $t26: &mut vector + var $t27: &ascii::String + var $t28: &vector + var $t29: u64 + var $t30: &u8 + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &ascii::String + var $t36: vector + var $t37: ascii::String + 0: $t8 := copy($t1) + 1: $t9 := copy($t2) + 2: $t10 := <=($t8, $t9) + 3: if ($t10) goto 4 else goto 11 + 4: label L1 + 5: $t11 := copy($t2) + 6: $t12 := copy($t0) + 7: $t13 := ascii::length($t12) + 8: $t14 := <=($t11, $t13) + 9: $t3 := $t14 + 10: goto 15 + 11: label L0 + 12: $t15 := false + 13: $t3 := $t15 + 14: goto 15 + 15: label L2 + 16: $t16 := move($t3) + 17: if ($t16) goto 18 else goto 20 + 18: label L4 + 19: goto 25 + 20: label L3 + 21: $t17 := move($t0) + 22: destroy($t17) + 23: $t18 := 65537 + 24: abort($t18) + 25: label L5 + 26: $t19 := [] + 27: $t4 := $t19 + 28: $t20 := move($t1) + 29: $t5 := $t20 + 30: $t21 := move($t2) + 31: $t7 := $t21 + 32: goto 33 + 33: label L8 + 34: $t22 := copy($t5) + 35: $t23 := copy($t7) + 36: $t24 := <($t22, $t23) + 37: if ($t24) goto 38 else goto 53 + 38: label L7 + 39: $t25 := copy($t5) + 40: $t6 := $t25 + 41: $t26 := borrow_local($t4) + 42: $t27 := copy($t0) + 43: $t28 := borrow_field.bytes($t27) + 44: $t29 := move($t6) + 45: $t30 := vector::borrow($t28, $t29) + 46: $t31 := read_ref($t30) + 47: vector::push_back($t26, $t31) + 48: $t32 := move($t5) + 49: $t33 := 1 + 50: $t34 := +($t32, $t33) + 51: $t5 := $t34 + 52: goto 33 + 53: label L6 + 54: $t35 := move($t0) + 55: destroy($t35) + 56: $t36 := move($t4) + 57: $t37 := pack ascii::String($t36) + 58: return $t37 +} + + +[variant baseline] +public fun ascii::to_lowercase($t0|string: &ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: &u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: &vector + var $t10|v#1#3: &vector + var $t11: &ascii::String + var $t12: &vector + var $t13: vector + var $t14: &vector + var $t15: &vector + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: bool + var $t22: u64 + var $t23: &vector + var $t24: u64 + var $t25: &u8 + var $t26: &mut vector + var $t27: &u8 + var $t28: u8 + var $t29: u8 + var $t30: &mut vector + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &vector + var $t36: vector + var $t37: ascii::String + 0: $t11 := move($t0) + 1: $t12 := ascii::as_bytes($t11) + 2: $t9 := $t12 + 3: $t13 := [] + 4: $t7 := $t13 + 5: $t14 := move($t9) + 6: $t10 := $t14 + 7: $t15 := copy($t10) + 8: $t16 := vector::length($t15) + 9: $t1 := $t16 + 10: $t17 := 0 + 11: $t6 := $t17 + 12: $t18 := move($t1) + 13: $t8 := $t18 + 14: goto 15 + 15: label L2 + 16: $t19 := copy($t6) + 17: $t20 := copy($t8) + 18: $t21 := <($t19, $t20) + 19: if ($t21) goto 20 else goto 41 + 20: label L1 + 21: $t22 := copy($t6) + 22: $t5 := $t22 + 23: $t23 := copy($t10) + 24: $t24 := move($t5) + 25: $t25 := vector::borrow($t23, $t24) + 26: $t4 := $t25 + 27: $t26 := borrow_local($t7) + 28: $t3 := $t26 + 29: $t27 := move($t4) + 30: $t28 := read_ref($t27) + 31: $t29 := ascii::char_to_lowercase($t28) + 32: $t2 := $t29 + 33: $t30 := move($t3) + 34: $t31 := move($t2) + 35: vector::push_back($t30, $t31) + 36: $t32 := move($t6) + 37: $t33 := 1 + 38: $t34 := +($t32, $t33) + 39: $t6 := $t34 + 40: goto 15 + 41: label L0 + 42: $t35 := move($t10) + 43: destroy($t35) + 44: $t36 := move($t7) + 45: $t37 := pack ascii::String($t36) + 46: return $t37 +} [variant baseline] -public native fun vector::push_back<#0>($t0|v: &mut vector<#0>, $t1|e: #0); +public fun ascii::to_uppercase($t0|string: &ascii::String): ascii::String { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: u8 + var $t3|tmp#$3: &mut vector + var $t4|e#1#13: &u8 + var $t5|i#1#12: u64 + var $t6|i#1#9: u64 + var $t7|r#1#1: vector + var $t8|stop#1#9: u64 + var $t9|v#1#1: &vector + var $t10|v#1#3: &vector + var $t11: &ascii::String + var $t12: &vector + var $t13: vector + var $t14: &vector + var $t15: &vector + var $t16: u64 + var $t17: u64 + var $t18: u64 + var $t19: u64 + var $t20: u64 + var $t21: bool + var $t22: u64 + var $t23: &vector + var $t24: u64 + var $t25: &u8 + var $t26: &mut vector + var $t27: &u8 + var $t28: u8 + var $t29: u8 + var $t30: &mut vector + var $t31: u8 + var $t32: u64 + var $t33: u64 + var $t34: u64 + var $t35: &vector + var $t36: vector + var $t37: ascii::String + 0: $t11 := move($t0) + 1: $t12 := ascii::as_bytes($t11) + 2: $t9 := $t12 + 3: $t13 := [] + 4: $t7 := $t13 + 5: $t14 := move($t9) + 6: $t10 := $t14 + 7: $t15 := copy($t10) + 8: $t16 := vector::length($t15) + 9: $t1 := $t16 + 10: $t17 := 0 + 11: $t6 := $t17 + 12: $t18 := move($t1) + 13: $t8 := $t18 + 14: goto 15 + 15: label L2 + 16: $t19 := copy($t6) + 17: $t20 := copy($t8) + 18: $t21 := <($t19, $t20) + 19: if ($t21) goto 20 else goto 41 + 20: label L1 + 21: $t22 := copy($t6) + 22: $t5 := $t22 + 23: $t23 := copy($t10) + 24: $t24 := move($t5) + 25: $t25 := vector::borrow($t23, $t24) + 26: $t4 := $t25 + 27: $t26 := borrow_local($t7) + 28: $t3 := $t26 + 29: $t27 := move($t4) + 30: $t28 := read_ref($t27) + 31: $t29 := ascii::char_to_uppercase($t28) + 32: $t2 := $t29 + 33: $t30 := move($t3) + 34: $t31 := move($t2) + 35: vector::push_back($t30, $t31) + 36: $t32 := move($t6) + 37: $t33 := 1 + 38: $t34 := +($t32, $t33) + 39: $t6 := $t34 + 40: goto 15 + 41: label L0 + 42: $t35 := move($t10) + 43: destroy($t35) + 44: $t36 := move($t7) + 45: $t37 := pack ascii::String($t36) + 46: return $t37 +} [variant baseline] -public fun vector::remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { - var $t2|tmp#$2: u64 - var $t3|tmp#$3: &mut vector<#0> - var $t4|len#1#0: u64 - var $t5: &mut vector<#0> - var $t6: &vector<#0> - var $t7: u64 - var $t8: u64 - var $t9: u64 - var $t10: bool - var $t11: &mut vector<#0> +public fun ascii::try_string($t0|bytes: vector): option::Option { + var $t1|$stop#0#6: u64 + var $t2|tmp#$2: bool + var $t3|tmp#$3: option::Option + var $t4|i#1#12: u64 + var $t5|i#1#9: u64 + var $t6|stop#1#9: u64 + var $t7|v#1#3: &vector + var $t8: &vector + var $t9: &vector + var $t10: u64 + var $t11: u64 var $t12: u64 var $t13: u64 var $t14: u64 - var $t15: u64 + var $t15: bool var $t16: u64 - var $t17: u64 - var $t18: bool - var $t19: &mut vector<#0> - var $t20: u64 - var $t21: u64 - var $t22: u64 - var $t23: u64 - var $t24: &mut vector<#0> + var $t17: &vector + var $t18: u64 + var $t19: &u8 + var $t20: u8 + var $t21: bool + var $t22: bool + var $t23: &vector + var $t24: bool var $t25: u64 var $t26: u64 - var $t27: &mut vector<#0> - var $t28: #0 - 0: $t5 := copy($t0) - 1: $t6 := freeze_ref($t5) - 2: $t7 := vector::length<#0>($t6) - 3: $t4 := $t7 - 4: $t8 := copy($t1) - 5: $t9 := copy($t4) - 6: $t10 := >=($t8, $t9) - 7: if ($t10) goto 8 else goto 13 - 8: label L1 - 9: $t11 := move($t0) - 10: destroy($t11) - 11: $t12 := 131072 - 12: abort($t12) - 13: label L0 - 14: $t13 := move($t4) - 15: $t14 := 1 - 16: $t15 := -($t13, $t14) - 17: $t4 := $t15 - 18: goto 19 - 19: label L5 - 20: $t16 := copy($t1) - 21: $t17 := copy($t4) - 22: $t18 := <($t16, $t17) - 23: if ($t18) goto 24 else goto 40 - 24: label L3 - 25: goto 26 - 26: label L4 - 27: $t19 := copy($t0) - 28: $t3 := $t19 - 29: $t20 := copy($t1) - 30: $t2 := $t20 - 31: $t21 := move($t1) - 32: $t22 := 1 - 33: $t23 := +($t21, $t22) - 34: $t1 := $t23 - 35: $t24 := move($t3) - 36: $t25 := move($t2) - 37: $t26 := copy($t1) - 38: vector::swap<#0>($t24, $t25, $t26) - 39: goto 19 - 40: label L2 - 41: $t27 := move($t0) - 42: $t28 := vector::pop_back<#0>($t27) - 43: return $t28 + var $t27: u64 + var $t28: &vector + var $t29: bool + var $t30: bool + var $t31: vector + var $t32: ascii::String + var $t33: option::Option + var $t34: option::Option + var $t35: option::Option + 0: $t8 := borrow_local($t0) + 1: $t7 := $t8 + 2: $t9 := copy($t7) + 3: $t10 := vector::length($t9) + 4: $t1 := $t10 + 5: $t11 := 0 + 6: $t5 := $t11 + 7: $t12 := move($t1) + 8: $t6 := $t12 + 9: goto 10 + 10: label L5 + 11: $t13 := copy($t5) + 12: $t14 := copy($t6) + 13: $t15 := <($t13, $t14) + 14: if ($t15) goto 15 else goto 37 + 15: label L1 + 16: $t16 := copy($t5) + 17: $t4 := $t16 + 18: $t17 := copy($t7) + 19: $t18 := move($t4) + 20: $t19 := vector::borrow($t17, $t18) + 21: $t20 := read_ref($t19) + 22: $t21 := ascii::is_valid_char($t20) + 23: $t22 := !($t21) + 24: if ($t22) goto 25 else goto 31 + 25: label L3 + 26: $t23 := move($t7) + 27: destroy($t23) + 28: $t24 := false + 29: $t2 := $t24 + 30: goto 43 + 31: label L2 + 32: $t25 := move($t5) + 33: $t26 := 1 + 34: $t27 := +($t25, $t26) + 35: $t5 := $t27 + 36: goto 10 + 37: label L0 + 38: $t28 := move($t7) + 39: destroy($t28) + 40: $t29 := true + 41: $t2 := $t29 + 42: goto 43 + 43: label L4 + 44: $t30 := move($t2) + 45: if ($t30) goto 46 else goto 52 + 46: label L7 + 47: $t31 := move($t0) + 48: $t32 := pack ascii::String($t31) + 49: $t33 := option::some($t32) + 50: $t3 := $t33 + 51: goto 56 + 52: label L6 + 53: $t34 := option::none() + 54: $t3 := $t34 + 55: goto 56 + 56: label L8 + 57: $t35 := move($t3) + 58: return $t35 } [variant baseline] -public fun vector::reverse<#0>($t0|v: &mut vector<#0>) { - var $t1|back_index#1#0: u64 - var $t2|front_index#1#0: u64 - var $t3|len#1#0: u64 - var $t4: &mut vector<#0> - var $t5: &vector<#0> +public fun string::append($t0|s: &mut string::String, $t1|r: string::String) { + var $t2: &mut string::String + var $t3: &mut vector + var $t4: &string::String + var $t5: &vector + var $t6: vector + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := borrow_local($t1) + 3: $t5 := borrow_field.bytes($t4) + 4: $t6 := read_ref($t5) + 5: vector::append($t3, $t6) + 6: return () +} + + +[variant baseline] +public fun string::index_of($t0|s: &string::String, $t1|r: &string::String): u64 { + var $t2: &string::String + var $t3: &vector + var $t4: &string::String + var $t5: &vector var $t6: u64 - var $t7: u64 - var $t8: u64 - var $t9: bool - var $t10: &mut vector<#0> - var $t11: u64 + 0: $t2 := move($t0) + 1: $t3 := borrow_field.bytes($t2) + 2: $t4 := move($t1) + 3: $t5 := borrow_field.bytes($t4) + 4: $t6 := string::internal_index_of($t3, $t5) + 5: return $t6 +} + + +[variant baseline] +public fun string::insert($t0|s: &mut string::String, $t1|at: u64, $t2|o: string::String) { + var $t3|tmp#$3: bool + var $t4|bytes#1#0: &vector + var $t5|end#1#0: string::String + var $t6|front#1#0: string::String + var $t7|l#1#0: u64 + var $t8: &mut string::String + var $t9: &vector + var $t10: u64 + var $t11: &vector var $t12: u64 - var $t13: u64 - var $t14: u64 + var $t13: bool + var $t14: &vector var $t15: u64 - var $t16: u64 - var $t17: bool - var $t18: &mut vector<#0> - var $t19: u64 - var $t20: u64 + var $t16: bool + var $t17: &vector + var $t18: bool + var $t19: bool + var $t20: &mut string::String var $t21: u64 - var $t22: u64 - var $t23: u64 + var $t22: &mut string::String + var $t23: &string::String var $t24: u64 - var $t25: u64 - var $t26: u64 - var $t27: &mut vector<#0> - 0: $t4 := copy($t0) - 1: $t5 := freeze_ref($t4) - 2: $t6 := vector::length<#0>($t5) - 3: $t3 := $t6 - 4: $t7 := copy($t3) - 5: $t8 := 0 - 6: $t9 := ==($t7, $t8) - 7: if ($t9) goto 8 else goto 12 + var $t25: &mut string::String + var $t26: &string::String + var $t27: u64 + var $t28: u64 + var $t29: string::String + var $t30: &mut string::String + var $t31: &string::String + var $t32: u64 + var $t33: u64 + var $t34: string::String + var $t35: &mut string::String + var $t36: string::String + var $t37: &mut string::String + var $t38: string::String + var $t39: string::String + var $t40: &mut string::String + 0: $t8 := copy($t0) + 1: $t9 := borrow_field.bytes($t8) + 2: $t4 := $t9 + 3: $t10 := copy($t1) + 4: $t11 := copy($t4) + 5: $t12 := vector::length($t11) + 6: $t13 := <=($t10, $t12) + 7: if ($t13) goto 8 else goto 14 8: label L1 - 9: $t10 := move($t0) - 10: destroy($t10) - 11: return () - 12: label L0 - 13: $t11 := 0 - 14: $t2 := $t11 - 15: $t12 := move($t3) - 16: $t13 := 1 - 17: $t14 := -($t12, $t13) - 18: $t1 := $t14 + 9: $t14 := move($t4) + 10: $t15 := copy($t1) + 11: $t16 := string::internal_is_char_boundary($t14, $t15) + 12: $t3 := $t16 + 13: goto 20 + 14: label L0 + 15: $t17 := move($t4) + 16: destroy($t17) + 17: $t18 := false + 18: $t3 := $t18 19: goto 20 - 20: label L5 - 21: $t15 := copy($t2) - 22: $t16 := copy($t1) - 23: $t17 := <($t15, $t16) - 24: if ($t17) goto 25 else goto 41 + 20: label L2 + 21: $t19 := move($t3) + 22: if ($t19) goto 23 else goto 25 + 23: label L4 + 24: goto 30 25: label L3 - 26: goto 27 - 27: label L4 - 28: $t18 := copy($t0) - 29: $t19 := copy($t2) - 30: $t20 := copy($t1) - 31: vector::swap<#0>($t18, $t19, $t20) - 32: $t21 := move($t2) - 33: $t22 := 1 - 34: $t23 := +($t21, $t22) - 35: $t2 := $t23 - 36: $t24 := move($t1) - 37: $t25 := 1 - 38: $t26 := -($t24, $t25) - 39: $t1 := $t26 - 40: goto 20 - 41: label L2 - 42: $t27 := move($t0) - 43: destroy($t27) - 44: return () + 26: $t20 := move($t0) + 27: destroy($t20) + 28: $t21 := 2 + 29: abort($t21) + 30: label L5 + 31: $t22 := copy($t0) + 32: $t23 := freeze_ref($t22) + 33: $t24 := string::length($t23) + 34: $t7 := $t24 + 35: $t25 := copy($t0) + 36: $t26 := freeze_ref($t25) + 37: $t27 := 0 + 38: $t28 := copy($t1) + 39: $t29 := string::substring($t26, $t27, $t28) + 40: $t6 := $t29 + 41: $t30 := copy($t0) + 42: $t31 := freeze_ref($t30) + 43: $t32 := move($t1) + 44: $t33 := move($t7) + 45: $t34 := string::substring($t31, $t32, $t33) + 46: $t5 := $t34 + 47: $t35 := borrow_local($t6) + 48: $t36 := move($t2) + 49: string::append($t35, $t36) + 50: $t37 := borrow_local($t6) + 51: $t38 := move($t5) + 52: string::append($t37, $t38) + 53: $t39 := move($t6) + 54: $t40 := move($t0) + 55: write_ref($t40, $t39) + 56: return () } [variant baseline] -public fun vector::singleton<#0>($t0|e: #0): vector<#0> { - var $t1|v#1#0: vector<#0> - var $t2: vector<#0> - var $t3: &mut vector<#0> - var $t4: #0 - var $t5: vector<#0> - 0: $t2 := vector::empty<#0>() - 1: $t1 := $t2 - 2: $t3 := borrow_local($t1) - 3: $t4 := move($t0) - 4: vector::push_back<#0>($t3, $t4) - 5: $t5 := move($t1) - 6: return $t5 +public fun string::is_empty($t0|s: &string::String): bool { + var $t1: &string::String + var $t2: &vector + var $t3: bool + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::is_empty($t2) + 3: return $t3 } [variant baseline] -public native fun vector::swap<#0>($t0|v: &mut vector<#0>, $t1|i: u64, $t2|j: u64); +public fun string::length($t0|s: &string::String): u64 { + var $t1: &string::String + var $t2: &vector + var $t3: u64 + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: $t3 := vector::length($t2) + 3: return $t3 +} [variant baseline] -public fun vector::swap_remove<#0>($t0|v: &mut vector<#0>, $t1|i: u64): #0 { - var $t2|last_idx#1#0: u64 - var $t3: &mut vector<#0> - var $t4: &vector<#0> - var $t5: bool - var $t6: bool - var $t7: &mut vector<#0> - var $t8: u64 - var $t9: &mut vector<#0> - var $t10: &vector<#0> +public fun string::as_bytes($t0|s: &string::String): &vector { + var $t1: &string::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := borrow_field.bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::into_bytes($t0|s: string::String): vector { + var $t1: string::String + var $t2: vector + 0: $t1 := move($t0) + 1: $t2 := unpack string::String($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::bytes($t0|s: &string::String): &vector { + var $t1: &string::String + var $t2: &vector + 0: $t1 := move($t0) + 1: $t2 := string::as_bytes($t1) + 2: return $t2 +} + + +[variant baseline] +public fun string::substring($t0|s: &string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3|tmp#$3: bool + var $t4|tmp#$4: bool + var $t5|tmp#$5: bool + var $t6|bytes#1#0: &vector + var $t7|l#1#0: u64 + var $t8: &string::String + var $t9: &vector + var $t10: &vector var $t11: u64 var $t12: u64 var $t13: u64 - var $t14: &mut vector<#0> + var $t14: bool var $t15: u64 var $t16: u64 - var $t17: &mut vector<#0> - var $t18: #0 - 0: $t3 := copy($t0) - 1: $t4 := freeze_ref($t3) - 2: $t5 := vector::is_empty<#0>($t4) - 3: $t6 := !($t5) - 4: if ($t6) goto 5 else goto 7 - 5: label L1 - 6: goto 12 - 7: label L0 - 8: $t7 := move($t0) - 9: destroy($t7) - 10: $t8 := 131072 - 11: abort($t8) - 12: label L2 - 13: $t9 := copy($t0) - 14: $t10 := freeze_ref($t9) - 15: $t11 := vector::length<#0>($t10) - 16: $t12 := 1 - 17: $t13 := -($t11, $t12) - 18: $t2 := $t13 - 19: $t14 := copy($t0) - 20: $t15 := move($t1) - 21: $t16 := move($t2) - 22: vector::swap<#0>($t14, $t15, $t16) - 23: $t17 := move($t0) - 24: $t18 := vector::pop_back<#0>($t17) - 25: return $t18 + var $t17: bool + var $t18: bool + var $t19: bool + var $t20: &vector + var $t21: u64 + var $t22: bool + var $t23: bool + var $t24: bool + var $t25: &vector + var $t26: u64 + var $t27: bool + var $t28: bool + var $t29: bool + var $t30: &vector + var $t31: u64 + var $t32: &vector + var $t33: u64 + var $t34: u64 + var $t35: vector + var $t36: string::String + 0: $t8 := move($t0) + 1: $t9 := borrow_field.bytes($t8) + 2: $t6 := $t9 + 3: $t10 := copy($t6) + 4: $t11 := vector::length($t10) + 5: $t7 := $t11 + 6: $t12 := copy($t2) + 7: $t13 := move($t7) + 8: $t14 := <=($t12, $t13) + 9: if ($t14) goto 10 else goto 16 + 10: label L1 + 11: $t15 := copy($t1) + 12: $t16 := copy($t2) + 13: $t17 := <=($t15, $t16) + 14: $t3 := $t17 + 15: goto 20 + 16: label L0 + 17: $t18 := false + 18: $t3 := $t18 + 19: goto 20 + 20: label L2 + 21: $t19 := move($t3) + 22: if ($t19) goto 23 else goto 29 + 23: label L4 + 24: $t20 := copy($t6) + 25: $t21 := copy($t1) + 26: $t22 := string::internal_is_char_boundary($t20, $t21) + 27: $t4 := $t22 + 28: goto 33 + 29: label L3 + 30: $t23 := false + 31: $t4 := $t23 + 32: goto 33 + 33: label L5 + 34: $t24 := move($t4) + 35: if ($t24) goto 36 else goto 42 + 36: label L7 + 37: $t25 := copy($t6) + 38: $t26 := copy($t2) + 39: $t27 := string::internal_is_char_boundary($t25, $t26) + 40: $t5 := $t27 + 41: goto 46 + 42: label L6 + 43: $t28 := false + 44: $t5 := $t28 + 45: goto 46 + 46: label L8 + 47: $t29 := move($t5) + 48: if ($t29) goto 49 else goto 51 + 49: label L10 + 50: goto 56 + 51: label L9 + 52: $t30 := move($t6) + 53: destroy($t30) + 54: $t31 := 2 + 55: abort($t31) + 56: label L11 + 57: $t32 := move($t6) + 58: $t33 := move($t1) + 59: $t34 := move($t2) + 60: $t35 := string::internal_sub_string($t32, $t33, $t34) + 61: $t36 := pack string::String($t35) + 62: return $t36 } [variant baseline] -fun ReturnRefsIntoVec::return_vec_index_immut($t0|v: &vector): &u64 { - var $t1: &vector - var $t2: u64 - var $t3: &u64 +public fun string::append_utf8($t0|s: &mut string::String, $t1|bytes: vector) { + var $t2: &mut string::String + var $t3: vector + var $t4: string::String + 0: $t2 := move($t0) + 1: $t3 := move($t1) + 2: $t4 := string::utf8($t3) + 3: string::append($t2, $t4) + 4: return () +} + + +[variant baseline] +public fun string::from_ascii($t0|s: ascii::String): string::String { + var $t1: ascii::String + var $t2: vector + var $t3: string::String 0: $t1 := move($t0) - 1: $t2 := 0 - 2: $t3 := vector::borrow($t1, $t2) + 1: $t2 := ascii::into_bytes($t1) + 2: $t3 := pack string::String($t2) 3: return $t3 } [variant baseline] -fun ReturnRefsIntoVec::return_vec_index_mut($t0|v: &mut vector): &mut u64 { - var $t1: &mut vector - var $t2: u64 - var $t3: &mut u64 +native fun string::internal_check_utf8($t0|v: &vector): bool; + + +[variant baseline] +native fun string::internal_index_of($t0|v: &vector, $t1|r: &vector): u64; + + +[variant baseline] +native fun string::internal_is_char_boundary($t0|v: &vector, $t1|i: u64): bool; + + +[variant baseline] +native fun string::internal_sub_string($t0|v: &vector, $t1|i: u64, $t2|j: u64): vector; + + +[variant baseline] +public fun string::sub_string($t0|s: &string::String, $t1|i: u64, $t2|j: u64): string::String { + var $t3: &string::String + var $t4: u64 + var $t5: u64 + var $t6: string::String + 0: $t3 := move($t0) + 1: $t4 := move($t1) + 2: $t5 := move($t2) + 3: $t6 := string::substring($t3, $t4, $t5) + 4: return $t6 +} + + +[variant baseline] +public fun string::to_ascii($t0|s: string::String): ascii::String { + var $t1: string::String + var $t2: vector + var $t3: ascii::String 0: $t1 := move($t0) - 1: $t2 := 0 - 2: $t3 := vector::borrow_mut($t1, $t2) + 1: $t2 := unpack string::String($t1) + 2: $t3 := ascii::string($t2) 3: return $t3 } + + +[variant baseline] +public fun string::try_utf8($t0|bytes: vector): option::Option { + var $t1|tmp#$1: option::Option + var $t2: &vector + var $t3: bool + var $t4: vector + var $t5: string::String + var $t6: option::Option + var $t7: option::Option + var $t8: option::Option + 0: $t2 := borrow_local($t0) + 1: $t3 := string::internal_check_utf8($t2) + 2: if ($t3) goto 3 else goto 9 + 3: label L1 + 4: $t4 := move($t0) + 5: $t5 := pack string::String($t4) + 6: $t6 := option::some($t5) + 7: $t1 := $t6 + 8: goto 13 + 9: label L0 + 10: $t7 := option::none() + 11: $t1 := $t7 + 12: goto 13 + 13: label L2 + 14: $t8 := move($t1) + 15: return $t8 +} + + +[variant baseline] +public fun string::utf8($t0|bytes: vector): string::String { + var $t1: &vector + var $t2: bool + var $t3: u64 + var $t4: vector + var $t5: string::String + 0: $t1 := borrow_local($t0) + 1: $t2 := string::internal_check_utf8($t1) + 2: if ($t2) goto 3 else goto 5 + 3: label L1 + 4: goto 8 + 5: label L0 + 6: $t3 := 1 + 7: abort($t3) + 8: label L2 + 9: $t4 := move($t0) + 10: $t5 := pack string::String($t4) + 11: return $t5 +} diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_refs_into_vec.move b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_refs_into_vec.move index f6518eabc4402..7c6ac51c5377a 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_refs_into_vec.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/return_refs_into_vec.move @@ -1,7 +1,11 @@ +// dep: ../move-stdlib/sources/macros.move +// dep: ../move-stdlib/sources/u64.move +// dep: ../move-stdlib/sources/option.move +// dep: ../move-stdlib/sources/ascii.move +// dep: ../move-stdlib/sources/string.move // dep: ../move-stdlib/sources/vector.move module 0x1::ReturnRefsIntoVec { - use std::vector; // should not complain fun return_vec_index_immut(v: &vector): &u64 { diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/struct_eq.exp b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/struct_eq.exp index 5b40517253203..a54b79a43f823 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/struct_eq.exp +++ b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/struct_eq.exp @@ -39,10 +39,3 @@ public fun StructEq::new(): StructEq::S { 1: $t1 := pack StructEq::S($t0) 2: return $t1 } - -============ Diagnostics ================ -warning: DEPRECATED. will be removed - ┌─ tests/escape_analysis/struct_eq.move:5:5 - │ -5 │ invariant forall s: S: s == S { f: 10 }; - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Specification blocks are deprecated and are no longer used diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/struct_eq.move b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/struct_eq.move index 33b9ff48059ee..216c7b3074f1a 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/struct_eq.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/escape_analysis/struct_eq.move @@ -1,8 +1,6 @@ module 0x1::StructEq { - struct S { f: u64 } - - invariant forall s: S: s == S { f: 10 }; + public struct S { f: u64 } public fun new(): S { S { f: 10 } diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/from_move/smoke_test.exp b/external-crates/move/crates/move-stackless-bytecode/tests/from_move/smoke_test.exp index 7c4c9b025d777..5f67678cfb725 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/from_move/smoke_test.exp +++ b/external-crates/move/crates/move-stackless-bytecode/tests/from_move/smoke_test.exp @@ -1,21 +1,13 @@ ============ initial translation from Move ================ [variant baseline] -public fun signer::address_of($t0|s: &signer): address { - var $t1: &signer - var $t2: &address - var $t3: address - 0: $t1 := move($t0) - 1: $t2 := signer::borrow_address($t1) - 2: $t3 := read_ref($t2) - 3: return $t3 +public fun address::length(): u64 { + var $t0: u64 + 0: $t0 := 32 + 1: return $t0 } -[variant baseline] -public native fun signer::borrow_address($t0|s: &signer): &address; - - [variant baseline] fun SmokeTest::arithmetic_ops($t0|a: u64): (u64, u64) { var $t1|c#1#0: u64 diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/from_move/smoke_test.move b/external-crates/move/crates/move-stackless-bytecode/tests/from_move/smoke_test.move index 92acb6be19f0a..a4a211a59f280 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/from_move/smoke_test.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/from_move/smoke_test.move @@ -1,7 +1,7 @@ // This module contains just some arbitrary code to smoke test the basic functionality of translation from Move // to stackless bytecode. Coverage for byte code translation is achieved by many more tests in the prover. -// dep: ../move-stdlib/sources/signer.move +// dep: ../move-stdlib/sources/address.move module 0x42::SmokeTest { // ----------------- @@ -24,17 +24,17 @@ module 0x42::SmokeTest { (c, a) } - struct A { + public struct A { addr: address, val: u64, } - struct B { + public struct B { val: u64, a: A, } - struct C { + public struct C { val: u64, b: B, } diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/livevar/basic_test.move b/external-crates/move/crates/move-stackless-bytecode/tests/livevar/basic_test.move index 9f0c3f241ef16..5d3373fa01e66 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/livevar/basic_test.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/livevar/basic_test.move @@ -1,5 +1,5 @@ module 0x42::TestLiveVars { - struct R has copy, drop { + public struct R has copy, drop { x: u64 } @@ -11,14 +11,14 @@ module 0x42::TestLiveVars { fun test2(b: bool) : u64 { let r1 = R {x: 3}; let r2 = R {x: 4}; - let r_ref = &r1; + let mut r_ref = &r1; if (b) { r_ref = &r2; }; test1(r_ref) } - fun test3(n: u64, r_ref: &R) : u64 { + fun test3(mut n: u64, mut r_ref: &R) : u64 { let r1 = R {x: 3}; let r2 = R {x: 4}; while (0 < n) { diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/memory_instr/basic_test.move b/external-crates/move/crates/move-stackless-bytecode/tests/memory_instr/basic_test.move index bacf2b4f7fd61..2f85281358bc4 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/memory_instr/basic_test.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/memory_instr/basic_test.move @@ -1,10 +1,10 @@ module 0x42::TestPackref { - struct R has copy, drop { + public struct R has copy, drop { x: u64 } fun test1() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; let x_ref = &mut r_ref.x; *x_ref = 0; @@ -21,7 +21,7 @@ module 0x42::TestPackref { } fun test4() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; test3(r_ref, 0); r @@ -32,7 +32,7 @@ module 0x42::TestPackref { } fun test6() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; let x_ref = test5(r_ref); test2(x_ref, 0); @@ -40,19 +40,19 @@ module 0x42::TestPackref { } fun test7(b: bool) { - let r1 = R {x: 3}; - let r2 = R {x: 4}; - let r_ref = &mut r1; + let mut r1 = R {x: 3}; + let mut r2 = R {x: 4}; + let mut r_ref = &mut r1; if (b) { r_ref = &mut r2; }; test3(r_ref, 0) } - fun test8(b: bool, n: u64, r_ref: &mut R) { - let r1 = R {x: 3}; - let r2 = R {x: 4}; - let t_ref = &mut r2; + fun test8(b: bool, mut n: u64, r_ref: &mut R) { + let mut r1 = R {x: 3}; + let mut r2 = R {x: 4}; + let mut t_ref = &mut r2; while (0 < n) { if (n/2 == 0) { t_ref = &mut r1 diff --git a/external-crates/move/crates/move-stackless-bytecode/tests/mut_ref_instrumentation/basic_test.move b/external-crates/move/crates/move-stackless-bytecode/tests/mut_ref_instrumentation/basic_test.move index 5133d72e27845..62ce5ab86038f 100644 --- a/external-crates/move/crates/move-stackless-bytecode/tests/mut_ref_instrumentation/basic_test.move +++ b/external-crates/move/crates/move-stackless-bytecode/tests/mut_ref_instrumentation/basic_test.move @@ -1,11 +1,11 @@ module 0x42::TestEliminateMutRefs { - struct R has copy, drop { + public struct R has copy, drop { x: u64 } fun test1() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; let x_ref = &mut r_ref.x; *x_ref = 0; @@ -22,7 +22,7 @@ module 0x42::TestEliminateMutRefs { } fun test4() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; test3(r_ref, 0); r @@ -33,7 +33,7 @@ module 0x42::TestEliminateMutRefs { } fun test6() : R { - let r = R {x: 3}; + let mut r = R {x: 3}; let r_ref = &mut r; let x_ref = test5(r_ref); test2(x_ref, 0); @@ -41,19 +41,19 @@ module 0x42::TestEliminateMutRefs { } fun test7(b: bool) { - let r1 = R {x: 3}; - let r2 = R {x: 4}; - let r_ref = &mut r1; + let mut r1 = R {x: 3}; + let mut r2 = R {x: 4}; + let mut r_ref = &mut r1; if (b) { r_ref = &mut r2; }; test3(r_ref, 0) } - fun test8(b: bool, n: u64, r_ref: &mut R) { - let r1 = R {x: 3}; - let r2 = R {x: 4}; - let t_ref = &mut r2; + fun test8(b: bool, mut n: u64, r_ref: &mut R) { + let mut r1 = R {x: 3}; + let mut r2 = R {x: 4}; + let mut t_ref = &mut r2; while (0 < n) { if (n/2 == 0) { t_ref = &mut r1 diff --git a/external-crates/move/crates/move-stdlib-natives/src/lib.rs b/external-crates/move/crates/move-stdlib-natives/src/lib.rs index 0a49187cb9623..4859724018619 100644 --- a/external-crates/move/crates/move-stdlib-natives/src/lib.rs +++ b/external-crates/move/crates/move-stdlib-natives/src/lib.rs @@ -20,6 +20,7 @@ use move_vm_runtime::native_functions::{make_table_from_iter, NativeFunctionTabl #[derive(Debug, Clone)] pub struct GasParameters { pub bcs: bcs::GasParameters, + pub debug: debug::GasParameters, pub hash: hash::GasParameters, pub signer: signer::GasParameters, pub string: string::GasParameters, @@ -40,7 +41,14 @@ impl GasParameters { failure: 0.into(), }, }, - + debug: debug::GasParameters { + print: debug::PrintGasParameters { + base_cost: 0.into(), + }, + print_stack_trace: debug::PrintStackTraceGasParameters { + base_cost: 0.into(), + }, + }, hash: hash::GasParameters { sha2_256: hash::Sha2_256GasParameters { base: 0.into(), @@ -102,49 +110,32 @@ impl GasParameters { }, } } -} - -pub fn all_natives( - move_std_addr: AccountAddress, - gas_params: GasParameters, -) -> NativeFunctionTable { - let mut natives = vec![]; - macro_rules! add_natives { - ($module_name: expr, $natives: expr) => { - natives.extend( - $natives.map(|(func_name, func)| ($module_name.to_string(), func_name, func)), - ); - }; - } - - add_natives!("bcs", bcs::make_all(gas_params.bcs)); - add_natives!("hash", hash::make_all(gas_params.hash)); - add_natives!("signer", signer::make_all(gas_params.signer)); - add_natives!("string", string::make_all(gas_params.string)); - add_natives!("type_name", type_name::make_all(gas_params.type_name)); - add_natives!("vector", vector::make_all(gas_params.vector)); - #[cfg(feature = "testing")] - { - add_natives!("unit_test", unit_test::make_all(gas_params.unit_test)); - } - - make_table_from_iter(move_std_addr, natives) -} - -#[derive(Debug, Clone)] -pub struct NurseryGasParameters { - debug: debug::GasParameters, -} - -impl NurseryGasParameters { - pub fn zeros() -> Self { + pub fn new( + bcs: bcs::GasParameters, + debug: debug::GasParameters, + hash: hash::GasParameters, + string: string::GasParameters, + type_name: type_name::GasParameters, + vector: vector::GasParameters, + ) -> Self { Self { - debug: debug::GasParameters { - print: debug::PrintGasParameters { + bcs, + debug, + hash, + string, + type_name, + vector, + signer: signer::GasParameters { + borrow_address: signer::BorrowAddressGasParameters { base: 0.into() }, + }, + #[cfg(feature = "testing")] + unit_test: unit_test::GasParameters { + create_signers_for_testing: unit_test::CreateSignersForTestingGasParameters { base_cost: 0.into(), + unit_cost: 0.into(), }, - print_stack_trace: debug::PrintStackTraceGasParameters { + poison: unit_test::PoisonGasParameters { base_cost: 0.into(), }, }, @@ -152,10 +143,10 @@ impl NurseryGasParameters { } } -pub fn nursery_natives( - silent: bool, +pub fn all_natives( move_std_addr: AccountAddress, - gas_params: NurseryGasParameters, + gas_params: GasParameters, + debug_is_silent: bool, ) -> NativeFunctionTable { let mut natives = vec![]; @@ -167,10 +158,20 @@ pub fn nursery_natives( }; } + add_natives!("bcs", bcs::make_all(gas_params.bcs)); + add_natives!("hash", hash::make_all(gas_params.hash)); + add_natives!("signer", signer::make_all(gas_params.signer)); + add_natives!("string", string::make_all(gas_params.string)); + add_natives!("type_name", type_name::make_all(gas_params.type_name)); + add_natives!("vector", vector::make_all(gas_params.vector)); add_natives!( "debug", - debug::make_all(silent, gas_params.debug, move_std_addr) + debug::make_all(debug_is_silent, gas_params.debug, move_std_addr) ); + #[cfg(feature = "testing")] + { + add_natives!("unit_test", unit_test::make_all(gas_params.unit_test)); + } make_table_from_iter(move_std_addr, natives) } diff --git a/external-crates/move/crates/move-stdlib/Move.toml b/external-crates/move/crates/move-stdlib/Move.toml index 8ea2f565bf829..43c2eb345a90b 100644 --- a/external-crates/move/crates/move-stdlib/Move.toml +++ b/external-crates/move/crates/move-stdlib/Move.toml @@ -1,5 +1,6 @@ [package] name = "MoveStdlib" +edition = "2024.beta" [addresses] std = "_" diff --git a/external-crates/move/crates/move-stdlib/docs/address.md b/external-crates/move/crates/move-stdlib/docs/address.md new file mode 100644 index 0000000000000..830fada18e886 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/docs/address.md @@ -0,0 +1,44 @@ + + + +# Module `0x1::address` + +Provides a way to get address length since it's a +platform-specific parameter. + + +- [Function `length`](#0x1_address_length) + + +
+ + + + + +## Function `length` + +Should be converted to a native function. +Current implementation only works for Sui. + + +
public fun length(): u64
+
+ + + +
+Implementation + + +
public fun length(): u64 {
+    32
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/ascii.md b/external-crates/move/crates/move-stdlib/docs/ascii.md index 5430a4e361c65..92cb66877a162 100644 --- a/external-crates/move/crates/move-stdlib/docs/ascii.md +++ b/external-crates/move/crates/move-stdlib/docs/ascii.md @@ -17,14 +17,24 @@ that characters are valid ASCII, and that strings consist of only valid ASCII ch - [Function `push_char`](#0x1_ascii_push_char) - [Function `pop_char`](#0x1_ascii_pop_char) - [Function `length`](#0x1_ascii_length) +- [Function `append`](#0x1_ascii_append) +- [Function `insert`](#0x1_ascii_insert) +- [Function `substring`](#0x1_ascii_substring) - [Function `as_bytes`](#0x1_ascii_as_bytes) - [Function `into_bytes`](#0x1_ascii_into_bytes) - [Function `byte`](#0x1_ascii_byte) - [Function `is_valid_char`](#0x1_ascii_is_valid_char) - [Function `is_printable_char`](#0x1_ascii_is_printable_char) +- [Function `is_empty`](#0x1_ascii_is_empty) +- [Function `to_uppercase`](#0x1_ascii_to_uppercase) +- [Function `to_lowercase`](#0x1_ascii_to_lowercase) +- [Function `index_of`](#0x1_ascii_index_of) +- [Function `char_to_uppercase`](#0x1_ascii_char_to_uppercase) +- [Function `char_to_lowercase`](#0x1_ascii_char_to_lowercase)
use 0x1::option;
+use 0x1::vector;
 
@@ -51,7 +61,7 @@ defined in this module.
-bytes: vector<u8> +bytes: vector<u8>
@@ -79,7 +89,7 @@ An ASCII character.
-byte: u8 +byte: u8
@@ -94,12 +104,22 @@ An ASCII character. ## Constants - + An invalid ASCII character was encountered when creating an ASCII string. -
const EINVALID_ASCII_CHARACTER: u64 = 65536;
+
const EInvalidASCIICharacter: u64 = 65536;
+
+ + + + + +An invalid index was encountered when creating a substring. + + +
const EInvalidIndex: u64 = 65537;
 
@@ -111,7 +131,7 @@ An invalid ASCII character was encountered when creating an ASCII string. Convert a byte into a Char that is checked to make sure it is valid ASCII. -
public fun char(byte: u8): ascii::Char
+
public fun char(byte: u8): ascii::Char
 
@@ -120,8 +140,8 @@ Convert a byte into a Char< Implementation -
public fun char(byte: u8): Char {
-    assert!(is_valid_char(byte), EINVALID_ASCII_CHARACTER);
+
public fun char(byte: u8): Char {
+    assert!(is_valid_char(byte), EInvalidASCIICharacter);
     Char { byte }
 }
 
@@ -138,7 +158,7 @@ Convert a vector of bytes bytes into an string(bytes: vector<u8>): ascii::String +
public fun string(bytes: vector<u8>): ascii::String
 
@@ -147,13 +167,10 @@ Convert a vector of bytes bytes into an string(bytes: vector<u8>): String { - let x = try_string(bytes); - assert!( - option::is_some(&x), - EINVALID_ASCII_CHARACTER - ); - option::destroy_some(x) +
public fun string(bytes: vector<u8>): String {
+    let x = try_string(bytes);
+    assert!(x.is_some(), EInvalidASCIICharacter);
+    x.destroy_some()
 }
 
@@ -170,7 +187,7 @@ Convert a vector of bytes bytes into an try_string(bytes: vector<u8>): option::Option<ascii::String> +
public fun try_string(bytes: vector<u8>): option::Option<ascii::String>
 
@@ -179,15 +196,10 @@ characters. Otherwise returns None. Implementation -
public fun try_string(bytes: vector<u8>): Option<String> {
-    let len = vector::length(&bytes);
-    let i = 0;
-    while (i < len) {
-        let possible_byte = *vector::borrow(&bytes, i);
-        if (!is_valid_char(possible_byte)) return option::none();
-        i = i + 1;
-    };
-    option::some(String { bytes })
+
public fun try_string(bytes: vector<u8>): Option<String> {
+    let is_valid = bytes.all!(|byte| is_valid_char(*byte));
+    if (is_valid) option::some(String { bytes })
+    else option::none()
 }
 
@@ -213,14 +225,7 @@ Returns false otherwise. Not all all_characters_printable(string: &String): bool { - let len = vector::length(&string.bytes); - let i = 0; - while (i < len) { - let byte = *vector::borrow(&string.bytes, i); - if (!is_printable_char(byte)) return false; - i = i + 1; - }; - true + string.bytes.all!(|byte| is_printable_char(*byte)) }
@@ -232,6 +237,7 @@ Returns false otherwise. Not all Char to the end of the string.
public fun push_char(string: &mut ascii::String, char: ascii::Char)
@@ -244,7 +250,7 @@ Returns false otherwise. Not all push_char(string: &mut String, char: Char) {
-    vector::push_back(&mut string.bytes, char.byte);
+    string.bytes.push_back(char.byte);
 }
 
@@ -256,6 +262,7 @@ Returns false otherwise. Not all Char from the end of the string.
public fun pop_char(string: &mut ascii::String): ascii::Char
@@ -268,7 +275,7 @@ Returns false otherwise. Not all pop_char(string: &mut String): Char {
-    Char { byte: vector::pop_back(&mut string.bytes) }
+    Char { byte: string.bytes.pop_back() }
 }
 
@@ -280,9 +287,60 @@ Returns false otherwise. Not all string in bytes. + + +
public fun length(string: &ascii::String): u64
+
+ + + +
+Implementation + + +
public fun length(string: &String): u64 {
+    string.as_bytes().length()
+}
+
+ + + +
+ + + +## Function `append` + +Append the other string to the end of string. + + +
public fun append(string: &mut ascii::String, other: ascii::String)
+
+ + + +
+Implementation + + +
public fun append(string: &mut String, other: String) {
+    string.bytes.append(other.into_bytes())
+}
+
+ + + +
+ + + +## Function `insert` + +Insert the other string at the at index of string. -
public fun length(string: &ascii::String): u64
+
public fun insert(s: &mut ascii::String, at: u64, o: ascii::String)
 
@@ -291,8 +349,37 @@ Returns false otherwise. Not all length(string: &String): u64 { - vector::length(as_bytes(string)) +
public fun insert(s: &mut String, at: u64, o: String) {
+    assert!(at <= s.length(), EInvalidIndex);
+    o.into_bytes().destroy!(|e| s.bytes.insert(e, at));
+}
+
+ + + + + + + +## Function `substring` + +Copy the slice of the string from i to j into a new String. + + +
public fun substring(string: &ascii::String, i: u64, j: u64): ascii::String
+
+ + + +
+Implementation + + +
public fun substring(string: &String, i: u64, j: u64): String {
+    assert!(i <= j && j <= string.length(), EInvalidIndex);
+    let mut bytes = vector[];
+    i.range_do!(j, |i| bytes.push_back(string.bytes[i]));
+    String { bytes }
 }
 
@@ -307,7 +394,7 @@ Returns false otherwise. Not all string as a reference -
public fun as_bytes(string: &ascii::String): &vector<u8>
+
public fun as_bytes(string: &ascii::String): &vector<u8>
 
@@ -316,8 +403,8 @@ Get the inner bytes of the stringImplementation -
public fun as_bytes(string: &String): &vector<u8> {
-   &string.bytes
+
public fun as_bytes(string: &String): &vector<u8> {
+    &string.bytes
 }
 
@@ -332,7 +419,7 @@ Get the inner bytes of the stringstring
to get its backing bytes -
public fun into_bytes(string: ascii::String): vector<u8>
+
public fun into_bytes(string: ascii::String): vector<u8>
 
@@ -341,9 +428,9 @@ Unpack the string to get its bac Implementation -
public fun into_bytes(string: String): vector<u8> {
-   let String { bytes } = string;
-   bytes
+
public fun into_bytes(string: String): vector<u8> {
+    let String { bytes } = string;
+    bytes
 }
 
@@ -355,10 +442,10 @@ Unpack the string to get its bac ## Function `byte` -Unpack the char into its underlying byte. +Unpack the char into its underlying bytes. -
public fun byte(char: ascii::Char): u8
+
public fun byte(char: ascii::Char): u8
 
@@ -367,9 +454,9 @@ Unpack the char into its underlying byte. Implementation -
public fun byte(char: Char): u8 {
-   let Char { byte } = char;
-   byte
+
public fun byte(char: Char): u8 {
+    let Char { byte } = char;
+    byte
 }
 
@@ -381,10 +468,11 @@ Unpack the char into its underlying byte. ## Function `is_valid_char` -Returns true if b is a valid ASCII character. Returns false otherwise. +Returns true if b is a valid ASCII character. +Returns false otherwise. -
public fun is_valid_char(b: u8): bool
+
public fun is_valid_char(b: u8): bool
 
@@ -393,8 +481,8 @@ Returns true if b is a valid ASCII character. R Implementation -
public fun is_valid_char(b: u8): bool {
-   b <= 0x7F
+
public fun is_valid_char(b: u8): bool {
+    b <= 0x7F
 }
 
@@ -406,10 +494,176 @@ Returns true if b is a valid ASCII character. R ## Function `is_printable_char` -Returns true if byte is an printable ASCII character. Returns false otherwise. +Returns true if byte is an printable ASCII character. +Returns false otherwise. + + +
public fun is_printable_char(byte: u8): bool
+
+ + + +
+Implementation + + +
public fun is_printable_char(byte: u8): bool {
+    byte >= 0x20 && // Disallow metacharacters
+    byte <= 0x7E // Don't allow DEL metacharacter
+}
+
+ + + +
+ + + +## Function `is_empty` + +Returns true if string is empty. + + +
public fun is_empty(string: &ascii::String): bool
+
+ + + +
+Implementation + + +
public fun is_empty(string: &String): bool {
+    string.bytes.is_empty()
+}
+
+ + + +
+ + + +## Function `to_uppercase` + +Convert a string to its uppercase equivalent. + + +
public fun to_uppercase(string: &ascii::String): ascii::String
+
+ + + +
+Implementation + + +
public fun to_uppercase(string: &String): String {
+    let bytes = string.as_bytes().map_ref!(|byte| char_to_uppercase(*byte));
+    String { bytes }
+}
+
+ + + +
+ + + +## Function `to_lowercase` + +Convert a string to its lowercase equivalent. + + +
public fun to_lowercase(string: &ascii::String): ascii::String
+
+ + + +
+Implementation + + +
public fun to_lowercase(string: &String): String {
+    let bytes = string.as_bytes().map_ref!(|byte| char_to_lowercase(*byte));
+    String { bytes }
+}
+
+ + + +
+ + + +## Function `index_of` + +Computes the index of the first occurrence of the substr in the string. +Returns the length of the string if the substr is not found. +Returns 0 if the substr is empty. + + +
public fun index_of(string: &ascii::String, substr: &ascii::String): u64
+
+ + + +
+Implementation + + +
public fun index_of(string: &String, substr: &String): u64 {
+    let mut i = 0;
+    let (n, m) = (string.length(), substr.length());
+    if (n < m) return n;
+    while (i <= n - m) {
+        let mut j = 0;
+        while (j < m && string.bytes[i + j] == substr.bytes[j]) j = j + 1;
+        if (j == m) return i;
+        i = i + 1;
+    };
+    n
+}
+
+ + + +
+ + + +## Function `char_to_uppercase` + +Convert a char to its lowercase equivalent. + + +
fun char_to_uppercase(byte: u8): u8
+
+ + + +
+Implementation + + +
fun char_to_uppercase(byte: u8): u8 {
+    if (byte >= 0x61 && byte <= 0x7A) byte - 0x20
+    else byte
+}
+
+ + + +
+ + + +## Function `char_to_lowercase` + +Convert a char to its lowercase equivalent. -
public fun is_printable_char(byte: u8): bool
+
fun char_to_lowercase(byte: u8): u8
 
@@ -418,9 +672,9 @@ Returns true if byte is an printable ASCII char Implementation -
public fun is_printable_char(byte: u8): bool {
-   byte >= 0x20 && // Disallow metacharacters
-   byte <= 0x7E // Don't allow DEL metacharacter
+
fun char_to_lowercase(byte: u8): u8 {
+    if (byte >= 0x41 && byte <= 0x5A) byte + 0x20
+    else byte
 }
 
diff --git a/external-crates/move/crates/move-stdlib/docs/bcs.md b/external-crates/move/crates/move-stdlib/docs/bcs.md index 1b89050bb7799..3497986f00b38 100644 --- a/external-crates/move/crates/move-stdlib/docs/bcs.md +++ b/external-crates/move/crates/move-stdlib/docs/bcs.md @@ -23,7 +23,7 @@ details on BCS. Return the binary representation of v in BCS (Binary Canonical Serialization) format -
public fun to_bytes<MoveValue>(v: &MoveValue): vector<u8>
+
public fun to_bytes<MoveValue>(v: &MoveValue): vector<u8>
 
@@ -32,7 +32,7 @@ Return the binary representation of v in BCS (Binary Canonical Seri Implementation -
native public fun to_bytes<MoveValue>(v: &MoveValue): vector<u8>;
+
native public fun to_bytes<MoveValue>(v: &MoveValue): vector<u8>;
 
diff --git a/external-crates/move/crates/move-stdlib/docs/bit_vector.md b/external-crates/move/crates/move-stdlib/docs/bit_vector.md index 30e0a7496901b..465aa95a26ff6 100644 --- a/external-crates/move/crates/move-stdlib/docs/bit_vector.md +++ b/external-crates/move/crates/move-stdlib/docs/bit_vector.md @@ -37,7 +37,7 @@
-length: u64 +length: u64
@@ -63,7 +63,7 @@ The provided index is out of bounds -
const EINDEX: u64 = 131072;
+
const EINDEX: u64 = 131072;
 
@@ -73,7 +73,7 @@ The provided index is out of bounds An invalid length of bitvector was given -
const ELENGTH: u64 = 131073;
+
const ELENGTH: u64 = 131073;
 
@@ -83,7 +83,16 @@ An invalid length of bitvector was given The maximum allowed bitvector size -
const MAX_SIZE: u64 = 1024;
+
const MAX_SIZE: u64 = 1024;
+
+ + + + + + + +
const WORD_SIZE: u64 = 1;
 
@@ -94,7 +103,7 @@ The maximum allowed bitvector size -
public fun new(length: u64): bit_vector::BitVector
+
public fun new(length: u64): bit_vector::BitVector
 
@@ -103,13 +112,13 @@ The maximum allowed bitvector size Implementation -
public fun new(length: u64): BitVector {
+
public fun new(length: u64): BitVector {
     assert!(length > 0, ELENGTH);
     assert!(length < MAX_SIZE, ELENGTH);
-    let counter = 0;
-    let bit_field = vector::empty();
+    let mut counter = 0;
+    let mut bit_field = vector::empty();
     while (counter < length) {
-        vector::push_back(&mut bit_field, false);
+        bit_field.push_back(false);
         counter = counter + 1;
     };
 
@@ -131,7 +140,7 @@ The maximum allowed bitvector size
 Set the bit at bit_index in the bitvector regardless of its previous state.
 
 
-
public fun set(bitvector: &mut bit_vector::BitVector, bit_index: u64)
+
public fun set(bitvector: &mut bit_vector::BitVector, bit_index: u64)
 
@@ -140,9 +149,9 @@ Set the bit at bit_index in the bitvector regardless o Implementation -
public fun set(bitvector: &mut BitVector, bit_index: u64) {
-    assert!(bit_index < vector::length(&bitvector.bit_field), EINDEX);
-    let x = vector::borrow_mut(&mut bitvector.bit_field, bit_index);
+
public fun set(bitvector: &mut BitVector, bit_index: u64) {
+    assert!(bit_index < bitvector.bit_field.length(), EINDEX);
+    let x = &mut bitvector.bit_field[bit_index];
     *x = true;
 }
 
@@ -158,7 +167,7 @@ Set the bit at bit_index in the bitvector regardless o Unset the bit at bit_index in the bitvector regardless of its previous state. -
public fun unset(bitvector: &mut bit_vector::BitVector, bit_index: u64)
+
public fun unset(bitvector: &mut bit_vector::BitVector, bit_index: u64)
 
@@ -167,9 +176,9 @@ Unset the bit at bit_index in the bitvector regardless Implementation -
public fun unset(bitvector: &mut BitVector, bit_index: u64) {
-    assert!(bit_index < vector::length(&bitvector.bit_field), EINDEX);
-    let x = vector::borrow_mut(&mut bitvector.bit_field, bit_index);
+
public fun unset(bitvector: &mut BitVector, bit_index: u64) {
+    assert!(bit_index < bitvector.bit_field.length(), EINDEX);
+    let x = &mut bitvector.bit_field[bit_index];
     *x = false;
 }
 
@@ -186,7 +195,7 @@ Shift the bitvector left by amount. If amountpublic fun shift_left(bitvector: &mut bit_vector::BitVector, amount: u64) +
public fun shift_left(bitvector: &mut bit_vector::BitVector, amount: u64)
 
@@ -195,21 +204,21 @@ bitvector's length the bitvector will be zeroed out. Implementation -
public fun shift_left(bitvector: &mut BitVector, amount: u64) {
+
public fun shift_left(bitvector: &mut BitVector, amount: u64) {
     if (amount >= bitvector.length) {
-       let len = vector::length(&bitvector.bit_field);
-       let i = 0;
+       let len = bitvector.bit_field.length();
+       let mut i = 0;
        while (i < len) {
-           let elem = vector::borrow_mut(&mut bitvector.bit_field, i);
+           let elem = &mut bitvector.bit_field[i];
            *elem = false;
            i = i + 1;
        };
     } else {
-        let i = amount;
+        let mut i = amount;
 
         while (i < bitvector.length) {
-            if (is_index_set(bitvector, i)) set(bitvector, i - amount)
-            else unset(bitvector, i - amount);
+            if (bitvector.is_index_set(i)) bitvector.set(i - amount)
+            else bitvector.unset(i - amount);
             i = i + 1;
         };
 
@@ -235,7 +244,7 @@ Return the value of the bit at bit_index in the bitvectorfalse represents a 0
 
 
-
public fun is_index_set(bitvector: &bit_vector::BitVector, bit_index: u64): bool
+
public fun is_index_set(bitvector: &bit_vector::BitVector, bit_index: u64): bool
 
@@ -244,9 +253,9 @@ represents "1" and false represents a 0 Implementation -
public fun is_index_set(bitvector: &BitVector, bit_index: u64): bool {
-    assert!(bit_index < vector::length(&bitvector.bit_field), EINDEX);
-    *vector::borrow(&bitvector.bit_field, bit_index)
+
public fun is_index_set(bitvector: &BitVector, bit_index: u64): bool {
+    assert!(bit_index < bitvector.bit_field.length(), EINDEX);
+    bitvector.bit_field[bit_index]
 }
 
@@ -261,7 +270,7 @@ represents "1" and false represents a 0 Return the length (number of usable bits) of this bitvector -
public fun length(bitvector: &bit_vector::BitVector): u64
+
public fun length(bitvector: &bit_vector::BitVector): u64
 
@@ -270,8 +279,8 @@ Return the length (number of usable bits) of this bitvector Implementation -
public fun length(bitvector: &BitVector): u64 {
-    vector::length(&bitvector.bit_field)
+
public fun length(bitvector: &BitVector): u64 {
+    bitvector.bit_field.length()
 }
 
@@ -288,7 +297,7 @@ including) start_index in the bitvector. If there is n sequence, then 0 is returned. -
public fun longest_set_sequence_starting_at(bitvector: &bit_vector::BitVector, start_index: u64): u64
+
public fun longest_set_sequence_starting_at(bitvector: &bit_vector::BitVector, start_index: u64): u64
 
@@ -297,13 +306,13 @@ sequence, then 0 is returned. Implementation -
public fun longest_set_sequence_starting_at(bitvector: &BitVector, start_index: u64): u64 {
+
public fun longest_set_sequence_starting_at(bitvector: &BitVector, start_index: u64): u64 {
     assert!(start_index < bitvector.length, EINDEX);
-    let index = start_index;
+    let mut index = start_index;
 
     // Find the greatest index in the vector such that all indices less than it are set.
     while (index < bitvector.length) {
-        if (!is_index_set(bitvector, index)) break;
+        if (!bitvector.is_index_set(index)) break;
         index = index + 1;
     };
 
diff --git a/external-crates/move/crates/move-stdlib/nursery/docs/debug.md b/external-crates/move/crates/move-stdlib/docs/debug.md
similarity index 86%
rename from external-crates/move/crates/move-stdlib/nursery/docs/debug.md
rename to external-crates/move/crates/move-stdlib/docs/debug.md
index 33bd18df12f6f..8cd525b3ea6ef 100644
--- a/external-crates/move/crates/move-stdlib/nursery/docs/debug.md
+++ b/external-crates/move/crates/move-stdlib/docs/debug.md
@@ -18,7 +18,6 @@ Module providing debug functionality.
 
 ## Function `print`
 
-Pretty-prints any Move value. For a Move struct, includes its field names, their types and their values.
 
 
 
public fun print<T>(x: &T)
@@ -41,7 +40,6 @@ Pretty-prints any Move value. For a Move struct, includes its field names, their
 
 ## Function `print_stack_trace`
 
-Prints the calling function's stack trace.
 
 
 
public fun print_stack_trace()
@@ -59,3 +57,6 @@ Prints the calling function's stack trace.
 
 
 
+ + +[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/error.md b/external-crates/move/crates/move-stdlib/docs/error.md deleted file mode 100644 index 0cc2487da9611..0000000000000 --- a/external-crates/move/crates/move-stdlib/docs/error.md +++ /dev/null @@ -1,475 +0,0 @@ - - - -# Module `0x1::error` - -This module defines a set of canonical error codes which are optional to use by applications for the -abort and assert! features. - -Canonical error codes use the 3 lowest bytes of the u64 abort code range (the upper 5 bytes are free for other use). -Of those, the highest byte represents the *error category* and the lower two bytes the *error reason*. -Given an error category 0x1 and a reason 0x3, a canonical abort code looks as 0x10003. - -A module can use a canonical code with a constant declaration of the following form: - -``` -/// An invalid ASCII character was encountered when creating a string. -const EINVALID_CHARACTER: u64 = 0x010003; -``` - -This code is both valid in the worlds with and without canonical errors. It can be used as a plain module local -error reason understand by the existing error map tooling, or as a canonical code. - -The actual canonical categories have been adopted from Google's canonical error codes, which in turn are derived -from Unix error codes [see here](https://cloud.google.com/apis/design/errors#handling_errors). Each code has an -associated HTTP error code which can be used in REST apis. The mapping from error code to http code is not 1:1; -error codes here are a bit richer than HTTP codes. - - -- [Constants](#@Constants_0) -- [Function `canonical`](#0x1_error_canonical) -- [Function `invalid_argument`](#0x1_error_invalid_argument) -- [Function `out_of_range`](#0x1_error_out_of_range) -- [Function `invalid_state`](#0x1_error_invalid_state) -- [Function `unauthenticated`](#0x1_error_unauthenticated) -- [Function `permission_denied`](#0x1_error_permission_denied) -- [Function `not_found`](#0x1_error_not_found) -- [Function `aborted`](#0x1_error_aborted) -- [Function `already_exists`](#0x1_error_already_exists) -- [Function `resource_exhausted`](#0x1_error_resource_exhausted) -- [Function `internal`](#0x1_error_internal) -- [Function `not_implemented`](#0x1_error_not_implemented) -- [Function `unavailable`](#0x1_error_unavailable) - - -
- - - - - -## Constants - - - - -Concurrency conflict, such as read-modify-write conflict (http: 409) - - -
const ABORTED: u64 = 7;
-
- - - - - -The resource that a client tried to create already exists (http: 409) - - -
const ALREADY_EXISTS: u64 = 8;
-
- - - - - -Request cancelled by the client (http: 499) - - -
const CANCELLED: u64 = 10;
-
- - - - - -Internal error (http: 500) - - -
const INTERNAL: u64 = 11;
-
- - - - - -Caller specified an invalid argument (http: 400) - - -
const INVALID_ARGUMENT: u64 = 1;
-
- - - - - -The system is not in a state where the operation can be performed (http: 400) - - -
const INVALID_STATE: u64 = 3;
-
- - - - - -A specified resource is not found (http: 404) - - -
const NOT_FOUND: u64 = 6;
-
- - - - - -Feature not implemented (http: 501) - - -
const NOT_IMPLEMENTED: u64 = 12;
-
- - - - - -An input or result of a computation is out of range (http: 400) - - -
const OUT_OF_RANGE: u64 = 2;
-
- - - - - -client does not have sufficient permission (http: 403) - - -
const PERMISSION_DENIED: u64 = 5;
-
- - - - - -Out of gas or other forms of quota (http: 429) - - -
const RESOURCE_EXHAUSTED: u64 = 9;
-
- - - - - -Request not authenticated due to missing, invalid, or expired auth token (http: 401) - - -
const UNAUTHENTICATED: u64 = 4;
-
- - - - - -The service is currently unavailable. Indicates that a retry could solve the issue (http: 503) - - -
const UNAVAILABLE: u64 = 13;
-
- - - - - -## Function `canonical` - -Construct a canonical error code from a category and a reason. - - -
public fun canonical(category: u64, reason: u64): u64
-
- - - -
-Implementation - - -
public fun canonical(category: u64, reason: u64): u64 {
-  (category << 16) + reason
-}
-
- - - -
- - - -## Function `invalid_argument` - -Functions to construct a canonical error code of the given category. - - -
public fun invalid_argument(r: u64): u64
-
- - - -
-Implementation - - -
public fun invalid_argument(r: u64): u64 {  canonical(INVALID_ARGUMENT, r) }
-
- - - -
- - - -## Function `out_of_range` - - - -
public fun out_of_range(r: u64): u64
-
- - - -
-Implementation - - -
public fun out_of_range(r: u64): u64 {  canonical(OUT_OF_RANGE, r) }
-
- - - -
- - - -## Function `invalid_state` - - - -
public fun invalid_state(r: u64): u64
-
- - - -
-Implementation - - -
public fun invalid_state(r: u64): u64 {  canonical(INVALID_STATE, r) }
-
- - - -
- - - -## Function `unauthenticated` - - - -
public fun unauthenticated(r: u64): u64
-
- - - -
-Implementation - - -
public fun unauthenticated(r: u64): u64 { canonical(UNAUTHENTICATED, r) }
-
- - - -
- - - -## Function `permission_denied` - - - -
public fun permission_denied(r: u64): u64
-
- - - -
-Implementation - - -
public fun permission_denied(r: u64): u64 { canonical(PERMISSION_DENIED, r) }
-
- - - -
- - - -## Function `not_found` - - - -
public fun not_found(r: u64): u64
-
- - - -
-Implementation - - -
public fun not_found(r: u64): u64 { canonical(NOT_FOUND, r) }
-
- - - -
- - - -## Function `aborted` - - - -
public fun aborted(r: u64): u64
-
- - - -
-Implementation - - -
public fun aborted(r: u64): u64 { canonical(ABORTED, r) }
-
- - - -
- - - -## Function `already_exists` - - - -
public fun already_exists(r: u64): u64
-
- - - -
-Implementation - - -
public fun already_exists(r: u64): u64 { canonical(ALREADY_EXISTS, r) }
-
- - - -
- - - -## Function `resource_exhausted` - - - -
public fun resource_exhausted(r: u64): u64
-
- - - -
-Implementation - - -
public fun resource_exhausted(r: u64): u64 {  canonical(RESOURCE_EXHAUSTED, r) }
-
- - - -
- - - -## Function `internal` - - - -
public fun internal(r: u64): u64
-
- - - -
-Implementation - - -
public fun internal(r: u64): u64 {  canonical(INTERNAL, r) }
-
- - - -
- - - -## Function `not_implemented` - - - -
public fun not_implemented(r: u64): u64
-
- - - -
-Implementation - - -
public fun not_implemented(r: u64): u64 {  canonical(NOT_IMPLEMENTED, r) }
-
- - - -
- - - -## Function `unavailable` - - - -
public fun unavailable(r: u64): u64
-
- - - -
-Implementation - - -
public fun unavailable(r: u64): u64 { canonical(UNAVAILABLE, r) }
-
- - - -
- - -[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/fixed_point32.md b/external-crates/move/crates/move-stdlib/docs/fixed_point32.md index 8644f861dd01d..95abd66963732 100644 --- a/external-crates/move/crates/move-stdlib/docs/fixed_point32.md +++ b/external-crates/move/crates/move-stdlib/docs/fixed_point32.md @@ -15,12 +15,6 @@ a 32-bit fractional part. - [Function `create_from_raw_value`](#0x1_fixed_point32_create_from_raw_value) - [Function `get_raw_value`](#0x1_fixed_point32_get_raw_value) - [Function `is_zero`](#0x1_fixed_point32_is_zero) -- [Function `min`](#0x1_fixed_point32_min) -- [Function `max`](#0x1_fixed_point32_max) -- [Function `create_from_u64`](#0x1_fixed_point32_create_from_u64) -- [Function `floor`](#0x1_fixed_point32_floor) -- [Function `ceil`](#0x1_fixed_point32_ceil) -- [Function `round`](#0x1_fixed_point32_round)
@@ -53,7 +47,7 @@ decimal.
-value: u64 +value: u64
@@ -73,17 +67,17 @@ decimal. The denominator provided was zero -
const EDENOMINATOR: u64 = 65537;
+
const EDENOMINATOR: u64 = 65537;
 
-The quotient value would be too large to be held in a u64 +The quotient value would be too large to be held in a u64 -
const EDIVISION: u64 = 131074;
+
const EDIVISION: u64 = 131074;
 
@@ -93,17 +87,17 @@ The quotient value would be too large to be held in a u64 A division by zero was encountered -
const EDIVISION_BY_ZERO: u64 = 65540;
+
const EDIVISION_BY_ZERO: u64 = 65540;
 
-The multiplied value would be too large to be held in a u64 +The multiplied value would be too large to be held in a u64 -
const EMULTIPLICATION: u64 = 131075;
+
const EMULTIPLICATION: u64 = 131075;
 
@@ -113,7 +107,7 @@ The multiplied value would be too large to be held in a u64 The computed ratio when converting to a FixedPoint32 would be unrepresentable -
const ERATIO_OUT_OF_RANGE: u64 = 131077;
+
const ERATIO_OUT_OF_RANGE: u64 = 131077;
 
@@ -123,7 +117,7 @@ The computed ratio when converting to a MAX_U64: u128 = 18446744073709551615; +
const MAX_U64: u128 = 18446744073709551615;
 
@@ -137,7 +131,7 @@ fractional part of the product. This will abort if the product overflows. -
public fun multiply_u64(val: u64, multiplier: fixed_point32::FixedPoint32): u64
+
public fun multiply_u64(val: u64, multiplier: fixed_point32::FixedPoint32): u64
 
@@ -146,17 +140,17 @@ overflows. Implementation -
public fun multiply_u64(val: u64, multiplier: FixedPoint32): u64 {
+
public fun multiply_u64(val: u64, multiplier: FixedPoint32): u64 {
     // The product of two 64 bit values has 128 bits, so perform the
-    // multiplication with u128 types and keep the full 128 bit product
+    // multiplication with u128 types and keep the full 128 bit product
     // to avoid losing accuracy.
-    let unscaled_product = (val as u128) * (multiplier.value as u128);
+    let unscaled_product = val as u128 * (multiplier.value as u128);
     // The unscaled product has 32 fractional bits (from the multiplier)
     // so rescale it by shifting away the low bits.
     let product = unscaled_product >> 32;
     // Check whether the value is too large.
     assert!(product <= MAX_U64, EMULTIPLICATION);
-    (product as u64)
+    product as u64
 }
 
@@ -173,7 +167,7 @@ fractional part of the quotient. This will abort if the divisor is zero or if the quotient overflows. -
public fun divide_u64(val: u64, divisor: fixed_point32::FixedPoint32): u64
+
public fun divide_u64(val: u64, divisor: fixed_point32::FixedPoint32): u64
 
@@ -182,18 +176,18 @@ is zero or if the quotient overflows. Implementation -
public fun divide_u64(val: u64, divisor: FixedPoint32): u64 {
+
public fun divide_u64(val: u64, divisor: FixedPoint32): u64 {
     // Check for division by zero.
     assert!(divisor.value != 0, EDIVISION_BY_ZERO);
     // First convert to 128 bits and then shift left to
     // add 32 fractional zero bits to the dividend.
-    let scaled_value = (val as u128) << 32;
-    let quotient = scaled_value / (divisor.value as u128);
+    let scaled_value = val as u128 << 32;
+    let quotient = scaled_value / (divisor.value as u128);
     // Check whether the value is too large.
     assert!(quotient <= MAX_U64, EDIVISION);
     // the value may be too large, which will cause the cast to fail
-    // with an arithmetic error.
-    (quotient as u64)
+    // with an arithmetic error.
+    quotient as u64
 }
 
@@ -217,7 +211,7 @@ very small imprecision in the binary representation could change the rounding, e.g., 0.0125 will round down to 0.012 instead of up to 0.013. -
public fun create_from_rational(numerator: u64, denominator: u64): fixed_point32::FixedPoint32
+
public fun create_from_rational(numerator: u64, denominator: u64): fixed_point32::FixedPoint32
 
@@ -226,20 +220,20 @@ rounding, e.g., 0.0125 will round down to 0.012 instead of up to 0.013. Implementation -
public fun create_from_rational(numerator: u64, denominator: u64): FixedPoint32 {
+
public fun create_from_rational(numerator: u64, denominator: u64): FixedPoint32 {
     // If the denominator is zero, this will abort.
     // Scale the numerator to have 64 fractional bits and the denominator
     // to have 32 fractional bits, so that the quotient will have 32
     // fractional bits.
-    let scaled_numerator = (numerator as u128) << 64;
-    let scaled_denominator = (denominator as u128) << 32;
+    let scaled_numerator = numerator as u128 << 64;
+    let scaled_denominator = denominator as u128 << 32;
     assert!(scaled_denominator != 0, EDENOMINATOR);
     let quotient = scaled_numerator / scaled_denominator;
     assert!(quotient != 0 || numerator == 0, ERATIO_OUT_OF_RANGE);
     // Return the quotient as a fixed-point number. We first need to check whether the cast
     // can succeed.
     assert!(quotient <= MAX_U64, ERATIO_OUT_OF_RANGE);
-    FixedPoint32 { value: (quotient as u64) }
+    FixedPoint32 { value: quotient as u64 }
 }
 
@@ -254,7 +248,7 @@ rounding, e.g., 0.0125 will round down to 0.012 instead of up to 0.013. Create a fixedpoint value from a raw value. -
public fun create_from_raw_value(value: u64): fixed_point32::FixedPoint32
+
public fun create_from_raw_value(value: u64): fixed_point32::FixedPoint32
 
@@ -263,7 +257,7 @@ Create a fixedpoint value from a raw value. Implementation -
public fun create_from_raw_value(value: u64): FixedPoint32 {
+
public fun create_from_raw_value(value: u64): FixedPoint32 {
     FixedPoint32 { value }
 }
 
@@ -281,7 +275,7 @@ adding or subtracting FixedPoint32 values, can be done using the raw values directly. -
public fun get_raw_value(num: fixed_point32::FixedPoint32): u64
+
public fun get_raw_value(num: fixed_point32::FixedPoint32): u64
 
@@ -290,7 +284,7 @@ values directly. Implementation -
public fun get_raw_value(num: FixedPoint32): u64 {
+
public fun get_raw_value(num: FixedPoint32): u64 {
     num.value
 }
 
@@ -322,177 +316,6 @@ Returns true if the ratio is zero. - - - - -## Function `min` - -Returns the smaller of the two FixedPoint32 numbers. - - -
public fun min(num1: fixed_point32::FixedPoint32, num2: fixed_point32::FixedPoint32): fixed_point32::FixedPoint32
-
- - - -
-Implementation - - -
public fun min(num1: FixedPoint32, num2: FixedPoint32): FixedPoint32 {
-    if (num1.value < num2.value) {
-        num1
-    } else {
-        num2
-    }
-}
-
- - - -
- - - -## Function `max` - -Returns the larger of the two FixedPoint32 numbers. - - -
public fun max(num1: fixed_point32::FixedPoint32, num2: fixed_point32::FixedPoint32): fixed_point32::FixedPoint32
-
- - - -
-Implementation - - -
public fun max(num1: FixedPoint32, num2: FixedPoint32): FixedPoint32 {
-    if (num1.value > num2.value) {
-        num1
-    } else {
-        num2
-    }
-}
-
- - - -
- - - -## Function `create_from_u64` - -Create a fixedpoint value from a u64 value. - - -
public fun create_from_u64(val: u64): fixed_point32::FixedPoint32
-
- - - -
-Implementation - - -
public fun create_from_u64(val: u64): FixedPoint32 {
-    let value = (val as u128) << 32;
-    assert!(value <= MAX_U64, ERATIO_OUT_OF_RANGE);
-    FixedPoint32{value: (value as u64)}
-}
-
- - - -
- - - -## Function `floor` - -Returns the largest integer less than or equal to a given number. - - -
public fun floor(num: fixed_point32::FixedPoint32): u64
-
- - - -
-Implementation - - -
public fun floor(num: FixedPoint32): u64 {
-    num.value >> 32
-}
-
- - - -
- - - -## Function `ceil` - -Rounds up the given FixedPoint32 to the next largest integer. - - -
public fun ceil(num: fixed_point32::FixedPoint32): u64
-
- - - -
-Implementation - - -
public fun ceil(num: FixedPoint32): u64 {
-    let floored_num = floor(num) << 32;
-    if (num.value == floored_num) {
-        return floored_num >> 32
-    };
-    let val = ((floored_num as u128) + (1 << 32));
-    (val >> 32 as u64)
-}
-
- - - -
- - - -## Function `round` - -Returns the value of a FixedPoint32 to the nearest integer. - - -
public fun round(num: fixed_point32::FixedPoint32): u64
-
- - - -
-Implementation - - -
public fun round(num: FixedPoint32): u64 {
-    let floored_num = floor(num) << 32;
-    let boundary = floored_num + ((1 << 32) / 2);
-    if (num.value < boundary) {
-        floored_num >> 32
-    } else {
-        ceil(num)
-    }
-}
-
- - -
diff --git a/external-crates/move/crates/move-stdlib/docs/hash.md b/external-crates/move/crates/move-stdlib/docs/hash.md index c054f33cb569a..e3b110a627729 100644 --- a/external-crates/move/crates/move-stdlib/docs/hash.md +++ b/external-crates/move/crates/move-stdlib/docs/hash.md @@ -23,7 +23,7 @@ as in the Move prover's prelude. -
public fun sha2_256(data: vector<u8>): vector<u8>
+
public fun sha2_256(data: vector<u8>): vector<u8>
 
@@ -32,7 +32,7 @@ as in the Move prover's prelude. Implementation -
native public fun sha2_256(data: vector<u8>): vector<u8>;
+
native public fun sha2_256(data: vector<u8>): vector<u8>;
 
@@ -45,7 +45,7 @@ as in the Move prover's prelude. -
public fun sha3_256(data: vector<u8>): vector<u8>
+
public fun sha3_256(data: vector<u8>): vector<u8>
 
@@ -54,7 +54,7 @@ as in the Move prover's prelude. Implementation -
native public fun sha3_256(data: vector<u8>): vector<u8>;
+
native public fun sha3_256(data: vector<u8>): vector<u8>;
 
diff --git a/external-crates/move/crates/move-stdlib/docs/macros.md b/external-crates/move/crates/move-stdlib/docs/macros.md new file mode 100644 index 0000000000000..4fd3e7cd33d95 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/docs/macros.md @@ -0,0 +1,14 @@ + + + +# Module `0x1::macros` + +This module holds shared implementation of macros used in std + + + + +
+ + +[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/option.md b/external-crates/move/crates/move-stdlib/docs/option.md index 04baf52a56f91..070a8f9672a07 100644 --- a/external-crates/move/crates/move-stdlib/docs/option.md +++ b/external-crates/move/crates/move-stdlib/docs/option.md @@ -72,7 +72,7 @@ The Option is in an inval The Option is Some while it should be None. -
const EOPTION_IS_SET: u64 = 262144;
+
const EOPTION_IS_SET: u64 = 262144;
 
@@ -83,7 +83,7 @@ The Option is in an inval The Option is None while it should be Some. -
const EOPTION_NOT_SET: u64 = 262145;
+
const EOPTION_NOT_SET: u64 = 262145;
 
@@ -155,7 +155,7 @@ Return true if t does not hold a value
public fun is_none<Element>(t: &Option<Element>): bool {
-    vector::is_empty(&t.vec)
+    t.vec.is_empty()
 }
 
@@ -180,7 +180,7 @@ Return true if t holds a value
public fun is_some<Element>(t: &Option<Element>): bool {
-    !vector::is_empty(&t.vec)
+    !t.vec.is_empty()
 }
 
@@ -206,7 +206,7 @@ Always returns false if t does not hold a value
public fun contains<Element>(t: &Option<Element>, e_ref: &Element): bool {
-    vector::contains(&t.vec, e_ref)
+    t.vec.contains(e_ref)
 }
 
@@ -232,8 +232,8 @@ Aborts if t does not hold a value
public fun borrow<Element>(t: &Option<Element>): &Element {
-    assert!(is_some(t), EOPTION_NOT_SET);
-    vector::borrow(&t.vec, 0)
+    assert!(t.is_some(), EOPTION_NOT_SET);
+    &t.vec[0]
 }
 
@@ -260,8 +260,8 @@ Return default_ref if t does not hold a value
public fun borrow_with_default<Element>(t: &Option<Element>, default_ref: &Element): &Element {
     let vec_ref = &t.vec;
-    if (vector::is_empty(vec_ref)) default_ref
-    else vector::borrow(vec_ref, 0)
+    if (vec_ref.is_empty()) default_ref
+    else &vec_ref[0]
 }
 
@@ -291,8 +291,8 @@ Return default if t does not hold a value default: Element, ): Element { let vec_ref = &t.vec; - if (vector::is_empty(vec_ref)) default - else *vector::borrow(vec_ref, 0) + if (vec_ref.is_empty()) default + else vec_ref[0] }
@@ -319,7 +319,7 @@ Aborts if t already holds a value
public fun fill<Element>(t: &mut Option<Element>, e: Element) {
     let vec_ref = &mut t.vec;
-    if (vector::is_empty(vec_ref)) vector::push_back(vec_ref, e)
+    if (vec_ref.is_empty()) vec_ref.push_back(e)
     else abort EOPTION_IS_SET
 }
 
@@ -346,8 +346,8 @@ Aborts if t does not hold a value
public fun extract<Element>(t: &mut Option<Element>): Element {
-    assert!(is_some(t), EOPTION_NOT_SET);
-    vector::pop_back(&mut t.vec)
+    assert!(t.is_some(), EOPTION_NOT_SET);
+    t.vec.pop_back()
 }
 
@@ -373,8 +373,8 @@ Aborts if t does not hold a value
public fun borrow_mut<Element>(t: &mut Option<Element>): &mut Element {
-    assert!(is_some(t), EOPTION_NOT_SET);
-    vector::borrow_mut(&mut t.vec, 0)
+    assert!(t.is_some(), EOPTION_NOT_SET);
+    &mut t.vec[0]
 }
 
@@ -400,10 +400,10 @@ Aborts if t does not hold a value
public fun swap<Element>(t: &mut Option<Element>, e: Element): Element {
-    assert!(is_some(t), EOPTION_NOT_SET);
+    assert!(t.is_some(), EOPTION_NOT_SET);
     let vec_ref = &mut t.vec;
-    let old_value = vector::pop_back(vec_ref);
-    vector::push_back(vec_ref, e);
+    let old_value = vec_ref.pop_back();
+    vec_ref.push_back(e);
     old_value
 }
 
@@ -432,9 +432,9 @@ Different from swap(), swap_or_fill() allows for t not holding a va
public fun swap_or_fill<Element>(t: &mut Option<Element>, e: Element): Option<Element> {
     let vec_ref = &mut t.vec;
-    let old_value = if (vector::is_empty(vec_ref)) none()
-        else some(vector::pop_back(vec_ref));
-    vector::push_back(vec_ref, e);
+    let old_value = if (vec_ref.is_empty()) none()
+        else some(vec_ref.pop_back());
+    vec_ref.push_back(e);
     old_value
 }
 
@@ -460,9 +460,9 @@ Destroys t. If t holds a value, return it. Returns public fun destroy_with_default<Element: drop>(t: Option<Element>, default: Element): Element { - let Option { vec } = t; - if (vector::is_empty(&vec)) default - else vector::pop_back(&mut vec) + let Option { mut vec } = t; + if (vec.is_empty()) default + else vec.pop_back() }
@@ -488,10 +488,10 @@ Aborts if t does not hold a value
public fun destroy_some<Element>(t: Option<Element>): Element {
-    assert!(is_some(&t), EOPTION_NOT_SET);
-    let Option { vec } = t;
-    let elem = vector::pop_back(&mut vec);
-    vector::destroy_empty(vec);
+    assert!(t.is_some(), EOPTION_NOT_SET);
+    let Option { mut vec } = t;
+    let elem = vec.pop_back();
+    vec.destroy_empty();
     elem
 }
 
@@ -518,9 +518,9 @@ Aborts if t holds a value
public fun destroy_none<Element>(t: Option<Element>) {
-    assert!(is_none(&t), EOPTION_IS_SET);
+    assert!(t.is_none(), EOPTION_IS_SET);
     let Option { vec } = t;
-    vector::destroy_empty(vec)
+    vec.destroy_empty()
 }
 
diff --git a/external-crates/move/crates/move-stdlib/docs/overview.md b/external-crates/move/crates/move-stdlib/docs/overview.md index e8aff3f0414fa..e3e118394a99c 100644 --- a/external-crates/move/crates/move-stdlib/docs/overview.md +++ b/external-crates/move/crates/move-stdlib/docs/overview.md @@ -12,16 +12,23 @@ This is the root document for the Move stdlib module documentation. The Move std ## Index +- [`0x1::address`](address.md#0x1_address) - [`0x1::ascii`](ascii.md#0x1_ascii) - [`0x1::bcs`](bcs.md#0x1_bcs) - [`0x1::bit_vector`](bit_vector.md#0x1_bit_vector) -- [`0x1::error`](error.md#0x1_error) +- [`0x1::debug`](debug.md#0x1_debug) - [`0x1::fixed_point32`](fixed_point32.md#0x1_fixed_point32) - [`0x1::hash`](hash.md#0x1_hash) +- [`0x1::macros`](macros.md#0x1_macros) - [`0x1::option`](option.md#0x1_option) -- [`0x1::signer`](signer.md#0x1_signer) - [`0x1::string`](string.md#0x1_string) - [`0x1::type_name`](type_name.md#0x1_type_name) +- [`0x1::u128`](u128.md#0x1_u128) +- [`0x1::u16`](u16.md#0x1_u16) +- [`0x1::u256`](u256.md#0x1_u256) +- [`0x1::u32`](u32.md#0x1_u32) +- [`0x1::u64`](u64.md#0x1_u64) +- [`0x1::u8`](u8.md#0x1_u8) - [`0x1::vector`](vector.md#0x1_vector) diff --git a/external-crates/move/crates/move-stdlib/docs/signer.md b/external-crates/move/crates/move-stdlib/docs/signer.md deleted file mode 100644 index 99b418f9e1abc..0000000000000 --- a/external-crates/move/crates/move-stdlib/docs/signer.md +++ /dev/null @@ -1,63 +0,0 @@ - - - -# Module `0x1::signer` - - - -- [Function `borrow_address`](#0x1_signer_borrow_address) -- [Function `address_of`](#0x1_signer_address_of) - - -
- - - - - -## Function `borrow_address` - - - -
public fun borrow_address(s: &signer): &address
-
- - - -
-Implementation - - -
native public fun borrow_address(s: &signer): &address;
-
- - - -
- - - -## Function `address_of` - - - -
public fun address_of(s: &signer): address
-
- - - -
-Implementation - - -
public fun address_of(s: &signer): address {
-    *borrow_address(s)
-}
-
- - - -
- - -[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/string.md b/external-crates/move/crates/move-stdlib/docs/string.md index e962b56d86758..c08d3514d8861 100644 --- a/external-crates/move/crates/move-stdlib/docs/string.md +++ b/external-crates/move/crates/move-stdlib/docs/string.md @@ -3,28 +3,35 @@ # Module `0x1::string` -The string module defines the String type which represents UTF8 encoded strings. +The string module defines the String type which represents UTF8 encoded +strings. - [Struct `String`](#0x1_string_String) - [Constants](#@Constants_0) - [Function `utf8`](#0x1_string_utf8) +- [Function `from_ascii`](#0x1_string_from_ascii) +- [Function `to_ascii`](#0x1_string_to_ascii) - [Function `try_utf8`](#0x1_string_try_utf8) -- [Function `bytes`](#0x1_string_bytes) +- [Function `as_bytes`](#0x1_string_as_bytes) +- [Function `into_bytes`](#0x1_string_into_bytes) - [Function `is_empty`](#0x1_string_is_empty) - [Function `length`](#0x1_string_length) - [Function `append`](#0x1_string_append) - [Function `append_utf8`](#0x1_string_append_utf8) - [Function `insert`](#0x1_string_insert) -- [Function `sub_string`](#0x1_string_sub_string) +- [Function `substring`](#0x1_string_substring) - [Function `index_of`](#0x1_string_index_of) - [Function `internal_check_utf8`](#0x1_string_internal_check_utf8) - [Function `internal_is_char_boundary`](#0x1_string_internal_is_char_boundary) - [Function `internal_sub_string`](#0x1_string_internal_sub_string) - [Function `internal_index_of`](#0x1_string_internal_index_of) +- [Function `bytes`](#0x1_string_bytes) +- [Function `sub_string`](#0x1_string_sub_string) -
use 0x1::option;
+
use 0x1::ascii;
+use 0x1::option;
 use 0x1::vector;
 
@@ -34,7 +41,8 @@ The string module defines the String
holds a sequence of bytes which is guaranteed to be in utf8 format. +A String holds a sequence of bytes which is guaranteed to be in utf8 +format.
struct String has copy, drop, store
@@ -48,7 +56,7 @@ A String holds a sequence
 
 
-bytes: vector<u8> +bytes: vector<u8>
@@ -63,22 +71,22 @@ A String holds a sequence ## Constants - + Index out of range. -
const EINVALID_INDEX: u64 = 2;
+
const EInvalidIndex: u64 = 2;
 
- + An invalid UTF8 encoding. -
const EINVALID_UTF8: u64 = 1;
+
const EInvalidUTF8: u64 = 1;
 
@@ -87,10 +95,63 @@ An invalid UTF8 encoding. ## Function `utf8` -Creates a new string from a sequence of bytes. Aborts if the bytes do not represent valid utf8. +Creates a new string from a sequence of bytes. Aborts if the bytes do +not represent valid utf8. + + +
public fun utf8(bytes: vector<u8>): string::String
+
+ + + +
+Implementation + + +
public fun utf8(bytes: vector<u8>): String {
+    assert!(internal_check_utf8(&bytes), EInvalidUTF8);
+    String { bytes }
+}
+
+ + + +
+ + + +## Function `from_ascii` + +Convert an ASCII string to a UTF8 string + + +
public fun from_ascii(s: ascii::String): string::String
+
+ -
public fun utf8(bytes: vector<u8>): string::String
+
+Implementation + + +
public fun from_ascii(s: ascii::String): String {
+    String { bytes: s.into_bytes() }
+}
+
+ + + +
+ + + +## Function `to_ascii` + +Convert an UTF8 string to an ASCII string. +Aborts if s is not valid ASCII + + +
public fun to_ascii(s: string::String): ascii::String
 
@@ -99,9 +160,9 @@ Creates a new string from a sequence of bytes. Aborts if the bytes do not repres Implementation -
public fun utf8(bytes: vector<u8>): String {
-    assert!(internal_check_utf8(&bytes), EINVALID_UTF8);
-    String{bytes}
+
public fun to_ascii(s: String): ascii::String {
+    let String { bytes } = s;
+    bytes.to_ascii_string()
 }
 
@@ -116,7 +177,7 @@ Creates a new string from a sequence of bytes. Aborts if the bytes do not repres Tries to create a new string from a sequence of bytes. -
public fun try_utf8(bytes: vector<u8>): option::Option<string::String>
+
public fun try_utf8(bytes: vector<u8>): option::Option<string::String>
 
@@ -125,12 +186,9 @@ Tries to create a new string from a sequence of bytes. Implementation -
public fun try_utf8(bytes: vector<u8>): Option<String> {
-    if (internal_check_utf8(&bytes)) {
-        option::some(String{bytes})
-    } else {
-        option::none()
-    }
+
public fun try_utf8(bytes: vector<u8>): Option<String> {
+    if (internal_check_utf8(&bytes)) option::some(String { bytes })
+    else option::none()
 }
 
@@ -138,14 +196,14 @@ Tries to create a new string from a sequence of bytes. - + -## Function `bytes` +## Function `as_bytes` Returns a reference to the underlying byte vector. -
public fun bytes(s: &string::String): &vector<u8>
+
public fun as_bytes(s: &string::String): &vector<u8>
 
@@ -154,13 +212,39 @@ Returns a reference to the underlying byte vector. Implementation -
public fun bytes(s: &String): &vector<u8> {
+
public fun as_bytes(s: &String): &vector<u8> {
     &s.bytes
 }
 
+ + + + +## Function `into_bytes` + +Unpack the string to get its underlying bytes. + + +
public fun into_bytes(s: string::String): vector<u8>
+
+ + + +
+Implementation + + +
public fun into_bytes(s: String): vector<u8> {
+    let String { bytes } = s;
+    bytes
+}
+
+ + +
@@ -180,7 +264,7 @@ Checks whether this string is empty.
public fun is_empty(s: &String): bool {
-    vector::is_empty(&s.bytes)
+    s.bytes.is_empty()
 }
 
@@ -195,7 +279,7 @@ Checks whether this string is empty. Returns the length of this string, in bytes. -
public fun length(s: &string::String): u64
+
public fun length(s: &string::String): u64
 
@@ -204,8 +288,8 @@ Returns the length of this string, in bytes. Implementation -
public fun length(s: &String): u64 {
-    vector::length(&s.bytes)
+
public fun length(s: &String): u64 {
+    s.bytes.length()
 }
 
@@ -230,7 +314,7 @@ Appends a string.
public fun append(s: &mut String, r: String) {
-    vector::append(&mut s.bytes, r.bytes)
+    s.bytes.append(r.bytes)
 }
 
@@ -245,7 +329,7 @@ Appends a string. Appends bytes which must be in valid utf8 format. -
public fun append_utf8(s: &mut string::String, bytes: vector<u8>)
+
public fun append_utf8(s: &mut string::String, bytes: vector<u8>)
 
@@ -254,8 +338,8 @@ Appends bytes which must be in valid utf8 format. Implementation -
public fun append_utf8(s: &mut String, bytes: vector<u8>) {
-    append(s, utf8(bytes))
+
public fun append_utf8(s: &mut String, bytes: vector<u8>) {
+    s.append(utf8(bytes))
 }
 
@@ -267,11 +351,11 @@ Appends bytes which must be in valid utf8 format. ## Function `insert` -Insert the other string at the byte index in given string. The index must be at a valid utf8 char -boundary. +Insert the other string at the byte index in given string. The index +must be at a valid utf8 char boundary. -
public fun insert(s: &mut string::String, at: u64, o: string::String)
+
public fun insert(s: &mut string::String, at: u64, o: string::String)
 
@@ -280,14 +364,17 @@ boundary. Implementation -
public fun insert(s: &mut String, at: u64, o: String) {
+
public fun insert(s: &mut String, at: u64, o: String) {
     let bytes = &s.bytes;
-    assert!(at <= vector::length(bytes) && internal_is_char_boundary(bytes, at), EINVALID_INDEX);
-    let l = length(s);
-    let front = sub_string(s, 0, at);
-    let end = sub_string(s, at, l);
-    append(&mut front, o);
-    append(&mut front, end);
+    assert!(
+        at <= bytes.length() && internal_is_char_boundary(bytes, at),
+        EInvalidIndex,
+    );
+    let l = s.length();
+    let mut front = s.substring(0, at);
+    let end = s.substring(at, l);
+    front.append(o);
+    front.append(end);
     *s = front;
 }
 
@@ -296,16 +383,17 @@ boundary. - + -## Function `sub_string` +## Function `substring` -Returns a sub-string using the given byte indices, where i is the first byte position and j is the start -of the first byte not included (or the length of the string). The indices must be at valid utf8 char boundaries, +Returns a sub-string using the given byte indices, where i is the first +byte position and j is the start of the first byte not included (or the +length of the string). The indices must be at valid utf8 char boundaries, guaranteeing that the result is valid utf8. -
public fun sub_string(s: &string::String, i: u64, j: u64): string::String
+
public fun substring(s: &string::String, i: u64, j: u64): string::String
 
@@ -314,14 +402,17 @@ guaranteeing that the result is valid utf8. Implementation -
public fun sub_string(s: &String, i: u64, j: u64): String {
+
public fun substring(s: &String, i: u64, j: u64): String {
     let bytes = &s.bytes;
-    let l = vector::length(bytes);
+    let l = bytes.length();
     assert!(
-        j <= l && i <= j && internal_is_char_boundary(bytes, i) && internal_is_char_boundary(bytes, j),
-        EINVALID_INDEX
+        j <= l &&
+        i <= j &&
+        internal_is_char_boundary(bytes, i) &&
+        internal_is_char_boundary(bytes, j),
+        EInvalidIndex,
     );
-    String{bytes: internal_sub_string(bytes, i, j)}
+    String { bytes: internal_sub_string(bytes, i, j) }
 }
 
@@ -333,10 +424,11 @@ guaranteeing that the result is valid utf8. ## Function `index_of` -Computes the index of the first occurrence of a string. Returns length(s) if no occurrence found. +Computes the index of the first occurrence of a string. Returns s.length() +if no occurrence found. -
public fun index_of(s: &string::String, r: &string::String): u64
+
public fun index_of(s: &string::String, r: &string::String): u64
 
@@ -345,7 +437,7 @@ Computes the index of the first occurrence of a string. Returns index_of(s: &String, r: &String): u64 { +
public fun index_of(s: &String, r: &String): u64 {
     internal_index_of(&s.bytes, &r.bytes)
 }
 
@@ -360,7 +452,7 @@ Computes the index of the first occurrence of a string. Returns internal_check_utf8(v: &vector<u8>): bool +
fun internal_check_utf8(v: &vector<u8>): bool
 
@@ -369,7 +461,7 @@ Computes the index of the first occurrence of a string. Returns internal_check_utf8(v: &vector<u8>): bool; +
native fun internal_check_utf8(v: &vector<u8>): bool;
 
@@ -382,7 +474,7 @@ Computes the index of the first occurrence of a string. Returns internal_is_char_boundary(v: &vector<u8>, i: u64): bool +
fun internal_is_char_boundary(v: &vector<u8>, i: u64): bool
 
@@ -391,7 +483,7 @@ Computes the index of the first occurrence of a string. Returns internal_is_char_boundary(v: &vector<u8>, i: u64): bool; +
native fun internal_is_char_boundary(v: &vector<u8>, i: u64): bool;
 
@@ -404,7 +496,7 @@ Computes the index of the first occurrence of a string. Returns internal_sub_string(v: &vector<u8>, i: u64, j: u64): vector<u8> +
fun internal_sub_string(v: &vector<u8>, i: u64, j: u64): vector<u8>
 
@@ -413,7 +505,7 @@ Computes the index of the first occurrence of a string. Returns internal_sub_string(v: &vector<u8>, i: u64, j: u64): vector<u8>; +
native fun internal_sub_string(v: &vector<u8>, i: u64, j: u64): vector<u8>;
 
@@ -426,7 +518,29 @@ Computes the index of the first occurrence of a string. Returns internal_index_of(v: &vector<u8>, r: &vector<u8>): u64 +
fun internal_index_of(v: &vector<u8>, r: &vector<u8>): u64
+
+ + + +
+Implementation + + +
native fun internal_index_of(v: &vector<u8>, r: &vector<u8>): u64;
+
+ + + +
+ + + +## Function `bytes` + + + +
public fun bytes(s: &string::String): &vector<u8>
 
@@ -435,7 +549,31 @@ Computes the index of the first occurrence of a string. Returns internal_index_of(v: &vector<u8>, r: &vector<u8>): u64; +
public fun bytes(s: &String): &vector<u8> { s.as_bytes() }
+
+ + + + + + + +## Function `sub_string` + + + +
public fun sub_string(s: &string::String, i: u64, j: u64): string::String
+
+ + + +
+Implementation + + +
public fun sub_string(s: &String, i: u64, j: u64): String {
+    s.substring(i, j)
+}
 
diff --git a/external-crates/move/crates/move-stdlib/docs/type_name.md b/external-crates/move/crates/move-stdlib/docs/type_name.md index 070e0ffd56e45..2c79606a1aefe 100644 --- a/external-crates/move/crates/move-stdlib/docs/type_name.md +++ b/external-crates/move/crates/move-stdlib/docs/type_name.md @@ -7,13 +7,18 @@ Functionality for converting Move types into values. Use with care! - [Struct `TypeName`](#0x1_type_name_TypeName) +- [Constants](#@Constants_0) - [Function `get`](#0x1_type_name_get) - [Function `get_with_original_ids`](#0x1_type_name_get_with_original_ids) +- [Function `is_primitive`](#0x1_type_name_is_primitive) - [Function `borrow_string`](#0x1_type_name_borrow_string) +- [Function `get_address`](#0x1_type_name_get_address) +- [Function `get_module`](#0x1_type_name_get_module) - [Function `into_string`](#0x1_type_name_into_string) -
use 0x1::ascii;
+
use 0x1::address;
+use 0x1::ascii;
 
@@ -40,10 +45,10 @@ Functionality for converting Move types into values. Use with care!
String representation of the type. All types are represented using their source syntax: - "u8", "u64", "u128", "bool", "address", "vector", "signer" for ground types. + "u8", "u64", "bool", "address", "vector", and so on for primitive types. Struct types are represented as fully qualified type names; e.g. 00000000000000000000000000000001::string::String or - 0000000000000000000000000000000a::module_name1::type_name1<0000000000000000000000000000000a::module_name2::type_name2<u64>> + 0000000000000000000000000000000a::module_name1::type_name1<0000000000000000000000000000000a::module_name2::type_name2<u64>> Addresses are hex-encoded lowercase values of length ADDRESS_LENGTH (16, 20, or 32 depending on the Move platform)
@@ -51,6 +56,91 @@ Functionality for converting Move types into values. Use with care! + + +## Constants + + + + +ASCII Character code for the c (lowercase c) symbol. + + +
const ASCII_C: u8 = 99;
+
+ + + + + +ASCII Character code for the : (colon) symbol. + + +
const ASCII_COLON: u8 = 58;
+
+ + + + + +ASCII Character code for the e (lowercase e) symbol. + + +
const ASCII_E: u8 = 101;
+
+ + + + + +ASCII Character code for the o (lowercase o) symbol. + + +
const ASCII_O: u8 = 111;
+
+ + + + + +ASCII Character code for the r (lowercase r) symbol. + + +
const ASCII_R: u8 = 114;
+
+ + + + + +ASCII Character code for the t (lowercase t) symbol. + + +
const ASCII_T: u8 = 116;
+
+ + + + + +ASCII Character code for the v (lowercase v) symbol. + + +
const ASCII_V: u8 = 118;
+
+ + + + + +The type is not from a package/module. It is a primitive type. + + +
const ENonModuleType: u64 = 0;
+
+ + + ## Function `get` @@ -102,6 +192,49 @@ later upgrade). + + + + +## Function `is_primitive` + +Returns true iff the TypeName represents a primitive type, i.e. one of +u8, u16, u32, u64, u128, u256, bool, address, vector. + + +
public fun is_primitive(self: &type_name::TypeName): bool
+
+ + + +
+Implementation + + +
public fun is_primitive(self: &TypeName): bool {
+    let bytes = self.name.as_bytes();
+    bytes == &b"bool" ||
+    bytes == &b"u8" ||
+    bytes == &b"u16" ||
+    bytes == &b"u32" ||
+    bytes == &b"u64" ||
+    bytes == &b"u128" ||
+    bytes == &b"u256" ||
+    bytes == &b"address" ||
+    (
+        bytes.length() >= 6 &&
+        bytes[0] == ASCII_V &&
+        bytes[1] == ASCII_E &&
+        bytes[2] == ASCII_C &&
+        bytes[3] == ASCII_T &&
+        bytes[4] == ASCII_O &&
+        bytes[5] == ASCII_R,
+    )
+}
+
+ + +
@@ -127,6 +260,89 @@ Get the String representation of self + + + + +## Function `get_address` + +Get Address string (Base16 encoded), first part of the TypeName. +Aborts if given a primitive type. + + +
public fun get_address(self: &type_name::TypeName): ascii::String
+
+ + + +
+Implementation + + +
public fun get_address(self: &TypeName): String {
+    assert!(!self.is_primitive(), ENonModuleType);
+
+    // Base16 (string) representation of an address has 2 symbols per byte.
+    let len = address::length() * 2;
+    let str_bytes = self.name.as_bytes();
+    let mut addr_bytes = vector[];
+    let mut i = 0;
+
+    // Read `len` bytes from the type name and push them to addr_bytes.
+    while (i < len) {
+        addr_bytes.push_back(str_bytes[i]);
+        i = i + 1;
+    };
+
+    ascii::string(addr_bytes)
+}
+
+ + + +
+ + + +## Function `get_module` + +Get name of the module. +Aborts if given a primitive type. + + +
public fun get_module(self: &type_name::TypeName): ascii::String
+
+ + + +
+Implementation + + +
public fun get_module(self: &TypeName): String {
+    assert!(!self.is_primitive(), ENonModuleType);
+
+    // Starts after address and a double colon: `<addr as HEX>::`
+    let mut i = address::length() * 2 + 2;
+    let str_bytes = self.name.as_bytes();
+    let mut module_name = vector[];
+    let colon = ASCII_COLON;
+    loop {
+        let char = &str_bytes[i];
+        if (char != &colon) {
+            module_name.push_back(*char);
+            i = i + 1;
+        } else {
+            break
+        }
+    };
+
+    ascii::string(module_name)
+}
+
+ + +
diff --git a/external-crates/move/crates/move-stdlib/docs/u128.md b/external-crates/move/crates/move-stdlib/docs/u128.md new file mode 100644 index 0000000000000..682372e184dc2 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/docs/u128.md @@ -0,0 +1,195 @@ + + + +# Module `0x1::u128` + + + +- [Function `max`](#0x1_u128_max) +- [Function `min`](#0x1_u128_min) +- [Function `diff`](#0x1_u128_diff) +- [Function `divide_and_round_up`](#0x1_u128_divide_and_round_up) +- [Function `pow`](#0x1_u128_pow) +- [Function `sqrt`](#0x1_u128_sqrt) + + +
+ + + + + +## Function `max` + +Return the larger of x and y + + +
public fun max(x: u128, y: u128): u128
+
+ + + +
+Implementation + + +
public fun max(x: u128, y: u128): u128 {
+    std::macros::num_max!(x, y)
+}
+
+ + + +
+ + + +## Function `min` + +Return the smaller of x and y + + +
public fun min(x: u128, y: u128): u128
+
+ + + +
+Implementation + + +
public fun min(x: u128, y: u128): u128 {
+    std::macros::num_min!(x, y)
+}
+
+ + + +
+ + + +## Function `diff` + +Return the absolute value of x - y + + +
public fun diff(x: u128, y: u128): u128
+
+ + + +
+Implementation + + +
public fun diff(x: u128, y: u128): u128 {
+    std::macros::num_diff!(x, y)
+}
+
+ + + +
+ + + +## Function `divide_and_round_up` + +Calculate x / y, but round up the result. + + +
public fun divide_and_round_up(x: u128, y: u128): u128
+
+ + + +
+Implementation + + +
public fun divide_and_round_up(x: u128, y: u128): u128 {
+    std::macros::num_divide_and_round_up!(x, y)
+}
+
+ + + +
+ + + +## Function `pow` + +Return the value of a base raised to a power + + +
public fun pow(base: u128, exponent: u8): u128
+
+ + + +
+Implementation + + +
public fun pow(base: u128, exponent: u8): u128 {
+    std::macros::num_pow!(base, exponent)
+}
+
+ + + +
+ + + +## Function `sqrt` + +Get a nearest lower integer Square Root for x. Given that this +function can only operate with integers, it is impossible +to get perfect (or precise) integer square root for some numbers. + +Example: +``` +math::sqrt(9) => 3 +math::sqrt(8) => 2 // the nearest lower square root is 4; +``` + +In integer math, one of the possible ways to get results with more +precision is to use higher values or temporarily multiply the +value by some bigger number. Ideally if this is a square of 10 or 100. + +Example: +``` +math::sqrt(8) => 2; +math::sqrt(8 * 10000) => 282; +// now we can use this value as if it was 2.82; +// but to get the actual result, this value needs +// to be divided by 100 (because sqrt(10000)). + + +math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) +``` + + +
public fun sqrt(x: u128): u128
+
+ + + +
+Implementation + + +
public fun sqrt(x: u128): u128 {
+    std::macros::num_sqrt!<u128, u256>(x, 128)
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/u16.md b/external-crates/move/crates/move-stdlib/docs/u16.md new file mode 100644 index 0000000000000..08f849ea354fa --- /dev/null +++ b/external-crates/move/crates/move-stdlib/docs/u16.md @@ -0,0 +1,195 @@ + + + +# Module `0x1::u16` + + + +- [Function `max`](#0x1_u16_max) +- [Function `min`](#0x1_u16_min) +- [Function `diff`](#0x1_u16_diff) +- [Function `divide_and_round_up`](#0x1_u16_divide_and_round_up) +- [Function `pow`](#0x1_u16_pow) +- [Function `sqrt`](#0x1_u16_sqrt) + + +
+ + + + + +## Function `max` + +Return the larger of x and y + + +
public fun max(x: u16, y: u16): u16
+
+ + + +
+Implementation + + +
public fun max(x: u16, y: u16): u16 {
+    std::macros::num_max!(x, y)
+}
+
+ + + +
+ + + +## Function `min` + +Return the smaller of x and y + + +
public fun min(x: u16, y: u16): u16
+
+ + + +
+Implementation + + +
public fun min(x: u16, y: u16): u16 {
+    std::macros::num_min!(x, y)
+}
+
+ + + +
+ + + +## Function `diff` + +Return the absolute value of x - y + + +
public fun diff(x: u16, y: u16): u16
+
+ + + +
+Implementation + + +
public fun diff(x: u16, y: u16): u16 {
+    std::macros::num_diff!(x, y)
+}
+
+ + + +
+ + + +## Function `divide_and_round_up` + +Calculate x / y, but round up the result. + + +
public fun divide_and_round_up(x: u16, y: u16): u16
+
+ + + +
+Implementation + + +
public fun divide_and_round_up(x: u16, y: u16): u16 {
+    std::macros::num_divide_and_round_up!(x, y)
+}
+
+ + + +
+ + + +## Function `pow` + +Return the value of a base raised to a power + + +
public fun pow(base: u16, exponent: u8): u16
+
+ + + +
+Implementation + + +
public fun pow(base: u16, exponent: u8): u16 {
+    std::macros::num_pow!(base, exponent)
+}
+
+ + + +
+ + + +## Function `sqrt` + +Get a nearest lower integer Square Root for x. Given that this +function can only operate with integers, it is impossible +to get perfect (or precise) integer square root for some numbers. + +Example: +``` +math::sqrt(9) => 3 +math::sqrt(8) => 2 // the nearest lower square root is 4; +``` + +In integer math, one of the possible ways to get results with more +precision is to use higher values or temporarily multiply the +value by some bigger number. Ideally if this is a square of 10 or 100. + +Example: +``` +math::sqrt(8) => 2; +math::sqrt(8 * 10000) => 282; +// now we can use this value as if it was 2.82; +// but to get the actual result, this value needs +// to be divided by 100 (because sqrt(10000)). + + +math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) +``` + + +
public fun sqrt(x: u16): u16
+
+ + + +
+Implementation + + +
public fun sqrt(x: u16): u16 {
+    std::macros::num_sqrt!<u16, u32>(x, 16)
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/u256.md b/external-crates/move/crates/move-stdlib/docs/u256.md new file mode 100644 index 0000000000000..84ed79a1229c6 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/docs/u256.md @@ -0,0 +1,145 @@ + + + +# Module `0x1::u256` + + + +- [Function `max`](#0x1_u256_max) +- [Function `min`](#0x1_u256_min) +- [Function `diff`](#0x1_u256_diff) +- [Function `divide_and_round_up`](#0x1_u256_divide_and_round_up) +- [Function `pow`](#0x1_u256_pow) + + +
+ + + + + +## Function `max` + +Return the larger of x and y + + +
public fun max(x: u256, y: u256): u256
+
+ + + +
+Implementation + + +
public fun max(x: u256, y: u256): u256 {
+    std::macros::num_max!(x, y)
+}
+
+ + + +
+ + + +## Function `min` + +Return the smaller of x and y + + +
public fun min(x: u256, y: u256): u256
+
+ + + +
+Implementation + + +
public fun min(x: u256, y: u256): u256 {
+    std::macros::num_min!(x, y)
+}
+
+ + + +
+ + + +## Function `diff` + +Return the absolute value of x - y + + +
public fun diff(x: u256, y: u256): u256
+
+ + + +
+Implementation + + +
public fun diff(x: u256, y: u256): u256 {
+    std::macros::num_diff!(x, y)
+}
+
+ + + +
+ + + +## Function `divide_and_round_up` + +Calculate x / y, but round up the result. + + +
public fun divide_and_round_up(x: u256, y: u256): u256
+
+ + + +
+Implementation + + +
public fun divide_and_round_up(x: u256, y: u256): u256 {
+    std::macros::num_divide_and_round_up!(x, y)
+}
+
+ + + +
+ + + +## Function `pow` + +Return the value of a base raised to a power + + +
public fun pow(base: u256, exponent: u8): u256
+
+ + + +
+Implementation + + +
public fun pow(base: u256, exponent: u8): u256 {
+    std::macros::num_pow!(base, exponent)
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/u32.md b/external-crates/move/crates/move-stdlib/docs/u32.md new file mode 100644 index 0000000000000..084335a41875f --- /dev/null +++ b/external-crates/move/crates/move-stdlib/docs/u32.md @@ -0,0 +1,195 @@ + + + +# Module `0x1::u32` + + + +- [Function `max`](#0x1_u32_max) +- [Function `min`](#0x1_u32_min) +- [Function `diff`](#0x1_u32_diff) +- [Function `divide_and_round_up`](#0x1_u32_divide_and_round_up) +- [Function `pow`](#0x1_u32_pow) +- [Function `sqrt`](#0x1_u32_sqrt) + + +
+ + + + + +## Function `max` + +Return the larger of x and y + + +
public fun max(x: u32, y: u32): u32
+
+ + + +
+Implementation + + +
public fun max(x: u32, y: u32): u32 {
+    std::macros::num_max!(x, y)
+}
+
+ + + +
+ + + +## Function `min` + +Return the smaller of x and y + + +
public fun min(x: u32, y: u32): u32
+
+ + + +
+Implementation + + +
public fun min(x: u32, y: u32): u32 {
+    std::macros::num_min!(x, y)
+}
+
+ + + +
+ + + +## Function `diff` + +Return the absolute value of x - y + + +
public fun diff(x: u32, y: u32): u32
+
+ + + +
+Implementation + + +
public fun diff(x: u32, y: u32): u32 {
+    std::macros::num_diff!(x, y)
+}
+
+ + + +
+ + + +## Function `divide_and_round_up` + +Calculate x / y, but round up the result. + + +
public fun divide_and_round_up(x: u32, y: u32): u32
+
+ + + +
+Implementation + + +
public fun divide_and_round_up(x: u32, y: u32): u32 {
+    std::macros::num_divide_and_round_up!(x, y)
+}
+
+ + + +
+ + + +## Function `pow` + +Return the value of a base raised to a power + + +
public fun pow(base: u32, exponent: u8): u32
+
+ + + +
+Implementation + + +
public fun pow(base: u32, exponent: u8): u32 {
+    std::macros::num_pow!(base, exponent)
+}
+
+ + + +
+ + + +## Function `sqrt` + +Get a nearest lower integer Square Root for x. Given that this +function can only operate with integers, it is impossible +to get perfect (or precise) integer square root for some numbers. + +Example: +``` +math::sqrt(9) => 3 +math::sqrt(8) => 2 // the nearest lower square root is 4; +``` + +In integer math, one of the possible ways to get results with more +precision is to use higher values or temporarily multiply the +value by some bigger number. Ideally if this is a square of 10 or 100. + +Example: +``` +math::sqrt(8) => 2; +math::sqrt(8 * 10000) => 282; +// now we can use this value as if it was 2.82; +// but to get the actual result, this value needs +// to be divided by 100 (because sqrt(10000)). + + +math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) +``` + + +
public fun sqrt(x: u32): u32
+
+ + + +
+Implementation + + +
public fun sqrt(x: u32): u32 {
+    std::macros::num_sqrt!<u32, u64>(x, 32)
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/u64.md b/external-crates/move/crates/move-stdlib/docs/u64.md new file mode 100644 index 0000000000000..9d27a4311f1c6 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/docs/u64.md @@ -0,0 +1,195 @@ + + + +# Module `0x1::u64` + + + +- [Function `max`](#0x1_u64_max) +- [Function `min`](#0x1_u64_min) +- [Function `diff`](#0x1_u64_diff) +- [Function `divide_and_round_up`](#0x1_u64_divide_and_round_up) +- [Function `pow`](#0x1_u64_pow) +- [Function `sqrt`](#0x1_u64_sqrt) + + +
+ + + + + +## Function `max` + +Return the larger of x and y + + +
public fun max(x: u64, y: u64): u64
+
+ + + +
+Implementation + + +
public fun max(x: u64, y: u64): u64 {
+    std::macros::num_max!(x, y)
+}
+
+ + + +
+ + + +## Function `min` + +Return the smaller of x and y + + +
public fun min(x: u64, y: u64): u64
+
+ + + +
+Implementation + + +
public fun min(x: u64, y: u64): u64 {
+    std::macros::num_min!(x, y)
+}
+
+ + + +
+ + + +## Function `diff` + +Return the absolute value of x - y + + +
public fun diff(x: u64, y: u64): u64
+
+ + + +
+Implementation + + +
public fun diff(x: u64, y: u64): u64 {
+    std::macros::num_diff!(x, y)
+}
+
+ + + +
+ + + +## Function `divide_and_round_up` + +Calculate x / y, but round up the result. + + +
public fun divide_and_round_up(x: u64, y: u64): u64
+
+ + + +
+Implementation + + +
public fun divide_and_round_up(x: u64, y: u64): u64 {
+    std::macros::num_divide_and_round_up!(x, y)
+}
+
+ + + +
+ + + +## Function `pow` + +Return the value of a base raised to a power + + +
public fun pow(base: u64, exponent: u8): u64
+
+ + + +
+Implementation + + +
public fun pow(base: u64, exponent: u8): u64 {
+    std::macros::num_pow!(base, exponent)
+}
+
+ + + +
+ + + +## Function `sqrt` + +Get a nearest lower integer Square Root for x. Given that this +function can only operate with integers, it is impossible +to get perfect (or precise) integer square root for some numbers. + +Example: +``` +math::sqrt(9) => 3 +math::sqrt(8) => 2 // the nearest lower square root is 4; +``` + +In integer math, one of the possible ways to get results with more +precision is to use higher values or temporarily multiply the +value by some bigger number. Ideally if this is a square of 10 or 100. + +Example: +``` +math::sqrt(8) => 2; +math::sqrt(8 * 10000) => 282; +// now we can use this value as if it was 2.82; +// but to get the actual result, this value needs +// to be divided by 100 (because sqrt(10000)). + + +math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) +``` + + +
public fun sqrt(x: u64): u64
+
+ + + +
+Implementation + + +
public fun sqrt(x: u64): u64 {
+    std::macros::num_sqrt!<u64, u128>(x, 64)
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/u8.md b/external-crates/move/crates/move-stdlib/docs/u8.md new file mode 100644 index 0000000000000..0dc6d3b4fc02e --- /dev/null +++ b/external-crates/move/crates/move-stdlib/docs/u8.md @@ -0,0 +1,195 @@ + + + +# Module `0x1::u8` + + + +- [Function `max`](#0x1_u8_max) +- [Function `min`](#0x1_u8_min) +- [Function `diff`](#0x1_u8_diff) +- [Function `divide_and_round_up`](#0x1_u8_divide_and_round_up) +- [Function `pow`](#0x1_u8_pow) +- [Function `sqrt`](#0x1_u8_sqrt) + + +
+ + + + + +## Function `max` + +Return the larger of x and y + + +
public fun max(x: u8, y: u8): u8
+
+ + + +
+Implementation + + +
public fun max(x: u8, y: u8): u8 {
+    std::macros::num_max!(x, y)
+}
+
+ + + +
+ + + +## Function `min` + +Return the smaller of x and y + + +
public fun min(x: u8, y: u8): u8
+
+ + + +
+Implementation + + +
public fun min(x: u8, y: u8): u8 {
+    std::macros::num_min!(x, y)
+}
+
+ + + +
+ + + +## Function `diff` + +Return the absolute value of x - y + + +
public fun diff(x: u8, y: u8): u8
+
+ + + +
+Implementation + + +
public fun diff(x: u8, y: u8): u8 {
+    std::macros::num_diff!(x, y)
+}
+
+ + + +
+ + + +## Function `divide_and_round_up` + +Calculate x / y, but round up the result. + + +
public fun divide_and_round_up(x: u8, y: u8): u8
+
+ + + +
+Implementation + + +
public fun divide_and_round_up(x: u8, y: u8): u8 {
+    std::macros::num_divide_and_round_up!(x, y)
+}
+
+ + + +
+ + + +## Function `pow` + +Return the value of a base raised to a power + + +
public fun pow(base: u8, exponent: u8): u8
+
+ + + +
+Implementation + + +
public fun pow(base: u8, exponent: u8): u8 {
+    std::macros::num_pow!(base, exponent)
+}
+
+ + + +
+ + + +## Function `sqrt` + +Get a nearest lower integer Square Root for x. Given that this +function can only operate with integers, it is impossible +to get perfect (or precise) integer square root for some numbers. + +Example: +``` +math::sqrt(9) => 3 +math::sqrt(8) => 2 // the nearest lower square root is 4; +``` + +In integer math, one of the possible ways to get results with more +precision is to use higher values or temporarily multiply the +value by some bigger number. Ideally if this is a square of 10 or 100. + +Example: +``` +math::sqrt(8) => 2; +math::sqrt(8 * 10000) => 282; +// now we can use this value as if it was 2.82; +// but to get the actual result, this value needs +// to be divided by 100 (because sqrt(10000)). + + +math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) +``` + + +
public fun sqrt(x: u8): u8
+
+ + + +
+Implementation + + +
public fun sqrt(x: u8): u8 {
+    std::macros::num_sqrt!<u8, u16>(x, 8)
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") diff --git a/external-crates/move/crates/move-stdlib/docs/vector.md b/external-crates/move/crates/move-stdlib/docs/vector.md index be96fad8c4044..1e13e7dc46eaf 100644 --- a/external-crates/move/crates/move-stdlib/docs/vector.md +++ b/external-crates/move/crates/move-stdlib/docs/vector.md @@ -41,7 +41,7 @@ vectors are growable. This module has many native functions. The index into the vector is out of bounds -
const EINDEX_OUT_OF_BOUNDS: u64 = 131072;
+
const EINDEX_OUT_OF_BOUNDS: u64 = 131072;
 
@@ -62,7 +62,7 @@ Create an empty vector. Implementation -
native public fun empty<Element>(): vector<Element>;
+
public native fun empty<Element>(): vector<Element>;
 
@@ -76,7 +76,7 @@ Create an empty vector. Return the length of the vector. -
public fun length<Element>(v: &vector<Element>): u64
+
public fun length<Element>(v: &vector<Element>): u64
 
@@ -85,7 +85,7 @@ Return the length of the vector. Implementation -
native public fun length<Element>(v: &vector<Element>): u64;
+
public native fun length<Element>(v: &vector<Element>): u64;
 
@@ -100,7 +100,7 @@ Acquire an immutable reference to the ith element of the vector i
is out of bounds. -
public fun borrow<Element>(v: &vector<Element>, i: u64): &Element
+
public fun borrow<Element>(v: &vector<Element>, i: u64): &Element
 
@@ -109,7 +109,7 @@ Aborts if i is out of bounds. Implementation -
native public fun borrow<Element>(v: &vector<Element>, i: u64): ∈
+
public native fun borrow<Element>(v: &vector<Element>, i: u64): ∈
 
@@ -132,7 +132,7 @@ Add element e to the end of the vector v. Implementation -
native public fun push_back<Element>(v: &mut vector<Element>, e: Element);
+
public native fun push_back<Element>(v: &mut vector<Element>, e: Element);
 
@@ -147,7 +147,7 @@ Return a mutable reference to the ith element in the vector v Aborts if i is out of bounds. -
public fun borrow_mut<Element>(v: &mut vector<Element>, i: u64): &mut Element
+
public fun borrow_mut<Element>(v: &mut vector<Element>, i: u64): &mut Element
 
@@ -156,7 +156,7 @@ Aborts if i is out of bounds. Implementation -
native public fun borrow_mut<Element>(v: &mut vector<Element>, i: u64): &mut Element;
+
public native fun borrow_mut<Element>(v: &mut vector<Element>, i: u64): &mut Element;
 
@@ -180,7 +180,7 @@ Aborts if v is empty. Implementation -
native public fun pop_back<Element>(v: &mut vector<Element>): Element;
+
public native fun pop_back<Element>(v: &mut vector<Element>): Element;
 
@@ -204,7 +204,7 @@ Aborts if v is not empty. Implementation -
native public fun destroy_empty<Element>(v: vector<Element>);
+
public native fun destroy_empty<Element>(v: vector<Element>);
 
@@ -219,7 +219,7 @@ Swaps the elements at the ith and jth indices in the v Aborts if i or j is out of bounds. -
public fun swap<Element>(v: &mut vector<Element>, i: u64, j: u64)
+
public fun swap<Element>(v: &mut vector<Element>, i: u64, j: u64)
 
@@ -228,7 +228,7 @@ Aborts if i or j is out of bounds. Implementation -
native public fun swap<Element>(v: &mut vector<Element>, i: u64, j: u64);
+
public native fun swap<Element>(v: &mut vector<Element>, i: u64, j: u64);
 
@@ -252,8 +252,8 @@ Return an vector of size one containing element e.
public fun singleton<Element>(e: Element): vector<Element> {
-    let v = empty();
-    push_back(&mut v, e);
+    let mut v = empty();
+    v.push_back(e);
     v
 }
 
@@ -279,13 +279,13 @@ Reverses the order of the elements in the vector v in place.
public fun reverse<Element>(v: &mut vector<Element>) {
-    let len = length(v);
+    let len = v.length();
     if (len == 0) return ();
 
-    let front_index = 0;
-    let back_index = len -1;
+    let mut front_index = 0;
+    let mut back_index = len - 1;
     while (front_index < back_index) {
-        swap(v, front_index, back_index);
+        v.swap(front_index, back_index);
         front_index = front_index + 1;
         back_index = back_index - 1;
     }
@@ -312,10 +312,10 @@ Pushes all of the elements of the other vector into the lhsImplementation
 
 
-
public fun append<Element>(lhs: &mut vector<Element>, other: vector<Element>) {
-    reverse(&mut other);
-    while (!is_empty(&other)) push_back(lhs, pop_back(&mut other));
-    destroy_empty(other);
+
public fun append<Element>(lhs: &mut vector<Element>, mut other: vector<Element>) {
+    other.reverse();
+    while (!other.is_empty()) lhs.push_back(other.pop_back());
+    other.destroy_empty();
 }
 
@@ -340,7 +340,7 @@ Return true if the vector v has no elements and
public fun is_empty<Element>(v: &vector<Element>): bool {
-    length(v) == 0
+    v.length() == 0
 }
 
@@ -366,10 +366,10 @@ Otherwise, returns false.
public fun contains<Element>(v: &vector<Element>, e: &Element): bool {
-    let i = 0;
-    let len = length(v);
+    let mut i = 0;
+    let len = v.length();
     while (i < len) {
-        if (borrow(v, i) == e) return true;
+        if (&v[i] == e) return true;
         i = i + 1;
     };
     false
@@ -388,7 +388,7 @@ Return (true, i) if e is in the vector v<
 Otherwise, returns (false, 0).
 
 
-
public fun index_of<Element>(v: &vector<Element>, e: &Element): (bool, u64)
+
public fun index_of<Element>(v: &vector<Element>, e: &Element): (bool, u64)
 
@@ -397,11 +397,11 @@ Otherwise, returns (false, 0). Implementation -
public fun index_of<Element>(v: &vector<Element>, e: &Element): (bool, u64) {
-    let i = 0;
-    let len = length(v);
+
public fun index_of<Element>(v: &vector<Element>, e: &Element): (bool, u64) {
+    let mut i = 0;
+    let len = v.length();
     while (i < len) {
-        if (borrow(v, i) == e) return (true, i);
+        if (&v[i] == e) return (true, i);
         i = i + 1;
     };
     (false, 0)
@@ -421,7 +421,7 @@ This is O(n) and preserves ordering of elements in the vector.
 Aborts if i is out of bounds.
 
 
-
public fun remove<Element>(v: &mut vector<Element>, i: u64): Element
+
public fun remove<Element>(v: &mut vector<Element>, i: u64): Element
 
@@ -430,14 +430,14 @@ Aborts if i is out of bounds. Implementation -
public fun remove<Element>(v: &mut vector<Element>, i: u64): Element {
-    let len = length(v);
+
public fun remove<Element>(v: &mut vector<Element>, mut i: u64): Element {
+    let mut len = v.length();
     // i out of bounds; abort
     if (i >= len) abort EINDEX_OUT_OF_BOUNDS;
 
     len = len - 1;
-    while (i < len) swap(v, i, { i = i + 1; i });
-    pop_back(v)
+    while (i < len) v.swap(i, { i = i + 1; i });
+    v.pop_back()
 }
 
@@ -451,12 +451,12 @@ Aborts if i is out of bounds. Insert e at position i in the vector v. If i is in bounds, this shifts the old v[i] and all subsequent elements to the right. -If i == length(v), this adds e to the end of the vector. +If i == v.length(), this adds e to the end of the vector. This is O(n) and preserves ordering of elements in the vector. -Aborts if i > length(v) +Aborts if i > v.length() -
public fun insert<Element>(v: &mut vector<Element>, e: Element, i: u64)
+
public fun insert<Element>(v: &mut vector<Element>, e: Element, i: u64)
 
@@ -465,14 +465,14 @@ Aborts if i > length(v)Implementation -
public fun insert<Element>(v: &mut vector<Element>, e: Element, i: u64) {
-    let len = length(v);
+
public fun insert<Element>(v: &mut vector<Element>, e: Element, mut i: u64) {
+    let len = v.length();
     // i too big abort
     if (i > len) abort EINDEX_OUT_OF_BOUNDS;
 
-    push_back(v, e);
+    v.push_back(e);
     while (i < len) {
-        swap(v, i, len);
+        v.swap(i, len);
         i = i + 1
     }
 }
@@ -491,7 +491,7 @@ This is O(1), but does not preserve ordering of elements in the vector.
 Aborts if i is out of bounds.
 
 
-
public fun swap_remove<Element>(v: &mut vector<Element>, i: u64): Element
+
public fun swap_remove<Element>(v: &mut vector<Element>, i: u64): Element
 
@@ -500,11 +500,11 @@ Aborts if i is out of bounds. Implementation -
public fun swap_remove<Element>(v: &mut vector<Element>, i: u64): Element {
-    assert!(!is_empty(v), EINDEX_OUT_OF_BOUNDS);
-    let last_idx = length(v) - 1;
-    swap(v, i, last_idx);
-    pop_back(v)
+
public fun swap_remove<Element>(v: &mut vector<Element>, i: u64): Element {
+    assert!(!v.is_empty(), EINDEX_OUT_OF_BOUNDS);
+    let last_idx = v.length() - 1;
+    v.swap(i, last_idx);
+    v.pop_back()
 }
 
diff --git a/external-crates/move/crates/move-stdlib/error_description.errmap b/external-crates/move/crates/move-stdlib/error_description.errmap deleted file mode 100644 index e278809587b0938d92310bc82416685344e3b14e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1310 zcmcJP(Qnf*5XO_S4KXn$#2ye&C*TDk?Ew(tVM5AUZ!_wWs!b>0B}tQOYbmvZ<8*_+ zo{Qs7(_ou;Ac_# z87vNV{)mu{)e=+U7A1l(P%l(d7BD59P)SS=e8;l4W(lMCzrk3^zrt9|`wi@j-sno| zdAnCdoy5nVUR$^pKN@8O zN&_^U4Z_8`b&XO`W_pf5#!@RUkXpK(6-b+pAJPXd+#Wld3}QYU@Ltf4*=HMc*_1|9 zr69ZhE$pVt?&%d}a`Y|v&PLHI2%r!vQMc1L{b_T$d30 - -# Module `0x1::compare` - -Utilities for comparing Move values based on their representation in BCS. - - -- [Constants](#@Constants_0) -- [Function `cmp_bcs_bytes`](#0x1_compare_cmp_bcs_bytes) -- [Function `cmp_u8`](#0x1_compare_cmp_u8) -- [Function `cmp_u64`](#0x1_compare_cmp_u64) - - -
- - - - - -## Constants - - - - - - -
const EQUAL: u8 = 0;
-
- - - - - - - -
const GREATER_THAN: u8 = 2;
-
- - - - - - - -
const LESS_THAN: u8 = 1;
-
- - - - - -## Function `cmp_bcs_bytes` - -compare vectors v1 and v2 using (1) vector contents from right to left and then -(2) vector length to break ties. -Returns either EQUAL (0u8), LESS_THAN (1u8), or GREATER_THAN (2u8). - -This function is designed to compare BCS (Binary Canonical Serialization)-encoded values -(i.e., vectors produced by bcs::to_bytes). A typical client will call -compare::cmp_bcs_bytes(bcs::to_bytes(&t1), bcs::to_bytes(&t2)). The comparison provides the -following guarantees w.r.t the original values t1 and t2: -- cmp_bcs_bytes(bcs(t1), bcs(t2)) == LESS_THAN iff cmp_bcs_bytes(t2, t1) == GREATER_THAN -- compare::cmp<T>(t1, t2) == EQUAL iff t1 == t2 and (similarly) -compare::cmp<T>(t1, t2) != EQUAL iff t1 != t2, where == and != denote the Move -bytecode operations for polymorphic equality. -- for all primitive types T with < and > comparison operators exposed in Move bytecode -(u8, u16, u32, u64, u128, u256), we have -compare_bcs_bytes(bcs(t1), bcs(t2)) == LESS_THAN iff t1 < t2 and (similarly) -compare_bcs_bytes(bcs(t1), bcs(t2)) == LESS_THAN iff t1 > t2. - -For all other types, the order is whatever the BCS encoding of the type and the comparison -strategy above gives you. One case where the order might be surprising is the address -type. -CoreAddresses are 16 byte hex values that BCS encodes with the identity function. The right -to left, byte-by-byte comparison means that (for example) -compare_bcs_bytes(bcs(0x01), bcs(0x10)) == LESS_THAN (as you'd expect), but -compare_bcs_bytes(bcs(0x100), bcs(0x001)) == LESS_THAN (as you probably wouldn't expect). -Keep this in mind when using this function to compare addresses. - - -
public fun cmp_bcs_bytes(v1: &vector<u8>, v2: &vector<u8>): u8
-
- - - -
-Implementation - - -
public fun cmp_bcs_bytes(v1: &vector<u8>, v2: &vector<u8>): u8 {
-    let i1 = vector::length(v1);
-    let i2 = vector::length(v2);
-    let len_cmp = cmp_u64(i1, i2);
-
-    // BCS uses little endian encoding for all integer types, so we choose to compare from left
-    // to right. Going right to left would make the behavior of compare::cmp diverge from the
-    // bytecode operators < and > on integer values (which would be confusing).
-    while (i1 > 0 && i2 > 0) {
-        i1 = i1 - 1;
-        i2 = i2 - 1;
-        let elem_cmp = cmp_u8(*vector::borrow(v1, i1), *vector::borrow(v2, i2));
-        if (elem_cmp != 0) return elem_cmp
-        // else, compare next element
-    };
-    // all compared elements equal; use length comparion to break the tie
-    len_cmp
-}
-
- - - -
- - - -## Function `cmp_u8` - -Compare two u8's - - -
fun cmp_u8(i1: u8, i2: u8): u8
-
- - - -
-Implementation - - -
fun cmp_u8(i1: u8, i2: u8): u8 {
-    if (i1 == i2) EQUAL
-    else if (i1 < i2) LESS_THAN
-    else GREATER_THAN
-}
-
- - - -
- - - -## Function `cmp_u64` - -Compare two u64's - - -
fun cmp_u64(i1: u64, i2: u64): u8
-
- - - -
-Implementation - - -
fun cmp_u64(i1: u64, i2: u64): u8 {
-    if (i1 == i2) EQUAL
-    else if (i1 < i2) LESS_THAN
-    else GREATER_THAN
-}
-
- - - -
diff --git a/external-crates/move/crates/move-stdlib/nursery/sources/compare.move b/external-crates/move/crates/move-stdlib/nursery/sources/compare.move deleted file mode 100644 index 04238e4c2afe7..0000000000000 --- a/external-crates/move/crates/move-stdlib/nursery/sources/compare.move +++ /dev/null @@ -1,70 +0,0 @@ -/// Utilities for comparing Move values based on their representation in BCS. -module std::compare { - use std::vector; - - // Move does not have signed integers, so we cannot use the usual 0, -1, 1 convention to - // represent EQUAL, LESS_THAN, and GREATER_THAN. Instead, we fun a new convention using u8 - // constants: - const EQUAL: u8 = 0; - const LESS_THAN: u8 = 1; - const GREATER_THAN: u8 = 2; - - /// compare vectors `v1` and `v2` using (1) vector contents from right to left and then - /// (2) vector length to break ties. - /// Returns either `EQUAL` (0u8), `LESS_THAN` (1u8), or `GREATER_THAN` (2u8). - /// - /// This function is designed to compare BCS (Binary Canonical Serialization)-encoded values - /// (i.e., vectors produced by `bcs::to_bytes`). A typical client will call - /// `compare::cmp_bcs_bytes(bcs::to_bytes(&t1), bcs::to_bytes(&t2))`. The comparison provides the - /// following guarantees w.r.t the original values t1 and t2: - /// - `cmp_bcs_bytes(bcs(t1), bcs(t2)) == LESS_THAN` iff `cmp_bcs_bytes(t2, t1) == GREATER_THAN` - /// - `compare::cmp(t1, t2) == EQUAL` iff `t1 == t2` and (similarly) - /// `compare::cmp(t1, t2) != EQUAL` iff `t1 != t2`, where `==` and `!=` denote the Move - /// bytecode operations for polymorphic equality. - /// - for all primitive types `T` with `<` and `>` comparison operators exposed in Move bytecode - /// (`u8`, `u16`, `u32`, `u64`, `u128`, `u256`), we have - /// `compare_bcs_bytes(bcs(t1), bcs(t2)) == LESS_THAN` iff `t1 < t2` and (similarly) - /// `compare_bcs_bytes(bcs(t1), bcs(t2)) == LESS_THAN` iff `t1 > t2`. - /// - /// For all other types, the order is whatever the BCS encoding of the type and the comparison - /// strategy above gives you. One case where the order might be surprising is the `address` - /// type. - /// CoreAddresses are 16 byte hex values that BCS encodes with the identity function. The right - /// to left, byte-by-byte comparison means that (for example) - /// `compare_bcs_bytes(bcs(0x01), bcs(0x10)) == LESS_THAN` (as you'd expect), but - /// `compare_bcs_bytes(bcs(0x100), bcs(0x001)) == LESS_THAN` (as you probably wouldn't expect). - /// Keep this in mind when using this function to compare addresses. - public fun cmp_bcs_bytes(v1: &vector, v2: &vector): u8 { - let i1 = vector::length(v1); - let i2 = vector::length(v2); - let len_cmp = cmp_u64(i1, i2); - - // BCS uses little endian encoding for all integer types, so we choose to compare from left - // to right. Going right to left would make the behavior of compare::cmp diverge from the - // bytecode operators < and > on integer values (which would be confusing). - while (i1 > 0 && i2 > 0) { - i1 = i1 - 1; - i2 = i2 - 1; - let elem_cmp = cmp_u8(*vector::borrow(v1, i1), *vector::borrow(v2, i2)); - if (elem_cmp != 0) return elem_cmp - // else, compare next element - }; - // all compared elements equal; use length comparion to break the tie - len_cmp - } - - /// Compare two `u8`'s - fun cmp_u8(i1: u8, i2: u8): u8 { - if (i1 == i2) EQUAL - else if (i1 < i2) LESS_THAN - else GREATER_THAN - } - - /// Compare two `u64`'s - fun cmp_u64(i1: u64, i2: u64): u8 { - if (i1 == i2) EQUAL - else if (i1 < i2) LESS_THAN - else GREATER_THAN - } - -} diff --git a/external-crates/move/crates/move-stdlib/nursery/sources/debug.move b/external-crates/move/crates/move-stdlib/nursery/sources/debug.move deleted file mode 100644 index d4a506d10f5dd..0000000000000 --- a/external-crates/move/crates/move-stdlib/nursery/sources/debug.move +++ /dev/null @@ -1,18 +0,0 @@ -/// Module providing debug functionality. -module std::debug { - - /// Pretty-prints any Move value. For a Move struct, includes its field names, their types and their values. - native public fun print(x: &T); - - /// Prints the calling function's stack trace. - native public fun print_stack_trace(); - - #[test_only] - use std::string; - - #[test_only] - /// Utility function for printing a sequence of UTF8 bytes as a string (e.g., `b"Hello"`). - public fun print_string(utf8_bytes: vector) { - print(&string::utf8(utf8_bytes)); - } -} diff --git a/external-crates/move/crates/move-stdlib/nursery/tests/compare_tests.move b/external-crates/move/crates/move-stdlib/nursery/tests/compare_tests.move deleted file mode 100644 index 4af198639ffd0..0000000000000 --- a/external-crates/move/crates/move-stdlib/nursery/tests/compare_tests.move +++ /dev/null @@ -1,86 +0,0 @@ -// Tests for polymorphic comparison in Move -#[test_only] -module std::compareTests { - use std::compare; - use std::bcs; - - const EQUAL: u8 = 0; - const LESS_THAN: u8 = 1; - const GREATER_THAN: u8 = 2; - - - #[test] - fun equality_of_simple_types() { - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&true), &bcs::to_bytes(&true)) == EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u8), &bcs::to_bytes(&1u8)) == EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u16), &bcs::to_bytes(&1u16)) == EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u32), &bcs::to_bytes(&1u32)) == EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1), &bcs::to_bytes(&1)) == EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u128), &bcs::to_bytes(&1u128)) == EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u256), &bcs::to_bytes(&1u256)) == EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&@0x1), &bcs::to_bytes(&@0x1)) == EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"01"), &bcs::to_bytes(&x"01")) == EQUAL, 0); - } - - #[test] - fun inequality_of_simple_types() { - // inequality of simple types - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&true), &bcs::to_bytes(&false)) != EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u8), &bcs::to_bytes(&0u8)) != EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u16), &bcs::to_bytes(&0u16)) != EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u32), &bcs::to_bytes(&0u32)) != EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1), &bcs::to_bytes(&0)) != EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u128), &bcs::to_bytes(&0u128)) != EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u256), &bcs::to_bytes(&0u256)) != EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&@0x1), &bcs::to_bytes(&@0x0)) != EQUAL, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"01"), &bcs::to_bytes(&x"00")) != EQUAL, 0); - } - - #[test] - fun less_than_with_natural_ordering() { - // less than for types with a natural ordering exposed via bytecode operations - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&false), &bcs::to_bytes(&true)) == LESS_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&0u8), &bcs::to_bytes(&1u8)) == LESS_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&0u16), &bcs::to_bytes(&1u16)) == LESS_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&0u32), &bcs::to_bytes(&1u32)) == LESS_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&0), &bcs::to_bytes(&1)) == LESS_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&0u128), &bcs::to_bytes(&1u128)) == LESS_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&0u256), &bcs::to_bytes(&1u256)) == LESS_THAN, 0); - } - - #[test] - fun less_than_without_natural_ordering() { - // less then for types without a natural ordering exposed by bytecode operations - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&@0x0), &bcs::to_bytes(&@0x1)) == LESS_THAN, 0); // sensible - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&@0x01), &bcs::to_bytes(&@0x10)) == LESS_THAN, 0); // sensible - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&@0x100), &bcs::to_bytes(&@0x001)) == LESS_THAN, 0); // potentially confusing - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"00"), &bcs::to_bytes(&x"01")) == LESS_THAN, 0); // sensible - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"01"), &bcs::to_bytes(&x"10")) == LESS_THAN, 0); // sensible - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"0000"), &bcs::to_bytes(&x"01")) == LESS_THAN, 0); // - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"0100"), &bcs::to_bytes(&x"0001")) == LESS_THAN, 0); // potentially confusing - } - - #[test] - fun greater_than_with_natural_ordering() { - // greater than for types with a natural ordering exposed by bytecode operations - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&true), &bcs::to_bytes(&false)) == GREATER_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u8), &bcs::to_bytes(&0u8)) == GREATER_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u16), &bcs::to_bytes(&0u16)) == GREATER_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u32), &bcs::to_bytes(&0u32)) == GREATER_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1), &bcs::to_bytes(&0)) == GREATER_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u128), &bcs::to_bytes(&0u128)) == GREATER_THAN, 0); - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&1u256), &bcs::to_bytes(&0u256)) == GREATER_THAN, 0); - } - - #[test] - fun greater_than_without_natural_ordering() { - // greater than for types without a natural ordering exposed by by bytecode operations - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&@0x1), &bcs::to_bytes(&@0x0)) == GREATER_THAN, 0); // sensible - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&@0x10), &bcs::to_bytes(&@0x01)) == GREATER_THAN, 0); // sensible - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&@0x001), &bcs::to_bytes(&@0x100)) == GREATER_THAN, 0); // potentially confusing - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"01"), &bcs::to_bytes(&x"00")) == GREATER_THAN, 0); // sensible - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"10"), &bcs::to_bytes(&x"01")) == GREATER_THAN, 0); // sensible - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"01"), &bcs::to_bytes(&x"0000")) == GREATER_THAN, 0); // sensible - assert!(compare::cmp_bcs_bytes(&bcs::to_bytes(&x"0001"), &bcs::to_bytes(&x"0100")) == GREATER_THAN, 0); // potentially confusing - } -} diff --git a/external-crates/move/crates/move-stdlib/sources/address.move b/external-crates/move/crates/move-stdlib/sources/address.move new file mode 100644 index 0000000000000..ec1416b4473bf --- /dev/null +++ b/external-crates/move/crates/move-stdlib/sources/address.move @@ -0,0 +1,12 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +/// Provides a way to get address length since it's a +/// platform-specific parameter. +module std::address { + /// Should be converted to a native function. + /// Current implementation only works for Sui. + public fun length(): u64 { + 32 + } +} diff --git a/external-crates/move/crates/move-stdlib/sources/ascii.move b/external-crates/move/crates/move-stdlib/sources/ascii.move index 95e05588b4be4..60564b49893a1 100644 --- a/external-crates/move/crates/move-stdlib/sources/ascii.move +++ b/external-crates/move/crates/move-stdlib/sources/ascii.move @@ -1,107 +1,166 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + /// The `ASCII` module defines basic string and char newtypes in Move that verify /// that characters are valid ASCII, and that strings consist of only valid ASCII characters. module std::ascii { - use std::vector; - use std::option::{Self, Option}; + // Allows calling `.to_string()` to convert an `ascii::String` into as `string::String` + public use fun std::string::from_ascii as String.to_string; /// An invalid ASCII character was encountered when creating an ASCII string. - const EINVALID_ASCII_CHARACTER: u64 = 0x10000; - - /// The `String` struct holds a vector of bytes that all represent - /// valid ASCII characters. Note that these ASCII characters may not all - /// be printable. To determine if a `String` contains only "printable" - /// characters you should use the `all_characters_printable` predicate - /// defined in this module. - struct String has copy, drop, store { - bytes: vector, - } - - /// An ASCII character. - struct Char has copy, drop, store { - byte: u8, - } + const EInvalidASCIICharacter: u64 = 0x10000; + /// An invalid index was encountered when creating a substring. + const EInvalidIndex: u64 = 0x10001; + + /// The `String` struct holds a vector of bytes that all represent + /// valid ASCII characters. Note that these ASCII characters may not all + /// be printable. To determine if a `String` contains only "printable" + /// characters you should use the `all_characters_printable` predicate + /// defined in this module. + public struct String has copy, drop, store { + bytes: vector, + } + + /// An ASCII character. + public struct Char has copy, drop, store { + byte: u8, + } /// Convert a `byte` into a `Char` that is checked to make sure it is valid ASCII. public fun char(byte: u8): Char { - assert!(is_valid_char(byte), EINVALID_ASCII_CHARACTER); + assert!(is_valid_char(byte), EInvalidASCIICharacter); Char { byte } } /// Convert a vector of bytes `bytes` into an `String`. Aborts if /// `bytes` contains non-ASCII characters. public fun string(bytes: vector): String { - let x = try_string(bytes); - assert!( - option::is_some(&x), - EINVALID_ASCII_CHARACTER - ); - option::destroy_some(x) + let x = try_string(bytes); + assert!(x.is_some(), EInvalidASCIICharacter); + x.destroy_some() } /// Convert a vector of bytes `bytes` into an `String`. Returns /// `Some()` if the `bytes` contains all valid ASCII /// characters. Otherwise returns `None`. public fun try_string(bytes: vector): Option { - let len = vector::length(&bytes); - let i = 0; - while (i < len) { - let possible_byte = *vector::borrow(&bytes, i); - if (!is_valid_char(possible_byte)) return option::none(); - i = i + 1; - }; - option::some(String { bytes }) + let is_valid = bytes.all!(|byte| is_valid_char(*byte)); + if (is_valid) option::some(String { bytes }) + else option::none() } /// Returns `true` if all characters in `string` are printable characters /// Returns `false` otherwise. Not all `String`s are printable strings. public fun all_characters_printable(string: &String): bool { - let len = vector::length(&string.bytes); - let i = 0; - while (i < len) { - let byte = *vector::borrow(&string.bytes, i); - if (!is_printable_char(byte)) return false; - i = i + 1; - }; - true + string.bytes.all!(|byte| is_printable_char(*byte)) } + /// Push a `Char` to the end of the `string`. public fun push_char(string: &mut String, char: Char) { - vector::push_back(&mut string.bytes, char.byte); + string.bytes.push_back(char.byte); } + /// Pop a `Char` from the end of the `string`. public fun pop_char(string: &mut String): Char { - Char { byte: vector::pop_back(&mut string.bytes) } + Char { byte: string.bytes.pop_back() } } + /// Returns the length of the `string` in bytes. public fun length(string: &String): u64 { - vector::length(as_bytes(string)) + string.as_bytes().length() + } + + /// Append the `other` string to the end of `string`. + public fun append(string: &mut String, other: String) { + string.bytes.append(other.into_bytes()) + } + + /// Insert the `other` string at the `at` index of `string`. + public fun insert(s: &mut String, at: u64, o: String) { + assert!(at <= s.length(), EInvalidIndex); + o.into_bytes().destroy!(|e| s.bytes.insert(e, at)); + } + + /// Copy the slice of the `string` from `i` to `j` into a new `String`. + public fun substring(string: &String, i: u64, j: u64): String { + assert!(i <= j && j <= string.length(), EInvalidIndex); + let mut bytes = vector[]; + i.range_do!(j, |i| bytes.push_back(string.bytes[i])); + String { bytes } } /// Get the inner bytes of the `string` as a reference public fun as_bytes(string: &String): &vector { - &string.bytes + &string.bytes } /// Unpack the `string` to get its backing bytes public fun into_bytes(string: String): vector { - let String { bytes } = string; - bytes + let String { bytes } = string; + bytes } - /// Unpack the `char` into its underlying byte. + /// Unpack the `char` into its underlying bytes. public fun byte(char: Char): u8 { - let Char { byte } = char; - byte + let Char { byte } = char; + byte } - /// Returns `true` if `b` is a valid ASCII character. Returns `false` otherwise. + /// Returns `true` if `b` is a valid ASCII character. + /// Returns `false` otherwise. public fun is_valid_char(b: u8): bool { - b <= 0x7F + b <= 0x7F } - /// Returns `true` if `byte` is an printable ASCII character. Returns `false` otherwise. + /// Returns `true` if `byte` is an printable ASCII character. + /// Returns `false` otherwise. public fun is_printable_char(byte: u8): bool { - byte >= 0x20 && // Disallow metacharacters - byte <= 0x7E // Don't allow DEL metacharacter + byte >= 0x20 && // Disallow metacharacters + byte <= 0x7E // Don't allow DEL metacharacter + } + + /// Returns `true` if `string` is empty. + public fun is_empty(string: &String): bool { + string.bytes.is_empty() + } + + /// Convert a `string` to its uppercase equivalent. + public fun to_uppercase(string: &String): String { + let bytes = string.as_bytes().map_ref!(|byte| char_to_uppercase(*byte)); + String { bytes } + } + + /// Convert a `string` to its lowercase equivalent. + public fun to_lowercase(string: &String): String { + let bytes = string.as_bytes().map_ref!(|byte| char_to_lowercase(*byte)); + String { bytes } + } + + /// Computes the index of the first occurrence of the `substr` in the `string`. + /// Returns the length of the `string` if the `substr` is not found. + /// Returns 0 if the `substr` is empty. + public fun index_of(string: &String, substr: &String): u64 { + let mut i = 0; + let (n, m) = (string.length(), substr.length()); + if (n < m) return n; + while (i <= n - m) { + let mut j = 0; + while (j < m && string.bytes[i + j] == substr.bytes[j]) j = j + 1; + if (j == m) return i; + i = i + 1; + }; + n + } + + /// Convert a `char` to its lowercase equivalent. + fun char_to_uppercase(byte: u8): u8 { + if (byte >= 0x61 && byte <= 0x7A) byte - 0x20 + else byte + } + + /// Convert a `char` to its lowercase equivalent. + fun char_to_lowercase(byte: u8): u8 { + if (byte >= 0x41 && byte <= 0x5A) byte + 0x20 + else byte } } diff --git a/external-crates/move/crates/move-stdlib/sources/bcs.move b/external-crates/move/crates/move-stdlib/sources/bcs.move index edac0cff2f19e..8e07273cf1ee5 100644 --- a/external-crates/move/crates/move-stdlib/sources/bcs.move +++ b/external-crates/move/crates/move-stdlib/sources/bcs.move @@ -1,3 +1,6 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + /// Utility for converting a Move value to its binary representation in BCS (Binary Canonical /// Serialization). BCS is the binary encoding for Move resources and other non-module values /// published on-chain. See https://github.com/diem/bcs#binary-canonical-serialization-bcs for more diff --git a/external-crates/move/crates/move-stdlib/sources/bit_vector.move b/external-crates/move/crates/move-stdlib/sources/bit_vector.move index ddf3b99b3fda1..354b72c492872 100644 --- a/external-crates/move/crates/move-stdlib/sources/bit_vector.move +++ b/external-crates/move/crates/move-stdlib/sources/bit_vector.move @@ -1,17 +1,18 @@ -module std::bit_vector { - use std::vector; +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +module std::bit_vector { /// The provided index is out of bounds const EINDEX: u64 = 0x20000; /// An invalid length of bitvector was given const ELENGTH: u64 = 0x20001; - #[test_only] + #[allow(unused_const)] const WORD_SIZE: u64 = 1; /// The maximum allowed bitvector size const MAX_SIZE: u64 = 1024; - struct BitVector has copy, drop, store { + public struct BitVector has copy, drop, store { length: u64, bit_field: vector, } @@ -19,10 +20,10 @@ module std::bit_vector { public fun new(length: u64): BitVector { assert!(length > 0, ELENGTH); assert!(length < MAX_SIZE, ELENGTH); - let counter = 0; - let bit_field = vector::empty(); + let mut counter = 0; + let mut bit_field = vector::empty(); while (counter < length) { - vector::push_back(&mut bit_field, false); + bit_field.push_back(false); counter = counter + 1; }; @@ -34,15 +35,15 @@ module std::bit_vector { /// Set the bit at `bit_index` in the `bitvector` regardless of its previous state. public fun set(bitvector: &mut BitVector, bit_index: u64) { - assert!(bit_index < vector::length(&bitvector.bit_field), EINDEX); - let x = vector::borrow_mut(&mut bitvector.bit_field, bit_index); + assert!(bit_index < bitvector.bit_field.length(), EINDEX); + let x = &mut bitvector.bit_field[bit_index]; *x = true; } /// Unset the bit at `bit_index` in the `bitvector` regardless of its previous state. public fun unset(bitvector: &mut BitVector, bit_index: u64) { - assert!(bit_index < vector::length(&bitvector.bit_field), EINDEX); - let x = vector::borrow_mut(&mut bitvector.bit_field, bit_index); + assert!(bit_index < bitvector.bit_field.length(), EINDEX); + let x = &mut bitvector.bit_field[bit_index]; *x = false; } @@ -50,19 +51,19 @@ module std::bit_vector { /// bitvector's length the bitvector will be zeroed out. public fun shift_left(bitvector: &mut BitVector, amount: u64) { if (amount >= bitvector.length) { - let len = vector::length(&bitvector.bit_field); - let i = 0; + let len = bitvector.bit_field.length(); + let mut i = 0; while (i < len) { - let elem = vector::borrow_mut(&mut bitvector.bit_field, i); + let elem = &mut bitvector.bit_field[i]; *elem = false; i = i + 1; }; } else { - let i = amount; + let mut i = amount; while (i < bitvector.length) { - if (is_index_set(bitvector, i)) set(bitvector, i - amount) - else unset(bitvector, i - amount); + if (bitvector.is_index_set(i)) bitvector.set(i - amount) + else bitvector.unset(i - amount); i = i + 1; }; @@ -78,13 +79,13 @@ module std::bit_vector { /// Return the value of the bit at `bit_index` in the `bitvector`. `true` /// represents "1" and `false` represents a 0 public fun is_index_set(bitvector: &BitVector, bit_index: u64): bool { - assert!(bit_index < vector::length(&bitvector.bit_field), EINDEX); - *vector::borrow(&bitvector.bit_field, bit_index) + assert!(bit_index < bitvector.bit_field.length(), EINDEX); + bitvector.bit_field[bit_index] } /// Return the length (number of usable bits) of this bitvector public fun length(bitvector: &BitVector): u64 { - vector::length(&bitvector.bit_field) + bitvector.bit_field.length() } /// Returns the length of the longest sequence of set bits starting at (and @@ -92,11 +93,11 @@ module std::bit_vector { /// sequence, then `0` is returned. public fun longest_set_sequence_starting_at(bitvector: &BitVector, start_index: u64): u64 { assert!(start_index < bitvector.length, EINDEX); - let index = start_index; + let mut index = start_index; // Find the greatest index in the vector such that all indices less than it are set. while (index < bitvector.length) { - if (!is_index_set(bitvector, index)) break; + if (!bitvector.is_index_set(index)) break; index = index + 1; }; diff --git a/external-crates/move/crates/move-stdlib/sources/debug.move b/external-crates/move/crates/move-stdlib/sources/debug.move new file mode 100644 index 0000000000000..dc9d236a8d07d --- /dev/null +++ b/external-crates/move/crates/move-stdlib/sources/debug.move @@ -0,0 +1,9 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +/// Module providing debug functionality. +module std::debug { + native public fun print(x: &T); + + native public fun print_stack_trace(); +} diff --git a/external-crates/move/crates/move-stdlib/sources/error.move b/external-crates/move/crates/move-stdlib/sources/error.move deleted file mode 100644 index 81958a6914eb4..0000000000000 --- a/external-crates/move/crates/move-stdlib/sources/error.move +++ /dev/null @@ -1,82 +0,0 @@ -/// This module defines a set of canonical error codes which are optional to use by applications for the -/// `abort` and `assert!` features. -/// -/// Canonical error codes use the 3 lowest bytes of the u64 abort code range (the upper 5 bytes are free for other use). -/// Of those, the highest byte represents the *error category* and the lower two bytes the *error reason*. -/// Given an error category `0x1` and a reason `0x3`, a canonical abort code looks as `0x10003`. -/// -/// A module can use a canonical code with a constant declaration of the following form: -/// -/// ``` -/// /// An invalid ASCII character was encountered when creating a string. -/// const EINVALID_CHARACTER: u64 = 0x010003; -/// ``` -/// -/// This code is both valid in the worlds with and without canonical errors. It can be used as a plain module local -/// error reason understand by the existing error map tooling, or as a canonical code. -/// -/// The actual canonical categories have been adopted from Google's canonical error codes, which in turn are derived -/// from Unix error codes [see here](https://cloud.google.com/apis/design/errors#handling_errors). Each code has an -/// associated HTTP error code which can be used in REST apis. The mapping from error code to http code is not 1:1; -/// error codes here are a bit richer than HTTP codes. -module std::error { - - /// Caller specified an invalid argument (http: 400) - const INVALID_ARGUMENT: u64 = 0x1; - - /// An input or result of a computation is out of range (http: 400) - const OUT_OF_RANGE: u64 = 0x2; - - /// The system is not in a state where the operation can be performed (http: 400) - const INVALID_STATE: u64 = 0x3; - - /// Request not authenticated due to missing, invalid, or expired auth token (http: 401) - const UNAUTHENTICATED: u64 = 0x4; - - /// client does not have sufficient permission (http: 403) - const PERMISSION_DENIED: u64 = 0x5; - - /// A specified resource is not found (http: 404) - const NOT_FOUND: u64 = 0x6; - - /// Concurrency conflict, such as read-modify-write conflict (http: 409) - const ABORTED: u64 = 0x7; - - /// The resource that a client tried to create already exists (http: 409) - const ALREADY_EXISTS: u64 = 0x8; - - /// Out of gas or other forms of quota (http: 429) - const RESOURCE_EXHAUSTED: u64 = 0x9; - - #[allow(unused_const)] - /// Request cancelled by the client (http: 499) - const CANCELLED: u64 = 0xA; - - /// Internal error (http: 500) - const INTERNAL: u64 = 0xB; - - /// Feature not implemented (http: 501) - const NOT_IMPLEMENTED: u64 = 0xC; - - /// The service is currently unavailable. Indicates that a retry could solve the issue (http: 503) - const UNAVAILABLE: u64 = 0xD; - - /// Construct a canonical error code from a category and a reason. - public fun canonical(category: u64, reason: u64): u64 { - (category << 16) + reason - } - - /// Functions to construct a canonical error code of the given category. - public fun invalid_argument(r: u64): u64 { canonical(INVALID_ARGUMENT, r) } - public fun out_of_range(r: u64): u64 { canonical(OUT_OF_RANGE, r) } - public fun invalid_state(r: u64): u64 { canonical(INVALID_STATE, r) } - public fun unauthenticated(r: u64): u64 { canonical(UNAUTHENTICATED, r) } - public fun permission_denied(r: u64): u64 { canonical(PERMISSION_DENIED, r) } - public fun not_found(r: u64): u64 { canonical(NOT_FOUND, r) } - public fun aborted(r: u64): u64 { canonical(ABORTED, r) } - public fun already_exists(r: u64): u64 { canonical(ALREADY_EXISTS, r) } - public fun resource_exhausted(r: u64): u64 { canonical(RESOURCE_EXHAUSTED, r) } - public fun internal(r: u64): u64 { canonical(INTERNAL, r) } - public fun not_implemented(r: u64): u64 { canonical(NOT_IMPLEMENTED, r) } - public fun unavailable(r: u64): u64 { canonical(UNAVAILABLE, r) } -} diff --git a/external-crates/move/crates/move-stdlib/sources/fixed_point32.move b/external-crates/move/crates/move-stdlib/sources/fixed_point32.move index 40cee62aeaefd..d25eb58ed3b1c 100644 --- a/external-crates/move/crates/move-stdlib/sources/fixed_point32.move +++ b/external-crates/move/crates/move-stdlib/sources/fixed_point32.move @@ -1,3 +1,6 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + /// Defines a fixed-point numeric type with a 32-bit integer part and /// a 32-bit fractional part. @@ -12,7 +15,7 @@ module std::fixed_point32 { /// floating-point has less than 16 decimal digits of precision, so /// be careful about using floating-point to convert these values to /// decimal. - struct FixedPoint32 has copy, drop, store { value: u64 } + public struct FixedPoint32 has copy, drop, store { value: u64 } ///> TODO: This is a basic constant and should be provided somewhere centrally in the framework. const MAX_U64: u128 = 18446744073709551615; @@ -35,13 +38,13 @@ module std::fixed_point32 { // The product of two 64 bit values has 128 bits, so perform the // multiplication with u128 types and keep the full 128 bit product // to avoid losing accuracy. - let unscaled_product = (val as u128) * (multiplier.value as u128); + let unscaled_product = val as u128 * (multiplier.value as u128); // The unscaled product has 32 fractional bits (from the multiplier) // so rescale it by shifting away the low bits. let product = unscaled_product >> 32; // Check whether the value is too large. assert!(product <= MAX_U64, EMULTIPLICATION); - (product as u64) + product as u64 } /// Divide a u64 integer by a fixed-point number, truncating any @@ -52,13 +55,13 @@ module std::fixed_point32 { assert!(divisor.value != 0, EDIVISION_BY_ZERO); // First convert to 128 bits and then shift left to // add 32 fractional zero bits to the dividend. - let scaled_value = (val as u128) << 32; + let scaled_value = val as u128 << 32; let quotient = scaled_value / (divisor.value as u128); // Check whether the value is too large. assert!(quotient <= MAX_U64, EDIVISION); // the value may be too large, which will cause the cast to fail // with an arithmetic error. - (quotient as u64) + quotient as u64 } /// Create a fixed-point value from a rational number specified by its @@ -76,15 +79,15 @@ module std::fixed_point32 { // Scale the numerator to have 64 fractional bits and the denominator // to have 32 fractional bits, so that the quotient will have 32 // fractional bits. - let scaled_numerator = (numerator as u128) << 64; - let scaled_denominator = (denominator as u128) << 32; + let scaled_numerator = numerator as u128 << 64; + let scaled_denominator = denominator as u128 << 32; assert!(scaled_denominator != 0, EDENOMINATOR); let quotient = scaled_numerator / scaled_denominator; assert!(quotient != 0 || numerator == 0, ERATIO_OUT_OF_RANGE); // Return the quotient as a fixed-point number. We first need to check whether the cast // can succeed. assert!(quotient <= MAX_U64, ERATIO_OUT_OF_RANGE); - FixedPoint32 { value: (quotient as u64) } + FixedPoint32 { value: quotient as u64 } } /// Create a fixedpoint value from a raw value. @@ -103,55 +106,4 @@ module std::fixed_point32 { public fun is_zero(num: FixedPoint32): bool { num.value == 0 } - - /// Returns the smaller of the two FixedPoint32 numbers. - public fun min(num1: FixedPoint32, num2: FixedPoint32): FixedPoint32 { - if (num1.value < num2.value) { - num1 - } else { - num2 - } - } - - /// Returns the larger of the two FixedPoint32 numbers. - public fun max(num1: FixedPoint32, num2: FixedPoint32): FixedPoint32 { - if (num1.value > num2.value) { - num1 - } else { - num2 - } - } - - /// Create a fixedpoint value from a u64 value. - public fun create_from_u64(val: u64): FixedPoint32 { - let value = (val as u128) << 32; - assert!(value <= MAX_U64, ERATIO_OUT_OF_RANGE); - FixedPoint32{value: (value as u64)} - } - - /// Returns the largest integer less than or equal to a given number. - public fun floor(num: FixedPoint32): u64 { - num.value >> 32 - } - - /// Rounds up the given FixedPoint32 to the next largest integer. - public fun ceil(num: FixedPoint32): u64 { - let floored_num = floor(num) << 32; - if (num.value == floored_num) { - return floored_num >> 32 - }; - let val = ((floored_num as u128) + (1 << 32)); - (val >> 32 as u64) - } - - /// Returns the value of a FixedPoint32 to the nearest integer. - public fun round(num: FixedPoint32): u64 { - let floored_num = floor(num) << 32; - let boundary = floored_num + ((1 << 32) / 2); - if (num.value < boundary) { - floored_num >> 32 - } else { - ceil(num) - } - } } diff --git a/external-crates/move/crates/move-stdlib/sources/hash.move b/external-crates/move/crates/move-stdlib/sources/hash.move index daadc4e815770..ed84f18a9a7fc 100644 --- a/external-crates/move/crates/move-stdlib/sources/hash.move +++ b/external-crates/move/crates/move-stdlib/sources/hash.move @@ -1,3 +1,6 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + /// Module which defines SHA hashes for byte vectors. /// /// The functions in this module are natively declared both in the Move runtime diff --git a/external-crates/move/crates/move-stdlib/sources/macros.move b/external-crates/move/crates/move-stdlib/sources/macros.move new file mode 100644 index 0000000000000..53416703f5c9c --- /dev/null +++ b/external-crates/move/crates/move-stdlib/sources/macros.move @@ -0,0 +1,102 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +/// This module holds shared implementation of macros used in `std` +module std::macros { + public macro fun num_max($x: _, $y: _): _ { + let x = $x; + let y = $y; + if (x > y) x + else y + } + + public macro fun num_min($x: _, $y: _): _ { + let x = $x; + let y = $y; + if (x < y) x + else y + } + + public macro fun num_diff($x: _, $y: _): _ { + let x = $x; + let y = $y; + if (x > y) x - y + else y - x + } + + public macro fun num_divide_and_round_up($x: _, $y: _): _ { + let x = $x; + let y = $y; + if (x % y == 0) x / y + else x / y + 1 + } + + + public macro fun num_pow($base: _, $exponent: u8): _ { + let mut base = $base; + let mut exponent = $exponent; + let mut res = 1; + while (exponent >= 1) { + if (exponent % 2 == 0) { + base = base * base; + exponent = exponent / 2; + } else { + res = res * base; + exponent = exponent - 1; + } + }; + + res + } + + public macro fun num_sqrt<$T, $U>($x: $T, $bitsize: u8): $T { + let x = $x; + let mut bit = (1: $U) << $bitsize; + let mut res = (0: $U); + let mut x = x as $U; + + while (bit != 0) { + if (x >= res + bit) { + x = x - (res + bit); + res = (res >> 1) + bit; + } else { + res = res >> 1; + }; + bit = bit >> 2; + }; + + res as $T + } + + public macro fun range_do($start: _, $stop: _, $f: |_|) { + let mut i = $start; + let stop = $stop; + while (i < stop) { + $f(i); + i = i + 1; + } + } + + public macro fun range_do_eq($start: _, $stop: _, $f: |_|) { + let mut i = $start; + let stop = $stop; + // we check `i >= stop` inside the loop instead of `i <= stop` as `while` condition to avoid + // incrementing `i` past the MAX integer value. + // Because of this, we need to check if `i > stop` and return early--instead of letting the + // loop bound handle it, like in the `range_do` macro. + if (i > stop) return; + loop { + $f(i); + if (i >= stop) break; + i = i + 1; + } + } + + public macro fun do($stop: _, $f: |_|) { + range_do!(0, $stop, $f) + } + + public macro fun do_eq($stop: _, $f: |_|) { + range_do_eq!(0, $stop, $f) + } +} diff --git a/external-crates/move/crates/move-stdlib/sources/option.move b/external-crates/move/crates/move-stdlib/sources/option.move index 1de18126613bc..b0f1862c91ba5 100644 --- a/external-crates/move/crates/move-stdlib/sources/option.move +++ b/external-crates/move/crates/move-stdlib/sources/option.move @@ -1,10 +1,11 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + /// This module defines the Option type and its methods to represent and handle an optional value. module std::option { - use std::vector; - /// Abstraction of a value that may or may not be present. Implemented with a vector of size /// zero or one because Move bytecode does not have ADTs. - struct Option has copy, drop, store { + public struct Option has copy, drop, store { vec: vector } @@ -27,33 +28,33 @@ module std::option { /// Return true if `t` does not hold a value public fun is_none(t: &Option): bool { - vector::is_empty(&t.vec) + t.vec.is_empty() } /// Return true if `t` holds a value public fun is_some(t: &Option): bool { - !vector::is_empty(&t.vec) + !t.vec.is_empty() } /// Return true if the value in `t` is equal to `e_ref` /// Always returns `false` if `t` does not hold a value public fun contains(t: &Option, e_ref: &Element): bool { - vector::contains(&t.vec, e_ref) + t.vec.contains(e_ref) } /// Return an immutable reference to the value inside `t` /// Aborts if `t` does not hold a value public fun borrow(t: &Option): &Element { - assert!(is_some(t), EOPTION_NOT_SET); - vector::borrow(&t.vec, 0) + assert!(t.is_some(), EOPTION_NOT_SET); + &t.vec[0] } /// Return a reference to the value inside `t` if it holds one /// Return `default_ref` if `t` does not hold a value public fun borrow_with_default(t: &Option, default_ref: &Element): &Element { let vec_ref = &t.vec; - if (vector::is_empty(vec_ref)) default_ref - else vector::borrow(vec_ref, 0) + if (vec_ref.is_empty()) default_ref + else &vec_ref[0] } /// Return the value inside `t` if it holds one @@ -63,39 +64,39 @@ module std::option { default: Element, ): Element { let vec_ref = &t.vec; - if (vector::is_empty(vec_ref)) default - else *vector::borrow(vec_ref, 0) + if (vec_ref.is_empty()) default + else vec_ref[0] } /// Convert the none option `t` to a some option by adding `e`. /// Aborts if `t` already holds a value public fun fill(t: &mut Option, e: Element) { let vec_ref = &mut t.vec; - if (vector::is_empty(vec_ref)) vector::push_back(vec_ref, e) + if (vec_ref.is_empty()) vec_ref.push_back(e) else abort EOPTION_IS_SET } /// Convert a `some` option to a `none` by removing and returning the value stored inside `t` /// Aborts if `t` does not hold a value public fun extract(t: &mut Option): Element { - assert!(is_some(t), EOPTION_NOT_SET); - vector::pop_back(&mut t.vec) + assert!(t.is_some(), EOPTION_NOT_SET); + t.vec.pop_back() } /// Return a mutable reference to the value inside `t` /// Aborts if `t` does not hold a value public fun borrow_mut(t: &mut Option): &mut Element { - assert!(is_some(t), EOPTION_NOT_SET); - vector::borrow_mut(&mut t.vec, 0) + assert!(t.is_some(), EOPTION_NOT_SET); + &mut t.vec[0] } /// Swap the old value inside `t` with `e` and return the old value /// Aborts if `t` does not hold a value public fun swap(t: &mut Option, e: Element): Element { - assert!(is_some(t), EOPTION_NOT_SET); + assert!(t.is_some(), EOPTION_NOT_SET); let vec_ref = &mut t.vec; - let old_value = vector::pop_back(vec_ref); - vector::push_back(vec_ref, e); + let old_value = vec_ref.pop_back(); + vec_ref.push_back(e); old_value } @@ -104,41 +105,136 @@ module std::option { /// Different from swap(), swap_or_fill() allows for `t` not holding a value. public fun swap_or_fill(t: &mut Option, e: Element): Option { let vec_ref = &mut t.vec; - let old_value = if (vector::is_empty(vec_ref)) none() - else some(vector::pop_back(vec_ref)); - vector::push_back(vec_ref, e); + let old_value = if (vec_ref.is_empty()) none() + else some(vec_ref.pop_back()); + vec_ref.push_back(e); old_value } /// Destroys `t.` If `t` holds a value, return it. Returns `default` otherwise public fun destroy_with_default(t: Option, default: Element): Element { - let Option { vec } = t; - if (vector::is_empty(&vec)) default - else vector::pop_back(&mut vec) + let Option { mut vec } = t; + if (vec.is_empty()) default + else vec.pop_back() } /// Unpack `t` and return its contents /// Aborts if `t` does not hold a value public fun destroy_some(t: Option): Element { - assert!(is_some(&t), EOPTION_NOT_SET); - let Option { vec } = t; - let elem = vector::pop_back(&mut vec); - vector::destroy_empty(vec); + assert!(t.is_some(), EOPTION_NOT_SET); + let Option { mut vec } = t; + let elem = vec.pop_back(); + vec.destroy_empty(); elem } /// Unpack `t` /// Aborts if `t` holds a value public fun destroy_none(t: Option) { - assert!(is_none(&t), EOPTION_IS_SET); + assert!(t.is_none(), EOPTION_IS_SET); let Option { vec } = t; - vector::destroy_empty(vec) + vec.destroy_empty() } - /// Convert `t` into a vector of length 1 if it is `Some`, /// and an empty vector otherwise public fun to_vec(t: Option): vector { let Option { vec } = t; vec } + + // === Macro Functions === + + /// Destroy `Option` and call the closure `f` on the value inside if it holds one. + public macro fun destroy<$T>($o: Option<$T>, $f: |$T|) { + let o = $o; + o.do!($f); + } + + /// Destroy `Option` and call the closure `f` on the value inside if it holds one. + public macro fun do<$T>($o: Option<$T>, $f: |$T|) { + let o = $o; + if (o.is_some()) { + $f(o.destroy_some()); + } + } + + /// Execute a closure on the value inside `t` if it holds one. + public macro fun do_ref<$T>($o: &Option<$T>, $f: |&$T|) { + let o = $o; + if (o.is_some()) { + $f(o.borrow()); + } + } + + /// Execute a closure on the mutable reference to the value inside `t` if it holds one. + public macro fun do_mut<$T>($o: &mut Option<$T>, $f: |&mut $T|) { + let o = $o; + if (o.is_some()) $f(o.borrow_mut()); + } + + /// Select the first `Some` value from the two options, or `None` if both are `None`. + /// Equivalent to Rust's `a.or(b)`. + public macro fun or<$T>($o: Option<$T>, $default: Option<$T>): Option<$T> { + let o = $o; + if (o.is_some()) o + else $default + } + + /// If the value is `Some`, call the closure `f` on it. Otherwise, return `None`. + /// Equivalent to Rust's `t.and_then(f)`. + public macro fun and<$T, $U>($o: Option<$T>, $f: |$T| -> Option<$U>): Option<$U> { + let o = $o; + if (o.is_some()) $f(o.extract()) + else none() + } + + /// If the value is `Some`, call the closure `f` on it. Otherwise, return `None`. + /// Equivalent to Rust's `t.and_then(f)`. + public macro fun and_ref<$T, $U>($o: &Option<$T>, $f: |&$T| -> Option<$U>): Option<$U> { + let o = $o; + if (o.is_some()) $f(o.borrow()) + else none() + } + + /// Map an `Option` to `Option` by applying a function to a contained value. + /// Equivalent to Rust's `t.map(f)`. + public macro fun map<$T, $U>($o: Option<$T>, $f: |$T| -> $U): Option<$U> { + let mut o = $o; + if (o.is_some()) some($f(o.extract())) + else none() + } + + /// Map an `Option` value to `Option` by applying a function to a contained value by reference. + /// Original `Option` is preserved. + /// Equivalent to Rust's `t.map(f)`. + public macro fun map_ref<$T, $U>($o: &Option<$T>, $f: |&$T| -> $U): Option<$U> { + let o = $o; + if (o.is_some()) some($f(o.borrow())) + else none() + } + + /// Return `None` if the value is `None`, otherwise return `Option` if the predicate `f` returns true. + public macro fun filter<$T: drop>($o: Option<$T>, $f: |&$T| -> bool): Option<$T> { + let o = $o; + if (o.is_some() && $f(o.borrow())) o + else none() + } + + /// Return `false` if the value is `None`, otherwise return the result of the predicate `f`. + public macro fun is_some_and<$T>($o: &Option<$T>, $f: |&$T| -> bool): bool { + let o = $o; + o.is_some() && $f(o.borrow()) + } + + /// Destroy `Option` and return the value inside if it holds one, or `default` otherwise. + /// Equivalent to Rust's `t.unwrap_or(default)`. + /// + /// Note: this function is a more efficient version of `destroy_with_default`, as it does not + /// evaluate the default value unless necessary. The `destroy_with_default` function should be + /// deprecated in favor of this function. + public macro fun destroy_or<$T>($o: Option<$T>, $default: $T): $T { + let o = $o; + if (o.is_some()) o.destroy_some() + else $default + } } diff --git a/external-crates/move/crates/move-stdlib/sources/signer.move b/external-crates/move/crates/move-stdlib/sources/signer.move deleted file mode 100644 index 55376dd3fff7e..0000000000000 --- a/external-crates/move/crates/move-stdlib/sources/signer.move +++ /dev/null @@ -1,15 +0,0 @@ -module std::signer { - // Borrows the address of the signer - // Conceptually, you can think of the `signer` as being a struct wrapper arround an - // address - // ``` - // struct signer has drop { addr: address } - // ``` - // `borrow_address` borrows this inner field - native public fun borrow_address(s: &signer): &address; - - // Copies the address of the signer - public fun address_of(s: &signer): address { - *borrow_address(s) - } -} diff --git a/external-crates/move/crates/move-stdlib/sources/string.move b/external-crates/move/crates/move-stdlib/sources/string.move index fa9f6b61b7967..0939b2cbe45f3 100644 --- a/external-crates/move/crates/move-stdlib/sources/string.move +++ b/external-crates/move/crates/move-stdlib/sources/string.move @@ -1,101 +1,137 @@ -/// The `string` module defines the `String` type which represents UTF8 encoded strings. +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +/// The `string` module defines the `String` type which represents UTF8 encoded +/// strings. module std::string { - use std::vector; - use std::option::{Self, Option}; + use std::ascii; /// An invalid UTF8 encoding. - const EINVALID_UTF8: u64 = 1; + const EInvalidUTF8: u64 = 1; /// Index out of range. - const EINVALID_INDEX: u64 = 2; + const EInvalidIndex: u64 = 2; - /// A `String` holds a sequence of bytes which is guaranteed to be in utf8 format. - struct String has copy, drop, store { + /// A `String` holds a sequence of bytes which is guaranteed to be in utf8 + /// format. + public struct String has copy, drop, store { bytes: vector, } - /// Creates a new string from a sequence of bytes. Aborts if the bytes do not represent valid utf8. + /// Creates a new string from a sequence of bytes. Aborts if the bytes do + /// not represent valid utf8. public fun utf8(bytes: vector): String { - assert!(internal_check_utf8(&bytes), EINVALID_UTF8); - String{bytes} + assert!(internal_check_utf8(&bytes), EInvalidUTF8); + String { bytes } + } + + /// Convert an ASCII string to a UTF8 string + public fun from_ascii(s: ascii::String): String { + String { bytes: s.into_bytes() } + } + + /// Convert an UTF8 string to an ASCII string. + /// Aborts if `s` is not valid ASCII + public fun to_ascii(s: String): ascii::String { + let String { bytes } = s; + bytes.to_ascii_string() } /// Tries to create a new string from a sequence of bytes. public fun try_utf8(bytes: vector): Option { - if (internal_check_utf8(&bytes)) { - option::some(String{bytes}) - } else { - option::none() - } + if (internal_check_utf8(&bytes)) option::some(String { bytes }) + else option::none() } /// Returns a reference to the underlying byte vector. - public fun bytes(s: &String): &vector { + public fun as_bytes(s: &String): &vector { &s.bytes } + /// Unpack the `string` to get its underlying bytes. + public fun into_bytes(s: String): vector { + let String { bytes } = s; + bytes + } + /// Checks whether this string is empty. public fun is_empty(s: &String): bool { - vector::is_empty(&s.bytes) + s.bytes.is_empty() } /// Returns the length of this string, in bytes. public fun length(s: &String): u64 { - vector::length(&s.bytes) + s.bytes.length() } /// Appends a string. public fun append(s: &mut String, r: String) { - vector::append(&mut s.bytes, r.bytes) + s.bytes.append(r.bytes) } /// Appends bytes which must be in valid utf8 format. public fun append_utf8(s: &mut String, bytes: vector) { - append(s, utf8(bytes)) + s.append(utf8(bytes)) } - /// Insert the other string at the byte index in given string. The index must be at a valid utf8 char - /// boundary. + /// Insert the other string at the byte index in given string. The index + /// must be at a valid utf8 char boundary. public fun insert(s: &mut String, at: u64, o: String) { let bytes = &s.bytes; - assert!(at <= vector::length(bytes) && internal_is_char_boundary(bytes, at), EINVALID_INDEX); - let l = length(s); - let front = sub_string(s, 0, at); - let end = sub_string(s, at, l); - append(&mut front, o); - append(&mut front, end); + assert!( + at <= bytes.length() && internal_is_char_boundary(bytes, at), + EInvalidIndex, + ); + let l = s.length(); + let mut front = s.substring(0, at); + let end = s.substring(at, l); + front.append(o); + front.append(end); *s = front; } - /// Returns a sub-string using the given byte indices, where `i` is the first byte position and `j` is the start - /// of the first byte not included (or the length of the string). The indices must be at valid utf8 char boundaries, + /// Returns a sub-string using the given byte indices, where `i` is the first + /// byte position and `j` is the start of the first byte not included (or the + /// length of the string). The indices must be at valid utf8 char boundaries, /// guaranteeing that the result is valid utf8. - public fun sub_string(s: &String, i: u64, j: u64): String { + public fun substring(s: &String, i: u64, j: u64): String { let bytes = &s.bytes; - let l = vector::length(bytes); + let l = bytes.length(); assert!( - j <= l && i <= j && internal_is_char_boundary(bytes, i) && internal_is_char_boundary(bytes, j), - EINVALID_INDEX + j <= l && + i <= j && + internal_is_char_boundary(bytes, i) && + internal_is_char_boundary(bytes, j), + EInvalidIndex, ); - String{bytes: internal_sub_string(bytes, i, j)} + String { bytes: internal_sub_string(bytes, i, j) } } - /// Computes the index of the first occurrence of a string. Returns `length(s)` if no occurrence found. + /// Computes the index of the first occurrence of a string. Returns `s.length()` + /// if no occurrence found. public fun index_of(s: &String, r: &String): u64 { internal_index_of(&s.bytes, &r.bytes) } - // Native API + native fun internal_check_utf8(v: &vector): bool; native fun internal_is_char_boundary(v: &vector, i: u64): bool; native fun internal_sub_string(v: &vector, i: u64, j: u64): vector; native fun internal_index_of(v: &vector, r: &vector): u64; - // Test only API for the native function. Don't return a value so other - // tests aren't tempted to use this function. #[test_only] - public fun internal_sub_string_for_testing(v: &vector, i: u64, j: u64) { - internal_sub_string(v, i, j); + public fun internal_sub_string_for_testing(v: &vector, i: u64, j: u64): vector { + internal_sub_string(v, i, j) + } + + // === Deprecated === + + #[deprecated(note = b"Use `std::string::as_bytes` instead.")] + public fun bytes(s: &String): &vector { s.as_bytes() } + + #[deprecated(note = b"Use `std::string::substring` instead.")] + public fun sub_string(s: &String, i: u64, j: u64): String { + s.substring(i, j) } } diff --git a/external-crates/move/crates/move-stdlib/sources/type_name.move b/external-crates/move/crates/move-stdlib/sources/type_name.move index f439a64182b01..70cc4407a8c5c 100644 --- a/external-crates/move/crates/move-stdlib/sources/type_name.move +++ b/external-crates/move/crates/move-stdlib/sources/type_name.move @@ -1,16 +1,39 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + /// Functionality for converting Move types into values. Use with care! module std::type_name { - use std::ascii::String; + use std::ascii::{Self, String}; + use std::address; + + /// ASCII Character code for the `:` (colon) symbol. + const ASCII_COLON: u8 = 58; + + /// ASCII Character code for the `v` (lowercase v) symbol. + const ASCII_V: u8 = 118; + /// ASCII Character code for the `e` (lowercase e) symbol. + const ASCII_E: u8 = 101; + /// ASCII Character code for the `c` (lowercase c) symbol. + const ASCII_C: u8 = 99; + /// ASCII Character code for the `t` (lowercase t) symbol. + const ASCII_T: u8 = 116; + /// ASCII Character code for the `o` (lowercase o) symbol. + const ASCII_O: u8 = 111; + /// ASCII Character code for the `r` (lowercase r) symbol. + const ASCII_R: u8 = 114; + + /// The type is not from a package/module. It is a primitive type. + const ENonModuleType: u64 = 0; - struct TypeName has copy, drop, store { + public struct TypeName has copy, drop, store { /// String representation of the type. All types are represented /// using their source syntax: - /// "u8", "u64", "u128", "bool", "address", "vector", "signer" for ground types. + /// "u8", "u64", "bool", "address", "vector", and so on for primitive types. /// Struct types are represented as fully qualified type names; e.g. /// `00000000000000000000000000000001::string::String` or /// `0000000000000000000000000000000a::module_name1::type_name1<0000000000000000000000000000000a::module_name2::type_name2>` /// Addresses are hex-encoded lowercase values of length ADDRESS_LENGTH (16, 20, or 32 depending on the Move platform) - name: String + name: String, } /// Return a value representation of the type `T`. Package IDs @@ -26,11 +49,77 @@ module std::type_name { /// later upgrade). public native fun get_with_original_ids(): TypeName; + /// Returns true iff the TypeName represents a primitive type, i.e. one of + /// u8, u16, u32, u64, u128, u256, bool, address, vector. + public fun is_primitive(self: &TypeName): bool { + let bytes = self.name.as_bytes(); + bytes == &b"bool" || + bytes == &b"u8" || + bytes == &b"u16" || + bytes == &b"u32" || + bytes == &b"u64" || + bytes == &b"u128" || + bytes == &b"u256" || + bytes == &b"address" || + ( + bytes.length() >= 6 && + bytes[0] == ASCII_V && + bytes[1] == ASCII_E && + bytes[2] == ASCII_C && + bytes[3] == ASCII_T && + bytes[4] == ASCII_O && + bytes[5] == ASCII_R, + ) + } + /// Get the String representation of `self` public fun borrow_string(self: &TypeName): &String { &self.name } + /// Get Address string (Base16 encoded), first part of the TypeName. + /// Aborts if given a primitive type. + public fun get_address(self: &TypeName): String { + assert!(!self.is_primitive(), ENonModuleType); + + // Base16 (string) representation of an address has 2 symbols per byte. + let len = address::length() * 2; + let str_bytes = self.name.as_bytes(); + let mut addr_bytes = vector[]; + let mut i = 0; + + // Read `len` bytes from the type name and push them to addr_bytes. + while (i < len) { + addr_bytes.push_back(str_bytes[i]); + i = i + 1; + }; + + ascii::string(addr_bytes) + } + + /// Get name of the module. + /// Aborts if given a primitive type. + public fun get_module(self: &TypeName): String { + assert!(!self.is_primitive(), ENonModuleType); + + // Starts after address and a double colon: `::` + let mut i = address::length() * 2 + 2; + let str_bytes = self.name.as_bytes(); + let mut module_name = vector[]; + let colon = ASCII_COLON; + loop { + let char = &str_bytes[i]; + if (char != &colon) { + module_name.push_back(*char); + i = i + 1; + } else { + break + } + }; + + ascii::string(module_name) + } + /// Convert `self` into its inner String public fun into_string(self: TypeName): String { self.name diff --git a/external-crates/move/crates/move-stdlib/sources/u128.move b/external-crates/move/crates/move-stdlib/sources/u128.move new file mode 100644 index 0000000000000..947c330085ca1 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/sources/u128.move @@ -0,0 +1,79 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[defines_primitive(u128)] +module std::u128 { + /// Return the larger of `x` and `y` + public fun max(x: u128, y: u128): u128 { + std::macros::num_max!(x, y) + } + + /// Return the smaller of `x` and `y` + public fun min(x: u128, y: u128): u128 { + std::macros::num_min!(x, y) + } + + /// Return the absolute value of x - y + public fun diff(x: u128, y: u128): u128 { + std::macros::num_diff!(x, y) + } + + /// Calculate x / y, but round up the result. + public fun divide_and_round_up(x: u128, y: u128): u128 { + std::macros::num_divide_and_round_up!(x, y) + } + + /// Return the value of a base raised to a power + public fun pow(base: u128, exponent: u8): u128 { + std::macros::num_pow!(base, exponent) + } + + /// Get a nearest lower integer Square Root for `x`. Given that this + /// function can only operate with integers, it is impossible + /// to get perfect (or precise) integer square root for some numbers. + /// + /// Example: + /// ``` + /// math::sqrt(9) => 3 + /// math::sqrt(8) => 2 // the nearest lower square root is 4; + /// ``` + /// + /// In integer math, one of the possible ways to get results with more + /// precision is to use higher values or temporarily multiply the + /// value by some bigger number. Ideally if this is a square of 10 or 100. + /// + /// Example: + /// ``` + /// math::sqrt(8) => 2; + /// math::sqrt(8 * 10000) => 282; + /// // now we can use this value as if it was 2.82; + /// // but to get the actual result, this value needs + /// // to be divided by 100 (because sqrt(10000)). + /// + /// + /// math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + /// ``` + public fun sqrt(x: u128): u128 { + std::macros::num_sqrt!(x, 128) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (exclusive) + public macro fun range_do($start: u128, $stop: u128, $f: |u128|) { + std::macros::range_do!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (inclusive) + public macro fun range_do_eq($start: u128, $stop: u128, $f: |u128|) { + std::macros::range_do_eq!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (exclusive) + public macro fun do($stop: u128, $f: |u128|) { + std::macros::do!($stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (inclusive) + public macro fun do_eq($stop: u128, $f: |u128|) { + std::macros::do_eq!($stop, $f) + } +} diff --git a/external-crates/move/crates/move-stdlib/sources/u16.move b/external-crates/move/crates/move-stdlib/sources/u16.move new file mode 100644 index 0000000000000..9d051c11721dc --- /dev/null +++ b/external-crates/move/crates/move-stdlib/sources/u16.move @@ -0,0 +1,79 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[defines_primitive(u16)] +module std::u16 { + /// Return the larger of `x` and `y` + public fun max(x: u16, y: u16): u16 { + std::macros::num_max!(x, y) + } + + /// Return the smaller of `x` and `y` + public fun min(x: u16, y: u16): u16 { + std::macros::num_min!(x, y) + } + + /// Return the absolute value of x - y + public fun diff(x: u16, y: u16): u16 { + std::macros::num_diff!(x, y) + } + + /// Calculate x / y, but round up the result. + public fun divide_and_round_up(x: u16, y: u16): u16 { + std::macros::num_divide_and_round_up!(x, y) + } + + /// Return the value of a base raised to a power + public fun pow(base: u16, exponent: u8): u16 { + std::macros::num_pow!(base, exponent) + } + + /// Get a nearest lower integer Square Root for `x`. Given that this + /// function can only operate with integers, it is impossible + /// to get perfect (or precise) integer square root for some numbers. + /// + /// Example: + /// ``` + /// math::sqrt(9) => 3 + /// math::sqrt(8) => 2 // the nearest lower square root is 4; + /// ``` + /// + /// In integer math, one of the possible ways to get results with more + /// precision is to use higher values or temporarily multiply the + /// value by some bigger number. Ideally if this is a square of 10 or 100. + /// + /// Example: + /// ``` + /// math::sqrt(8) => 2; + /// math::sqrt(8 * 10000) => 282; + /// // now we can use this value as if it was 2.82; + /// // but to get the actual result, this value needs + /// // to be divided by 100 (because sqrt(10000)). + /// + /// + /// math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + /// ``` + public fun sqrt(x: u16): u16 { + std::macros::num_sqrt!(x, 16) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (exclusive) + public macro fun range_do($start: u16, $stop: u16, $f: |u16|) { + std::macros::range_do!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (inclusive) + public macro fun range_do_eq($start: u16, $stop: u16, $f: |u16|) { + std::macros::range_do_eq!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (exclusive) + public macro fun do($stop: u16, $f: |u16|) { + std::macros::do!($stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (inclusive) + public macro fun do_eq($stop: u16, $f: |u16|) { + std::macros::do_eq!($stop, $f) + } +} diff --git a/external-crates/move/crates/move-stdlib/sources/u256.move b/external-crates/move/crates/move-stdlib/sources/u256.move new file mode 100644 index 0000000000000..1c1846db661d7 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/sources/u256.move @@ -0,0 +1,50 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[defines_primitive(u256)] +module std::u256 { + /// Return the larger of `x` and `y` + public fun max(x: u256, y: u256): u256 { + std::macros::num_max!(x, y) + } + + /// Return the smaller of `x` and `y` + public fun min(x: u256, y: u256): u256 { + std::macros::num_min!(x, y) + } + + /// Return the absolute value of x - y + public fun diff(x: u256, y: u256): u256 { + std::macros::num_diff!(x, y) + } + + /// Calculate x / y, but round up the result. + public fun divide_and_round_up(x: u256, y: u256): u256 { + std::macros::num_divide_and_round_up!(x, y) + } + + /// Return the value of a base raised to a power + public fun pow(base: u256, exponent: u8): u256 { + std::macros::num_pow!(base, exponent) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (exclusive) + public macro fun range_do($start: u256, $stop: u256, $f: |u256|) { + std::macros::range_do!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (inclusive) + public macro fun range_do_eq($start: u256, $stop: u256, $f: |u256|) { + std::macros::range_do_eq!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (exclusive) + public macro fun do($stop: u256, $f: |u256|) { + std::macros::do!($stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (inclusive) + public macro fun do_eq($stop: u256, $f: |u256|) { + std::macros::do_eq!($stop, $f) + } +} diff --git a/external-crates/move/crates/move-stdlib/sources/u32.move b/external-crates/move/crates/move-stdlib/sources/u32.move new file mode 100644 index 0000000000000..8ad44d722c178 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/sources/u32.move @@ -0,0 +1,79 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[defines_primitive(u32)] +module std::u32 { + /// Return the larger of `x` and `y` + public fun max(x: u32, y: u32): u32 { + std::macros::num_max!(x, y) + } + + /// Return the smaller of `x` and `y` + public fun min(x: u32, y: u32): u32 { + std::macros::num_min!(x, y) + } + + /// Return the absolute value of x - y + public fun diff(x: u32, y: u32): u32 { + std::macros::num_diff!(x, y) + } + + /// Calculate x / y, but round up the result. + public fun divide_and_round_up(x: u32, y: u32): u32 { + std::macros::num_divide_and_round_up!(x, y) + } + + /// Return the value of a base raised to a power + public fun pow(base: u32, exponent: u8): u32 { + std::macros::num_pow!(base, exponent) + } + + /// Get a nearest lower integer Square Root for `x`. Given that this + /// function can only operate with integers, it is impossible + /// to get perfect (or precise) integer square root for some numbers. + /// + /// Example: + /// ``` + /// math::sqrt(9) => 3 + /// math::sqrt(8) => 2 // the nearest lower square root is 4; + /// ``` + /// + /// In integer math, one of the possible ways to get results with more + /// precision is to use higher values or temporarily multiply the + /// value by some bigger number. Ideally if this is a square of 10 or 100. + /// + /// Example: + /// ``` + /// math::sqrt(8) => 2; + /// math::sqrt(8 * 10000) => 282; + /// // now we can use this value as if it was 2.82; + /// // but to get the actual result, this value needs + /// // to be divided by 100 (because sqrt(10000)). + /// + /// + /// math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + /// ``` + public fun sqrt(x: u32): u32 { + std::macros::num_sqrt!(x, 32) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (exclusive) + public macro fun range_do($start: u32, $stop: u32, $f: |u32|) { + std::macros::range_do!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (inclusive) + public macro fun range_do_eq($start: u32, $stop: u32, $f: |u32|) { + std::macros::range_do_eq!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (exclusive) + public macro fun do($stop: u32, $f: |u32|) { + std::macros::do!($stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (inclusive) + public macro fun do_eq($stop: u32, $f: |u32|) { + std::macros::do_eq!($stop, $f) + } +} diff --git a/external-crates/move/crates/move-stdlib/sources/u64.move b/external-crates/move/crates/move-stdlib/sources/u64.move new file mode 100644 index 0000000000000..9963dcc1b8206 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/sources/u64.move @@ -0,0 +1,79 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[defines_primitive(u64)] +module std::u64 { + /// Return the larger of `x` and `y` + public fun max(x: u64, y: u64): u64 { + std::macros::num_max!(x, y) + } + + /// Return the smaller of `x` and `y` + public fun min(x: u64, y: u64): u64 { + std::macros::num_min!(x, y) + } + + /// Return the absolute value of x - y + public fun diff(x: u64, y: u64): u64 { + std::macros::num_diff!(x, y) + } + + /// Calculate x / y, but round up the result. + public fun divide_and_round_up(x: u64, y: u64): u64 { + std::macros::num_divide_and_round_up!(x, y) + } + + /// Return the value of a base raised to a power + public fun pow(base: u64, exponent: u8): u64 { + std::macros::num_pow!(base, exponent) + } + + /// Get a nearest lower integer Square Root for `x`. Given that this + /// function can only operate with integers, it is impossible + /// to get perfect (or precise) integer square root for some numbers. + /// + /// Example: + /// ``` + /// math::sqrt(9) => 3 + /// math::sqrt(8) => 2 // the nearest lower square root is 4; + /// ``` + /// + /// In integer math, one of the possible ways to get results with more + /// precision is to use higher values or temporarily multiply the + /// value by some bigger number. Ideally if this is a square of 10 or 100. + /// + /// Example: + /// ``` + /// math::sqrt(8) => 2; + /// math::sqrt(8 * 10000) => 282; + /// // now we can use this value as if it was 2.82; + /// // but to get the actual result, this value needs + /// // to be divided by 100 (because sqrt(10000)). + /// + /// + /// math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + /// ``` + public fun sqrt(x: u64): u64 { + std::macros::num_sqrt!(x, 64) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (exclusive) + public macro fun range_do($start: u64, $stop: u64, $f: |u64|) { + std::macros::range_do!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (inclusive) + public macro fun range_do_eq($start: u64, $stop: u64, $f: |u64|) { + std::macros::range_do_eq!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (exclusive) + public macro fun do($stop: u64, $f: |u64|) { + std::macros::do!($stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (inclusive) + public macro fun do_eq($stop: u64, $f: |u64|) { + std::macros::do_eq!($stop, $f) + } +} diff --git a/external-crates/move/crates/move-stdlib/sources/u8.move b/external-crates/move/crates/move-stdlib/sources/u8.move new file mode 100644 index 0000000000000..4eaca05a94345 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/sources/u8.move @@ -0,0 +1,79 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[defines_primitive(u8)] +module std::u8 { + /// Return the larger of `x` and `y` + public fun max(x: u8, y: u8): u8 { + std::macros::num_max!(x, y) + } + + /// Return the smaller of `x` and `y` + public fun min(x: u8, y: u8): u8 { + std::macros::num_min!(x, y) + } + + /// Return the absolute value of x - y + public fun diff(x: u8, y: u8): u8 { + std::macros::num_diff!(x, y) + } + + /// Calculate x / y, but round up the result. + public fun divide_and_round_up(x: u8, y: u8): u8 { + std::macros::num_divide_and_round_up!(x, y) + } + + /// Return the value of a base raised to a power + public fun pow(base: u8, exponent: u8): u8 { + std::macros::num_pow!(base, exponent) + } + + /// Get a nearest lower integer Square Root for `x`. Given that this + /// function can only operate with integers, it is impossible + /// to get perfect (or precise) integer square root for some numbers. + /// + /// Example: + /// ``` + /// math::sqrt(9) => 3 + /// math::sqrt(8) => 2 // the nearest lower square root is 4; + /// ``` + /// + /// In integer math, one of the possible ways to get results with more + /// precision is to use higher values or temporarily multiply the + /// value by some bigger number. Ideally if this is a square of 10 or 100. + /// + /// Example: + /// ``` + /// math::sqrt(8) => 2; + /// math::sqrt(8 * 10000) => 282; + /// // now we can use this value as if it was 2.82; + /// // but to get the actual result, this value needs + /// // to be divided by 100 (because sqrt(10000)). + /// + /// + /// math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + /// ``` + public fun sqrt(x: u8): u8 { + std::macros::num_sqrt!(x, 8) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (exclusive) + public macro fun range_do($start: u8, $stop: u8, $f: |u8|) { + std::macros::range_do!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `$start` to `$stop` (inclusive) + public macro fun range_do_eq($start: u8, $stop: u8, $f: |u8|) { + std::macros::range_do_eq!($start, $stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (exclusive) + public macro fun do($stop: u8, $f: |u8|) { + std::macros::do!($stop, $f) + } + + /// Loops applying `$f` to each number from `0` to `$stop` (inclusive) + public macro fun do_eq($stop: u8, $f: |u8|) { + std::macros::do_eq!($stop, $f) + } +} diff --git a/external-crates/move/crates/move-stdlib/sources/unit_test.move b/external-crates/move/crates/move-stdlib/sources/unit_test.move index 28526857c8521..1deb6a70c0529 100644 --- a/external-crates/move/crates/move-stdlib/sources/unit_test.move +++ b/external-crates/move/crates/move-stdlib/sources/unit_test.move @@ -1,3 +1,6 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[test_only] /// Module providing testing functionality. Only included for tests. module std::unit_test { @@ -9,4 +12,23 @@ module std::unit_test { /// This will cause a linking failure if an attempt is made to publish a /// test module in a VM that isn't in unit test mode. native public fun poison(); + + public macro fun assert_eq<$T: drop>($t1: $T, $t2: $T) { + let t1 = $t1; + let t2 = $t2; + assert_ref_eq!(&t1, &t2) + } + + public macro fun assert_ref_eq<$T>($t1: &$T, $t2: &$T) { + let t1 = $t1; + let t2 = $t2; + let res = t1 == t2; + if (!res) { + std::debug::print(&b"Assertion failed:"); + std::debug::print(t1); + std::debug::print(&b"!="); + std::debug::print(t2); + assert!(false); + } + } } diff --git a/external-crates/move/crates/move-stdlib/sources/vector.move b/external-crates/move/crates/move-stdlib/sources/vector.move index 1eb179ba683c1..cd98ed0ae7955 100644 --- a/external-crates/move/crates/move-stdlib/sources/vector.move +++ b/external-crates/move/crates/move-stdlib/sources/vector.move @@ -1,88 +1,106 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[defines_primitive(vector)] /// A variable-sized container that can hold any type. Indexing is 0-based, and /// vectors are growable. This module has many native functions. module std::vector { + /// Allows calling `.to_string()` on a vector of `u8` to get a utf8 `String`. + public use fun std::string::utf8 as vector.to_string; + + /// Allows calling `.try_to_string()` on a vector of `u8` to get a utf8 `String`. + /// This will return `None` if the vector is not valid utf8. + public use fun std::string::try_utf8 as vector.try_to_string; + + /// Allows calling `.to_ascii_string()` on a vector of `u8` to get an `ascii::String`. + public use fun std::ascii::string as vector.to_ascii_string; + + /// Allows calling `.try_to_ascii_string()` on a vector of `u8` to get an + /// `ascii::String`. This will return `None` if the vector is not valid ascii. + public use fun std::ascii::try_string as vector.try_to_ascii_string; /// The index into the vector is out of bounds const EINDEX_OUT_OF_BOUNDS: u64 = 0x20000; #[bytecode_instruction] /// Create an empty vector. - native public fun empty(): vector; + public native fun empty(): vector; #[bytecode_instruction] /// Return the length of the vector. - native public fun length(v: &vector): u64; + public native fun length(v: &vector): u64; + #[syntax(index)] #[bytecode_instruction] /// Acquire an immutable reference to the `i`th element of the vector `v`. /// Aborts if `i` is out of bounds. - native public fun borrow(v: &vector, i: u64): ∈ + public native fun borrow(v: &vector, i: u64): ∈ #[bytecode_instruction] /// Add element `e` to the end of the vector `v`. - native public fun push_back(v: &mut vector, e: Element); + public native fun push_back(v: &mut vector, e: Element); + #[syntax(index)] #[bytecode_instruction] /// Return a mutable reference to the `i`th element in the vector `v`. /// Aborts if `i` is out of bounds. - native public fun borrow_mut(v: &mut vector, i: u64): &mut Element; + public native fun borrow_mut(v: &mut vector, i: u64): &mut Element; #[bytecode_instruction] /// Pop an element from the end of vector `v`. /// Aborts if `v` is empty. - native public fun pop_back(v: &mut vector): Element; + public native fun pop_back(v: &mut vector): Element; #[bytecode_instruction] /// Destroy the vector `v`. /// Aborts if `v` is not empty. - native public fun destroy_empty(v: vector); + public native fun destroy_empty(v: vector); #[bytecode_instruction] /// Swaps the elements at the `i`th and `j`th indices in the vector `v`. /// Aborts if `i` or `j` is out of bounds. - native public fun swap(v: &mut vector, i: u64, j: u64); + public native fun swap(v: &mut vector, i: u64, j: u64); /// Return an vector of size one containing element `e`. public fun singleton(e: Element): vector { - let v = empty(); - push_back(&mut v, e); + let mut v = empty(); + v.push_back(e); v } /// Reverses the order of the elements in the vector `v` in place. public fun reverse(v: &mut vector) { - let len = length(v); + let len = v.length(); if (len == 0) return (); - let front_index = 0; - let back_index = len -1; + let mut front_index = 0; + let mut back_index = len - 1; while (front_index < back_index) { - swap(v, front_index, back_index); + v.swap(front_index, back_index); front_index = front_index + 1; back_index = back_index - 1; } } /// Pushes all of the elements of the `other` vector into the `lhs` vector. - public fun append(lhs: &mut vector, other: vector) { - reverse(&mut other); - while (!is_empty(&other)) push_back(lhs, pop_back(&mut other)); - destroy_empty(other); + public fun append(lhs: &mut vector, mut other: vector) { + other.reverse(); + while (!other.is_empty()) lhs.push_back(other.pop_back()); + other.destroy_empty(); } /// Return `true` if the vector `v` has no elements and `false` otherwise. public fun is_empty(v: &vector): bool { - length(v) == 0 + v.length() == 0 } /// Return true if `e` is in the vector `v`. /// Otherwise, returns false. public fun contains(v: &vector, e: &Element): bool { - let i = 0; - let len = length(v); + let mut i = 0; + let len = v.length(); while (i < len) { - if (borrow(v, i) == e) return true; + if (&v[i] == e) return true; i = i + 1; }; false @@ -91,10 +109,10 @@ module std::vector { /// Return `(true, i)` if `e` is in the vector `v` at index `i`. /// Otherwise, returns `(false, 0)`. public fun index_of(v: &vector, e: &Element): (bool, u64) { - let i = 0; - let len = length(v); + let mut i = 0; + let len = v.length(); while (i < len) { - if (borrow(v, i) == e) return (true, i); + if (&v[i] == e) return (true, i); i = i + 1; }; (false, 0) @@ -103,29 +121,29 @@ module std::vector { /// Remove the `i`th element of the vector `v`, shifting all subsequent elements. /// This is O(n) and preserves ordering of elements in the vector. /// Aborts if `i` is out of bounds. - public fun remove(v: &mut vector, i: u64): Element { - let len = length(v); + public fun remove(v: &mut vector, mut i: u64): Element { + let mut len = v.length(); // i out of bounds; abort if (i >= len) abort EINDEX_OUT_OF_BOUNDS; len = len - 1; - while (i < len) swap(v, i, { i = i + 1; i }); - pop_back(v) + while (i < len) v.swap(i, { i = i + 1; i }); + v.pop_back() } /// Insert `e` at position `i` in the vector `v`. /// If `i` is in bounds, this shifts the old `v[i]` and all subsequent elements to the right. - /// If `i == length(v)`, this adds `e` to the end of the vector. + /// If `i == v.length()`, this adds `e` to the end of the vector. /// This is O(n) and preserves ordering of elements in the vector. - /// Aborts if `i > length(v)` - public fun insert(v: &mut vector, e: Element, i: u64) { - let len = length(v); + /// Aborts if `i > v.length()` + public fun insert(v: &mut vector, e: Element, mut i: u64) { + let len = v.length(); // i too big abort if (i > len) abort EINDEX_OUT_OF_BOUNDS; - push_back(v, e); + v.push_back(e); while (i < len) { - swap(v, i, len); + v.swap(i, len); i = i + 1 } } @@ -134,9 +152,213 @@ module std::vector { /// This is O(1), but does not preserve ordering of elements in the vector. /// Aborts if `i` is out of bounds. public fun swap_remove(v: &mut vector, i: u64): Element { - assert!(!is_empty(v), EINDEX_OUT_OF_BOUNDS); - let last_idx = length(v) - 1; - swap(v, i, last_idx); - pop_back(v) + assert!(!v.is_empty(), EINDEX_OUT_OF_BOUNDS); + let last_idx = v.length() - 1; + v.swap(i, last_idx); + v.pop_back() + } + + // === Macros === + + /// Create a vector of length `n` by calling the function `f` on each index. + public macro fun tabulate<$T>($n: u64, $f: |u64| -> $T): vector<$T> { + let mut v = vector[]; + let n = $n; + n.do!(|i| v.push_back($f(i))); + v + } + + /// Destroy the vector `v` by calling `f` on each element and then destroying the vector. + /// Does not preserve the order of elements in the vector (starts from the end of the vector). + public macro fun destroy<$T>($v: vector<$T>, $f: |$T|) { + let mut v = $v; + while (!v.is_empty()) $f(v.pop_back()); + v.destroy_empty(); + } + + /// Destroy the vector `v` by calling `f` on each element and then destroying the vector. + /// Preserves the order of elements in the vector. + public macro fun do<$T>($v: vector<$T>, $f: |$T|) { + let mut v = $v; + v.reverse(); + while (!v.is_empty()) $f(v.pop_back()); + v.destroy_empty(); + } + + /// Perform an action `f` on each element of the vector `v`. The vector is not modified. + public macro fun do_ref<$T>($v: &vector<$T>, $f: |&$T|) { + let v = $v; + v.length().do!(|i| $f(&v[i])) + } + + /// Perform an action `f` on each element of the vector `v`. + /// The function `f` takes a mutable reference to the element. + public macro fun do_mut<$T>($v: &mut vector<$T>, $f: |&mut $T|) { + let v = $v; + v.length().do!(|i| $f(&mut v[i])) + } + + /// Map the vector `v` to a new vector by applying the function `f` to each element. + /// Preserves the order of elements in the vector, first is called first. + public macro fun map<$T, $U>($v: vector<$T>, $f: |$T| -> $U): vector<$U> { + let v = $v; + let mut r = vector[]; + v.do!(|e| r.push_back($f(e))); + r + } + + /// Map the vector `v` to a new vector by applying the function `f` to each element. + /// Preserves the order of elements in the vector, first is called first. + public macro fun map_ref<$T, $U>($v: &vector<$T>, $f: |&$T| -> $U): vector<$U> { + let v = $v; + let mut r = vector[]; + v.do_ref!(|e| r.push_back($f(e))); + r + } + + /// Filter the vector `v` by applying the function `f` to each element. + /// Return a new vector containing only the elements for which `f` returns `true`. + public macro fun filter<$T: drop>($v: vector<$T>, $f: |&$T| -> bool): vector<$T> { + let v = $v; + let mut r = vector[]; + v.do!(|e| if ($f(&e)) r.push_back(e)); + r + } + + /// Split the vector `v` into two vectors by applying the function `f` to each element. + /// Return a tuple containing two vectors: the first containing the elements for which `f` returns `true`, + /// and the second containing the elements for which `f` returns `false`. + public macro fun partition<$T>($v: vector<$T>, $f: |&$T| -> bool): (vector<$T>, vector<$T>) { + let v = $v; + let mut r1 = vector[]; + let mut r2 = vector[]; + v.do!(|e| if ($f(&e)) r1.push_back(e) else r2.push_back(e)); + (r1, r2) + } + + /// Finds the index of first element in the vector `v` that satisfies the predicate `f`. + /// Returns `some(index)` if such an element is found, otherwise `none()`. + public macro fun find_index<$T>($v: vector<$T>, $f: |&$T| -> bool): Option { + let v = $v; + 'find_index: { + v.length().do!(|i| if ($f(&v[i])) return 'find_index option::some(i)); + option::none() + } + } + + /// Count how many elements in the vector `v` satisfy the predicate `f`. + public macro fun count<$T>($v: &vector<$T>, $f: |&$T| -> bool): u64 { + let v = $v; + let mut count = 0; + v.do_ref!(|e| if ($f(e)) count = count + 1); + count + } + + /// Reduce the vector `v` to a single value by applying the function `f` to each element. + /// Similar to `fold_left` in Rust and `reduce` in Python and JavaScript. + public macro fun fold<$T, $Acc>($v: vector<$T>, $init: $Acc, $f: |$Acc, $T| -> $Acc): $Acc { + let v = $v; + let mut acc = $init; + v.do!(|e| acc = $f(acc, e)); + acc + } + + /// Whether any element in the vector `v` satisfies the predicate `f`. + /// If the vector is empty, returns `false`. + public macro fun any<$T>($v: &vector<$T>, $f: |&$T| -> bool): bool { + let v = $v; + 'any: { + v.do_ref!(|e| if ($f(e)) return 'any true); + false + } + } + + /// Whether all elements in the vector `v` satisfy the predicate `f`. + /// If the vector is empty, returns `true`. + public macro fun all<$T>($v: &vector<$T>, $f: |&$T| -> bool): bool { + let v = $v; + 'all: { + v.do_ref!(|e| if (!$f(e)) return 'all false); + true + } + } + + /// Destroys two vectors `v1` and `v2` by calling `f` to each pair of elements. + /// Aborts if the vectors are not of the same length. + /// The order of elements in the vectors is preserved. + public macro fun zip_do<$T1, $T2>($v1: vector<$T1>, $v2: vector<$T2>, $f: |$T1, $T2|) { + let v1 = $v1; + let mut v2 = $v2; + v2.reverse(); + let len = v1.length(); + assert!(len == v2.length()); + v1.do!(|el1| $f(el1, v2.pop_back())); + } + + /// Destroys two vectors `v1` and `v2` by calling `f` to each pair of elements. + /// Aborts if the vectors are not of the same length. + /// Starts from the end of the vectors. + public macro fun zip_do_reverse<$T1, $T2>($v1: vector<$T1>, $v2: vector<$T2>, $f: |$T1, $T2|) { + let v1 = $v1; + let mut v2 = $v2; + let len = v1.length(); + assert!(len == v2.length()); + v1.destroy!(|el1| $f(el1, v2.pop_back())); + } + + /// Iterate through `v1` and `v2` and apply the function `f` to references of each pair of + /// elements. The vectors are not modified. + /// Aborts if the vectors are not of the same length. + /// The order of elements in the vectors is preserved. + public macro fun zip_do_ref<$T1, $T2>($v1: &vector<$T1>, $v2: &vector<$T2>, $f: |&$T1, &$T2|) { + let v1 = $v1; + let v2 = $v2; + let len = v1.length(); + assert!(len == v2.length()); + len.do!(|i| $f(&v1[i], &v2[i])); + } + + /// Iterate through `v1` and `v2` and apply the function `f` to mutable references of each pair + /// of elements. The vectors may be modified. + /// Aborts if the vectors are not of the same length. + /// The order of elements in the vectors is preserved. + public macro fun zip_do_mut<$T1, $T2>( + $v1: &mut vector<$T1>, + $v2: &mut vector<$T2>, + $f: |&mut $T1, &mut $T2|, + ) { + let v1 = $v1; + let v2 = $v2; + let len = v1.length(); + assert!(len == v2.length()); + len.do!(|i| $f(&mut v1[i], &mut v2[i])); + } + + /// Destroys two vectors `v1` and `v2` by applying the function `f` to each pair of elements. + /// The returned values are collected into a new vector. + /// Aborts if the vectors are not of the same length. + /// The order of elements in the vectors is preserved. + public macro fun zip_map<$T1, $T2, $U>( + $v1: vector<$T1>, + $v2: vector<$T2>, + $f: |$T1, $T2| -> $U, + ): vector<$U> { + let mut r = vector[]; + zip_do!($v1, $v2, |el1, el2| r.push_back($f(el1, el2))); + r + } + + /// Iterate through `v1` and `v2` and apply the function `f` to references of each pair of + /// elements. The returned values are collected into a new vector. + /// Aborts if the vectors are not of the same length. + /// The order of elements in the vectors is preserved. + public macro fun zip_map_ref<$T1, $T2, $U>( + $v1: &vector<$T1>, + $v2: &vector<$T2>, + $f: |&$T1, &$T2| -> $U, + ): vector<$U> { + let mut r = vector[]; + zip_do_ref!($v1, $v2, |el1, el2| r.push_back($f(el1, el2))); + r } } diff --git a/external-crates/move/crates/move-stdlib/src/lib.rs b/external-crates/move/crates/move-stdlib/src/lib.rs index 45c5c87b8b7d2..5d714e3d3acd1 100644 --- a/external-crates/move/crates/move-stdlib/src/lib.rs +++ b/external-crates/move/crates/move-stdlib/src/lib.rs @@ -14,9 +14,7 @@ mod tests; pub mod utils; const MODULES_DIR: &str = "sources"; -const NURSERY_DIR: &str = "nursery"; const DOCS_DIR: &str = "docs"; -const NURSERY_DOCS_DIR: &str = "nursery/docs"; const REFERENCES_TEMPLATE: &str = "doc_templates/references.md"; const OVERVIEW_TEMPLATE: &str = "doc_templates/overview.md"; @@ -45,20 +43,11 @@ pub fn move_stdlib_docs_full_path() -> String { format!("{}/{}", env!("CARGO_MANIFEST_DIR"), DOCS_DIR) } -pub fn move_nursery_docs_full_path() -> String { - format!("{}/{}", env!("CARGO_MANIFEST_DIR"), NURSERY_DOCS_DIR) -} - pub fn move_stdlib_files() -> Vec { let path = path_in_crate(MODULES_DIR); find_filenames(&[path], |p| extension_equals(p, MOVE_EXTENSION)).unwrap() } -pub fn move_nursery_files() -> Vec { - let path = path_in_crate(NURSERY_DIR); - find_filenames(&[path], |p| extension_equals(p, MOVE_EXTENSION)).unwrap() -} - pub fn move_stdlib_named_addresses() -> BTreeMap { let mapping = [("std", "0x1")]; mapping @@ -116,16 +105,3 @@ pub fn build_stdlib_doc(output_path: &str) { move_stdlib_named_addresses(), ) } - -pub fn build_nursery_doc(output_path: &str) { - build_doc( - output_path, - "", - vec![], - None, - move_nursery_files().as_slice(), - vec![move_stdlib_modules_full_path()], - false, - move_stdlib_named_addresses(), - ) -} diff --git a/external-crates/move/crates/move-stdlib/src/main.rs b/external-crates/move/crates/move-stdlib/src/main.rs index 03652b782db60..500c40977c5d5 100644 --- a/external-crates/move/crates/move-stdlib/src/main.rs +++ b/external-crates/move/crates/move-stdlib/src/main.rs @@ -12,10 +12,5 @@ fn main() { //std::fs::create_dir_all(&move_stdlib::move_stdlib_docs_full_path()).unwrap(); move_stdlib::build_stdlib_doc(&move_stdlib::move_stdlib_docs_full_path()); }); - - time_it("Generating nursery documentation", || { - std::fs::remove_dir_all(move_stdlib::move_nursery_docs_full_path()).unwrap_or(()); - move_stdlib::build_nursery_doc(&move_stdlib::move_nursery_docs_full_path()); - }); } } diff --git a/external-crates/move/crates/move-stdlib/tests/ascii_tests.move b/external-crates/move/crates/move-stdlib/tests/ascii_tests.move index c455b362b62fa..ec6d4c7fdb817 100644 --- a/external-crates/move/crates/move-stdlib/tests/ascii_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/ascii_tests.move @@ -1,120 +1,222 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[test_only] module std::ascii_tests { use std::ascii; - use std::vector; - use std::option; #[test] fun test_ascii_chars() { - let i = 0; + let mut i = 0; let end = 128; - let vec = vector::empty(); + let mut vec = vector[]; while (i < end) { - assert!(ascii::is_valid_char(i), 0); - vector::push_back(&mut vec, i); + assert!(ascii::is_valid_char(i)); + vec.push_back(i); i = i + 1; }; - let str = ascii::string(vec); - assert!(vector::length(ascii::as_bytes(&str)) == 128, 0); - assert!(!ascii::all_characters_printable(&str), 1); - assert!(vector::length(&ascii::into_bytes(str)) == 128, 2); + let str = vec.to_ascii_string(); + assert!(str.as_bytes().length() == 128); + assert!(!str.all_characters_printable()); + assert!(str.into_bytes().length() == 128); } #[test] fun test_ascii_push_chars() { - let i = 0; + let mut i = 0; let end = 128; - let str = ascii::string(vector::empty()); + let mut str = vector[].to_ascii_string(); while (i < end) { - ascii::push_char(&mut str, ascii::char(i)); + str.push_char(ascii::char(i)); i = i + 1; }; - assert!(vector::length(ascii::as_bytes(&str)) == 128, 0); - assert!(ascii::length(&str) == 128, 0); - assert!(!ascii::all_characters_printable(&str), 1); + assert!(str.as_bytes().length() == 128); + assert!(str.length() == 128); + assert!(!str.all_characters_printable()); } #[test] fun test_ascii_push_char_pop_char() { - let i = 0; + let mut i = 0; let end = 128; - let str = ascii::string(vector::empty()); + let mut str = vector[].to_ascii_string(); while (i < end) { - ascii::push_char(&mut str, ascii::char(i)); + str.push_char(ascii::char(i)); i = i + 1; }; while (i > 0) { - let char = ascii::pop_char(&mut str); - assert!(ascii::byte(char) == i - 1, 0); + let char = str.pop_char(); + assert!(ascii::byte(char) == i - 1); i = i - 1; }; - assert!(vector::length(ascii::as_bytes(&str)) == 0, 0); - assert!(ascii::length(&str) == 0, 0); - assert!(ascii::all_characters_printable(&str), 1); + assert!(str.as_bytes().length() == 0); + assert!(str.length() == 0); + assert!(str.all_characters_printable()); } #[test] fun test_printable_chars() { - let i = 0x20; + let mut i = 0x20; let end = 0x7E; - let vec = vector::empty(); + let mut vec = vector[]; while (i <= end) { - assert!(ascii::is_printable_char(i), 0); - vector::push_back(&mut vec, i); + assert!(ascii::is_printable_char(i)); + vec.push_back(i); i = i + 1; }; - let str = ascii::string(vec); - assert!(ascii::all_characters_printable(&str), 0); + let str = vec.to_ascii_string(); + assert!(str.all_characters_printable()); } #[test] fun printable_chars_dont_allow_tab() { - let str = ascii::string(vector::singleton(0x09)); - assert!(!ascii::all_characters_printable(&str), 0); + let str = vector[0x09].to_ascii_string(); + assert!(!str.all_characters_printable()); } #[test] fun printable_chars_dont_allow_newline() { - let str = ascii::string(vector::singleton(0x0A)); - assert!(!ascii::all_characters_printable(&str), 0); + let str = vector[0x0A].to_ascii_string(); + assert!(!str.all_characters_printable()); } #[test] fun test_invalid_ascii_characters() { - let i = 128u8; + let mut i = 128u8; let end = 255u8; while (i < end) { - let try_str = ascii::try_string(vector::singleton(i)); - assert!(option::is_none(&try_str), 0); + let try_str = vector[i].try_to_ascii_string(); + assert!(try_str.is_none()); i = i + 1; }; } #[test] fun test_nonvisible_chars() { - let i = 0; + let mut i = 0; let end = 0x09; while (i < end) { - let str = ascii::string(vector::singleton(i)); - assert!(!ascii::all_characters_printable(&str), 0); + let str = vector[i].to_ascii_string(); + assert!(!str.all_characters_printable()); i = i + 1; }; - let i = 0x0B; + let mut i = 0x0B; let end = 0x0F; while (i <= end) { - let str = ascii::string(vector::singleton(i)); - assert!(!ascii::all_characters_printable(&str), 0); + let str = vector[i].to_ascii_string(); + assert!(!str.all_characters_printable()); i = i + 1; }; } + + #[test] + fun test_append() { + let mut str = b"hello".to_ascii_string(); + str.append(b" world".to_ascii_string()); + + assert!(str == b"hello world".to_ascii_string()); + } + + #[test] + fun test_to_uppercase() { + let str = b"azhello_world_!".to_ascii_string(); + assert!(str.to_uppercase() == b"AZHELLO_WORLD_!".to_ascii_string()); + } + + #[test] + fun test_to_lowercase() { + let str = b"AZHELLO_WORLD_!".to_ascii_string(); + assert!(str.to_lowercase() == b"azhello_world_!".to_ascii_string()); + } + + #[test] + fun test_substring() { + let str = b"hello world".to_ascii_string(); + assert!(str.substring(0, 5) == b"hello".to_ascii_string()); + assert!(str.substring(6, 11) == b"world".to_ascii_string()); + } + + #[test] + fun test_substring_len_one() { + let str = b"hello world".to_ascii_string(); + assert!(str.substring(0, 1) == b"h".to_ascii_string()); + assert!(str.substring(6, 7) == b"w".to_ascii_string()); + } + + #[test] + fun test_substring_len_zero() { + let str = b"hello world".to_ascii_string(); + assert!(str.substring(0, 0).is_empty()); + } + + #[test] + fun test_index_of() { + let str = b"hello world orwell".to_ascii_string(); + assert!(str.index_of(&b"hello".to_ascii_string()) == 0); + assert!(str.index_of(&b"world".to_ascii_string()) == 6); + assert!(str.index_of(&b"o".to_ascii_string()) == 4); + assert!(str.index_of(&b"z".to_ascii_string()) == str.length()); + assert!(str.index_of(&b"o ".to_ascii_string()) == 4); + assert!(str.index_of(&b"or".to_ascii_string()) == 7); + assert!(str.index_of(&b"".to_ascii_string()) == 0); + assert!(str.index_of(&b"orwell".to_ascii_string()) == 12); + assert!( + b"ororwell" + .to_ascii_string() + .index_of(&b"orwell".to_ascii_string()) == 2, + ); + } + + #[test, expected_failure(abort_code = ascii::EInvalidIndex)] + fun test_substring_i_out_of_bounds_fail() { + let str = b"hello world".to_ascii_string(); + str.substring(12, 13); + } + + #[test, expected_failure(abort_code = ascii::EInvalidIndex)] + fun test_substring_j_lt_i_fail() { + let str = b"hello world".to_ascii_string(); + str.substring(9, 8); + } + + #[test, expected_failure(abort_code = ascii::EInvalidIndex)] + fun test_substring_j_out_of_bounds_fail() { + let str = b"hello world".to_ascii_string(); + str.substring(9, 13); + } + + #[test] + fun test_insert() { + let mut str = b"hello".to_ascii_string(); + str.insert(5, b" world".to_ascii_string()); + assert!(str == b"hello world".to_ascii_string()); + + str.insert(5, b" cruel".to_ascii_string()); + assert!(str == b"hello cruel world".to_ascii_string()); + } + + #[test] + fun test_insert_empty() { + let mut str = b"hello".to_ascii_string(); + str.insert(5, b"".to_ascii_string()); + assert!(str == b"hello".to_ascii_string()); + } + + #[test, expected_failure(abort_code = ascii::EInvalidIndex)] + fun test_insert_out_of_bounds_fail() { + let mut str = b"hello".to_ascii_string(); + str.insert(6, b" world".to_ascii_string()); + } } diff --git a/external-crates/move/crates/move-stdlib/tests/bcs_tests.move b/external-crates/move/crates/move-stdlib/tests/bcs_tests.move index c6ca978b397c1..308dd99920289 100644 --- a/external-crates/move/crates/move-stdlib/tests/bcs_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/bcs_tests.move @@ -1,69 +1,74 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[test_only] module std::bcs_tests { use std::bcs; - struct Box has copy, drop, store { x: T } - struct Box3 has copy, drop, store { x: Box> } - struct Box7 has copy, drop, store { x: Box3> } - struct Box15 has copy, drop, store { x: Box7> } - struct Box31 has copy, drop, store { x: Box15> } - struct Box63 has copy, drop, store { x: Box31> } - struct Box127 has copy, drop, store { x: Box63> } + public struct Box has copy, drop, store { x: T } + public struct Box3 has copy, drop, store { x: Box> } + public struct Box7 has copy, drop, store { x: Box3> } + public struct Box15 has copy, drop, store { x: Box7> } + public struct Box31 has copy, drop, store { x: Box15> } + public struct Box63 has copy, drop, store { x: Box31> } + public struct Box127 has copy, drop, store { x: Box63> } #[test] fun bcs_address() { - let addr = @0x1234567890abcdef1234567890abcdef89b9f9d1fadc027cf9532d6f99041522; - let expected_output = x"1234567890abcdef1234567890abcdef89b9f9d1fadc027cf9532d6f99041522"; - assert!(bcs::to_bytes(&addr) == expected_output, 0); + let addr = @0x0000000000000000000000000000000089b9f9d1fadc027cf9532d6f99041522; + let expected_output = x"0000000000000000000000000000000089b9f9d1fadc027cf9532d6f99041522"; + assert!(bcs::to_bytes(&addr) == expected_output); } #[test] fun bcs_bool() { let expected_output = x"01"; - assert!(bcs::to_bytes(&true) == expected_output, 0); + assert!(bcs::to_bytes(&true) == expected_output); } #[test] fun bcs_u8() { let expected_output = x"01"; - assert!(bcs::to_bytes(&1u8) == expected_output, 0); + assert!(bcs::to_bytes(&1u8) == expected_output); } #[test] fun bcs_u16() { let expected_output = x"0100"; - assert!(bcs::to_bytes(&1u16) == expected_output, 0); + assert!(bcs::to_bytes(&1u16) == expected_output); } #[test] fun bcs_u32() { let expected_output = x"01000000"; - assert!(bcs::to_bytes(&1u32) == expected_output, 0); + assert!(bcs::to_bytes(&1u32) == expected_output); } #[test] fun bcs_u64() { let expected_output = x"0100000000000000"; - assert!(bcs::to_bytes(&1) == expected_output, 0); + assert!(bcs::to_bytes(&1) == expected_output); } #[test] fun bcs_u128() { let expected_output = x"01000000000000000000000000000000"; - assert!(bcs::to_bytes(&1u128) == expected_output, 0); + assert!(bcs::to_bytes(&1u128) == expected_output); } #[test] fun bcs_u256() { let expected_output = x"0100000000000000000000000000000000000000000000000000000000000000"; - assert!(bcs::to_bytes(&1u256) == expected_output, 0); + assert!(bcs::to_bytes(&1u256) == expected_output); } #[test] fun bcs_vec_u8() { let v = x"0f"; let expected_output = x"010f"; - assert!(bcs::to_bytes(&v) == expected_output, 0); + assert!(bcs::to_bytes(&v) == expected_output); } fun box3(x: T): Box3 { @@ -96,7 +101,8 @@ module std::bcs_tests { } #[test] - #[expected_failure] // VM_MAX_VALUE_DEPTH_REACHED + #[expected_failure] + // failes due to VM max value depth fun encode_129() { bcs::to_bytes(&Box { x: box127(true) }); } diff --git a/external-crates/move/crates/move-stdlib/tests/bit_vector_tests.move b/external-crates/move/crates/move-stdlib/tests/bit_vector_tests.move index 2dfa2e047471a..10a35c0cfa84c 100644 --- a/external-crates/move/crates/move-stdlib/tests/bit_vector_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/bit_vector_tests.move @@ -1,18 +1,23 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[test_only] module std::bit_vector_tests { use std::bit_vector; #[test_only] fun test_bitvector_set_unset_of_size(k: u64) { - let bitvector = bit_vector::new(k); - let index = 0; + let mut bitvector = bit_vector::new(k); + let mut index = 0; while (index < k) { - bit_vector::set(&mut bitvector, index); - assert!(bit_vector::is_index_set(&bitvector, index), 0); + bitvector.set(index); + assert!(bitvector.is_index_set(index)); index = index + 1; - let index_to_right = index; + let mut index_to_right = index; while (index_to_right < k) { - assert!(!bit_vector::is_index_set(&bitvector, index_to_right), 1); + assert!(!bitvector.is_index_set(index_to_right)); index_to_right = index_to_right + 1; }; }; @@ -20,12 +25,12 @@ module std::bit_vector_tests { index = 0; while (index < k) { - bit_vector::unset(&mut bitvector, index); - assert!(!bit_vector::is_index_set(&bitvector, index), 0); + bitvector.unset(index); + assert!(!bitvector.is_index_set(index)); index = index + 1; - let index_to_right = index; + let mut index_to_right = index; while (index_to_right < k) { - assert!(bit_vector::is_index_set(&bitvector, index_to_right), 1); + assert!(bitvector.is_index_set(index_to_right)); index_to_right = index_to_right + 1; }; }; @@ -34,22 +39,22 @@ module std::bit_vector_tests { #[test] #[expected_failure(abort_code = bit_vector::EINDEX)] fun set_bit_out_of_bounds() { - let bitvector = bit_vector::new(bit_vector::word_size()); - bit_vector::set(&mut bitvector, bit_vector::word_size()); + let mut bitvector = bit_vector::new(bit_vector::word_size()); + bitvector.set(bit_vector::word_size()); } #[test] #[expected_failure(abort_code = bit_vector::EINDEX)] fun unset_bit_out_of_bounds() { - let bitvector = bit_vector::new(bit_vector::word_size()); - bit_vector::unset(&mut bitvector, bit_vector::word_size()); + let mut bitvector = bit_vector::new(bit_vector::word_size()); + bitvector.unset(bit_vector::word_size()); } #[test] #[expected_failure(abort_code = bit_vector::EINDEX)] fun index_bit_out_of_bounds() { let bitvector = bit_vector::new(bit_vector::word_size()); - bit_vector::is_index_set(&bitvector, bit_vector::word_size()); + bitvector.is_index_set(bit_vector::word_size()); } #[test] @@ -59,71 +64,71 @@ module std::bit_vector_tests { #[test] fun test_set_bit_and_index_odd_size() { - test_bitvector_set_unset_of_size(300) + test_bitvector_set_unset_of_size(140) } #[test] fun longest_sequence_no_set_zero_index() { let bitvector = bit_vector::new(100); - assert!(bit_vector::longest_set_sequence_starting_at(&bitvector, 0) == 0, 0); + assert!(bitvector.longest_set_sequence_starting_at(0) == 0); } #[test] fun longest_sequence_one_set_zero_index() { - let bitvector = bit_vector::new(100); - bit_vector::set(&mut bitvector, 1); - assert!(bit_vector::longest_set_sequence_starting_at(&bitvector, 0) == 0, 0); + let mut bitvector = bit_vector::new(100); + bitvector.set(1); + assert!(bitvector.longest_set_sequence_starting_at(0) == 0); } #[test] fun longest_sequence_no_set_nonzero_index() { let bitvector = bit_vector::new(100); - assert!(bit_vector::longest_set_sequence_starting_at(&bitvector, 51) == 0, 0); + assert!(bitvector.longest_set_sequence_starting_at(51) == 0); } #[test] fun longest_sequence_two_set_nonzero_index() { - let bitvector = bit_vector::new(100); - bit_vector::set(&mut bitvector, 50); - bit_vector::set(&mut bitvector, 52); - assert!(bit_vector::longest_set_sequence_starting_at(&bitvector, 51) == 0, 0); + let mut bitvector = bit_vector::new(100); + bitvector.set(50); + bitvector.set(52); + assert!(bitvector.longest_set_sequence_starting_at(51) == 0); } #[test] fun longest_sequence_with_break() { - let bitvector = bit_vector::new(100); - let i = 0; + let mut bitvector = bit_vector::new(100); + let mut i = 0; while (i < 20) { - bit_vector::set(&mut bitvector, i); + bitvector.set(i); i = i + 1; }; // create a break in the run i = i + 1; while (i < 100) { - bit_vector::set(&mut bitvector, i); + bitvector.set(i); i = i + 1; }; - assert!(bit_vector::longest_set_sequence_starting_at(&bitvector, 0) == 20, 0); - assert!(bit_vector::longest_set_sequence_starting_at(&bitvector, 20) == 0, 0); - assert!(bit_vector::longest_set_sequence_starting_at(&bitvector, 21) == 100 - 21, 0); + assert!(bitvector.longest_set_sequence_starting_at(0) == 20); + assert!(bitvector.longest_set_sequence_starting_at(20) == 0); + assert!(bitvector.longest_set_sequence_starting_at(21) == 100 - 21); } #[test] fun test_shift_left() { - let bitlen = 133; - let bitvector = bit_vector::new(bitlen); + let bitlen = 97; + let mut bitvector = bit_vector::new(bitlen); - let i = 0; + let mut i = 0; while (i < bitlen) { - bit_vector::set(&mut bitvector, i); + bitvector.set(i); i = i + 1; }; i = bitlen - 1; while (i > 0) { - assert!(bit_vector::is_index_set(&bitvector, i), 0); - bit_vector::shift_left(&mut bitvector, 1); - assert!(!bit_vector::is_index_set(&bitvector, i), 1); + assert!(bitvector.is_index_set(i)); + bitvector.shift_left(1); + assert!(!bitvector.is_index_set( i)); i = i - 1; }; } @@ -132,21 +137,21 @@ module std::bit_vector_tests { fun test_shift_left_specific_amount() { let bitlen = 300; let shift_amount = 133; - let bitvector = bit_vector::new(bitlen); + let mut bitvector = bit_vector::new(bitlen); - bit_vector::set(&mut bitvector, 201); - assert!(bit_vector::is_index_set(&bitvector, 201), 0); + bitvector.set(201); + assert!(bitvector.is_index_set(201)); - bit_vector::shift_left(&mut bitvector, shift_amount); - assert!(bit_vector::is_index_set(&bitvector, 201 - shift_amount), 1); - assert!(!bit_vector::is_index_set(&bitvector, 201), 2); + bitvector.shift_left(shift_amount); + assert!(bitvector.is_index_set(201 - shift_amount)); + assert!(!bitvector.is_index_set(201)); // Make sure this shift clears all the bits - bit_vector::shift_left(&mut bitvector, bitlen - 1); + bitvector.shift_left(bitlen - 1); - let i = 0; + let mut i = 0; while (i < bitlen) { - assert!(!bit_vector::is_index_set(&bitvector, i), 3); + assert!(!bitvector.is_index_set(i)); i = i + 1; } } @@ -156,28 +161,28 @@ module std::bit_vector_tests { let bitlen = 50; let chosen_index = 24; let shift_amount = 3; - let bitvector = bit_vector::new(bitlen); + let mut bitvector = bit_vector::new(bitlen); - let i = 0; + let mut i = 0; while (i < bitlen) { - bit_vector::set(&mut bitvector, i); + bitvector.set(i); i = i + 1; }; - bit_vector::unset(&mut bitvector, chosen_index); - assert!(!bit_vector::is_index_set(&bitvector, chosen_index), 0); + bitvector.unset(chosen_index); + assert!(!bitvector.is_index_set(chosen_index)); - bit_vector::shift_left(&mut bitvector, shift_amount); + bitvector.shift_left(shift_amount); i = 0; while (i < bitlen) { // only chosen_index - shift_amount and the remaining bits should be BitVector::unset if ((i == chosen_index - shift_amount) || (i >= bitlen - shift_amount)) { - assert!(!bit_vector::is_index_set(&bitvector, i), 1); + assert!(!bitvector.is_index_set(i)); } else { - assert!(bit_vector::is_index_set(&bitvector, i), 2); + assert!(bitvector.is_index_set(i)); }; i = i + 1; } @@ -186,18 +191,18 @@ module std::bit_vector_tests { #[test] fun shift_left_at_size() { let bitlen = 133; - let bitvector = bit_vector::new(bitlen); + let mut bitvector = bit_vector::new(bitlen); - let i = 0; + let mut i = 0; while (i < bitlen) { - bit_vector::set(&mut bitvector, i); + bitvector.set(i); i = i + 1; }; - bit_vector::shift_left(&mut bitvector, bitlen - 1); + bitvector.shift_left(bitlen - 1); i = bitlen - 1; while (i > 0) { - assert!(!bit_vector::is_index_set(&bitvector, i), 1); + assert!(!bitvector.is_index_set( i)); i = i - 1; }; } @@ -205,8 +210,8 @@ module std::bit_vector_tests { #[test] fun shift_left_more_than_size() { let bitlen = 133; - let bitvector = bit_vector::new(bitlen); - bit_vector::shift_left(&mut bitvector, bitlen); + let mut bitvector = bit_vector::new(bitlen); + bitvector.shift_left(bitlen); } #[test] @@ -218,6 +223,6 @@ module std::bit_vector_tests { #[test] fun single_bit_bitvector() { let bitvector = bit_vector::new(1); - assert!(bit_vector::length(&bitvector) == 1, 0); + assert!(bitvector.length() == 1); } } diff --git a/external-crates/move/crates/move-stdlib/tests/fixedpoint32_tests.move b/external-crates/move/crates/move-stdlib/tests/fixedpoint32_tests.move index 83513dbe0cfda..4fd5f847b4ab9 100644 --- a/external-crates/move/crates/move-stdlib/tests/fixedpoint32_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/fixedpoint32_tests.move @@ -1,3 +1,8 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[test_only] module std::fixed_point32_tests { use std::fixed_point32; @@ -28,7 +33,7 @@ module std::fixed_point32_tests { #[test] fun create_zero() { let x = fixed_point32::create_from_rational(0, 1); - assert!(fixed_point32::is_zero(x), 0); + assert!(x.is_zero()); } #[test] @@ -75,14 +80,14 @@ module std::fixed_point32_tests { fun exact_multiply() { let f = fixed_point32::create_from_rational(3, 4); // 0.75 let nine = fixed_point32::multiply_u64(12, f); // 12 * 0.75 - assert!(nine == 9, 0); + assert!(nine == 9); } #[test] fun exact_divide() { let f = fixed_point32::create_from_rational(3, 4); // 0.75 let twelve = fixed_point32::divide_u64(9, f); // 9 / 0.75 - assert!(twelve == 12, 0); + assert!(twelve == 12); } #[test] @@ -91,98 +96,19 @@ module std::fixed_point32_tests { let not_three = fixed_point32::multiply_u64(9, copy f); // 9 * 0.333... // multiply_u64 does NOT round -- it truncates -- so values that // are not perfectly representable in binary may be off by one. - assert!(not_three == 2, 0); + assert!(not_three == 2); // Try again with a fraction slightly larger than 1/3. - let f = fixed_point32::create_from_raw_value(fixed_point32::get_raw_value(f) + 1); + let f = fixed_point32::create_from_raw_value(f.get_raw_value() + 1); let three = fixed_point32::multiply_u64(9, f); - assert!(three == 3, 1); + assert!(three == 3); } #[test] fun create_from_rational_max_numerator_denominator() { // Test creating a 1.0 fraction from the maximum u64 value. let f = fixed_point32::create_from_rational(18446744073709551615, 18446744073709551615); - let one = fixed_point32::get_raw_value(f); - assert!(one == 4294967296, 0); // 0x1.00000000 - } - - #[test] - fun min_can_return_smaller_fixed_point_number() { - let one = fixed_point32::create_from_rational(1, 1); - let two = fixed_point32::create_from_rational(2, 1); - let smaller_number1 = fixed_point32::min(one, two); - let val1 = fixed_point32::get_raw_value(smaller_number1); - assert!(val1 == 4294967296, 0); // 0x1.00000000 - let smaller_number2 = fixed_point32::min(two, one); - let val2 = fixed_point32::get_raw_value(smaller_number2); - assert!(val2 == 4294967296, 0); // 0x1.00000000 - } - - #[test] - fun max_can_return_larger_fixed_point_number() { - let one = fixed_point32::create_from_rational(1, 1); - let two = fixed_point32::create_from_rational(2, 1); - let larger_number1 = fixed_point32::max(one, two); - let larger_number2 = fixed_point32::max(two, one); - let val1 = fixed_point32::get_raw_value(larger_number1); - assert!(val1 == 8589934592, 0); // 0x2.00000000 - let val2 = fixed_point32::get_raw_value(larger_number2); - assert!(val2 == 8589934592, 0); // 0x2.00000000 - } - - #[test] - fun floor_can_return_the_correct_number_zero() { - let point_five = fixed_point32::create_from_rational(1, 2); - let val = fixed_point32::floor(point_five); - assert!(val == 0, 0); - } - - #[test] - fun create_from_u64_create_correct_fixed_point_number() { - let one = fixed_point32::create_from_u64(1); - let val = fixed_point32::get_raw_value(one); - assert!(val == 4294967296, 0); - } - - #[test] - #[expected_failure(abort_code = fixed_point32::ERATIO_OUT_OF_RANGE)] - fun create_from_u64_throw_error_when_number_too_large() { - fixed_point32::create_from_u64(4294967296); // (u64 >> 32) + 1 - } - - #[test] - fun floor_can_return_the_correct_number_one() { - let three_point_five = fixed_point32::create_from_rational(7, 2); // 3.5 - let val = fixed_point32::floor(three_point_five); - assert!(val == 3, 0); - } - - #[test] - fun ceil_can_round_up_correctly() { - let point_five = fixed_point32::create_from_rational(1, 2); // 0.5 - let val = fixed_point32::ceil(point_five); - assert!(val == 1, 0); - } - - #[test] - fun ceil_will_not_change_if_number_already_integer() { - let one = fixed_point32::create_from_rational(1, 1); // 0.5 - let val = fixed_point32::ceil(one); - assert!(val == 1, 0); - } - - #[test] - fun round_can_round_up_correctly() { - let point_five = fixed_point32::create_from_rational(1, 2); // 0.5 - let val = fixed_point32::round(point_five); - assert!(val == 1, 0); - } - - #[test] - fun round_can_round_down_correctly() { - let num = fixed_point32::create_from_rational(499, 1000); // 0.499 - let val = fixed_point32::round(num); - assert!(val == 0, 0); + let one = f.get_raw_value(); + assert!(one == 4294967296); // 0x1.00000000 } } diff --git a/external-crates/move/crates/move-stdlib/tests/hash_tests.move b/external-crates/move/crates/move-stdlib/tests/hash_tests.move index 449f7b914bae7..8b309c30e1f75 100644 --- a/external-crates/move/crates/move-stdlib/tests/hash_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/hash_tests.move @@ -1,3 +1,8 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[test_only] module std::hash_tests { use std::hash; @@ -6,13 +11,13 @@ module std::hash_tests { fun sha2_256_expected_hash() { let input = x"616263"; let expected_output = x"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"; - assert!(hash::sha2_256(input) == expected_output, 0); + assert!(hash::sha2_256(input) == expected_output); } #[test] fun sha3_256_expected_hash() { let input = x"616263"; let expected_output = x"3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"; - assert!(hash::sha3_256(input) == expected_output, 0); + assert!(hash::sha3_256(input) == expected_output); } } diff --git a/external-crates/move/crates/move-stdlib/tests/integer_tests.move b/external-crates/move/crates/move-stdlib/tests/integer_tests.move new file mode 100644 index 0000000000000..07d940b7a86d4 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/tests/integer_tests.move @@ -0,0 +1,220 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +// helpers for integer tests +#[test_only] +module std::integer_tests { + use std::unit_test::assert_eq; + + public(package) macro fun cases($max: _, $cases: vector<_>, $f: |_, _, _|) { + let mut cases = $cases; + let max_pred = $max - 1; + while (!cases.is_empty()) { + let case = cases.pop_back(); + let case_pred = case.max(1) - 1; + let case_succ = case.min(max_pred) + 1; + $f(case_pred, case, case_succ); + } + } + + public(package) macro fun test_max($max: _, $cases: vector<_>) { + let max = $max; + let cases = $cases; + assert_eq!(max.max(max), max); + cases!(max, cases, |case_pred, case, case_succ| { + assert_eq!(max.max(case), max); + assert_eq!(case.max(max), max); + assert_eq!(case.max(case), case); + assert_eq!(case_pred.max(case), case); + assert_eq!(case_succ.max(case), case_succ); + }) + } + + public(package) macro fun test_min($max: _, $cases: vector<_>) { + let max = $max; + let cases = $cases; + assert_eq!(max.min(max), max); + cases!(max, cases, |case_pred, case, case_succ| { + assert_eq!(max.min(case), case); + assert_eq!(case.min(max), case); + assert_eq!(case.min(case), case); + assert_eq!(case_pred.min(case), case_pred); + assert_eq!(case_succ.min(case), case); + }) + } + + public(package) macro fun test_diff($max: _, $cases: vector<_>) { + let max = $max; + let cases = $cases; + assert_eq!(max.diff(max), 0); + cases!(max, cases, |case_pred, case, case_succ| { + assert_eq!(max.diff(case), max - case); + assert_eq!(case.diff(max), max - case); + assert_eq!(case.diff(case), 0); + assert_eq!(case_pred.diff(case), case - case_pred); + assert_eq!(case.diff(case_pred), case - case_pred); + assert_eq!(case_succ.diff(case), case_succ - case); + assert_eq!(case.diff(case_succ), case_succ - case); + }) + } + + public(package) macro fun check_div_round($x: _, $y: _) { + let x = $x; + let y = $y; + if (y == 0) return; + assert_eq!(x.divide_and_round_up(y), (x / y) + (x % y).min(1)); + } + + public(package) macro fun test_divide_and_round_up($max: _, $cases: vector<_>) { + let max = $max; + let cases = $cases; + assert_eq!(max.divide_and_round_up(max), 1); + check_div_round!(max, max); + cases!(max, cases, |case_pred, case, case_succ| { + check_div_round!(max, case); + check_div_round!(case, max); + check_div_round!(case, case); + check_div_round!(case_pred, case); + check_div_round!(case, case_pred); + check_div_round!(case_succ, case); + check_div_round!(case, case_succ); + }) + } + + public(package) macro fun slow_pow($base: _, $exp: u8): _ { + let base = $base; + let mut exp = $exp; + let mut result = 1; + while (exp > 0) { + result = result * base; + exp = exp - 1; + }; + result + } + + public(package) macro fun test_pow<$T>($max: $T, $cases: vector<$T>) { + let max = $max; + let cases = $cases; + cases!(max, cases, |case_pred, case, case_succ| { + assert_eq!(case_pred.pow(0), 1); + assert_eq!(case_pred.pow(1), case_pred); + assert_eq!(case.pow(0), 1); + assert_eq!(case.pow(1), case); + assert_eq!(case_succ.pow(0), 1); + assert_eq!(case_succ.pow(1), case_succ); + }); + assert_eq!((0: $T).pow(2), 0); + assert_eq!((1: $T).pow(255), 1); + assert_eq!((2: $T).pow(7), slow_pow!((2: $T), 7)); + assert_eq!((3: $T).pow(5), slow_pow!((3: $T), 5)); + } + + public(package) macro fun test_sqrt<$T>( + $max: $T, + $bound_cases: vector<$T>, + $reflexive_cases: vector<$T>, + ) { + let max = $max; + let cases = $bound_cases; + // logical bounds cases + let max_sqrt = max.sqrt(); + cases!(max, cases, |case_pred, case, case_succ| { + let sqrt_pred = case_pred.sqrt(); + assert!(sqrt_pred * sqrt_pred <= case_pred); + let sqrt = case.sqrt(); + assert!(sqrt * sqrt <= case); + let sqrt_succ = case_succ.sqrt(); + assert!(sqrt_succ * sqrt_succ <= case_succ); + + if (sqrt_pred >= max_sqrt) return; + assert!((sqrt_pred + 1) * (sqrt_pred + 1) > case_pred); + + if (sqrt >= max_sqrt) return; + assert!((sqrt + 1) * (sqrt + 1) > case); + + if (sqrt_succ >= max_sqrt) return; + assert!((sqrt_succ + 1) * (sqrt_succ + 1) > case_succ); + }); + + // simple reflexive cases + let cases: vector<$T> = $reflexive_cases; + cases!(max, cases, |case_pred, case, case_succ| { + assert_eq!((case_pred * case_pred).sqrt(), case_pred); + assert_eq!((case * case).sqrt(), case); + assert_eq!((case_succ * case_succ).sqrt(), case_succ); + }); + + // test that the square of a non perfect square is the most recent square root perfect + // square, rounding down + let mut cases: vector<$T> = vector[2, 3, 4, 5, 6]; + while (!cases.is_empty()) { + let case = cases.pop_back(); + let prev = case - 1; + let square = case * case; + let prev_suare = prev * prev; + let mut i = prev_suare; + while (i < square) { + assert_eq!(i.sqrt(), prev); + i = i + 1; + } + } + } + + public(package) macro fun sum_range<$T>($n: $T): $T { + let n = $n; + (n * (n + 1)) / 2 + } + + public(package) macro fun test_dos_case<$T>($case: $T) { + let case = $case; + let mut sum: $T = 0; + case.do!(|i| sum = sum + i); + assert_eq!(sum, sum_range!(case - 1)); + + sum = 0; + case.do_eq!(|i| sum = sum + i); + assert_eq!(sum, sum_range!(case)); + + let half = case / 2; + + sum = 0; + half.range_do!(case, |i| sum = sum + i); + assert_eq!(sum, sum_range!(case - 1) - sum_range!(half - 1)); + + sum = 0; + half.range_do_eq!(case, |i| sum = sum + i); + assert_eq!(sum, sum_range!(case) - sum_range!(half - 1)); + } + + public(package) macro fun test_dos<$T>($max: $T, $cases: vector<$T>) { + let max = $max; + let cases = $cases; + // test bounds/invalid ranges + (0: $T).do!(|_| assert!(false)); + cases!(max, cases, |case_pred, case, case_succ| { + if (case == 0) return; + case.range_do!(0, |_| assert!(false)); + case.range_do_eq!(0, |_| assert!(false)); + + if (case == max) return; + case.range_do!(case_pred, |_| assert!(false)); + case_succ.range_do!(case, |_| assert!(false)); + case.range_do_eq!(case_pred, |_| assert!(false)); + case_succ.range_do_eq!(case, |_| assert!(false)); + }); + + // test upper bound being max + let max_pred = max - 1; + max_pred.range_do_eq!(max, |_| ()); + + // test iteration numbers + let cases: vector<$T> = vector[3, 5, 8, 11, 14]; + cases!(max, cases, |case_pred, case, case_succ| { + test_dos_case!(case_pred); + test_dos_case!(case); + test_dos_case!(case_succ); + }); + } + + +} diff --git a/external-crates/move/crates/move-stdlib/tests/move_unit_test.rs b/external-crates/move/crates/move-stdlib/tests/move_unit_test.rs deleted file mode 100644 index 538b08c3e8718..0000000000000 --- a/external-crates/move/crates/move-stdlib/tests/move_unit_test.rs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) The Diem Core Contributors -// Copyright (c) The Move Contributors -// SPDX-License-Identifier: Apache-2.0 - -use move_cli::base::test::{run_move_unit_tests, UnitTestResult}; -use move_core_types::account_address::AccountAddress; -use move_stdlib::path_in_crate; -use move_stdlib_natives::{all_natives, nursery_natives, GasParameters, NurseryGasParameters}; -use move_unit_test::UnitTestingConfig; -use tempfile::tempdir; - -fn run_tests_for_pkg(path_to_pkg: impl Into, include_nursery_natives: bool) { - let pkg_path = path_in_crate(path_to_pkg); - - let mut natives = all_natives( - AccountAddress::from_hex_literal("0x1").unwrap(), - GasParameters::zeros(), - ); - if include_nursery_natives { - natives.extend(nursery_natives( - /* silent */ false, - AccountAddress::from_hex_literal("0x1").unwrap(), - NurseryGasParameters::zeros(), - )) - } - - let result = run_move_unit_tests( - &pkg_path, - move_package::BuildConfig { - test_mode: true, - install_dir: Some(tempdir().unwrap().path().to_path_buf()), - ..Default::default() - }, - UnitTestingConfig::default_with_bound(Some(1_000_000_000)), - natives, - None, - /* compute_coverage */ false, - &mut std::io::stdout(), - ) - .unwrap(); - if result.0 != UnitTestResult::Success { - panic!("aborting because of Move unit test failures"); - } -} - -#[test] -fn move_unit_tests() { - run_tests_for_pkg(".", false); - run_tests_for_pkg("nursery", true); -} diff --git a/external-crates/move/crates/move-stdlib/tests/move_verification_test.rs b/external-crates/move/crates/move-stdlib/tests/move_verification_test.rs deleted file mode 100644 index 2a5dbffb18fa8..0000000000000 --- a/external-crates/move/crates/move-stdlib/tests/move_verification_test.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) The Diem Core Contributors -// Copyright (c) The Move Contributors -// SPDX-License-Identifier: Apache-2.0 - -// TODO: split this into individual tests once the package system supports this. - -#[test] -fn prove() { - // TODO re-enable when the prover works again - // use move_cli::base::prove::ProverTest; - // ProverTest::create(".").run(); - // ProverTest::create("nursery").run() -} diff --git a/external-crates/move/crates/move-stdlib/tests/option_tests.move b/external-crates/move/crates/move-stdlib/tests/option_tests.move index 950a940dc4207..a8cb8875d5495 100644 --- a/external-crates/move/crates/move-stdlib/tests/option_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/option_tests.move @@ -1,20 +1,22 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[test_only] module std::option_tests { - use std::option; - use std::vector; - #[test] fun option_none_is_none() { let none = option::none(); - assert!(option::is_none(&none), 0); - assert!(!option::is_some(&none), 1); + assert!(none.is_none()); + assert!(!none.is_some()); } #[test] fun option_some_is_some() { let some = option::some(5); - assert!(!option::is_none(&some), 0); - assert!(option::is_some(&some), 1); + assert!(!some.is_none()); + assert!(some.is_some()); } #[test] @@ -22,149 +24,197 @@ module std::option_tests { let none = option::none(); let some = option::some(5); let some_other = option::some(6); - assert!(option::contains(&some, &5), 0); - assert!(option::contains(&some_other, &6), 1); - assert!(!option::contains(&none, &5), 2); - assert!(!option::contains(&some_other, &5), 3); + assert!(some.contains(&5)); + assert!(some_other.contains(&6)); + assert!(!none.contains(&5)); + assert!(!some_other.contains(&5)); } #[test] fun option_borrow_some() { let some = option::some(5); let some_other = option::some(6); - assert!(*option::borrow(&some) == 5, 3); - assert!(*option::borrow(&some_other) == 6, 4); + assert!(*some.borrow() == 5); + assert!(*some_other.borrow() == 6); } #[test] #[expected_failure(abort_code = option::EOPTION_NOT_SET)] fun option_borrow_none() { - option::borrow(&option::none()); + option::none().borrow(); } #[test] fun borrow_mut_some() { - let some = option::some(1); - let ref = option::borrow_mut(&mut some); + let mut some = option::some(1); + let ref = some.borrow_mut(); *ref = 10; - assert!(*option::borrow(&some) == 10, 0); + assert!(*some.borrow() == 10); } #[test] #[expected_failure(abort_code = option::EOPTION_NOT_SET)] fun borrow_mut_none() { - option::borrow_mut(&mut option::none()); + option::none().borrow_mut(); } #[test] fun borrow_with_default() { let none = option::none(); let some = option::some(5); - assert!(*option::borrow_with_default(&some, &7) == 5, 0); - assert!(*option::borrow_with_default(&none, &7) == 7, 1); + assert!(*some.borrow_with_default(&7) == 5); + assert!(*none.borrow_with_default(&7) == 7); } #[test] fun get_with_default() { let none = option::none(); let some = option::some(5); - assert!(option::get_with_default(&some, 7) == 5, 0); - assert!(option::get_with_default(&none, 7) == 7, 1); + assert!(option::get_with_default(&some, 7) == 5); + assert!(option::get_with_default(&none, 7) == 7); } #[test] fun extract_some() { - let opt = option::some(1); - assert!(option::extract(&mut opt) == 1, 0); - assert!(option::is_none(&opt), 1); + let mut opt = option::some(1); + assert!(opt.extract() == 1); + assert!(opt.is_none()); } #[test] #[expected_failure(abort_code = option::EOPTION_NOT_SET)] fun extract_none() { - option::extract(&mut option::none()); + option::none().extract(); } #[test] fun swap_some() { - let some = option::some(5); - assert!(option::swap(&mut some, 1) == 5, 0); - assert!(*option::borrow(&some) == 1, 1); + let mut some = option::some(5); + assert!(some.swap(1) == 5); + assert!(*some.borrow() == 1); } #[test] fun swap_or_fill_some() { - let some = option::some(5); - assert!(option::swap_or_fill(&mut some, 1) == option::some(5), 0); - assert!(*option::borrow(&some) == 1, 1); + let mut some = option::some(5); + assert!(some.swap_or_fill(1) == option::some(5)); + assert!(*some.borrow() == 1); } #[test] fun swap_or_fill_none() { - let none = option::none(); - assert!(option::swap_or_fill(&mut none, 1) == option::none(), 0); - assert!(*option::borrow(&none) == 1, 1); + let mut none = option::none(); + assert!(none.swap_or_fill(1) == option::none()); + assert!(*none.borrow() == 1); } #[test] #[expected_failure(abort_code = option::EOPTION_NOT_SET)] fun swap_none() { - option::swap(&mut option::none(), 1); + option::none().swap(1); } #[test] fun fill_none() { - let none = option::none(); - option::fill(&mut none, 3); - assert!(option::is_some(&none), 0); - assert!(*option::borrow(&none) == 3, 1); + let mut none = option::none(); + none.fill(3); + assert!(none.is_some()); + assert!(*none.borrow() == 3); } #[test] #[expected_failure(abort_code = option::EOPTION_IS_SET)] fun fill_some() { - option::fill(&mut option::some(3), 0); + option::some(3).fill(0); } #[test] fun destroy_with_default() { - assert!(option::destroy_with_default(option::none(), 4) == 4, 0); - assert!(option::destroy_with_default(option::some(4), 5) == 4, 1); + assert!(option::none().destroy_with_default(4) == 4); + assert!(option::some(4).destroy_with_default(5) == 4); } #[test] fun destroy_some() { - assert!(option::destroy_some(option::some(4)) == 4, 0); + assert!(option::some(4).destroy_some() == 4); } #[test] #[expected_failure(abort_code = option::EOPTION_NOT_SET)] fun destroy_some_none() { - option::destroy_some(option::none()); + option::none().destroy_some(); } #[test] fun destroy_none() { - option::destroy_none(option::none()); + option::none().destroy_none(); } #[test] #[expected_failure(abort_code = option::EOPTION_IS_SET)] fun destroy_none_some() { - option::destroy_none(option::some(0)); + option::some(0).destroy_none(); } #[test] fun into_vec_some() { - let v = option::to_vec(option::some(0)); - assert!(vector::length(&v) == 1, 0); - let x = vector::pop_back(&mut v); - assert!(x == 0, 1); + let mut v = option::some(0).to_vec(); + assert!(v.length() == 1); + let x = v.pop_back(); + assert!(x == 0); } #[test] fun into_vec_none() { - let v: vector = option::to_vec(option::none()); - assert!(vector::is_empty(&v), 0); + let v: vector = option::none().to_vec(); + assert!(v.is_empty()); + } + + // === Macros === + + #[test] + fun do_destroy() { + let mut counter = 0; + option::some(5).destroy!(|x| counter = x); + option::some(10).do!(|x| counter = counter + x); + + assert!(counter == 15); + } + + #[test] + fun do_ref_mut() { + let mut counter = 0; + let mut opt = option::some(5); + opt.do_mut!(|x| *x = 100); + opt.do_ref!(|x| counter = *x); + + assert!(counter == 100); + } + + #[test] + fun map_map_ref() { + assert!(option::some(5).map!(|x| vector[x]) == option::some(vector[5])); + assert!(option::some(5).map_ref!(|x| vector[*x]) == option::some(vector[5])); + assert!(option::none().map!(|x| vector[x]) == option::none()); + assert!(option::none().map_ref!(|x| vector[*x]) == option::none()); + } + + #[test] + fun filter() { + assert!(option::some(5).filter!(|x| *x == 5) == option::some(5)); + assert!(option::some(5).filter!(|x| *x == 6) == option::none()); + } + + #[test] + fun is_some_and() { + assert!(option::some(5).is_some_and!(|x| *x == 5)); + assert!(!option::some(5).is_some_and!(|x| *x == 6)); + assert!(!option::none().is_some_and!(|x| *x == 5)); + } + + #[test] + fun destroy_or() { + assert!(option::none().destroy_or!(10) == 10); + assert!(option::some(5).destroy_or!(10) == 5); } } diff --git a/external-crates/move/crates/move-stdlib/tests/string_tests.move b/external-crates/move/crates/move-stdlib/tests/string_tests.move index e7810a3422262..bf99e678860d0 100644 --- a/external-crates/move/crates/move-stdlib/tests/string_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/string_tests.move @@ -1,3 +1,8 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[test_only] module std::string_tests { use std::string; @@ -5,74 +10,79 @@ module std::string_tests { #[test] fun test_valid_utf8() { let sparkle_heart = vector[240, 159, 146, 150]; - let s = string::utf8(sparkle_heart); - assert!(string::length(&s) == 4, 22); + let s = sparkle_heart.to_string(); + assert!(s.length() == 4); } #[test] - #[expected_failure(abort_code = string::EINVALID_UTF8)] + #[expected_failure(abort_code = string::EInvalidUTF8)] fun test_invalid_utf8() { let no_sparkle_heart = vector[0, 159, 146, 150]; - let s = string::utf8(no_sparkle_heart); - assert!(string::length(&s) == 1, 22); + let s = no_sparkle_heart.to_string(); + assert!(s.length() == 1); } #[test] - fun test_sub_string() { - let s = string::utf8(b"abcd"); - let sub = string::sub_string(&s, 2, 4); - assert!(sub == string::utf8(b"cd"), 22) + fun test_substring() { + let s = b"abcd".to_string(); + let sub = s.substring(2, 4); + assert!(sub == b"cd".to_string()) } #[test] - #[expected_failure(abort_code = string::EINVALID_INDEX)] - fun test_sub_string_invalid_boundary() { + #[expected_failure(abort_code = string::EInvalidIndex)] + fun test_substring_invalid_boundary() { let sparkle_heart = vector[240, 159, 146, 150]; - let s = string::utf8(sparkle_heart); - let _sub = string::sub_string(&s, 1, 4); + let s = sparkle_heart.to_string(); + let _sub = s.substring(1, 4); } #[test] - #[expected_failure(abort_code = string::EINVALID_INDEX)] - fun test_sub_string_invalid_index() { - let s = string::utf8(b"abcd"); - let _sub = string::sub_string(&s, 4, 5); + #[expected_failure(abort_code = string::EInvalidIndex)] + fun test_substring_invalid_index() { + let s = b"abcd".to_string(); + let _sub = s.substring(4, 5); } #[test] - fun test_sub_string_empty() { - let s = string::utf8(b"abcd"); - let sub = string::sub_string(&s, 4, 4); - assert!(string::is_empty(&sub), 22) + fun test_substring_empty() { + let s = b"abcd".to_string(); + let sub = s.substring(4, 4); + assert!(sub.is_empty()) } #[test] fun test_index_of() { - let s = string::utf8(b"abcd"); - let r = string::utf8(b"bc"); - let p = string::index_of(&s, &r); - assert!(p == 1, 22) + let s = b"abcd".to_string(); + let r = b"bc".to_string(); + let p = s.index_of(&r); + assert!(p == 1) } #[test] fun test_index_of_fail() { - let s = string::utf8(b"abcd"); - let r = string::utf8(b"bce"); - let p = string::index_of(&s, &r); - assert!(p == 4, 22) + let s = b"abcd".to_string(); + let r = b"bce".to_string(); + let p = s.index_of(&r); + assert!(p == 4) } #[test] fun test_append() { - let s = string::utf8(b"abcd"); - string::append(&mut s, string::utf8(b"ef")); - assert!(s == string::utf8(b"abcdef"), 22) + let mut s = b"abcd".to_string(); + s.append(b"ef".to_string()); + assert!(s == b"abcdef".to_string()) } #[test] fun test_insert() { - let s = string::utf8(b"abcd"); - string::insert(&mut s, 1, string::utf8(b"xy")); - assert!(s == string::utf8(b"axybcd"), 22) + let mut s = b"abcd".to_string(); + s.insert(1, b"xy".to_string()); + assert!(s == b"axybcd".to_string()) + } + + #[test] + fun test_into_bytes() { + assert!(b"abcd" == b"abcd".to_string().into_bytes()) } } diff --git a/external-crates/move/crates/move-stdlib/tests/type_name_tests.move b/external-crates/move/crates/move-stdlib/tests/type_name_tests.move index 48c1ba2edc1a5..256c31c901fa8 100644 --- a/external-crates/move/crates/move-stdlib/tests/type_name_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/type_name_tests.move @@ -1,47 +1,104 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + // note: intentionally using 0xa here to test non-0x1 module addresses module 0xA::type_name_tests { #[test_only] - use std::type_name::{get, into_string}; + use std::type_name::{get, into_string, is_primitive, get_address, get_module}; #[test_only] use std::ascii::string; - struct TestStruct {} + public struct TestStruct {} - struct TestGenerics { } + public struct TestGenerics { } - struct TestMultiGenerics { } + public struct TestMultiGenerics { } #[test] - fun test_ground_types() { - assert!(into_string(get()) == string(b"u8"), 0); - assert!(into_string(get()) == string(b"u64"), 0); - assert!(into_string(get()) == string(b"u128"), 0); - assert!(into_string(get
()) == string(b"address"), 0); - assert!(into_string(get()) == string(b"signer"), 0); - assert!(into_string(get>()) == string(b"vector"), 0) + fun test_primitive_types() { + assert!(into_string(get()) == string(b"u8")); + assert!(into_string(get()) == string(b"u16")); + assert!(into_string(get()) == string(b"u32")); + assert!(into_string(get()) == string(b"u64")); + assert!(into_string(get()) == string(b"u128")); + assert!(into_string(get()) == string(b"u256")); + assert!(into_string(get
()) == string(b"address")); + assert!(into_string(get>()) == string(b"vector")); + assert!(into_string(get>>()) == string(b"vector>")); + assert!(into_string(get>>()) == string(b"vector>")); } - // Note: these tests assume a 16 byte address length, and will fail on platforms where addresses are 20 or 32 bytes + #[test] + fun test_is_primitive() { + assert!(is_primitive(&get())); + assert!(is_primitive(&get())); + assert!(is_primitive(&get())); + assert!(is_primitive(&get())); + assert!(is_primitive(&get())); + assert!(is_primitive(&get())); + assert!(is_primitive(&get
())); + assert!(is_primitive(&get>())); + assert!(is_primitive(&get>>())); + assert!(is_primitive(&get>>())); + } + + // Note: these tests assume a 32 byte address length #[test] fun test_structs() { - assert!(into_string(get()) == string(b"000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestStruct"), 0); - assert!(into_string(get()) == string(b"0000000000000000000000000000000000000000000000000000000000000001::ascii::String"), 0); - assert!(into_string(get>()) == string(b"0000000000000000000000000000000000000000000000000000000000000001::option::Option"), 0); - assert!(into_string(get()) == string(b"0000000000000000000000000000000000000000000000000000000000000001::string::String"), 0); + assert!(into_string(get()) == string(b"000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestStruct")); + assert!(into_string(get()) == string(b"0000000000000000000000000000000000000000000000000000000000000001::ascii::String")); + assert!(into_string(get>()) == string(b"0000000000000000000000000000000000000000000000000000000000000001::option::Option")); + assert!(into_string(get()) == string(b"0000000000000000000000000000000000000000000000000000000000000001::string::String")); } - // Note: these tests assume a 16 byte address length, and will fail on platforms where addresses are 20 or 32 bytes + // Note: these tests assume a 32 byte address length #[test] fun test_generics() { - assert!(into_string(get>()) == string(b"000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestGenerics<0000000000000000000000000000000000000000000000000000000000000001::string::String>"), 0); - assert!(into_string(get>>()) == string(b"vector<000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestGenerics>"), 0); - assert!(into_string(get>>()) == string(b"0000000000000000000000000000000000000000000000000000000000000001::option::Option<000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestGenerics>"), 0); + assert!(into_string(get>()) == string(b"000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestGenerics<0000000000000000000000000000000000000000000000000000000000000001::string::String>")); + assert!(into_string(get>>()) == string(b"vector<000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestGenerics>")); + assert!(into_string(get>>()) == string(b"0000000000000000000000000000000000000000000000000000000000000001::option::Option<000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestGenerics>")); } - // Note: these tests assume a 16 byte address length, and will fail on platforms where addresses are 20 or 32 bytes + // Note: these tests assume a 32 byte address length #[test] fun test_multi_generics() { - assert!(into_string(get>()) == string(b"000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestMultiGenerics"), 0); - assert!(into_string(get, TestGenerics>>()) == string(b"000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestMultiGenerics,000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestGenerics>"), 0); + assert!(into_string(get>()) == string(b"000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestMultiGenerics")); + assert!(into_string(get, TestGenerics>>()) == string(b"000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestMultiGenerics,000000000000000000000000000000000000000000000000000000000000000a::type_name_tests::TestGenerics>")); + } + + #[test] + fun test_get_address() { + assert!(get_address(&get()) == string(b"0000000000000000000000000000000000000000000000000000000000000001")); + assert!(get_address(&get()) == string(b"000000000000000000000000000000000000000000000000000000000000000a")); + assert!(get_address(&get>()) == string(b"000000000000000000000000000000000000000000000000000000000000000a")); + } + + #[test] + fun test_get_module() { + assert!(get_module(&get()) == string(b"ascii")); + assert!(get_module(&get()) == string(b"type_name_tests")); + assert!(get_module(&get>()) == string(b"type_name_tests")); + } + + #[test, expected_failure(abort_code = std::type_name::ENonModuleType)] + fun test_get_address_aborts_with_primitive() { + get_address(&get()); + } + + #[test, expected_failure(abort_code = std::type_name::ENonModuleType)] + fun test_get_module_aborts_with_primitive() { + get_module(&get()); + } + + #[test, expected_failure(abort_code = std::type_name::ENonModuleType)] + fun test_get_address_aborts_with_primitive_generic() { + get_address(&get>()); + } + + #[test, expected_failure(abort_code = std::type_name::ENonModuleType)] + fun test_get_module_aborts_with_primitive_generic() { + get_module(&get>>()); } } diff --git a/external-crates/move/crates/move-stdlib/tests/u128_tests.move b/external-crates/move/crates/move-stdlib/tests/u128_tests.move new file mode 100644 index 0000000000000..315190be0589b --- /dev/null +++ b/external-crates/move/crates/move-stdlib/tests/u128_tests.move @@ -0,0 +1,78 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module std::u128_tests { + use std::integer_tests; + use std::unit_test::assert_eq; + + const BIT_SIZE: u8 = 128; + const MAX: u128 = 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF; + const MAX_PRED: u128 = MAX - 1; + + const CASES: vector = vector[ + 0, + 1, + 10, + 11, + 100, + 111, + 1 << (BIT_SIZE / 2 - 1), + (1 << (BIT_SIZE / 2 - 1)) + 1, + 1 << (BIT_SIZE - 1), + (1 << (BIT_SIZE - 1)) + 1, + MAX / 2, + (MAX / 2) + 1, + MAX_PRED, + MAX, + ]; + + #[test] + fun test_max() { + integer_tests::test_max!(MAX, CASES); + } + + #[test] + fun test_min() { + integer_tests::test_min!(MAX, CASES); + } + + #[test] + fun test_diff() { + integer_tests::test_diff!(MAX, CASES); + } + + #[test] + fun test_divide_and_round_up() { + integer_tests::test_divide_and_round_up!(MAX, CASES); + } + + #[test, expected_failure(arithmetic_error, location = std::u8)] + fun test_divide_and_round_up_error() { + 1u8.divide_and_round_up(0); + } + + #[test] + fun test_pow() { + integer_tests::test_pow!(MAX, CASES); + assert_eq!(2u128.pow(12), integer_tests::slow_pow!(2u128, 12)); + assert_eq!(3u128.pow(27), integer_tests::slow_pow!(3u128, 27)); + } + + #[test, expected_failure(arithmetic_error, location = std::u16)] + fun test_pow_overflow() { + 255u16.pow(255); + } + + #[test] + fun test_sqrt() { + let reflexive_cases = + vector[0, 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59]; + integer_tests::test_sqrt!(MAX, CASES, reflexive_cases) + } + + #[test] + fun test_dos() { + integer_tests::test_dos!(MAX, CASES); + } +} diff --git a/external-crates/move/crates/move-stdlib/tests/u16_tests.move b/external-crates/move/crates/move-stdlib/tests/u16_tests.move new file mode 100644 index 0000000000000..f872acf70f988 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/tests/u16_tests.move @@ -0,0 +1,78 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module std::u16_tests { + use std::integer_tests; + use std::unit_test::assert_eq; + + const BIT_SIZE: u8 = 16; + const MAX: u16 = 0xFFFF; + const MAX_PRED: u16 = MAX - 1; + + const CASES: vector = vector[ + 0, + 1, + 10, + 11, + 100, + 111, + 1 << (BIT_SIZE / 2 - 1), + (1 << (BIT_SIZE / 2 - 1)) + 1, + 1 << (BIT_SIZE - 1), + (1 << (BIT_SIZE - 1)) + 1, + MAX / 2, + (MAX / 2) + 1, + MAX_PRED, + MAX, + ]; + + #[test] + fun test_max() { + integer_tests::test_max!(MAX, CASES); + } + + #[test] + fun test_min() { + integer_tests::test_min!(MAX, CASES); + } + + #[test] + fun test_diff() { + integer_tests::test_diff!(MAX, CASES); + } + + #[test] + fun test_divide_and_round_up() { + integer_tests::test_divide_and_round_up!(MAX, CASES); + } + + #[test, expected_failure(arithmetic_error, location = std::u8)] + fun test_divide_and_round_up_error() { + 1u8.divide_and_round_up(0); + } + + #[test] + fun test_pow() { + integer_tests::test_pow!(MAX, CASES); + assert_eq!(2u16.pow(12), integer_tests::slow_pow!(2u16, 12)); + assert_eq!(3u16.pow(10), integer_tests::slow_pow!(3u16, 10)); + } + + #[test, expected_failure(arithmetic_error, location = std::u16)] + fun test_pow_overflow() { + 255u16.pow(255); + } + + #[test] + fun test_sqrt() { + let reflexive_cases = + vector[0, 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59]; + integer_tests::test_sqrt!(MAX, CASES, reflexive_cases) + } + + #[test] + fun test_dos() { + integer_tests::test_dos!(MAX, CASES); + } +} diff --git a/external-crates/move/crates/move-stdlib/tests/u256_tests.move b/external-crates/move/crates/move-stdlib/tests/u256_tests.move new file mode 100644 index 0000000000000..eff171bf43fa0 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/tests/u256_tests.move @@ -0,0 +1,72 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module std::u256_tests { + use std::integer_tests; + use std::unit_test::assert_eq; + + const BIT_SIZE: u8 = 255; + const MAX: u256 = + 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF; + const MAX_PRED: u256 = MAX - 1; + + const CASES: vector = vector[ + 0, + 1, + 10, + 11, + 100, + 111, + 1 << (BIT_SIZE / 2), + (1 << (BIT_SIZE / 2)) + 1, + 1 << BIT_SIZE, + (1 << BIT_SIZE) + 1, + MAX / 2, + (MAX / 2) + 1, + MAX_PRED, + MAX, + ]; + + #[test] + fun test_max() { + integer_tests::test_max!(MAX, CASES); + } + + #[test] + fun test_min() { + integer_tests::test_min!(MAX, CASES); + } + + #[test] + fun test_diff() { + integer_tests::test_diff!(MAX, CASES); + } + + #[test] + fun test_divide_and_round_up() { + integer_tests::test_divide_and_round_up!(MAX, CASES); + } + + #[test, expected_failure(arithmetic_error, location = std::u8)] + fun test_divide_and_round_up_error() { + 1u8.divide_and_round_up(0); + } + + #[test] + fun test_pow() { + integer_tests::test_pow!(MAX, CASES); + assert_eq!(2u256.pow(12), integer_tests::slow_pow!(2u256, 12)); + assert_eq!(3u256.pow(27), integer_tests::slow_pow!(3u256, 27)); + } + + #[test, expected_failure(arithmetic_error, location = std::u256)] + fun test_pow_overflow() { + 255u256.pow(255); + } + + #[test] + fun test_dos() { + integer_tests::test_dos!(MAX, CASES); + } +} diff --git a/external-crates/move/crates/move-stdlib/tests/u32_tests.move b/external-crates/move/crates/move-stdlib/tests/u32_tests.move new file mode 100644 index 0000000000000..c2890c1d5cff9 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/tests/u32_tests.move @@ -0,0 +1,78 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module std::u32_tests { + use std::integer_tests; + use std::unit_test::assert_eq; + + const BIT_SIZE: u8 = 32; + const MAX: u32 = 0xFFFF_FFFF; + const MAX_PRED: u32 = MAX - 1; + + const CASES: vector = vector[ + 0, + 1, + 10, + 11, + 100, + 111, + 1 << (BIT_SIZE / 2 - 1), + (1 << (BIT_SIZE / 2 - 1)) + 1, + 1 << (BIT_SIZE - 1), + (1 << (BIT_SIZE - 1)) + 1, + MAX / 2, + (MAX / 2) + 1, + MAX_PRED, + MAX, + ]; + + #[test] + fun test_max() { + integer_tests::test_max!(MAX, CASES); + } + + #[test] + fun test_min() { + integer_tests::test_min!(MAX, CASES); + } + + #[test] + fun test_diff() { + integer_tests::test_diff!(MAX, CASES); + } + + #[test] + fun test_divide_and_round_up() { + integer_tests::test_divide_and_round_up!(MAX, CASES); + } + + #[test, expected_failure(arithmetic_error, location = std::u8)] + fun test_divide_and_round_up_error() { + 1u8.divide_and_round_up(0); + } + + #[test] + fun test_pow() { + integer_tests::test_pow!(MAX, CASES); + assert_eq!(2u32.pow(12), integer_tests::slow_pow!(2u32, 12)); + assert_eq!(3u32.pow(20), integer_tests::slow_pow!(3u32, 20)); + } + + #[test, expected_failure(arithmetic_error, location = std::u32)] + fun test_pow_overflow() { + 255u32.pow(255); + } + + #[test] + fun test_sqrt() { + let reflexive_cases = + vector[0, 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59]; + integer_tests::test_sqrt!(MAX, CASES, reflexive_cases) + } + + #[test] + fun test_dos() { + integer_tests::test_dos!(MAX, CASES); + } +} diff --git a/external-crates/move/crates/move-stdlib/tests/u64_tests.move b/external-crates/move/crates/move-stdlib/tests/u64_tests.move new file mode 100644 index 0000000000000..aee0790856f0f --- /dev/null +++ b/external-crates/move/crates/move-stdlib/tests/u64_tests.move @@ -0,0 +1,79 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module std::u64_tests { + use std::integer_tests; + use std::unit_test::assert_eq; + + const BIT_SIZE: u8 = 64; + const MAX: u64 = 0xFFFF_FFFF_FFFF_FFFF; + const MAX_PRED: u64 = MAX - 1; + + const CASES: vector = vector[ + 0, + 1, + 10, + 11, + 100, + 111, + 1 << (BIT_SIZE / 2 - 1), + (1 << (BIT_SIZE / 2 - 1)) + 1, + 1 << (BIT_SIZE - 1), + (1 << (BIT_SIZE - 1)) + 1, + MAX / 2, + (MAX / 2) + 1, + MAX_PRED, + MAX, + ]; + + #[test] + fun test_max() { + integer_tests::test_max!(MAX, CASES); + } + + #[test] + fun test_min() { + integer_tests::test_min!(MAX, CASES); + } + + #[test] + fun test_diff() { + integer_tests::test_diff!(MAX, CASES); + } + + #[test] + fun test_divide_and_round_up() { + integer_tests::test_divide_and_round_up!(MAX, CASES); + } + + #[test, expected_failure(arithmetic_error, location = std::u8)] + fun test_divide_and_round_up_error() { + 1u8.divide_and_round_up(0); + } + + #[test] + fun test_pow() { + integer_tests::test_pow!(MAX, CASES); + assert_eq!(2u64.pow(12), integer_tests::slow_pow!(2u64, 12)); + assert_eq!(3u64.pow(27), integer_tests::slow_pow!(3u64, 27)); + } + + #[test, expected_failure(arithmetic_error, location = std::u64)] + fun test_pow_overflow() { + 255u64.pow(255); + } + + #[test] + fun test_sqrt() { + let reflexive_cases = + vector[0, 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59]; + integer_tests::test_sqrt!(MAX, CASES, reflexive_cases) + } + + #[test] + fun test_dos() { + integer_tests::test_dos!(MAX, CASES); + } + +} diff --git a/external-crates/move/crates/move-stdlib/tests/u8_tests.move b/external-crates/move/crates/move-stdlib/tests/u8_tests.move new file mode 100644 index 0000000000000..7aa1d6f263a00 --- /dev/null +++ b/external-crates/move/crates/move-stdlib/tests/u8_tests.move @@ -0,0 +1,77 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module std::u8_tests { + use std::integer_tests; + use std::unit_test::assert_eq; + + const BIT_SIZE: u8 = 8; + const MAX: u8 = 0xFF; + const MAX_PRED: u8 = MAX - 1; + + const CASES: vector = vector[ + 0, + 1, + 10, + 11, + 100, + 111, + 1 << (BIT_SIZE / 2 - 1), + (1 << (BIT_SIZE / 2 - 1)) + 1, + 1 << (BIT_SIZE - 1), + (1 << (BIT_SIZE - 1)) + 1, + MAX / 2, + (MAX / 2) + 1, + MAX_PRED, + MAX, + ]; + + #[test] + fun test_max() { + integer_tests::test_max!(MAX, CASES); + } + + #[test] + fun test_min() { + integer_tests::test_min!(MAX, CASES); + } + + #[test] + fun test_diff() { + integer_tests::test_diff!(MAX, CASES); + } + + #[test] + fun test_divide_and_round_up() { + integer_tests::test_divide_and_round_up!(MAX, CASES); + } + + #[test, expected_failure(arithmetic_error, location = std::u8)] + fun test_divide_and_round_up_error() { + 1u8.divide_and_round_up(0); + } + + #[test] + fun test_pow() { + integer_tests::test_pow!(MAX, CASES); + } + + #[test, expected_failure(arithmetic_error, location = std::u8)] + fun test_pow_overflow() { + 255u8.pow(255); + } + + #[test] + fun test_sqrt() { + integer_tests::test_sqrt!(MAX, CASES, vector[0, 2, 5, 8, 11, 14]); + } + + #[test] + fun test_dos() { + let mut sum = 0u16; + 255u8.do_eq!(|i| sum = sum + (i as u16)); + assert_eq!(sum, 32640); + integer_tests::test_dos!(MAX, CASES); + } +} diff --git a/external-crates/move/crates/move-stdlib/tests/vector_tests.move b/external-crates/move/crates/move-stdlib/tests/vector_tests.move index 5480f6b685d96..2bb76d6310017 100644 --- a/external-crates/move/crates/move-stdlib/tests/vector_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/vector_tests.move @@ -1,90 +1,93 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + #[test_only] module std::vector_tests { - use std::vector as V; - - struct R has store { } - struct Droppable has drop {} - struct NotDroppable {} + public struct R has store { } + public struct Droppable has drop {} + public struct NotDroppable {} #[test] fun test_singleton_contains() { - assert!(*V::borrow(&V::singleton(0), 0) == 0, 0); - assert!(*V::borrow(&V::singleton(true), 0) == true, 0); - assert!(*V::borrow(&V::singleton(@0x1), 0) == @0x1, 0); + assert!(vector[0][0] == 0); + assert!(vector[true][0] == true); + assert!(vector[@0x1][0] == @0x1); } #[test] fun test_singleton_len() { - assert!(V::length(&V::singleton(0)) == 1, 0); - assert!(V::length(&V::singleton(true)) == 1, 0); - assert!(V::length(&V::singleton(@0x1)) == 1, 0); + assert!(&vector[0].length() == 1); + assert!(&vector[true].length() == 1); + assert!(&vector[@0x1].length() == 1); } #[test] fun test_empty_is_empty() { - assert!(V::is_empty(&V::empty()), 0); + assert!(vector[].is_empty()); } #[test] fun append_empties_is_empty() { - let v1 = V::empty(); - let v2 = V::empty(); - V::append(&mut v1, v2); - assert!(V::is_empty(&v1), 0); + let mut v1 = vector[]; + let v2 = vector[]; + v1.append(v2); + assert!(v1.is_empty()); } #[test] fun append_respects_order_empty_lhs() { - let v1 = V::empty(); - let v2 = V::empty(); - V::push_back(&mut v2, 0); - V::push_back(&mut v2, 1); - V::push_back(&mut v2, 2); - V::push_back(&mut v2, 3); - V::append(&mut v1, v2); - assert!(!V::is_empty(&v1), 0); - assert!(V::length(&v1) == 4, 1); - assert!(*V::borrow(&v1, 0) == 0, 2); - assert!(*V::borrow(&v1, 1) == 1, 3); - assert!(*V::borrow(&v1, 2) == 2, 4); - assert!(*V::borrow(&v1, 3) == 3, 5); + let mut v1 = vector[]; + let mut v2 = vector[]; + v2.push_back(0); + v2.push_back(1); + v2.push_back(2); + v2.push_back(3); + v1.append(v2); + assert!(!v1.is_empty()); + assert!(v1.length() == 4); + assert!(v1[0] == 0); + assert!(v1[1] == 1); + assert!(v1[2] == 2); + assert!(v1[3] == 3); } #[test] fun append_respects_order_empty_rhs() { - let v1 = V::empty(); - let v2 = V::empty(); - V::push_back(&mut v1, 0); - V::push_back(&mut v1, 1); - V::push_back(&mut v1, 2); - V::push_back(&mut v1, 3); - V::append(&mut v1, v2); - assert!(!V::is_empty(&v1), 0); - assert!(V::length(&v1) == 4, 1); - assert!(*V::borrow(&v1, 0) == 0, 2); - assert!(*V::borrow(&v1, 1) == 1, 3); - assert!(*V::borrow(&v1, 2) == 2, 4); - assert!(*V::borrow(&v1, 3) == 3, 5); + let mut v1 = vector[]; + let v2 = vector[]; + v1.push_back(0); + v1.push_back(1); + v1.push_back(2); + v1.push_back(3); + v1.append(v2); + assert!(!v1.is_empty()); + assert!(v1.length() == 4); + assert!(v1[0] == 0); + assert!(v1[1] == 1); + assert!(v1[2] == 2); + assert!(v1[3] == 3); } #[test] fun append_respects_order_nonempty_rhs_lhs() { - let v1 = V::empty(); - let v2 = V::empty(); - V::push_back(&mut v1, 0); - V::push_back(&mut v1, 1); - V::push_back(&mut v1, 2); - V::push_back(&mut v1, 3); - V::push_back(&mut v2, 4); - V::push_back(&mut v2, 5); - V::push_back(&mut v2, 6); - V::push_back(&mut v2, 7); - V::append(&mut v1, v2); - assert!(!V::is_empty(&v1), 0); - assert!(V::length(&v1) == 8, 1); - let i = 0; + let mut v1 = vector[]; + let mut v2 = vector[]; + v1.push_back(0); + v1.push_back(1); + v1.push_back(2); + v1.push_back(3); + v2.push_back(4); + v2.push_back(5); + v2.push_back(6); + v2.push_back(7); + v1.append(v2); + assert!(!v1.is_empty()); + assert!(v1.length() == 8); + let mut i = 0; while (i < 8) { - assert!(*V::borrow(&v1, i) == i, i); + assert!(v1[i] == i, i); i = i + 1; } } @@ -92,395 +95,397 @@ module std::vector_tests { #[test] #[expected_failure(vector_error, minor_status = 1, location = Self)] fun borrow_out_of_range() { - let v = V::empty(); - V::push_back(&mut v, 7); - V::borrow(&v, 1); + let mut v = vector[]; + v.push_back(7); + &v[1]; } #[test] fun vector_contains() { - let vec = V::empty(); - assert!(!V::contains(&vec, &0), 1); + let mut vec = vector[]; + assert!(!vec.contains(&0)); - V::push_back(&mut vec, 0); - assert!(V::contains(&vec, &0), 2); - assert!(!V::contains(&vec, &1), 3); + vec.push_back(0); + assert!(vec.contains(&0)); + assert!(!vec.contains(&1)); - V::push_back(&mut vec, 1); - assert!(V::contains(&vec, &0), 4); - assert!(V::contains(&vec, &1), 5); - assert!(!V::contains(&vec, &2), 6); + vec.push_back(1); + assert!(vec.contains(&0)); + assert!(vec.contains(&1)); + assert!(!vec.contains(&2)); - V::push_back(&mut vec, 2); - assert!(V::contains(&vec, &0), 7); - assert!(V::contains(&vec, &1), 8); - assert!(V::contains(&vec, &2), 9); - assert!(!V::contains(&vec, &3), 10); + vec.push_back(2); + assert!(vec.contains(&0)); + assert!(vec.contains(&1)); + assert!(vec.contains(&2)); + assert!(!vec.contains(&3)); } #[test] fun destroy_empty() { - V::destroy_empty(V::empty()); - V::destroy_empty(V::empty()); + vector[].destroy_empty(); + vector[].destroy_empty(); + vector::empty().destroy_empty(); + vector::empty().destroy_empty(); } #[test] fun destroy_empty_with_pops() { - let v = V::empty(); - V::push_back(&mut v, 42); - V::pop_back(&mut v); - V::destroy_empty(v); + let mut v = vector[]; + v.push_back(42); + v.pop_back(); + v.destroy_empty(); } #[test] #[expected_failure(vector_error, minor_status = 3, location = Self)] fun destroy_non_empty() { - let v = V::empty(); - V::push_back(&mut v, 42); - V::destroy_empty(v); + let mut v = vector[]; + v.push_back(42); + v.destroy_empty(); } #[test] fun get_set_work() { - let vec = V::empty(); - V::push_back(&mut vec, 0); - V::push_back(&mut vec, 1); - assert!(*V::borrow(&vec, 1) == 1, 0); - assert!(*V::borrow(&vec, 0) == 0, 1); + let mut vec = vector[]; + vec.push_back(0); + vec.push_back(1); + assert!(vec[1] == 1); + assert!(vec[0] == 0); - *V::borrow_mut(&mut vec, 0) = 17; - assert!(*V::borrow(&vec, 1) == 1, 0); - assert!(*V::borrow(&vec, 0) == 17, 0); + *&mut vec[0] = 17; + assert!(vec[1] == 1); + assert!(vec[0] == 17); } #[test] #[expected_failure(vector_error, minor_status = 2, location = Self)] fun pop_out_of_range() { - let v = V::empty(); - V::pop_back(&mut v); + let mut v = vector[]; + v.pop_back(); } #[test] fun swap_different_indices() { - let vec = V::empty(); - V::push_back(&mut vec, 0); - V::push_back(&mut vec, 1); - V::push_back(&mut vec, 2); - V::push_back(&mut vec, 3); - V::swap(&mut vec, 0, 3); - V::swap(&mut vec, 1, 2); - assert!(*V::borrow(&vec, 0) == 3, 0); - assert!(*V::borrow(&vec, 1) == 2, 0); - assert!(*V::borrow(&vec, 2) == 1, 0); - assert!(*V::borrow(&vec, 3) == 0, 0); + let mut vec = vector[]; + vec.push_back(0); + vec.push_back(1); + vec.push_back(2); + vec.push_back(3); + vec.swap(0, 3); + vec.swap(1, 2); + assert!(vec[0] == 3); + assert!(vec[1] == 2); + assert!(vec[2] == 1); + assert!(vec[3] == 0); } #[test] fun swap_same_index() { - let vec = V::empty(); - V::push_back(&mut vec, 0); - V::push_back(&mut vec, 1); - V::push_back(&mut vec, 2); - V::push_back(&mut vec, 3); - V::swap(&mut vec, 1, 1); - assert!(*V::borrow(&vec, 0) == 0, 0); - assert!(*V::borrow(&vec, 1) == 1, 0); - assert!(*V::borrow(&vec, 2) == 2, 0); - assert!(*V::borrow(&vec, 3) == 3, 0); + let mut vec = vector[]; + vec.push_back(0); + vec.push_back(1); + vec.push_back(2); + vec.push_back(3); + vec.swap(1, 1); + assert!(vec[0] == 0); + assert!(vec[1] == 1); + assert!(vec[2] == 2); + assert!(vec[3] == 3); } #[test] fun remove_singleton_vector() { - let v = V::empty(); - V::push_back(&mut v, 0); - assert!(V::remove(&mut v, 0) == 0, 0); - assert!(V::length(&v) == 0, 0); + let mut v = vector[]; + v.push_back(0); + assert!(v.remove(0) == 0); + assert!(v.length() == 0); } #[test] fun remove_nonsingleton_vector() { - let v = V::empty(); - V::push_back(&mut v, 0); - V::push_back(&mut v, 1); - V::push_back(&mut v, 2); - V::push_back(&mut v, 3); + let mut v = vector[]; + v.push_back(0); + v.push_back(1); + v.push_back(2); + v.push_back(3); - assert!(V::remove(&mut v, 1) == 1, 0); - assert!(V::length(&v) == 3, 0); - assert!(*V::borrow(&v, 0) == 0, 0); - assert!(*V::borrow(&v, 1) == 2, 0); - assert!(*V::borrow(&v, 2) == 3, 0); + assert!(v.remove(1) == 1); + assert!(v.length() == 3); + assert!(v[0] == 0); + assert!(v[1] == 2); + assert!(v[2] == 3); } #[test] fun remove_nonsingleton_vector_last_elem() { - let v = V::empty(); - V::push_back(&mut v, 0); - V::push_back(&mut v, 1); - V::push_back(&mut v, 2); - V::push_back(&mut v, 3); + let mut v = vector[]; + v.push_back(0); + v.push_back(1); + v.push_back(2); + v.push_back(3); - assert!(V::remove(&mut v, 3) == 3, 0); - assert!(V::length(&v) == 3, 0); - assert!(*V::borrow(&v, 0) == 0, 0); - assert!(*V::borrow(&v, 1) == 1, 0); - assert!(*V::borrow(&v, 2) == 2, 0); + assert!(v.remove(3) == 3); + assert!(v.length() == 3); + assert!(v[0] == 0); + assert!(v[1] == 1); + assert!(v[2] == 2); } #[test] - #[expected_failure(abort_code = V::EINDEX_OUT_OF_BOUNDS)] + #[expected_failure(abort_code = vector::EINDEX_OUT_OF_BOUNDS)] fun remove_empty_vector() { - let v = V::empty(); - V::remove(&mut v, 0); + let mut v = vector[]; + v.remove(0); } #[test] - #[expected_failure(abort_code = V::EINDEX_OUT_OF_BOUNDS)] + #[expected_failure(abort_code = vector::EINDEX_OUT_OF_BOUNDS)] fun remove_out_of_bound_index() { - let v = V::empty(); - V::push_back(&mut v, 0); - V::remove(&mut v, 1); + let mut v = vector[]; + v.push_back(0); + v.remove(1); } #[test] fun reverse_vector_empty() { - let v = V::empty(); - let is_empty = V::is_empty(&v); - V::reverse(&mut v); - assert!(is_empty == V::is_empty(&v), 0); + let mut v = vector[]; + let is_empty = v.is_empty(); + v.reverse(); + assert!(is_empty == v.is_empty()); } #[test] fun reverse_singleton_vector() { - let v = V::empty(); - V::push_back(&mut v, 0); - assert!(*V::borrow(&v, 0) == 0, 1); - V::reverse(&mut v); - assert!(*V::borrow(&v, 0) == 0, 2); + let mut v = vector[]; + v.push_back(0); + assert!(v[0] == 0); + v.reverse(); + assert!(v[0] == 0); } #[test] fun reverse_vector_nonempty_even_length() { - let v = V::empty(); - V::push_back(&mut v, 0); - V::push_back(&mut v, 1); - V::push_back(&mut v, 2); - V::push_back(&mut v, 3); + let mut v = vector[]; + v.push_back(0); + v.push_back(1); + v.push_back(2); + v.push_back(3); - assert!(*V::borrow(&v, 0) == 0, 1); - assert!(*V::borrow(&v, 1) == 1, 2); - assert!(*V::borrow(&v, 2) == 2, 3); - assert!(*V::borrow(&v, 3) == 3, 4); + assert!(v[0] == 0); + assert!(v[1] == 1); + assert!(v[2] == 2); + assert!(v[3] == 3); - V::reverse(&mut v); + v.reverse(); - assert!(*V::borrow(&v, 3) == 0, 5); - assert!(*V::borrow(&v, 2) == 1, 6); - assert!(*V::borrow(&v, 1) == 2, 7); - assert!(*V::borrow(&v, 0) == 3, 8); + assert!(v[3] == 0); + assert!(v[2] == 1); + assert!(v[1] == 2); + assert!(v[0] == 3); } #[test] fun reverse_vector_nonempty_odd_length_non_singleton() { - let v = V::empty(); - V::push_back(&mut v, 0); - V::push_back(&mut v, 1); - V::push_back(&mut v, 2); + let mut v = vector[]; + v.push_back(0); + v.push_back(1); + v.push_back(2); - assert!(*V::borrow(&v, 0) == 0, 1); - assert!(*V::borrow(&v, 1) == 1, 2); - assert!(*V::borrow(&v, 2) == 2, 3); + assert!(v[0] == 0); + assert!(v[1] == 1); + assert!(v[2] == 2); - V::reverse(&mut v); + v.reverse(); - assert!(*V::borrow(&v, 2) == 0, 4); - assert!(*V::borrow(&v, 1) == 1, 5); - assert!(*V::borrow(&v, 0) == 2, 6); + assert!(v[2] == 0); + assert!(v[1] == 1); + assert!(v[0] == 2); } #[test] #[expected_failure(vector_error, minor_status = 1, location = Self)] fun swap_empty() { - let v = V::empty(); - V::swap(&mut v, 0, 0); + let mut v = vector[]; + v.swap(0, 0); } #[test] #[expected_failure(vector_error, minor_status = 1, location = Self)] fun swap_out_of_range() { - let v = V::empty(); + let mut v = vector[]; - V::push_back(&mut v, 0); - V::push_back(&mut v, 1); - V::push_back(&mut v, 2); - V::push_back(&mut v, 3); + v.push_back(0); + v.push_back(1); + v.push_back(2); + v.push_back(3); - V::swap(&mut v, 1, 10); + v.swap(1, 10); } #[test] - #[expected_failure(abort_code = V::EINDEX_OUT_OF_BOUNDS)] + #[expected_failure(abort_code = std::vector::EINDEX_OUT_OF_BOUNDS)] fun swap_remove_empty() { - let v = V::empty(); - V::swap_remove(&mut v, 0); + let mut v = vector[]; + v.swap_remove(0); } #[test] fun swap_remove_singleton() { - let v = V::empty(); - V::push_back(&mut v, 0); - assert!(V::swap_remove(&mut v, 0) == 0, 0); - assert!(V::is_empty(&v), 1); + let mut v = vector[]; + v.push_back(0); + assert!(v.swap_remove(0) == 0); + assert!(v.is_empty()); } #[test] fun swap_remove_inside_vector() { - let v = V::empty(); - V::push_back(&mut v, 0); - V::push_back(&mut v, 1); - V::push_back(&mut v, 2); - V::push_back(&mut v, 3); + let mut v = vector[]; + v.push_back(0); + v.push_back(1); + v.push_back(2); + v.push_back(3); - assert!(*V::borrow(&v, 0) == 0, 1); - assert!(*V::borrow(&v, 1) == 1, 2); - assert!(*V::borrow(&v, 2) == 2, 3); - assert!(*V::borrow(&v, 3) == 3, 4); + assert!(v[0] == 0); + assert!(v[1] == 1); + assert!(v[2] == 2); + assert!(v[3] == 3); - assert!(V::swap_remove(&mut v, 1) == 1, 5); - assert!(V::length(&v) == 3, 6); + assert!(v.swap_remove(1) == 1); + assert!(v.length() == 3); - assert!(*V::borrow(&v, 0) == 0, 7); - assert!(*V::borrow(&v, 1) == 3, 8); - assert!(*V::borrow(&v, 2) == 2, 9); + assert!(v[0] == 0); + assert!(v[1] == 3); + assert!(v[2] == 2); } #[test] fun swap_remove_end_of_vector() { - let v = V::empty(); - V::push_back(&mut v, 0); - V::push_back(&mut v, 1); - V::push_back(&mut v, 2); - V::push_back(&mut v, 3); + let mut v = vector[]; + v.push_back(0); + v.push_back(1); + v.push_back(2); + v.push_back(3); - assert!(*V::borrow(&v, 0) == 0, 1); - assert!(*V::borrow(&v, 1) == 1, 2); - assert!(*V::borrow(&v, 2) == 2, 3); - assert!(*V::borrow(&v, 3) == 3, 4); + assert!(v[0] == 0); + assert!(v[1] == 1); + assert!(v[2] == 2); + assert!(v[3] == 3); - assert!(V::swap_remove(&mut v, 3) == 3, 5); - assert!(V::length(&v) == 3, 6); + assert!(v.swap_remove(3) == 3); + assert!(v.length() == 3); - assert!(*V::borrow(&v, 0) == 0, 7); - assert!(*V::borrow(&v, 1) == 1, 8); - assert!(*V::borrow(&v, 2) == 2, 9); + assert!(v[0] == 0); + assert!(v[1] == 1); + assert!(v[2] == 2); } #[test] #[expected_failure(vector_error, minor_status = 1, location = std::vector)] fun swap_remove_out_of_range() { - let v = V::empty(); - V::push_back(&mut v, 0); - V::swap_remove(&mut v, 1); + let mut v = vector[]; + v.push_back(0); + v.swap_remove(1); } #[test] fun push_back_and_borrow() { - let v = V::empty(); - V::push_back(&mut v, 7); - assert!(!V::is_empty(&v), 0); - assert!(V::length(&v) == 1, 1); - assert!(*V::borrow(&v, 0) == 7, 2); + let mut v = vector[]; + v.push_back(7); + assert!(!v.is_empty()); + assert!(v.length() == 1); + assert!(v[0] == 7); - V::push_back(&mut v, 8); - assert!(V::length(&v) == 2, 3); - assert!(*V::borrow(&v, 0) == 7, 4); - assert!(*V::borrow(&v, 1) == 8, 5); + v.push_back(8); + assert!(v.length() == 2); + assert!(v[0] == 7); + assert!(v[1] == 8); } #[test] fun index_of_empty_not_has() { - let v = V::empty(); - let (has, index) = V::index_of(&v, &true); - assert!(!has, 0); - assert!(index == 0, 1); + let v = vector[]; + let (has, index) = v.index_of(&true); + assert!(!has); + assert!(index == 0); } #[test] fun index_of_nonempty_not_has() { - let v = V::empty(); - V::push_back(&mut v, false); - let (has, index) = V::index_of(&v, &true); - assert!(!has, 0); - assert!(index == 0, 1); + let mut v = vector[]; + v.push_back(false); + let (has, index) = v.index_of(&true); + assert!(!has); + assert!(index == 0); } #[test] fun index_of_nonempty_has() { - let v = V::empty(); - V::push_back(&mut v, false); - V::push_back(&mut v, true); - let (has, index) = V::index_of(&v, &true); - assert!(has, 0); - assert!(index == 1, 1); + let mut v = vector[]; + v.push_back(false); + v.push_back(true); + let (has, index) = v.index_of(&true); + assert!(has); + assert!(index == 1); } // index_of will return the index first occurence that is equal #[test] fun index_of_nonempty_has_multiple_occurences() { - let v = V::empty(); - V::push_back(&mut v, false); - V::push_back(&mut v, true); - V::push_back(&mut v, true); - let (has, index) = V::index_of(&v, &true); - assert!(has, 0); - assert!(index == 1, 1); + let mut v = vector[]; + v.push_back(false); + v.push_back(true); + v.push_back(true); + let (has, index) = v.index_of(&true); + assert!(has); + assert!(index == 1); } #[test] fun length() { - let empty = V::empty(); - assert!(V::length(&empty) == 0, 0); - let i = 0; + let mut empty = vector[]; + assert!(empty.length() == 0); + let mut i = 0; let max_len = 42; while (i < max_len) { - V::push_back(&mut empty, i); - assert!(V::length(&empty) == i + 1, i); + empty.push_back(i); + assert!(empty.length() == i + 1, i); i = i + 1; } } #[test] fun pop_push_back() { - let v = V::empty(); - let i = 0; + let mut v = vector[]; + let mut i = 0; let max_len = 42; while (i < max_len) { - V::push_back(&mut v, i); + v.push_back(i); i = i + 1; }; while (i > 0) { - assert!(V::pop_back(&mut v) == i - 1, i); + assert!(v.pop_back() == i - 1, i); i = i - 1; }; } #[test_only] - fun test_natives_with_type(x1: T, x2: T): (T, T) { - let v = V::empty(); - assert!(V::length(&v) == 0, 0); - V::push_back(&mut v, x1); - assert!(V::length(&v) == 1, 1); - V::push_back(&mut v, x2); - assert!(V::length(&v) == 2, 2); - V::swap(&mut v, 0, 1); - x1 = V::pop_back(&mut v); - assert!(V::length(&v) == 1, 3); - x2 = V::pop_back(&mut v); - assert!(V::length(&v) == 0, 4); - V::destroy_empty(v); + fun test_natives_with_type(mut x1: T, mut x2: T): (T, T) { + let mut v = vector[]; + assert!(v.length() == 0); + v.push_back(x1); + assert!(v.length() == 1); + v.push_back(x2); + assert!(v.length() == 2); + v.swap(0, 1); + x1 = v.pop_back(); + assert!(v.length() == 1); + x2 = v.pop_back(); + assert!(v.length() == 0); + v.destroy_empty(); (x1, x2) } @@ -495,7 +500,7 @@ module std::vector_tests { test_natives_with_type(true, false); test_natives_with_type
(@0x1, @0x2); - test_natives_with_type>(V::empty(), V::empty()); + test_natives_with_type>(vector[], vector[]); test_natives_with_type(Droppable{}, Droppable{}); (NotDroppable {}, NotDroppable {}) = test_natives_with_type( @@ -506,64 +511,279 @@ module std::vector_tests { #[test] fun test_insert() { - let v = vector[7]; - V::insert(&mut v, 6, 0); - assert!(v == vector[6, 7], 0); + let mut v = vector[7]; + v.insert(6, 0); + assert!(v == vector[6, 7]); - let v = vector[7, 9]; - V::insert(&mut v, 8, 1); - assert!(v == vector[7, 8, 9], 0); + let mut v = vector[7, 9]; + v.insert(8, 1); + assert!(v == vector[7, 8, 9]); - let v = vector[6, 7]; - V::insert(&mut v, 5, 0); - assert!(v == vector[5, 6, 7], 0); + let mut v = vector[6, 7]; + v.insert(5, 0); + assert!(v == vector[5, 6, 7]); - let v = vector[5, 6, 8]; - V::insert(&mut v, 7, 2); - assert!(v == vector[5, 6, 7, 8], 0); + let mut v = vector[5, 6, 8]; + v.insert(7, 2); + assert!(v == vector[5, 6, 7, 8]); } #[test] fun insert_at_end() { - let v = vector[]; - V::insert(&mut v, 6, 0); - assert!(v == vector[6], 0); + let mut v = vector[]; + v.insert(6, 0); + assert!(v == vector[6]); - V::insert(&mut v, 7, 1); - assert!(v == vector[6, 7], 0); + v.insert(7, 1); + assert!(v == vector[6, 7]); } #[test] - #[expected_failure(abort_code = V::EINDEX_OUT_OF_BOUNDS)] + #[expected_failure(abort_code = std::vector::EINDEX_OUT_OF_BOUNDS)] fun insert_out_of_range() { - let v = vector[7]; - V::insert(&mut v, 6, 2); + let mut v = vector[7]; + v.insert(6, 2); } #[test] fun size_limit_ok() { - let v = V::empty(); - let i = 0; - // Limit is currently 1024 * 1024 - let max_len = 1024 * 1024; + let mut v = vector[]; + let mut i = 0; + // Limit is currently 1024 * 54 + let max_len = 1024 * 53; while (i < max_len) { - V::push_back(&mut v, i); + v.push_back(i); i = i + 1; }; } #[test] - #[expected_failure(vector_error, minor_status = 4, location = Self)] + #[expected_failure(out_of_gas, location = Self)] fun size_limit_fail() { - let v = V::empty(); - let i = 0; - // Limit is currently 1024 * 1024 - let max_len = 1024 * 1024 + 1; + let mut v = vector[]; + let mut i = 0; + // Choose value beyond limit + let max_len = 1024 * 1024; while (i < max_len) { - V::push_back(&mut v, i); + v.push_back(i); i = i + 1; }; } + + #[test] + fun test_string_aliases() { + assert!(b"hello_world".to_string().length() == 11); + assert!(b"hello_world".try_to_string().is_some()); + + assert!(b"hello_world".to_ascii_string().length() == 11); + assert!(b"hello_world".try_to_ascii_string().is_some()); + } + + // === Macros === + + #[test] + fun test_destroy_macro() { + vector[].destroy!(|_| assert!(false)); // very funky + + let mut acc = 0; + vector[10, 20, 30, 40].destroy!(|e| acc = acc + e); + assert!(acc == 100); + } + + #[test] + fun test_count_macro() { + assert!(vector[].count!(|e| *e == 2) == 0); + assert!(vector[0, 1, 2, 3].count!(|e| *e == 2) == 1); + assert!(vector[0, 1, 2, 3].count!(|e| *e % 2 == 0) == vector[0, 2].length()); + } + + #[test] + fun test_tabulate_macro() { + let v = vector::tabulate!(10, |i| i); + assert!(v == vector[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + + let v = vector::tabulate!(5, |i| 10 - i); + assert!(v == vector[10, 9, 8, 7, 6]); + + let v = vector::tabulate!(0, |i| i); + assert!(v == vector[]); + } + + #[test] + fun test_do_macro() { + vector[].do!(|_| assert!(false)); // should never run + vector[].do_ref!(|_| assert!(false)); + vector[].do_mut!(|_| assert!(false)); + + let mut acc = 0; + vector[10, 20, 30, 40].do!(|e| acc = acc + e); + assert!(acc == 100); + + let vec = vector[10, 20]; + vec.do!(|e| acc = acc + e); + assert!(vector[10, 20] == vec); + + let mut acc = 0; + vector[10, 20, 30, 40].do_ref!(|e| acc = acc + *e); + assert!(acc == 100); + + let mut vec = vector[10, 20, 30, 40]; + vec.do_mut!(|e| *e = *e + 1); + assert!(vec == vector[11, 21, 31, 41]); + } + + #[test] + fun test_map_macro() { + let e = vector[]; + assert!(e.map!(|e| e + 1) == vector[]); + + let r = vector[0, 1, 2, 3]; + assert!(r.map!(|e| e + 1) == vector[1, 2, 3, 4]); + + let r = vector[0, 1, 2, 3]; + assert!(r.map_ref!(|e| *e * 2) == vector[0, 2, 4, 6]); + } + + #[test] + fun filter_macro() { + let e = vector[]; + assert!(e.filter!(|e| *e % 2 == 0) == vector[]); + + let r = vector[0, 1, 2, 3]; + assert!(r.filter!(|e| *e % 2 == 0) == vector[0, 2]); + } + + #[test] + fun partition_macro() { + let e = vector[]; + let (even, odd) = e.partition!(|e| (*e % 2) == 0); + assert!(even == vector[]); + assert!(odd == vector[]); + + let r = vector[0, 1, 2, 3]; + let (even, odd) = r.partition!(|e| (*e % 2) == 0); + assert!(even == vector[0, 2]); + assert!(odd == vector[1, 3]); + } + + #[test] + fun find_index_macro() { + let e = vector[]; + assert!(e.find_index!(|e| *e == 0).is_none()); + assert!(e.find_index!(|_| true).is_none()); + + let r = vector[0, 10, 100, 1_000]; + assert!(r.find_index!(|e| *e == 100).destroy_some() == 2); + assert!(r.find_index!(|e| *e == 10_000).is_none()); + } + + #[test] + fun fold_macro() { + let e = vector[]; + assert!(e.fold!(0, |acc, e| acc + e) == 0); + + let r = vector[0, 1, 2, 3]; + assert!(r.fold!(10, |acc, e| acc + e) == 16); + } + + #[test] + fun any_all_macro() { + assert!(vector[].any!(|e| *e == 2) == false); + assert!(vector[].all!(|e| *e == 2) == true); + assert!(vector[0, 1, 2, 3].any!(|e| *e == 2)); + assert!(!vector[0, 1, 2, 3].any!(|e| *e == 4)); + assert!(vector[0, 1, 2, 3].all!(|e| *e < 4)); + assert!(!vector[0, 1, 2, 3].all!(|e| *e < 3)); + } + + #[test, expected_failure] + fun zip_do_macro_fail() { + let v1 = vector[1u64]; + let v2 = vector[4u64, 5]; + let mut res = vector[]; + v1.zip_do!(v2, |a, b| res.push_back(a + b)); + } + + #[test] + fun zip_do_macro() { + let v1 = vector[1u64, 2, 3]; + let v2 = vector[4u64, 5, 6]; + let mut res = vector[]; + v1.zip_do!(v2, |a, b| res.push_back(a + b)); + assert!(res == vector[5, 7, 9]); + } + + #[test, expected_failure] + fun zip_do_reverse_macro_fail() { + let v1 = vector[1u64]; + let v2 = vector[4u64, 5]; + let mut res = vector[]; + v2.zip_do_reverse!(v1, |a, b| res.push_back(a + b)); + } + + #[test] + fun zip_do_reverse_macro() { + let v1 = vector[1u64, 2, 3]; + let v2 = vector[4u64, 5, 6]; + let mut res = vector[]; + v2.zip_do_reverse!(v1, |a, b| res.push_back(a + b)); + assert!(res == vector[9, 7, 5]); + } + + #[test, expected_failure] + fun zip_do_ref_macro_fail() { + let v1 = vector[1u64]; + let v2 = vector[4u64, 5]; + let mut res = vector[]; + v2.zip_do_ref!(&v1, |a, b| res.push_back(*a + *b)); + } + + #[test] + fun zip_do_ref_macro() { + let v1 = vector[1u64, 2, 3]; + let v2 = vector[4u64, 5, 6]; + let mut res = vector[]; + v1.zip_do_ref!(&v2, |a, b| res.push_back(*a + *b)); + assert!(res == vector[5, 7, 9]); + } + + #[test, expected_failure] + fun zip_do_mut_macro_fail() { + let mut v1 = vector[1u64]; + let mut v2 = vector[4u64, 5]; + v1.zip_do_mut!(&mut v2, |a, b| { + let c = *a; + *a = *b; + *b = c; + }); + } + + #[test] + fun zip_do_mut_macro() { + let mut v1 = vector[1u64, 2, 3]; + let mut v2 = vector[4u64, 5, 6]; + v1.zip_do_mut!(&mut v2, |a, b| { + let c = *a; + *a = *b; + *b = c; + }); + assert!(v1 == vector[4, 5, 6]); + assert!(v2 == vector[1, 2, 3]); + } + + #[test] + fun zip_map_macro() { + let v1 = vector[1u64, 2, 3]; + let v2 = vector[4u64, 5, 6]; + assert!(v1.zip_map!(v2, |a, b| a + b) == vector[5, 7, 9]); + } + + #[test] + fun zip_map_ref_macro() { + let v1 = vector[1u64, 2, 3]; + let v2 = vector[4u64, 5, 6]; + assert!(v2.zip_map_ref!(&v1, |a, b| *a + *b) == vector[5, 7, 9]); + } } diff --git a/external-crates/move/crates/move-transactional-test-runner/src/vm_test_harness.rs b/external-crates/move/crates/move-transactional-test-runner/src/vm_test_harness.rs index 9ae5ca713a235..bfa9734d737e8 100644 --- a/external-crates/move/crates/move-transactional-test-runner/src/vm_test_harness.rs +++ b/external-crates/move/crates/move-transactional-test-runner/src/vm_test_harness.rs @@ -274,6 +274,7 @@ impl SimpleVMTestAdapter { STD_ADDR, // TODO: come up with a suitable gas schedule move_stdlib_natives::GasParameters::zeros(), + /* silent */ false, ), vm_config, ) diff --git a/external-crates/move/crates/move-unit-test/src/test_runner.rs b/external-crates/move/crates/move-unit-test/src/test_runner.rs index 186d45575fa12..9cc5b87c9ca0f 100644 --- a/external-crates/move/crates/move-unit-test/src/test_runner.rs +++ b/external-crates/move/crates/move-unit-test/src/test_runner.rs @@ -126,6 +126,7 @@ impl TestRunner { move_stdlib_natives::all_natives( AccountAddress::from_hex_literal("0x1").unwrap(), move_stdlib_natives::GasParameters::zeros(), + /* silent */ false, ) }); Ok(Self { diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/address_args.move b/external-crates/move/crates/move-unit-test/tests/test_sources/address_args.move index 4faabd02d0ba4..bb56acb2f988e 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/address_args.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/address_args.move @@ -1,5 +1,4 @@ -address 0x1 { -module M { +module 0x1::M { const ErrorCode: u64 = 100; #[test(a = @0x42)] @@ -19,4 +18,3 @@ module M { assert!(a == @0x43, 100); } } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/arithmetic_errors.move b/external-crates/move/crates/move-unit-test/tests/test_sources/arithmetic_errors.move index 74185c75d5e20..d4a9cb199d735 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/arithmetic_errors.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/arithmetic_errors.move @@ -1,5 +1,4 @@ -address 0x1 { -module M { +module 0x1::M { #[test] #[expected_failure] fun u64_sub_underflow() { @@ -24,4 +23,3 @@ module M { 4294967296 * 4294967296; } } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/construct_data.move b/external-crates/move/crates/move-unit-test/tests/test_sources/construct_data.move index 7a6da03ba315f..8876a204089e9 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/construct_data.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/construct_data.move @@ -1,7 +1,6 @@ -address 0x1 { -module B { +module 0x1::B { #[test_only] - struct TestingStruct has drop { x: u64 } + public struct TestingStruct has drop { x: u64 } #[test_only] public fun construct_with_number(x: u64): TestingStruct { @@ -14,7 +13,7 @@ module B { } } -module M { +module 0x1::M { #[test_only] use 0x1::B; @@ -30,4 +29,3 @@ module M { assert!(B::get_struct_x_field(&s) != 0, 0); } } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/cross_module_aborts.exp b/external-crates/move/crates/move-unit-test/tests/test_sources/cross_module_aborts.exp index d2d0ae63e60c7..6e7e37be0ed86 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/cross_module_aborts.exp +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/cross_module_aborts.exp @@ -8,16 +8,16 @@ Failures in 0x1::B: ┌── failing_test ────── │ error[E11001]: test failure -│ ┌─ cross_module_aborts.move:5:9 +│ ┌─ cross_module_aborts.move:4:9 │ │ -│ 4 │ public fun this_aborts() { +│ 3 │ public fun this_aborts() { │ │ ----------- In this function in 0x1::M -│ 5 │ abort 0 +│ 4 │ abort 0 │ │ ^^^^^^^ Test was not expected to error, but it aborted with code 0 originating in the module 0x1::M rooted here │ │ │ stack trace -│ B::failing_test(tests/test_sources/cross_module_aborts.move:19) +│ B::failing_test(tests/test_sources/cross_module_aborts.move:18) │ └────────────────── diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/cross_module_aborts.move b/external-crates/move/crates/move-unit-test/tests/test_sources/cross_module_aborts.move index 519690185ebb0..2ab099fc48c06 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/cross_module_aborts.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/cross_module_aborts.move @@ -1,5 +1,4 @@ -address 0x1 { -module M { +module 0x1::M { #[test_only] public fun this_aborts() { abort 0 @@ -9,7 +8,7 @@ module M { fun dummy_test() { } } -module B { +module 0x1::B { #[test_only] use 0x1::M; @@ -19,4 +18,3 @@ module B { M::this_aborts() } } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/do_nothing.move b/external-crates/move/crates/move-unit-test/tests/test_sources/do_nothing.move index 8aa9bb708bd51..15fe4a72923ed 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/do_nothing.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/do_nothing.move @@ -1,6 +1,4 @@ -address 0x1 { -module M { +module 0x1::M { #[test] fun do_nothing() {} } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/expected_abort_no_abort.move b/external-crates/move/crates/move-unit-test/tests/test_sources/expected_abort_no_abort.move index e7c022e8366b3..fc94d10c56240 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/expected_abort_no_abort.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/expected_abort_no_abort.move @@ -1,9 +1,7 @@ -address 0x1 { -module M { +module 0x1::M { #[test, expected_failure] fun fail() { } #[test, expected_failure(abort_code=0, location=0x1::M)] fun fail_with_code() { } } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/native_abort.exp b/external-crates/move/crates/move-unit-test/tests/test_sources/native_abort.exp index ad65b7f3924c6..e62e47b3f0368 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/native_abort.exp +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/native_abort.exp @@ -9,11 +9,11 @@ Failures in 0x1::A: ┌── native_abort_good_wrong_code ────── │ error[E11001]: test failure -│ ┌─ native_abort.move:12:9 +│ ┌─ native_abort.move:11:9 │ │ -│ 11 │ fun native_abort_good_wrong_code() { +│ 10 │ fun native_abort_good_wrong_code() { │ │ ---------------------------- In this function in 0x1::A -│ 12 │ vector::borrow(&vector::empty(), 1); +│ 11 │ vector::borrow(&vector::empty(), 1); │ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Test did not error as expected. Expected test to give a vector operation error with sub-status 0 originating in the module 0x1::A but instead it gave a vector operation error with sub-status 1 originating in the module 0x1::A rooted here │ │ @@ -22,11 +22,11 @@ Failures in 0x1::A: ┌── native_abort_unexpected_abort ────── │ error[E11001]: test failure -│ ┌─ native_abort.move:6:9 +│ ┌─ native_abort.move:5:9 │ │ -│ 5 │ fun native_abort_unexpected_abort() { +│ 4 │ fun native_abort_unexpected_abort() { │ │ ----------------------------- In this function in 0x1::A -│ 6 │ vector::borrow(&vector::empty(), 1); +│ 5 │ vector::borrow(&vector::empty(), 1); │ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Test was not expected to error, but it gave a vector operation error with sub-status 1 originating in the module 0x1::A rooted here │ │ diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/native_abort.move b/external-crates/move/crates/move-unit-test/tests/test_sources/native_abort.move index ca5ec24c188de..53203d68f1a84 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/native_abort.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/native_abort.move @@ -1,5 +1,4 @@ module 0x1::A { - use std::vector; #[test] fun native_abort_unexpected_abort() { diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/non_exsistent_native.move b/external-crates/move/crates/move-unit-test/tests/test_sources/non_exsistent_native.move index 2dd99823a43b4..b623fa3170c51 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/non_exsistent_native.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/non_exsistent_native.move @@ -1,5 +1,4 @@ -address 0x1 { -module M { +module 0x1::M { native fun foo(); #[test] @@ -7,4 +6,3 @@ module M { foo() } } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/proposal_test.move b/external-crates/move/crates/move-unit-test/tests/test_sources/proposal_test.move index 4c5b0c42c7444..40d74305afa16 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/proposal_test.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/proposal_test.move @@ -1,13 +1,12 @@ // This is a test based on the example in the unit testing proposal -address 0x1 { -module TestonlyModule { +module 0x1::TestonlyModule { #[test_only] public fun aborts() { abort 42 } } -module Module { +module 0x1::Module { fun a(a: u64): bool { a == 10 } @@ -26,7 +25,7 @@ module Module { // A test only struct. This will only be included in test mode. #[test_only, allow(unused_field)] - struct C has drop, key, store { x: T } + public struct C has drop, key, store { x: T } #[test] // test entry point. fun tests_a() { // an actual test that will be run @@ -47,4 +46,3 @@ module Module { TestonlyModule::aborts() } } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/signer_args.exp b/external-crates/move/crates/move-unit-test/tests/test_sources/signer_args.exp index 08c535f42f67e..b4f7f0f84b3f6 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/signer_args.exp +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/signer_args.exp @@ -17,11 +17,11 @@ Failures in 0x1::M: ┌── single_signer_fail ────── │ error[E11001]: test failure -│ ┌─ signer_args.move:9:9 +│ ┌─ signer_args.move:8:9 │ │ -│ 8 │ fun single_signer_fail(_a: signer) { +│ 7 │ fun single_signer_fail(_a: signer) { │ │ ------------------ In this function in 0x1::M -│ 9 │ abort 0 +│ 8 │ abort 0 │ │ ^^^^^^^ Test was not expected to error, but it aborted with code 0 originating in the module 0x1::M rooted here │ │ diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/signer_args.move b/external-crates/move/crates/move-unit-test/tests/test_sources/signer_args.move index 7b8edcb5dd3e0..9da46ca0a99e5 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/signer_args.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/signer_args.move @@ -1,5 +1,4 @@ -address 0x1 { -module M { +module 0x1::M { #[test(_a=@0x1)] fun single_signer_pass(_a: signer) { } @@ -20,13 +19,8 @@ module M { abort 0 } - #[test_only] - use std::signer; - #[test(a=@0x1, b=@0x2)] fun test_correct_signer_arg_addrs(a: signer, b: signer) { - assert!(signer::address_of(&a) == @0x1, 0); - assert!(signer::address_of(&b) == @0x2, 1); + assert!(a != b) } } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.exp b/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.exp index 9fe952826d7eb..05c32d5cdd88e 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.exp +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.exp @@ -11,9 +11,9 @@ Failures in 0x1::M: ┌── no_timeout_fail ────── │ error[E11001]: test failure -│ ┌─ timeout.move:18:29 +│ ┌─ timeout.move:17:29 │ │ -│ 18 │ fun no_timeout_fail() { abort 0 } +│ 17 │ fun no_timeout_fail() { abort 0 } │ │ --------------- ^^^^^^^ Test was not expected to error, but it aborted with code 0 originating in the module 0x1::M rooted here │ │ │ │ │ In this function in 0x1::M diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.move b/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.move index 1c045830269af..b772e68a35d88 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.move @@ -1,5 +1,4 @@ -address 0x1 { -module M { +module 0x1::M { #[test] fun timeout_fail() { while (true) {} @@ -19,10 +18,9 @@ module M { #[test] fun no_timeout_while_loop() { - let i = 0; + let mut i = 0; while (i < 10) { i = i + 1; }; } } -} diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/unexpected_abort.exp b/external-crates/move/crates/move-unit-test/tests/test_sources/unexpected_abort.exp index ea763695bbc0e..7aeae31d736f8 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/unexpected_abort.exp +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/unexpected_abort.exp @@ -12,11 +12,11 @@ Failures in 0x1::M: ┌── unexpected_abort ────── │ error[E11001]: test failure -│ ┌─ unexpected_abort.move:5:9 +│ ┌─ unexpected_abort.move:4:9 │ │ -│ 4 │ public fun unexpected_abort() { +│ 3 │ public fun unexpected_abort() { │ │ ---------------- In this function in 0x1::M -│ 5 │ abort 0 +│ 4 │ abort 0 │ │ ^^^^^^^ Test was not expected to error, but it aborted with code 0 originating in the module 0x1::M rooted here │ │ @@ -25,45 +25,45 @@ Failures in 0x1::M: ┌── unexpected_abort_in_native_function ────── │ error[E11001]: test failure -│ ┌─ string.move:92:16 -│ │ -│ 92 │ native fun internal_sub_string(v: &vector, i: u64, j: u64): vector; -│ │ ^^^^^^^^^^^^^^^^^^^ -│ │ │ -│ │ Test was not expected to error, but it aborted with code 1 originating in the module std::string rooted here -│ │ In this function in std::string +│ ┌─ string.move:120:16 +│ │ +│ 120 │ native fun internal_sub_string(v: &vector, i: u64, j: u64): vector; +│ │ ^^^^^^^^^^^^^^^^^^^ +│ │ │ +│ │ Test was not expected to error, but it aborted with code 1 originating in the module std::string rooted here +│ │ In this function in std::string │ │ │ stack trace -│ M::abort_in_native(tests/test_sources/unexpected_abort.move:43) -│ M::unexpected_abort_in_native_function(tests/test_sources/unexpected_abort.move:39) +│ M::abort_in_native(tests/test_sources/unexpected_abort.move:42) +│ M::unexpected_abort_in_native_function(tests/test_sources/unexpected_abort.move:38) │ └────────────────── ┌── unexpected_abort_in_other_function ────── │ error[E11001]: test failure -│ ┌─ unexpected_abort.move:28:9 +│ ┌─ unexpected_abort.move:27:9 │ │ -│ 27 │ fun abort_in_other_function() { +│ 26 │ fun abort_in_other_function() { │ │ ----------------------- In this function in 0x1::M -│ 28 │ abort 1 +│ 27 │ abort 1 │ │ ^^^^^^^ Test was not expected to error, but it aborted with code 1 originating in the module 0x1::M rooted here │ │ │ stack trace -│ M::unexpected_abort_in_other_function(tests/test_sources/unexpected_abort.move:33) +│ M::unexpected_abort_in_other_function(tests/test_sources/unexpected_abort.move:32) │ └────────────────── ┌── wrong_abort_code ────── │ error[E11001]: test failure -│ ┌─ unexpected_abort.move:11:9 +│ ┌─ unexpected_abort.move:10:9 │ │ -│ 10 │ public fun wrong_abort_code() { +│ 9 │ public fun wrong_abort_code() { │ │ ---------------- In this function in 0x1::M -│ 11 │ abort 0 +│ 10 │ abort 0 │ │ ^^^^^^^ Test did not error as expected. Expected test to abort with code 1 originating in the module 0x1::M but instead it aborted with code 0 originating in the module 0x1::M rooted here │ │ diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/unexpected_abort.move b/external-crates/move/crates/move-unit-test/tests/test_sources/unexpected_abort.move index 2eaa062d07abc..1b81628abfd15 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/unexpected_abort.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/unexpected_abort.move @@ -1,5 +1,4 @@ -address 0x1 { -module M { +module 0x1::M { #[test] public fun unexpected_abort() { abort 0 @@ -43,4 +42,3 @@ module M { std::string::internal_sub_string_for_testing(&vector[0], 1, 0); } } -} diff --git a/external-crates/move/crates/move-vm-integration-tests/Cargo.toml b/external-crates/move/crates/move-vm-integration-tests/Cargo.toml index 0df741d16e3dc..370d32a3e43e0 100644 --- a/external-crates/move/crates/move-vm-integration-tests/Cargo.toml +++ b/external-crates/move/crates/move-vm-integration-tests/Cargo.toml @@ -18,7 +18,7 @@ tempfile.workspace = true memory-stats = "1.0.0" move-core-types.workspace = true -move-binary-format.workspace = true +move-binary-format = { workspace = true, features = ["fuzzing"] } move-bytecode-verifier.workspace = true move-compiler.workspace = true move-vm-config.workspace = true diff --git a/external-crates/move/crates/move-vm-integration-tests/src/tests/binary_format_version.rs b/external-crates/move/crates/move-vm-integration-tests/src/tests/binary_format_version.rs index 11490fe82b292..7a39280c5997e 100644 --- a/external-crates/move/crates/move-vm-integration-tests/src/tests/binary_format_version.rs +++ b/external-crates/move/crates/move-vm-integration-tests/src/tests/binary_format_version.rs @@ -23,6 +23,7 @@ fn test_publish_module_with_custom_max_binary_format_version() { let vm = MoveVM::new(move_stdlib_natives::all_natives( AccountAddress::from_hex_literal("0x1").unwrap(), move_stdlib_natives::GasParameters::zeros(), + /* silent debug */ true, )) .unwrap(); let mut sess = vm.new_session(&storage); @@ -55,6 +56,7 @@ fn test_publish_module_with_custom_max_binary_format_version() { move_stdlib_natives::all_natives( AccountAddress::from_hex_literal("0x1").unwrap(), move_stdlib_natives::GasParameters::zeros(), + /* silent debug */ true, ), vm_config, ) diff --git a/external-crates/move/crates/move-vm-integration-tests/src/tests/depth_tests_modules.move b/external-crates/move/crates/move-vm-integration-tests/src/tests/depth_tests_modules.move index 22f0c4c9fc5b3..639d337290280 100644 --- a/external-crates/move/crates/move-vm-integration-tests/src/tests/depth_tests_modules.move +++ b/external-crates/move/crates/move-vm-integration-tests/src/tests/depth_tests_modules.move @@ -1,61 +1,60 @@ -address 0x2 { -module A { - struct S has copy, drop { +module 0x2::A { + public struct S has copy, drop { f1: 0x2::B::S, f2: 0x2::C::S, } - struct Box has copy, drop, store { x: T } - struct Box3 has copy, drop, store { x: Box> } - struct Box7 has copy, drop, store { x: Box3> } - struct Box15 has copy, drop, store { x: Box7> } - struct Box31 has copy, drop, store { x: Box15> } - struct Box63 has copy, drop, store { x: Box31> } - struct Box127 has copy, drop, store { x: Box63> } + public struct Box has copy, drop, store { x: T } + public struct Box3 has copy, drop, store { x: Box> } + public struct Box7 has copy, drop, store { x: Box3> } + public struct Box15 has copy, drop, store { x: Box7> } + public struct Box31 has copy, drop, store { x: Box15> } + public struct Box63 has copy, drop, store { x: Box31> } + public struct Box127 has copy, drop, store { x: Box63> } } -module B { - struct S has copy, drop { +module 0x2::B { + public struct S has copy, drop { f1: u64, f2: u128, } } -module C { - struct S has copy, drop { +module 0x2::C { + public struct S has copy, drop { f1: address, f2: bool, } } -module D { - struct S has copy, drop { +module 0x2::D { + public struct S has copy, drop { f1: 0x2::B::S, } } -module E { - struct S has copy, drop { +module 0x2::E { + public struct S has copy, drop { f1: 0x2::F::S, f2: u64, } } -module F { - struct S has copy, drop { +module 0x2::F { + public struct S has copy, drop { f1: T, f2: u64, } } -module G { - struct S has copy, drop { +module 0x2::G { + public struct S has copy, drop { f1: 0x2::H::S, f2: u64, } } -module H { - struct S has copy, drop { +module 0x2::H { + public struct S has copy, drop { f1: 0x2::F::S, f2: 0x2::E::S, f3: 0x2::E::S<0x2::F::S>, @@ -65,8 +64,8 @@ module H { } } -module I { - struct S { +module 0x2::I { + public struct S { f1: F, f2: E, f3: E>, @@ -77,37 +76,36 @@ module I { f8: u64, } - struct E { + public struct E { f1: F, f2: u64, } - struct F { + public struct F { f1: T, f2: u64, } - struct H { + public struct H { f1: T, f2: u64, } - struct G { + public struct G { f: H, } - struct L { + public struct L { g1: G, g2: H, } - struct LL { + public struct LL { g1: G, g2: H, } - struct N { + public struct N { f: u64 } } -} diff --git a/external-crates/move/crates/move-vm-integration-tests/src/tests/function_arg_tests.rs b/external-crates/move/crates/move-vm-integration-tests/src/tests/function_arg_tests.rs index 1f11fa7376aef..1953109d2c136 100644 --- a/external-crates/move/crates/move-vm-integration-tests/src/tests/function_arg_tests.rs +++ b/external-crates/move/crates/move-vm-integration-tests/src/tests/function_arg_tests.rs @@ -39,8 +39,8 @@ fn run( let code = format!( r#" module 0x{}::M {{ - struct Foo has copy, drop {{ x: u64 }} - struct Bar has copy, drop {{ x: T }} + public struct Foo has copy, drop {{ x: u64 }} + public struct Bar has copy, drop {{ x: T }} fun foo<{}>({}) {{ }} }} diff --git a/external-crates/move/crates/move-vm-integration-tests/src/tests/loader_tests_modules.move b/external-crates/move/crates/move-vm-integration-tests/src/tests/loader_tests_modules.move index dcdc5a4764034..74d980a6c0e28 100644 --- a/external-crates/move/crates/move-vm-integration-tests/src/tests/loader_tests_modules.move +++ b/external-crates/move/crates/move-vm-integration-tests/src/tests/loader_tests_modules.move @@ -1,173 +1,171 @@ -address 0x2 { - module A { - struct S has copy, drop { - f1: 0x2::B::S, - f2: 0x2::C::S, - } +module 0x2::A { + public struct S has copy, drop { + f1: 0x2::B::S, + f2: 0x2::C::S, + } - public fun new(f1: 0x2::B::S, f2: 0x2::C::S): S { - Self::S { f1, f2 } - } + public fun new(f1: 0x2::B::S, f2: 0x2::C::S): S { + Self::S { f1, f2 } + } - public fun destroy(v: S): (0x2::B::S, 0x2::C::S) { - let S { f1: v1, f2: v2 } = v; - (v1, v2) - } + public fun destroy(v: S): (0x2::B::S, 0x2::C::S) { + let S { f1: v1, f2: v2 } = v; + (v1, v2) + } - public fun entry_a() { - let i = 0; - while (i < 10) { - let b = 0x2::B::new(20, 100); - let c = 0x2::C::new(@0x42, true); - let another_b = 0x2::B::b_and_c(&b, c); - let (_, _) = 0x2::B::destroy(another_b); - let another_c = 0x2::C::new(@0x42, false); - 0x2::C::destroy(another_c); - i = i + 1; - } + public fun entry_a() { + let mut i = 0; + while (i < 10) { + let b = 0x2::B::new(20, 100); + let c = 0x2::C::new(@0x42, true); + let another_b = 0x2::B::b_and_c(&b, c); + let (_, _) = 0x2::B::destroy(another_b); + let another_c = 0x2::C::new(@0x42, false); + 0x2::C::destroy(another_c); + i = i + 1; } + } - public fun get_field_1(s: &S): 0x2::B::S { - *&s.f1 - } + public fun get_field_1(s: &S): 0x2::B::S { + *&s.f1 } +} - module B { - struct S has copy, drop { - f1: u64, - f2: u128, - } +module 0x2::B { + public struct S has copy, drop { + f1: u64, + f2: u128, + } - public fun new(v1: u64, v2: u128): S { S { f1: v1, f2: v2 } } + public fun new(v1: u64, v2: u128): S { S { f1: v1, f2: v2 } } - public fun destroy(v: S): (u64, u128) { - let S { f1: val1, f2: val2 } = v; - (val1, val2) - } + public fun destroy(v: S): (u64, u128) { + let S { f1: val1, f2: val2 } = v; + (val1, val2) + } - public fun b_and_c(b: &S, c: 0x2::C::S): S { - let _ = 0x2::C::destroy(c); - let another_b = S { - f1: 0, - f2: b.f2, - }; - another_b - } + public fun b_and_c(b: &S, c: 0x2::C::S): S { + let _ = 0x2::C::destroy(c); + let another_b = S { + f1: 0, + f2: b.f2, + }; + another_b } +} - module C { - struct S has copy, drop { - f1: address, - f2: bool, - } +module 0x2::C { + public struct S has copy, drop { + f1: address, + f2: bool, + } - public fun new(v1: address, v2: bool): S { - Self::S { - f1: v1, - f2: v2, - } + public fun new(v1: address, v2: bool): S { + Self::S { + f1: v1, + f2: v2, } + } - public fun destroy(v: S): address { - let S { f1: v1, f2: _ } = v; - v1 - } + public fun destroy(v: S): address { + let S { f1: v1, f2: _ } = v; + v1 + } - public fun just_c() { - let i = 0; - while (i < 10) { - let c = new(@0x0, false); - let S { f1: _, f2: _ } = c; - i = i + 1; - } + public fun just_c() { + let mut i = 0; + while (i < 10) { + let c = new(@0x0, false); + let S { f1: _, f2: _ } = c; + i = i + 1; } } +} - module D { - struct S has copy, drop { - f1: 0x2::B::S, - } +module 0x2::D { + public struct S has copy, drop { + f1: 0x2::B::S, + } - public fun new(): 0x2::D::S { - Self::S { - f1: 0x2::B::new(20, 100), - } + public fun new(): 0x2::D::S { + Self::S { + f1: 0x2::B::new(20, 100), } + } - public fun entry_d() { - let i = 0; - while (i < 10) { - let b = 0x2::B::new(20, 100); - let c = 0x2::C::new(@0x45, false); - let another_b = 0x2::B::b_and_c(&b, c); - let (_, _) = 0x2::B::destroy(another_b); - let another_c = 0x2::C::new(@0x46, true); - 0x2::C::destroy(another_c); - i = i + 1; - } + public fun entry_d() { + let mut i = 0; + while (i < 10) { + let b = 0x2::B::new(20, 100); + let c = 0x2::C::new(@0x45, false); + let another_b = 0x2::B::b_and_c(&b, c); + let (_, _) = 0x2::B::destroy(another_b); + let another_c = 0x2::C::new(@0x46, true); + 0x2::C::destroy(another_c); + i = i + 1; } } +} - module E { - struct S { - f1: u64, - } +module 0x2::E { + public struct S { + f1: u64, + } - public fun new(): 0x2::E::S { Self::S { f1: 20 } } - - public fun entry_e() { - let i = 0; - while (i < 10) { - let b = 0x2::B::new(20, 100); - let c = 0x2::C::new(@0x100, false); - let another_b = 0x2::B::b_and_c(&b, c); - let (_, _) = 0x2::B::destroy(another_b); - let another_c = 0x2::C::new(@0x101, true); - 0x2::C::destroy(another_c); - i = i + 1; - }; - } + public fun new(): 0x2::E::S { Self::S { f1: 20 } } + + public fun entry_e() { + let mut i = 0; + while (i < 10) { + let b = 0x2::B::new(20, 100); + let c = 0x2::C::new(@0x100, false); + let another_b = 0x2::B::b_and_c(&b, c); + let (_, _) = 0x2::B::destroy(another_b); + let another_c = 0x2::C::new(@0x101, true); + 0x2::C::destroy(another_c); + i = i + 1; + }; } +} - module F { - struct S { - f1: u64, - } +module 0x2::F { + public struct S { + f1: u64, + } - public fun new(): 0x2::F::S { Self::S { f1: 20 } } + public fun new(): 0x2::F::S { Self::S { f1: 20 } } - public fun entry_f() { - 0x2::A::entry_a(); - } + public fun entry_f() { + 0x2::A::entry_a(); } +} - module G { - struct S has copy, drop { - f1: u64, - f2: u128, - f3: u16, - f4: u32, - f5: u256 - } +module 0x2::G { + public struct S has copy, drop { + f1: u64, + f2: u128, + f3: u16, + f4: u32, + f5: u256 + } - public fun new(v1: u64, v2: u128, v3: u16, v4: u32, v5: u256): S { S { f1: v1, f2: v2, f3: v3, f4: v4, f5: v5 } } + public fun new(v1: u64, v2: u128, v3: u16, v4: u32, v5: u256): S { S { f1: v1, f2: v2, f3: v3, f4: v4, f5: v5 } } - public fun destroy(v: S): (u64, u128, u16, u32, u256) { - let S { f1: val1, f2: val2, f3: val3, f4: val4, f5: val5 } = v; - (val1, val2, val3, val4, val5) - } + public fun destroy(v: S): (u64, u128, u16, u32, u256) { + let S { f1: val1, f2: val2, f3: val3, f4: val4, f5: val5 } = v; + (val1, val2, val3, val4, val5) + } - public fun b_and_c(b: &S, c: 0x2::C::S): S { - let _ = 0x2::C::destroy(c); - let another_b = S { - f1: 0, - f2: b.f2, - f3: b.f3 + (b.f2 as u16), - f4: (b.f1 as u32), - f5: b.f5 - }; - another_b - } + public fun b_and_c(b: &S, c: 0x2::C::S): S { + let _ = 0x2::C::destroy(c); + let another_b = S { + f1: 0, + f2: b.f2, + f3: b.f3 + (b.f2 as u16), + f4: (b.f1 as u32), + f5: b.f5 + }; + another_b } } diff --git a/external-crates/move/crates/move-vm-integration-tests/src/tests/nested_loop_tests.rs b/external-crates/move/crates/move-vm-integration-tests/src/tests/nested_loop_tests.rs index 633f0d4f15db6..05b5110ad5bad 100644 --- a/external-crates/move/crates/move-vm-integration-tests/src/tests/nested_loop_tests.rs +++ b/external-crates/move/crates/move-vm-integration-tests/src/tests/nested_loop_tests.rs @@ -17,9 +17,9 @@ fn test_publish_module_with_nested_loops() { let code = r#" module {{ADDR}}::M { fun foo() { - let i = 0; + let mut i = 0; while (i < 10) { - let j = 0; + let mut j = 0; while (j < 10) { j = j + 1; }; @@ -42,6 +42,7 @@ fn test_publish_module_with_nested_loops() { move_stdlib_natives::all_natives( AccountAddress::from_hex_literal("0x1").unwrap(), move_stdlib_natives::GasParameters::zeros(), + /* silent debug */ true, ), VMConfig { verifier: VerifierConfig { @@ -65,6 +66,7 @@ fn test_publish_module_with_nested_loops() { move_stdlib_natives::all_natives( AccountAddress::from_hex_literal("0x1").unwrap(), move_stdlib_natives::GasParameters::zeros(), + /* silent debug */ true, ), VMConfig { verifier: VerifierConfig { diff --git a/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_b_v1.move b/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_b_v1.move index 2adcb5bdb6a41..bf93efa2b63d3 100644 --- a/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_b_v1.move +++ b/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_b_v1.move @@ -1,6 +1,6 @@ /// Dependencies: [C v0+] module 0x2::b { - struct S { x: u64 } + public struct S { x: u64 } public fun b(): u64 { 0x2::c::c() * 0x2::c::d() diff --git a/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v0.move b/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v0.move index f099f126c4b47..6efe3748c3795 100644 --- a/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v0.move +++ b/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v0.move @@ -1,6 +1,6 @@ /// Dependencies: [] module 0x2::c { - struct S { x: u64 } + public struct S { x: u64 } public fun c(): u64 { 42 diff --git a/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v1.move b/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v1.move index fecfe86940a76..b36c4e9549b78 100644 --- a/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v1.move +++ b/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v1.move @@ -1,7 +1,7 @@ /// Dependencies: [] module 0x2::c { - struct S { x: u64 } - struct R { x: u64, y: u64 } + public struct S { x: u64 } + public struct R { x: u64, y: u64 } public fun c(): u64 { 43 diff --git a/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v2.move b/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v2.move index 2660fbbe6346e..ba0318bef1cfe 100644 --- a/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v2.move +++ b/external-crates/move/crates/move-vm-integration-tests/src/tests/relinking_tests_c_v2.move @@ -1,8 +1,8 @@ /// Dependencies: [] module 0x2::c { - struct S { x: u64 } - struct R { x: u64, y: u64 } - struct Q { x: u64, y: u64, z: u64 } + public struct S { x: u64 } + public struct R { x: u64, y: u64 } + public struct Q { x: u64, y: u64, z: u64 } public fun c(): u64 { 45 diff --git a/external-crates/move/crates/move-vm-transactional-tests/tests/builtins/get_txn_sender.exp b/external-crates/move/crates/move-vm-transactional-tests/tests/builtins/get_txn_sender.exp index 6cd67db3f6472..c23aa2b760be4 100644 --- a/external-crates/move/crates/move-vm-transactional-tests/tests/builtins/get_txn_sender.exp +++ b/external-crates/move/crates/move-vm-transactional-tests/tests/builtins/get_txn_sender.exp @@ -1 +1,5 @@ processed 1 task + +task 0, lines 1-8: +//# run --signers 0x1 +return values: { 0000000000000000000000000000000000000000000000000000000000000001 } diff --git a/external-crates/move/crates/move-vm-transactional-tests/tests/builtins/get_txn_sender.mvir b/external-crates/move/crates/move-vm-transactional-tests/tests/builtins/get_txn_sender.mvir index 3bc4def5fbcc9..d50e8c3015153 100644 --- a/external-crates/move/crates/move-vm-transactional-tests/tests/builtins/get_txn_sender.mvir +++ b/external-crates/move/crates/move-vm-transactional-tests/tests/builtins/get_txn_sender.mvir @@ -1,14 +1,8 @@ //# run --signers 0x1 module 0x42.m { -import 0x1.signer; -entry foo(account: signer) { - let sender: address; - let addr: address; +entry foo(account: signer): signer { label b0: - sender = signer.address_of(&account); - addr = 0x1; - assert(copy(sender) == copy(addr), 42); - return; + return move(account); } } diff --git a/external-crates/move/crates/move-vm-transactional-tests/tests/entry_points/call_native.exp b/external-crates/move/crates/move-vm-transactional-tests/tests/entry_points/call_native.exp index 7dc107f50aff1..f2d3d9e9a0fdc 100644 --- a/external-crates/move/crates/move-vm-transactional-tests/tests/entry_points/call_native.exp +++ b/external-crates/move/crates/move-vm-transactional-tests/tests/entry_points/call_native.exp @@ -5,8 +5,8 @@ task 0, line 2: return values: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] task 1, line 4: -//# run std::signer::borrow_address --args @3735928559 -return values: 00000000000000000000000000000000000000000000000000000000deadbeef +//# run std::vector::borrow --type-args u64 --args vector[42] 0 +return values: 42 task 2, line 6: //# run std::type_name::get --type-args vector diff --git a/external-crates/move/crates/move-vm-transactional-tests/tests/entry_points/call_native.move b/external-crates/move/crates/move-vm-transactional-tests/tests/entry_points/call_native.move index 11de68abe0ba4..d471f44d41748 100644 --- a/external-crates/move/crates/move-vm-transactional-tests/tests/entry_points/call_native.move +++ b/external-crates/move/crates/move-vm-transactional-tests/tests/entry_points/call_native.move @@ -1,6 +1,6 @@ //# run std::bcs::to_bytes --type-args u256 --args 0u256 -//# run std::signer::borrow_address --args @3735928559 +//# run std::vector::borrow --type-args u64 --args vector[42] 0 //# run std::type_name::get --type-args vector diff --git a/external-crates/move/crates/test-generation/src/lib.rs b/external-crates/move/crates/test-generation/src/lib.rs index 0a7ee75176b71..4a4ce8449659a 100644 --- a/external-crates/move/crates/test-generation/src/lib.rs +++ b/external-crates/move/crates/test-generation/src/lib.rs @@ -135,6 +135,7 @@ fn execute_function_in_module( let vm = MoveVM::new(move_stdlib_natives::all_natives( AccountAddress::from_hex_literal("0x1").unwrap(), move_stdlib_natives::GasParameters::zeros(), + /* silent debug */ true, )) .unwrap(); diff --git a/sui-execution/latest/sui-adapter/src/execution_engine.rs b/sui-execution/latest/sui-adapter/src/execution_engine.rs index 60035e6806f60..306e2a9d25126 100644 --- a/sui-execution/latest/sui-adapter/src/execution_engine.rs +++ b/sui-execution/latest/sui-adapter/src/execution_engine.rs @@ -917,7 +917,7 @@ mod checked { if protocol_config.fresh_vm_on_framework_upgrade() { let new_vm = new_move_vm( - all_natives(/* silent */ true), + all_natives(/* silent */ true, protocol_config), protocol_config, /* enable_profiler */ None, ) diff --git a/sui-execution/latest/sui-move-natives/src/lib.rs b/sui-execution/latest/sui-move-natives/src/lib.rs index c129bf4e26539..36fb6865d69eb 100644 --- a/sui-execution/latest/sui-move-natives/src/lib.rs +++ b/sui-execution/latest/sui-move-natives/src/lib.rs @@ -51,7 +51,7 @@ use move_core_types::{ runtime_value as R, vm_status::StatusCode, }; -use move_stdlib_natives::{GasParameters, NurseryGasParameters}; +use move_stdlib_natives::{self as MSN, GasParameters}; use move_vm_runtime::native_functions::{NativeContext, NativeFunction, NativeFunctionTable}; use move_vm_types::{ loaded_data::runtime_types::Type, @@ -640,7 +640,111 @@ impl NativesCostTable { } } -pub fn all_natives(silent: bool) -> NativeFunctionTable { +pub fn make_stdlib_gas_params_for_protocol_config( + protocol_config: &ProtocolConfig, +) -> GasParameters { + macro_rules! get_gas_cost_or_default { + ($name: ident) => {{ + debug_assert!( + protocol_config.version.as_u64() < 53 || protocol_config.$name().is_some() + ); + protocol_config.$name().map(Into::into).unwrap_or(0.into()) + }}; + } + GasParameters::new( + MSN::bcs::GasParameters { + to_bytes: MSN::bcs::ToBytesGasParameters { + per_byte_serialized: get_gas_cost_or_default!( + bcs_per_byte_serialized_cost_as_option + ), + legacy_min_output_size: get_gas_cost_or_default!( + bcs_legacy_min_output_size_cost_as_option + ), + failure: get_gas_cost_or_default!(bcs_failure_cost_as_option), + }, + }, + MSN::debug::GasParameters { + print: MSN::debug::PrintGasParameters { + base_cost: get_gas_cost_or_default!(debug_print_base_cost_as_option), + }, + print_stack_trace: MSN::debug::PrintStackTraceGasParameters { + base_cost: get_gas_cost_or_default!(debug_print_stack_trace_base_cost_as_option), + }, + }, + MSN::hash::GasParameters { + sha2_256: MSN::hash::Sha2_256GasParameters { + base: get_gas_cost_or_default!(hash_sha2_256_base_cost_as_option), + per_byte: get_gas_cost_or_default!(hash_sha2_256_per_byte_cost_as_option), + legacy_min_input_len: get_gas_cost_or_default!( + hash_sha2_256_legacy_min_input_len_cost_as_option + ), + }, + sha3_256: MSN::hash::Sha3_256GasParameters { + base: get_gas_cost_or_default!(hash_sha3_256_base_cost_as_option), + per_byte: get_gas_cost_or_default!(hash_sha3_256_per_byte_cost_as_option), + legacy_min_input_len: get_gas_cost_or_default!( + hash_sha3_256_legacy_min_input_len_cost_as_option + ), + }, + }, + MSN::string::GasParameters { + check_utf8: MSN::string::CheckUtf8GasParameters { + base: get_gas_cost_or_default!(string_check_utf8_base_cost_as_option), + per_byte: get_gas_cost_or_default!(string_check_utf8_per_byte_cost_as_option), + }, + is_char_boundary: MSN::string::IsCharBoundaryGasParameters { + base: get_gas_cost_or_default!(string_is_char_boundary_base_cost_as_option), + }, + sub_string: MSN::string::SubStringGasParameters { + base: get_gas_cost_or_default!(string_sub_string_base_cost_as_option), + per_byte: get_gas_cost_or_default!(string_sub_string_per_byte_cost_as_option), + }, + index_of: MSN::string::IndexOfGasParameters { + base: get_gas_cost_or_default!(string_index_of_base_cost_as_option), + per_byte_pattern: get_gas_cost_or_default!( + string_index_of_per_byte_pattern_cost_as_option + ), + per_byte_searched: get_gas_cost_or_default!( + string_index_of_per_byte_searched_cost_as_option + ), + }, + }, + MSN::type_name::GasParameters { + get: MSN::type_name::GetGasParameters { + base: get_gas_cost_or_default!(type_name_get_base_cost_as_option), + per_byte: get_gas_cost_or_default!(type_name_get_per_byte_cost_as_option), + }, + }, + MSN::vector::GasParameters { + empty: MSN::vector::EmptyGasParameters { + base: get_gas_cost_or_default!(vector_empty_base_cost_as_option), + }, + length: MSN::vector::LengthGasParameters { + base: get_gas_cost_or_default!(vector_length_base_cost_as_option), + }, + push_back: MSN::vector::PushBackGasParameters { + base: get_gas_cost_or_default!(vector_push_back_base_cost_as_option), + legacy_per_abstract_memory_unit: get_gas_cost_or_default!( + vector_push_back_legacy_per_abstract_memory_unit_cost_as_option + ), + }, + borrow: MSN::vector::BorrowGasParameters { + base: get_gas_cost_or_default!(vector_borrow_base_cost_as_option), + }, + pop_back: MSN::vector::PopBackGasParameters { + base: get_gas_cost_or_default!(vector_pop_back_base_cost_as_option), + }, + destroy_empty: MSN::vector::DestroyEmptyGasParameters { + base: get_gas_cost_or_default!(vector_destroy_empty_base_cost_as_option), + }, + swap: MSN::vector::SwapGasParameters { + base: get_gas_cost_or_default!(vector_swap_base_cost_as_option), + }, + }, + ) +} + +pub fn all_natives(silent: bool, protocol_config: &ProtocolConfig) -> NativeFunctionTable { let sui_framework_natives: &[(&str, &str, NativeFunction)] = &[ ("address", "from_bytes", make_native!(address::from_bytes)), ("address", "to_u256", make_native!(address::to_u256)), @@ -966,14 +1070,8 @@ pub fn all_natives(silent: bool) -> NativeFunctionTable { .chain(sui_framework_natives_iter) .chain(move_stdlib_natives::all_natives( MOVE_STDLIB_ADDRESS, - // TODO: tune gas params - GasParameters::zeros(), - )) - .chain(move_stdlib_natives::nursery_natives( + make_stdlib_gas_params_for_protocol_config(protocol_config), silent, - MOVE_STDLIB_ADDRESS, - // TODO: tune gas params - NurseryGasParameters::zeros(), )) .collect() } diff --git a/sui-execution/src/latest.rs b/sui-execution/src/latest.rs index a9f165624b928..4fb142dda49b9 100644 --- a/sui-execution/src/latest.rs +++ b/sui-execution/src/latest.rs @@ -50,7 +50,7 @@ impl Executor { enable_profiler: Option, ) -> Result { Ok(Executor(Arc::new(new_move_vm( - all_natives(silent), + all_natives(silent, protocol_config), protocol_config, enable_profiler, )?)))