From 45f6387456d8a64717faf5c83f5d79b9b32010ea Mon Sep 17 00:00:00 2001 From: Vineeth Kashyap Date: Fri, 13 Dec 2024 17:53:13 -0500 Subject: [PATCH] [compiler-v2] Experimental flush writes, second take --- .../function_generator.rs | 67 +- .../src/pipeline/dead_store_elimination.rs | 33 +- .../src/pipeline/flush_writes_processor.rs | 459 ++++++++++---- .../ability-transform/destroy_after_call.exp | 4 +- .../foreach_mut_expanded.exp | 7 +- .../bytecode-generator/conditional_borrow.exp | 56 +- .../tests/bytecode-generator/fields.exp | 7 +- .../bytecode-generator/freeze_mut_ref.exp | 37 +- .../tests/bytecode-generator/inline_specs.exp | 16 +- .../tests/bytecode-generator/pack_unpack.exp | 2 + .../eager-pushes/framework_reduced_06.exp | 4 +- .../eager-pushes/framework_reduced_07.exp | 4 +- .../eager-pushes/framework_reduced_08.exp | 4 +- .../eager-pushes/framework_reduced_09.exp | 4 +- .../framework_reduced_06.opt.exp | 25 +- .../file-format-generator/opt_load_05.opt.exp | 1 - .../file-format-generator/pack_unpack.opt.exp | 2 + .../struct_variants.opt.exp | 2 + .../tests/flush-writes/def_use_01.on.exp | 6 +- .../tests/flush-writes/def_use_02.on.exp | 6 +- .../tests/flush-writes/def_use_05.on.exp | 3 +- .../tests/flush-writes/def_use_08.on.exp | 10 +- .../flush-writes/framework_reduced_11.move | 17 + .../flush-writes/framework_reduced_11.off.exp | 58 ++ .../flush-writes/framework_reduced_11.on.exp | 142 +++++ .../flush-writes/framework_reduced_12.move | 57 ++ .../flush-writes/framework_reduced_12.off.exp | 112 ++++ .../flush-writes/framework_reduced_12.on.exp | 261 ++++++++ .../flush-writes/in_order_use_01.off.exp | 7 + .../tests/flush-writes/in_order_use_01.on.exp | 23 +- .../tests/flush-writes/in_order_use_02.move | 12 + .../flush-writes/in_order_use_02.off.exp | 32 + .../tests/flush-writes/in_order_use_02.on.exp | 90 +++ .../tests/flush-writes/in_order_use_03.move | 20 + .../flush-writes/in_order_use_03.off.exp | 39 ++ .../tests/flush-writes/in_order_use_03.on.exp | 105 ++++ .../tests/flush-writes/in_order_use_04.move | 20 + .../flush-writes/in_order_use_04.off.exp | 44 ++ .../tests/flush-writes/in_order_use_04.on.exp | 124 ++++ .../tests/flush-writes/in_order_use_05.move | 16 + .../flush-writes/in_order_use_05.off.exp | 31 + .../tests/flush-writes/in_order_use_05.on.exp | 78 +++ .../tests/flush-writes/loop_01.off.exp | 1 - .../tests/flush-writes/loop_01.on.exp | 24 +- .../flush-writes/out_of_order_use_01.on.exp | 22 +- .../flush-writes/out_of_order_use_02.on.exp | 8 +- .../flush-writes/out_of_order_use_03.on.exp | 8 +- .../flush-writes/out_of_order_use_04.on.exp | 6 +- .../flush-writes/out_of_order_use_05.move | 12 + .../flush-writes/out_of_order_use_05.off.exp | 46 ++ .../flush-writes/out_of_order_use_05.on.exp | 80 +++ .../flush-writes/out_of_order_use_06.move | 17 + .../flush-writes/out_of_order_use_06.off.exp | 61 ++ .../flush-writes/out_of_order_use_06.on.exp | 125 ++++ .../flush-writes/out_of_order_use_07.move | 20 + .../flush-writes/out_of_order_use_07.off.exp | 43 ++ .../flush-writes/out_of_order_use_07.on.exp | 109 ++++ .../flush-writes/out_of_order_use_08.move | 20 + .../flush-writes/out_of_order_use_08.off.exp | 48 ++ .../flush-writes/out_of_order_use_08.on.exp | 128 ++++ .../flush-writes/out_of_order_use_09.move | 20 + .../flush-writes/out_of_order_use_09.off.exp | 49 ++ .../flush-writes/out_of_order_use_09.on.exp | 108 ++++ .../flush-writes/out_of_order_use_10.move | 17 + .../flush-writes/out_of_order_use_10.off.exp | 37 ++ .../flush-writes/out_of_order_use_10.on.exp | 84 +++ .../flush-writes/out_of_order_use_11.move | 14 + .../flush-writes/out_of_order_use_11.off.exp | 31 + .../flush-writes/out_of_order_use_11.on.exp | 77 +++ .../flush-writes/out_of_order_use_12.move | 16 + .../flush-writes/out_of_order_use_12.off.exp | 40 ++ .../flush-writes/out_of_order_use_12.on.exp | 90 +++ .../flush-writes/out_of_order_use_13.move | 17 + .../flush-writes/out_of_order_use_13.off.exp | 35 ++ .../flush-writes/out_of_order_use_13.on.exp | 84 +++ .../flush-writes/out_of_order_use_14.move | 16 + .../flush-writes/out_of_order_use_14.off.exp | 36 ++ .../flush-writes/out_of_order_use_14.on.exp | 79 +++ .../flush-writes/out_of_order_use_15.move | 16 + .../flush-writes/out_of_order_use_15.off.exp | 32 + .../flush-writes/out_of_order_use_15.on.exp | 77 +++ .../flush-writes/tuples_in_order_use_01.move | 12 + .../tuples_in_order_use_01.off.exp | 32 + .../tuples_in_order_use_01.on.exp | 90 +++ .../flush-writes/unused_flush_early_01.on.exp | 16 +- .../unused_flush_early_02.off.exp | 17 +- .../flush-writes/unused_flush_early_02.on.exp | 22 +- .../unused_flush_early_03.off.exp | 9 +- .../flush-writes/unused_flush_early_03.on.exp | 56 +- .../tests/flush-writes/write_ref_01.on.exp | 9 +- .../tests/variable-coalescing/branch_1.exp | 23 +- .../variable-coalescing/branch_1.opt.exp | 23 +- .../tests/variable-coalescing/call_1.exp | 8 +- .../tests/variable-coalescing/call_1.opt.exp | 8 +- .../tests/variable-coalescing/call_2.exp | 13 +- .../tests/variable-coalescing/call_2.opt.exp | 13 +- .../cant_copy_propagate.exp | 21 +- .../cant_copy_propagate.opt.exp | 21 +- .../tests/variable-coalescing/consume_2.exp | 10 +- .../variable-coalescing/consume_2.opt.exp | 10 +- .../variable-coalescing/dead_assignment_1.exp | 3 +- .../dead_assignment_1.opt.exp | 3 +- .../variable-coalescing/dead_assignment_2.exp | 3 +- .../dead_assignment_2.opt.exp | 3 +- .../variable-coalescing/dead_assignment_4.exp | 3 +- .../dead_assignment_4.opt.exp | 3 +- .../variable-coalescing/intermingled_1.exp | 10 +- .../intermingled_1.opt.exp | 9 +- .../variable-coalescing/intermingled_2.exp | 18 +- .../variable-coalescing/intermingled_3.exp | 16 +- .../intermingled_3.opt.exp | 9 +- .../tests/variable-coalescing/loop_1.exp | 3 +- .../tests/variable-coalescing/loop_1.opt.exp | 3 +- .../tests/variable-coalescing/loop_2.exp | 3 +- .../tests/variable-coalescing/loop_2.opt.exp | 3 +- .../tests/variable-coalescing/mut_refs_1.exp | 7 +- .../variable-coalescing/mut_refs_1.opt.exp | 7 +- .../tests/variable-coalescing/mut_refs_2.exp | 7 +- .../variable-coalescing/mut_refs_2.opt.exp | 7 +- .../non_overlapping_vars1.exp | 14 +- .../non_overlapping_vars1.opt.exp | 14 +- .../non_overlapping_vars_diff_type.exp | 14 +- .../non_overlapping_vars_diff_type.opt.exp | 14 +- .../variable-coalescing/overlapping_vars.exp | 9 +- .../variable-coalescing/reassigned_var.exp | 5 +- .../reassigned_var.opt.exp | 7 +- .../variable-coalescing/self_assigns.exp | 9 +- .../variable-coalescing/self_assigns.opt.exp | 9 +- .../tests/variable-coalescing/seq_kills_1.exp | 5 +- .../variable-coalescing/seq_kills_1.opt.exp | 5 +- .../tests/variable-coalescing/seq_kills_2.exp | 5 +- .../variable-coalescing/seq_kills_2.opt.exp | 5 +- .../sequential_assign_struct.exp | 3 +- .../sequential_assign_struct.opt.exp | 3 +- .../simple_sequential_assign.exp | 3 +- .../simple_sequential_assign.opt.exp | 3 +- .../straight_line_kills.exp | 5 +- .../straight_line_kills.opt.exp | 5 +- .../tests/variable-coalescing/swap.exp | 13 +- .../tests/variable-coalescing/swap.opt.exp | 13 +- .../variable-coalescing/swap_in_a_loop.exp | 3 +- .../swap_in_a_loop.opt.exp | 3 +- .../tests/variable-coalescing/unused_add.exp | 7 +- .../src/source_map.rs | 4 +- .../tests/bit_vector_loop_example.exp | 591 +++++++++--------- .../tests/sources/functional/enum.v2_exp | 2 +- .../tests/sources/functional/enum_self.v2_exp | 2 +- .../sources/functional/invariants.v2_exp | 2 +- .../tests/sources/functional/mut_ref.v2_exp | 2 +- .../sources/functional/strong_edges.v2_exp | 2 +- .../move-decompiler/tests/simple_map.exp | 8 +- 151 files changed, 4252 insertions(+), 870 deletions(-) create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.on.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.move create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.off.exp create mode 100644 third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.on.exp diff --git a/third_party/move/move-compiler-v2/src/file_format_generator/function_generator.rs b/third_party/move/move-compiler-v2/src/file_format_generator/function_generator.rs index 904e88de4914b..0a8bd83507019 100644 --- a/third_party/move/move-compiler-v2/src/file_format_generator/function_generator.rs +++ b/third_party/move/move-compiler-v2/src/file_format_generator/function_generator.rs @@ -151,27 +151,24 @@ impl<'a> FunctionGenerator<'a> { type_parameters: fun_env.get_type_parameters(), def_idx, }); - if fun_gen.spec_blocks.is_empty() { - // Currently, peephole optimizations require that there are no inline spec blocks. - // This is to ensure that spec-related data structures do not refer to code - // offsets which could be changed by the peephole optimizer. - let options = ctx - .env - .get_extension::() - .expect("Options is available"); - if options.experiment_on(Experiment::PEEPHOLE_OPTIMIZATION) { - let transformed_code_chunk = peephole_optimizer::optimize(&code.code); - // Fix the source map for the optimized code. - fun_gen - .gen - .source_map - .remap_code_map(def_idx, transformed_code_chunk.original_offsets) - .expect(SOURCE_MAP_OK); - // Replace the code with the optimized one. - code.code = transformed_code_chunk.code; - } - } else { - // Write the spec block table back to the environment. + let options = ctx + .env + .get_extension::() + .expect("Options is available"); + if options.experiment_on(Experiment::PEEPHOLE_OPTIMIZATION) { + let transformed_code_chunk = peephole_optimizer::optimize(&code.code); + // Fix the source map for the optimized code. + fun_gen + .gen + .source_map + .remap_code_map(def_idx, &transformed_code_chunk.original_offsets) + .expect(SOURCE_MAP_OK); + // Replace the code with the optimized one. + code.code = transformed_code_chunk.code; + // Remap the spec blocks to the new code offsets. + fun_gen.remap_spec_blocks(&transformed_code_chunk.original_offsets); + } + if !fun_gen.spec_blocks.is_empty() { fun_env.get_mut_spec().on_impl = fun_gen.spec_blocks; } (fun_gen.gen, Some(code)) @@ -913,6 +910,34 @@ impl<'a> FunctionGenerator<'a> { self.emit(FF::Bytecode::Nop) } + /// Remap the spec blocks, given the mapping of new offsets to original offsets. + fn remap_spec_blocks(&mut self, new_to_original_offsets: &[CodeOffset]) { + if new_to_original_offsets.is_empty() { + return; + } + let old_to_new = new_to_original_offsets + .iter() + .enumerate() + .map(|(new_offset, old_offset)| (*old_offset, new_offset as CodeOffset)) + .collect::>(); + let largest_offset = (new_to_original_offsets.len() - 1) as CodeOffset; + + // Rewrite the spec blocks mapping. + self.spec_blocks = std::mem::take(&mut self.spec_blocks) + .into_iter() + .map(|(old_offset, spec)| { + // If there is no mapping found for the old offset, then we use the next largest + // offset. If there is no such offset, then we use the overall largest offset. + let new_offset = old_to_new + .range(old_offset..) + .next() + .map(|(_, v)| *v) + .unwrap_or(largest_offset); + (new_offset, spec) + }) + .collect::>(); + } + /// Emits a file-format bytecode. fn emit(&mut self, bc: FF::Bytecode) { self.code.push(bc) diff --git a/third_party/move/move-compiler-v2/src/pipeline/dead_store_elimination.rs b/third_party/move/move-compiler-v2/src/pipeline/dead_store_elimination.rs index 62d336cf064cb..58a2e06d60392 100644 --- a/third_party/move/move-compiler-v2/src/pipeline/dead_store_elimination.rs +++ b/third_party/move/move-compiler-v2/src/pipeline/dead_store_elimination.rs @@ -24,7 +24,6 @@ use move_stackless_bytecode::{ function_target::{FunctionData, FunctionTarget}, function_target_pipeline::{FunctionTargetProcessor, FunctionTargetsHolder}, stackless_bytecode::Bytecode, - stackless_control_flow_graph::StacklessControlFlowGraph, }; use std::collections::{BTreeMap, BTreeSet}; @@ -81,7 +80,6 @@ impl ReducedDefUseGraph { eliminate_all_self_assigns: bool, ) -> BTreeSet { let code = target.get_bytecode(); - let cfg = StacklessControlFlowGraph::new_forward(code); let live_vars = target .get_annotations() .get::() @@ -113,7 +111,6 @@ impl ReducedDefUseGraph { let eliminate_this_self_assign = Self::should_eliminate_given_self_assign( self_assign, code, - &cfg, live_vars, eliminate_all_self_assigns, ); @@ -232,27 +229,29 @@ impl ReducedDefUseGraph { /// Should `self_assign` be eliminated? fn should_eliminate_given_self_assign( - self_assign: CodeOffset, + self_assign_offset: CodeOffset, code: &[Bytecode], - cfg: &StacklessControlFlowGraph, live_vars: &LiveVarAnnotation, eliminate_all_self_assigns: bool, ) -> bool { if !eliminate_all_self_assigns { - // Eliminate this self assign if the definition for this self-assign is in the same block - // before the self assign. - let block = cfg.enclosing_block(self_assign); - let block_begin_offset = cfg.code_range(block).start; - let self_assign_instr = &code[self_assign as usize]; + // Eliminate this self assign if each of its uses are the last sources of their instructions. + let self_assign_instr = &code[self_assign_offset as usize]; let self_assign_temp = self_assign_instr.dests()[0]; - // Is `self_assign_temp` live before this block? - let info = live_vars - .get_info_at(block_begin_offset as CodeOffset) - .before + let live_info_after = live_vars + .get_info_at(self_assign_offset) + .after .get(&self_assign_temp); - match info { - None => true, // must be defined in the block - Some(live) => !live.usage_offsets().contains(&self_assign), + match live_info_after { + None => true, + Some(live) => live.usage_offsets().iter().all(|use_offset| { + let use_instr = &code[*use_offset as usize]; + let sources = use_instr.sources(); + sources + .iter() + .position(|source| *source == self_assign_temp) + .is_some_and(|pos| pos == sources.len() - 1) + }), } } else { true diff --git a/third_party/move/move-compiler-v2/src/pipeline/flush_writes_processor.rs b/third_party/move/move-compiler-v2/src/pipeline/flush_writes_processor.rs index 23c748713d8be..f2f9a93d57507 100644 --- a/third_party/move/move-compiler-v2/src/pipeline/flush_writes_processor.rs +++ b/third_party/move/move-compiler-v2/src/pipeline/flush_writes_processor.rs @@ -28,7 +28,7 @@ //! getting consumed anyway at the end of the block. //! 2. Used multiple times. Before getting consumed, these have to be flushed to local //! memory anyway. -//! 3. Used in the wrong order in an instruction, than they are put on the stack. +//! 3. Used in the wrong order than they are put on the stack. //! In such a case, they would be flushed before getting consumed anyway. //! For example, in the code below: //! ```move @@ -54,7 +54,7 @@ use move_stackless_bytecode::{ }; use std::{ collections::{BTreeMap, BTreeSet}, - ops::RangeInclusive, + ops::{Range, RangeInclusive}, }; /// For a given code offset, tracks which temporaries written at the code offset @@ -207,36 +207,50 @@ impl FlushWritesProcessor { flush_writes: &mut BTreeMap>, ) { let upper = *block_range.end(); - // Traverse the block in reverse order: for each definition starting from the - // latest in a block, we compute whether is should be flushed away. This - // information is available for subsequent definitions processed. - for offset in block_range.rev() { + for offset in block_range.clone() { let instr = &code[offset as usize]; use Bytecode::{Assign, Call, Load}; // Only `Assign`, `Call`, and `Load` instructions push temps to the stack. // We need to find if any of these temps are better flushed right away. if matches!(instr, Assign(..) | Call(..) | Load(..)) { - for (dest_index, dest) in instr.dests().into_iter().enumerate().rev() { + for (dest_index, dest) in instr.dests().into_iter().enumerate() { let def = DefOrUsePoint { offset, index: dest_index, }; - if Self::could_flush_right_away(def, upper, code, use_def_links, flush_writes) { + if Self::better_flushed_right_away(def, upper, use_def_links) { flush_writes.entry(offset).or_default().insert(dest); } } } } + // We have identified some of the temps that are better flushed right away. + // We identity more based on their usage order below. + for offset in block_range.clone() { + Self::process_out_of_order_uses_in_same_instruction( + code, + offset, + *block_range.start(), + use_def_links, + flush_writes, + ); + Self::process_out_of_order_uses_in_different_instructions( + code, + offset, + *block_range.start(), + use_def_links, + flush_writes, + ); + } } /// Is the `def` better flushed right away? + /// If there more than one use or the use is outside the block, then it is better flushed right away. /// `block_end` is the end of the block that has `def`. - fn could_flush_right_away( + fn better_flushed_right_away( def: DefOrUsePoint, block_end: CodeOffset, - code: &[Bytecode], use_def_links: &UseDefLinks, - flush_writes: &BTreeMap>, ) -> bool { use_def_links.def_to_use.get(&def).map_or(true, |uses| { let exactly_one_use = uses.len() == 1; @@ -250,78 +264,298 @@ impl FlushWritesProcessor { // If used outside the basic block, flush right away. return true; } - // If has intervening definitions, flush right away. - // The first call checks the definitions of preceding uses in the same instruction. - // The second call checks definitions between `def` and `use_`. - Self::has_intervening_def(&def, use_, use_def_links) - || Self::has_flush_causing_defs_in_between( - &def, - use_, - code, - use_def_links, - flush_writes, - ) + false }) } - /// Given the `use_` of `def`, is there a previous use of any temp at the same - /// instruction as `use_`, which has a definition after `def` and before - /// the `use_` instruction? - fn has_intervening_def( - def: &DefOrUsePoint, - use_: &DefOrUsePoint, + /// Given an instruction at `offset` of `code`, check if there are uses of temporaries in the + /// wrong order, and if so, mark the corresponding temporaries for flushing. + /// `block_start` is the start of the block that has the instruction at `offset`. + /// + /// Example of a wrong order use in the same instruction: + /// ```move + /// let a = some_integer(); // stack: [`a`] + /// let b = some_integer(); // stack: [`a`, `b`] + /// let c = some_integer(); // stack: [`a`, `b`, `c`] + /// let d = some_integer(); // stack: [`a`, `b`, `c`, `d`] + /// consume(a, c, b, d); + /// ``` + /// In the above code, the stack should be [`a`, `c`, `b`, `d`] before the `consume` call. + /// However, as it stands, the stack is [`a`, `b`, `c`, `d`]. Thus, the top 3 temps on the + /// stack have to be flushed and re-loaded in the right order. + /// Instead, because we know the (`c`, `b`) pair is used in the wrong order, we can flush `b` + /// right away. With this, we only flush and re-load one temp instead of three. This function + /// accomplishes this behavior by marking `b` for flushing right away. + fn process_out_of_order_uses_in_same_instruction( + code: &[Bytecode], + offset: CodeOffset, + block_start: CodeOffset, use_def_links: &UseDefLinks, - ) -> bool { - let DefOrUsePoint { - offset: use_offset, - index: use_index, - } = use_; - (0..*use_index).any(|prev| { - let prev_use_at_usage_instr = DefOrUsePoint { - offset: *use_offset, - index: prev, - }; - use_def_links - .use_to_def - .get(&prev_use_at_usage_instr) - .map_or(false, |defs| { - defs.iter().any(|defs_of_prev_use| { - defs_of_prev_use > def && defs_of_prev_use.offset < *use_offset - }) - }) - }) + flush_writes: &mut BTreeMap>, + ) { + let instr = &code[offset as usize]; + // We are only interested in `Call` and `Ret` instructions, which have multiple sources, + // and therefore can have uses in the wrong order compared to their definitions. + if !matches!(instr, Bytecode::Call(..) | Bytecode::Ret(..)) { + return; + } + let offset_range = block_start..offset; + let sources = instr.sources(); + for pair in (0..sources.len()).combinations(2) { + Self::flush_out_of_order_uses_in_same_instruction( + pair[0], + pair[1], + offset, + code, + use_def_links, + &offset_range, + &sources, + flush_writes, + ); + } } - /// Check for various conditions where between a `def` and its `use_`, there are other - /// definitions that could cause `def` to be flushed before its `use_`. - fn has_flush_causing_defs_in_between( - def: &DefOrUsePoint, - use_: &DefOrUsePoint, + /// Given two use indices `use_index_1` and `use_index_2` in the same instruction, such that + /// `use_index_1 < use_index_2`, check if the uses are in the wrong order compared to their + /// definition. If so, mark the corresponding temporary for flushing. + /// See `process_out_of_order_uses_in_same_instruction` for an example. + fn flush_out_of_order_uses_in_same_instruction( + use_index_1: usize, + use_index_2: usize, + offset: CodeOffset, code: &[Bytecode], use_def_links: &UseDefLinks, - flush_writes: &BTreeMap>, - ) -> bool { - // For each definition in between `def` and `use_`, is there at least one that is: - // 1. not marked to be flushed right away? - // 2. not consumed before `use_`? - // 3. not used in the same offset as `use_`? - // If so, `def` could be flushed before its `use_`, so we should suggest flush it - // right after definition. - // Note that we expect the code in the block to be processed in the reverse order. - let defs_in_between = Self::get_defs_between(def, use_, use_def_links); - for def_in_between in defs_in_between { - if Self::is_def_flushed_away(&def_in_between, code, flush_writes) { - continue; + offset_range: &Range, + sources: &[TempIndex], + flush_writes: &mut BTreeMap>, + ) { + let use_1 = DefOrUsePoint { + offset, + index: use_index_1, + }; + let use_2 = DefOrUsePoint { + offset, + index: use_index_2, + }; + let def_set_1 = use_def_links.use_to_def.get(&use_1); + let def_set_2 = use_def_links.use_to_def.get(&use_2); + match (def_set_1, def_set_2) { + (None, None) => { + // nothing to be done, both definitions are not within this block + }, + (_, None) => { + // nothing to be done, the second definition is not within this block + }, + (None, Some(defs_2)) => { + // Is the `def_2` within this block (and the only definition)? If so, it must be flushed. + if defs_2.len() == 1 { + let def_2_offset = defs_2 + .first() + .expect("there must be at least one def") + .offset; + if offset_range.contains(&def_2_offset) { + flush_writes + .entry(def_2_offset) + .or_default() + .insert(sources[use_index_2]); + } + } + }, + (Some(defs_1), Some(defs_2)) => { + if defs_1.len() == 1 && defs_2.len() == 1 { + let def_1 = defs_1.first().expect("there must be at least one def"); + let def_2 = defs_2.first().expect("there must be at least one def"); + let def_1_actual = Self::get_def_skipping_self_assigns( + def_1, + code, + offset_range, + use_def_links, + ); + let def_2_actual = Self::get_def_skipping_self_assigns( + def_2, + code, + offset_range, + use_def_links, + ); + if offset_range.contains(&def_1_actual.offset) + && offset_range.contains(&def_2_actual.offset) + && def_1_actual > def_2_actual + { + flush_writes + .entry(def_2_actual.offset) + .or_default() + .insert(sources[use_index_2]); + } + } + }, + } + } + + /// Given an instruction at `offset` of `code`, check if there are uses of temporaries in the + /// wrong order when looking at uses at this instruction and other instructions. If so, mark + /// the corresponding temporaries for flushing. + /// `block_start` is the start of the block that has the instruction at `offset`. + /// + /// Example of a wrong order use within different instructions: + /// ```move + /// let a = some_integer(); // stack: [`a`] + /// let b = some_integer(); // stack: [`a`, `b`] + /// let c = some_integer(); // stack: [`a`, `b`, `c`] + /// consume_2(a, c); + /// consume_1(b); + /// ``` + /// In the above code, the stack should be [`a`, `c`] before the `consume_2` call. + /// However, as it stands, the stack is [`a`, `b`, `c`]. Thus, the top 2 temps on the + /// stack have to be flushed and re-loaded in the right order. + /// Instead, because we know the (`c`, `b`) pair is used in the wrong order, we can + /// flush `b` right away. With this, we only flush and re-load one temp instead of two. + fn process_out_of_order_uses_in_different_instructions( + code: &[Bytecode], + offset: CodeOffset, + block_start: CodeOffset, + use_def_links: &UseDefLinks, + flush_writes: &mut BTreeMap>, + ) { + // We are only interested in the uses in `Call` and `Ret` instructions. + let instr = &code[offset as usize]; + if !matches!(instr, Bytecode::Call(..) | Bytecode::Ret(..)) { + return; + } + if matches!(instr, Bytecode::Call(_, _, Operation::BorrowLoc, ..)) { + // `BorrowLoc` does not require its operands to be on the stack. + return; + } + let sources = instr.sources(); + for (use_index, use_temp) in sources.into_iter().enumerate() { + Self::flush_out_of_order_uses_in_different_instructions( + use_index, + use_temp, + offset, + block_start, + code, + use_def_links, + flush_writes, + ); + } + } + + /// Given a `use_index` at instruction `offset` of `code`, check if there are uses of temps + /// in other previous instructions that are in the wrong order compared to their definition. + /// If so, mark the corresponding temp for flushing. + /// See `process_out_of_order_uses_in_different_instructions` for an example. + fn flush_out_of_order_uses_in_different_instructions( + use_index: usize, + use_temp: TempIndex, + offset: CodeOffset, + block_start: CodeOffset, + code: &[Bytecode], + use_def_links: &UseDefLinks, + flush_writes: &mut BTreeMap>, + ) { + let this_use_point = DefOrUsePoint { + offset, + index: use_index, + }; + if let Some(this_uses_actual_def) = Self::get_singular_actual_def_in_range( + &this_use_point, + use_def_links, + code, + block_start..offset, + ) { + if Self::is_def_flushed_away(&this_uses_actual_def, code, flush_writes) { + return; } - if Self::consumed_before(&def_in_between, use_, use_def_links) { - continue; + let other_uses = + Self::get_uses_in_between(this_uses_actual_def.offset + 1..offset, code); + // Compare this use with all other uses that may conflict with this use. + for other_use in other_uses { + if let Some(other_uses_actual_def) = Self::get_singular_actual_def_in_range( + &other_use, + use_def_links, + code, + block_start..other_use.offset, + ) { + if other_uses_actual_def < this_uses_actual_def + && !Self::is_def_flushed_away(&other_uses_actual_def, code, flush_writes) + { + // Flush the use that is the only use, to minimize flushes. + // TODO: This heuristic could be improved by considering multiple uses in two (or more) + // conflicting instructions at the same time. + if Self::is_only_use_in_instr(&this_use_point, code) { + flush_writes + .entry(this_uses_actual_def.offset) + .or_default() + .insert(use_temp); + } else if Self::is_only_use_in_instr(&other_use, code) { + flush_writes + .entry(other_uses_actual_def.offset) + .or_default() + .insert(Self::get_temp_from_def_point( + &other_uses_actual_def, + code, + )); + } + } + } } - if Self::consumed_at(&def_in_between, use_, use_def_links) { - continue; + } + } + + /// Get the temporary corresponding to `def_point`. + fn get_temp_from_def_point(def_point: &DefOrUsePoint, code: &[Bytecode]) -> TempIndex { + let instr = &code[def_point.offset as usize]; + instr.dests()[def_point.index] + } + + /// Is `use_point` the only use in that instruction? + fn is_only_use_in_instr(use_point: &DefOrUsePoint, code: &[Bytecode]) -> bool { + let instr = &code[use_point.offset as usize]; + let sources = instr.sources(); + sources.len() == 1 && use_point.index == 0 + } + + /// Get all the use points in the `offset_range`. + fn get_uses_in_between( + offset_range: Range, + code: &[Bytecode], + ) -> Vec { + let mut uses = vec![]; + for offset in offset_range { + let instr = &code[offset as usize]; + if let Bytecode::Call(_, _, op, sources, _) = instr { + if *op == Operation::BorrowLoc { + continue; + } + for use_index in 0..sources.len() { + uses.push(DefOrUsePoint { + offset, + index: use_index, + }); + } } - return true; } - false + uses + } + + /// Get the actual definition (the definition obtained by skipping self-assigns) of `use_point`. + /// Is this the only definition and is it within the `range`? + fn get_singular_actual_def_in_range( + use_point: &DefOrUsePoint, + use_def_links: &UseDefLinks, + code: &[Bytecode], + range: Range, + ) -> Option { + let def_set = use_def_links.use_to_def.get(use_point)?; + if def_set.len() != 1 { + return None; + } + let def = def_set.first().expect("there is at least one def"); + let actual_def = Self::get_def_skipping_self_assigns(def, code, &range, use_def_links); + if range.contains(&def.offset) { + Some(actual_def) + } else { + None + } } /// Has `def` been marked to be flushed right away? @@ -340,66 +574,39 @@ impl FlushWritesProcessor { false } - /// Is `def` consumed before `use_`? - fn consumed_before( + /// Trace `def` to the actual definition by skipping self-assigns in the `offset_range`. + fn get_def_skipping_self_assigns( def: &DefOrUsePoint, - use_: &DefOrUsePoint, - use_def_links: &UseDefLinks, - ) -> bool { - use_def_links - .def_to_use - .get(def) - .map_or(false, |uses| uses.iter().all(|u| u.offset < use_.offset)) - } - - /// Is `def` consumed at `use_`'s offset? - fn consumed_at(def: &DefOrUsePoint, use_: &DefOrUsePoint, use_def_links: &UseDefLinks) -> bool { - let use_offset = use_.offset; - use_def_links - .def_to_use - .get(def) - .map_or(false, |uses| uses.iter().all(|u| u.offset == use_offset)) - } - - /// Get all the definitions between `def` and `use_`. - fn get_defs_between( - def: &DefOrUsePoint, - use_: &DefOrUsePoint, + code: &[Bytecode], + offset_range: &Range, use_def_links: &UseDefLinks, - ) -> Vec { - let DefOrUsePoint { - offset: def_offset, - index: def_index, - } = def; - let use_offset = use_.offset; - let mut defs = vec![]; - if *def_offset == use_offset { - return defs; - } - // Are there defs at def_offset with index > def_index? - for index in def_index + 1.. { - let potential_def = DefOrUsePoint { - offset: *def_offset, - index, - }; - if use_def_links.def_to_use.contains_key(&potential_def) { - defs.push(potential_def); - } else { - break; - } - } - // Are there defs after def_offset and before use_offset? - for offset in (*def_offset + 1)..use_offset { - for index in 0.. { - let potential_def = DefOrUsePoint { offset, index }; - if use_def_links.def_to_use.contains_key(&potential_def) { - defs.push(potential_def); - } else { - break; + ) -> DefOrUsePoint { + let mut actual_def = def.clone(); + // Only get defs within the same block. + while offset_range.contains(&actual_def.offset) { + let instr = &code[actual_def.offset as usize]; + let mut changed = false; + if let Bytecode::Assign(_, dest, src, _) = instr { + if *dest == *src { + // This is a self assign, skip it and get the actual def. + let self_use = DefOrUsePoint { + offset: actual_def.offset, + index: 0, + }; + if let Some(new_def) = use_def_links.use_to_def.get(&self_use) { + if new_def.len() == 1 { + actual_def = + new_def.first().expect("there is at least one def").clone(); + changed = true; + } + } } } + if !changed { + break; + } } - defs + actual_def } /// Registers annotation formatter at the given function target. diff --git a/third_party/move/move-compiler-v2/tests/ability-transform/destroy_after_call.exp b/third_party/move/move-compiler-v2/tests/ability-transform/destroy_after_call.exp index 28989b60c87a0..57006b13af531 100644 --- a/third_party/move/move-compiler-v2/tests/ability-transform/destroy_after_call.exp +++ b/third_party/move/move-compiler-v2/tests/ability-transform/destroy_after_call.exp @@ -370,9 +370,7 @@ fun m::g() { fun m::f($t0: &mut u64): &mut u64 { var $t1: &mut u64 [unused] # live vars: $t0 - 0: $t0 := move($t0) - # live vars: $t0 - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/ability-transform/foreach_mut_expanded.exp b/third_party/move/move-compiler-v2/tests/ability-transform/foreach_mut_expanded.exp index 4b6ab45471a9d..da0c4f780f630 100644 --- a/third_party/move/move-compiler-v2/tests/ability-transform/foreach_mut_expanded.exp +++ b/third_party/move/move-compiler-v2/tests/ability-transform/foreach_mut_expanded.exp @@ -1161,7 +1161,8 @@ L0: loc0: vector L1: loc1: u64 L2: loc2: u64 L3: loc3: &mut vector -L4: loc4: &mut u64 +L4: loc4: u64 +L5: loc5: &mut u64 B0: 0: LdConst[0](Vector(U64): [3, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0]) 1: StLoc[0](loc0: vector) @@ -1181,9 +1182,9 @@ B2: 13: CopyLoc[3](loc3: &mut vector) 14: CopyLoc[1](loc1: u64) 15: VecMutBorrow(1) - 16: StLoc[4](loc4: &mut u64) + 16: StLoc[5](loc5: &mut u64) 17: LdU64(2) - 18: MoveLoc[4](loc4: &mut u64) + 18: MoveLoc[5](loc5: &mut u64) 19: WriteRef 20: MoveLoc[1](loc1: u64) 21: LdU64(1) diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/conditional_borrow.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/conditional_borrow.exp index 556bc35ef880d..fe541e00f0afc 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/conditional_borrow.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/conditional_borrow.exp @@ -430,8 +430,8 @@ B0: } test1(Arg0: u64): u64 /* def_idx: 1 */ { L1: loc0: u64 -L2: loc1: &mut u64 -L3: loc2: u64 +L2: loc1: u64 +L3: loc2: &mut u64 L4: loc3: u64 L5: loc4: u64 L6: loc5: u64 @@ -447,65 +447,65 @@ B1: 5: StLoc[1](loc0: u64) B2: 6: MutBorrowLoc[1](loc0: u64) - 7: StLoc[2](loc1: &mut u64) + 7: StLoc[3](loc2: &mut u64) 8: LdU64(10) - 9: MoveLoc[2](loc1: &mut u64) + 9: MoveLoc[3](loc2: &mut u64) 10: WriteRef 11: MoveLoc[0](Arg0: u64) - 12: StLoc[3](loc2: u64) - 13: MutBorrowLoc[3](loc2: u64) - 14: StLoc[2](loc1: &mut u64) - 15: CopyLoc[2](loc1: &mut u64) + 12: StLoc[4](loc3: u64) + 13: MutBorrowLoc[4](loc3: u64) + 14: StLoc[3](loc2: &mut u64) + 15: CopyLoc[3](loc2: &mut u64) 16: ReadRef 17: LdU64(1) 18: Add - 19: MoveLoc[2](loc1: &mut u64) + 19: MoveLoc[3](loc2: &mut u64) 20: WriteRef - 21: MoveLoc[3](loc2: u64) - 22: StLoc[4](loc3: u64) - 23: CopyLoc[4](loc3: u64) + 21: MoveLoc[4](loc3: u64) + 22: StLoc[2](loc1: u64) + 23: CopyLoc[2](loc1: u64) 24: LdU64(0) 25: Add 26: StLoc[5](loc4: u64) 27: MutBorrowLoc[5](loc4: u64) - 28: StLoc[2](loc1: &mut u64) - 29: CopyLoc[2](loc1: &mut u64) + 28: StLoc[3](loc2: &mut u64) + 29: CopyLoc[3](loc2: &mut u64) 30: ReadRef 31: LdU64(2) 32: Add - 33: MoveLoc[2](loc1: &mut u64) + 33: MoveLoc[3](loc2: &mut u64) 34: WriteRef - 35: CopyLoc[4](loc3: u64) + 35: CopyLoc[2](loc1: u64) 36: StLoc[6](loc5: u64) 37: MutBorrowLoc[6](loc5: u64) - 38: StLoc[2](loc1: &mut u64) - 39: CopyLoc[2](loc1: &mut u64) + 38: StLoc[3](loc2: &mut u64) + 39: CopyLoc[3](loc2: &mut u64) 40: ReadRef 41: LdU64(4) 42: Add - 43: MoveLoc[2](loc1: &mut u64) + 43: MoveLoc[3](loc2: &mut u64) 44: WriteRef - 45: CopyLoc[4](loc3: u64) + 45: CopyLoc[2](loc1: u64) 46: StLoc[7](loc6: u64) 47: MutBorrowLoc[7](loc6: u64) - 48: StLoc[2](loc1: &mut u64) - 49: CopyLoc[2](loc1: &mut u64) + 48: StLoc[3](loc2: &mut u64) + 49: CopyLoc[3](loc2: &mut u64) 50: ReadRef 51: LdU64(8) 52: Add - 53: MoveLoc[2](loc1: &mut u64) + 53: MoveLoc[3](loc2: &mut u64) 54: WriteRef - 55: CopyLoc[4](loc3: u64) + 55: CopyLoc[2](loc1: u64) 56: StLoc[8](loc7: u64) 57: MutBorrowLoc[8](loc7: u64) - 58: StLoc[2](loc1: &mut u64) - 59: CopyLoc[2](loc1: &mut u64) + 58: StLoc[3](loc2: &mut u64) + 59: CopyLoc[3](loc2: &mut u64) 60: ReadRef 61: LdU64(16) 62: Add - 63: MoveLoc[2](loc1: &mut u64) + 63: MoveLoc[3](loc2: &mut u64) 64: WriteRef - 65: MoveLoc[4](loc3: u64) + 65: MoveLoc[2](loc1: u64) 66: Ret B3: 67: LdU64(3) diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/fields.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/fields.exp index f3ff487814513..658b767172dee 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/fields.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/fields.exp @@ -348,7 +348,8 @@ B0: } write_local_via_ref_2(): S /* def_idx: 6 */ { L0: loc0: S -L1: loc1: &mut u64 +L1: loc1: u64 +L2: loc2: &mut u64 B0: 0: LdU64(0) 1: LdU64(0) @@ -358,9 +359,9 @@ B0: 5: MutBorrowLoc[0](loc0: S) 6: MutBorrowField[1](S.g: T) 7: MutBorrowField[2](T.h: u64) - 8: StLoc[1](loc1: &mut u64) + 8: StLoc[2](loc2: &mut u64) 9: LdU64(42) - 10: MoveLoc[1](loc1: &mut u64) + 10: MoveLoc[2](loc2: &mut u64) 11: WriteRef 12: MoveLoc[0](loc0: S) 13: Ret diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/freeze_mut_ref.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/freeze_mut_ref.exp index 734e7667cfc63..1ad27dd46da9d 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/freeze_mut_ref.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/freeze_mut_ref.exp @@ -469,6 +469,7 @@ B0: 2: Ret } t2(Arg0: &mut u64, Arg1: &mut u64): &u64 * &mut u64 /* def_idx: 6 */ { +L2: loc0: &u64 B0: 0: MoveLoc[0](Arg0: &mut u64) 1: FreezeRef @@ -494,10 +495,12 @@ B0: } public t5(Arg0: &mut G) /* def_idx: 8 */ { L1: loc0: &mut u64 -L2: loc1: &mut u64 +L2: loc1: u64 L3: loc2: u64 L4: loc3: &mut u64 L5: loc4: &u64 +L6: loc5: u64 +L7: loc6: &mut u64 B0: 0: LdU64(0) 1: LdU64(1) @@ -510,21 +513,23 @@ B0: 8: Pop 9: MoveLoc[0](Arg0: &mut G) 10: MutBorrowField[0](G.f: u64) - 11: StLoc[2](loc1: &mut u64) - 12: LdU64(2) - 13: StLoc[3](loc2: u64) - 14: MutBorrowLoc[3](loc2: u64) - 15: StLoc[4](loc3: &mut u64) - 16: LdU64(2) - 17: LdU64(0) - 18: MoveLoc[1](loc0: &mut u64) - 19: WriteRef - 20: MoveLoc[4](loc3: &mut u64) - 21: FreezeRef - 22: Pop - 23: MoveLoc[2](loc1: &mut u64) - 24: WriteRef - 25: Ret + 11: LdU64(2) + 12: StLoc[3](loc2: u64) + 13: MutBorrowLoc[3](loc2: u64) + 14: StLoc[4](loc3: &mut u64) + 15: LdU64(2) + 16: LdU64(0) + 17: MoveLoc[1](loc0: &mut u64) + 18: WriteRef + 19: MoveLoc[4](loc3: &mut u64) + 20: FreezeRef + 21: Pop + 22: StLoc[6](loc5: u64) + 23: StLoc[7](loc6: &mut u64) + 24: MoveLoc[6](loc5: u64) + 25: MoveLoc[7](loc6: &mut u64) + 26: WriteRef + 27: Ret } t6(Arg0: bool, Arg1: &mut S, Arg2: &S) /* def_idx: 9 */ { L3: loc0: &S diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/inline_specs.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/inline_specs.exp index a17c8ced9927e..397b2d775dac3 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/inline_specs.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/inline_specs.exp @@ -87,15 +87,13 @@ module 42.inline_specs { specs(): u64 /* def_idx: 0 */ { L0: loc0: u64 B0: - 0: LdU64(0) - 1: StLoc[0](loc0: u64) - 2: Nop - 3: MoveLoc[0](loc0: u64) - 4: Call succ(u64): u64 - 5: StLoc[0](loc0: u64) - 6: Nop - 7: MoveLoc[0](loc0: u64) - 8: Ret + 0: Nop + 1: LdU64(0) + 2: Call succ(u64): u64 + 3: StLoc[0](loc0: u64) + 4: Nop + 5: MoveLoc[0](loc0: u64) + 6: Ret } succ(Arg0: u64): u64 /* def_idx: 1 */ { B0: diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/pack_unpack.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/pack_unpack.exp index 5cdfcc682917e..5792041151ffe 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/pack_unpack.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/pack_unpack.exp @@ -85,6 +85,8 @@ B0: 4: Ret } unpack(Arg0: S): u64 * u64 /* def_idx: 1 */ { +L1: loc0: u64 +L2: loc1: u64 B0: 0: MoveLoc[0](Arg0: S) 1: Unpack[1](S) diff --git a/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_06.exp b/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_06.exp index 280e224e41e66..49a51d377d18c 100644 --- a/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_06.exp +++ b/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_06.exp @@ -76,9 +76,7 @@ fun m::bar($t0: &mut 0xc0ffee::m::S, $t1: u64): u64 { # live vars: $t1, $t3 1: write_ref($t3, $t1) # live vars: $t1 - 2: $t1 := move($t1) - # live vars: $t1 - 3: return $t1 + 2: return $t1 } diff --git a/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_07.exp b/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_07.exp index c8eca1b327793..437b80736c3dc 100644 --- a/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_07.exp +++ b/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_07.exp @@ -59,9 +59,7 @@ fun m::foo($t0: &mut u64, $t1: u64): &mut u64 { # live vars: $t0, $t1 0: write_ref($t0, $t1) # live vars: $t0 - 1: $t0 := move($t0) - # live vars: $t0 - 2: return $t0 + 1: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_08.exp b/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_08.exp index 0ba77f3e40d87..e78651e90f36e 100644 --- a/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_08.exp +++ b/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_08.exp @@ -55,9 +55,7 @@ fun m::bar($t0: &u64, $t1: u64) { fun m::foo($t0: &u64, $t1: u64): &u64 { var $t2: &u64 [unused] # live vars: $t0, $t1 - 0: $t0 := move($t0) - # live vars: $t0 - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_09.exp b/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_09.exp index 1011e6826b7d0..749118228690d 100644 --- a/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_09.exp +++ b/third_party/move/move-compiler-v2/tests/eager-pushes/framework_reduced_09.exp @@ -65,9 +65,7 @@ fun m::bar($t0: &mut u64, $t1: u64): &mut u64 { # live vars: $t0, $t1 0: write_ref($t0, $t1) # live vars: $t0 - 1: $t0 := move($t0) - # live vars: $t0 - 2: return $t0 + 1: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/framework_reduced_06.opt.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/framework_reduced_06.opt.exp index 66710764d3088..8d7d87b60c1ae 100644 --- a/third_party/move/move-compiler-v2/tests/file-format-generator/framework_reduced_06.opt.exp +++ b/third_party/move/move-compiler-v2/tests/file-format-generator/framework_reduced_06.opt.exp @@ -38,9 +38,6 @@ B0: } foo(Arg0: address, Arg1: &mut S, Arg2: &mut S): u64 /* def_idx: 4 */ { L3: loc0: u64 -L4: loc1: u64 -L5: loc2: &mut S -L6: loc3: address B0: 0: MoveLoc[1](Arg1: &mut S) 1: LdU64(1) @@ -51,18 +48,16 @@ B0: 6: StLoc[1](Arg1: &mut S) 7: CopyLoc[0](Arg0: address) 8: CopyLoc[1](Arg1: &mut S) - 9: CopyLoc[3](loc0: u64) - 10: StLoc[4](loc1: u64) - 11: MoveLoc[0](Arg0: address) - 12: MoveLoc[4](loc1: u64) - 13: MoveLoc[2](Arg2: &mut S) - 14: Call f2(address, &mut S, address, u64, &mut S) - 15: CopyLoc[3](loc0: u64) - 16: MoveLoc[1](Arg1: &mut S) - 17: ImmBorrowField[0](S.g: u64) - 18: Call f3(u64, &u64) - 19: MoveLoc[3](loc0: u64) - 20: Ret + 9: MoveLoc[0](Arg0: address) + 10: CopyLoc[3](loc0: u64) + 11: MoveLoc[2](Arg2: &mut S) + 12: Call f2(address, &mut S, address, u64, &mut S) + 13: CopyLoc[3](loc0: u64) + 14: MoveLoc[1](Arg1: &mut S) + 15: ImmBorrowField[0](S.g: u64) + 16: Call f3(u64, &u64) + 17: MoveLoc[3](loc0: u64) + 18: Ret } } ============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/opt_load_05.opt.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/opt_load_05.opt.exp index a0d0bb9f292c7..d1313596adbab 100644 --- a/third_party/move/move-compiler-v2/tests/file-format-generator/opt_load_05.opt.exp +++ b/third_party/move/move-compiler-v2/tests/file-format-generator/opt_load_05.opt.exp @@ -31,7 +31,6 @@ B0: } public test3(Arg0: u64) /* def_idx: 4 */ { L1: loc0: u64 -L2: loc1: u64 B0: 0: Call one(): u64 1: StLoc[1](loc0: u64) diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/pack_unpack.opt.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/pack_unpack.opt.exp index b1263d5089755..54242e8716e6d 100644 --- a/third_party/move/move-compiler-v2/tests/file-format-generator/pack_unpack.opt.exp +++ b/third_party/move/move-compiler-v2/tests/file-format-generator/pack_unpack.opt.exp @@ -19,6 +19,8 @@ B0: 4: Ret } unpack(Arg0: S): u64 * u64 /* def_idx: 1 */ { +L1: loc0: u64 +L2: loc1: u64 B0: 0: MoveLoc[0](Arg0: S) 1: Unpack[1](S) diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.opt.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.opt.exp index 0a38b33ad65b2..91c6546a8b356 100644 --- a/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.opt.exp +++ b/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.opt.exp @@ -65,6 +65,8 @@ enum Outer { public inner_value(Arg0: Inner): u64 /* def_idx: 0 */ { L1: loc0: &Inner L2: loc1: u64 +L3: loc2: u64 +L4: loc3: u64 B0: 0: ImmBorrowLoc[0](Arg0: Inner) 1: StLoc[1](loc0: &Inner) diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/def_use_01.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/def_use_01.on.exp index 612ad7279fadd..8cb774900a663 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/def_use_01.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/def_use_01.on.exp @@ -38,9 +38,11 @@ public fun m::test() { # live vars: $t0, $t1 1: m::take1($t1) # live vars: $t0, $t1 - 2: m::take2($t0, $t1) + 2: $t0 := move($t0) + # live vars: $t0, $t1 + 3: m::take2($t0, $t1) # live vars: - 3: return () + 4: return () } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/def_use_02.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/def_use_02.on.exp index 5a68ae7e6cf9f..44af7ea1b0c1b 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/def_use_02.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/def_use_02.on.exp @@ -38,9 +38,11 @@ public fun m::test() { # live vars: $t0, $t1 1: m::take1($t1) # live vars: $t0, $t1 - 2: m::take2($t1, $t0) + 2: $t1 := move($t1) + # live vars: $t0, $t1 + 3: m::take2($t1, $t0) # live vars: - 3: return () + 4: return () } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/def_use_05.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/def_use_05.on.exp index f88bc7bdfeec9..09f07ac515fca 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/def_use_05.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/def_use_05.on.exp @@ -31,7 +31,7 @@ fun m::take2($t0: u64, $t1: u64) { public fun m::test() { var $t0: u64 var $t1: u64 - # flush: $t0 + # flush: $t1 # live vars: 0: ($t0, $t1) := m::one_one() # live vars: $t0, $t1 @@ -64,7 +64,6 @@ B0: } public test() /* def_idx: 3 */ { L0: loc0: u64 -L1: loc1: u64 B0: 0: Call one_one(): u64 * u64 1: StLoc[0](loc0: u64) diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/def_use_08.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/def_use_08.on.exp index bd4686eb0dd2d..9f95fb97c4a1a 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/def_use_08.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/def_use_08.on.exp @@ -39,9 +39,15 @@ public fun m::test() { # live vars: 0: ($t0, $t1, $t2, $t3) := m::foo() # live vars: $t0, $t1, $t2, $t3 - 1: m::take($t1, $t2, $t3, $t0) + 1: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3 + 2: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3 + 3: $t3 := move($t3) + # live vars: $t0, $t1, $t2, $t3 + 4: m::take($t1, $t2, $t3, $t0) # live vars: - 2: return () + 5: return () } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.move b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.move new file mode 100644 index 0000000000000..baee8c1a45fd1 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.move @@ -0,0 +1,17 @@ +module 0xc0ffee::m { + use std::vector; + + fun one(): u64 { + 1 + } + + fun consume(_a: u64, _b: &u64) {} + + public fun test(v: vector) { + let x = one(); + vector::for_each_ref(&v, |e| { + let e1 = e; + consume(x, e1); + }); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.off.exp new file mode 100644 index 0000000000000..6b71771f5b7fe --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.off.exp @@ -0,0 +1,58 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: &u64) /* def_idx: 0 */ { +B0: + 0: MoveLoc[1](Arg1: &u64) + 1: Pop + 2: Ret +} +one(): u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test(Arg0: vector) /* def_idx: 2 */ { +L1: loc0: &vector +L2: loc1: u64 +L3: loc2: u64 +L4: loc3: u64 +L5: loc4: &u64 +B0: + 0: Call one(): u64 + 1: ImmBorrowLoc[0](Arg0: vector) + 2: StLoc[1](loc0: &vector) + 3: LdU64(0) + 4: StLoc[2](loc1: u64) + 5: StLoc[3](loc2: u64) +B1: + 6: CopyLoc[2](loc1: u64) + 7: CopyLoc[1](loc0: &vector) + 8: VecLen(2) + 9: Lt + 10: BrFalse(25) +B2: + 11: CopyLoc[1](loc0: &vector) + 12: CopyLoc[2](loc1: u64) + 13: VecImmBorrow(2) + 14: CopyLoc[3](loc2: u64) + 15: StLoc[4](loc3: u64) + 16: StLoc[5](loc4: &u64) + 17: MoveLoc[4](loc3: u64) + 18: MoveLoc[5](loc4: &u64) + 19: Call consume(u64, &u64) + 20: MoveLoc[2](loc1: u64) + 21: LdU64(1) + 22: Add + 23: StLoc[2](loc1: u64) + 24: Branch(6) +B3: + 25: MoveLoc[1](loc0: &vector) + 26: Pop + 27: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.on.exp new file mode 100644 index 0000000000000..ed90266339ce5 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_11.on.exp @@ -0,0 +1,142 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume($t0: u64, $t1: &u64) { + # live vars: $t0, $t1 + 0: drop($t1) + # live vars: + 1: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +public fun m::test($t0: vector) { + var $t1: u64 + var $t2: &vector [unused] + var $t3: &vector + var $t4: u64 + var $t5: bool + var $t6: u64 + var $t7: u64 + var $t8: &u64 [unused] + var $t9: &u64 + var $t10: &vector + var $t11: &u64 [unused] + var $t12: u64 [unused] + var $t13: u64 [unused] + var $t14: u64 [unused] + var $t15: u64 [unused] + # flush: $t1 + # live vars: $t0 + 0: $t1 := m::one() + # flush: $t3 + # live vars: $t0, $t1 + 1: $t3 := borrow_local($t0) + # flush: $t4 + # live vars: $t1, $t3 + 2: $t4 := 0 + # live vars: $t1, $t3, $t4 + 3: label L0 + # live vars: $t1, $t3, $t4 + 4: $t6 := copy($t4) + # live vars: $t1, $t3, $t4, $t6 + 5: $t7 := vector::length($t3) + # live vars: $t1, $t3, $t4, $t6, $t7 + 6: $t5 := <($t6, $t7) + # live vars: $t1, $t3, $t4, $t5 + 7: if ($t5) goto 8 else goto 18 + # live vars: $t1, $t3, $t4 + 8: label L2 + # live vars: $t1, $t3, $t4 + 9: $t10 := copy($t3) + # flush: $t9 + # live vars: $t1, $t3, $t4, $t10 + 10: $t9 := vector::borrow($t10, $t4) + # live vars: $t1, $t3, $t4, $t9 + 11: $t6 := copy($t1) + # live vars: $t1, $t3, $t4, $t6, $t9 + 12: m::consume($t6, $t9) + # live vars: $t1, $t3, $t4 + 13: $t6 := move($t4) + # live vars: $t1, $t3, $t6 + 14: $t7 := 1 + # live vars: $t1, $t3, $t6, $t7 + 15: $t6 := +($t6, $t7) + # flush: $t4 + # live vars: $t1, $t3, $t6 + 16: $t4 := move($t6) + # live vars: $t1, $t3, $t4 + 17: goto 3 + # live vars: $t1, $t3, $t4 + 18: label L3 + # live vars: $t3 + 19: drop($t3) + # live vars: + 20: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: &u64) /* def_idx: 0 */ { +B0: + 0: MoveLoc[1](Arg1: &u64) + 1: Pop + 2: Ret +} +one(): u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test(Arg0: vector) /* def_idx: 2 */ { +L1: loc0: u64 +L2: loc1: &vector +L3: loc2: u64 +L4: loc3: &u64 +B0: + 0: Call one(): u64 + 1: StLoc[1](loc0: u64) + 2: ImmBorrowLoc[0](Arg0: vector) + 3: StLoc[2](loc1: &vector) + 4: LdU64(0) + 5: StLoc[3](loc2: u64) +B1: + 6: CopyLoc[3](loc2: u64) + 7: CopyLoc[2](loc1: &vector) + 8: VecLen(2) + 9: Lt + 10: BrFalse(23) +B2: + 11: CopyLoc[2](loc1: &vector) + 12: CopyLoc[3](loc2: u64) + 13: VecImmBorrow(2) + 14: StLoc[4](loc3: &u64) + 15: CopyLoc[1](loc0: u64) + 16: MoveLoc[4](loc3: &u64) + 17: Call consume(u64, &u64) + 18: MoveLoc[3](loc2: u64) + 19: LdU64(1) + 20: Add + 21: StLoc[3](loc2: u64) + 22: Branch(6) +B3: + 23: MoveLoc[2](loc1: &vector) + 24: Pop + 25: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.move b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.move new file mode 100644 index 0000000000000..20d7070cd5f78 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.move @@ -0,0 +1,57 @@ +module 0xc0ffee::m { + use std::vector; + + fun id(x: u64): u64 { + x + } + + fun bytes(_x: &u64): vector { + vector[1u8, 2u8] + } + + fun cons_2(x: u64, _y: &mut u64): u64 { + x + } + + fun one(): u64 { + 1 + } + + fun cons_7(_x: vector, _a: u64, _b: u64, _c: u64, _d: u64, _e: u64, _f: u64): u64 { + 0 + } + + fun cons_2_another(_x: &u64, _y: u64) {} + + fun test(new_address: u64): u64 { + let new_account = id(new_address); + let authentication_key = bytes(&new_address); + assert!( + vector::length(&authentication_key) == 2, + 42 + ); + + let guid_creation_num = 0; + + let guid_for_coin = cons_2(new_address, &mut guid_creation_num); + let coin_register_events = id(guid_for_coin); + + let guid_for_rotation = cons_2(new_address, &mut guid_creation_num); + let key_rotation_events = id(guid_for_rotation); + + cons_2_another( + &new_account, + cons_7( + authentication_key, + 0, + guid_creation_num, + coin_register_events, + key_rotation_events, + id(one()), + id(one()), + ) + ); + + new_account + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.off.exp new file mode 100644 index 0000000000000..3ead2ca389a85 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.off.exp @@ -0,0 +1,112 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +bytes(Arg0: &u64): vector /* def_idx: 0 */ { +B0: + 0: LdConst[0](Vector(U8): [2, 1, 2]) + 1: MoveLoc[0](Arg0: &u64) + 2: Pop + 3: Ret +} +cons_2(Arg0: u64, Arg1: &mut u64): u64 /* def_idx: 1 */ { +B0: + 0: MoveLoc[1](Arg1: &mut u64) + 1: Pop + 2: MoveLoc[0](Arg0: u64) + 3: Ret +} +cons_2_another(Arg0: &u64, Arg1: u64) /* def_idx: 2 */ { +B0: + 0: MoveLoc[0](Arg0: &u64) + 1: Pop + 2: Ret +} +cons_7(Arg0: vector, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64, Arg5: u64, Arg6: u64): u64 /* def_idx: 3 */ { +B0: + 0: LdU64(0) + 1: Ret +} +id(Arg0: u64): u64 /* def_idx: 4 */ { +B0: + 0: MoveLoc[0](Arg0: u64) + 1: Ret +} +one(): u64 /* def_idx: 5 */ { +B0: + 0: LdU64(1) + 1: Ret +} +test(Arg0: u64): u64 /* def_idx: 6 */ { +L1: loc0: u64 +L2: loc1: vector +L3: loc2: u64 +L4: loc3: u64 +L5: loc4: u64 +L6: loc5: vector +L7: loc6: &u64 +L8: loc7: u64 +L9: loc8: u64 +L10: loc9: u64 +L11: loc10: u64 +B0: + 0: CopyLoc[0](Arg0: u64) + 1: Call id(u64): u64 + 2: StLoc[1](loc0: u64) + 3: ImmBorrowLoc[0](Arg0: u64) + 4: Call bytes(&u64): vector + 5: StLoc[2](loc1: vector) + 6: ImmBorrowLoc[2](loc1: vector) + 7: VecLen(7) + 8: LdU64(2) + 9: Eq + 10: BrFalse(51) +B1: + 11: LdU64(0) + 12: StLoc[3](loc2: u64) + 13: CopyLoc[0](Arg0: u64) + 14: MutBorrowLoc[3](loc2: u64) + 15: Call cons_2(u64, &mut u64): u64 + 16: Call id(u64): u64 + 17: MoveLoc[0](Arg0: u64) + 18: MutBorrowLoc[3](loc2: u64) + 19: Call cons_2(u64, &mut u64): u64 + 20: Call id(u64): u64 + 21: ImmBorrowLoc[1](loc0: u64) + 22: MoveLoc[2](loc1: vector) + 23: LdU64(0) + 24: MoveLoc[3](loc2: u64) + 25: StLoc[4](loc3: u64) + 26: StLoc[5](loc4: u64) + 27: StLoc[6](loc5: vector) + 28: StLoc[7](loc6: &u64) + 29: Call one(): u64 + 30: Call id(u64): u64 + 31: Call one(): u64 + 32: Call id(u64): u64 + 33: StLoc[10](loc9: u64) + 34: StLoc[11](loc10: u64) + 35: StLoc[8](loc7: u64) + 36: StLoc[9](loc8: u64) + 37: MoveLoc[6](loc5: vector) + 38: MoveLoc[5](loc4: u64) + 39: MoveLoc[4](loc3: u64) + 40: MoveLoc[9](loc8: u64) + 41: MoveLoc[8](loc7: u64) + 42: MoveLoc[11](loc10: u64) + 43: MoveLoc[10](loc9: u64) + 44: Call cons_7(vector, u64, u64, u64, u64, u64, u64): u64 + 45: StLoc[9](loc8: u64) + 46: MoveLoc[7](loc6: &u64) + 47: MoveLoc[9](loc8: u64) + 48: Call cons_2_another(&u64, u64) + 49: MoveLoc[1](loc0: u64) + 50: Ret +B2: + 51: LdU64(42) + 52: Abort +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.on.exp new file mode 100644 index 0000000000000..54e6283f42e06 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/framework_reduced_12.on.exp @@ -0,0 +1,261 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::bytes($t0: &u64): vector { + var $t1: vector + # live vars: $t0 + 0: $t1 := ["1", "2"] + # live vars: $t0, $t1 + 1: drop($t0) + # live vars: $t1 + 2: return $t1 +} + + +[variant baseline] +fun m::cons_2($t0: u64, $t1: &mut u64): u64 { + var $t2: u64 [unused] + # live vars: $t0, $t1 + 0: drop($t1) + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +fun m::cons_2_another($t0: &u64, $t1: u64) { + # live vars: $t0, $t1 + 0: drop($t0) + # live vars: + 1: return () +} + + +[variant baseline] +fun m::cons_7($t0: vector, $t1: u64, $t2: u64, $t3: u64, $t4: u64, $t5: u64, $t6: u64): u64 { + var $t7: u64 [unused] + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 0: $t1 := 0 + # live vars: $t1 + 1: return $t1 +} + + +[variant baseline] +fun m::id($t0: u64): u64 { + var $t1: u64 [unused] + # live vars: $t0 + 0: return $t0 +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +fun m::test($t0: u64): u64 { + var $t1: u64 [unused] + var $t2: u64 + var $t3: vector + var $t4: &u64 + var $t5: bool + var $t6: u64 + var $t7: &vector + var $t8: u64 + var $t9: u64 [unused] + var $t10: u64 + var $t11: u64 [unused] + var $t12: u64 [unused] + var $t13: &mut u64 + var $t14: u64 [unused] + var $t15: u64 [unused] + var $t16: u64 [unused] + var $t17: &mut u64 [unused] + var $t18: u64 [unused] + var $t19: &u64 [unused] + var $t20: u64 [unused] + var $t21: vector + var $t22: u64 + var $t23: u64 + var $t24: u64 [unused] + var $t25: u64 [unused] + var $t26: u64 [unused] + var $t27: u64 + var $t28: u64 [unused] + var $t29: u64 + # flush: $t2 + # live vars: $t0 + 0: $t2 := m::id($t0) + # live vars: $t0, $t2 + 1: $t4 := borrow_local($t0) + # flush: $t3 + # live vars: $t0, $t2, $t4 + 2: $t3 := m::bytes($t4) + # live vars: $t0, $t2, $t3 + 3: $t7 := borrow_local($t3) + # live vars: $t0, $t2, $t3, $t7 + 4: $t6 := vector::length($t7) + # live vars: $t0, $t2, $t3, $t6 + 5: $t8 := 2 + # live vars: $t0, $t2, $t3, $t6, $t8 + 6: $t5 := ==($t6, $t8) + # live vars: $t0, $t2, $t3, $t5 + 7: if ($t5) goto 8 else goto 32 + # live vars: $t0, $t2, $t3 + 8: label L0 + # flush: $t10 + # live vars: $t0, $t2, $t3 + 9: $t10 := 0 + # live vars: $t0, $t2, $t3, $t10 + 10: $t6 := copy($t0) + # live vars: $t0, $t2, $t3, $t6, $t10 + 11: $t13 := borrow_local($t10) + # live vars: $t0, $t2, $t3, $t6, $t10, $t13 + 12: $t6 := m::cons_2($t6, $t13) + # flush: $t6 + # live vars: $t0, $t2, $t3, $t6, $t10 + 13: $t6 := m::id($t6) + # live vars: $t0, $t2, $t3, $t6, $t10 + 14: $t8 := move($t0) + # live vars: $t2, $t3, $t6, $t8, $t10 + 15: $t13 := borrow_local($t10) + # live vars: $t2, $t3, $t6, $t8, $t10, $t13 + 16: $t8 := m::cons_2($t8, $t13) + # flush: $t8 + # live vars: $t2, $t3, $t6, $t8, $t10 + 17: $t8 := m::id($t8) + # live vars: $t2, $t3, $t6, $t8, $t10 + 18: $t4 := borrow_local($t2) + # live vars: $t2, $t3, $t4, $t6, $t8, $t10 + 19: $t21 := move($t3) + # live vars: $t2, $t4, $t6, $t8, $t10, $t21 + 20: $t22 := 0 + # live vars: $t2, $t4, $t6, $t8, $t10, $t21, $t22 + 21: $t23 := move($t10) + # live vars: $t2, $t4, $t6, $t8, $t21, $t22, $t23 + 22: $t6 := move($t6) + # live vars: $t2, $t4, $t6, $t8, $t21, $t22, $t23 + 23: $t8 := move($t8) + # live vars: $t2, $t4, $t6, $t8, $t21, $t22, $t23 + 24: $t27 := m::one() + # live vars: $t2, $t4, $t6, $t8, $t21, $t22, $t23, $t27 + 25: $t27 := m::id($t27) + # live vars: $t2, $t4, $t6, $t8, $t21, $t22, $t23, $t27 + 26: $t29 := m::one() + # live vars: $t2, $t4, $t6, $t8, $t21, $t22, $t23, $t27, $t29 + 27: $t29 := m::id($t29) + # live vars: $t2, $t4, $t6, $t8, $t21, $t22, $t23, $t27, $t29 + 28: $t6 := m::cons_7($t21, $t22, $t23, $t6, $t8, $t27, $t29) + # live vars: $t2, $t4, $t6 + 29: m::cons_2_another($t4, $t6) + # live vars: $t2 + 30: $t6 := move($t2) + # live vars: $t6 + 31: return $t6 + # live vars: $t0, $t2, $t3 + 32: label L1 + # live vars: + 33: $t6 := 42 + # live vars: $t6 + 34: abort($t6) +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +bytes(Arg0: &u64): vector /* def_idx: 0 */ { +B0: + 0: LdConst[0](Vector(U8): [2, 1, 2]) + 1: MoveLoc[0](Arg0: &u64) + 2: Pop + 3: Ret +} +cons_2(Arg0: u64, Arg1: &mut u64): u64 /* def_idx: 1 */ { +B0: + 0: MoveLoc[1](Arg1: &mut u64) + 1: Pop + 2: MoveLoc[0](Arg0: u64) + 3: Ret +} +cons_2_another(Arg0: &u64, Arg1: u64) /* def_idx: 2 */ { +B0: + 0: MoveLoc[0](Arg0: &u64) + 1: Pop + 2: Ret +} +cons_7(Arg0: vector, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64, Arg5: u64, Arg6: u64): u64 /* def_idx: 3 */ { +B0: + 0: LdU64(0) + 1: Ret +} +id(Arg0: u64): u64 /* def_idx: 4 */ { +B0: + 0: MoveLoc[0](Arg0: u64) + 1: Ret +} +one(): u64 /* def_idx: 5 */ { +B0: + 0: LdU64(1) + 1: Ret +} +test(Arg0: u64): u64 /* def_idx: 6 */ { +L1: loc0: u64 +L2: loc1: vector +L3: loc2: u64 +L4: loc3: u64 +L5: loc4: u64 +B0: + 0: CopyLoc[0](Arg0: u64) + 1: Call id(u64): u64 + 2: StLoc[1](loc0: u64) + 3: ImmBorrowLoc[0](Arg0: u64) + 4: Call bytes(&u64): vector + 5: StLoc[2](loc1: vector) + 6: ImmBorrowLoc[2](loc1: vector) + 7: VecLen(7) + 8: LdU64(2) + 9: Eq + 10: BrFalse(37) +B1: + 11: LdU64(0) + 12: StLoc[3](loc2: u64) + 13: CopyLoc[0](Arg0: u64) + 14: MutBorrowLoc[3](loc2: u64) + 15: Call cons_2(u64, &mut u64): u64 + 16: Call id(u64): u64 + 17: StLoc[4](loc3: u64) + 18: MoveLoc[0](Arg0: u64) + 19: MutBorrowLoc[3](loc2: u64) + 20: Call cons_2(u64, &mut u64): u64 + 21: Call id(u64): u64 + 22: StLoc[5](loc4: u64) + 23: ImmBorrowLoc[1](loc0: u64) + 24: MoveLoc[2](loc1: vector) + 25: LdU64(0) + 26: MoveLoc[3](loc2: u64) + 27: MoveLoc[4](loc3: u64) + 28: MoveLoc[5](loc4: u64) + 29: Call one(): u64 + 30: Call id(u64): u64 + 31: Call one(): u64 + 32: Call id(u64): u64 + 33: Call cons_7(vector, u64, u64, u64, u64, u64, u64): u64 + 34: Call cons_2_another(&u64, u64) + 35: MoveLoc[1](loc0: u64) + 36: Ret +B2: + 37: LdU64(42) + 38: Abort +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_01.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_01.off.exp index fd1d67a0bace5..ac86b11f5356a 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_01.off.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_01.off.exp @@ -14,6 +14,13 @@ B0: 1: Ret } public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +L6: loc6: u64 B0: 0: Call one(): u64 1: Call one(): u64 diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_01.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_01.on.exp index a56b53ebf5f68..6e552832eec84 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_01.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_01.on.exp @@ -47,9 +47,21 @@ public fun m::test() { # live vars: $t0, $t1, $t2, $t3, $t4, $t5 6: $t6 := m::one() # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 - 7: m::consume($t0, $t1, $t2, $t3, $t4, $t5, $t6) + 7: $t0 := move($t0) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 8: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 9: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 10: $t3 := move($t3) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 11: $t4 := move($t4) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 12: $t5 := move($t5) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 13: m::consume($t0, $t1, $t2, $t3, $t4, $t5, $t6) # live vars: - 8: return () + 14: return () } @@ -68,6 +80,13 @@ B0: 1: Ret } public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +L6: loc6: u64 B0: 0: Call one(): u64 1: Call one(): u64 diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.move b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.move new file mode 100644 index 0000000000000..24cc6772def53 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.move @@ -0,0 +1,12 @@ +module 0xc0ffee::m { + fun foo(): (u64, u64, u64, u64, u64) { + (1, 2, 3, 4, 5) + } + + fun consume(_a: u64, _b: u64, _c: u64, _d: u64, _e: u64) {} + + public fun test() { + let (a, b, c, d, e) = foo(); + consume(a, b, c, d, e); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.off.exp new file mode 100644 index 0000000000000..249f372aff360 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.off.exp @@ -0,0 +1,32 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +foo(): u64 * u64 * u64 * u64 * u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: LdU64(2) + 2: LdU64(3) + 3: LdU64(4) + 4: LdU64(5) + 5: Ret +} +public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +B0: + 0: Call foo(): u64 * u64 * u64 * u64 * u64 + 1: Call consume(u64, u64, u64, u64, u64) + 2: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.on.exp new file mode 100644 index 0000000000000..32b4c53436a38 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_02.on.exp @@ -0,0 +1,90 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume($t0: u64, $t1: u64, $t2: u64, $t3: u64, $t4: u64) { + # live vars: $t0, $t1, $t2, $t3, $t4 + 0: return () +} + + +[variant baseline] +fun m::foo(): (u64, u64, u64, u64, u64) { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: $t1 := 2 + # live vars: $t0, $t1 + 2: $t2 := 3 + # live vars: $t0, $t1, $t2 + 3: $t3 := 4 + # live vars: $t0, $t1, $t2, $t3 + 4: $t4 := 5 + # live vars: $t0, $t1, $t2, $t3, $t4 + 5: return ($t0, $t1, $t2, $t3, $t4) +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + var $t5: u64 [unused] + var $t6: u64 [unused] + var $t7: u64 [unused] + var $t8: u64 [unused] + # live vars: + 0: ($t0, $t1, $t2, $t3, $t4) := m::foo() + # live vars: $t0, $t1, $t2, $t3, $t4 + 1: $t0 := move($t0) + # live vars: $t0, $t1, $t2, $t3, $t4 + 2: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3, $t4 + 3: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3, $t4 + 4: $t3 := move($t3) + # live vars: $t0, $t1, $t2, $t3, $t4 + 5: m::consume($t0, $t1, $t2, $t3, $t4) + # live vars: + 6: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +foo(): u64 * u64 * u64 * u64 * u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: LdU64(2) + 2: LdU64(3) + 3: LdU64(4) + 4: LdU64(5) + 5: Ret +} +public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +B0: + 0: Call foo(): u64 * u64 * u64 * u64 * u64 + 1: Call consume(u64, u64, u64, u64, u64) + 2: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.move b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.move new file mode 100644 index 0000000000000..27a29c7cd1cd6 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.move @@ -0,0 +1,20 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun consume_4(_a: u64, _b: u64, _c: u64, _d: u64) {} + + fun consume_2(_a: u64, _b: u64) {} + + public fun test() { + let a = one(); + let b = one(); + let c = one(); + let d = one(); + let e = one(); + let f = one(); + consume_2(e, f); + consume_4(a, b, c, d); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.off.exp new file mode 100644 index 0000000000000..20c9ee4c47c48 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.off.exp @@ -0,0 +1,39 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_4(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: Call one(): u64 + 4: Call one(): u64 + 5: Call one(): u64 + 6: Call consume_2(u64, u64) + 7: Call consume_4(u64, u64, u64, u64) + 8: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.on.exp new file mode 100644 index 0000000000000..364c7bb1bca0e --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_03.on.exp @@ -0,0 +1,105 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::consume_4($t0: u64, $t1: u64, $t2: u64, $t3: u64) { + # live vars: $t0, $t1, $t2, $t3 + 0: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + var $t5: u64 + var $t6: u64 [unused] + var $t7: u64 [unused] + var $t8: u64 [unused] + var $t9: u64 [unused] + # live vars: + 0: $t0 := m::one() + # live vars: $t0 + 1: $t1 := m::one() + # live vars: $t0, $t1 + 2: $t2 := m::one() + # live vars: $t0, $t1, $t2 + 3: $t3 := m::one() + # live vars: $t0, $t1, $t2, $t3 + 4: $t4 := m::one() + # live vars: $t0, $t1, $t2, $t3, $t4 + 5: $t5 := m::one() + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 6: $t4 := move($t4) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 7: m::consume_2($t4, $t5) + # live vars: $t0, $t1, $t2, $t3 + 8: $t0 := move($t0) + # live vars: $t0, $t1, $t2, $t3 + 9: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3 + 10: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3 + 11: m::consume_4($t0, $t1, $t2, $t3) + # live vars: + 12: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_4(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: Call one(): u64 + 4: Call one(): u64 + 5: Call one(): u64 + 6: Call consume_2(u64, u64) + 7: Call consume_4(u64, u64, u64, u64) + 8: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.move b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.move new file mode 100644 index 0000000000000..375d799080fa8 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.move @@ -0,0 +1,20 @@ +module 0xc0ffee::m { + fun four(): (u64, u64, u64, u64) { + (1, 2, 3, 4) + } + + fun two(): (u64, u64) { + (5, 6) + } + + fun consume_4(_a: u64, _b: u64, _c: u64, _d: u64) {} + + fun consume_2(_a: u64, _b: u64) {} + + public fun test() { + let (a, b, c, d) = four(); + let (e, f) = two(); + consume_2(e, f); + consume_4(a, b, c, d); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.off.exp new file mode 100644 index 0000000000000..46c7bf5fcc507 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.off.exp @@ -0,0 +1,44 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_4(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +four(): u64 * u64 * u64 * u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: LdU64(2) + 2: LdU64(3) + 3: LdU64(4) + 4: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call four(): u64 * u64 * u64 * u64 + 1: Call two(): u64 * u64 + 2: Call consume_2(u64, u64) + 3: Call consume_4(u64, u64, u64, u64) + 4: Ret +} +two(): u64 * u64 /* def_idx: 4 */ { +B0: + 0: LdU64(5) + 1: LdU64(6) + 2: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.on.exp new file mode 100644 index 0000000000000..370d185ab5701 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_04.on.exp @@ -0,0 +1,124 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::consume_4($t0: u64, $t1: u64, $t2: u64, $t3: u64) { + # live vars: $t0, $t1, $t2, $t3 + 0: return () +} + + +[variant baseline] +fun m::four(): (u64, u64, u64, u64) { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: $t1 := 2 + # live vars: $t0, $t1 + 2: $t2 := 3 + # live vars: $t0, $t1, $t2 + 3: $t3 := 4 + # live vars: $t0, $t1, $t2, $t3 + 4: return ($t0, $t1, $t2, $t3) +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + var $t5: u64 + var $t6: u64 [unused] + var $t7: u64 [unused] + var $t8: u64 [unused] + var $t9: u64 [unused] + # live vars: + 0: ($t0, $t1, $t2, $t3) := m::four() + # live vars: $t0, $t1, $t2, $t3 + 1: ($t4, $t5) := m::two() + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 2: $t4 := move($t4) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 3: m::consume_2($t4, $t5) + # live vars: $t0, $t1, $t2, $t3 + 4: $t0 := move($t0) + # live vars: $t0, $t1, $t2, $t3 + 5: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3 + 6: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3 + 7: m::consume_4($t0, $t1, $t2, $t3) + # live vars: + 8: return () +} + + +[variant baseline] +fun m::two(): (u64, u64) { + var $t0: u64 + var $t1: u64 + # live vars: + 0: $t0 := 5 + # live vars: $t0 + 1: $t1 := 6 + # live vars: $t0, $t1 + 2: return ($t0, $t1) +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_4(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +four(): u64 * u64 * u64 * u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: LdU64(2) + 2: LdU64(3) + 3: LdU64(4) + 4: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call four(): u64 * u64 * u64 * u64 + 1: Call two(): u64 * u64 + 2: Call consume_2(u64, u64) + 3: Call consume_4(u64, u64, u64, u64) + 4: Ret +} +two(): u64 * u64 /* def_idx: 4 */ { +B0: + 0: LdU64(5) + 1: LdU64(6) + 2: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.move b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.move new file mode 100644 index 0000000000000..b22966f0c263e --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.move @@ -0,0 +1,16 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun consume_2(_a: u64, _b: u64) {} + + public fun test() { + let a = one(); + let b = one(); + let c = one(); + let d = one(); + consume_2(c, d); + consume_2(a, b); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.off.exp new file mode 100644 index 0000000000000..adaaa69807a96 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.off.exp @@ -0,0 +1,31 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: Call one(): u64 + 4: Call consume_2(u64, u64) + 5: Call consume_2(u64, u64) + 6: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.on.exp new file mode 100644 index 0000000000000..67d329497cd94 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/in_order_use_05.on.exp @@ -0,0 +1,78 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 [unused] + var $t5: u64 [unused] + # live vars: + 0: $t0 := m::one() + # live vars: $t0 + 1: $t1 := m::one() + # live vars: $t0, $t1 + 2: $t2 := m::one() + # live vars: $t0, $t1, $t2 + 3: $t3 := m::one() + # live vars: $t0, $t1, $t2, $t3 + 4: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3 + 5: m::consume_2($t2, $t3) + # live vars: $t0, $t1 + 6: $t0 := move($t0) + # live vars: $t0, $t1 + 7: m::consume_2($t0, $t1) + # live vars: + 8: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: Call one(): u64 + 4: Call consume_2(u64, u64) + 5: Call consume_2(u64, u64) + 6: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/loop_01.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/loop_01.off.exp index 3973407c4006f..332dc444699aa 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/loop_01.off.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/loop_01.off.exp @@ -14,7 +14,6 @@ B0: } public test1(Arg0: u64) /* def_idx: 1 */ { L1: loc0: u64 -L2: loc1: u64 B0: 0: MoveLoc[0](Arg0: u64) 1: Call foo(u64): u64 * u64 diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/loop_01.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/loop_01.on.exp index 9cbe17fd83e31..46fb670fc5c47 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/loop_01.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/loop_01.on.exp @@ -31,15 +31,17 @@ public fun m::test1($t0: u64) { # live vars: $t0 1: ($t1, $t0) := m::foo($t0) # live vars: $t0, $t1 - 2: $t4 := 0 + 2: $t1 := move($t1) + # live vars: $t0, $t1 + 3: $t4 := 0 # live vars: $t0, $t1, $t4 - 3: $t2 := ==($t1, $t4) + 4: $t2 := ==($t1, $t4) # live vars: $t0, $t2 - 4: if ($t2) goto 5 else goto 0 + 5: if ($t2) goto 6 else goto 0 # live vars: $t0 - 5: label L2 + 6: label L2 # live vars: - 6: return () + 7: return () } @@ -55,15 +57,17 @@ public fun m::test2($t0: u64) { # live vars: $t0 1: ($t0, $t1) := m::foo($t0) # live vars: $t0, $t1 - 2: $t4 := 0 + 2: $t1 := move($t1) + # live vars: $t0, $t1 + 3: $t4 := 0 # live vars: $t0, $t1, $t4 - 3: $t2 := ==($t1, $t4) + 4: $t2 := ==($t1, $t4) # live vars: $t0, $t2 - 4: if ($t2) goto 5 else goto 0 + 5: if ($t2) goto 6 else goto 0 # live vars: $t0 - 5: label L2 + 6: label L2 # live vars: - 6: return () + 7: return () } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_01.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_01.on.exp index beaa1a23f6fae..a0801cee7bced 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_01.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_01.on.exp @@ -48,9 +48,21 @@ public fun m::test() { # live vars: $t0, $t1, $t2, $t3, $t4, $t5 6: $t6 := m::one() # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 - 7: m::consume($t1, $t2, $t3, $t4, $t5, $t6, $t0) + 7: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 8: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 9: $t3 := move($t3) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 10: $t4 := move($t4) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 11: $t5 := move($t5) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 12: $t6 := move($t6) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5, $t6 + 13: m::consume($t1, $t2, $t3, $t4, $t5, $t6, $t0) # live vars: - 8: return () + 14: return () } @@ -70,6 +82,12 @@ B0: } public test() /* def_idx: 2 */ { L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +L6: loc6: u64 B0: 0: Call one(): u64 1: StLoc[0](loc0: u64) diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_02.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_02.on.exp index 57467a8403c5f..18fb0681de07d 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_02.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_02.on.exp @@ -29,11 +29,13 @@ public fun m::test() { # live vars: $t0 1: $t1 := m::one() # live vars: $t0, $t1 - 2: $t3 := copy($t0) + 2: $t1 := move($t1) + # live vars: $t0, $t1 + 3: $t3 := copy($t0) # live vars: $t0, $t1, $t3 - 3: m::consume($t1, $t3, $t0) + 4: m::consume($t1, $t3, $t0) # live vars: - 4: return () + 5: return () } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_03.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_03.on.exp index 5d14ab4849a09..7aedbcdd189f0 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_03.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_03.on.exp @@ -30,11 +30,13 @@ public fun m::test() { # live vars: 0: ($t0, $t1) := m::one_one() # live vars: $t0, $t1 - 1: $t3 := copy($t0) + 1: $t1 := move($t1) + # live vars: $t0, $t1 + 2: $t3 := copy($t0) # live vars: $t0, $t1, $t3 - 2: m::consume($t1, $t3, $t0) + 3: m::consume($t1, $t3, $t0) # live vars: - 3: return () + 4: return () } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_04.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_04.on.exp index a0242ca717e5d..1585a3a38f117 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_04.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_04.on.exp @@ -32,9 +32,11 @@ public fun m::test() { # live vars: $t0, $t1 2: $t2 := copy($t0) # live vars: $t0, $t1, $t2 - 3: m::consume($t2, $t1, $t0) + 3: $t1 := move($t1) + # live vars: $t0, $t1, $t2 + 4: m::consume($t2, $t1, $t0) # live vars: - 4: return () + 5: return () } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.move new file mode 100644 index 0000000000000..c58318af7fa8f --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.move @@ -0,0 +1,12 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun consume(_a: u64, _b: u64, _c: u64, _d: u64, _e: u64, _f: u64) {} + + fun test() { + let a = one(); + consume(one(), a, one(), one(), one(), one()); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.off.exp new file mode 100644 index 0000000000000..6a1af98be1263 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.off.exp @@ -0,0 +1,46 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64, Arg5: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: Ret +} +test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: StLoc[0](loc0: u64) + 3: Call one(): u64 + 4: Call one(): u64 + 5: Call one(): u64 + 6: Call one(): u64 + 7: StLoc[2](loc2: u64) + 8: StLoc[3](loc3: u64) + 9: StLoc[4](loc4: u64) + 10: StLoc[5](loc5: u64) + 11: StLoc[1](loc1: u64) + 12: MoveLoc[0](loc0: u64) + 13: MoveLoc[1](loc1: u64) + 14: MoveLoc[5](loc5: u64) + 15: MoveLoc[4](loc4: u64) + 16: MoveLoc[3](loc3: u64) + 17: MoveLoc[2](loc2: u64) + 18: Call consume(u64, u64, u64, u64, u64, u64) + 19: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.on.exp new file mode 100644 index 0000000000000..ab65189fed4db --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_05.on.exp @@ -0,0 +1,80 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume($t0: u64, $t1: u64, $t2: u64, $t3: u64, $t4: u64, $t5: u64) { + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 0: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 [unused] + var $t3: u64 + var $t4: u64 + var $t5: u64 + var $t6: u64 + # flush: $t0 + # live vars: + 0: $t0 := m::one() + # live vars: $t0 + 1: $t1 := m::one() + # live vars: $t0, $t1 + 2: $t0 := move($t0) + # live vars: $t0, $t1 + 3: $t3 := m::one() + # live vars: $t0, $t1, $t3 + 4: $t4 := m::one() + # live vars: $t0, $t1, $t3, $t4 + 5: $t5 := m::one() + # live vars: $t0, $t1, $t3, $t4, $t5 + 6: $t6 := m::one() + # live vars: $t0, $t1, $t3, $t4, $t5, $t6 + 7: m::consume($t1, $t0, $t3, $t4, $t5, $t6) + # live vars: + 8: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64, Arg5: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: Ret +} +test() /* def_idx: 2 */ { +L0: loc0: u64 +B0: + 0: Call one(): u64 + 1: StLoc[0](loc0: u64) + 2: Call one(): u64 + 3: MoveLoc[0](loc0: u64) + 4: Call one(): u64 + 5: Call one(): u64 + 6: Call one(): u64 + 7: Call one(): u64 + 8: Call consume(u64, u64, u64, u64, u64, u64) + 9: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.move new file mode 100644 index 0000000000000..29c7ea29c4794 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.move @@ -0,0 +1,17 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun multi(): (u64, u64, u64, u64, u64, u64) { + (one(), one(), one(), one(), one(), one()) + } + + fun consume(_a: u64, _b: u64, _c: u64, _d: u64, _e: u64, _f: u64) {} + + fun test() { + let (a, _, _, _, _, _) = multi(); + consume(one(), a, one(), one(), one(), one()); + } + +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.off.exp new file mode 100644 index 0000000000000..9f2742cf0f927 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.off.exp @@ -0,0 +1,61 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64, Arg5: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +multi(): u64 * u64 * u64 * u64 * u64 * u64 /* def_idx: 1 */ { +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: Call one(): u64 + 4: Call one(): u64 + 5: Call one(): u64 + 6: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call multi(): u64 * u64 * u64 * u64 * u64 * u64 + 1: Call one(): u64 + 2: StLoc[0](loc0: u64) + 3: Pop + 4: Pop + 5: Pop + 6: Pop + 7: Pop + 8: Call one(): u64 + 9: Call one(): u64 + 10: Call one(): u64 + 11: Call one(): u64 + 12: StLoc[2](loc2: u64) + 13: StLoc[3](loc3: u64) + 14: StLoc[4](loc4: u64) + 15: StLoc[5](loc5: u64) + 16: StLoc[1](loc1: u64) + 17: MoveLoc[0](loc0: u64) + 18: MoveLoc[1](loc1: u64) + 19: MoveLoc[5](loc5: u64) + 20: MoveLoc[4](loc4: u64) + 21: MoveLoc[3](loc3: u64) + 22: MoveLoc[2](loc2: u64) + 23: Call consume(u64, u64, u64, u64, u64, u64) + 24: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.on.exp new file mode 100644 index 0000000000000..24a550fdd557b --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_06.on.exp @@ -0,0 +1,125 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume($t0: u64, $t1: u64, $t2: u64, $t3: u64, $t4: u64, $t5: u64) { + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 0: return () +} + + +[variant baseline] +fun m::multi(): (u64, u64, u64, u64, u64, u64) { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + var $t5: u64 + # live vars: + 0: $t0 := m::one() + # live vars: $t0 + 1: $t1 := m::one() + # live vars: $t0, $t1 + 2: $t2 := m::one() + # live vars: $t0, $t1, $t2 + 3: $t3 := m::one() + # live vars: $t0, $t1, $t2, $t3 + 4: $t4 := m::one() + # live vars: $t0, $t1, $t2, $t3, $t4 + 5: $t5 := m::one() + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 6: return ($t0, $t1, $t2, $t3, $t4, $t5) +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + var $t5: u64 + var $t6: u64 + var $t7: u64 [unused] + var $t8: u64 + var $t9: u64 + var $t10: u64 + var $t11: u64 + # flush: $t0, $t1, $t2, $t3, $t4, $t5 + # live vars: + 0: ($t0, $t1, $t2, $t3, $t4, $t5) := m::multi() + # live vars: $t0 + 1: $t6 := m::one() + # live vars: $t0, $t6 + 2: $t0 := move($t0) + # live vars: $t0, $t6 + 3: $t8 := m::one() + # live vars: $t0, $t6, $t8 + 4: $t9 := m::one() + # live vars: $t0, $t6, $t8, $t9 + 5: $t10 := m::one() + # live vars: $t0, $t6, $t8, $t9, $t10 + 6: $t11 := m::one() + # live vars: $t0, $t6, $t8, $t9, $t10, $t11 + 7: m::consume($t6, $t0, $t8, $t9, $t10, $t11) + # live vars: + 8: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64, Arg5: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +multi(): u64 * u64 * u64 * u64 * u64 * u64 /* def_idx: 1 */ { +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: Call one(): u64 + 4: Call one(): u64 + 5: Call one(): u64 + 6: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +test() /* def_idx: 3 */ { +L0: loc0: u64 +B0: + 0: Call multi(): u64 * u64 * u64 * u64 * u64 * u64 + 1: Pop + 2: Pop + 3: Pop + 4: Pop + 5: Pop + 6: StLoc[0](loc0: u64) + 7: Call one(): u64 + 8: MoveLoc[0](loc0: u64) + 9: Call one(): u64 + 10: Call one(): u64 + 11: Call one(): u64 + 12: Call one(): u64 + 13: Call consume(u64, u64, u64, u64, u64, u64) + 14: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.move new file mode 100644 index 0000000000000..d62db319beca5 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.move @@ -0,0 +1,20 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun consume_4(_a: u64, _b: u64, _c: u64, _d: u64) {} + + fun consume_2(_a: u64, _b: u64) {} + + public fun test() { + let a = one(); + let b = one(); + let c = one(); + let d = one(); + let e = one(); + let f = one(); + consume_4(a, b, c, d); + consume_2(e, f); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.off.exp new file mode 100644 index 0000000000000..d63b91d766514 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.off.exp @@ -0,0 +1,43 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_4(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: Call one(): u64 + 4: Call one(): u64 + 5: Call one(): u64 + 6: StLoc[0](loc0: u64) + 7: StLoc[1](loc1: u64) + 8: Call consume_4(u64, u64, u64, u64) + 9: MoveLoc[1](loc1: u64) + 10: MoveLoc[0](loc0: u64) + 11: Call consume_2(u64, u64) + 12: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.on.exp new file mode 100644 index 0000000000000..1df16be00b82b --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_07.on.exp @@ -0,0 +1,109 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::consume_4($t0: u64, $t1: u64, $t2: u64, $t3: u64) { + # live vars: $t0, $t1, $t2, $t3 + 0: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + var $t5: u64 + var $t6: u64 [unused] + var $t7: u64 [unused] + var $t8: u64 [unused] + var $t9: u64 [unused] + # live vars: + 0: $t0 := m::one() + # live vars: $t0 + 1: $t1 := m::one() + # live vars: $t0, $t1 + 2: $t2 := m::one() + # live vars: $t0, $t1, $t2 + 3: $t3 := m::one() + # live vars: $t0, $t1, $t2, $t3 + 4: $t4 := m::one() + # live vars: $t0, $t1, $t2, $t3, $t4 + 5: $t5 := m::one() + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 6: $t0 := move($t0) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 7: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 8: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 9: m::consume_4($t0, $t1, $t2, $t3) + # live vars: $t4, $t5 + 10: $t4 := move($t4) + # live vars: $t4, $t5 + 11: m::consume_2($t4, $t5) + # live vars: + 12: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_4(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: Call one(): u64 + 4: Call one(): u64 + 5: Call one(): u64 + 6: StLoc[0](loc0: u64) + 7: StLoc[1](loc1: u64) + 8: Call consume_4(u64, u64, u64, u64) + 9: MoveLoc[1](loc1: u64) + 10: MoveLoc[0](loc0: u64) + 11: Call consume_2(u64, u64) + 12: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.move new file mode 100644 index 0000000000000..2eb816707f27d --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.move @@ -0,0 +1,20 @@ +module 0xc0ffee::m { + fun four(): (u64, u64, u64, u64) { + (1, 2, 3, 4) + } + + fun two(): (u64, u64) { + (5, 6) + } + + fun consume_4(_a: u64, _b: u64, _c: u64, _d: u64) {} + + fun consume_2(_a: u64, _b: u64) {} + + public fun test() { + let (a, b, c, d) = four(); + let (e, f) = two(); + consume_4(a, b, c, d); + consume_2(e, f); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.off.exp new file mode 100644 index 0000000000000..22c7c8a2ddccd --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.off.exp @@ -0,0 +1,48 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_4(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +four(): u64 * u64 * u64 * u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: LdU64(2) + 2: LdU64(3) + 3: LdU64(4) + 4: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call four(): u64 * u64 * u64 * u64 + 1: Call two(): u64 * u64 + 2: StLoc[0](loc0: u64) + 3: StLoc[1](loc1: u64) + 4: Call consume_4(u64, u64, u64, u64) + 5: MoveLoc[1](loc1: u64) + 6: MoveLoc[0](loc0: u64) + 7: Call consume_2(u64, u64) + 8: Ret +} +two(): u64 * u64 /* def_idx: 4 */ { +B0: + 0: LdU64(5) + 1: LdU64(6) + 2: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.on.exp new file mode 100644 index 0000000000000..0f19b30d3a6e9 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_08.on.exp @@ -0,0 +1,128 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::consume_4($t0: u64, $t1: u64, $t2: u64, $t3: u64) { + # live vars: $t0, $t1, $t2, $t3 + 0: return () +} + + +[variant baseline] +fun m::four(): (u64, u64, u64, u64) { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: $t1 := 2 + # live vars: $t0, $t1 + 2: $t2 := 3 + # live vars: $t0, $t1, $t2 + 3: $t3 := 4 + # live vars: $t0, $t1, $t2, $t3 + 4: return ($t0, $t1, $t2, $t3) +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + var $t5: u64 + var $t6: u64 [unused] + var $t7: u64 [unused] + var $t8: u64 [unused] + var $t9: u64 [unused] + # live vars: + 0: ($t0, $t1, $t2, $t3) := m::four() + # live vars: $t0, $t1, $t2, $t3 + 1: ($t4, $t5) := m::two() + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 2: $t0 := move($t0) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 3: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 4: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 5: m::consume_4($t0, $t1, $t2, $t3) + # live vars: $t4, $t5 + 6: $t4 := move($t4) + # live vars: $t4, $t5 + 7: m::consume_2($t4, $t5) + # live vars: + 8: return () +} + + +[variant baseline] +fun m::two(): (u64, u64) { + var $t0: u64 + var $t1: u64 + # live vars: + 0: $t0 := 5 + # live vars: $t0 + 1: $t1 := 6 + # live vars: $t0, $t1 + 2: return ($t0, $t1) +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_4(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +four(): u64 * u64 * u64 * u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: LdU64(2) + 2: LdU64(3) + 3: LdU64(4) + 4: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call four(): u64 * u64 * u64 * u64 + 1: Call two(): u64 * u64 + 2: StLoc[0](loc0: u64) + 3: StLoc[1](loc1: u64) + 4: Call consume_4(u64, u64, u64, u64) + 5: MoveLoc[1](loc1: u64) + 6: MoveLoc[0](loc0: u64) + 7: Call consume_2(u64, u64) + 8: Ret +} +two(): u64 * u64 /* def_idx: 4 */ { +B0: + 0: LdU64(5) + 1: LdU64(6) + 2: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.move new file mode 100644 index 0000000000000..86945bdc17486 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.move @@ -0,0 +1,20 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun consume_5(_a: u64, _b: u64, _c: u64, _d: u64, _e: u64) {} + + fun consume_1(_a: u64) {} + + public fun test() { + let a = one(); + let b = one(); + let c = one(); + let d = one(); + let e = one(); + let f = one(); + consume_5(a, c, d, e, f); + consume_1(b); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.off.exp new file mode 100644 index 0000000000000..0ca184f2da5ed --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.off.exp @@ -0,0 +1,49 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_5(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: Call one(): u64 + 4: Call one(): u64 + 5: Call one(): u64 + 6: StLoc[0](loc0: u64) + 7: StLoc[1](loc1: u64) + 8: StLoc[2](loc2: u64) + 9: StLoc[3](loc3: u64) + 10: StLoc[4](loc4: u64) + 11: MoveLoc[3](loc3: u64) + 12: MoveLoc[2](loc2: u64) + 13: MoveLoc[1](loc1: u64) + 14: MoveLoc[0](loc0: u64) + 15: Call consume_5(u64, u64, u64, u64, u64) + 16: MoveLoc[4](loc4: u64) + 17: Call consume_1(u64) + 18: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.on.exp new file mode 100644 index 0000000000000..401a796eaaa51 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_09.on.exp @@ -0,0 +1,108 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_1($t0: u64) { + # live vars: $t0 + 0: return () +} + + +[variant baseline] +fun m::consume_5($t0: u64, $t1: u64, $t2: u64, $t3: u64, $t4: u64) { + # live vars: $t0, $t1, $t2, $t3, $t4 + 0: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + var $t5: u64 + var $t6: u64 [unused] + var $t7: u64 [unused] + var $t8: u64 [unused] + var $t9: u64 [unused] + # live vars: + 0: $t0 := m::one() + # flush: $t1 + # live vars: $t0 + 1: $t1 := m::one() + # live vars: $t0, $t1 + 2: $t2 := m::one() + # live vars: $t0, $t1, $t2 + 3: $t3 := m::one() + # live vars: $t0, $t1, $t2, $t3 + 4: $t4 := m::one() + # live vars: $t0, $t1, $t2, $t3, $t4 + 5: $t5 := m::one() + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 6: $t0 := move($t0) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 7: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 8: $t3 := move($t3) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 9: $t4 := move($t4) + # live vars: $t0, $t1, $t2, $t3, $t4, $t5 + 10: m::consume_5($t0, $t2, $t3, $t4, $t5) + # live vars: $t1 + 11: m::consume_1($t1) + # live vars: + 12: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_5(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +L5: loc5: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: StLoc[0](loc0: u64) + 3: Call one(): u64 + 4: Call one(): u64 + 5: Call one(): u64 + 6: Call one(): u64 + 7: Call consume_5(u64, u64, u64, u64, u64) + 8: MoveLoc[0](loc0: u64) + 9: Call consume_1(u64) + 10: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.move new file mode 100644 index 0000000000000..11032f93f7807 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.move @@ -0,0 +1,17 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun consume_1(_a: u64) {} + + fun consume_2(_a: u64, _b: u64) {} + + public fun test() { + let a = one(); + let b = one(); + let c = one(); + consume_1(a); + consume_2(b, c); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.off.exp new file mode 100644 index 0000000000000..4602125e99d23 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.off.exp @@ -0,0 +1,37 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: StLoc[0](loc0: u64) + 4: StLoc[1](loc1: u64) + 5: Call consume_1(u64) + 6: MoveLoc[1](loc1: u64) + 7: MoveLoc[0](loc0: u64) + 8: Call consume_2(u64, u64) + 9: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.on.exp new file mode 100644 index 0000000000000..f9e9151c181a1 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_10.on.exp @@ -0,0 +1,84 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_1($t0: u64) { + # live vars: $t0 + 0: return () +} + + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 [unused] + # flush: $t0 + # live vars: + 0: $t0 := m::one() + # live vars: $t0 + 1: $t1 := m::one() + # live vars: $t0, $t1 + 2: $t2 := m::one() + # live vars: $t0, $t1, $t2 + 3: m::consume_1($t0) + # live vars: $t1, $t2 + 4: $t1 := move($t1) + # live vars: $t1, $t2 + 5: m::consume_2($t1, $t2) + # live vars: + 6: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +B0: + 0: Call one(): u64 + 1: StLoc[0](loc0: u64) + 2: Call one(): u64 + 3: Call one(): u64 + 4: MoveLoc[0](loc0: u64) + 5: Call consume_1(u64) + 6: Call consume_2(u64, u64) + 7: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.move new file mode 100644 index 0000000000000..44cde4f898c6e --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.move @@ -0,0 +1,14 @@ +module 0xc0ffee::m { + fun one_one(): (u64, u64) { + (1, 1) + } + + fun consume_2(_a: u64, _b: u64) {} + + public fun test() { + let (a, b) = one_one(); + let (c, d) = one_one(); + consume_2(b, c); + consume_2(a, d); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.off.exp new file mode 100644 index 0000000000000..442054aba4067 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.off.exp @@ -0,0 +1,31 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +one_one(): u64 * u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: LdU64(1) + 2: Ret +} +public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +B0: + 0: Call one_one(): u64 * u64 + 1: Call one_one(): u64 * u64 + 2: StLoc[0](loc0: u64) + 3: Call consume_2(u64, u64) + 4: MoveLoc[0](loc0: u64) + 5: Call consume_2(u64, u64) + 6: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.on.exp new file mode 100644 index 0000000000000..ffd0d924d6c96 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_11.on.exp @@ -0,0 +1,77 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::one_one(): (u64, u64) { + var $t0: u64 + var $t1: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: $t1 := 1 + # live vars: $t0, $t1 + 2: return ($t0, $t1) +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 [unused] + var $t5: u64 [unused] + # live vars: + 0: ($t0, $t1) := m::one_one() + # live vars: $t0, $t1 + 1: ($t2, $t3) := m::one_one() + # live vars: $t0, $t1, $t2, $t3 + 2: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3 + 3: m::consume_2($t1, $t2) + # live vars: $t0, $t3 + 4: $t0 := move($t0) + # live vars: $t0, $t3 + 5: m::consume_2($t0, $t3) + # live vars: + 6: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +one_one(): u64 * u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: LdU64(1) + 2: Ret +} +public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +B0: + 0: Call one_one(): u64 * u64 + 1: Call one_one(): u64 * u64 + 2: StLoc[0](loc0: u64) + 3: Call consume_2(u64, u64) + 4: MoveLoc[0](loc0: u64) + 5: Call consume_2(u64, u64) + 6: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.move new file mode 100644 index 0000000000000..2c7907bfad8d7 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.move @@ -0,0 +1,16 @@ +module 0xc0ffee::m { + fun one_one(): (u64, u64) { + (1, 1) + } + + fun consume_3(_a: u64, _b: u64, _c: u64) {} + + fun consume_1(_a: u64) {} + + public fun test() { + let (a, b) = one_one(); + let (c, d) = one_one(); + consume_3(a, c, d); + consume_1(b); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.off.exp new file mode 100644 index 0000000000000..bce0e4f95c483 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.off.exp @@ -0,0 +1,40 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_3(Arg0: u64, Arg1: u64, Arg2: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one_one(): u64 * u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: LdU64(1) + 2: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +B0: + 0: Call one_one(): u64 * u64 + 1: Call one_one(): u64 * u64 + 2: StLoc[0](loc0: u64) + 3: StLoc[1](loc1: u64) + 4: StLoc[2](loc2: u64) + 5: MoveLoc[1](loc1: u64) + 6: MoveLoc[0](loc0: u64) + 7: Call consume_3(u64, u64, u64) + 8: MoveLoc[2](loc2: u64) + 9: Call consume_1(u64) + 10: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.on.exp new file mode 100644 index 0000000000000..4dd31916ff1d9 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_12.on.exp @@ -0,0 +1,90 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_1($t0: u64) { + # live vars: $t0 + 0: return () +} + + +[variant baseline] +fun m::consume_3($t0: u64, $t1: u64, $t2: u64) { + # live vars: $t0, $t1, $t2 + 0: return () +} + + +[variant baseline] +fun m::one_one(): (u64, u64) { + var $t0: u64 + var $t1: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: $t1 := 1 + # live vars: $t0, $t1 + 2: return ($t0, $t1) +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 [unused] + var $t5: u64 [unused] + # flush: $t1 + # live vars: + 0: ($t0, $t1) := m::one_one() + # live vars: $t0, $t1 + 1: ($t2, $t3) := m::one_one() + # live vars: $t0, $t1, $t2, $t3 + 2: $t0 := move($t0) + # live vars: $t0, $t1, $t2, $t3 + 3: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3 + 4: m::consume_3($t0, $t2, $t3) + # live vars: $t1 + 5: m::consume_1($t1) + # live vars: + 6: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_3(Arg0: u64, Arg1: u64, Arg2: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one_one(): u64 * u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: LdU64(1) + 2: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +B0: + 0: Call one_one(): u64 * u64 + 1: StLoc[0](loc0: u64) + 2: Call one_one(): u64 * u64 + 3: Call consume_3(u64, u64, u64) + 4: MoveLoc[0](loc0: u64) + 5: Call consume_1(u64) + 6: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.move new file mode 100644 index 0000000000000..c03fefbf8c543 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.move @@ -0,0 +1,17 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun consume_1(_a: u64) {} + + fun consume_2(_a: u64, _b: u64) {} + + public fun test() { + let a = one(); + let b = one(); + let c = one(); + consume_2(a, b); + consume_1(c); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.off.exp new file mode 100644 index 0000000000000..f368f1cc006aa --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.off.exp @@ -0,0 +1,35 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: StLoc[0](loc0: u64) + 4: Call consume_2(u64, u64) + 5: MoveLoc[0](loc0: u64) + 6: Call consume_1(u64) + 7: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.on.exp new file mode 100644 index 0000000000000..b16ecb68430dd --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_13.on.exp @@ -0,0 +1,84 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_1($t0: u64) { + # live vars: $t0 + 0: return () +} + + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 [unused] + # live vars: + 0: $t0 := m::one() + # live vars: $t0 + 1: $t1 := m::one() + # flush: $t2 + # live vars: $t0, $t1 + 2: $t2 := m::one() + # live vars: $t0, $t1, $t2 + 3: $t0 := move($t0) + # live vars: $t0, $t1, $t2 + 4: m::consume_2($t0, $t1) + # live vars: $t2 + 5: m::consume_1($t2) + # live vars: + 6: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test() /* def_idx: 3 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: Call one(): u64 + 3: StLoc[0](loc0: u64) + 4: Call consume_2(u64, u64) + 5: MoveLoc[0](loc0: u64) + 6: Call consume_1(u64) + 7: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.move new file mode 100644 index 0000000000000..e281816343b18 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.move @@ -0,0 +1,16 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun consume_1(_a: u64) {} + + fun consume_2(_a: u64, _b: u64) {} + + public fun test(a: u64) { + let b = one(); + let c = one(); + consume_2(a, b); + consume_1(c); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.off.exp new file mode 100644 index 0000000000000..20243548f05d2 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.off.exp @@ -0,0 +1,36 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test(Arg0: u64) /* def_idx: 3 */ { +L1: loc0: u64 +L2: loc1: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: StLoc[1](loc0: u64) + 3: StLoc[2](loc1: u64) + 4: MoveLoc[0](Arg0: u64) + 5: MoveLoc[2](loc1: u64) + 6: Call consume_2(u64, u64) + 7: MoveLoc[1](loc0: u64) + 8: Call consume_1(u64) + 9: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.on.exp new file mode 100644 index 0000000000000..e5b3207e2c775 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_14.on.exp @@ -0,0 +1,79 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_1($t0: u64) { + # live vars: $t0 + 0: return () +} + + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +public fun m::test($t0: u64) { + var $t1: u64 + var $t2: u64 + var $t3: u64 [unused] + # flush: $t1 + # live vars: $t0 + 0: $t1 := m::one() + # live vars: $t0, $t1 + 1: $t2 := m::one() + # live vars: $t0, $t1, $t2 + 2: $t0 := move($t0) + # live vars: $t0, $t1, $t2 + 3: m::consume_2($t0, $t1) + # live vars: $t2 + 4: m::consume_1($t2) + # live vars: + 5: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test(Arg0: u64) /* def_idx: 3 */ { +L1: loc0: u64 +B0: + 0: Call one(): u64 + 1: StLoc[1](loc0: u64) + 2: Call one(): u64 + 3: MoveLoc[0](Arg0: u64) + 4: MoveLoc[1](loc0: u64) + 5: Call consume_2(u64, u64) + 6: Call consume_1(u64) + 7: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.move b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.move new file mode 100644 index 0000000000000..5db396c348240 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.move @@ -0,0 +1,16 @@ +module 0xc0ffee::m { + fun one(): u64 { + 1 + } + + fun consume_1(_a: u64) {} + + fun consume_2(_a: u64, _b: u64) {} + + public fun test(a: u64) { + let b = one(); + let c = one(); + consume_1(a); + consume_2(b, c); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.off.exp new file mode 100644 index 0000000000000..6cb9e30e4d6c3 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.off.exp @@ -0,0 +1,32 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test(Arg0: u64) /* def_idx: 3 */ { +L1: loc0: u64 +L2: loc1: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: MoveLoc[0](Arg0: u64) + 3: Call consume_1(u64) + 4: Call consume_2(u64, u64) + 5: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.on.exp new file mode 100644 index 0000000000000..402ef1b36188b --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/out_of_order_use_15.on.exp @@ -0,0 +1,77 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume_1($t0: u64) { + # live vars: $t0 + 0: return () +} + + +[variant baseline] +fun m::consume_2($t0: u64, $t1: u64) { + # live vars: $t0, $t1 + 0: return () +} + + +[variant baseline] +fun m::one(): u64 { + var $t0: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: return $t0 +} + + +[variant baseline] +public fun m::test($t0: u64) { + var $t1: u64 + var $t2: u64 + var $t3: u64 [unused] + # live vars: $t0 + 0: $t1 := m::one() + # live vars: $t0, $t1 + 1: $t2 := m::one() + # live vars: $t0, $t1, $t2 + 2: m::consume_1($t0) + # live vars: $t1, $t2 + 3: $t1 := move($t1) + # live vars: $t1, $t2 + 4: m::consume_2($t1, $t2) + # live vars: + 5: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume_1(Arg0: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +consume_2(Arg0: u64, Arg1: u64) /* def_idx: 1 */ { +B0: + 0: Ret +} +one(): u64 /* def_idx: 2 */ { +B0: + 0: LdU64(1) + 1: Ret +} +public test(Arg0: u64) /* def_idx: 3 */ { +L1: loc0: u64 +L2: loc1: u64 +B0: + 0: Call one(): u64 + 1: Call one(): u64 + 2: MoveLoc[0](Arg0: u64) + 3: Call consume_1(u64) + 4: Call consume_2(u64, u64) + 5: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.move b/third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.move new file mode 100644 index 0000000000000..24cc6772def53 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.move @@ -0,0 +1,12 @@ +module 0xc0ffee::m { + fun foo(): (u64, u64, u64, u64, u64) { + (1, 2, 3, 4, 5) + } + + fun consume(_a: u64, _b: u64, _c: u64, _d: u64, _e: u64) {} + + public fun test() { + let (a, b, c, d, e) = foo(); + consume(a, b, c, d, e); + } +} diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.off.exp new file mode 100644 index 0000000000000..249f372aff360 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.off.exp @@ -0,0 +1,32 @@ + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +foo(): u64 * u64 * u64 * u64 * u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: LdU64(2) + 2: LdU64(3) + 3: LdU64(4) + 4: LdU64(5) + 5: Ret +} +public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +B0: + 0: Call foo(): u64 * u64 * u64 * u64 * u64 + 1: Call consume(u64, u64, u64, u64, u64) + 2: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.on.exp new file mode 100644 index 0000000000000..32b4c53436a38 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/flush-writes/tuples_in_order_use_01.on.exp @@ -0,0 +1,90 @@ +============ after FlushWritesProcessor: ================ + +[variant baseline] +fun m::consume($t0: u64, $t1: u64, $t2: u64, $t3: u64, $t4: u64) { + # live vars: $t0, $t1, $t2, $t3, $t4 + 0: return () +} + + +[variant baseline] +fun m::foo(): (u64, u64, u64, u64, u64) { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + # live vars: + 0: $t0 := 1 + # live vars: $t0 + 1: $t1 := 2 + # live vars: $t0, $t1 + 2: $t2 := 3 + # live vars: $t0, $t1, $t2 + 3: $t3 := 4 + # live vars: $t0, $t1, $t2, $t3 + 4: $t4 := 5 + # live vars: $t0, $t1, $t2, $t3, $t4 + 5: return ($t0, $t1, $t2, $t3, $t4) +} + + +[variant baseline] +public fun m::test() { + var $t0: u64 + var $t1: u64 + var $t2: u64 + var $t3: u64 + var $t4: u64 + var $t5: u64 [unused] + var $t6: u64 [unused] + var $t7: u64 [unused] + var $t8: u64 [unused] + # live vars: + 0: ($t0, $t1, $t2, $t3, $t4) := m::foo() + # live vars: $t0, $t1, $t2, $t3, $t4 + 1: $t0 := move($t0) + # live vars: $t0, $t1, $t2, $t3, $t4 + 2: $t1 := move($t1) + # live vars: $t0, $t1, $t2, $t3, $t4 + 3: $t2 := move($t2) + # live vars: $t0, $t1, $t2, $t3, $t4 + 4: $t3 := move($t3) + # live vars: $t0, $t1, $t2, $t3, $t4 + 5: m::consume($t0, $t1, $t2, $t3, $t4) + # live vars: + 6: return () +} + + +============ disassembled file-format ================== +// Move bytecode v8 +module c0ffee.m { + + +consume(Arg0: u64, Arg1: u64, Arg2: u64, Arg3: u64, Arg4: u64) /* def_idx: 0 */ { +B0: + 0: Ret +} +foo(): u64 * u64 * u64 * u64 * u64 /* def_idx: 1 */ { +B0: + 0: LdU64(1) + 1: LdU64(2) + 2: LdU64(3) + 3: LdU64(4) + 4: LdU64(5) + 5: Ret +} +public test() /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 +L3: loc3: u64 +L4: loc4: u64 +B0: + 0: Call foo(): u64 * u64 * u64 * u64 * u64 + 1: Call consume(u64, u64, u64, u64, u64) + 2: Ret +} +} +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_01.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_01.on.exp index c9d248f08dca0..f97a7d11693dc 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_01.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_01.on.exp @@ -25,7 +25,9 @@ public fun m::test1(): (u64, u64) { # live vars: $t3 2: $t4 := m::one() # live vars: $t3, $t4 - 3: return ($t3, $t4) + 3: $t3 := move($t3) + # live vars: $t3, $t4 + 4: return ($t3, $t4) } @@ -44,7 +46,9 @@ public fun m::test2(): (u64, u64) { # live vars: $t2 2: $t4 := m::one() # live vars: $t2, $t4 - 3: return ($t2, $t4) + 3: $t2 := move($t2) + # live vars: $t2, $t4 + 4: return ($t2, $t4) } @@ -64,7 +68,9 @@ public fun m::test3(): (u64, u64) { # live vars: $t2 2: $t4 := m::one() # live vars: $t2, $t4 - 3: return ($t4, $t2) + 3: $t4 := move($t4) + # live vars: $t2, $t4 + 4: return ($t4, $t2) } @@ -79,6 +85,8 @@ B0: 1: Ret } public test1(): u64 * u64 /* def_idx: 1 */ { +L0: loc0: u64 +L1: loc1: u64 B0: 0: Call one(): u64 1: Pop @@ -87,6 +95,8 @@ B0: 4: Ret } public test2(): u64 * u64 /* def_idx: 2 */ { +L0: loc0: u64 +L1: loc1: u64 B0: 0: Call one(): u64 1: Call one(): u64 diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.off.exp index 4058648feefbf..b419aa2dd397a 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.off.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.off.exp @@ -16,27 +16,26 @@ B0: public test(): u64 * u64 /* def_idx: 2 */ { L0: loc0: u64 L1: loc1: u64 -L2: loc2: u64 -L3: loc3: bool -L4: loc4: u64 +L2: loc2: bool +L3: loc3: u64 B0: 0: Call one(): u64 1: Call one(): u64 2: Call one(): u64 - 3: StLoc[1](loc1: u64) + 3: StLoc[0](loc0: u64) 4: LdU64(0) 5: Eq - 6: StLoc[3](loc3: bool) - 7: StLoc[4](loc4: u64) - 8: MoveLoc[3](loc3: bool) + 6: StLoc[2](loc2: bool) + 7: StLoc[3](loc3: u64) + 8: MoveLoc[2](loc2: bool) 9: BrTrue(11) B1: 10: Branch(12) B2: 11: Call bar() B3: - 12: MoveLoc[4](loc4: u64) - 13: MoveLoc[1](loc1: u64) + 12: MoveLoc[3](loc3: u64) + 13: MoveLoc[0](loc0: u64) 14: Ret } } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.on.exp index ea75eda12850a..ba2457bd04348 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.on.exp @@ -36,25 +36,25 @@ public fun m::test(): (u64, u64) { # live vars: $t2, $t3 2: $t4 := m::one() # live vars: $t2, $t3, $t4 - 3: $t7 := 0 + 3: $t3 := move($t3) + # live vars: $t2, $t3, $t4 + 4: $t7 := 0 # live vars: $t2, $t3, $t4, $t7 - 4: $t5 := ==($t3, $t7) + 5: $t5 := ==($t3, $t7) # live vars: $t2, $t4, $t5 - 5: if ($t5) goto 8 else goto 6 - # live vars: $t2, $t4 - 6: label L3 + 6: if ($t5) goto 9 else goto 7 # live vars: $t2, $t4 - 7: goto 10 + 7: label L3 # live vars: $t2, $t4 - 8: label L0 + 8: goto 11 # live vars: $t2, $t4 - 9: m::bar() + 9: label L0 # live vars: $t2, $t4 - 10: label L2 + 10: m::bar() # live vars: $t2, $t4 - 11: $t2 := move($t2) + 11: label L2 # live vars: $t2, $t4 - 12: $t4 := move($t4) + 12: $t2 := move($t2) # live vars: $t2, $t4 13: return ($t2, $t4) } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.off.exp index 4391ac5b2a293..d7e68815531cc 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.off.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.off.exp @@ -19,11 +19,10 @@ public test1() /* def_idx: 2 */ { L0: loc0: u64 L1: loc1: u64 L2: loc2: u64 -L3: loc3: u64 B0: 0: Call foo(): u64 * u64 * u64 - 1: StLoc[1](loc1: u64) - 2: StLoc[2](loc2: u64) + 1: StLoc[0](loc0: u64) + 2: StLoc[1](loc1: u64) 3: LdU64(0) 4: Eq 5: BrTrue(7) @@ -32,7 +31,7 @@ B1: B2: 7: Call bar() B3: - 8: MoveLoc[2](loc2: u64) + 8: MoveLoc[1](loc1: u64) 9: LdU64(0) 10: Eq 11: BrTrue(13) @@ -41,7 +40,7 @@ B4: B5: 13: Call bar() B6: - 14: MoveLoc[1](loc1: u64) + 14: MoveLoc[0](loc0: u64) 15: LdU64(0) 16: Eq 17: BrTrue(19) diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.on.exp index 3191cdbd8a588..2e3176d611f29 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.on.exp @@ -41,59 +41,61 @@ public fun m::test1() { # live vars: 0: ($t0, $t1, $t2) := m::foo() # live vars: $t0, $t1, $t2 - 1: $t5 := 0 + 1: $t0 := move($t0) + # live vars: $t0, $t1, $t2 + 2: $t5 := 0 # live vars: $t0, $t1, $t2, $t5 - 2: $t3 := ==($t0, $t5) + 3: $t3 := ==($t0, $t5) # live vars: $t1, $t2, $t3 - 3: if ($t3) goto 6 else goto 4 + 4: if ($t3) goto 7 else goto 5 # live vars: $t1, $t2 - 4: label L9 + 5: label L9 # live vars: $t1, $t2 - 5: goto 8 + 6: goto 9 # live vars: $t1, $t2 - 6: label L0 + 7: label L0 # live vars: $t1, $t2 - 7: m::bar() + 8: m::bar() # live vars: $t1, $t2 - 8: label L2 + 9: label L2 # live vars: $t1, $t2 - 9: $t1 := move($t1) + 10: $t1 := move($t1) # live vars: $t1, $t2 - 10: $t0 := 0 + 11: $t0 := 0 # live vars: $t0, $t1, $t2 - 11: $t3 := ==($t1, $t0) + 12: $t3 := ==($t1, $t0) # live vars: $t2, $t3 - 12: if ($t3) goto 15 else goto 13 + 13: if ($t3) goto 16 else goto 14 # live vars: $t2 - 13: label L10 + 14: label L10 # live vars: $t2 - 14: goto 17 + 15: goto 18 # live vars: $t2 - 15: label L3 + 16: label L3 # live vars: $t2 - 16: m::bar() + 17: m::bar() # live vars: $t2 - 17: label L5 + 18: label L5 # live vars: $t2 - 18: $t2 := move($t2) + 19: $t2 := move($t2) # live vars: $t2 - 19: $t0 := 0 + 20: $t0 := 0 # live vars: $t0, $t2 - 20: $t3 := ==($t2, $t0) + 21: $t3 := ==($t2, $t0) # live vars: $t3 - 21: if ($t3) goto 24 else goto 22 + 22: if ($t3) goto 25 else goto 23 # live vars: - 22: label L11 + 23: label L11 # live vars: - 23: goto 26 + 24: goto 27 # live vars: - 24: label L6 + 25: label L6 # live vars: - 25: m::bar() + 26: m::bar() # live vars: - 26: label L8 + 27: label L8 # live vars: - 27: return () + 28: return () } diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/write_ref_01.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/write_ref_01.on.exp index 7f51244bae81b..f5c87396dc563 100644 --- a/third_party/move/move-compiler-v2/tests/flush-writes/write_ref_01.on.exp +++ b/third_party/move/move-compiler-v2/tests/flush-writes/write_ref_01.on.exp @@ -4,7 +4,7 @@ public fun m::test($t0: u64) { var $t1: &mut u64 var $t2: u64 - # flush: $t1 + # flush: $t2 # live vars: $t0 0: $t1 := borrow_local($t0) # live vars: $t1 @@ -22,12 +22,13 @@ module c0ffee.m { public test(Arg0: u64) /* def_idx: 0 */ { -L1: loc0: &mut u64 +L1: loc0: u64 +L2: loc1: &mut u64 B0: 0: MutBorrowLoc[0](Arg0: u64) - 1: StLoc[1](loc0: &mut u64) + 1: StLoc[2](loc1: &mut u64) 2: LdU64(42) - 3: MoveLoc[1](loc0: &mut u64) + 3: MoveLoc[2](loc1: &mut u64) 4: WriteRef 5: Ret } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.exp index 9aa28b9c4aad4..237e4e168e5c1 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.exp @@ -119,18 +119,17 @@ fun m::foo($t0: bool, $t1: u64): u64 { var $t4: u64 var $t5: u64 [unused] var $t6: u64 [unused] - 0: $t1 := move($t1) - 1: if ($t0) goto 4 else goto 2 - 2: label L3 - 3: goto 7 - 4: label L0 - 5: $t4 := 0 - 6: $t1 := move($t4) - 7: label L2 - 8: $t1 := move($t1) - 9: $t4 := 1 - 10: $t1 := +($t1, $t4) - 11: return $t1 + 0: if ($t0) goto 3 else goto 1 + 1: label L3 + 2: goto 6 + 3: label L0 + 4: $t4 := 0 + 5: $t1 := move($t4) + 6: label L2 + 7: $t1 := move($t1) + 8: $t4 := 1 + 9: $t1 := +($t1, $t4) + 10: return $t1 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.opt.exp index 9aa28b9c4aad4..237e4e168e5c1 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.opt.exp @@ -119,18 +119,17 @@ fun m::foo($t0: bool, $t1: u64): u64 { var $t4: u64 var $t5: u64 [unused] var $t6: u64 [unused] - 0: $t1 := move($t1) - 1: if ($t0) goto 4 else goto 2 - 2: label L3 - 3: goto 7 - 4: label L0 - 5: $t4 := 0 - 6: $t1 := move($t4) - 7: label L2 - 8: $t1 := move($t1) - 9: $t4 := 1 - 10: $t1 := +($t1, $t4) - 11: return $t1 + 0: if ($t0) goto 3 else goto 1 + 1: label L3 + 2: goto 6 + 3: label L0 + 4: $t4 := 0 + 5: $t1 := move($t4) + 6: label L2 + 7: $t1 := move($t1) + 8: $t4 := 1 + 9: $t1 := +($t1, $t4) + 10: return $t1 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/call_1.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/call_1.exp index 039723aa6b3e0..d76c6aad706a8 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/call_1.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/call_1.exp @@ -140,8 +140,7 @@ fun m::test($t0: u64): u64 { [variant baseline] fun m::id($t0: u64): u64 { var $t1: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } @@ -153,11 +152,10 @@ fun m::test($t0: u64): u64 { var $t4: u64 [unused] var $t5: u64 [unused] var $t6: u64 [unused] - 0: $t0 := move($t0) + 0: $t0 := m::id($t0) 1: $t0 := m::id($t0) 2: $t0 := m::id($t0) - 3: $t0 := m::id($t0) - 4: return $t0 + 3: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/call_1.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/call_1.opt.exp index 039723aa6b3e0..d76c6aad706a8 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/call_1.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/call_1.opt.exp @@ -140,8 +140,7 @@ fun m::test($t0: u64): u64 { [variant baseline] fun m::id($t0: u64): u64 { var $t1: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } @@ -153,11 +152,10 @@ fun m::test($t0: u64): u64 { var $t4: u64 [unused] var $t5: u64 [unused] var $t6: u64 [unused] - 0: $t0 := move($t0) + 0: $t0 := m::id($t0) 1: $t0 := m::id($t0) 2: $t0 := m::id($t0) - 3: $t0 := m::id($t0) - 4: return $t0 + 3: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/call_2.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/call_2.exp index 70ac5f53b5889..d6ed0da58a74c 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/call_2.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/call_2.exp @@ -144,10 +144,9 @@ fun m::test($t0: u64): u64 { var $t4: u64 [unused] var $t5: &mut u64 0: $t2 := copy($t0) - 1: $t0 := move($t0) - 2: $t5 := borrow_local($t2) - 3: m::update($t5) - 4: return $t0 + 1: $t5 := borrow_local($t2) + 2: m::update($t5) + 3: return $t0 } @@ -168,9 +167,9 @@ L1: loc0: u64 B0: 0: CopyLoc[0](Arg0: u64) 1: StLoc[1](loc0: u64) - 2: MoveLoc[0](Arg0: u64) - 3: MutBorrowLoc[1](loc0: u64) - 4: Call update(&mut u64) + 2: MutBorrowLoc[1](loc0: u64) + 3: Call update(&mut u64) + 4: MoveLoc[0](Arg0: u64) 5: Ret } } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/call_2.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/call_2.opt.exp index 70ac5f53b5889..d6ed0da58a74c 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/call_2.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/call_2.opt.exp @@ -144,10 +144,9 @@ fun m::test($t0: u64): u64 { var $t4: u64 [unused] var $t5: &mut u64 0: $t2 := copy($t0) - 1: $t0 := move($t0) - 2: $t5 := borrow_local($t2) - 3: m::update($t5) - 4: return $t0 + 1: $t5 := borrow_local($t2) + 2: m::update($t5) + 3: return $t0 } @@ -168,9 +167,9 @@ L1: loc0: u64 B0: 0: CopyLoc[0](Arg0: u64) 1: StLoc[1](loc0: u64) - 2: MoveLoc[0](Arg0: u64) - 3: MutBorrowLoc[1](loc0: u64) - 4: Call update(&mut u64) + 2: MutBorrowLoc[1](loc0: u64) + 3: Call update(&mut u64) + 4: MoveLoc[0](Arg0: u64) 5: Ret } } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/cant_copy_propagate.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/cant_copy_propagate.exp index e82f7f8a3a62a..c8a7565b458fe 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/cant_copy_propagate.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/cant_copy_propagate.exp @@ -177,17 +177,16 @@ fun m::test($t0: u64, $t1: bool) { var $t5: u64 [unused] var $t6: u64 [unused] var $t7: u64 - 0: $t0 := move($t0) - 1: if ($t1) goto 2 else goto 6 - 2: label L0 - 3: m::consume($t0) - 4: label L2 - 5: return () - 6: label L1 - 7: $t0 := move($t0) - 8: $t7 := 1 - 9: $t0 := +($t0, $t7) - 10: goto 4 + 0: if ($t1) goto 1 else goto 5 + 1: label L0 + 2: m::consume($t0) + 3: label L2 + 4: return () + 5: label L1 + 6: $t0 := move($t0) + 7: $t7 := 1 + 8: $t0 := +($t0, $t7) + 9: goto 3 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/cant_copy_propagate.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/cant_copy_propagate.opt.exp index e82f7f8a3a62a..c8a7565b458fe 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/cant_copy_propagate.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/cant_copy_propagate.opt.exp @@ -177,17 +177,16 @@ fun m::test($t0: u64, $t1: bool) { var $t5: u64 [unused] var $t6: u64 [unused] var $t7: u64 - 0: $t0 := move($t0) - 1: if ($t1) goto 2 else goto 6 - 2: label L0 - 3: m::consume($t0) - 4: label L2 - 5: return () - 6: label L1 - 7: $t0 := move($t0) - 8: $t7 := 1 - 9: $t0 := +($t0, $t7) - 10: goto 4 + 0: if ($t1) goto 1 else goto 5 + 1: label L0 + 2: m::consume($t0) + 3: label L2 + 4: return () + 5: label L1 + 6: $t0 := move($t0) + 7: $t7 := 1 + 8: $t0 := +($t0, $t7) + 9: goto 3 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/consume_2.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/consume_2.exp index 079a92befc295..463e923348a88 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/consume_2.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/consume_2.exp @@ -163,20 +163,18 @@ fun m::consume_($t0: 0xc0ffee::m::W) { [variant baseline] public fun m::test1($t0: u64) { var $t1: u64 [unused] - 0: $t0 := move($t0) + 0: m::consume($t0) 1: m::consume($t0) - 2: m::consume($t0) - 3: return () + 2: return () } [variant baseline] public fun m::test2($t0: 0xc0ffee::m::W) { var $t1: 0xc0ffee::m::W [unused] - 0: $t0 := move($t0) + 0: m::consume_($t0) 1: m::consume_($t0) - 2: m::consume_($t0) - 3: return () + 2: return () } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/consume_2.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/consume_2.opt.exp index 079a92befc295..463e923348a88 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/consume_2.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/consume_2.opt.exp @@ -163,20 +163,18 @@ fun m::consume_($t0: 0xc0ffee::m::W) { [variant baseline] public fun m::test1($t0: u64) { var $t1: u64 [unused] - 0: $t0 := move($t0) + 0: m::consume($t0) 1: m::consume($t0) - 2: m::consume($t0) - 3: return () + 2: return () } [variant baseline] public fun m::test2($t0: 0xc0ffee::m::W) { var $t1: 0xc0ffee::m::W [unused] - 0: $t0 := move($t0) + 0: m::consume_($t0) 1: m::consume_($t0) - 2: m::consume_($t0) - 3: return () + 2: return () } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_1.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_1.exp index c283de390ca0d..1a3cf0b4e3711 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_1.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_1.exp @@ -65,8 +65,7 @@ fun m::dead($t0: u64): u64 { var $t1: u64 [unused] var $t2: u64 [unused] var $t3: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_1.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_1.opt.exp index c283de390ca0d..1a3cf0b4e3711 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_1.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_1.opt.exp @@ -65,8 +65,7 @@ fun m::dead($t0: u64): u64 { var $t1: u64 [unused] var $t2: u64 [unused] var $t3: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_2.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_2.exp index dc5c1d71c5fa6..986f606835706 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_2.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_2.exp @@ -44,8 +44,7 @@ fun m::dead($t0: u64): u64 { [variant baseline] fun m::dead($t0: u64): u64 { var $t1: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_2.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_2.opt.exp index dc5c1d71c5fa6..986f606835706 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_2.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_2.opt.exp @@ -44,8 +44,7 @@ fun m::dead($t0: u64): u64 { [variant baseline] fun m::dead($t0: u64): u64 { var $t1: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_4.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_4.exp index 59dc55044d55a..a1aff35d88e3a 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_4.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_4.exp @@ -243,8 +243,7 @@ public fun m::test1(): u64 { public fun m::test2($t0: u64): u64 { var $t1: u64 [unused] var $t2: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_4.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_4.opt.exp index 9ccca5d4a98e3..47249d4c20b13 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_4.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/dead_assignment_4.opt.exp @@ -210,8 +210,7 @@ public fun m::test1(): u64 { public fun m::test2($t0: u64): u64 { var $t1: u64 [unused] var $t2: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_1.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_1.exp index 820445f101d4d..9f869f4392801 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_1.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_1.exp @@ -120,10 +120,12 @@ fun m::test(): u64 { var $t6: u64 [unused] 0: $t1 := 1 1: $t2 := 2 - 2: $t1 := +($t1, $t2) - 3: $t3 := copy($t2) - 4: $t2 := +($t3, $t2) - 5: return $t2 + 2: $t1 := move($t1) + 3: $t1 := +($t1, $t2) + 4: $t3 := copy($t2) + 5: $t3 := move($t3) + 6: $t2 := +($t3, $t2) + 7: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_1.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_1.opt.exp index ba52516f4ec58..dd0a16aff1184 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_1.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_1.opt.exp @@ -97,10 +97,11 @@ fun m::test(): u64 { var $t3: u64 [unused] var $t4: u64 0: $t1 := 1 - 1: $t4 := 2 - 2: $t1 := +($t1, $t4) - 3: $t2 := 4 - 4: return $t2 + 1: $t1 := move($t1) + 2: $t4 := 2 + 3: $t1 := +($t1, $t4) + 4: $t2 := 4 + 5: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_2.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_2.exp index 28f27885ba9c9..544d778e3cdc6 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_2.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_2.exp @@ -132,8 +132,9 @@ fun m::test(): u64 { 3: $t5 := 1 4: $t4 := +($t4, $t5) 5: $t1 := move($t4) - 6: $t1 := +($t2, $t1) - 7: return $t1 + 6: $t2 := move($t2) + 7: $t1 := +($t2, $t1) + 8: return $t1 } @@ -144,13 +145,16 @@ module c0ffee.m { test(): u64 /* def_idx: 0 */ { L0: loc0: u64 +L1: loc1: u64 B0: - 0: LdU64(2) + 0: LdU64(1) 1: LdU64(1) - 2: LdU64(1) - 3: Add - 4: Add - 5: Ret + 2: Add + 3: StLoc[1](loc1: u64) + 4: LdU64(2) + 5: MoveLoc[1](loc1: u64) + 6: Add + 7: Ret } } ============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_3.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_3.exp index 16d4c4d51862a..96c02ac0157a9 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_3.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_3.exp @@ -120,9 +120,10 @@ fun m::test(): u64 { var $t6: u64 [unused] 0: $t1 := 1 1: $t2 := 2 - 2: $t5 := 1 - 3: $t1 := +($t1, $t5) - 4: return $t2 + 2: $t1 := move($t1) + 3: $t5 := 1 + 4: $t1 := +($t1, $t5) + 5: return $t2 } @@ -133,13 +134,12 @@ module c0ffee.m { test(): u64 /* def_idx: 0 */ { L0: loc0: u64 -L1: loc1: u64 B0: - 0: LdU64(2) + 0: LdU64(1) 1: LdU64(1) - 2: LdU64(1) - 3: Add - 4: Pop + 2: Add + 3: Pop + 4: LdU64(2) 5: Ret } } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_3.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_3.opt.exp index 8aecac891a811..446dbdd3c3aee 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_3.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/intermingled_3.opt.exp @@ -97,10 +97,11 @@ fun m::test(): u64 { var $t3: u64 [unused] var $t4: u64 0: $t1 := 1 - 1: $t4 := 1 - 2: $t1 := +($t1, $t4) - 3: $t2 := 2 - 4: return $t2 + 1: $t1 := move($t1) + 2: $t4 := 1 + 3: $t1 := +($t1, $t4) + 4: $t2 := 2 + 5: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_1.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_1.exp index d390c313f9361..1dc5675c93b04 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_1.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_1.exp @@ -188,8 +188,7 @@ fun m::test($t0: u64): u64 { 12: $t3 := move($t5) 13: goto 2 14: label L3 - 15: $t2 := move($t2) - 16: return $t2 + 15: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_1.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_1.opt.exp index d390c313f9361..1dc5675c93b04 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_1.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_1.opt.exp @@ -188,8 +188,7 @@ fun m::test($t0: u64): u64 { 12: $t3 := move($t5) 13: goto 2 14: label L3 - 15: $t2 := move($t2) - 16: return $t2 + 15: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_2.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_2.exp index 79557cdcc0bc2..c0ef785d3f874 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_2.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_2.exp @@ -188,8 +188,7 @@ fun m::test($t0: u64): u64 { 12: $t3 := move($t5) 13: goto 2 14: label L3 - 15: $t2 := move($t2) - 16: return $t2 + 15: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_2.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_2.opt.exp index 79557cdcc0bc2..c0ef785d3f874 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_2.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/loop_2.opt.exp @@ -188,8 +188,7 @@ fun m::test($t0: u64): u64 { 12: $t3 := move($t5) 13: goto 2 14: label L3 - 15: $t2 := move($t2) - 16: return $t2 + 15: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_1.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_1.exp index fc0721f97ebdf..8ad3351fea3f1 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_1.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_1.exp @@ -96,13 +96,14 @@ module c0ffee.m { test(Arg0: u64): u64 /* def_idx: 0 */ { -L1: loc0: &mut u64 +L1: loc0: u64 +L2: loc1: &mut u64 B0: 0: CopyLoc[0](Arg0: u64) 1: MutBorrowLoc[0](Arg0: u64) - 2: StLoc[1](loc0: &mut u64) + 2: StLoc[2](loc1: &mut u64) 3: LdU64(1) - 4: MoveLoc[1](loc0: &mut u64) + 4: MoveLoc[2](loc1: &mut u64) 5: WriteRef 6: Ret } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_1.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_1.opt.exp index fc0721f97ebdf..8ad3351fea3f1 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_1.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_1.opt.exp @@ -96,13 +96,14 @@ module c0ffee.m { test(Arg0: u64): u64 /* def_idx: 0 */ { -L1: loc0: &mut u64 +L1: loc0: u64 +L2: loc1: &mut u64 B0: 0: CopyLoc[0](Arg0: u64) 1: MutBorrowLoc[0](Arg0: u64) - 2: StLoc[1](loc0: &mut u64) + 2: StLoc[2](loc1: &mut u64) 3: LdU64(1) - 4: MoveLoc[1](loc0: &mut u64) + 4: MoveLoc[2](loc1: &mut u64) 5: WriteRef 6: Ret } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_2.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_2.exp index bbc91150e8a27..ee1e8880b64bf 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_2.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_2.exp @@ -149,7 +149,8 @@ struct S has copy, drop { test(Arg0: S): u64 /* def_idx: 0 */ { L1: loc0: S L2: loc1: S -L3: loc2: &mut u64 +L3: loc2: u64 +L4: loc3: &mut u64 B0: 0: MoveLoc[0](Arg0: S) 1: StLoc[1](loc0: S) @@ -157,9 +158,9 @@ B0: 3: StLoc[2](loc1: S) 4: MutBorrowLoc[1](loc0: S) 5: MutBorrowField[0](S.a: u64) - 6: StLoc[3](loc2: &mut u64) + 6: StLoc[4](loc3: &mut u64) 7: LdU64(0) - 8: MoveLoc[3](loc2: &mut u64) + 8: MoveLoc[4](loc3: &mut u64) 9: WriteRef 10: ImmBorrowLoc[2](loc1: S) 11: ImmBorrowField[0](S.a: u64) diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_2.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_2.opt.exp index bbc91150e8a27..ee1e8880b64bf 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_2.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/mut_refs_2.opt.exp @@ -149,7 +149,8 @@ struct S has copy, drop { test(Arg0: S): u64 /* def_idx: 0 */ { L1: loc0: S L2: loc1: S -L3: loc2: &mut u64 +L3: loc2: u64 +L4: loc3: &mut u64 B0: 0: MoveLoc[0](Arg0: S) 1: StLoc[1](loc0: S) @@ -157,9 +158,9 @@ B0: 3: StLoc[2](loc1: S) 4: MutBorrowLoc[1](loc0: S) 5: MutBorrowField[0](S.a: u64) - 6: StLoc[3](loc2: &mut u64) + 6: StLoc[4](loc3: &mut u64) 7: LdU64(0) - 8: MoveLoc[3](loc2: &mut u64) + 8: MoveLoc[4](loc3: &mut u64) 9: WriteRef 10: ImmBorrowLoc[2](loc1: S) 11: ImmBorrowField[0](S.a: u64) diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars1.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars1.exp index 1950f688d5d3b..c5aa3f01d69ad 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars1.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars1.exp @@ -136,12 +136,14 @@ fun m::test() { var $t6: u64 [unused] var $t7: u64 [unused] 0: $t0 := 1 - 1: $t3 := 1 - 2: $t0 := +($t0, $t3) - 3: $t1 := 2 - 4: $t3 := 1 - 5: $t1 := +($t1, $t3) - 6: return () + 1: $t0 := move($t0) + 2: $t3 := 1 + 3: $t0 := +($t0, $t3) + 4: $t1 := 2 + 5: $t1 := move($t1) + 6: $t3 := 1 + 7: $t1 := +($t1, $t3) + 8: return () } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars1.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars1.opt.exp index 1950f688d5d3b..c5aa3f01d69ad 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars1.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars1.opt.exp @@ -136,12 +136,14 @@ fun m::test() { var $t6: u64 [unused] var $t7: u64 [unused] 0: $t0 := 1 - 1: $t3 := 1 - 2: $t0 := +($t0, $t3) - 3: $t1 := 2 - 4: $t3 := 1 - 5: $t1 := +($t1, $t3) - 6: return () + 1: $t0 := move($t0) + 2: $t3 := 1 + 3: $t0 := +($t0, $t3) + 4: $t1 := 2 + 5: $t1 := move($t1) + 6: $t3 := 1 + 7: $t1 := +($t1, $t3) + 8: return () } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars_diff_type.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars_diff_type.exp index 59e9927e0fc3b..1361eabb8991d 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars_diff_type.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars_diff_type.exp @@ -136,12 +136,14 @@ fun m::test() { var $t6: u64 [unused] var $t7: u64 0: $t0 := 1 - 1: $t3 := 1 - 2: $t0 := +($t0, $t3) - 3: $t4 := 2 - 4: $t7 := 1 - 5: $t4 := +($t4, $t7) - 6: return () + 1: $t0 := move($t0) + 2: $t3 := 1 + 3: $t0 := +($t0, $t3) + 4: $t4 := 2 + 5: $t4 := move($t4) + 6: $t7 := 1 + 7: $t4 := +($t4, $t7) + 8: return () } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars_diff_type.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars_diff_type.opt.exp index 59e9927e0fc3b..1361eabb8991d 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars_diff_type.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/non_overlapping_vars_diff_type.opt.exp @@ -136,12 +136,14 @@ fun m::test() { var $t6: u64 [unused] var $t7: u64 0: $t0 := 1 - 1: $t3 := 1 - 2: $t0 := +($t0, $t3) - 3: $t4 := 2 - 4: $t7 := 1 - 5: $t4 := +($t4, $t7) - 6: return () + 1: $t0 := move($t0) + 2: $t3 := 1 + 3: $t0 := +($t0, $t3) + 4: $t4 := 2 + 5: $t4 := move($t4) + 6: $t7 := 1 + 7: $t4 := +($t4, $t7) + 8: return () } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/overlapping_vars.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/overlapping_vars.exp index 7c7343d42833b..3dbf2f51b7139 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/overlapping_vars.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/overlapping_vars.exp @@ -101,9 +101,10 @@ fun m::test(): u64 { 0: $t1 := 1 1: $t2 := 2 2: $t3 := 3 - 3: $t1 := +($t1, $t2) - 4: $t1 := +($t1, $t3) - 5: return $t1 + 3: $t1 := move($t1) + 4: $t1 := +($t1, $t2) + 5: $t1 := +($t1, $t3) + 6: return $t1 } @@ -114,6 +115,8 @@ module c0ffee.m { test(): u64 /* def_idx: 0 */ { L0: loc0: u64 +L1: loc1: u64 +L2: loc2: u64 B0: 0: LdU64(1) 1: LdU64(2) diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/reassigned_var.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/reassigned_var.exp index 83ed3028842de..872232853fdc4 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/reassigned_var.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/reassigned_var.exp @@ -98,8 +98,9 @@ fun m::test(): u64 { var $t4: u64 [unused] 0: $t2 := 2 1: $t3 := 9 - 2: $t2 := +($t3, $t2) - 3: return $t2 + 2: $t3 := move($t3) + 3: $t2 := +($t3, $t2) + 4: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/reassigned_var.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/reassigned_var.opt.exp index c862a8614e6ac..ade21b3784dc0 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/reassigned_var.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/reassigned_var.opt.exp @@ -97,9 +97,10 @@ fun m::test(): u64 { var $t3: u64 [unused] var $t4: u64 0: $t2 := 9 - 1: $t4 := 2 - 2: $t2 := +($t2, $t4) - 3: return $t2 + 1: $t2 := move($t2) + 2: $t4 := 2 + 3: $t2 := +($t2, $t4) + 4: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/self_assigns.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/self_assigns.exp index 1265101037e93..a77112bd8eaf8 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/self_assigns.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/self_assigns.exp @@ -383,8 +383,7 @@ public fun m::test1($t0: u64) { [variant baseline] public fun m::test2($t0: u64): u64 { var $t1: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } @@ -413,8 +412,7 @@ public fun m::test3(): u64 { 11: $t1 := move($t4) 12: goto 2 13: label L3 - 14: $t2 := move($t2) - 15: return $t2 + 14: return $t2 } @@ -441,8 +439,7 @@ public fun m::test4($t0: u64): u64 { 10: $t2 := move($t4) 11: goto 1 12: label L3 - 13: $t0 := move($t0) - 14: return $t0 + 13: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/self_assigns.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/self_assigns.opt.exp index 1265101037e93..a77112bd8eaf8 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/self_assigns.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/self_assigns.opt.exp @@ -383,8 +383,7 @@ public fun m::test1($t0: u64) { [variant baseline] public fun m::test2($t0: u64): u64 { var $t1: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } @@ -413,8 +412,7 @@ public fun m::test3(): u64 { 11: $t1 := move($t4) 12: goto 2 13: label L3 - 14: $t2 := move($t2) - 15: return $t2 + 14: return $t2 } @@ -441,8 +439,7 @@ public fun m::test4($t0: u64): u64 { 10: $t2 := move($t4) 11: goto 1 12: label L3 - 13: $t0 := move($t0) - 14: return $t0 + 13: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_1.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_1.exp index 598c94372c3b7..12a1de76e241b 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_1.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_1.exp @@ -134,8 +134,9 @@ fun m::test($t0: u64): bool { 2: $t0 := move($t0) 3: $t7 := 1 4: $t0 := +($t0, $t7) - 5: $t1 := ==($t2, $t3) - 6: return $t1 + 5: $t2 := move($t2) + 6: $t1 := ==($t2, $t3) + 7: return $t1 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_1.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_1.opt.exp index 598c94372c3b7..12a1de76e241b 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_1.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_1.opt.exp @@ -134,8 +134,9 @@ fun m::test($t0: u64): bool { 2: $t0 := move($t0) 3: $t7 := 1 4: $t0 := +($t0, $t7) - 5: $t1 := ==($t2, $t3) - 6: return $t1 + 5: $t2 := move($t2) + 6: $t1 := ==($t2, $t3) + 7: return $t1 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_2.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_2.exp index 01550498bd5b4..be460b9ed9318 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_2.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_2.exp @@ -134,8 +134,9 @@ fun m::test($t0: u64): bool { 2: $t0 := move($t0) 3: $t7 := 1 4: $t0 := +($t0, $t7) - 5: $t1 := ==($t2, $t4) - 6: return $t1 + 5: $t2 := move($t2) + 6: $t1 := ==($t2, $t4) + 7: return $t1 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_2.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_2.opt.exp index 01550498bd5b4..be460b9ed9318 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_2.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/seq_kills_2.opt.exp @@ -134,8 +134,9 @@ fun m::test($t0: u64): bool { 2: $t0 := move($t0) 3: $t7 := 1 4: $t0 := +($t0, $t7) - 5: $t1 := ==($t2, $t4) - 6: return $t1 + 5: $t2 := move($t2) + 6: $t1 := ==($t2, $t4) + 7: return $t1 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/sequential_assign_struct.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/sequential_assign_struct.exp index 6f00d7f3720e6..22d56c2c67a3a 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/sequential_assign_struct.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/sequential_assign_struct.exp @@ -98,8 +98,7 @@ fun m::sequential($t0: 0xc0ffee::m::Foo): 0xc0ffee::m::Foo { var $t4: 0xc0ffee::m::Foo [unused] var $t5: 0xc0ffee::m::Foo [unused] var $t6: 0xc0ffee::m::Foo [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/sequential_assign_struct.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/sequential_assign_struct.opt.exp index 6f00d7f3720e6..22d56c2c67a3a 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/sequential_assign_struct.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/sequential_assign_struct.opt.exp @@ -98,8 +98,7 @@ fun m::sequential($t0: 0xc0ffee::m::Foo): 0xc0ffee::m::Foo { var $t4: 0xc0ffee::m::Foo [unused] var $t5: 0xc0ffee::m::Foo [unused] var $t6: 0xc0ffee::m::Foo [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/simple_sequential_assign.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/simple_sequential_assign.exp index 7d0f64a2a3ebd..a839f4cafad8d 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/simple_sequential_assign.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/simple_sequential_assign.exp @@ -98,8 +98,7 @@ fun m::sequential($t0: u64): u64 { var $t4: u64 [unused] var $t5: u64 [unused] var $t6: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/simple_sequential_assign.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/simple_sequential_assign.opt.exp index 7d0f64a2a3ebd..a839f4cafad8d 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/simple_sequential_assign.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/simple_sequential_assign.opt.exp @@ -98,8 +98,7 @@ fun m::sequential($t0: u64): u64 { var $t4: u64 [unused] var $t5: u64 [unused] var $t6: u64 [unused] - 0: $t0 := move($t0) - 1: return $t0 + 0: return $t0 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/straight_line_kills.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/straight_line_kills.exp index 952adc3ca50e8..156750a589bc2 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/straight_line_kills.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/straight_line_kills.exp @@ -123,8 +123,9 @@ fun m::copy_kill($t0: u64): u64 { 2: $t0 := move($t0) 3: $t6 := 1 4: $t0 := +($t0, $t6) - 5: $t2 := +($t3, $t2) - 6: return $t2 + 5: $t3 := move($t3) + 6: $t2 := +($t3, $t2) + 7: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/straight_line_kills.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/straight_line_kills.opt.exp index 952adc3ca50e8..156750a589bc2 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/straight_line_kills.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/straight_line_kills.opt.exp @@ -123,8 +123,9 @@ fun m::copy_kill($t0: u64): u64 { 2: $t0 := move($t0) 3: $t6 := 1 4: $t0 := +($t0, $t6) - 5: $t2 := +($t3, $t2) - 6: return $t2 + 5: $t3 := move($t3) + 6: $t2 := +($t3, $t2) + 7: return $t2 } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/swap.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/swap.exp index b546a583a4056..32a6fa7788cd5 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/swap.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/swap.exp @@ -79,7 +79,8 @@ public fun m::test($t0: u64, $t1: u64): (u64, u64) { 0: $t4 := move($t0) 1: $t0 := move($t1) 2: $t1 := move($t4) - 3: return ($t0, $t1) + 3: $t0 := move($t0) + 4: return ($t0, $t1) } @@ -92,10 +93,12 @@ public test(Arg0: u64, Arg1: u64): u64 * u64 /* def_idx: 0 */ { L2: loc0: u64 B0: 0: MoveLoc[0](Arg0: u64) - 1: StLoc[2](loc0: u64) - 2: MoveLoc[1](Arg1: u64) - 3: MoveLoc[2](loc0: u64) - 4: Ret + 1: MoveLoc[1](Arg1: u64) + 2: StLoc[0](Arg0: u64) + 3: StLoc[1](Arg1: u64) + 4: MoveLoc[0](Arg0: u64) + 5: MoveLoc[1](Arg1: u64) + 6: Ret } } ============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/swap.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/swap.opt.exp index b546a583a4056..32a6fa7788cd5 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/swap.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/swap.opt.exp @@ -79,7 +79,8 @@ public fun m::test($t0: u64, $t1: u64): (u64, u64) { 0: $t4 := move($t0) 1: $t0 := move($t1) 2: $t1 := move($t4) - 3: return ($t0, $t1) + 3: $t0 := move($t0) + 4: return ($t0, $t1) } @@ -92,10 +93,12 @@ public test(Arg0: u64, Arg1: u64): u64 * u64 /* def_idx: 0 */ { L2: loc0: u64 B0: 0: MoveLoc[0](Arg0: u64) - 1: StLoc[2](loc0: u64) - 2: MoveLoc[1](Arg1: u64) - 3: MoveLoc[2](loc0: u64) - 4: Ret + 1: MoveLoc[1](Arg1: u64) + 2: StLoc[0](Arg0: u64) + 3: StLoc[1](Arg1: u64) + 4: MoveLoc[0](Arg0: u64) + 5: MoveLoc[1](Arg1: u64) + 6: Ret } } ============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/swap_in_a_loop.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/swap_in_a_loop.exp index ee572dd1f670e..d4ea1e75d5c1b 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/swap_in_a_loop.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/swap_in_a_loop.exp @@ -207,8 +207,7 @@ public fun m::test($t0: u64, $t1: u64): (u64, u64) { 14: goto 1 15: label L3 16: $t0 := move($t0) - 17: $t1 := move($t1) - 18: return ($t0, $t1) + 17: return ($t0, $t1) } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/swap_in_a_loop.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/swap_in_a_loop.opt.exp index ee572dd1f670e..d4ea1e75d5c1b 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/swap_in_a_loop.opt.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/swap_in_a_loop.opt.exp @@ -207,8 +207,7 @@ public fun m::test($t0: u64, $t1: u64): (u64, u64) { 14: goto 1 15: label L3 16: $t0 := move($t0) - 17: $t1 := move($t1) - 18: return ($t0, $t1) + 17: return ($t0, $t1) } diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/unused_add.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/unused_add.exp index 722471aa28a29..ed021a0424d52 100644 --- a/third_party/move/move-compiler-v2/tests/variable-coalescing/unused_add.exp +++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/unused_add.exp @@ -93,8 +93,9 @@ public fun m::test() { var $t3: u64 [unused] 0: $t0 := 1 1: $t1 := 2 - 2: $t0 := +($t0, $t1) - 3: return () + 2: $t0 := move($t0) + 3: $t0 := +($t0, $t1) + 4: return () } @@ -104,6 +105,8 @@ module c0ffee.m { public test() /* def_idx: 0 */ { +L0: loc0: u64 +L1: loc1: u64 B0: 0: LdU64(1) 1: LdU64(2) diff --git a/third_party/move/move-ir-compiler/move-bytecode-source-map/src/source_map.rs b/third_party/move/move-ir-compiler/move-bytecode-source-map/src/source_map.rs index dd52da7ebd5f8..97718c6016e3e 100644 --- a/third_party/move/move-ir-compiler/move-bytecode-source-map/src/source_map.rs +++ b/third_party/move/move-ir-compiler/move-bytecode-source-map/src/source_map.rs @@ -207,7 +207,7 @@ impl FunctionSourceMap { /// Remap the code map based on the given `remap`. /// If `remap[i] == j`, then the code location associated with code offset `j` /// will now be associated with code offset `i`. - pub fn remap_code_map(&mut self, remap: Vec) { + pub fn remap_code_map(&mut self, remap: &[CodeOffset]) { let mut prev_loc = None; let new_code_map = remap .iter() @@ -395,7 +395,7 @@ impl SourceMap { pub fn remap_code_map( &mut self, fdef_idx: FunctionDefinitionIndex, - remap: Vec, + remap: &[CodeOffset], ) -> Result<()> { let func_entry = self .function_map diff --git a/third_party/move/move-model/bytecode/ast-generator-tests/tests/bit_vector_loop_example.exp b/third_party/move/move-model/bytecode/ast-generator-tests/tests/bit_vector_loop_example.exp index 0d69bba7b69b8..381f6d03f0ce8 100644 --- a/third_party/move/move-model/bytecode/ast-generator-tests/tests/bit_vector_loop_example.exp +++ b/third_party/move/move-model/bytecode/ast-generator-tests/tests/bit_vector_loop_example.exp @@ -85,63 +85,64 @@ public fun set(self: &mut BitVector, bit_index: u64) { --- Stackless Bytecode public fun m::set($t0|self: &mut 0x1::m::BitVector, $t1|bit_index: u64) { - var $t2|x: &mut bool - var $t3: u64 - var $t4: &mut 0x1::m::BitVector - var $t5: &vector - var $t6: u64 - var $t7: bool - var $t8: &mut 0x1::m::BitVector - var $t9: &mut vector - var $t10: u64 - var $t11: &mut bool - var $t12: bool - var $t13: &mut bool - var $t14: &mut 0x1::m::BitVector - var $t15: u64 - 0: $t3 := copy($t1) - 1: $t4 := copy($t0) - 2: $t5 := borrow_field<0x1::m::BitVector>.bit_field($t4) - 3: $t6 := vector::length($t5) - 4: $t7 := <($t3, $t6) - 5: if ($t7) goto 6 else goto 16 + var $t2|$t2: bool [unused] + var $t3|x: &mut bool + var $t4: u64 + var $t5: &mut 0x1::m::BitVector + var $t6: &vector + var $t7: u64 + var $t8: bool + var $t9: &mut 0x1::m::BitVector + var $t10: &mut vector + var $t11: u64 + var $t12: &mut bool + var $t13: bool + var $t14: &mut bool + var $t15: &mut 0x1::m::BitVector + var $t16: u64 + 0: $t4 := copy($t1) + 1: $t5 := copy($t0) + 2: $t6 := borrow_field<0x1::m::BitVector>.bit_field($t5) + 3: $t7 := vector::length($t6) + 4: $t8 := <($t4, $t7) + 5: if ($t8) goto 6 else goto 16 6: label L1 - 7: $t8 := move($t0) - 8: $t9 := borrow_field<0x1::m::BitVector>.bit_field($t8) - 9: $t10 := move($t1) - 10: $t11 := vector::borrow_mut($t9, $t10) - 11: $t2 := $t11 - 12: $t12 := true - 13: $t13 := move($t2) - 14: write_ref($t13, $t12) + 7: $t9 := move($t0) + 8: $t10 := borrow_field<0x1::m::BitVector>.bit_field($t9) + 9: $t11 := move($t1) + 10: $t12 := vector::borrow_mut($t10, $t11) + 11: $t3 := $t12 + 12: $t13 := true + 13: $t14 := move($t3) + 14: write_ref($t14, $t13) 15: return () 16: label L0 - 17: $t14 := move($t0) - 18: drop($t14) - 19: $t15 := 131072 - 20: abort($t15) + 17: $t15 := move($t0) + 18: drop($t15) + 19: $t16 := 131072 + 20: abort($t16) } --- Raw Generated AST -_t3: u64 = bit_index; -_t4: &mut BitVector = self; -_t5: &vector = select m::BitVector.bit_field(_t4); -_t6: u64 = vector::length(_t5); -_t7: bool = Lt(_t3, _t6); +_t4: u64 = bit_index; +_t5: &mut BitVector = self; +_t6: &vector = select m::BitVector.bit_field(_t5); +_t7: u64 = vector::length(_t6); +_t8: bool = Lt(_t4, _t7); loop { - if (_t7) break; - _t14: &mut BitVector = self; - _t15: u64 = 131072; - Abort(_t15) + if (_t8) break; + _t15: &mut BitVector = self; + _t16: u64 = 131072; + Abort(_t16) }; -_t8: &mut BitVector = self; -_t9: &mut vector = select m::BitVector.bit_field(_t8); -_t10: u64 = bit_index; -_t11: &mut bool = vector::borrow_mut(_t9, _t10); -_t2: &mut bool = _t11; -_t12: bool = true; -_t13: &mut bool = _t2; -_t13 = _t12; +_t9: &mut BitVector = self; +_t10: &mut vector = select m::BitVector.bit_field(_t9); +_t11: u64 = bit_index; +_t12: &mut bool = vector::borrow_mut(_t10, _t11); +_t3: &mut bool = _t12; +_t13: bool = true; +_t14: &mut bool = _t3; +_t14 = _t13; return Tuple() --- Assign-Transformed Generated AST @@ -192,274 +193,275 @@ public fun shift_left(self: &mut BitVector, amount: u64) { public fun m::shift_left($t0|self: &mut 0x1::m::BitVector, $t1|amount: u64) { var $t2|$t7: &mut vector var $t3|$t3: u64 - var $t4|$t14: &mut bool - var $t5: u64 - var $t6: &mut 0x1::m::BitVector - var $t7: &u64 - var $t8: u64 - var $t9: bool - var $t10: &mut 0x1::m::BitVector - var $t11: &mut vector - var $t12: u64 + var $t4|$t2: bool [unused] + var $t5|$t14: &mut bool + var $t6: u64 + var $t7: &mut 0x1::m::BitVector + var $t8: &u64 + var $t9: u64 + var $t10: bool + var $t11: &mut 0x1::m::BitVector + var $t12: &mut vector var $t13: u64 - var $t14: &mut vector - var $t15: &vector - var $t16: u64 - var $t17: bool - var $t18: &mut vector - var $t19: u64 - var $t20: &mut bool - var $t21: bool - var $t22: &mut bool - var $t23: u64 + var $t14: u64 + var $t15: &mut vector + var $t16: &vector + var $t17: u64 + var $t18: bool + var $t19: &mut vector + var $t20: u64 + var $t21: &mut bool + var $t22: bool + var $t23: &mut bool var $t24: u64 var $t25: u64 - var $t26: &mut vector - var $t27: u64 + var $t26: u64 + var $t27: &mut vector var $t28: u64 - var $t29: &mut 0x1::m::BitVector - var $t30: &u64 - var $t31: u64 - var $t32: bool - var $t33: &mut 0x1::m::BitVector - var $t34: &0x1::m::BitVector - var $t35: u64 - var $t36: bool - var $t37: &mut 0x1::m::BitVector - var $t38: u64 + var $t29: u64 + var $t30: &mut 0x1::m::BitVector + var $t31: &u64 + var $t32: u64 + var $t33: bool + var $t34: &mut 0x1::m::BitVector + var $t35: &0x1::m::BitVector + var $t36: u64 + var $t37: bool + var $t38: &mut 0x1::m::BitVector var $t39: u64 var $t40: u64 var $t41: u64 var $t42: u64 var $t43: u64 - var $t44: &mut 0x1::m::BitVector - var $t45: u64 + var $t44: u64 + var $t45: &mut 0x1::m::BitVector var $t46: u64 var $t47: u64 - var $t48: &mut 0x1::m::BitVector - var $t49: &u64 - var $t50: u64 + var $t48: u64 + var $t49: &mut 0x1::m::BitVector + var $t50: &u64 var $t51: u64 var $t52: u64 var $t53: u64 - var $t54: &mut 0x1::m::BitVector - var $t55: &u64 - var $t56: u64 - var $t57: bool - var $t58: &mut 0x1::m::BitVector - var $t59: u64 + var $t54: u64 + var $t55: &mut 0x1::m::BitVector + var $t56: &u64 + var $t57: u64 + var $t58: bool + var $t59: &mut 0x1::m::BitVector var $t60: u64 var $t61: u64 var $t62: u64 - var $t63: &mut 0x1::m::BitVector - 0: $t5 := copy($t1) - 1: $t6 := copy($t0) - 2: $t7 := borrow_field<0x1::m::BitVector>.length($t6) - 3: $t8 := read_ref($t7) - 4: $t9 := >=($t5, $t8) - 5: if ($t9) goto 6 else goto 39 + var $t63: u64 + var $t64: &mut 0x1::m::BitVector + 0: $t6 := copy($t1) + 1: $t7 := copy($t0) + 2: $t8 := borrow_field<0x1::m::BitVector>.length($t7) + 3: $t9 := read_ref($t8) + 4: $t10 := >=($t6, $t9) + 5: if ($t10) goto 6 else goto 39 6: label L1 - 7: $t10 := move($t0) - 8: $t11 := borrow_field<0x1::m::BitVector>.bit_field($t10) - 9: $t2 := $t11 - 10: $t12 := 0 - 11: $t3 := $t12 + 7: $t11 := move($t0) + 8: $t12 := borrow_field<0x1::m::BitVector>.bit_field($t11) + 9: $t2 := $t12 + 10: $t13 := 0 + 11: $t3 := $t13 12: goto 13 13: label L4 - 14: $t13 := copy($t3) - 15: $t14 := copy($t2) - 16: $t15 := freeze_ref($t14) - 17: $t16 := vector::length($t15) - 18: $t17 := <($t13, $t16) - 19: if ($t17) goto 20 else goto 33 + 14: $t14 := copy($t3) + 15: $t15 := copy($t2) + 16: $t16 := freeze_ref($t15) + 17: $t17 := vector::length($t16) + 18: $t18 := <($t14, $t17) + 19: if ($t18) goto 20 else goto 33 20: label L3 - 21: $t18 := copy($t2) - 22: $t19 := copy($t3) - 23: $t20 := vector::borrow_mut($t18, $t19) - 24: $t4 := $t20 - 25: $t21 := false - 26: $t22 := move($t4) - 27: write_ref($t22, $t21) - 28: $t23 := move($t3) - 29: $t24 := 1 - 30: $t25 := +($t23, $t24) - 31: $t3 := $t25 + 21: $t19 := copy($t2) + 22: $t20 := copy($t3) + 23: $t21 := vector::borrow_mut($t19, $t20) + 24: $t5 := $t21 + 25: $t22 := false + 26: $t23 := move($t5) + 27: write_ref($t23, $t22) + 28: $t24 := move($t3) + 29: $t25 := 1 + 30: $t26 := +($t24, $t25) + 31: $t3 := $t26 32: goto 13 33: label L2 - 34: $t26 := move($t2) - 35: drop($t26) + 34: $t27 := move($t2) + 35: drop($t27) 36: goto 37 37: label L14 38: return () 39: label L0 - 40: $t27 := copy($t1) - 41: $t3 := $t27 + 40: $t28 := copy($t1) + 41: $t3 := $t28 42: goto 43 43: label L9 - 44: $t28 := copy($t3) - 45: $t29 := copy($t0) - 46: $t30 := borrow_field<0x1::m::BitVector>.length($t29) - 47: $t31 := read_ref($t30) - 48: $t32 := <($t28, $t31) - 49: if ($t32) goto 50 else goto 76 + 44: $t29 := copy($t3) + 45: $t30 := copy($t0) + 46: $t31 := borrow_field<0x1::m::BitVector>.length($t30) + 47: $t32 := read_ref($t31) + 48: $t33 := <($t29, $t32) + 49: if ($t33) goto 50 else goto 76 50: label L6 - 51: $t33 := copy($t0) - 52: $t34 := freeze_ref($t33) - 53: $t35 := copy($t3) - 54: $t36 := m::is_index_set($t34, $t35) - 55: if ($t36) goto 56 else goto 69 + 51: $t34 := copy($t0) + 52: $t35 := freeze_ref($t34) + 53: $t36 := copy($t3) + 54: $t37 := m::is_index_set($t35, $t36) + 55: if ($t37) goto 56 else goto 69 56: label L8 - 57: $t37 := copy($t0) - 58: $t38 := copy($t3) - 59: $t39 := copy($t1) - 60: $t40 := -($t38, $t39) - 61: m::set($t37, $t40) + 57: $t38 := copy($t0) + 58: $t39 := copy($t3) + 59: $t40 := copy($t1) + 60: $t41 := -($t39, $t40) + 61: m::set($t38, $t41) 62: goto 63 63: label L10 - 64: $t41 := move($t3) - 65: $t42 := 1 - 66: $t43 := +($t41, $t42) - 67: $t3 := $t43 + 64: $t42 := move($t3) + 65: $t43 := 1 + 66: $t44 := +($t42, $t43) + 67: $t3 := $t44 68: goto 43 69: label L7 - 70: $t44 := copy($t0) - 71: $t45 := copy($t3) - 72: $t46 := copy($t1) - 73: $t47 := -($t45, $t46) - 74: m::unset($t44, $t47) + 70: $t45 := copy($t0) + 71: $t46 := copy($t3) + 72: $t47 := copy($t1) + 73: $t48 := -($t46, $t47) + 74: m::unset($t45, $t48) 75: goto 63 76: label L5 - 77: $t48 := copy($t0) - 78: $t49 := borrow_field<0x1::m::BitVector>.length($t48) - 79: $t50 := read_ref($t49) - 80: $t51 := move($t1) - 81: $t52 := -($t50, $t51) - 82: $t3 := $t52 + 77: $t49 := copy($t0) + 78: $t50 := borrow_field<0x1::m::BitVector>.length($t49) + 79: $t51 := read_ref($t50) + 80: $t52 := move($t1) + 81: $t53 := -($t51, $t52) + 82: $t3 := $t53 83: goto 84 84: label L13 - 85: $t53 := copy($t3) - 86: $t54 := copy($t0) - 87: $t55 := borrow_field<0x1::m::BitVector>.length($t54) - 88: $t56 := read_ref($t55) - 89: $t57 := <($t53, $t56) - 90: if ($t57) goto 91 else goto 100 + 85: $t54 := copy($t3) + 86: $t55 := copy($t0) + 87: $t56 := borrow_field<0x1::m::BitVector>.length($t55) + 88: $t57 := read_ref($t56) + 89: $t58 := <($t54, $t57) + 90: if ($t58) goto 91 else goto 100 91: label L12 - 92: $t58 := copy($t0) - 93: $t59 := copy($t3) - 94: m::unset($t58, $t59) - 95: $t60 := move($t3) - 96: $t61 := 1 - 97: $t62 := +($t60, $t61) - 98: $t3 := $t62 + 92: $t59 := copy($t0) + 93: $t60 := copy($t3) + 94: m::unset($t59, $t60) + 95: $t61 := move($t3) + 96: $t62 := 1 + 97: $t63 := +($t61, $t62) + 98: $t3 := $t63 99: goto 84 100: label L11 -101: $t63 := move($t0) -102: drop($t63) +101: $t64 := move($t0) +102: drop($t64) 103: goto 37 } --- Raw Generated AST -_t5: u64 = amount; -_t6: &mut BitVector = self; -_t7: &u64 = select m::BitVector.length(_t6); -_t8: u64 = Deref(_t7); -_t9: bool = Ge(_t5, _t8); +_t6: u64 = amount; +_t7: &mut BitVector = self; +_t8: &u64 = select m::BitVector.length(_t7); +_t9: u64 = Deref(_t8); +_t10: bool = Ge(_t6, _t9); loop { loop { loop { loop { - if (Not(_t9)) break; - _t10: &mut BitVector = self; - _t11: &mut vector = select m::BitVector.bit_field(_t10); - _t2: &mut vector = _t11; - _t12: u64 = 0; - _t3: u64 = _t12; + if (Not(_t10)) break; + _t11: &mut BitVector = self; + _t12: &mut vector = select m::BitVector.bit_field(_t11); + _t2: &mut vector = _t12; + _t13: u64 = 0; + _t3: u64 = _t13; break[1] }; - _t27: u64 = amount; - _t3: u64 = _t27; + _t28: u64 = amount; + _t3: u64 = _t28; break[1] }; loop { - _t13: u64 = _t3; - _t14: &mut vector = _t2; - _t15: &vector = Freeze(true)(_t14); - _t16: u64 = vector::length(_t15); - _t17: bool = Lt(_t13, _t16); - if (Not(_t17)) break; - _t18: &mut vector = _t2; - _t19: u64 = _t3; - _t20: &mut bool = vector::borrow_mut(_t18, _t19); - _t4: &mut bool = _t20; - _t21: bool = false; - _t22: &mut bool = _t4; - _t22 = _t21; - _t23: u64 = _t3; - _t24: u64 = 1; - _t25: u64 = Add(_t23, _t24); - _t3: u64 = _t25; + _t14: u64 = _t3; + _t15: &mut vector = _t2; + _t16: &vector = Freeze(true)(_t15); + _t17: u64 = vector::length(_t16); + _t18: bool = Lt(_t14, _t17); + if (Not(_t18)) break; + _t19: &mut vector = _t2; + _t20: u64 = _t3; + _t21: &mut bool = vector::borrow_mut(_t19, _t20); + _t5: &mut bool = _t21; + _t22: bool = false; + _t23: &mut bool = _t5; + _t23 = _t22; + _t24: u64 = _t3; + _t25: u64 = 1; + _t26: u64 = Add(_t24, _t25); + _t3: u64 = _t26; continue }; - _t26: &mut vector = _t2; + _t27: &mut vector = _t2; break[1] }; loop { - _t28: u64 = _t3; - _t29: &mut BitVector = self; - _t30: &u64 = select m::BitVector.length(_t29); - _t31: u64 = Deref(_t30); - _t32: bool = Lt(_t28, _t31); - if (Not(_t32)) break; - _t33: &mut BitVector = self; - _t34: &BitVector = Freeze(true)(_t33); - _t35: u64 = _t3; - _t36: bool = m::is_index_set(_t34, _t35); + _t29: u64 = _t3; + _t30: &mut BitVector = self; + _t31: &u64 = select m::BitVector.length(_t30); + _t32: u64 = Deref(_t31); + _t33: bool = Lt(_t29, _t32); + if (Not(_t33)) break; + _t34: &mut BitVector = self; + _t35: &BitVector = Freeze(true)(_t34); + _t36: u64 = _t3; + _t37: bool = m::is_index_set(_t35, _t36); loop { loop { - if (Not(_t36)) break; - _t37: &mut BitVector = self; - _t38: u64 = _t3; - _t39: u64 = amount; - _t40: u64 = Sub(_t38, _t39); - m::set(_t37, _t40); + if (Not(_t37)) break; + _t38: &mut BitVector = self; + _t39: u64 = _t3; + _t40: u64 = amount; + _t41: u64 = Sub(_t39, _t40); + m::set(_t38, _t41); break[1] }; - _t44: &mut BitVector = self; - _t45: u64 = _t3; - _t46: u64 = amount; - _t47: u64 = Sub(_t45, _t46); - m::unset(_t44, _t47); + _t45: &mut BitVector = self; + _t46: u64 = _t3; + _t47: u64 = amount; + _t48: u64 = Sub(_t46, _t47); + m::unset(_t45, _t48); break }; - _t41: u64 = _t3; - _t42: u64 = 1; - _t43: u64 = Add(_t41, _t42); - _t3: u64 = _t43; + _t42: u64 = _t3; + _t43: u64 = 1; + _t44: u64 = Add(_t42, _t43); + _t3: u64 = _t44; continue }; - _t48: &mut BitVector = self; - _t49: &u64 = select m::BitVector.length(_t48); - _t50: u64 = Deref(_t49); - _t51: u64 = amount; - _t52: u64 = Sub(_t50, _t51); - _t3: u64 = _t52; + _t49: &mut BitVector = self; + _t50: &u64 = select m::BitVector.length(_t49); + _t51: u64 = Deref(_t50); + _t52: u64 = amount; + _t53: u64 = Sub(_t51, _t52); + _t3: u64 = _t53; loop { - _t53: u64 = _t3; - _t54: &mut BitVector = self; - _t55: &u64 = select m::BitVector.length(_t54); - _t56: u64 = Deref(_t55); - _t57: bool = Lt(_t53, _t56); - if (Not(_t57)) break; - _t58: &mut BitVector = self; - _t59: u64 = _t3; - m::unset(_t58, _t59); + _t54: u64 = _t3; + _t55: &mut BitVector = self; + _t56: &u64 = select m::BitVector.length(_t55); + _t57: u64 = Deref(_t56); + _t58: bool = Lt(_t54, _t57); + if (Not(_t58)) break; + _t59: &mut BitVector = self; _t60: u64 = _t3; - _t61: u64 = 1; - _t62: u64 = Add(_t60, _t61); - _t3: u64 = _t62; + m::unset(_t59, _t60); + _t61: u64 = _t3; + _t62: u64 = 1; + _t63: u64 = Add(_t61, _t62); + _t3: u64 = _t63; continue }; - _t63: &mut BitVector = self; + _t64: &mut BitVector = self; break }; return Tuple() @@ -605,63 +607,64 @@ public fun unset(self: &mut BitVector, bit_index: u64) { --- Stackless Bytecode public fun m::unset($t0|self: &mut 0x1::m::BitVector, $t1|bit_index: u64) { - var $t2|x: &mut bool - var $t3: u64 - var $t4: &mut 0x1::m::BitVector - var $t5: &vector - var $t6: u64 - var $t7: bool - var $t8: &mut 0x1::m::BitVector - var $t9: &mut vector - var $t10: u64 - var $t11: &mut bool - var $t12: bool - var $t13: &mut bool - var $t14: &mut 0x1::m::BitVector - var $t15: u64 - 0: $t3 := copy($t1) - 1: $t4 := copy($t0) - 2: $t5 := borrow_field<0x1::m::BitVector>.bit_field($t4) - 3: $t6 := vector::length($t5) - 4: $t7 := <($t3, $t6) - 5: if ($t7) goto 6 else goto 16 + var $t2|$t2: bool [unused] + var $t3|x: &mut bool + var $t4: u64 + var $t5: &mut 0x1::m::BitVector + var $t6: &vector + var $t7: u64 + var $t8: bool + var $t9: &mut 0x1::m::BitVector + var $t10: &mut vector + var $t11: u64 + var $t12: &mut bool + var $t13: bool + var $t14: &mut bool + var $t15: &mut 0x1::m::BitVector + var $t16: u64 + 0: $t4 := copy($t1) + 1: $t5 := copy($t0) + 2: $t6 := borrow_field<0x1::m::BitVector>.bit_field($t5) + 3: $t7 := vector::length($t6) + 4: $t8 := <($t4, $t7) + 5: if ($t8) goto 6 else goto 16 6: label L1 - 7: $t8 := move($t0) - 8: $t9 := borrow_field<0x1::m::BitVector>.bit_field($t8) - 9: $t10 := move($t1) - 10: $t11 := vector::borrow_mut($t9, $t10) - 11: $t2 := $t11 - 12: $t12 := false - 13: $t13 := move($t2) - 14: write_ref($t13, $t12) + 7: $t9 := move($t0) + 8: $t10 := borrow_field<0x1::m::BitVector>.bit_field($t9) + 9: $t11 := move($t1) + 10: $t12 := vector::borrow_mut($t10, $t11) + 11: $t3 := $t12 + 12: $t13 := false + 13: $t14 := move($t3) + 14: write_ref($t14, $t13) 15: return () 16: label L0 - 17: $t14 := move($t0) - 18: drop($t14) - 19: $t15 := 131072 - 20: abort($t15) + 17: $t15 := move($t0) + 18: drop($t15) + 19: $t16 := 131072 + 20: abort($t16) } --- Raw Generated AST -_t3: u64 = bit_index; -_t4: &mut BitVector = self; -_t5: &vector = select m::BitVector.bit_field(_t4); -_t6: u64 = vector::length(_t5); -_t7: bool = Lt(_t3, _t6); +_t4: u64 = bit_index; +_t5: &mut BitVector = self; +_t6: &vector = select m::BitVector.bit_field(_t5); +_t7: u64 = vector::length(_t6); +_t8: bool = Lt(_t4, _t7); loop { - if (_t7) break; - _t14: &mut BitVector = self; - _t15: u64 = 131072; - Abort(_t15) + if (_t8) break; + _t15: &mut BitVector = self; + _t16: u64 = 131072; + Abort(_t16) }; -_t8: &mut BitVector = self; -_t9: &mut vector = select m::BitVector.bit_field(_t8); -_t10: u64 = bit_index; -_t11: &mut bool = vector::borrow_mut(_t9, _t10); -_t2: &mut bool = _t11; -_t12: bool = false; -_t13: &mut bool = _t2; -_t13 = _t12; +_t9: &mut BitVector = self; +_t10: &mut vector = select m::BitVector.bit_field(_t9); +_t11: u64 = bit_index; +_t12: &mut bool = vector::borrow_mut(_t10, _t11); +_t3: &mut bool = _t12; +_t13: bool = false; +_t14: &mut bool = _t3; +_t14 = _t13; return Tuple() --- Assign-Transformed Generated AST diff --git a/third_party/move/move-prover/tests/sources/functional/enum.v2_exp b/third_party/move/move-prover/tests/sources/functional/enum.v2_exp index 9a4eed455c87b..222a6c41b27d1 100644 --- a/third_party/move/move-prover/tests/sources/functional/enum.v2_exp +++ b/third_party/move/move-prover/tests/sources/functional/enum.v2_exp @@ -32,8 +32,8 @@ error: data invariant does not hold = common = = at tests/sources/functional/enum.move:37: test_data_invariant = = - = z = = at tests/sources/functional/enum.move:38: test_data_invariant + = z = = at tests/sources/functional/enum.move:17 = at tests/sources/functional/enum.move:18 diff --git a/third_party/move/move-prover/tests/sources/functional/enum_self.v2_exp b/third_party/move/move-prover/tests/sources/functional/enum_self.v2_exp index d8d994257ea57..b242d492fda7c 100644 --- a/third_party/move/move-prover/tests/sources/functional/enum_self.v2_exp +++ b/third_party/move/move-prover/tests/sources/functional/enum_self.v2_exp @@ -12,6 +12,6 @@ error: data invariant does not hold = at tests/sources/functional/enum_self.move:19: test_enum_self = self_s = = at tests/sources/functional/enum_self.move:22: test_enum_self - = self = = at tests/sources/functional/enum_self.move:23: test_enum_self + = self = = at tests/sources/functional/enum_self.move:12 diff --git a/third_party/move/move-prover/tests/sources/functional/invariants.v2_exp b/third_party/move/move-prover/tests/sources/functional/invariants.v2_exp index fd831907a889c..01a2cd1aa10a1 100644 --- a/third_party/move/move-prover/tests/sources/functional/invariants.v2_exp +++ b/third_party/move/move-prover/tests/sources/functional/invariants.v2_exp @@ -20,8 +20,8 @@ error: data invariant does not hold = r = = at tests/sources/functional/invariants.move:114: lifetime_invalid_R = at tests/sources/functional/invariants.move:115: lifetime_invalid_R - = x_ref = = at tests/sources/functional/invariants.move:116: lifetime_invalid_R + = x_ref = = at tests/sources/functional/invariants.move:15 error: data invariant does not hold diff --git a/third_party/move/move-prover/tests/sources/functional/mut_ref.v2_exp b/third_party/move/move-prover/tests/sources/functional/mut_ref.v2_exp index d0db7fb4ce3c1..75804ab3c4042 100644 --- a/third_party/move/move-prover/tests/sources/functional/mut_ref.v2_exp +++ b/third_party/move/move-prover/tests/sources/functional/mut_ref.v2_exp @@ -39,6 +39,6 @@ error: data invariant does not hold = result = = x = = at tests/sources/functional/mut_ref.move:92: return_ref_different_path_vec2 - = r = = at tests/sources/functional/mut_ref.move:122: call_return_ref_different_path_vec2_incorrect + = r = = at tests/sources/functional/mut_ref.move:8 diff --git a/third_party/move/move-prover/tests/sources/functional/strong_edges.v2_exp b/third_party/move/move-prover/tests/sources/functional/strong_edges.v2_exp index 33c9f0347305e..b5276c3d47324 100644 --- a/third_party/move/move-prover/tests/sources/functional/strong_edges.v2_exp +++ b/third_party/move/move-prover/tests/sources/functional/strong_edges.v2_exp @@ -25,7 +25,7 @@ error: unknown assertion failed = at tests/sources/functional/strong_edges.move:60: loc__edge_incorrect = r = = at tests/sources/functional/strong_edges.move:61: loc__edge_incorrect - = r_ref = = at tests/sources/functional/strong_edges.move:62: loc__edge_incorrect + = r_ref = = r = = at tests/sources/functional/strong_edges.move:64: loc__edge_incorrect diff --git a/third_party/move/tools/move-decompiler/tests/simple_map.exp b/third_party/move/tools/move-decompiler/tests/simple_map.exp index fc003d61fd8b1..82afda47093de 100644 --- a/third_party/move/tools/move-decompiler/tests/simple_map.exp +++ b/third_party/move/tools/move-decompiler/tests/simple_map.exp @@ -40,13 +40,13 @@ module 0x1::simple_map { option::none() } public fun remove(self: &mut SimpleMap, key: &Key): (Key, Value) { - let _t17; - let _t16; + let _t19; + let _t18; let _t2; _t2 = find(/*freeze*/self, key); if (!option::is_some(&_t2)) abort error::invalid_argument(2); - Element{key: _t16,value: _t17} = vector::swap_remove>(&mut self.data, option::extract(&mut _t2)); - (_t16, _t17) + Element{key: _t18,value: _t19} = vector::swap_remove>(&mut self.data, option::extract(&mut _t2)); + (_t18, _t19) } public fun add(self: &mut SimpleMap, key: Key, value: Value) { if (!option::is_none(&find(/*freeze*/self, &key))) abort error::invalid_argument(1);