From d3b1592c0d7f9306935a8cdd21e16a367d64930c Mon Sep 17 00:00:00 2001 From: xunilrj Date: Wed, 10 Jun 2026 16:56:09 -0300 Subject: [PATCH 1/4] fix justfile for mac --- justfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index 47785bc1de2..a19867aec25 100644 --- a/justfile +++ b/justfile @@ -93,6 +93,7 @@ perf-diff-latest format='md': alias psh := perf-snapshot-historical # collect historic gas usages from a snapshot test that has a `forc test` output [linux] +[macos] [group('performance')] perf-snapshot-historical path revision_range='' format='csv' open='': #!/usr/bin/env bash @@ -175,4 +176,4 @@ generate-sway-lib-std: [group('test')] test-forc-fmt-check-panic: - cd ./scripts/formatter && ./forc-fmt-check-panic.sh \ No newline at end of file + cd ./scripts/formatter && ./forc-fmt-check-panic.sh From 97cfc2dff7ceb3fef3948ee5a8d60f1d5942e6fc Mon Sep 17 00:00:00 2001 From: xunilrj Date: Thu, 11 Jun 2026 16:43:18 -0300 Subject: [PATCH 2/4] generate snapshot for ir tests --- Cargo.lock | 2 + sway-ir/Cargo.toml | 4 + sway-ir/tests/ccp/ccp1.ir.snap | 36 ++ sway-ir/tests/constants/cbr_cmp_fold.ir.snap | 23 + sway-ir/tests/constants/u256_cmp.ir.snap | 14 + sway-ir/tests/constants/u256_ops.ir.snap | 28 ++ sway-ir/tests/cse/cse1.ir.snap | 20 + sway-ir/tests/cse/cse2.ir.snap | 21 + sway-ir/tests/cse/cse3.ir.snap | 29 ++ sway-ir/tests/dce/copy_prop_1.ir.snap | 22 + sway-ir/tests/dce/copy_prop_2.ir.snap | 23 + sway-ir/tests/dce/copy_prop_3.ir.snap | 23 + sway-ir/tests/dce/dce1.ir.snap | 18 + sway-ir/tests/dce/dce2.ir.snap | 14 + sway-ir/tests/dce/dce3.ir.snap | 41 ++ sway-ir/tests/dce/dce_cast_ptr.ir.snap | 34 ++ sway-ir/tests/dce/dce_dead_arg1.ir.snap | 21 + sway-ir/tests/dce/dce_dead_asm_block.ir.snap | 112 +++++ .../dce/dce_dead_config_assignment.ir.snap | 35 ++ .../dce/dce_dead_constant_assignment.ir.snap | 34 ++ sway-ir/tests/dce/dce_int_to_ptr.ir.snap | 48 +++ sway-ir/tests/dce/dce_load_from_b256.ir.snap | 29 ++ .../tests/dce/dce_load_from_struct.ir.snap | 42 ++ .../dce/dce_mem_clear_val_removal.ir.snap | 25 ++ sway-ir/tests/demote_arg/demote_arg00.ir.snap | 30 ++ sway-ir/tests/demote_arg/demote_arg01.ir.snap | 33 ++ sway-ir/tests/demote_arg/demote_arg02.ir.snap | 68 +++ sway-ir/tests/demote_arg/demote_arg03.ir.snap | 58 +++ sway-ir/tests/demote_arg/demote_arg04.ir.snap | 71 ++++ .../tests/demote_const/demote_const00.ir.snap | 17 + .../tests/demote_const/demote_const01.ir.snap | 17 + .../demote_misc/demote_asm_block_arg.ir.snap | 25 ++ .../demote_misc/demote_asm_block_ret.ir.snap | 21 + sway-ir/tests/demote_misc/demote_log.ir.snap | 20 + .../demote_wide_binary_ops_constants.ir.snap | 35 ++ .../demote_wide_binary_ops_loads.ir.snap | 30 ++ .../demote_wide_cmp_constants.ir.snap | 23 + .../demote_wide_mod_constants.ir.snap | 32 ++ .../demote_wide_not_constants.ir.snap | 22 + sway-ir/tests/demote_ret/demote_ret00.ir.snap | 32 ++ sway-ir/tests/demote_ret/demote_ret01.ir.snap | 96 +++++ .../tests/fn_dedup/debug/debug-dce.ir.snap | 70 +++ .../tests/fn_dedup/debug/debug-nodce.ir.snap | 79 ++++ .../tests/fn_dedup/release/fuelvm-ops.ir.snap | 47 ++ .../fn_dedup/release/release-dce.ir.snap | 73 ++++ .../tests/globals_dce/dce_dead_global.ir.snap | 17 + sway-ir/tests/inline/big_asm_blocks.ir.snap | 93 ++++ sway-ir/tests/inline/bigger.ir.snap | 64 +++ .../inline/by_block_and_instr_count.ir.snap | 82 ++++ sway-ir/tests/inline/by_block_count.ir.snap | 54 +++ sway-ir/tests/inline/by_instr_count.ir.snap | 120 ++++++ sway-ir/tests/inline/by_stack_count.ir.snap | 102 +++++ sway-ir/tests/inline/fiddly.ir.snap | 65 +++ sway-ir/tests/inline/int_to_ptr.ir.snap | 29 ++ sway-ir/tests/inline/recursive-1.ir.snap | 80 ++++ sway-ir/tests/inline/simple.ir.snap | 27 ++ sway-ir/tests/mem2reg/global_simple.ir.snap | 17 + sway-ir/tests/mem2reg/is_prime.ir.snap | 350 +++++++++++++++ sway-ir/tests/mem2reg/while_loops.ir.snap | 402 ++++++++++++++++++ sway-ir/tests/memcpy_prop/memcpy_prop.ir.snap | 95 +++++ sway-ir/tests/memcpyopt/copy_prop_1.ir.snap | 23 + sway-ir/tests/memcpyopt/copy_prop_2.ir.snap | 23 + sway-ir/tests/memcpyopt/copy_prop_3.ir.snap | 24 ++ sway-ir/tests/memcpyopt/copy_prop_mut.ir.snap | 49 +++ .../no_copy_prop_src_ptr_escapes.ir.snap | 27 ++ .../no_memcpyopt_wide_binary_operator.ir.snap | 21 + .../no_memcpyopt_wide_unary_operator.ir.snap | 21 + sway-ir/tests/memcpyopt/ret_value.ir.snap | 25 ++ sway-ir/tests/serialize/asm_block.ir.snap | 18 + sway-ir/tests/serialize/entry.ir.snap | 18 + .../tests/serialize/get_storage_key.ir.snap | 52 +++ .../tests/serialize/intrinsic_addr_of.ir.snap | 18 + .../serialize/log_event_metadata.ir.snap | 18 + sway-ir/tests/serialize/mem_copy.ir.snap | 18 + sway-ir/tests/serialize/metadata.ir.snap | 31 ++ sway-ir/tests/serialize/storage_clear.ir.snap | 20 + sway-ir/tests/serialize/storage_load.ir.snap | 43 ++ .../tests/serialize/storage_preload.ir.snap | 17 + sway-ir/tests/serialize/storage_store.ir.snap | 38 ++ sway-ir/tests/serialize/str_slice.ir.snap | 35 ++ sway-ir/tests/serialize/test.ir.snap | 24 ++ .../serialize/untyped_arg_to_call.ir.snap | 20 + sway-ir/tests/serialize/wide_ops.ir.snap | 30 ++ .../tests/simplify_cfg/dead_blocks.ir.snap | 74 ++++ .../simplify_cfg/merge_all_blocks.ir.snap | 28 ++ .../tests/sroa/nested_struct_array.ir.snap | 156 +++++++ .../tests/sroa/struct_unused_field.ir.snap | 37 ++ sway-ir/tests/tests.rs | 115 ++++- 88 files changed, 4214 insertions(+), 3 deletions(-) create mode 100644 sway-ir/tests/ccp/ccp1.ir.snap create mode 100644 sway-ir/tests/constants/cbr_cmp_fold.ir.snap create mode 100644 sway-ir/tests/constants/u256_cmp.ir.snap create mode 100644 sway-ir/tests/constants/u256_ops.ir.snap create mode 100644 sway-ir/tests/cse/cse1.ir.snap create mode 100644 sway-ir/tests/cse/cse2.ir.snap create mode 100644 sway-ir/tests/cse/cse3.ir.snap create mode 100644 sway-ir/tests/dce/copy_prop_1.ir.snap create mode 100644 sway-ir/tests/dce/copy_prop_2.ir.snap create mode 100644 sway-ir/tests/dce/copy_prop_3.ir.snap create mode 100644 sway-ir/tests/dce/dce1.ir.snap create mode 100644 sway-ir/tests/dce/dce2.ir.snap create mode 100644 sway-ir/tests/dce/dce3.ir.snap create mode 100644 sway-ir/tests/dce/dce_cast_ptr.ir.snap create mode 100644 sway-ir/tests/dce/dce_dead_arg1.ir.snap create mode 100644 sway-ir/tests/dce/dce_dead_asm_block.ir.snap create mode 100644 sway-ir/tests/dce/dce_dead_config_assignment.ir.snap create mode 100644 sway-ir/tests/dce/dce_dead_constant_assignment.ir.snap create mode 100644 sway-ir/tests/dce/dce_int_to_ptr.ir.snap create mode 100644 sway-ir/tests/dce/dce_load_from_b256.ir.snap create mode 100644 sway-ir/tests/dce/dce_load_from_struct.ir.snap create mode 100644 sway-ir/tests/dce/dce_mem_clear_val_removal.ir.snap create mode 100644 sway-ir/tests/demote_arg/demote_arg00.ir.snap create mode 100644 sway-ir/tests/demote_arg/demote_arg01.ir.snap create mode 100644 sway-ir/tests/demote_arg/demote_arg02.ir.snap create mode 100644 sway-ir/tests/demote_arg/demote_arg03.ir.snap create mode 100644 sway-ir/tests/demote_arg/demote_arg04.ir.snap create mode 100644 sway-ir/tests/demote_const/demote_const00.ir.snap create mode 100644 sway-ir/tests/demote_const/demote_const01.ir.snap create mode 100644 sway-ir/tests/demote_misc/demote_asm_block_arg.ir.snap create mode 100644 sway-ir/tests/demote_misc/demote_asm_block_ret.ir.snap create mode 100644 sway-ir/tests/demote_misc/demote_log.ir.snap create mode 100644 sway-ir/tests/demote_misc/demote_wide_binary_ops_constants.ir.snap create mode 100644 sway-ir/tests/demote_misc/demote_wide_binary_ops_loads.ir.snap create mode 100644 sway-ir/tests/demote_misc/demote_wide_cmp_constants.ir.snap create mode 100644 sway-ir/tests/demote_misc/demote_wide_mod_constants.ir.snap create mode 100644 sway-ir/tests/demote_misc/demote_wide_not_constants.ir.snap create mode 100644 sway-ir/tests/demote_ret/demote_ret00.ir.snap create mode 100644 sway-ir/tests/demote_ret/demote_ret01.ir.snap create mode 100644 sway-ir/tests/fn_dedup/debug/debug-dce.ir.snap create mode 100644 sway-ir/tests/fn_dedup/debug/debug-nodce.ir.snap create mode 100644 sway-ir/tests/fn_dedup/release/fuelvm-ops.ir.snap create mode 100644 sway-ir/tests/fn_dedup/release/release-dce.ir.snap create mode 100644 sway-ir/tests/globals_dce/dce_dead_global.ir.snap create mode 100644 sway-ir/tests/inline/big_asm_blocks.ir.snap create mode 100644 sway-ir/tests/inline/bigger.ir.snap create mode 100644 sway-ir/tests/inline/by_block_and_instr_count.ir.snap create mode 100644 sway-ir/tests/inline/by_block_count.ir.snap create mode 100644 sway-ir/tests/inline/by_instr_count.ir.snap create mode 100644 sway-ir/tests/inline/by_stack_count.ir.snap create mode 100644 sway-ir/tests/inline/fiddly.ir.snap create mode 100644 sway-ir/tests/inline/int_to_ptr.ir.snap create mode 100644 sway-ir/tests/inline/recursive-1.ir.snap create mode 100644 sway-ir/tests/inline/simple.ir.snap create mode 100644 sway-ir/tests/mem2reg/global_simple.ir.snap create mode 100644 sway-ir/tests/mem2reg/is_prime.ir.snap create mode 100644 sway-ir/tests/mem2reg/while_loops.ir.snap create mode 100644 sway-ir/tests/memcpy_prop/memcpy_prop.ir.snap create mode 100644 sway-ir/tests/memcpyopt/copy_prop_1.ir.snap create mode 100644 sway-ir/tests/memcpyopt/copy_prop_2.ir.snap create mode 100644 sway-ir/tests/memcpyopt/copy_prop_3.ir.snap create mode 100644 sway-ir/tests/memcpyopt/copy_prop_mut.ir.snap create mode 100644 sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir.snap create mode 100644 sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir.snap create mode 100644 sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir.snap create mode 100644 sway-ir/tests/memcpyopt/ret_value.ir.snap create mode 100644 sway-ir/tests/serialize/asm_block.ir.snap create mode 100644 sway-ir/tests/serialize/entry.ir.snap create mode 100644 sway-ir/tests/serialize/get_storage_key.ir.snap create mode 100644 sway-ir/tests/serialize/intrinsic_addr_of.ir.snap create mode 100644 sway-ir/tests/serialize/log_event_metadata.ir.snap create mode 100644 sway-ir/tests/serialize/mem_copy.ir.snap create mode 100644 sway-ir/tests/serialize/metadata.ir.snap create mode 100644 sway-ir/tests/serialize/storage_clear.ir.snap create mode 100644 sway-ir/tests/serialize/storage_load.ir.snap create mode 100644 sway-ir/tests/serialize/storage_preload.ir.snap create mode 100644 sway-ir/tests/serialize/storage_store.ir.snap create mode 100644 sway-ir/tests/serialize/str_slice.ir.snap create mode 100644 sway-ir/tests/serialize/test.ir.snap create mode 100644 sway-ir/tests/serialize/untyped_arg_to_call.ir.snap create mode 100644 sway-ir/tests/serialize/wide_ops.ir.snap create mode 100644 sway-ir/tests/simplify_cfg/dead_blocks.ir.snap create mode 100644 sway-ir/tests/simplify_cfg/merge_all_blocks.ir.snap create mode 100644 sway-ir/tests/sroa/nested_struct_array.ir.snap create mode 100644 sway-ir/tests/sroa/struct_unused_field.ir.snap diff --git a/Cargo.lock b/Cargo.lock index 47633dd5ecd..c542d09a12f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7686,6 +7686,7 @@ dependencies = [ "downcast-rs", "filecheck", "indexmap 2.14.0", + "insta", "itertools 0.13.0", "once_cell", "peg", @@ -7697,6 +7698,7 @@ dependencies = [ "sway-ir-macros", "sway-types", "sway-utils", + "vte 0.13.1", ] [[package]] diff --git a/sway-ir/Cargo.toml b/sway-ir/Cargo.toml index 0ab3fcc7dc4..5433776c137 100644 --- a/sway-ir/Cargo.toml +++ b/sway-ir/Cargo.toml @@ -25,5 +25,9 @@ sway-ir-macros.workspace = true sway-types.workspace = true sway-utils.workspace = true +[dev-dependencies] +vte.workspace = true +insta.workspace = true + [lints] workspace = true diff --git a/sway-ir/tests/ccp/ccp1.ir.snap b/sway-ir/tests/ccp/ccp1.ir.snap new file mode 100644 index 00000000000..8dff6421cb8 --- /dev/null +++ b/sway-ir/tests/ccp/ccp1.ir.snap @@ -0,0 +1,36 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn test1(p: u64) -> u64 { + entry(p: u64): + v2v1 = const u64 100 + v3v1 = cmp eq v2v1 p + cbr v3v1, get_0_block0(), get_0_block1() + + get_0_block0(): + v5v1 = const u64 1 +- v6v1 = add v5v1, p ++ v6v1 = add v5v1, v2v1 + ret u64 v6v1 + + get_0_block1(): + v8v1 = const u64 111 + v9v1 = add v8v1, p + ret u64 v9v1 + } + + fn must_not_optimize(p: u64) -> u64 { + entry(p: u64): + v12v1 = const u64 100 + v13v1 = cmp eq v12v1 p + cbr v13v1, get_0_block0(), get_0_block0() + + get_0_block0(): + v15v1 = const u64 1 + v16v1 = add v15v1, p + ret u64 v16v1 + } +} diff --git a/sway-ir/tests/constants/cbr_cmp_fold.ir.snap b/sway-ir/tests/constants/cbr_cmp_fold.ir.snap new file mode 100644 index 00000000000..ab4cc86e0a0 --- /dev/null +++ b/sway-ir/tests/constants/cbr_cmp_fold.ir.snap @@ -0,0 +1,23 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn test1() -> u64 { + entry(): +- v1v1 = const bool false +- v2v1 = const bool false +- v3v1 = cmp eq v1v1 v2v1 +- cbr v3v1, get_0_block0(), get_0_block1() ++ br get_0_block0() + + get_0_block0(): + v5v1 = const u64 101 + ret u64 v5v1 + + get_0_block1(): + v7v1 = const u64 111 + ret u64 v7v1 + } +} diff --git a/sway-ir/tests/constants/u256_cmp.ir.snap b/sway-ir/tests/constants/u256_cmp.ir.snap new file mode 100644 index 00000000000..bdfdaddf12b --- /dev/null +++ b/sway-ir/tests/constants/u256_cmp.ir.snap @@ -0,0 +1,14 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool { + entry(): +- v1v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000000 +- v3v1 = cmp eq v1v1 v1v1 ++ v3v1 = const bool true + ret bool v3v1 + } +} diff --git a/sway-ir/tests/constants/u256_ops.ir.snap b/sway-ir/tests/constants/u256_ops.ir.snap new file mode 100644 index 00000000000..9fbd13923b2 --- /dev/null +++ b/sway-ir/tests/constants/u256_ops.ir.snap @@ -0,0 +1,28 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> u256 { + entry(): +- v5v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000004 +- v9v1 = const u64 2 +- v10v1 = rsh v5v1, v9v1 +- v3v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002 +- v11v1 = lsh v3v1, v9v1 +- v12v1 = add v10v1, v11v1 +- v2v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001 +- v13v1 = sub v12v1, v2v1 +- v14v1 = mul v13v1, v3v1 +- v15v1 = div v14v1, v5v1 +- v16v1 = or v15v1, v3v1 +- v17v1 = and v16v1, v5v1 +- v18v1 = not v17v1 +- v19v1 = not v18v1 +- v7v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000006 +- v20v1 = xor v19v1, v7v1 ++ v20v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002 + ret u256 v20v1 + } +} diff --git a/sway-ir/tests/cse/cse1.ir.snap b/sway-ir/tests/cse/cse1.ir.snap new file mode 100644 index 00000000000..5e7168013cb --- /dev/null +++ b/sway-ir/tests/cse/cse1.ir.snap @@ -0,0 +1,20 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool { + entry(): + v1v1 = const u64 11 + v2v1 = const u64 0 + v3v1 = add v1v1, v2v1 + v4v1 = add v1v1, v2v1 + v6v1 = add v2v1, v1v1 +- v7v1 = cmp eq v3v1 v4v1 ++ v7v1 = cmp eq v3v1 v3v1 + v8v1 = cmp eq v6v1 v3v1 + v9v1 = cmp eq v7v1 v8v1 + ret bool v9v1 + } +} diff --git a/sway-ir/tests/cse/cse2.ir.snap b/sway-ir/tests/cse/cse2.ir.snap new file mode 100644 index 00000000000..7217fe40c79 --- /dev/null +++ b/sway-ir/tests/cse/cse2.ir.snap @@ -0,0 +1,21 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool { + entry(): + v1v1 = const u64 11 + v3v1 = const u64 0 + v4v1 = add v1v1, v3v1 + v5v1 = add v1v1, v3v1 + v6v1 = sub v1v1, v4v1 + v2v1 = const u64 11 +- v7v1 = sub v2v1, v5v1 +- v8v1 = cmp eq v6v1 v7v1 ++ v7v1 = sub v2v1, v4v1 ++ v8v1 = cmp eq v6v1 v6v1 + ret bool v8v1 + } +} diff --git a/sway-ir/tests/cse/cse3.ir.snap b/sway-ir/tests/cse/cse3.ir.snap new file mode 100644 index 00000000000..229293d7edb --- /dev/null +++ b/sway-ir/tests/cse/cse3.ir.snap @@ -0,0 +1,29 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main(a: u64, b: u64) -> () { + entry(a: u64, b: u64): + v5v1 = add a, b + v6v1 = const u64 0 + br while(v6v1, v5v1) + + while(v3v1: u64, v4v1: u64): +- v8v1 = cmp lt v3v1 v4v1 ++ v8v1 = cmp lt v3v1 v5v1 + cbr v8v1, while_body(), end_while() + + while_body(): + v10v1 = add a, b + v11v1 = const u64 1 + v12v1 = add v3v1, v11v1 +- br while(v12v1, v10v1) ++ br while(v12v1, v5v1) + + end_while(): + v14v1 = const unit () + ret () v14v1 + } +} diff --git a/sway-ir/tests/dce/copy_prop_1.ir.snap b/sway-ir/tests/dce/copy_prop_1.ir.snap new file mode 100644 index 00000000000..7864085e90c --- /dev/null +++ b/sway-ir/tests/dce/copy_prop_1.ir.snap @@ -0,0 +1,22 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64 { + local { u64, u64, u64, u64 } __anon_0 +- local { u64, u64, u64, u64 } __anon_468 + + entry(): + v1v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0 + v2v1 = const u64 0 + v3v1 = get_elem_ptr v1v1, __ptr u64, v2v1 +- v4v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_468 +- v5v1 = const u64 0 +- v6v1 = get_elem_ptr v4v1, __ptr u64, v5v1 +- mem_copy_val v6v1, v3v1 + v8v1 = load v3v1 + ret u64 v8v1 + } +} diff --git a/sway-ir/tests/dce/copy_prop_2.ir.snap b/sway-ir/tests/dce/copy_prop_2.ir.snap new file mode 100644 index 00000000000..0a0e0f5d12d --- /dev/null +++ b/sway-ir/tests/dce/copy_prop_2.ir.snap @@ -0,0 +1,23 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64 { + local { u64, u64, u64, u64 } __anon_0 +- local { u64, u64, u64, u64 } __anon_468 + + entry(): +- v1v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0 +- v2v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_468 +- mem_copy_val v2v1, v1v1 ++ v6v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0 + v4v1 = const u64 0 +- v5v1 = get_elem_ptr v2v1, __ptr u64, v4v1 +- v6v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0 + v7v1 = get_elem_ptr v6v1, __ptr u64, v4v1 + v8v1 = load v7v1 + ret u64 v8v1 + } +} diff --git a/sway-ir/tests/dce/copy_prop_3.ir.snap b/sway-ir/tests/dce/copy_prop_3.ir.snap new file mode 100644 index 00000000000..ab798ce6484 --- /dev/null +++ b/sway-ir/tests/dce/copy_prop_3.ir.snap @@ -0,0 +1,23 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main(v101: u64) -> u64 { + local [u64; 8] __anon_0 +- local [u64; 8] __anon_468 + + entry(v101: u64): +- v2v1 = get_local __ptr [u64; 8], __anon_0 +- v3v1 = get_local __ptr [u64; 8], __anon_468 +- mem_copy_val v3v1, v2v1 + v5v1 = const u64 1 + v6v1 = add v101, v5v1 +- v7v1 = get_elem_ptr v3v1, __ptr u64, v6v1 + v8v1 = get_local __ptr [u64; 8], __anon_0 + v9v1 = get_elem_ptr v8v1, __ptr u64, v6v1 + v10v1 = load v9v1 + ret u64 v10v1 + } +} diff --git a/sway-ir/tests/dce/dce1.ir.snap b/sway-ir/tests/dce/dce1.ir.snap new file mode 100644 index 00000000000..28177008e0f --- /dev/null +++ b/sway-ir/tests/dce/dce1.ir.snap @@ -0,0 +1,18 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool { + entry(): +- v1v1 = const u64 11 +- v2v1 = const u64 0 +- v3v1 = cmp eq v1v1 v2v1 + br block0() + + block0(): + v5v1 = const bool false + ret bool v5v1 + } +} diff --git a/sway-ir/tests/dce/dce2.ir.snap b/sway-ir/tests/dce/dce2.ir.snap new file mode 100644 index 00000000000..a8cd1bed524 --- /dev/null +++ b/sway-ir/tests/dce/dce2.ir.snap @@ -0,0 +1,14 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool { +- local u64 i +- + entry(): + v1v1 = const bool false + ret bool v1v1 + } +} diff --git a/sway-ir/tests/dce/dce3.ir.snap b/sway-ir/tests/dce/dce3.ir.snap new file mode 100644 index 00000000000..d76758bbd61 --- /dev/null +++ b/sway-ir/tests/dce/dce3.ir.snap @@ -0,0 +1,41 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> bool { + local mut u64 state + + entry(): + v1v1 = get_local __ptr u64, state + v2v1 = const u64 0 + store v2v1 to v1v1 + v4v1 = get_local __ptr u64, state + v5v1 = call function_0(v4v1) + v6v1 = get_local __ptr u64, state + v7v1 = load v6v1 + v8v1 = const u64 42 + v9v1 = cmp eq v7v1 v8v1 + v10v1 = const bool false + v11v1 = cmp eq v9v1 v10v1 + cbr v11v1, assert_1_block0(), assert_1_block1() + + assert_1_block0(): + v13v1 = const u64 18446744073709486084 + revert v13v1 + + assert_1_block1(): + v15v1 = const bool true + ret bool v15v1 + } + + fn function_0(state: __ptr u64) -> () { + entry(state: __ptr u64): + v18v1 = const u64 42 + store v18v1 to state +- v21v1 = add v18v1, v18v1 + v20v1 = const unit () + ret () v20v1 + } +} diff --git a/sway-ir/tests/dce/dce_cast_ptr.ir.snap b/sway-ir/tests/dce/dce_cast_ptr.ir.snap new file mode 100644 index 00000000000..c77d8d44171 --- /dev/null +++ b/sway-ir/tests/dce/dce_cast_ptr.ir.snap @@ -0,0 +1,34 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64 { + local u64 S +- local u64 dummy + + entry(): + br block0() + + block0(): + v3v1 = get_local __ptr u64, S + v2v1 = const u64 123 + store v2v1 to v3v1 + v5v1 = cast_ptr v3v1 to __ptr u8 + v6v1 = ptr_to_int v5v1 to u64 + v7v1 = add v6v1, v2v1 + v8v1 = sub v7v1, v2v1 + v9v1 = call test(v8v1) + ret u64 v9v1 + } + + fn test(arg: u64) -> u64 { + entry(arg: u64): + br block0(arg) + + block0(v12v1: __ptr u64): + v14v1 = load v12v1 + ret u64 v14v1 + } +} diff --git a/sway-ir/tests/dce/dce_dead_arg1.ir.snap b/sway-ir/tests/dce/dce_dead_arg1.ir.snap new file mode 100644 index 00000000000..4bfb98815eb --- /dev/null +++ b/sway-ir/tests/dce/dce_dead_arg1.ir.snap @@ -0,0 +1,21 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool { + entry(): +- v2v1 = const u64 0 +- v3v1 = const u64 11 +- v4v1 = cmp eq v2v1 v3v1 +- br block0(v4v1) ++ br block0() + +- block0(v1v1: bool): ++ block0(): + v6v1 = const bool false +- v7v1 = cmp eq v1v1 v6v1 + ret bool v6v1 + } +} diff --git a/sway-ir/tests/dce/dce_dead_asm_block.ir.snap b/sway-ir/tests/dce/dce_dead_asm_block.ir.snap new file mode 100644 index 00000000000..66f8504d566 --- /dev/null +++ b/sway-ir/tests/dce/dce_dead_asm_block.ir.snap @@ -0,0 +1,112 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { +- local () a + local u64 arg +- local u64 b +- local () c +- local u64 d +- local u64 e +- local u64 f + + entry(): + v1v1 = asm() -> () { + } + v2v1 = call poke_1(v1v1) + v3v1 = asm() -> u64 zero { + } + v4v1 = call poke_2(v3v1) + v5v1 = asm() -> () zero { + } + v6v1 = call poke_1(v5v1) + v7v1 = get_local __ptr u64, arg + v8v1 = const u64 11 + store v8v1 to v7v1 + v10v1 = get_local __ptr u64, arg + v11v1 = load v10v1 + v12v1 = get_local __ptr u64, arg + v13v1 = load v12v1 + v14v1 = asm(a: v11v1, b: v13v1, res) -> () { + add res a b + } + v15v1 = get_local __ptr u64, arg + v16v1 = load v15v1 + v17v1 = get_local __ptr u64, arg + v18v1 = load v17v1 + v19v1 = asm(a: v16v1, b: v18v1, res) -> u64 res { + add res a b + } + v20v1 = asm() -> u64 zero { + } + v21v1 = call poke_2(v20v1) +- v22v1 = asm() -> () { +- } +- v23v1 = asm() -> u64 zero { +- } +- v24v1 = asm() -> () zero { +- } +- v25v1 = get_local __ptr u64, arg +- v26v1 = load v25v1 +- v27v1 = asm(arg: v26v1) -> () { +- } +- v28v1 = get_local __ptr u64, arg +- v29v1 = load v28v1 +- v30v1 = asm(arg: v29v1) -> u64 arg { +- } +- v31v1 = asm() -> () { +- } +- v32v1 = get_local __ptr (), a +- store v31v1 to v32v1 +- v34v1 = asm() -> u64 zero { +- } +- v35v1 = get_local __ptr u64, b +- store v34v1 to v35v1 +- v37v1 = get_local __ptr u64, arg +- v38v1 = load v37v1 +- v39v1 = asm(arg: v38v1) -> () { +- } +- v40v1 = get_local __ptr (), c +- store v39v1 to v40v1 +- v42v1 = get_local __ptr u64, arg +- v43v1 = load v42v1 +- v44v1 = asm(arg: v43v1) -> u64 arg { +- } +- v45v1 = get_local __ptr u64, d +- store v44v1 to v45v1 +- v47v1 = get_local __ptr u64, arg +- v48v1 = load v47v1 +- v49v1 = asm(arg: v48v1) -> u64 arg { +- } +- v50v1 = get_local __ptr u64, e +- store v49v1 to v50v1 + v52v1 = call function() +- v53v1 = asm(arg: v52v1) -> u64 arg { +- } +- v54v1 = get_local __ptr u64, f +- store v53v1 to v54v1 + v56v1 = const unit () + ret () v56v1 + } + + fn poke_1(_x: ()) -> () { + entry(_x: ()): + v59v1 = const unit () + ret () v59v1 + } + + fn poke_2(_x: u64) -> () { + entry(_x: u64): + v62v1 = const unit () + ret () v62v1 + } + + fn function() -> u64 { + entry(): + v64v1 = const u64 0 + ret u64 v64v1 + } +} diff --git a/sway-ir/tests/dce/dce_dead_config_assignment.ir.snap b/sway-ir/tests/dce/dce_dead_config_assignment.ir.snap new file mode 100644 index 00000000000..6f017309174 --- /dev/null +++ b/sway-ir/tests/dce/dce_dead_config_assignment.ir.snap @@ -0,0 +1,35 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +contract { + CONFIG = config u64, abi_decode_in_place_0, 0x00000000000004d2 + + pub fn abi_decode_in_place_0(__ptr: u64, len: u64, target: u64) -> () { + entry(__ptr: u64, len: u64, target: u64): + v4v1 = const unit () + ret () v4v1 + } + + pub entry fn assign_config_call_pass_config<28892dec>() -> () { +- local u64 x +- + entry(): +- v6v1 = get_config __ptr u64, CONFIG +- v7v1 = load v6v1 +- v8v1 = get_local __ptr u64, x +- store v7v1 to v8v1 + v10v1 = get_config __ptr u64, CONFIG + v11v1 = load v10v1 + v12v1 = call poke_0(v11v1) + v13v1 = const unit () + ret () v13v1 + } + + fn poke_0(_x: u64) -> () { + entry(_x: u64): + v16v1 = const unit () + ret () v16v1 + } +} diff --git a/sway-ir/tests/dce/dce_dead_constant_assignment.ir.snap b/sway-ir/tests/dce/dce_dead_constant_assignment.ir.snap new file mode 100644 index 00000000000..08a1463b7bd --- /dev/null +++ b/sway-ir/tests/dce/dce_dead_constant_assignment.ir.snap @@ -0,0 +1,34 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { +- local { u64, u64 } __anon_0 +- local slice __anon_1 +- local string<3> __anon_2 +- local slice x +- + entry(): +- v2v1 = get_local __ptr string<3>, __anon_2 +- v1v1 = const string<3> "str" +- store v1v1 to v2v1 +- v4v1 = ptr_to_int v2v1 to u64 +- v5v1 = get_local __ptr { u64, u64 }, __anon_0 +- v6v1 = const u64 0 +- v7v1 = get_elem_ptr v5v1, __ptr u64, v6v1 +- store v4v1 to v7v1 +- v9v1 = const u64 1 +- v10v1 = get_elem_ptr v5v1, __ptr u64, v9v1 +- v11v1 = const u64 3 +- store v11v1 to v10v1 +- v13v1 = get_local __ptr slice, __anon_1 +- mem_copy_bytes v13v1, v5v1, 16 +- v15v1 = load v13v1 +- v16v1 = get_local __ptr slice, x +- store v15v1 to v16v1 + v18v1 = const unit () + ret () v18v1 + } +} diff --git a/sway-ir/tests/dce/dce_int_to_ptr.ir.snap b/sway-ir/tests/dce/dce_int_to_ptr.ir.snap new file mode 100644 index 00000000000..75b73c79b39 --- /dev/null +++ b/sway-ir/tests/dce/dce_int_to_ptr.ir.snap @@ -0,0 +1,48 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> bool { +- local mut u64 dummy + local mut u64 x + local mut u64 y + + entry(): + v2v1 = const u64 0 + v3v1 = const u64 2 + v4v1 = cmp eq v2v1 v3v1 + v5v1 = const bool false + v6v1 = cmp eq v5v1 v4v1 + cbr v6v1, block0(), block1() + + block0(): + v8v1 = get_local __ptr u64, x + v9v1 = cast_ptr v8v1 to __ptr u8 + v10v1 = cast_ptr v9v1 to __ptr u64 + v11v1 = ptr_to_int v10v1 to u64 + v12v1 = int_to_ptr v11v1 to __ptr u64 + v13v1 = ptr_to_int v12v1 to u64 + br block2(v13v1) + + block1(): + v15v1 = get_local __ptr u64, y + v16v1 = cast_ptr v15v1 to __ptr u8 + v17v1 = cast_ptr v16v1 to __ptr u64 + v18v1 = ptr_to_int v17v1 to u64 + v19v1 = int_to_ptr v18v1 to __ptr u64 + v20v1 = ptr_to_int v19v1 to u64 + br block2(v20v1) + + block2(v1v1: u64): + v22v1 = int_to_ptr v1v1 to __ptr u64 + v23v1 = const u64 42 + store v23v1 to v22v1 +- v25v1 = get_local __ptr u64, dummy +- v26v1 = const u64 42 +- store v26v1 to v25v1 + v28v1 = const bool true + ret bool v28v1 + } +} diff --git a/sway-ir/tests/dce/dce_load_from_b256.ir.snap b/sway-ir/tests/dce/dce_load_from_b256.ir.snap new file mode 100644 index 00000000000..4ba747637d6 --- /dev/null +++ b/sway-ir/tests/dce/dce_load_from_b256.ir.snap @@ -0,0 +1,29 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { + local b256 local +- local b256 x + + entry(): + v1v1 = get_local __ptr b256, local + v2v1 = const b256 0x1f212e1f2e7b5a8cff18d994b7b7faa61db1a89cbf697facc518f6b6c8430196 + store v2v1 to v1v1 + v4v1 = get_local __ptr b256, local + v5v1 = load v4v1 + v6v1 = call take_b256_2(v5v1) +- v7v1 = get_local __ptr b256, x +- store v6v1 to v7v1 + v9v1 = const unit () + ret () v9v1 + } + + fn take_b256_2(_x: b256) -> b256 { + entry(_x: b256): + v12v1 = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 + ret b256 v12v1 + } +} diff --git a/sway-ir/tests/dce/dce_load_from_struct.ir.snap b/sway-ir/tests/dce/dce_load_from_struct.ir.snap new file mode 100644 index 00000000000..f9f62767f74 --- /dev/null +++ b/sway-ir/tests/dce/dce_load_from_struct.ir.snap @@ -0,0 +1,42 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { + local { u64, u64 } __anon_0 + local { u64, u64 } local +- local { u64, u64 } x + + entry(): + v1v1 = get_local __ptr { u64, u64 }, __anon_0 + v2v1 = const u64 0 + v3v1 = get_elem_ptr v1v1, __ptr u64, v2v1 + v4v1 = const u64 112233 + store v4v1 to v3v1 + v6v1 = const u64 1 + v7v1 = get_elem_ptr v1v1, __ptr u64, v6v1 + v8v1 = const u64 445566 + store v8v1 to v7v1 + v10v1 = load v1v1 + v11v1 = get_local __ptr { u64, u64 }, local + store v10v1 to v11v1 + v13v1 = get_local __ptr { u64, u64 }, local + v14v1 = load v13v1 + v15v1 = call take_struct_2(v14v1) +- v16v1 = get_local __ptr { u64, u64 }, x +- store v15v1 to v16v1 + v18v1 = const unit () + ret () v18v1 + } + + fn take_struct_2(_x: { u64, u64 }) -> { u64, u64 } { + local { u64, u64 } __anon_0 + + entry(_x: { u64, u64 }): + v21v1 = get_local __ptr { u64, u64 }, __anon_0 + v22v1 = load v21v1 + ret { u64, u64 } v22v1 + } +} diff --git a/sway-ir/tests/dce/dce_mem_clear_val_removal.ir.snap b/sway-ir/tests/dce/dce_mem_clear_val_removal.ir.snap new file mode 100644 index 00000000000..fbb21067608 --- /dev/null +++ b/sway-ir/tests/dce/dce_mem_clear_val_removal.ir.snap @@ -0,0 +1,25 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> bool { +- local { u64 } __struct_init_00 +- local { u64 } __struct_init_01 +- local { u64 } __struct_init_02 +- local { u64 } __struct_init_03 +- + entry(): +- v1v1 = get_local __ptr { u64 }, __struct_init_00 +- mem_clear_val v1v1 +- v3v1 = get_local __ptr { u64 }, __struct_init_01 +- mem_clear_val v3v1 +- v5v1 = get_local __ptr { u64 }, __struct_init_02 +- mem_clear_val v5v1 +- v7v1 = get_local __ptr { u64 }, __struct_init_03 +- mem_clear_val v7v1 + v9v1 = const bool true + ret bool v9v1 + } +} diff --git a/sway-ir/tests/demote_arg/demote_arg00.ir.snap b/sway-ir/tests/demote_arg/demote_arg00.ir.snap new file mode 100644 index 00000000000..297563928ac --- /dev/null +++ b/sway-ir/tests/demote_arg/demote_arg00.ir.snap @@ -0,0 +1,30 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64 { + entry(): + v1v1 = const u64 42 + ret u64 v1v1 + } + +- fn foo(e: b256) -> bool { +- entry(e: b256): ++ fn foo(e: __ptr b256) -> bool { ++ entry(e: __ptr b256): ++ v11v1 = load e + v4v1 = const bool false + ret bool v4v1 + } + +- fn bar(i: b256, j: u64) -> bool { +- entry(i: b256, j: u64): ++ fn bar(i: __ptr b256, j: u64) -> bool { ++ entry(i: __ptr b256, j: u64): ++ v13v1 = load i + v8v1 = const bool false + ret bool v8v1 + } +} diff --git a/sway-ir/tests/demote_arg/demote_arg01.ir.snap b/sway-ir/tests/demote_arg/demote_arg01.ir.snap new file mode 100644 index 00000000000..86a44860740 --- /dev/null +++ b/sway-ir/tests/demote_arg/demote_arg01.ir.snap @@ -0,0 +1,33 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { ++ local b256 __tmp_arg + local b256 dada = const b256 0xdadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadada + + entry(): + v1v1 = get_local __ptr b256, dada + v2v1 = load v1v1 ++ v15v1 = get_local __ptr b256, __tmp_arg ++ store v2v1 to v15v1 + v3v1 = const u64 22 +- v4v1 = call foo(v2v1, v3v1) ++ v17v1 = call foo(v15v1, v3v1) + v5v1 = const unit () + ret () v5v1 + } + +- fn foo(x: b256, y: u64) -> () { +- entry(x: b256, y: u64): ++ fn foo(x: __ptr b256, y: u64) -> () { ++ entry(x: __ptr b256, y: u64): ++ v14v1 = load x + v9v1 = const u64 0 + log u64 y, v9v1 + v11v1 = const unit () + ret () v11v1 + } +} diff --git a/sway-ir/tests/demote_arg/demote_arg02.ir.snap b/sway-ir/tests/demote_arg/demote_arg02.ir.snap new file mode 100644 index 00000000000..c88dfbee88c --- /dev/null +++ b/sway-ir/tests/demote_arg/demote_arg02.ir.snap @@ -0,0 +1,68 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { ++ local b256 __tmp_arg ++ local b256 __tmp_arg0 + local b256 dada = const b256 0xdadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadada + local b256 twobee = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b + + entry(): + v1v1 = get_local __ptr b256, twobee + v2v1 = load v1v1 + v3v1 = get_local __ptr b256, dada + v4v1 = load v3v1 + v5v1 = call bar() ++ v30v1 = get_local __ptr b256, __tmp_arg ++ store v2v1 to v30v1 + v6v1 = const u64 33 +- v7v1 = call foo(v2v1, v6v1) ++ v32v1 = call foo(v30v1, v6v1) ++ v33v1 = get_local __ptr b256, __tmp_arg0 ++ store v4v1 to v33v1 + v8v1 = const u64 44 +- v9v1 = call foo(v4v1, v8v1) ++ v35v1 = call foo(v33v1, v8v1) + v10v1 = const unit () + ret () v10v1 + } + + fn bar() -> () { ++ local b256 __tmp_arg ++ local b256 __tmp_arg0 + local b256 fafa = const b256 0xfafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa + local b256 feve = const b256 0x5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e + + entry(): + v12v1 = get_local __ptr b256, feve + v13v1 = load v12v1 + v14v1 = get_local __ptr b256, fafa + v15v1 = load v14v1 ++ v36v1 = get_local __ptr b256, __tmp_arg ++ store v13v1 to v36v1 + v16v1 = const u64 11 +- v17v1 = call foo(v13v1, v16v1) ++ v38v1 = call foo(v36v1, v16v1) ++ v39v1 = get_local __ptr b256, __tmp_arg0 ++ store v15v1 to v39v1 + v18v1 = const u64 22 +- v19v1 = call foo(v15v1, v18v1) ++ v41v1 = call foo(v39v1, v18v1) + v20v1 = const unit () + ret () v20v1 + } + +- fn foo(x: b256, y: u64) -> () { +- entry(x: b256, y: u64): ++ fn foo(x: __ptr b256, y: u64) -> () { ++ entry(x: __ptr b256, y: u64): ++ v29v1 = load x + v24v1 = const u64 3 + log u64 y, v24v1 + v26v1 = const unit () + ret () v26v1 + } +} diff --git a/sway-ir/tests/demote_arg/demote_arg03.ir.snap b/sway-ir/tests/demote_arg/demote_arg03.ir.snap new file mode 100644 index 00000000000..fab4a39694e --- /dev/null +++ b/sway-ir/tests/demote_arg/demote_arg03.ir.snap @@ -0,0 +1,58 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { ++ local b256 __tmp_arg ++ local b256 __tmp_arg0 + local b256 dada = const b256 0xdadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadada + local b256 tmp + local b256 twobee = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b + + entry(): + v1v1 = get_local __ptr b256, twobee + v2v1 = load v1v1 + v3v1 = get_local __ptr b256, dada + v4v1 = load v3v1 ++ v22v1 = get_local __ptr b256, __tmp_arg ++ store v2v1 to v22v1 ++ v24v1 = get_local __ptr b256, __tmp_arg0 ++ store v4v1 to v24v1 + v5v1 = const bool false +- v6v1 = call a(v5v1, v2v1, v4v1) ++ v26v1 = call a(v5v1, v22v1, v24v1) + v7v1 = get_local __ptr b256, tmp +- store v6v1 to v7v1 ++ store v26v1 to v7v1 + v9v1 = const unit () + ret () v9v1 + } + +- fn a(p: bool, a: b256, b: b256) -> b256 { +- entry(p: bool, a: b256, b: b256): +- cbr p, block2(a), block1() ++ fn a(p: bool, a: __ptr b256, b: __ptr b256) -> b256 { ++ local b256 __tmp_block_arg + ++ entry(p: bool, a: __ptr b256, b: __ptr b256): ++ v20v1 = load a ++ v21v1 = load b ++ v29v1 = get_local __ptr b256, __tmp_block_arg ++ store v20v1 to v29v1 ++ cbr p, block2(v29v1), block1() ++ + block1(): +- br block2(b) ++ v31v1 = get_local __ptr b256, __tmp_block_arg ++ store v21v1 to v31v1 ++ br block2(v31v1) + +- block2(v14v1: b256): +- ret b256 v14v1 ++ block2(v27v1: __ptr b256): ++ v28v1 = load v27v1 ++ ret b256 v28v1 + } +} diff --git a/sway-ir/tests/demote_arg/demote_arg04.ir.snap b/sway-ir/tests/demote_arg/demote_arg04.ir.snap new file mode 100644 index 00000000000..7c1b5a4c4e6 --- /dev/null +++ b/sway-ir/tests/demote_arg/demote_arg04.ir.snap @@ -0,0 +1,71 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { ++ local b256 __tmp_block_arg ++ local b256 __tmp_block_arg0 ++ local b256 __tmp_block_arg1 ++ local b256 __tmp_block_arg2 ++ local b256 __tmp_block_arg3 + local b256 fors = const b256 0x4444444444444444444444444444444444444444444444444444444444444444 + local b256 ones = const b256 0x1111111111111111111111111111111111111111111111111111111111111111 + local b256 thrs = const b256 0x3333333333333333333333333333333333333333333333333333333333333333 + local b256 tmp + local b256 twos = const b256 0x2222222222222222222222222222222222222222222222222222222222222222 + + entry(): + v8v1 = get_local __ptr b256, ones + v9v1 = load v8v1 + v10v1 = get_local __ptr b256, twos + v11v1 = load v10v1 + v12v1 = get_local __ptr b256, thrs + v13v1 = load v12v1 + v14v1 = get_local __ptr b256, fors + v15v1 = load v14v1 ++ v30v1 = get_local __ptr b256, __tmp_block_arg ++ store v9v1 to v30v1 ++ v32v1 = get_local __ptr b256, __tmp_block_arg0 ++ store v11v1 to v32v1 ++ v38v1 = get_local __ptr b256, __tmp_block_arg1 ++ store v13v1 to v38v1 ++ v40v1 = get_local __ptr b256, __tmp_block_arg2 ++ store v15v1 to v40v1 + v16v1 = const bool false + v17v1 = const bool true +- cbr v16v1, block1(v9v1, v17v1, v11v1), block2(v13v1, v17v1, v15v1) ++ cbr v16v1, block1(v30v1, v17v1, v32v1), block2(v38v1, v17v1, v40v1) + +- block1(v1v1: b256, v2v1: bool, v3v1: b256): +- br block3(v3v1) ++ block1(v26v1: __ptr b256, v2v1: bool, v28v1: __ptr b256): ++ v27v1 = load v26v1 ++ v29v1 = load v28v1 ++ v44v1 = get_local __ptr b256, __tmp_block_arg3 ++ store v29v1 to v44v1 ++ br block3(v44v1) + +- block2(v4v1: b256, v5v1: bool, v6v1: b256): +- br block3(v6v1) ++ block2(v34v1: __ptr b256, v5v1: bool, v36v1: __ptr b256): ++ v35v1 = load v34v1 ++ v37v1 = load v36v1 ++ v46v1 = get_local __ptr b256, __tmp_block_arg3 ++ store v37v1 to v46v1 ++ br block3(v46v1) + +- block3(v7v1: b256): ++ block3(v42v1: __ptr b256): ++ v43v1 = load v42v1 + v21v1 = get_local __ptr b256, tmp +- store v7v1 to v21v1 ++ store v43v1 to v21v1 + br exit() + + exit(): + v24v1 = const unit () + ret () v24v1 + } +} diff --git a/sway-ir/tests/demote_const/demote_const00.ir.snap b/sway-ir/tests/demote_const/demote_const00.ir.snap new file mode 100644 index 00000000000..4c6822c1bc5 --- /dev/null +++ b/sway-ir/tests/demote_const/demote_const00.ir.snap @@ -0,0 +1,17 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> b256 { ++ local b256 __const = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b ++ + entry(): +- v1v1 = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b +- ret b256 v1v1 ++ v3v1 = get_local __ptr b256, __const ++ v4v1 = load v3v1 ++ ret b256 v4v1 + } +} diff --git a/sway-ir/tests/demote_const/demote_const01.ir.snap b/sway-ir/tests/demote_const/demote_const01.ir.snap new file mode 100644 index 00000000000..e55845fa949 --- /dev/null +++ b/sway-ir/tests/demote_const/demote_const01.ir.snap @@ -0,0 +1,17 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> { u64, bool } { ++ local { u64, bool } __const = const { u64, bool } { u64 42, bool false } ++ + entry(): +- v1v1 = const { u64, bool } { u64 42, bool false } +- ret { u64, bool } v1v1 ++ v3v1 = get_local __ptr { u64, bool }, __const ++ v4v1 = load v3v1 ++ ret { u64, bool } v4v1 + } +} diff --git a/sway-ir/tests/demote_misc/demote_asm_block_arg.ir.snap b/sway-ir/tests/demote_misc/demote_asm_block_arg.ir.snap new file mode 100644 index 00000000000..7a58e4d220e --- /dev/null +++ b/sway-ir/tests/demote_misc/demote_asm_block_arg.ir.snap @@ -0,0 +1,25 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> bool { ++ local b256 __asm_arg ++ local b256 __asm_arg0 ++ + entry(): ++ v5v1 = get_local __ptr b256, __asm_arg + v1v1 = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b ++ store v1v1 to v5v1 ++ v7v1 = get_local __ptr b256, __asm_arg0 + v2v1 = const b256 0x2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c +- v3v1 = asm(r1: v1v1, r2: v2v1, r3, r4) -> bool r4 { ++ store v2v1 to v7v1 ++ v3v1 = asm(r1: v5v1, r2: v7v1, r3, r4) -> bool r4 { + addi r3 zero i32 + meq r4 r1 r2 r3 + } + ret bool v3v1 + } +} diff --git a/sway-ir/tests/demote_misc/demote_asm_block_ret.ir.snap b/sway-ir/tests/demote_misc/demote_asm_block_ret.ir.snap new file mode 100644 index 00000000000..8b86fe4d941 --- /dev/null +++ b/sway-ir/tests/demote_misc/demote_asm_block_ret.ir.snap @@ -0,0 +1,21 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> b256 { ++ local b256 __asm_arg ++ + entry(): ++ v4v1 = get_local __ptr b256, __asm_arg + v1v1 = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b +- v2v1 = asm(pointer: v1v1) -> b256 pointer { ++ store v1v1 to v4v1 ++ v6v1 = asm(pointer: v4v1) -> __ptr b256 pointer { + } +- ret b256 v2v1 ++ v7v1 = load v6v1 ++ ret b256 v7v1 + } +} diff --git a/sway-ir/tests/demote_misc/demote_log.ir.snap b/sway-ir/tests/demote_misc/demote_log.ir.snap new file mode 100644 index 00000000000..488de06dce0 --- /dev/null +++ b/sway-ir/tests/demote_misc/demote_log.ir.snap @@ -0,0 +1,20 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { ++ local b256 __log_arg ++ + entry(): ++ v6v1 = get_local __ptr b256, __log_arg + v1v1 = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b ++ store v1v1 to v6v1 + v2v1 = const u64 0 +- log b256 v1v1, v2v1 ++ log __ptr b256 v6v1, v2v1 + v4v1 = const unit () + ret () v4v1 + } +} diff --git a/sway-ir/tests/demote_misc/demote_wide_binary_ops_constants.ir.snap b/sway-ir/tests/demote_misc/demote_wide_binary_ops_constants.ir.snap new file mode 100644 index 00000000000..77272143dc6 --- /dev/null +++ b/sway-ir/tests/demote_misc/demote_wide_binary_ops_constants.ir.snap @@ -0,0 +1,35 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u256 { ++ local u256 __wide_lhs ++ local u256 __wide_lhs0 ++ local mut u256 __wide_result ++ local mut u256 __wide_result0 ++ local u256 __wide_rhs ++ + entry(): ++ v9v1 = get_local __ptr u256, __wide_lhs + v1v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001 ++ store v1v1 to v9v1 ++ v11v1 = get_local __ptr u256, __wide_rhs + v2v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002 +- v3v1 = add v1v1, v2v1 ++ store v2v1 to v11v1 ++ v7v1 = get_local __ptr u256, __wide_result ++ wide add v9v1, v11v1 to v7v1 ++ v8v1 = load v7v1 ++ v16v1 = get_local __ptr u256, __wide_lhs0 ++ store v1v1 to v16v1 ++ v14v1 = get_local __ptr u256, __wide_result0 + v4v1 = const u64 2 +- v5v1 = lsh v1v1, v4v1 +- ret u256 v3v1 ++ wide lsh v16v1, v4v1 to v14v1 ++ v15v1 = load v14v1 ++ ret u256 v8v1 + } +} diff --git a/sway-ir/tests/demote_misc/demote_wide_binary_ops_loads.ir.snap b/sway-ir/tests/demote_misc/demote_wide_binary_ops_loads.ir.snap new file mode 100644 index 00000000000..bda7816a807 --- /dev/null +++ b/sway-ir/tests/demote_misc/demote_wide_binary_ops_loads.ir.snap @@ -0,0 +1,30 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u256 { ++ local u256 __wide_lhs ++ local mut u256 __wide_result ++ local u256 __wide_rhs + local u256 lhs + local u256 rhs + + entry(): + v1v1 = get_local __ptr u256, lhs + v2v1 = load v1v1 + v3v1 = get_local __ptr u256, rhs + v4v1 = load v3v1 +- v5v1 = add v2v1, v4v1 +- ret u256 v5v1 ++ v9v1 = get_local __ptr u256, __wide_lhs ++ store v2v1 to v9v1 ++ v11v1 = get_local __ptr u256, __wide_rhs ++ store v4v1 to v11v1 ++ v7v1 = get_local __ptr u256, __wide_result ++ wide add v9v1, v11v1 to v7v1 ++ v8v1 = load v7v1 ++ ret u256 v8v1 + } +} diff --git a/sway-ir/tests/demote_misc/demote_wide_cmp_constants.ir.snap b/sway-ir/tests/demote_misc/demote_wide_cmp_constants.ir.snap new file mode 100644 index 00000000000..3475768e820 --- /dev/null +++ b/sway-ir/tests/demote_misc/demote_wide_cmp_constants.ir.snap @@ -0,0 +1,23 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> bool { ++ local u256 __wide_lhs ++ local u256 __wide_rhs ++ + entry(): ++ v5v1 = get_local __ptr u256, __wide_lhs + v1v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001 ++ store v1v1 to v5v1 ++ v7v1 = get_local __ptr u256, __wide_rhs + v2v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002 +- v3v1 = cmp eq v1v1 v2v1 +- ret bool v3v1 ++ store v2v1 to v7v1 ++ v9v1 = wide cmp eq v5v1 v7v1 ++ ret bool v9v1 + } +} diff --git a/sway-ir/tests/demote_misc/demote_wide_mod_constants.ir.snap b/sway-ir/tests/demote_misc/demote_wide_mod_constants.ir.snap new file mode 100644 index 00000000000..522be30bb94 --- /dev/null +++ b/sway-ir/tests/demote_misc/demote_wide_mod_constants.ir.snap @@ -0,0 +1,32 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u256 { ++ local u256 __wide_lhs ++ local mut u256 __wide_result ++ local u256 __wide_rhs ++ local mut u256 __wide_zero = const u256 0x0000000000000000000000000000000000000000000000000000000000000000 + local u256 lhs + local u256 rhs + + entry(): + v1v1 = get_local __ptr u256, lhs + v2v1 = load v1v1 + v3v1 = get_local __ptr u256, rhs + v4v1 = load v3v1 +- v5v1 = mod v2v1, v4v1 +- ret u256 v5v1 ++ v9v1 = get_local __ptr u256, __wide_lhs ++ store v2v1 to v9v1 ++ v13v1 = get_local __ptr u256, __wide_zero ++ v11v1 = get_local __ptr u256, __wide_rhs ++ store v4v1 to v11v1 ++ v7v1 = get_local __ptr u256, __wide_result ++ wide mod v9v1, v13v1, v11v1 to v7v1 ++ v8v1 = load v7v1 ++ ret u256 v8v1 + } +} diff --git a/sway-ir/tests/demote_misc/demote_wide_not_constants.ir.snap b/sway-ir/tests/demote_misc/demote_wide_not_constants.ir.snap new file mode 100644 index 00000000000..fd18989d897 --- /dev/null +++ b/sway-ir/tests/demote_misc/demote_wide_not_constants.ir.snap @@ -0,0 +1,22 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> bool { ++ local u256 __wide_lhs ++ local mut u256 __wide_result ++ + entry(): ++ v7v1 = get_local __ptr u256, __wide_lhs + v1v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001 +- v2v1 = not v1v1 ++ store v1v1 to v7v1 ++ v5v1 = get_local __ptr u256, __wide_result ++ wide not v7v1 to v5v1 ++ v6v1 = load v5v1 + v3v1 = const bool true + ret bool v3v1 + } +} diff --git a/sway-ir/tests/demote_ret/demote_ret00.ir.snap b/sway-ir/tests/demote_ret/demote_ret00.ir.snap new file mode 100644 index 00000000000..cfd72448946 --- /dev/null +++ b/sway-ir/tests/demote_ret/demote_ret00.ir.snap @@ -0,0 +1,32 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { ++ local b256 __ret_val ++ + entry(): +- v1v1 = call a() ++ v11v1 = get_local __ptr b256, __ret_val ++ v12v1 = call a(v11v1) ++ v13v1 = load v11v1 + v2v1 = const unit () + ret () v2v1 + } + +- fn a() -> b256 { ++ fn a(__ret_value: __ptr b256) -> () { + local b256 __const = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b + +- entry(): ++ entry(__ret_value: __ptr b256): + v4v1 = get_local __ptr b256, __const + v5v1 = load v4v1 +- ret b256 v5v1 ++ store v5v1 to __ret_value ++ v9v1 = const unit () ++ ret () v9v1 + } +} diff --git a/sway-ir/tests/demote_ret/demote_ret01.ir.snap b/sway-ir/tests/demote_ret/demote_ret01.ir.snap new file mode 100644 index 00000000000..9e6f73c8e1f --- /dev/null +++ b/sway-ir/tests/demote_ret/demote_ret01.ir.snap @@ -0,0 +1,96 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { ++ local b256 __ret_val + local b256 tmp + + entry(): ++ v30v1 = get_local __ptr b256, __ret_val + v1v1 = const bool false + v2v1 = const bool true +- v3v1 = call c(v1v1, v2v1) ++ v31v1 = call c(v1v1, v2v1, v30v1) ++ v32v1 = load v30v1 + v4v1 = get_local __ptr b256, tmp +- store v3v1 to v4v1 ++ store v32v1 to v4v1 + v6v1 = const unit () + ret () v6v1 + } + +- fn c(p: bool, q: bool) -> b256 { +- entry(p: bool, q: bool): ++ fn c(p: bool, q: bool, __ret_value: __ptr b256) -> () { ++ local b256 __ret_val ++ local b256 __ret_val0 ++ local b256 __ret_val1 ++ ++ entry(p: bool, q: bool, __ret_value: __ptr b256): + cbr p, block0(), block1() + + block0(): +- v12v1 = call a() +- br block5(v12v1) ++ v37v1 = get_local __ptr b256, __ret_val ++ v38v1 = call a(v37v1) ++ v39v1 = load v37v1 ++ br block5(v39v1) + + block1(): + cbr q, block2(), block3() + + block2(): +- v15v1 = call a() +- br block5(v15v1) ++ v40v1 = get_local __ptr b256, __ret_val0 ++ v41v1 = call a(v40v1) ++ v42v1 = load v40v1 ++ br block5(v42v1) + + block3(): +- v17v1 = call b() +- br block5(v17v1) ++ v47v1 = get_local __ptr b256, __ret_val1 ++ v48v1 = call b(v47v1) ++ v49v1 = load v47v1 ++ br block5(v49v1) + + block5(v10v1: b256): +- ret b256 v10v1 ++ store v10v1 to __ret_value ++ v28v1 = const unit () ++ ret () v28v1 + } + +- fn a() -> b256 { ++ fn a(__ret_value: __ptr b256) -> () { + local b256 twobee = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b + +- entry(): ++ entry(__ret_value: __ptr b256): + v20v1 = get_local __ptr b256, twobee + v21v1 = load v20v1 +- ret b256 v21v1 ++ store v21v1 to __ret_value ++ v35v1 = const unit () ++ ret () v35v1 + } + +- fn b() -> b256 { ++ fn b(__ret_value: __ptr b256) -> () { + local b256 dada = const b256 0xdadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadada + +- entry(): ++ entry(__ret_value: __ptr b256): + v23v1 = get_local __ptr b256, dada + v24v1 = load v23v1 +- ret b256 v24v1 ++ store v24v1 to __ret_value ++ v45v1 = const unit () ++ ret () v45v1 + } +} diff --git a/sway-ir/tests/fn_dedup/debug/debug-dce.ir.snap b/sway-ir/tests/fn_dedup/debug/debug-dce.ir.snap new file mode 100644 index 00000000000..9276fbefd96 --- /dev/null +++ b/sway-ir/tests/fn_dedup/debug/debug-dce.ir.snap @@ -0,0 +1,70 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> bool, !1 { + entry(): + v2v1 = const u64 1, !2 + v3v1 = const u64 1, !3 +- v4v1 = call foo_1(v2v1, v3v1), !4 ++ v4v1 = call foo_3(v2v1, v3v1), !4 + cbr v4v1, block0(), block1(v4v1), !5 + + block0(): + v6v1 = const u64 1, !6 + v7v1 = const u64 2, !7 + v8v1 = call foo_3(v6v1, v7v1), !8 + br block1(v8v1), !5 + + block1(v1v1: bool): + ret bool v1v1 + } + +- fn foo_1(t1 !9: u64, t2 !10: u64) -> bool, !13 { ++ fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !13 { + entry(t1: u64, t2: u64): +- v13v1 = call eq_2(t1, t2), !14 +- ret bool v13v1 +- } +- +- pub fn eq_2(self !16: u64, other !17: u64) -> bool, !18 { +- entry(self: u64, other: u64): +- v17v1 = cmp eq self other +- ret bool v17v1 +- } +- +- fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !19 { +- entry(t1: u64, t2: u64): + v21v1 = call eq_4(t1, t2), !14 + ret bool v21v1 + } + + pub fn eq_4(self !16: u64, other !17: u64) -> bool, !18 { + entry(self: u64, other: u64): + v25v1 = cmp eq self other + ret bool v25v1 + } +} + +!0 = "sway_test/src/main.sw" +!1 = span !0 9 55 +!2 = span !0 35 36 +!3 = span !0 38 39 +!4 = span !0 31 40 +!5 = span !0 31 53 +!6 = span !0 48 49 +!7 = span !0 51 52 +!8 = span !0 44 53 +!9 = span !0 84 86 +!10 = span !0 91 93 +!11 = span !0 74 134 +!12 = inline "never" +!13 = (!11 !12) +!14 = span !0 123 132 +!15 = "sway/sway-lib-std/src/ops.sw" +!16 = span !15 12645 12649 +!17 = span !15 12651 12656 +!18 = span !15 12639 12705 +- !19 = (!11 !12) diff --git a/sway-ir/tests/fn_dedup/debug/debug-nodce.ir.snap b/sway-ir/tests/fn_dedup/debug/debug-nodce.ir.snap new file mode 100644 index 00000000000..77bec7e6fc1 --- /dev/null +++ b/sway-ir/tests/fn_dedup/debug/debug-nodce.ir.snap @@ -0,0 +1,79 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> bool, !1 { + entry(): + v2v1 = const u64 1, !2 + v3v1 = const u64 1, !3 + v4v1 = call foo_1(v2v1, v3v1), !4 + cbr v4v1, block0(), block1(v4v1), !5 + + block0(): + v6v1 = const u64 1, !6 + v7v1 = const u64 2, !7 + v8v1 = call foo_3(v6v1, v7v1), !8 + br block1(v8v1), !5 + + block1(v1v1: bool): + ret bool v1v1 + } + + fn foo_1(t1 !9: u64, t2 !10: u64) -> bool, !13 { + entry(t1: u64, t2: u64): +- v13v1 = call eq_2(t1, t2), !14 ++ v13v1 = call eq_4(t1, t2), !14 + ret bool v13v1 + } + +- pub fn eq_2(self !16: u64, other !17: u64) -> bool, !18 { +- entry(self: u64, other: u64): +- v17v1 = cmp eq self other +- ret bool v17v1 +- } +- +- fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !19 { ++ fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !15 { + entry(t1: u64, t2: u64): +- v21v1 = call eq_4(t1, t2), !20 ++ v21v1 = call eq_4(t1, t2), !16 + ret bool v21v1 + } + +- pub fn eq_4(self !16: u64, other !17: u64) -> bool, !18 { ++ pub fn eq_4(self !18: u64, other !19: u64) -> bool, !20 { + entry(self: u64, other: u64): + v25v1 = cmp eq self other + ret bool v25v1 + } +} + +!0 = "sway_test/src/main.sw" +!1 = span !0 9 55 +!2 = span !0 35 36 +!3 = span !0 38 39 +!4 = span !0 31 40 +!5 = span !0 31 53 +!6 = span !0 48 49 +!7 = span !0 51 52 +!8 = span !0 44 53 +!9 = span !0 84 86 +!10 = span !0 91 93 +!11 = span !0 74 134 +!12 = inline "never" +!13 = (!11 !12) +!14 = span !0 123 132 +- !15 = "sway/sway-lib-std/src/ops.sw" +- !16 = span !15 12645 12649 +- !17 = span !15 12651 12656 +- !18 = span !15 12639 12705 +- !19 = (!11 !12) +- !20 = span !0 133 142 ++ !15 = (!11 !12) ++ !16 = span !0 133 142 ++ !17 = "sway/sway-lib-std/src/ops.sw" ++ !18 = span !17 12645 12649 ++ !19 = span !17 12651 12656 ++ !20 = span !17 12639 12705 diff --git a/sway-ir/tests/fn_dedup/release/fuelvm-ops.ir.snap b/sway-ir/tests/fn_dedup/release/fuelvm-ops.ir.snap new file mode 100644 index 00000000000..e4bcacac322 --- /dev/null +++ b/sway-ir/tests/fn_dedup/release/fuelvm-ops.ir.snap @@ -0,0 +1,47 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64 { + entry(): + v1v1 = call foo() + v2v1 = call bar() +- v3v1 = call foo_dup() ++ v3v1 = call foo() + v4v1 = add v1v1, v2v1 + v5v1 = add v4v1, v3v1 + ret u64 v4v1 + } + + fn foo() -> u64 { + entry(): + v7v1 = const u64 0 + v8v1 = int_to_ptr v7v1 to __ptr b256 + v10v1 = int_to_ptr v7v1 to __ptr b256 + v11v1 = const u64 1 + v12v1 = state_load_quad_word v8v1, key v10v1, v11v1 + ret u64 v11v1 + } + +- fn foo_dup() -> u64 { +- entry(): +- v14v1 = const u64 0 +- v15v1 = int_to_ptr v14v1 to __ptr b256 +- v17v1 = int_to_ptr v14v1 to __ptr b256 +- v18v1 = const u64 1 +- v19v1 = state_load_quad_word v15v1, key v17v1, v18v1 +- ret u64 v18v1 +- } +- + fn bar() -> u64 { + entry(): + v21v1 = const u64 0 + v22v1 = int_to_ptr v21v1 to __ptr b256 + v24v1 = int_to_ptr v21v1 to __ptr b256 + v25v1 = const u64 1 + v26v1 = state_store_quad_word v22v1, key v24v1, v25v1 + ret u64 v25v1 + } +} diff --git a/sway-ir/tests/fn_dedup/release/release-dce.ir.snap b/sway-ir/tests/fn_dedup/release/release-dce.ir.snap new file mode 100644 index 00000000000..fe7a18d6ba7 --- /dev/null +++ b/sway-ir/tests/fn_dedup/release/release-dce.ir.snap @@ -0,0 +1,73 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> bool, !1 { + entry(): + v2v1 = const u64 1, !2 + v3v1 = const u64 1, !3 +- v4v1 = call foo_1(v2v1, v3v1), !4 ++ v4v1 = call foo_3(v2v1, v3v1), !4 + cbr v4v1, block0(), block1(v4v1), !5 + + block0(): + v6v1 = const u64 1, !6 + v7v1 = const u64 2, !7 + v8v1 = call foo_3(v6v1, v7v1), !8 + br block1(v8v1), !5 + + block1(v1v1: bool): + ret bool v1v1 + } + +- fn foo_1(t1 !9: u64, t2 !10: u64) -> bool, !13 { ++ fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !13 { + entry(t1: u64, t2: u64): +- v13v1 = call eq_2(t1, t2), !14 +- ret bool v13v1 +- } +- +- pub fn eq_2(self !16: u64, other !17: u64) -> bool, !18 { +- entry(self: u64, other: u64): +- v17v1 = cmp eq self other +- ret bool v17v1 +- } +- +- fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !19 { +- entry(t1: u64, t2: u64): +- v21v1 = call eq_4(t1, t2), !20 ++ v21v1 = call eq_4(t1, t2), !14 + ret bool v21v1 + } + + pub fn eq_4(self !16: u64, other !17: u64) -> bool, !18 { + entry(self: u64, other: u64): + v25v1 = cmp eq self other + ret bool v25v1 + } +} + +!0 = "sway_test/src/main.sw" +!1 = span !0 9 55 +!2 = span !0 35 36 +!3 = span !0 38 39 +!4 = span !0 31 40 +!5 = span !0 31 53 +!6 = span !0 48 49 +!7 = span !0 51 52 +!8 = span !0 44 53 +!9 = span !0 84 86 +!10 = span !0 91 93 +!11 = span !0 74 134 +!12 = inline "never" +!13 = (!11 !12) +- !14 = span !0 123 132 ++ !14 = span !0 133 142 +!15 = "sway/sway-lib-std/src/ops.sw" +!16 = span !15 12645 12649 +!17 = span !15 12651 12656 +!18 = span !15 12639 12705 +- !19 = (!11 !12) +- !20 = span !0 133 142 diff --git a/sway-ir/tests/globals_dce/dce_dead_global.ir.snap b/sway-ir/tests/globals_dce/dce_dead_global.ir.snap new file mode 100644 index 00000000000..865d7384824 --- /dev/null +++ b/sway-ir/tests/globals_dce/dce_dead_global.ir.snap @@ -0,0 +1,17 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +contract { +- global X : u64 = const u64 11 +- + pub entry fn main() -> u64 { + local u64 x + + entry(): + v1v1 = get_local __ptr u64, x + v2v1 = load v1v1 + ret u64 v2v1 + } +} diff --git a/sway-ir/tests/inline/big_asm_blocks.ir.snap b/sway-ir/tests/inline/big_asm_blocks.ir.snap new file mode 100644 index 00000000000..0c385341260 --- /dev/null +++ b/sway-ir/tests/inline/big_asm_blocks.ir.snap @@ -0,0 +1,93 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { + entry(): +- v1v1 = call test_function1() +- v2v1 = call test_function2() +- v3v1 = call test_function3() ++ v1v3 = call testf() ++ v7v1 = const unit () ++ br block0(v7v1) ++ ++ block0(v18v1: ()): ++ v2v3 = call testf() ++ v10v1 = const bool true ++ br block1(v10v1) ++ ++ block1(v20v1: bool): ++ v3v3 = call testf() ++ v13v1 = const u64 0 ++ br block2(v13v1) ++ ++ block2(v22v1: u64): + v4v1 = const unit () + ret () v4v1 + } + + fn test_function1() -> () { + entry(): + v6v1 = call testf() + v7v1 = const unit () + ret () v7v1 + } + + fn test_function2() -> bool { + entry(): + v9v1 = call testf() + v10v1 = const bool true + ret bool v10v1 + } + + fn test_function3() -> u64 { + entry(): + v12v1 = call testf() + v13v1 = const u64 0 + ret u64 v13v1 + } + + fn testf() -> () { + entry(): + v15v1 = asm(r1, r2) -> () { + movi r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + addi r1 r2 i1 + } + v16v1 = const unit () + ret () v16v1 + } +} diff --git a/sway-ir/tests/inline/bigger.ir.snap b/sway-ir/tests/inline/bigger.ir.snap new file mode 100644 index 00000000000..3f339ca3db7 --- /dev/null +++ b/sway-ir/tests/inline/bigger.ir.snap @@ -0,0 +1,64 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn a(b: bool) -> u64 { + local u64 x + + entry(b: bool): + v3v1 = get_local __ptr u64, x + v4v1 = const u64 10 + store v4v1 to v3v1 + cbr b, block0(), block1() + + block0(): + v7v1 = get_local __ptr u64, x + v8v1 = load v7v1 + br block2(v8v1) + + block1(): + v10v1 = const u64 1 + br block2(v10v1) + + block2(v2v1: u64): + ret u64 v2v1 + } + + fn main() -> u64 { + local u64 x ++ local u64 x0 + + entry(): + v13v1 = get_local __ptr u64, x + v14v1 = const u64 0 + store v14v1 to v13v1 ++ v24v1 = get_local __ptr u64, x0 ++ v4v1 = const u64 10 ++ store v4v1 to v24v1 + v16v1 = const bool true +- v17v1 = call a(v16v1) ++ cbr v16v1, a_block0(), a_block1() ++ ++ a_block0(): ++ v28v1 = get_local __ptr u64, x0 ++ v29v1 = load v28v1 ++ br a_block2(v29v1) ++ ++ a_block1(): ++ v10v1 = const u64 1 ++ br a_block2(v10v1) ++ ++ a_block2(v17v3: u64): ++ br block0(v17v3) ++ ++ block0(v23v1: u64): + v18v1 = get_local __ptr u64, x +- store v17v1 to v18v1 ++ store v23v1 to v18v1 + v20v1 = get_local __ptr u64, x + v21v1 = load v20v1 + ret u64 v21v1 + } +} diff --git a/sway-ir/tests/inline/by_block_and_instr_count.ir.snap b/sway-ir/tests/inline/by_block_and_instr_count.ir.snap new file mode 100644 index 00000000000..74312258843 --- /dev/null +++ b/sway-ir/tests/inline/by_block_and_instr_count.ir.snap @@ -0,0 +1,82 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn two_blocks_four_instrs() -> bool { + entry(): + v2v1 = const bool true + br block(v2v1) + + block(v1v1: bool): + v4v1 = const bool false + v5v1 = cmp eq v1v1 v4v1 + v6v1 = cmp eq v4v1 v5v1 + ret bool v6v1 + } + + fn two_blocks_five_instrs() -> bool { + entry(): + v9v1 = const bool true + br block(v9v1) + + block(v8v1: bool): + v11v1 = const bool false + v12v1 = cmp eq v8v1 v11v1 + v13v1 = cmp eq v11v1 v12v1 + v14v1 = const bool true + v15v1 = cmp eq v13v1 v14v1 + ret bool v15v1 + } + + fn three_blocks_four_instrs(b: bool) -> bool { + entry(b: bool): + v18v1 = const bool false + v19v1 = cmp eq b v18v1 + cbr v19v1, then_block(), else_block() + + then_block(): + v21v1 = const bool false + ret bool v21v1 + + else_block(): + v23v1 = const bool true + ret bool v23v1 + } + + fn three_blocks_five_instrs(b: bool) -> bool { + entry(b: bool): + v26v1 = const bool false + v27v1 = cmp eq b v26v1 + v28v1 = cmp eq b v27v1 + cbr v28v1, then_block(), else_block() + + then_block(): + v30v1 = const bool false + ret bool v30v1 + + else_block(): + v32v1 = const bool true + ret bool v32v1 + } + + fn main() -> bool { + entry(): +- v34v1 = call two_blocks_four_instrs() ++ v2v1 = const bool true ++ br two_blocks_four_instrs_block(v2v1) ++ ++ two_blocks_four_instrs_block(v34v3: bool): ++ v4v1 = const bool false ++ v41v1 = cmp eq v34v3 v4v1 ++ v42v1 = cmp eq v4v1 v41v1 ++ br block0(v42v1) ++ ++ block0(v39v1: bool): + v35v1 = call two_blocks_five_instrs() + v36v1 = call three_blocks_four_instrs() + v37v1 = call three_blocks_five_instrs() + ret bool v37v1 + } +} diff --git a/sway-ir/tests/inline/by_block_count.ir.snap b/sway-ir/tests/inline/by_block_count.ir.snap new file mode 100644 index 00000000000..e734121e9d1 --- /dev/null +++ b/sway-ir/tests/inline/by_block_count.ir.snap @@ -0,0 +1,54 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn one_block() -> bool { + entry(): + v1v1 = const bool false + ret bool v1v1 + } + + fn two_blocks() -> bool { + entry(): + v4v1 = const bool true + br block(v4v1) + + block(v3v1: bool): + ret bool v3v1 + } + + fn three_blocks(b: bool) -> bool { + entry(b: bool): + cbr b, then_block(), else_block() + + then_block(): + v9v1 = const bool false + ret bool v9v1 + + else_block(): + v11v1 = const bool true + ret bool v11v1 + } + + fn main() -> bool { + entry(): +- v13v1 = call one_block() +- v14v1 = call two_blocks() +- v15v1 = call three_blocks(v14v1) ++ v1v1 = const bool false ++ br block0(v1v1) ++ ++ block0(v17v1: bool): ++ v4v1 = const bool true ++ br two_blocks_block(v4v1) ++ ++ two_blocks_block(v14v3: bool): ++ br block1(v14v3) ++ ++ block1(v18v1: bool): ++ v15v1 = call three_blocks(v18v1) + ret bool v15v1 + } +} diff --git a/sway-ir/tests/inline/by_instr_count.ir.snap b/sway-ir/tests/inline/by_instr_count.ir.snap new file mode 100644 index 00000000000..87bd1d696b2 --- /dev/null +++ b/sway-ir/tests/inline/by_instr_count.ir.snap @@ -0,0 +1,120 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn less_one_block() -> u64 { + entry(): + v1v1 = const u64 11 + ret u64 v1v1 + } + + fn less_two_blocks() -> u64 { + entry(): + v4v1 = const u64 22 + br block(v4v1) + + block(v3v1: u64): + ret u64 v3v1 + } + + fn less_three_blocks(b: bool) -> u64 { + entry(b: bool): + cbr b, then_block(), else_block() + + then_block(): + v9v1 = const u64 33 + ret u64 v9v1 + + else_block(): + v11v1 = const u64 44 + ret u64 v11v1 + } + + fn more_one_block() -> bool { + entry(): + v13v1 = const u64 55 + v14v1 = const u64 66 + v15v1 = cmp eq v13v1 v14v1 + v16v1 = const bool true + v17v1 = cmp eq v15v1 v16v1 + v18v1 = const bool true + v19v1 = cmp eq v17v1 v18v1 + v20v1 = const bool true + v21v1 = cmp eq v19v1 v20v1 + ret bool v21v1 + } + + fn more_two_blocks() -> bool { + entry(): + v24v1 = const u64 77 + v25v1 = const u64 88 + v26v1 = cmp eq v24v1 v25v1 + v27v1 = const bool true + v28v1 = cmp eq v26v1 v27v1 + v29v1 = const bool true + v30v1 = cmp eq v28v1 v29v1 + v31v1 = const bool true + v32v1 = cmp eq v30v1 v31v1 + br block(v32v1) + + block(v23v1: bool): + ret bool v23v1 + } + + fn more_three_blocks(b: bool) -> bool { + entry(b: bool): + cbr b, then_block(), else_block() + + then_block(): + v37v1 = const u64 99 + v38v1 = const u64 1010 + v39v1 = cmp eq v37v1 v38v1 + v40v1 = const bool true + v41v1 = cmp eq v39v1 v40v1 + ret bool v41v1 + + else_block(): + v43v1 = const u64 1111 + v44v1 = const u64 1212 + v45v1 = cmp eq v43v1 v44v1 + v46v1 = const bool true + v47v1 = cmp eq v45v1 v46v1 + ret bool v47v1 + } + + fn main() -> bool { + entry(): +- v49v1 = call less_one_block() +- v50v1 = call less_two_blocks() ++ v1v1 = const u64 11 ++ br block0(v1v1) ++ ++ block0(v57v1: u64): ++ v4v1 = const u64 22 ++ br less_two_blocks_block(v4v1) ++ ++ less_two_blocks_block(v50v3: u64): ++ br block1(v50v3) ++ ++ block1(v58v1: u64): + v51v1 = const bool true +- v52v1 = call less_three_blocks(v51v1) ++ cbr v51v1, less_three_blocks_then_block(), less_three_blocks_else_block() ++ ++ less_three_blocks_then_block(): ++ v9v1 = const u64 33 ++ br block2(v9v1) ++ ++ less_three_blocks_else_block(): ++ v11v1 = const u64 44 ++ br block2(v11v1) ++ ++ block2(v61v1: u64): + v53v1 = call more_one_block() + v54v1 = call more_two_blocks() + v55v1 = call more_three_blocks(v54v1) + ret bool v55v1 + } +} diff --git a/sway-ir/tests/inline/by_stack_count.ir.snap b/sway-ir/tests/inline/by_stack_count.ir.snap new file mode 100644 index 00000000000..5c980f9198e --- /dev/null +++ b/sway-ir/tests/inline/by_stack_count.ir.snap @@ -0,0 +1,102 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn one_local() -> u64 { + local u64 num + + entry(): + v1v1 = const u64 11 + ret u64 v1v1 + } + + fn two_locals() -> u64 { + local bool flag + local u64 num + + entry(): + v3v1 = const u64 22 + ret u64 v3v1 + } + + fn three_locals() -> u64 { + local bool flag + local string<10> name + local u64 num + + entry(): + v5v1 = const u64 33 + ret u64 v5v1 + } + + fn two_struct_locals() -> u64 { + local { u64, u64 } pair + + entry(): + v7v1 = const u64 44 + ret u64 v7v1 + } + + fn three_struct_locals() -> u64 { + local { u64, u64, bool } triple + + entry(): + v9v1 = const u64 55 + ret u64 v9v1 + } + + fn two_mixed_locals() -> u64 { + local bool flag + local { u64 } single + + entry(): + v11v1 = const u64 66 + ret u64 v11v1 + } + + fn three_mixed_locals() -> u64 { + local bool flag + local { u64, string<10> } pair + + entry(): + v13v1 = const u64 77 + ret u64 v13v1 + } + + fn main() -> u64 { ++ local bool flag ++ local bool flag0 ++ local u64 num ++ local u64 num0 ++ local { u64, u64 } pair ++ local { u64 } single ++ + entry(): +- v15v1 = call one_local() +- v16v1 = call two_locals() ++ v1v1 = const u64 11 ++ br block0(v1v1) ++ ++ block0(v23v1: u64): ++ v3v1 = const u64 22 ++ br block1(v3v1) ++ ++ block1(v24v1: u64): + v17v1 = call three_locals() +- v18v1 = call two_struct_locals() ++ v7v1 = const u64 44 ++ br block2(v7v1) ++ ++ block2(v25v1: u64): + v19v1 = call three_struct_locals() +- v20v1 = call two_mixed_locals() ++ v11v1 = const u64 66 ++ br block3(v11v1) ++ ++ block3(v26v1: u64): + v21v1 = call three_mixed_locals() + ret u64 v21v1 + } +} diff --git a/sway-ir/tests/inline/fiddly.ir.snap b/sway-ir/tests/inline/fiddly.ir.snap new file mode 100644 index 00000000000..fc11ffaac68 --- /dev/null +++ b/sway-ir/tests/inline/fiddly.ir.snap @@ -0,0 +1,65 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn not(v: bool) -> bool { + entry(v: bool): + cbr v, block0(), block1() + + block0(): + v4v1 = const bool false + br block2(v4v1) + + block1(): + v6v1 = const bool true + br block2(v6v1) + + block2(v2v1: bool): + ret bool v2v1 + } + + fn main() -> bool { + entry(): + v11v1 = const bool true +- v12v1 = call not(v11v1) +- cbr v12v1, block1(v12v1), block0(v12v1) ++ cbr v11v1, not_block0(), not_block1() + ++ not_block0(): ++ v4v1 = const bool false ++ br not_block2(v4v1) ++ ++ not_block1(): ++ v6v1 = const bool true ++ br not_block2(v6v1) ++ ++ not_block2(v12v3: bool): ++ br block01(v12v3) ++ ++ block01(v18v1: bool): ++ cbr v18v1, block1(v18v1), block0(v18v1) ++ + block0(v9v1: bool): + v14v1 = const bool false +- v15v1 = call not(v14v1) +- br block1(v15v1) ++ cbr v14v1, not_block03(), not_block14() + ++ not_block03(): ++ br not_block25(v4v1) ++ ++ not_block14(): ++ br not_block25(v6v1) ++ ++ not_block25(v15v3: bool): ++ br block2(v15v3) ++ ++ block2(v23v1: bool): ++ br block1(v23v1) ++ + block1(v10v1: bool): + ret bool v10v1 + } +} diff --git a/sway-ir/tests/inline/int_to_ptr.ir.snap b/sway-ir/tests/inline/int_to_ptr.ir.snap new file mode 100644 index 00000000000..146febb3283 --- /dev/null +++ b/sway-ir/tests/inline/int_to_ptr.ir.snap @@ -0,0 +1,29 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn a(b: u64, __ret_value: __ptr b256) -> __ptr b256 { + entry(b: u64, __ret_value: __ptr b256): + v3v1 = int_to_ptr b to __ptr b256 + mem_copy_val __ret_value, v3v1 + ret __ptr b256 __ret_value + } + + fn main() -> __ptr b256 { + local b256 __ret_val_a + + entry(): + v6v1 = get_local __ptr b256, __ret_val_a + v7v1 = const u64 11 +- v8v1 = call a(v7v1, v6v1) +- ret __ptr b256 v8v1 ++ v8v3 = int_to_ptr v7v1 to __ptr b256 ++ mem_copy_val v6v1, v8v3 ++ br block0(v6v1) ++ ++ block0(v10v1: __ptr b256): ++ ret __ptr b256 v10v1 + } +} diff --git a/sway-ir/tests/inline/recursive-1.ir.snap b/sway-ir/tests/inline/recursive-1.ir.snap new file mode 100644 index 00000000000..892a35ca931 --- /dev/null +++ b/sway-ir/tests/inline/recursive-1.ir.snap @@ -0,0 +1,80 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn id_from_foo(b: u64) -> u64, !0 { + entry(b: u64): + ret u64 b + } + + fn foo(b: u64) -> u64 { + entry(b: u64): + v4v1 = call id_from_foo(b) + v5v1 = call foo(v4v1) + ret u64 v5v1 + } + + fn id_from_ping(b: u64) -> u64, !0 { + entry(b: u64): + ret u64 b + } + + fn id_from_pong(b: u64) -> u64, !0 { + entry(b: u64): + ret u64 b + } + + fn main() -> u64 { + entry(): + v11v1 = const u64 11 +- v12v1 = call foo(v11v1) +- v13v1 = call ping(v12v1) +- v14v1 = add v12v1, v13v1 ++ v12v3 = call id_from_foo(v11v1) ++ v25v1 = call foo(v12v3) ++ br block0(v25v1) ++ ++ block0(v24v1: u64): ++ v13v3 = call id_from_ping(v24v1) ++ v28v1 = call pong(v13v3) ++ br block1(v28v1) ++ ++ block1(v27v1: u64): ++ v14v1 = add v24v1, v27v1 + ret u64 v14v1 + } + + fn ping(b: u64) -> u64 { + entry(b: u64): + v17v1 = call id_from_ping(b) +- v18v1 = call pong(v17v1) +- ret u64 v18v1 ++ v18v3 = call id_from_pong(v17v1) ++ v31v1 = call ping(v18v3) ++ br block0(v31v1) ++ ++ block0(v30v1: u64): ++ ret u64 v30v1 + } + + fn pong(b: u64) -> u64 { + entry(b: u64): + v21v1 = call id_from_pong(b) +- v22v1 = call ping(v21v1) +- ret u64 v22v1 ++ v34v1 = call id_from_ping(v21v1) ++ v35v1 = call id_from_pong(v34v1) ++ v36v1 = call ping(v35v1) ++ br ping_block0(v36v1) ++ ++ ping_block0(v22v3: u64): ++ br block0(v22v3) ++ ++ block0(v33v1: u64): ++ ret u64 v33v1 + } +} + +!0 = inline "never" diff --git a/sway-ir/tests/inline/simple.ir.snap b/sway-ir/tests/inline/simple.ir.snap new file mode 100644 index 00000000000..0329a07514a --- /dev/null +++ b/sway-ir/tests/inline/simple.ir.snap @@ -0,0 +1,27 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn a(b: u64) -> u64 { + entry(b: u64): + ret u64 b + } + + fn main() -> u64 { + entry(): + v3v1 = const u64 11 +- v4v1 = call a(v3v1) ++ br block0(v3v1) ++ ++ block0(v8v1: u64): + v5v1 = const u64 22 +- v6v1 = call a(v5v1) +- ret u64 v6v1 ++ br block1(v5v1) ++ ++ block1(v9v1: u64): ++ ret u64 v9v1 + } +} diff --git a/sway-ir/tests/mem2reg/global_simple.ir.snap b/sway-ir/tests/mem2reg/global_simple.ir.snap new file mode 100644 index 00000000000..fad21bdea65 --- /dev/null +++ b/sway-ir/tests/mem2reg/global_simple.ir.snap @@ -0,0 +1,17 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + global sway3::F1 : u64 = const u64 11 + + pub entry fn main_0() -> u64 { + entry(): + v1v1 = get_global __ptr u64, sway3::F1 + v2v1 = load v1v1 +- ret u64 v2v1 ++ v4v1 = const u64 11 ++ ret u64 v4v1 + } +} diff --git a/sway-ir/tests/mem2reg/is_prime.ir.snap b/sway-ir/tests/mem2reg/is_prime.ir.snap new file mode 100644 index 00000000000..3367bf46a9a --- /dev/null +++ b/sway-ir/tests/mem2reg/is_prime.ir.snap @@ -0,0 +1,350 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool, !1 { + entry(): + v1v1 = const u64 64, !2 + v2v1 = call check_prime_4(v1v1), !3 + v3v1 = const bool false, !4 + v4v1 = call eq_3(v2v1, v3v1), !5 + v5v1 = call assert_0(v4v1), !7 + v6v1 = const u64 8, !8 + v7v1 = call check_prime_4(v6v1), !3 + v8v1 = const bool false, !9 + v9v1 = call eq_3(v7v1, v8v1), !10 + v10v1 = call assert_0(v9v1), !7 + v11v1 = const u64 7, !11 + v12v1 = call check_prime_4(v11v1), !3 + v13v1 = const bool true, !12 + v14v1 = call eq_3(v12v1, v13v1), !13 + v15v1 = call assert_0(v14v1), !7 + v16v1 = const u64 11, !14 + v17v1 = call check_prime_4(v16v1), !3 + v18v1 = const bool true, !15 + v19v1 = call eq_3(v17v1, v18v1), !16 + v20v1 = call assert_0(v19v1), !7 + v21v1 = const u64 13, !17 + v22v1 = call check_prime_4(v21v1), !3 + v23v1 = const bool true, !18 + v24v1 = call eq_3(v22v1, v23v1), !19 + v25v1 = call assert_0(v24v1), !7 + v26v1 = const u64 2, !20 + v27v1 = call check_prime_4(v26v1), !3 + v28v1 = const bool true, !21 + v29v1 = call eq_3(v27v1, v28v1), !22 + v30v1 = call assert_0(v29v1), !7 + v31v1 = const u64 3, !23 + v32v1 = call check_prime_4(v31v1), !3 + v33v1 = const bool true, !24 + v34v1 = call eq_3(v32v1, v33v1), !25 + v35v1 = call assert_0(v34v1), !7 + v36v1 = const u64 1, !26 + v37v1 = call check_prime_4(v36v1), !3 + v38v1 = const bool false, !27 + v39v1 = call eq_3(v37v1, v38v1), !28 + v40v1 = call assert_0(v39v1), !7 + v41v1 = const u64 0, !29 + v42v1 = call check_prime_4(v41v1), !3 + v43v1 = const bool false, !30 + v44v1 = call eq_3(v42v1, v43v1), !31 + v45v1 = call assert_0(v44v1), !7 + v46v1 = const u64 11, !32 + v47v1 = call check_prime_4(v46v1), !3 + v48v1 = const u64 17, !33 + v49v1 = call check_prime_4(v48v1), !3 + v50v1 = call eq_3(v47v1, v49v1), !34 + v51v1 = call assert_0(v50v1), !7 + v52v1 = const u64 12, !35 + v53v1 = call check_prime_4(v52v1), !3 + v54v1 = const bool false, !36 + v55v1 = call eq_3(v53v1, v54v1), !37 + v56v1 = call assert_0(v55v1), !7 + v57v1 = const u64 18, !38 + v58v1 = call check_prime_4(v57v1), !3 + v59v1 = const bool false, !39 + v60v1 = call eq_3(v58v1, v59v1), !40 + v61v1 = call assert_0(v60v1), !7 + v62v1 = const u64 12, !41 + v63v1 = call check_prime_4(v62v1), !3 + v64v1 = const u64 18, !42 + v65v1 = call check_prime_4(v64v1), !3 + v66v1 = call eq_3(v63v1, v65v1), !43 + v67v1 = call assert_0(v66v1), !7 + v68v1 = const bool true, !44 + ret bool v68v1 + } + + fn assert_0(condition !45: bool) -> (), !7 { + entry(condition: bool): + v72v1 = call not_1(condition), !46 + cbr v72v1, block0(), block1(), !46 + + block0(): + v74v1 = const u64 0, !47 + v75v1 = call revert_2(v74v1), !49 + v76v1 = const unit () + br block2(v76v1) + + block1(): + v78v1 = const unit () + br block2(v78v1) + + block2(v71v1: ()): + v80v1 = const unit () + ret () v80v1 + } + + fn not_1(self !51: bool) -> bool, !52 { + entry(self: bool): + v83v1 = const bool false, !53 + v84v1 = cmp eq self v83v1 + ret bool v84v1 + } + + fn revert_2(code !54: u64) -> (), !49 { + entry(code: u64): + revert code, !55 + } + + fn eq_3(self !56: bool, other !57: bool) -> bool, !58 { + entry(self: bool, other: bool): + v90v1 = cmp eq self other + ret bool v90v1 + } + + fn check_prime_4(n !59: u64) -> bool, !3 { + local u64 i + local bool is_not_prime + + entry(n: u64): + v96v1 = const u64 0, !60 + v97v1 = call eq_5(n, v96v1), !61 + cbr v97v1, block1(v97v1), block0(), !62 + + block0(): + v99v1 = const u64 1, !63 + v100v1 = call eq_5(n, v99v1), !64 + br block1(v100v1), !62 + + block1(v93v1: bool): + cbr v93v1, block2(), block3(), !62 + + block2(): + v103v1 = const bool false, !65 + br block7(v103v1) + + block3(): + v105v1 = get_local __ptr bool, is_not_prime, !66 +- v106v1 = const bool false, !67 +- store v106v1 to v105v1, !66 +- v108v1 = get_local __ptr u64, i, !68 +- v109v1 = const u64 2, !69 +- store v109v1 to v108v1, !68 +- br while() ++ v108v1 = get_local __ptr u64, i, !67 ++ v109v1 = const u64 2, !68 ++ v106v1 = const bool false, !69 ++ br while(v109v1, v106v1) + +- while(): ++ while(v163v1: u64, v166v1: bool): + v112v1 = get_local __ptr u64, i, !70 +- v113v1 = load v112v1, !70 +- v114v1 = call lt_8(v113v1, n), !71 ++ v114v1 = call lt_8(v163v1, n), !71 + cbr v114v1, while_body(), end_while() + + while_body(): + v116v1 = get_local __ptr u64, i, !72 +- v117v1 = load v116v1, !72 +- v118v1 = call modulo_6(n, v117v1), !73 ++ v118v1 = call modulo_6(n, v163v1), !73 + v119v1 = const u64 0, !74 + v120v1 = call eq_5(v118v1, v119v1), !75 + cbr v120v1, block4(), block5(), !75 + + end_while(): + v122v1 = get_local __ptr bool, is_not_prime, !76 +- v123v1 = load v122v1, !76 +- v124v1 = call not_9(v123v1), !77 ++ v124v1 = call not_9(v166v1), !77 + br block7(v124v1) + + block4(): + v126v1 = get_local __ptr bool, is_not_prime, !78 +- v127v1 = const bool true, !79 +- store v127v1 to v126v1, !78 +- v129v1 = get_local __ptr u64, i, !80 +- store n to v129v1, !80 ++ v129v1 = get_local __ptr u64, i, !79 + v131v1 = const unit () +- br block6(v131v1) ++ v127v1 = const bool true, !80 ++ br block6(v131v1, n, v127v1) + + block5(): + v133v1 = const unit () +- br block6(v133v1) ++ br block6(v133v1, v163v1, v166v1) + +- block6(v94v1: ()): ++ block6(v94v1: (), v164v1: u64, v165v1: bool): + v135v1 = get_local __ptr u64, i, !81 + v136v1 = get_local __ptr u64, i, !82 +- v137v1 = load v136v1, !82 + v138v1 = const u64 1, !83 +- v139v1 = call add_7(v137v1, v138v1), !84 +- store v139v1 to v135v1, !81 +- br while() ++ v139v1 = call add_7(v164v1, v138v1), !84 ++ br while(v139v1, v165v1) + + block7(v95v1: bool): + ret bool v95v1 + } + + fn eq_5(self !85: u64, other !86: u64) -> bool, !87 { + entry(self: u64, other: u64): + v145v1 = cmp eq self other + ret bool v145v1 + } + + fn modulo_6(self !88: u64, other !89: u64) -> u64, !90 { + entry(self: u64, other: u64): + v149v1 = asm(r1: self, r2: other, r3) -> u64 r3, !91 { + mod r3 r1 r2, !92 + } + ret u64 v149v1 + } + + fn add_7(self !93: u64, other !94: u64) -> u64, !95 { + entry(self: u64, other: u64): + v153v1 = add self, other + ret u64 v153v1 + } + + fn lt_8(self !96: u64, other !97: u64) -> bool, !98 { + entry(self: u64, other: u64): + v157v1 = asm(r1: self, r2: other, r3) -> bool r3, !99 { + lt r3 r1 r2, !100 + } + ret bool v157v1 + } + + fn not_9(self !51: bool) -> bool, !52 { + entry(self: bool): + v160v1 = const bool false, !53 + v161v1 = cmp eq self v160v1 + ret bool v161v1 + } +} + +!0 = "sway/test/src/e2e_vm_tests/test_programs/should_pass/language/is_prime/src/main.sw" +!1 = span !0 395 930 +!2 = span !0 438 440 +!3 = span !0 48 393 +!4 = span !0 445 450 +!5 = span !0 426 450 +!6 = "sway/sway-lib-std/src/assert.sw" +!7 = span !6 308 387 +!8 = span !0 476 477 +!9 = span !0 482 487 +!10 = span !0 464 487 +!11 = span !0 513 514 +!12 = span !0 519 523 +!13 = span !0 501 523 +!14 = span !0 549 551 +!15 = span !0 556 560 +!16 = span !0 537 560 +!17 = span !0 586 588 +!18 = span !0 593 597 +!19 = span !0 574 597 +!20 = span !0 623 624 +!21 = span !0 629 633 +!22 = span !0 611 633 +!23 = span !0 659 660 +!24 = span !0 665 669 +!25 = span !0 647 669 +!26 = span !0 695 696 +!27 = span !0 701 706 +!28 = span !0 683 706 +!29 = span !0 732 733 +!30 = span !0 738 743 +!31 = span !0 720 743 +!32 = span !0 770 772 +!33 = span !0 789 791 +!34 = span !0 758 792 +!35 = span !0 818 820 +!36 = span !0 825 830 +!37 = span !0 806 830 +!38 = span !0 856 858 +!39 = span !0 863 868 +!40 = span !0 844 868 +!41 = span !0 894 896 +!42 = span !0 913 915 +!43 = span !0 882 916 +!44 = span !0 924 928 +!45 = span !6 322 331 +!46 = span !6 348 358 +!47 = span !6 376 377 +!48 = "sway/sway-lib-std/src/revert.sw" +!49 = span !48 172 219 +!50 = "sway/sway-lib-std/src/ops.sw" +!51 = span !50 2706 2710 +!52 = span !50 2699 2753 +!53 = span !50 2741 2746 +!54 = span !48 186 190 +!55 = span !48 203 217 +!56 = span !50 2923 2927 +!57 = span !50 2929 2934 +!58 = span !50 2917 2983 +!59 = span !0 63 64 +!60 = span !0 93 94 +!61 = span !0 88 94 +!62 = span !0 88 104 +!63 = span !0 103 104 +!64 = span !0 98 104 +!65 = span !0 115 120 +!66 = span !0 142 171 +- !67 = span !0 165 170 +- !68 = span !0 180 194 +- !69 = span !0 192 193 ++ !67 = span !0 180 194 ++ !68 = span !0 192 193 ++ !69 = span !0 165 170 +!70 = span !0 209 210 +!71 = span !0 209 214 +!72 = span !0 237 238 +!73 = span !0 233 238 +!74 = span !0 242 243 +!75 = span !0 233 243 +!76 = span !0 373 385 +!77 = span !0 372 385 +!78 = span !0 262 281 +- !79 = span !0 277 281 +- !80 = span !0 299 304 ++ !79 = span !0 299 304 ++ !80 = span !0 277 281 +!81 = span !0 342 351 +!82 = span !0 346 347 +!83 = span !0 350 351 +!84 = span !0 346 351 +!85 = span !50 3015 3019 +!86 = span !50 3021 3026 +!87 = span !50 3009 3075 +!88 = span !50 2001 2005 +!89 = span !50 2007 2012 +!90 = span !50 1991 2130 +!91 = span !50 2038 2124 +!92 = span !50 2081 2093 +!93 = span !50 117 121 +!94 = span !50 123 128 +!95 = span !50 110 178 +!96 = span !50 3993 3997 +!97 = span !50 3999 4004 +!98 = span !50 3987 4122 +!99 = span !50 4030 4116 +!100 = span !50 4073 4084 diff --git a/sway-ir/tests/mem2reg/while_loops.ir.snap b/sway-ir/tests/mem2reg/while_loops.ir.snap new file mode 100644 index 00000000000..9fc581c9833 --- /dev/null +++ b/sway-ir/tests/mem2reg/while_loops.ir.snap @@ -0,0 +1,402 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool, !1 { + local u64 counter + local u64 counter_2 + local u64 counter_3 + local u64 counter_4 + local u64 counter_5 + local () result + + entry(): + v3v1 = get_local __ptr u64, counter, !2 + v4v1 = const u64 0, !3 +- store v4v1 to v3v1, !2 +- br while() ++ br while(v4v1) + +- while(): ++ while(v153v1: u64): + v7v1 = get_local __ptr u64, counter, !4 +- v8v1 = load v7v1, !4 + v9v1 = const u64 10, !5 +- v10v1 = call lt_1(v8v1, v9v1), !6 ++ v10v1 = call lt_1(v153v1, v9v1), !6 + cbr v10v1, while_body(), end_while() + + while_body(): + v12v1 = get_local __ptr u64, counter, !7 + v13v1 = get_local __ptr u64, counter, !8 +- v14v1 = load v13v1, !8 + v15v1 = const u64 1, !9 +- v16v1 = call add_0(v14v1, v15v1), !10 +- store v16v1 to v12v1, !7 +- br while() ++ v16v1 = call add_0(v153v1, v15v1), !10 ++ br while(v16v1) + + end_while(): + v19v1 = get_local __ptr u64, counter, !11 +- v20v1 = load v19v1, !11 + v21v1 = const u64 10, !12 +- v22v1 = call eq_5(v20v1, v21v1), !13 ++ v22v1 = call eq_5(v153v1, v21v1), !13 + v23v1 = call assert_2(v22v1), !15 + v24v1 = get_local __ptr u64, counter_2, !16 +- v25v1 = const u64 0, !17 +- store v25v1 to v24v1, !16 +- v27v1 = get_local __ptr u64, counter_3, !18 ++ v27v1 = get_local __ptr u64, counter_3, !17 ++ v25v1 = const u64 0, !18 + v28v1 = const u64 0, !19 +- store v28v1 to v27v1, !18 +- br while0() ++ br while0(v25v1, v28v1) + +- while0(): ++ while0(v155v1: u64, v157v1: u64): + v31v1 = get_local __ptr u64, counter_2, !20 +- v32v1 = load v31v1, !20 + v33v1 = const u64 10, !21 +- v34v1 = call lt_1(v32v1, v33v1), !22 ++ v34v1 = call lt_1(v155v1, v33v1), !22 + cbr v34v1, while_body1(), end_while2() + + while_body1(): + v36v1 = get_local __ptr u64, counter_2, !23 +- v37v1 = load v36v1, !23 + v38v1 = const u64 3, !24 +- v39v1 = call eq_5(v37v1, v38v1), !25 ++ v39v1 = call eq_5(v155v1, v38v1), !25 + cbr v39v1, block3(), block4(), !25 + + end_while2(): + v41v1 = get_local __ptr u64, counter_2, !26 +- v42v1 = load v41v1, !26 + v43v1 = const u64 10, !27 +- v44v1 = call eq_5(v42v1, v43v1), !28 ++ v44v1 = call eq_5(v155v1, v43v1), !28 + cbr v44v1, block6(), block7(v44v1), !29 + + block3(): + v46v1 = get_local __ptr u64, counter_2, !30 ++ v49v1 = const unit () + v47v1 = const u64 10, !31 +- store v47v1 to v46v1, !30 +- v49v1 = const unit () +- br block5(v49v1) ++ br block5(v49v1, v47v1, v157v1) + + block4(): + v51v1 = get_local __ptr u64, counter_2, !32 + v52v1 = get_local __ptr u64, counter_2, !33 +- v53v1 = load v52v1, !33 + v54v1 = const u64 1, !34 +- v55v1 = call add_0(v53v1, v54v1), !35 +- store v55v1 to v51v1, !32 ++ v55v1 = call add_0(v155v1, v54v1), !35 + v57v1 = get_local __ptr u64, counter_3, !36 + v58v1 = get_local __ptr u64, counter_3, !37 +- v59v1 = load v58v1, !37 + v60v1 = const u64 1, !38 +- v61v1 = call add_0(v59v1, v60v1), !39 +- store v61v1 to v57v1, !36 ++ v61v1 = call add_0(v157v1, v60v1), !39 + v63v1 = const unit () +- br block5(v63v1) ++ br block5(v63v1, v55v1, v61v1) + +- block5(v1v1: ()): +- br while0() ++ block5(v1v1: (), v154v1: u64, v156v1: u64): ++ br while0(v154v1, v156v1) + + block6(): + v66v1 = get_local __ptr u64, counter_3, !40 +- v67v1 = load v66v1, !40 + v68v1 = const u64 3, !41 +- v69v1 = call eq_5(v67v1, v68v1), !42 ++ v69v1 = call eq_5(v157v1, v68v1), !42 + br block7(v69v1), !29 + + block7(v2v1: bool): + v71v1 = call assert_2(v2v1), !15 + v72v1 = get_local __ptr u64, counter_4, !43 +- v73v1 = const u64 0, !44 +- store v73v1 to v72v1, !43 +- v75v1 = get_local __ptr u64, counter_5, !45 +- v76v1 = const u64 0, !46 +- store v76v1 to v75v1, !45 +- br while8() ++ v75v1 = get_local __ptr u64, counter_5, !44 ++ v76v1 = const u64 0, !45 ++ v73v1 = const u64 0, !46 ++ br while8(v76v1, v73v1) + +- while8(): ++ while8(v159v1: u64, v160v1: u64): + v79v1 = get_local __ptr u64, counter_4, !47 +- v80v1 = load v79v1, !47 + v81v1 = const u64 7, !48 +- v82v1 = call lt_1(v80v1, v81v1), !49 ++ v82v1 = call lt_1(v160v1, v81v1), !49 + cbr v82v1, while_body9(), end_while10() + + while_body9(): +- br while11() ++ br while11(v159v1) + + end_while10(): + v85v1 = get_local __ptr u64, counter_5, !50 +- v86v1 = load v85v1, !50 + v87v1 = const u64 11, !51 +- v88v1 = call eq_5(v86v1, v87v1), !52 ++ v88v1 = call eq_5(v159v1, v87v1), !52 + v89v1 = call assert_2(v88v1), !15 + v90v1 = get_local __ptr u64, counter_4, !53 +- v91v1 = load v90v1, !53 + v92v1 = const u64 7, !54 +- v93v1 = call eq_5(v91v1, v92v1), !55 ++ v93v1 = call eq_5(v160v1, v92v1), !55 + v94v1 = call assert_2(v93v1), !15 + br while14() + +- while11(): ++ while11(v158v1: u64): + v96v1 = get_local __ptr u64, counter_5, !56 +- v97v1 = load v96v1, !56 + v98v1 = const u64 11, !57 +- v99v1 = call lt_1(v97v1, v98v1), !58 ++ v99v1 = call lt_1(v158v1, v98v1), !58 + cbr v99v1, while_body12(), end_while13() + + while_body12(): + v101v1 = get_local __ptr u64, counter_5, !59 + v102v1 = get_local __ptr u64, counter_5, !60 +- v103v1 = load v102v1, !60 + v104v1 = const u64 1, !61 +- v105v1 = call add_0(v103v1, v104v1), !62 +- store v105v1 to v101v1, !59 +- br while11() ++ v105v1 = call add_0(v158v1, v104v1), !62 ++ br while11(v105v1) + + end_while13(): + v108v1 = get_local __ptr u64, counter_4, !63 + v109v1 = get_local __ptr u64, counter_4, !64 +- v110v1 = load v109v1, !64 + v111v1 = const u64 1, !65 +- v112v1 = call add_0(v110v1, v111v1), !66 +- store v112v1 to v108v1, !63 +- br while8() ++ v112v1 = call add_0(v160v1, v111v1), !66 ++ br while8(v158v1, v112v1) + + while14(): + v115v1 = const bool true, !67 + cbr v115v1, while_body15(), end_while16() + + while_body15(): + br end_while16() + + end_while16(): + v118v1 = get_local __ptr (), result, !68 +- v119v1 = const unit (), !69 +- store v119v1 to v118v1, !68 +- v121v1 = const bool true, !70 ++ v121v1 = const bool true, !69 + ret bool v121v1 + } + +- fn add_0(self !72: u64, other !73: u64) -> u64, !74 { ++ fn add_0(self !71: u64, other !72: u64) -> u64, !73 { + entry(self: u64, other: u64): + v125v1 = add self, other + ret u64 v125v1 + } + +- fn lt_1(self !75: u64, other !76: u64) -> bool, !77 { ++ fn lt_1(self !74: u64, other !75: u64) -> bool, !76 { + entry(self: u64, other: u64): +- v129v1 = asm(r1: self, r2: other, r3) -> bool r3, !78 { +- lt r3 r1 r2, !79 ++ v129v1 = asm(r1: self, r2: other, r3) -> bool r3, !77 { ++ lt r3 r1 r2, !78 + } + ret bool v129v1 + } + +- fn assert_2(condition !80: bool) -> (), !15 { ++ fn assert_2(condition !79: bool) -> (), !15 { + entry(condition: bool): +- v133v1 = call not_3(condition), !81 +- cbr v133v1, block0(), block1(), !81 ++ v133v1 = call not_3(condition), !80 ++ cbr v133v1, block0(), block1(), !80 + + block0(): +- v135v1 = const u64 0, !82 +- v136v1 = call revert_4(v135v1), !84 ++ v135v1 = const u64 0, !81 ++ v136v1 = call revert_4(v135v1), !83 + v137v1 = const unit () + br block2(v137v1) + + block1(): + v139v1 = const unit () + br block2(v139v1) + + block2(v132v1: ()): + v141v1 = const unit () + ret () v141v1 + } + +- fn not_3(self !85: bool) -> bool, !86 { ++ fn not_3(self !84: bool) -> bool, !85 { + entry(self: bool): +- v144v1 = const bool false, !87 ++ v144v1 = const bool false, !86 + v145v1 = cmp eq self v144v1 + ret bool v145v1 + } + +- fn revert_4(code !88: u64) -> (), !84 { ++ fn revert_4(code !87: u64) -> (), !83 { + entry(code: u64): +- revert code, !89 ++ revert code, !88 + } + +- fn eq_5(self !90: u64, other !91: u64) -> bool, !92 { ++ fn eq_5(self !89: u64, other !90: u64) -> bool, !91 { + entry(self: u64, other: u64): + v151v1 = cmp eq self other + ret bool v151v1 + } +} + +!0 = "sway/test/src/e2e_vm_tests/test_programs/should_pass/language/while_loops/src/main.sw" +!1 = span !0 35 1010 +!2 = span !0 59 79 +!3 = span !0 77 78 +!4 = span !0 123 130 +!5 = span !0 133 135 +!6 = span !0 123 135 +!7 = span !0 146 167 +!8 = span !0 156 163 +!9 = span !0 166 167 +!10 = span !0 156 167 +!11 = span !0 186 193 +!12 = span !0 197 199 +!13 = span !0 186 199 +!14 = "sway/sway-lib-std/src/assert.sw" +!15 = span !14 308 387 +!16 = span !0 293 315 +- !17 = span !0 313 314 +- !18 = span !0 320 342 ++ !17 = span !0 320 342 ++ !18 = span !0 313 314 +!19 = span !0 340 341 +!20 = span !0 353 362 +!21 = span !0 365 367 +!22 = span !0 353 367 +!23 = span !0 381 390 +!24 = span !0 394 395 +!25 = span !0 381 395 +!26 = span !0 602 611 +!27 = span !0 615 617 +!28 = span !0 602 617 +!29 = span !0 602 635 +!30 = span !0 463 477 +!31 = span !0 475 477 +!32 = span !0 508 533 +!33 = span !0 520 529 +!34 = span !0 532 533 +!35 = span !0 520 533 +!36 = span !0 547 572 +!37 = span !0 559 568 +!38 = span !0 571 572 +!39 = span !0 559 572 +!40 = span !0 621 630 +!41 = span !0 634 635 +!42 = span !0 621 635 +!43 = span !0 669 691 +- !44 = span !0 689 690 +- !45 = span !0 696 718 +- !46 = span !0 716 717 ++ !44 = span !0 696 718 ++ !45 = span !0 716 717 ++ !46 = span !0 689 690 +!47 = span !0 730 739 +!48 = span !0 742 743 +!49 = span !0 730 743 +!50 = span !0 878 887 +!51 = span !0 891 893 +!52 = span !0 878 893 +!53 = span !0 907 916 +!54 = span !0 920 921 +!55 = span !0 907 921 +!56 = span !0 760 769 +!57 = span !0 772 774 +!58 = span !0 760 774 +!59 = span !0 789 814 +!60 = span !0 801 810 +!61 = span !0 813 814 +!62 = span !0 801 814 +!63 = span !0 834 859 +!64 = span !0 846 855 +!65 = span !0 858 859 +!66 = span !0 846 859 +!67 = span !0 982 986 +!68 = span !0 963 998 +- !69 = span !0 976 997 +- !70 = span !0 1004 1008 +- !71 = "sway/sway-lib-std/src/ops.sw" +- !72 = span !71 117 121 +- !73 = span !71 123 128 +- !74 = span !71 110 178 +- !75 = span !71 3993 3997 +- !76 = span !71 3999 4004 +- !77 = span !71 3987 4122 +- !78 = span !71 4030 4116 +- !79 = span !71 4073 4084 +- !80 = span !14 322 331 +- !81 = span !14 348 358 +- !82 = span !14 376 377 +- !83 = "sway/sway-lib-std/src/revert.sw" +- !84 = span !83 172 219 +- !85 = span !71 2706 2710 +- !86 = span !71 2699 2753 +- !87 = span !71 2741 2746 +- !88 = span !83 186 190 +- !89 = span !83 203 217 +- !90 = span !71 3015 3019 +- !91 = span !71 3021 3026 +- !92 = span !71 3009 3075 ++ !69 = span !0 1004 1008 ++ !70 = "sway/sway-lib-std/src/ops.sw" ++ !71 = span !70 117 121 ++ !72 = span !70 123 128 ++ !73 = span !70 110 178 ++ !74 = span !70 3993 3997 ++ !75 = span !70 3999 4004 ++ !76 = span !70 3987 4122 ++ !77 = span !70 4030 4116 ++ !78 = span !70 4073 4084 ++ !79 = span !14 322 331 ++ !80 = span !14 348 358 ++ !81 = span !14 376 377 ++ !82 = "sway/sway-lib-std/src/revert.sw" ++ !83 = span !82 172 219 ++ !84 = span !70 2706 2710 ++ !85 = span !70 2699 2753 ++ !86 = span !70 2741 2746 ++ !87 = span !82 186 190 ++ !88 = span !82 203 217 ++ !89 = span !70 3015 3019 ++ !90 = span !70 3021 3026 ++ !91 = span !70 3009 3075 diff --git a/sway-ir/tests/memcpy_prop/memcpy_prop.ir.snap b/sway-ir/tests/memcpy_prop/memcpy_prop.ir.snap new file mode 100644 index 00000000000..a65f31b1b4f --- /dev/null +++ b/sway-ir/tests/memcpy_prop/memcpy_prop.ir.snap @@ -0,0 +1,95 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + pub entry fn __entry() -> __ptr slice { + local mut slice __aggr_memcpy_0 + local { u64, u64 } __anon_0 + local slice __ret_value + + entry(): + v1v1 = get_local __ptr slice, __ret_value + v2v1 = call main_0() + v3v1 = get_local __ptr { u64, u64 }, __anon_0 + v4v1 = const u64 0 + v5v1 = get_elem_ptr v3v1, __ptr u64, v4v1 + v6v1 = const u64 0 + store v6v1 to v5v1 + v8v1 = const u64 1 + v9v1 = get_elem_ptr v3v1, __ptr u64, v8v1 + v10v1 = const u64 0 + store v10v1 to v9v1 + v12v1 = asm(s: v3v1) -> __ptr slice s { + } + v13v1 = get_local __ptr slice, __aggr_memcpy_0 + mem_copy_val v13v1, v12v1 + mem_copy_val v1v1, v13v1 + ret __ptr slice v1v1 + } + + entry_orig fn main_0() -> () { + local { b256 } __ret_val + + entry(): + v17v1 = get_local __ptr { b256 }, __ret_val + v18v1 = call wrapper_1(v17v1) + v19v1 = const unit () + ret () v19v1 + } + + fn wrapper_1(__ret_value: __ptr { b256 }) -> () { + local { u64, ( () | { b256 } ) } __matched_value_4 + local { u64, ( () | { b256 } ) } __ret_val + local { u64, ( () | { b256 } ) } self_ + + entry(__ret_value: __ptr { b256 }): +- v22v1 = get_local __ptr { u64, ( () | { b256 } ) }, __ret_val ++ v22v1 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4 + v23v1 = call return_option_5(v22v1) +- v24v1 = get_local __ptr { u64, ( () | { b256 } ) }, self_ +- mem_copy_val v24v1, v22v1 +- v26v1 = get_local __ptr { u64, ( () | { b256 } ) }, self_ ++ v24v1 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4 ++ v26v1 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4 + v27v1 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4 +- mem_copy_val v27v1, v26v1 +- v29v1 = get_local __ptr { u64, ( () | { b256 } ) }, self_ ++ v29v1 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4 + v30v1 = const u64 0 + v31v1 = get_elem_ptr v29v1, __ptr u64, v30v1 + v32v1 = load v31v1 + v33v1 = const u64 1 + v34v1 = cmp eq v32v1 v33v1 + cbr v34v1, unwrap_2_block0(), unwrap_2_block1() + + unwrap_2_block0(): + v36v1 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4 + v37v1 = const u64 1 + v38v1 = const u64 1 + v39v1 = get_elem_ptr v36v1, __ptr { b256 }, v37v1, v38v1 + mem_copy_val __ret_value, v39v1 + v41v1 = const unit () + ret () v41v1 + + unwrap_2_block1(): + v43v1 = const u64 0 + revert v43v1 + } + + fn return_option_5(__ret_value: __ptr { u64, ( () | { b256 } ) }) -> () { + local { u64, ( () | { b256 } ) } __anon_0 + + entry(__ret_value: __ptr { u64, ( () | { b256 } ) }): + v46v1 = get_local __ptr { u64, ( () | { b256 } ) }, __anon_0 + v47v1 = const u64 0 +- v48v1 = get_elem_ptr v46v1, __ptr u64, v47v1 ++ v48v1 = get_elem_ptr __ret_value, __ptr u64, v47v1 + v49v1 = const u64 0 + store v49v1 to v48v1 +- mem_copy_val __ret_value, v46v1 + v52v1 = const unit () + ret () v52v1 + } +} diff --git a/sway-ir/tests/memcpyopt/copy_prop_1.ir.snap b/sway-ir/tests/memcpyopt/copy_prop_1.ir.snap new file mode 100644 index 00000000000..9d1aae43671 --- /dev/null +++ b/sway-ir/tests/memcpyopt/copy_prop_1.ir.snap @@ -0,0 +1,23 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64 { + local { u64, u64, u64, u64 } __anon_0 + local { u64, u64, u64, u64 } __anon_468 + + entry(): + v1v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0 + v2v1 = const u64 0 + v3v1 = get_elem_ptr v1v1, __ptr u64, v2v1 + v4v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_468 + v5v1 = const u64 0 + v6v1 = get_elem_ptr v4v1, __ptr u64, v5v1 + mem_copy_val v6v1, v3v1 +- v8v1 = load v6v1 ++ v8v1 = load v3v1 + ret u64 v8v1 + } +} diff --git a/sway-ir/tests/memcpyopt/copy_prop_2.ir.snap b/sway-ir/tests/memcpyopt/copy_prop_2.ir.snap new file mode 100644 index 00000000000..548eb6ee14c --- /dev/null +++ b/sway-ir/tests/memcpyopt/copy_prop_2.ir.snap @@ -0,0 +1,23 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64 { + local { u64, u64, u64, u64 } __anon_0 + local { u64, u64, u64, u64 } __anon_468 + + entry(): + v1v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0 + v2v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_468 + mem_copy_val v2v1, v1v1 + v4v1 = const u64 0 + v5v1 = get_elem_ptr v2v1, __ptr u64, v4v1 +- v6v1 = load v5v1 ++ v8v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0 ++ v9v1 = get_elem_ptr v8v1, __ptr u64, v4v1 ++ v6v1 = load v9v1 + ret u64 v6v1 + } +} diff --git a/sway-ir/tests/memcpyopt/copy_prop_3.ir.snap b/sway-ir/tests/memcpyopt/copy_prop_3.ir.snap new file mode 100644 index 00000000000..271730014d8 --- /dev/null +++ b/sway-ir/tests/memcpyopt/copy_prop_3.ir.snap @@ -0,0 +1,24 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main(v101: u64) -> u64 { + local [u64; 8] __anon_0 + local [u64; 8] __anon_468 + + entry(v101: u64): + v2v1 = get_local __ptr [u64; 8], __anon_0 + v3v1 = get_local __ptr [u64; 8], __anon_468 + mem_copy_val v3v1, v2v1 + v5v1 = const u64 1 + v6v1 = add v101, v5v1 + v7v1 = get_elem_ptr v3v1, __ptr u64, v6v1 +- v8v1 = load v7v1 ++ v10v1 = get_local __ptr [u64; 8], __anon_0 ++ v11v1 = get_elem_ptr v10v1, __ptr u64, v6v1 ++ v8v1 = load v11v1 + ret u64 v8v1 + } +} diff --git a/sway-ir/tests/memcpyopt/copy_prop_mut.ir.snap b/sway-ir/tests/memcpyopt/copy_prop_mut.ir.snap new file mode 100644 index 00000000000..22b27c4e574 --- /dev/null +++ b/sway-ir/tests/memcpyopt/copy_prop_mut.ir.snap @@ -0,0 +1,49 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> () { + entry(): + v1v1 = call test_single() + v2v1 = call test_double() + v3v1 = const unit () + ret () v3v1 + } + + fn test_single() -> b256 { +- local b256 a = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 ++ local mut b256 a = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 + local mut b256 b + + entry(): + v5v1 = get_local __ptr b256, a + v6v1 = load v5v1 +- v7v1 = get_local __ptr b256, b +- store v6v1 to v7v1 ++ v7v1 = get_local __ptr b256, a + v9v1 = load v7v1 + ret b256 v9v1 + } + + fn test_double() -> b256 { +- local b256 a = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 ++ local mut b256 a = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 + local b256 b + local mut b256 c + + entry(): + v11v1 = get_local __ptr b256, a + v12v1 = load v11v1 +- v13v1 = get_local __ptr b256, b +- store v12v1 to v13v1 +- v15v1 = get_local __ptr b256, c ++ v13v1 = get_local __ptr b256, a ++ v15v1 = get_local __ptr b256, a + v16v1 = load v13v1 +- store v16v1 to v15v1 + v18v1 = load v15v1 + ret b256 v18v1 + } +} diff --git a/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir.snap b/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir.snap new file mode 100644 index 00000000000..42c41b28bf8 --- /dev/null +++ b/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir.snap @@ -0,0 +1,27 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64 { + local u64 x + local u64 y + + entry(): + v1v1 = get_local __ptr u64, x + v2v1 = get_local __ptr u64, y + v3v1 = load v1v1 + v4v1 = call escape(v1v1) + store v3v1 to v2v1 + v6v1 = load v2v1 + ret u64 v6v1 + } + + fn escape(a: __ptr u64) -> u64 { + entry(a: __ptr u64): + v9v1 = const u64 0 + store v9v1 to a + ret u64 v9v1 + } +} diff --git a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir.snap b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir.snap new file mode 100644 index 00000000000..8743dd39680 --- /dev/null +++ b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir.snap @@ -0,0 +1,21 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u256 { + local u256 x + local u256 y + local u256 z + + entry(): + v1v1 = get_local __ptr u256, x + v2v1 = get_local __ptr u256, y + v3v1 = get_local __ptr u256, z + mem_copy_val v3v1, v1v1 + wide add v1v1, v2v1 to v3v1 + v6v1 = load v3v1 + ret u256 v6v1 + } +} diff --git a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir.snap b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir.snap new file mode 100644 index 00000000000..e193b6c05f7 --- /dev/null +++ b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir.snap @@ -0,0 +1,21 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u256 { + local u256 x + local u256 y + local u256 z + + entry(): + v1v1 = get_local __ptr u256, x + v2v1 = get_local __ptr u256, y + v3v1 = get_local __ptr u256, z + mem_copy_val v3v1, v1v1 + wide not v2v1 to v3v1 + v6v1 = load v3v1 + ret u256 v6v1 + } +} diff --git a/sway-ir/tests/memcpyopt/ret_value.ir.snap b/sway-ir/tests/memcpyopt/ret_value.ir.snap new file mode 100644 index 00000000000..3aa32b3d473 --- /dev/null +++ b/sway-ir/tests/memcpyopt/ret_value.ir.snap @@ -0,0 +1,25 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main(__ret_value: __ptr { u64, u64 }) -> __ptr { u64, u64 } { + local { u64, u64 } __anon_0 + + entry(__ret_value: __ptr { u64, u64 }): + v2v1 = get_local __ptr { u64, u64 }, __anon_0 + v3v1 = const u64 0 + v4v1 = get_elem_ptr v2v1, __ptr u64, v3v1 + v5v1 = const u64 11 + store v5v1 to v4v1 + v7v1 = const u64 1 + v8v1 = get_elem_ptr v2v1, __ptr u64, v7v1 + v9v1 = const u64 22 + store v9v1 to v8v1 + v11v1 = load v2v1 +- store v11v1 to __ret_value ++ mem_copy_val __ret_value, v2v1 + ret __ptr { u64, u64 } __ret_value + } +} diff --git a/sway-ir/tests/serialize/asm_block.ir.snap b/sway-ir/tests/serialize/asm_block.ir.snap new file mode 100644 index 00000000000..ec62dd6412f --- /dev/null +++ b/sway-ir/tests/serialize/asm_block.ir.snap @@ -0,0 +1,18 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64 { + entry(): + v2v1 = asm() -> () { + } + v3v1 = asm() -> () zero { + } + v4v1 = asm() -> u64 zero { + } + v5v1 = const u64 0 + ret u64 v5v1 + } +} diff --git a/sway-ir/tests/serialize/entry.ir.snap b/sway-ir/tests/serialize/entry.ir.snap new file mode 100644 index 00000000000..e33d88a0ad0 --- /dev/null +++ b/sway-ir/tests/serialize/entry.ir.snap @@ -0,0 +1,18 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn foo() -> u64 { + entry(): + } + + pub entry fn bar() -> u64 { + entry(): + } + + pub fn baz() -> u64 { + entry(): + } +} diff --git a/sway-ir/tests/serialize/get_storage_key.ir.snap b/sway-ir/tests/serialize/get_storage_key.ir.snap new file mode 100644 index 00000000000..ec3de6b0273 --- /dev/null +++ b/sway-ir/tests/serialize/get_storage_key.ir.snap @@ -0,0 +1,52 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +contract { + storage_key storage.a = 0xeb7ceb95f655d60faa3ae0cd0de1ff1af784e38a3b25a88f2be480f15478907f + storage_key storage.a.b = 0xeb7ceb95f655d60faa3ae0cd0de1ff1af784e38a3b25a88f2be480f15478907f : 0 : 0x9cb84a7467ade86aea47c23daff70a989ae56e1466ffbb2e04aba9255b262fc6 + storage_key storage.b = 0x1111111111111111111111111111111111111111111111111111111111111111 + storage_key storage.c = 0x2222222222222222222222222222222222222222222222222222222222222222 : 2 + storage_key storage::n1.a = 0xbde9a42c506e6c3dd71dcf63c89e2d066b3fea525afe68f1ddc47d58bad97337 + storage_key storage::n1::n2.a = 0xdf79747c92e7208309fd8865d0fd592109b7bf72667bccfcaaabf9b12ac8c5d3 : 3 + storage_key storage::n1::n2.a.b.c = 0x8888888888888888888888888888888888888888888888888888888888888888 : 2 + + pub entry fn all_in_one<0e615b65>() -> () { + local { b256, u64, b256 } __tmp_arg + local { b256, u64, b256 } __tmp_arg0 + local { b256, u64, b256 } __tmp_arg1 + local { b256, u64, b256 } __tmp_arg2 + local { b256, u64, b256 } __tmp_arg3 + + entry(): + v1v1 = get_storage_key __ptr { b256, u64, b256 }, storage.a + v2v1 = get_local __ptr { b256, u64, b256 }, __tmp_arg + mem_copy_val v2v1, v1v1 + v4v1 = call poke_0(v2v1) + v5v1 = get_storage_key __ptr { b256, u64, b256 }, storage.a.b + v6v1 = get_local __ptr { b256, u64, b256 }, __tmp_arg0 + mem_copy_val v6v1, v5v1 + v8v1 = call poke_0(v6v1) + v9v1 = get_storage_key __ptr { b256, u64, b256 }, storage::n1.a + v10v1 = get_local __ptr { b256, u64, b256 }, __tmp_arg1 + mem_copy_val v10v1, v9v1 + v12v1 = call poke_0(v10v1) + v13v1 = get_storage_key __ptr { b256, u64, b256 }, storage::n1::n2.a + v14v1 = get_local __ptr { b256, u64, b256 }, __tmp_arg2 + mem_copy_val v14v1, v13v1 + v16v1 = call poke_0(v14v1) + v17v1 = get_storage_key __ptr { b256, u64, b256 }, storage::n1::n2.a.b.c + v18v1 = get_local __ptr { b256, u64, b256 }, __tmp_arg3 + mem_copy_val v18v1, v17v1 + v20v1 = call poke_0(v18v1) + v21v1 = const unit () + ret () v21v1 + } + + fn poke_0(_t: __ptr { b256, u64, b256 }) -> () { + entry(_t: __ptr { b256, u64, b256 }): + v24v1 = const unit () + ret () v24v1 + } +} diff --git a/sway-ir/tests/serialize/intrinsic_addr_of.ir.snap b/sway-ir/tests/serialize/intrinsic_addr_of.ir.snap new file mode 100644 index 00000000000..28dcbca4e0c --- /dev/null +++ b/sway-ir/tests/serialize/intrinsic_addr_of.ir.snap @@ -0,0 +1,18 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> u64 { + local { u64, ( { b256 } | { b256 } ) } sender + + entry(): + v1v1 = get_local __ptr { u64, ( { b256 } | { b256 } ) }, sender + v2v1 = const { u64, ( { b256 } | { b256 } ) } { u64 0, { b256 } { b256 0x0100000000000000000000000000000000000000000000000000000000000010 } } + store v2v1 to v1v1 + v4v1 = get_local __ptr { u64, ( { b256 } | { b256 } ) }, sender + v5v1 = ptr_to_int v4v1 to u64 + ret u64 v5v1 + } +} diff --git a/sway-ir/tests/serialize/log_event_metadata.ir.snap b/sway-ir/tests/serialize/log_event_metadata.ir.snap new file mode 100644 index 00000000000..fa5c5b9f71f --- /dev/null +++ b/sway-ir/tests/serialize/log_event_metadata.ir.snap @@ -0,0 +1,18 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> () { + entry(): + v1v1 = const u64 0 + v2v1 = const u64 1 + log u64 v1v1, v2v1 + v4v1 = const u64 2 + v5v1 = const u64 3 + log u64 v4v1, v5v1 log_data(version: 0, is_event: true, is_indexed: true, event_type_size: 8, num_elements: 2) + v7v1 = const unit () + ret () v7v1 + } +} diff --git a/sway-ir/tests/serialize/mem_copy.ir.snap b/sway-ir/tests/serialize/mem_copy.ir.snap new file mode 100644 index 00000000000..958260ad1fe --- /dev/null +++ b/sway-ir/tests/serialize/mem_copy.ir.snap @@ -0,0 +1,18 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> () { + local b256 addr_a = const b256 0x1111111111111111111111111111111111111111111111111111111111111111 + local b256 addr_b + + entry(): + v1v1 = get_local __ptr b256, addr_a + v2v1 = get_local __ptr b256, addr_b + mem_copy_val v2v1, v1v1 + v4v1 = const unit () + ret () v4v1 + } +} diff --git a/sway-ir/tests/serialize/metadata.ir.snap b/sway-ir/tests/serialize/metadata.ir.snap new file mode 100644 index 00000000000..2af959c11a0 --- /dev/null +++ b/sway-ir/tests/serialize/metadata.ir.snap @@ -0,0 +1,31 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool, !1 { + entry(): + v3v1 = const bool true, !2 + cbr v3v1, block1(v3v1), block0(v3v1), !3 + + block0(v1v1: bool): + v5v1 = call f(), !4 + br block1(v5v1), !3 + + block1(v2v1: bool): + ret bool v2v1 + } + + fn f() -> bool, !4 { + entry(): + v8v1 = const bool false + ret bool v8v1 + } +} + +!0 = "a string\\n" +!1 = !0 +!2 = a_struct !0 11 22 !1 +!3 = (!1 !2) +!4 = 12345 diff --git a/sway-ir/tests/serialize/storage_clear.ir.snap b/sway-ir/tests/serialize/storage_clear.ir.snap new file mode 100644 index 00000000000..00807ee2796 --- /dev/null +++ b/sway-ir/tests/serialize/storage_clear.ir.snap @@ -0,0 +1,20 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> () { + local b256 key_for_x + + entry(): + v1v1 = get_local __ptr b256, key_for_x + v2v1 = const b256 0x7fbd1192666bfac3767b890bd4d048c940879d316071e20c7c8c81bce2ca41c5 + store v2v1 to v1v1 + v4v1 = const u64 1 + v5v1 = state_clear key v1v1, v4v1 + state_clear_slots key v1v1, v4v1 + v7v1 = const unit () + ret () v7v1 + } +} diff --git a/sway-ir/tests/serialize/storage_load.ir.snap b/sway-ir/tests/serialize/storage_load.ir.snap new file mode 100644 index 00000000000..d4eeb0fe0e5 --- /dev/null +++ b/sway-ir/tests/serialize/storage_load.ir.snap @@ -0,0 +1,43 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> () { + local b256 key_for_x + local b256 key_for_y + local u64 value_for_x + local b256 value_for_y + local u64 x + local b256 y + + entry(): + v1v1 = get_local __ptr b256, key_for_x + v2v1 = const b256 0x7fbd1192666bfac3767b890bd4d048c940879d316071e20c7c8c81bce2ca41c5 + store v2v1 to v1v1 + v4v1 = get_local __ptr u64, value_for_x + v5v1 = state_load_word key v1v1, 0 + store v5v1 to v4v1 + v7v1 = get_local __ptr u64, value_for_x + v8v1 = load v7v1 + v9v1 = get_local __ptr u64, x + store v8v1 to v9v1 + v11v1 = get_local __ptr b256, key_for_y + v12v1 = const b256 0xa15d6d36b54df993ed1fbe4544a45d4c4f70d81b4229861dfde0e20eb652202c + store v12v1 to v11v1 + v14v1 = get_local __ptr b256, value_for_y + v15v1 = const u64 1 + v16v1 = state_load_quad_word v14v1, key v11v1, v15v1 + v17v1 = get_local __ptr b256, value_for_y + v18v1 = load v17v1 + v19v1 = get_local __ptr b256, y + store v18v1 to v19v1 + v23v1 = cast_ptr v14v1 to ptr + v21v1 = const u64 0 + v22v1 = const u64 32 + state_read_slot v23v1, key v11v1, v21v1, v22v1 + v25v1 = const unit () + ret () v25v1 + } +} diff --git a/sway-ir/tests/serialize/storage_preload.ir.snap b/sway-ir/tests/serialize/storage_preload.ir.snap new file mode 100644 index 00000000000..c9e8434a67e --- /dev/null +++ b/sway-ir/tests/serialize/storage_preload.ir.snap @@ -0,0 +1,17 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> u64 { + local b256 key_for_x + + entry(): + v1v1 = get_local __ptr b256, key_for_x + v2v1 = const b256 0x7fbd1192666bfac3767b890bd4d048c940879d316071e20c7c8c81bce2ca41c5 + store v2v1 to v1v1 + v4v1 = state_preload key v1v1 + ret u64 v4v1 + } +} diff --git a/sway-ir/tests/serialize/storage_store.ir.snap b/sway-ir/tests/serialize/storage_store.ir.snap new file mode 100644 index 00000000000..44e49deecd9 --- /dev/null +++ b/sway-ir/tests/serialize/storage_store.ir.snap @@ -0,0 +1,38 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +contract { + fn main() -> () { + local b256 key_for_x + local b256 key_for_y + local u64 value_for_x + local b256 value_for_y + + entry(): + v1v1 = get_local __ptr u64, value_for_x + v2v1 = const u64 0 + store v2v1 to v1v1 + v4v1 = get_local __ptr b256, key_for_x + v5v1 = const b256 0x7fbd1192666bfac3767b890bd4d048c940879d316071e20c7c8c81bce2ca41c5 + store v5v1 to v4v1 + v7v1 = const u64 0 + v8v1 = state_store_word v7v1, key v4v1 + v9v1 = get_local __ptr b256, value_for_y + v10v1 = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 + store v10v1 to v9v1 + v12v1 = get_local __ptr b256, key_for_y + v13v1 = const b256 0xa15d6d36b54df993ed1fbe4544a45d4c4f70d81b4229861dfde0e20eb652202c + store v13v1 to v12v1 + v15v1 = get_local __ptr b256, value_for_y + v16v1 = const u64 1 + v17v1 = state_store_quad_word v15v1, key v12v1, v16v1 + v18v1 = cast_ptr v15v1 to ptr + v19v1 = const u64 32 + state_write_slot v18v1, key v12v1, v19v1 + state_update_slot v18v1, key v12v1, v2v1, v19v1 + v22v1 = const unit () + ret () v22v1 + } +} diff --git a/sway-ir/tests/serialize/str_slice.ir.snap b/sway-ir/tests/serialize/str_slice.ir.snap new file mode 100644 index 00000000000..8971c630297 --- /dev/null +++ b/sway-ir/tests/serialize/str_slice.ir.snap @@ -0,0 +1,35 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> slice { + local { u64, u64 } __anon_0 + local slice __anon_1 + local string<3> __anon_2 + local slice a + + entry(): + v2v1 = get_local __ptr string<3>, __anon_2 + v1v1 = const string<3> "abc" + store v1v1 to v2v1 + v4v1 = ptr_to_int v2v1 to u64 + v5v1 = get_local __ptr { u64, u64 }, __anon_0 + v6v1 = const u64 0 + v7v1 = get_elem_ptr v5v1, __ptr u64, v6v1 + store v4v1 to v7v1 + v9v1 = const u64 1 + v10v1 = get_elem_ptr v5v1, __ptr u64, v9v1 + v11v1 = const u64 3 + store v11v1 to v10v1 + v13v1 = get_local __ptr slice, __anon_1 + mem_copy_bytes v13v1, v5v1, 16 + v15v1 = load v13v1 + v16v1 = get_local __ptr slice, a + store v15v1 to v16v1 + v18v1 = get_local __ptr slice, a + v19v1 = load v18v1 + ret slice v19v1 + } +} diff --git a/sway-ir/tests/serialize/test.ir.snap b/sway-ir/tests/serialize/test.ir.snap new file mode 100644 index 00000000000..97bfda4cf56 --- /dev/null +++ b/sway-ir/tests/serialize/test.ir.snap @@ -0,0 +1,24 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> (), !1 { + entry(): + v1v1 = const unit () + ret () v1v1 + } + + fn my_test_func() -> (), !4 { + entry(): + v3v1 = const unit () + ret () v3v1 + } +} + +!0 = "a string\\n" +!1 = span !0 9 21 +!2 = span !0 307 341 +!3 = decl_index 4 +!4 = (!2 !3) diff --git a/sway-ir/tests/serialize/untyped_arg_to_call.ir.snap b/sway-ir/tests/serialize/untyped_arg_to_call.ir.snap new file mode 100644 index 00000000000..81c7b77f924 --- /dev/null +++ b/sway-ir/tests/serialize/untyped_arg_to_call.ir.snap @@ -0,0 +1,20 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool { + entry(): + v1v1 = const bool true + v2v1 = call a(v1v1) + v3v1 = call a(v2v1) + ret bool v3v1 + } + + fn a(x: bool) -> bool { + entry(x: bool): + v6v1 = const bool true + ret bool v6v1 + } +} diff --git a/sway-ir/tests/serialize/wide_ops.ir.snap b/sway-ir/tests/serialize/wide_ops.ir.snap new file mode 100644 index 00000000000..7eccfc039ca --- /dev/null +++ b/sway-ir/tests/serialize/wide_ops.ir.snap @@ -0,0 +1,30 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> () { + local u256 a + + entry(): + v1v1 = get_local __ptr u256, a + wide add v1v1, v1v1 to v1v1 + wide sub v1v1, v1v1 to v1v1 + wide mul v1v1, v1v1 to v1v1 + wide div v1v1, v1v1 to v1v1 + wide mod v1v1, v1v1 to v1v1 + v7v1 = const u64 2 + wide lsh v1v1, v7v1 to v1v1 + wide rsh v1v1, v7v1 to v1v1 + wide not v1v1 to v1v1 + wide and v1v1, v1v1 to v1v1 + wide or v1v1, v1v1 to v1v1 + wide xor v1v1, v1v1 to v1v1 + v14v1 = wide cmp eq v1v1 v1v1 + v15v1 = wide cmp lt v1v1 v1v1 + v16v1 = wide cmp gt v1v1 v1v1 + v17v1 = const unit () + ret () v17v1 + } +} diff --git a/sway-ir/tests/simplify_cfg/dead_blocks.ir.snap b/sway-ir/tests/simplify_cfg/dead_blocks.ir.snap new file mode 100644 index 00000000000..2720557b185 --- /dev/null +++ b/sway-ir/tests/simplify_cfg/dead_blocks.ir.snap @@ -0,0 +1,74 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> u64 { + local u64 x + + entry(): + v3v1 = call foo() + v4v1 = call bar() + v5v1 = call baz() + v6v1 = get_local __ptr u64, x + v7v1 = const u64 11 + store v7v1 to v6v1 +- br block1(v7v1) +- +- block0(v1v1: u64): +- v10v1 = const u64 22 +- store v10v1 to v6v1 +- br block1(v10v1) +- +- block1(v2v1: u64): + v13v1 = const u64 33 + ret u64 v13v1 + } + + fn foo(b: bool) -> bool { + entry(b: bool): + v17v1 = const u64 100 + cbr b, block0(), block1(v17v1) + + block0(): + v19v1 = const u64 333 + br block1(v19v1) + + block1(v16v1: u64): + ret bool b + } + + fn bar(b: bool) -> bool { + entry(b: bool): + v24v1 = const u64 100 + cbr b, block0(), block2(v24v1) + + block0(): +- br block1() +- +- block1(): + v27v1 = const u64 333 + br block2(v27v1) + + block2(v23v1: u64): + ret bool b + } + + fn baz(b: bool) -> bool { + entry(b: bool): + v33v1 = const u64 100 + cbr b, block0(), block2(v33v1) + + block0(): + v35v1 = const u64 11 +- br block1(v35v1) ++ br block2(v35v1) + +- block1(v31v1: u64): +- br block2(v31v1) +- + block2(v32v1: u64): + ret bool b + } +} diff --git a/sway-ir/tests/simplify_cfg/merge_all_blocks.ir.snap b/sway-ir/tests/simplify_cfg/merge_all_blocks.ir.snap new file mode 100644 index 00000000000..86356017a95 --- /dev/null +++ b/sway-ir/tests/simplify_cfg/merge_all_blocks.ir.snap @@ -0,0 +1,28 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + fn main() -> bool { + entry(): + v4v1 = const u64 11 + v5v1 = const u64 0 + v6v1 = cmp eq v4v1 v5v1 +- br block0(v6v1) +- +- block0(v1v1: bool): + v8v1 = const u64 22 + v9v1 = cmp eq v8v1 v5v1 +- br block1(v9v1) +- +- block1(v2v1: bool): + v11v1 = const u64 33 + v12v1 = cmp eq v11v1 v5v1 +- br block2(v12v1) +- +- block2(v3v1: bool): +- ret bool v3v1 ++ ret bool v12v1 + } +} diff --git a/sway-ir/tests/sroa/nested_struct_array.ir.snap b/sway-ir/tests/sroa/nested_struct_array.ir.snap new file mode 100644 index 00000000000..39abaf3e6b8 --- /dev/null +++ b/sway-ir/tests/sroa/nested_struct_array.ir.snap @@ -0,0 +1,156 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64, !1 { + local [u64; 4] __anon_0 +- local { u64, u64 } __anon_1 + local { u64, u64, [u64; 4], { u64, u64 } } __anon_2 + + entry(): + v1v1 = get_local __ptr [u64; 4], __anon_0, !2 + v2v1 = const u64 0 + v3v1 = get_elem_ptr v1v1, __ptr u64, v2v1 + v4v1 = const u64 0, !3 + store v4v1 to v3v1, !2 + v6v1 = const u64 1 + v7v1 = get_elem_ptr v1v1, __ptr u64, v6v1 + v8v1 = const u64 1, !4 + store v8v1 to v7v1, !2 + v10v1 = const u64 2 + v11v1 = get_elem_ptr v1v1, __ptr u64, v10v1 + v12v1 = const u64 2, !5 + store v12v1 to v11v1, !2 + v14v1 = const u64 3 + v15v1 = get_elem_ptr v1v1, __ptr u64, v14v1 + v16v1 = const u64 3, !6 + store v16v1 to v15v1, !2 +- v18v1 = get_local __ptr { u64, u64 }, __anon_1, !7 +- v19v1 = const u64 0 +- v20v1 = get_elem_ptr v18v1, __ptr u64, v19v1 +- v21v1 = const u64 199, !8 +- store v21v1 to v20v1, !7 +- v23v1 = const u64 1 +- v24v1 = get_elem_ptr v18v1, __ptr u64, v23v1 +- v25v1 = const u64 200, !9 +- store v25v1 to v24v1, !7 +- v27v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !10 ++ v27v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !7 + v28v1 = const u64 0 + v29v1 = get_elem_ptr v27v1, __ptr u64, v28v1 +- v30v1 = const u64 2, !11 +- store v30v1 to v29v1, !10 ++ v30v1 = const u64 2, !8 ++ store v30v1 to v29v1, !7 + v32v1 = const u64 1 + v33v1 = get_elem_ptr v27v1, __ptr u64, v32v1 +- v34v1 = const u64 3, !12 +- store v34v1 to v33v1, !10 ++ v34v1 = const u64 3, !9 ++ store v34v1 to v33v1, !7 + v36v1 = const u64 2 + v37v1 = get_elem_ptr v27v1, __ptr [u64; 4], v36v1 + mem_copy_val v37v1, v1v1 + v39v1 = const u64 3 + v40v1 = get_elem_ptr v27v1, __ptr { u64, u64 }, v39v1 +- mem_copy_val v40v1, v18v1 +- v42v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !13 ++ v74v1 = const u64 0 ++ v75v1 = get_elem_ptr v40v1, __ptr u64, v74v1 ++ v21v1 = const u64 199, !10 ++ store v21v1 to v75v1 ++ v77v1 = const u64 1 ++ v78v1 = get_elem_ptr v40v1, __ptr u64, v77v1 ++ v25v1 = const u64 200, !11 ++ store v25v1 to v78v1 ++ v42v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !12 + v43v1 = const u64 0 +- v44v1 = get_elem_ptr v42v1, __ptr u64, v43v1, !14 ++ v44v1 = get_elem_ptr v42v1, __ptr u64, v43v1, !13 + v45v1 = load v44v1 +- v46v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !15 ++ v46v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !14 + v47v1 = const u64 3 +- v48v1 = get_elem_ptr v46v1, __ptr { u64, u64 }, v47v1, !16 ++ v48v1 = get_elem_ptr v46v1, __ptr { u64, u64 }, v47v1, !15 + v49v1 = const u64 0 +- v50v1 = get_elem_ptr v48v1, __ptr u64, v49v1, !17 ++ v50v1 = get_elem_ptr v48v1, __ptr u64, v49v1, !16 + v51v1 = load v50v1 +- v52v1 = add v45v1, v51v1, !18 +- v53v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !19 ++ v52v1 = add v45v1, v51v1, !17 ++ v53v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !18 + v54v1 = const u64 3 +- v55v1 = get_elem_ptr v53v1, __ptr { u64, u64 }, v54v1, !16 ++ v55v1 = get_elem_ptr v53v1, __ptr { u64, u64 }, v54v1, !15 + v56v1 = const u64 1 +- v57v1 = get_elem_ptr v55v1, __ptr u64, v56v1, !20 ++ v57v1 = get_elem_ptr v55v1, __ptr u64, v56v1, !19 + v58v1 = load v57v1 +- v59v1 = add v52v1, v58v1, !21 +- v60v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !22 ++ v59v1 = add v52v1, v58v1, !20 ++ v60v1 = get_local __ptr { u64, u64, [u64; 4], { u64, u64 } }, __anon_2, !21 + v61v1 = const u64 2 +- v62v1 = get_elem_ptr v60v1, __ptr [u64; 4], v61v1, !23 +- v63v1 = const u64 1, !24 +- v64v1 = get_elem_ptr v62v1, __ptr u64, v63v1, !25 ++ v62v1 = get_elem_ptr v60v1, __ptr [u64; 4], v61v1, !22 ++ v63v1 = const u64 1, !23 ++ v64v1 = get_elem_ptr v62v1, __ptr u64, v63v1, !24 + v65v1 = load v64v1 +- v66v1 = add v59v1, v65v1, !26 ++ v66v1 = add v59v1, v65v1, !25 + ret u64 v66v1 + } +} + +!0 = "src/main.sw" +!1 = span !0 100 262 +!2 = span !0 174 186 +!3 = span !0 175 176 +!4 = span !0 178 179 +!5 = span !0 181 182 +!6 = span !0 184 185 +- !7 = span !0 199 220 +- !8 = span !0 206 209 +- !9 = span !0 215 218 +- !10 = span !0 130 226 +- !11 = span !0 146 147 +- !12 = span !0 160 161 +- !13 = span !0 232 233 +- !14 = span !0 56 62 +- !15 = span !0 238 239 +- !16 = span !0 91 95 +- !17 = span !0 22 28 +- !18 = span !0 232 243 +- !19 = span !0 246 247 +- !20 = span !0 32 38 +- !21 = span !0 232 251 +- !22 = span !0 254 255 +- !23 = span !0 76 87 +- !24 = span !0 258 259 +- !25 = span !0 254 260 +- !26 = span !0 232 260 ++ !7 = span !0 130 226 ++ !8 = span !0 146 147 ++ !9 = span !0 160 161 ++ !10 = span !0 206 209 ++ !11 = span !0 215 218 ++ !12 = span !0 232 233 ++ !13 = span !0 56 62 ++ !14 = span !0 238 239 ++ !15 = span !0 91 95 ++ !16 = span !0 22 28 ++ !17 = span !0 232 243 ++ !18 = span !0 246 247 ++ !19 = span !0 32 38 ++ !20 = span !0 232 251 ++ !21 = span !0 254 255 ++ !22 = span !0 76 87 ++ !23 = span !0 258 259 ++ !24 = span !0 254 260 ++ !25 = span !0 232 260 diff --git a/sway-ir/tests/sroa/struct_unused_field.ir.snap b/sway-ir/tests/sroa/struct_unused_field.ir.snap new file mode 100644 index 00000000000..337a204533d --- /dev/null +++ b/sway-ir/tests/sroa/struct_unused_field.ir.snap @@ -0,0 +1,37 @@ +--- +source: sway-ir/tests/tests.rs +--- +Modified: true + +script { + entry fn main() -> u64, !1 { +- local { u64, u64 } __anon_0 +- + entry(): +- v1v1 = get_local __ptr { u64, u64 }, __anon_0, !2 +- v2v1 = const u64 0 +- v3v1 = get_elem_ptr v1v1, __ptr u64, v2v1 +- v4v1 = const u64 2, !3 +- store v4v1 to v3v1, !2 +- v6v1 = const u64 1 +- v7v1 = get_elem_ptr v1v1, __ptr u64, v6v1 +- v8v1 = const u64 3, !4 +- store v8v1 to v7v1, !2 +- v10v1 = get_local __ptr { u64, u64 }, __anon_0, !5 +- v11v1 = const u64 0 +- v12v1 = get_elem_ptr v10v1, __ptr u64, v11v1, !6 +- v13v1 = load v12v1 +- ret u64 v13v1 ++ v4v1 = const u64 2, !2 ++ ret u64 v4v1 + } +} + +!0 = "test/src/main.sw" +!1 = span !0 43 122 +- !2 = span !0 73 111 +- !3 = span !0 89 90 +- !4 = span !0 103 104 +- !5 = span !0 117 118 +- !6 = span !0 22 28 ++ !2 = span !0 89 90 diff --git a/sway-ir/tests/tests.rs b/sway-ir/tests/tests.rs index 2ede1eb7358..a667bebafc3 100644 --- a/sway-ir/tests/tests.rs +++ b/sway-ir/tests/tests.rs @@ -1,4 +1,7 @@ -use std::path::PathBuf; +use std::{ + panic::catch_unwind, + path::{Path, PathBuf}, +}; use itertools::Itertools; use sway_features::ExperimentalFeatures; @@ -18,6 +21,47 @@ use sway_types::SourceEngine; // ------------------------------------------------------------------------------------------------- // Utility for finding test files and running FileCheck. See actual pass invocations below. +fn clean_output(output: &str) -> String { + #[derive(Default)] + struct RawText(String); + + impl vte::Perform for RawText { + fn print(&mut self, c: char) { + self.0.push(c); + } + + fn execute(&mut self, _: u8) {} + + fn hook(&mut self, _: &vte::Params, _: &[u8], _: bool, _: char) {} + + fn put(&mut self, b: u8) { + self.0.push(b as char); + } + + fn unhook(&mut self) {} + + fn osc_dispatch(&mut self, _: &[&[u8]], _: bool) {} + + fn csi_dispatch(&mut self, _: &vte::Params, _: &[u8], _: bool, _: char) {} + + fn esc_dispatch(&mut self, _: &[u8], _: bool, _: u8) {} + } + + let mut raw = String::new(); + for line in output.lines() { + let mut performer = RawText::default(); + let mut p = vte::Parser::new(); + for b in line.as_bytes() { + p.advance(&mut performer, *b); + } + raw.push_str(&performer.0); + raw.push('\n'); + } + + let result = raw; + result.to_string() +} + fn run_tests bool>(sub_dir: &str, opt_fn: F) { let source_engine = SourceEngine::default(); let manifest_dir = env!("CARGO_MANIFEST_DIR"); @@ -25,6 +69,11 @@ fn run_tests bool>(sub_dir: &str, opt_fn: F) { for entry in std::fs::read_dir(dir).unwrap() { let path = entry.unwrap().path(); + let ext = path.extension().unwrap().to_str().unwrap(); + if ext != "ir" { + continue; + } + let input_bytes = std::fs::read(&path).unwrap(); let input = String::from_utf8_lossy(&input_bytes); @@ -45,9 +94,69 @@ fn run_tests bool>(sub_dir: &str, opt_fn: F) { let first_line = input.split('\n').next().unwrap(); - // The tests should return true, indicating they made modifications. + let before = ir.to_string(); + let r = opt_fn(first_line, &mut ir); + let after = ir.to_string(); + + fn run_insta(file: &Path, snapshot: String) { + let root = file.parent().unwrap(); + let test_name = file.file_name().unwrap().to_str().unwrap(); + + let mut insta = insta::Settings::new(); + insta.set_snapshot_path(root); + insta.set_prepend_module_to_snapshot(false); + insta.set_omit_expression(true); + + let scope = insta.bind_to_scope(); + + let _ = catch_unwind(|| { + insta::assert_snapshot!(test_name, snapshot); + }); + drop(scope); + } + + let mut snapshot = String::new(); + snapshot.push_str(&format!("Modified: {}\n\n", r)); + for diff in prettydiff::diff_lines(&before, &after).diff() { + match diff { + prettydiff::basic::DiffOp::Insert(lines) => { + for line in lines { + snapshot.push_str("+ "); + snapshot.push_str(line); + snapshot.push_str("\n"); + } + } + prettydiff::basic::DiffOp::Replace(removed, inserted) => { + for line in removed { + snapshot.push_str("- "); + snapshot.push_str(line); + snapshot.push_str("\n"); + } + for line in inserted { + snapshot.push_str("+ "); + snapshot.push_str(line); + snapshot.push_str("\n"); + } + } + prettydiff::basic::DiffOp::Remove(removed) => { + for line in removed { + snapshot.push_str("- "); + snapshot.push_str(line); + snapshot.push_str("\n"); + } + } + prettydiff::basic::DiffOp::Equal(lines) => { + for line in lines { + snapshot.push_str(line); + snapshot.push_str("\n"); + } + } + } + } + run_insta(&path, clean_output(&snapshot)); + assert!( - opt_fn(first_line, &mut ir), + r, "Pass returned false (no changes made to {}).", path.display() ); From ba4564318e21c3a2a73ee3e6263e870bc77b3893 Mon Sep 17 00:00:00 2001 From: xunilrj Date: Thu, 11 Jun 2026 16:53:47 -0300 Subject: [PATCH 3/4] fmt and clippy issues --- sway-ir/tests/tests.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sway-ir/tests/tests.rs b/sway-ir/tests/tests.rs index a667bebafc3..acd491875d8 100644 --- a/sway-ir/tests/tests.rs +++ b/sway-ir/tests/tests.rs @@ -123,32 +123,32 @@ fn run_tests bool>(sub_dir: &str, opt_fn: F) { for line in lines { snapshot.push_str("+ "); snapshot.push_str(line); - snapshot.push_str("\n"); + snapshot.push('\n'); } } prettydiff::basic::DiffOp::Replace(removed, inserted) => { for line in removed { snapshot.push_str("- "); snapshot.push_str(line); - snapshot.push_str("\n"); + snapshot.push('\n'); } for line in inserted { snapshot.push_str("+ "); snapshot.push_str(line); - snapshot.push_str("\n"); + snapshot.push('\n'); } } prettydiff::basic::DiffOp::Remove(removed) => { for line in removed { snapshot.push_str("- "); snapshot.push_str(line); - snapshot.push_str("\n"); + snapshot.push('\n'); } } prettydiff::basic::DiffOp::Equal(lines) => { for line in lines { snapshot.push_str(line); - snapshot.push_str("\n"); + snapshot.push('\n'); } } } From 82291d89625362672ed39a915c5ee87e3baabdfa Mon Sep 17 00:00:00 2001 From: xunilrj Date: Thu, 11 Jun 2026 16:54:37 -0300 Subject: [PATCH 4/4] lint cargo.toml --- sway-ir/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway-ir/Cargo.toml b/sway-ir/Cargo.toml index 5433776c137..7f2982d262f 100644 --- a/sway-ir/Cargo.toml +++ b/sway-ir/Cargo.toml @@ -26,8 +26,8 @@ sway-types.workspace = true sway-utils.workspace = true [dev-dependencies] -vte.workspace = true insta.workspace = true +vte.workspace = true [lints] workspace = true