diff --git a/forc-test/src/execute.rs b/forc-test/src/execute.rs index b0ad8a7a24e..436564cc8b8 100644 --- a/forc-test/src/execute.rs +++ b/forc-test/src/execute.rs @@ -85,9 +85,8 @@ impl TestExecutor { .add_unsigned_coin_input(secret_key, utxo_id, amount, asset_id, tx_pointer) .maturity(maturity); - let mut output_index = 1; // Insert contract ids into tx input - for contract_id in test_setup.contract_ids() { + for (output_index, contract_id) in (1..).zip(test_setup.contract_ids()) { tx_builder .add_input(tx::Input::contract( tx::UtxoId::new(tx::Bytes32::zeroed(), 0), @@ -101,7 +100,6 @@ impl TestExecutor { balance_root: fuel_tx::Bytes32::zeroed(), state_root: tx::Bytes32::zeroed(), })); - output_index += 1; } let consensus_params = tx_builder.get_params().clone(); diff --git a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs index 00df9484c89..5d4fbe0dbdb 100644 --- a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs +++ b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs @@ -2335,7 +2335,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { // XXX not required after we have FuelVM specific verifier. if !val .get_type(self.context) - .and_then(|val_ty| key.get_type(self.context).map(|key_ty| (val_ty, key_ty))) + .zip(key.get_type(self.context)) .is_some_and(|(val_ty, key_ty)| { val_ty.is_ptr(self.context) && key_ty.is_ptr(self.context) }) diff --git a/sway-core/src/asm_generation/fuel/functions.rs b/sway-core/src/asm_generation/fuel/functions.rs index 43ac3310881..455dc3c887c 100644 --- a/sway-core/src/asm_generation/fuel/functions.rs +++ b/sway-core/src/asm_generation/fuel/functions.rs @@ -418,7 +418,7 @@ impl FuelAsmBuilder<'_, '_> { let fn_name = function.get_name(self.context); let uses_stack = function.num_args(self.context) > compiler_constants::NUM_ARG_REGISTERS as usize; - for (idx, (arg_name, arg_val)) in function.args_iter(self.context).enumerate() { + for (idx, arg) in function.args_iter(self.context).enumerate() { let load_arg = uses_stack && (idx >= compiler_constants::NUM_ARG_REGISTERS as usize - 1); let arg_reg = if !load_arg { @@ -428,8 +428,8 @@ impl FuelAsmBuilder<'_, '_> { self.cur_bytecode.push(Op::register_move( arg_copy_reg.clone(), initial_arg_reg, - format!("[fn init: {fn_name}]: copy argument {idx} ({arg_name})"), - self.md_mgr.val_to_span(self.context, *arg_val), + format!("[fn init: {fn_name}]: copy argument {idx} ({})", arg.name), + self.md_mgr.val_to_span(self.context, arg.value), )); arg_copy_reg } else { @@ -456,20 +456,23 @@ impl FuelAsmBuilder<'_, '_> { VirtualImmediate12::try_new( stack_offset, self.md_mgr - .val_to_span(self.context, *arg_val) + .val_to_span(self.context, arg.value) .unwrap_or(Span::dummy()), ) .expect("Too many arguments, cannot handle."), )), - comment: format!("[fn init: {fn_name}]: load argument {idx} ({arg_name}) from its stack slot"), - owning_span: self.md_mgr.val_to_span(self.context, *arg_val), + comment: format!( + "[fn init: {fn_name}]: load argument {idx} ({}) from its stack slot", + arg.name + ), + owning_span: self.md_mgr.val_to_span(self.context, arg.value), }); arg_copy_reg }; // Remember our arg copy. - self.reg_map.insert(*arg_val, arg_reg); + self.reg_map.insert(arg.value, arg_reg); } } @@ -482,7 +485,7 @@ impl FuelAsmBuilder<'_, '_> { // A special case for when there's only a single arg, its value (or address) is placed // directly in the base register. 1 => { - let (_, val) = function.args_iter(self.context).next().unwrap(); + let arg = function.args_iter(self.context).next().unwrap(); let single_arg_reg = self.reg_seqr.next(); match self.program_kind { ProgramKind::Contract => { @@ -498,7 +501,8 @@ impl FuelAsmBuilder<'_, '_> { // The base is an offset. Dereference it. // XXX val.get_type() should be a pointer if it's not meant to be loaded. - if val + if arg + .value .get_type(self.context) .is_some_and(|t| self.is_copy_type(&t)) { @@ -514,7 +518,7 @@ impl FuelAsmBuilder<'_, '_> { } } } - self.reg_map.insert(*val, single_arg_reg); + self.reg_map.insert(arg.value, single_arg_reg); Ok(()) } @@ -533,12 +537,13 @@ impl FuelAsmBuilder<'_, '_> { // Successively load each argument. The asm generated depends on the arg type size // and whether the offset fits in a 12-bit immediate. let mut arg_word_offset = 0; - for (name, val) in function.args_iter(self.context) { + for arg in function.args_iter(self.context) { let current_arg_reg = self.reg_seqr.next(); // The function arg type might be a pointer, but the value in the struct will // be of the pointed to type. So strip the pointer if necessary. - let arg_type = val + let arg_type = arg + .value .get_type(self.context) .map(|ty| ty.get_pointee_type(self.context).unwrap_or(ty)) .unwrap(); @@ -552,7 +557,7 @@ impl FuelAsmBuilder<'_, '_> { args_base_reg.clone(), offs_reg.clone(), )), - comment: format!("get offset of argument {name}"), + comment: format!("get offset of argument {}", arg.name), owning_span: None, }); @@ -563,7 +568,7 @@ impl FuelAsmBuilder<'_, '_> { offs_reg, VirtualImmediate12::new(0), )), - comment: format!("get argument {name}"), + comment: format!("get argument {}", arg.name), owning_span: None, }); } else { @@ -573,7 +578,7 @@ impl FuelAsmBuilder<'_, '_> { offs_reg, VirtualImmediate12::new(0), )), - comment: format!("get argument {name}"), + comment: format!("get argument {}", arg.name), owning_span: None, }); } @@ -584,7 +589,7 @@ impl FuelAsmBuilder<'_, '_> { args_base_reg.clone(), VirtualImmediate12::new(arg_word_offset * 8), )), - comment: format!("get argument {name}"), + comment: format!("get argument {}", arg.name), owning_span: None, }); } else { @@ -594,7 +599,7 @@ impl FuelAsmBuilder<'_, '_> { args_base_reg.clone(), VirtualImmediate12::new(arg_word_offset), )), - comment: format!("get argument {name}"), + comment: format!("get argument {}", arg.name), owning_span: None, }); } @@ -603,13 +608,13 @@ impl FuelAsmBuilder<'_, '_> { arg_word_offset * 8, current_arg_reg.clone(), Some(&args_base_reg), - format!("get offset of argument {name}"), + format!("get offset of argument {}", arg.name), None, ); } arg_word_offset += arg_type_size.in_words(); - self.reg_map.insert(*val, current_arg_reg); + self.reg_map.insert(arg.value, current_arg_reg); } Ok(()) diff --git a/sway-core/src/ir_generation.rs b/sway-core/src/ir_generation.rs index aedfd27ce96..cfecf0f9a12 100644 --- a/sway-core/src/ir_generation.rs +++ b/sway-core/src/ir_generation.rs @@ -472,11 +472,11 @@ fn type_correction(ctx: &mut Context) -> Result<(), IrError> { match &instr.get_instruction(ctx).unwrap().op { InstOp::Call(callee, actual_params) => { let formal_params: Vec<_> = callee.args_iter(ctx).collect(); - for (param_idx, (actual_param, (_, formal_param))) in + for (param_idx, (actual_param, arg)) in actual_params.iter().zip(formal_params.iter()).enumerate() { let actual_ty = actual_param.get_type(ctx).unwrap(); - let formal_ty = formal_param.get_type(ctx).unwrap(); + let formal_ty = arg.value.get_type(ctx).unwrap(); if actual_ty != formal_ty { instrs_to_fix.push(TypeCorrection { actual_ty, diff --git a/sway-core/src/ir_generation/compile.rs b/sway-core/src/ir_generation/compile.rs index 153d420b6c8..0f5f04e682e 100644 --- a/sway-core/src/ir_generation/compile.rs +++ b/sway-core/src/ir_generation/compile.rs @@ -1035,8 +1035,10 @@ fn compile_fn( ref_mut_args.insert(param.name.as_str().to_owned()); } ( + // TODO: We can improve here. Setting all arguments as mutable for now. + IrMutability::Mutable, // Convert the name. - param.name.as_str().into(), + param.name.to_string(), // Convert the type further to a pointer if it's a reference. if param.is_reference { Type::new_typed_pointer(context, ty) @@ -1054,6 +1056,7 @@ fn compile_fn( let keyed_decl = KeyedTyFunctionDecl::new(ast_fn_decl, engines); if context.backtrace != Backtrace::None && panicking_fn_cache.can_panic(&keyed_decl, engines) { args.push(( + IrMutability::Immutable, FnCompiler::BACKTRACE_FN_ARG_NAME.to_string(), Type::new_uint(context, 64), None, diff --git a/sway-core/src/ir_generation/convert.rs b/sway-core/src/ir_generation/convert.rs index e90bd74c84e..8c3ef120634 100644 --- a/sway-core/src/ir_generation/convert.rs +++ b/sway-core/src/ir_generation/convert.rs @@ -176,7 +176,7 @@ pub(super) fn convert_resolved_type_info( elem_type.type_id, span, )?; - Type::new_array(context, elem_type, len as u64) + Type::new_array(context, elem_type, len) } TypeInfo::Tuple(fields) => { diff --git a/sway-core/src/ir_generation/function.rs b/sway-core/src/ir_generation/function.rs index 67d22397c56..b672c087a69 100644 --- a/sway-core/src/ir_generation/function.rs +++ b/sway-core/src/ir_generation/function.rs @@ -217,11 +217,8 @@ impl<'a> FnCompiler<'a> { panicking_fn_cache: &'a mut PanickingFunctionCache, compiled_fn_cache: &'a mut CompiledFunctionCache, ) -> Self { - let lexical_map = LexicalMap::from_iter( - function - .args_iter(context) - .map(|(name, _value)| name.clone()), - ); + let lexical_map = + LexicalMap::from_iter(function.args_iter(context).map(|arg| arg.name.clone())); FnCompiler { engines, module, @@ -267,25 +264,26 @@ impl<'a> FnCompiler<'a> { // Function arguments, like all locals need to be in memory, so that their addresses // can be taken. So we create locals for each argument and store the value there. let entry = self.function.get_entry_block(context); - for (arg_name, arg_value) in self + for arg in self .function .args_iter(context) .cloned() .collect::>() { - let local_name = self.lexical_map.insert(arg_name.as_str().to_owned()); + let local_name = self.lexical_map.insert(arg.name.as_str().to_owned()); let local_var = self.function.new_unique_local_var( context, local_name.clone(), - arg_value.get_type(context).unwrap(), + arg.value.get_type(context).unwrap(), None, + // TODO We should consider if this is mutable or not here. false, ); - if self.ref_mut_args.contains(&arg_name) { + if self.ref_mut_args.contains(&arg.name) { self.ref_mut_args.insert(local_name); } let local_val = entry.append(context).get_local(local_var); - entry.append(context).store(local_val, arg_value); + entry.append(context).store(local_val, arg.value); } match self.compile_code_block(context, md_mgr, ast_block)?.value { // Final value must always be in a register, not in memory. @@ -4735,26 +4733,42 @@ impl<'a> FnCompiler<'a> { .expect("All local symbols must be in the lexical symbol map."); // First look for a local variable with the required name - let lhs_val = self - .function - .get_local_var(context, name) - .map(|var| { - self.current_block - .append(context) - .get_local(var) - .add_metadatum(context, span_md_idx) - }) - .or_else(|| - // Now look for an argument with the required name - self.function - .args_iter(context) - .find_map(|(arg_name, arg_val)| (arg_name == name).then_some(*arg_val))) - .ok_or_else(|| { - CompileError::InternalOwned( + let local_var = self.function.get_local_var(context, name); + let lhs_val = if let Some(local_var) = local_var { + // TODO This check breaks some tests + // if local_var.is_mutable(context) { + self.current_block + .append(context) + .get_local(local_var) + .add_metadatum(context, span_md_idx) + // } else { + // return Err(CompileError::InternalOwned( + // format!("Local var `{name}` is not mutable."), + // base_name.span(), + // )); + // } + } else { + // Not a local var, check is an argument + let Some(arg) = self + .function + .args_iter(context) + .find_map(|arg| (&arg.name == name).then_some(arg.value)) + else { + return Err(CompileError::InternalOwned( format!("Variable not found: {name}."), base_name.span(), - ) - })?; + )); + }; + + if arg.get_argument(context).unwrap().is_immutable { + return Err(CompileError::InternalOwned( + format!("Func arg `{name}` is not mutable."), + base_name.span(), + )); + } else { + arg + } + }; if indices.is_empty() { if self.ref_mut_args.contains(name) { diff --git a/sway-ir/src/block.rs b/sway-ir/src/block.rs index 789db4767fe..14d086aa495 100644 --- a/sway-ir/src/block.rs +++ b/sway-ir/src/block.rs @@ -420,11 +420,19 @@ impl Block { /// /// For every instruction within the block, any reference to `old_val` is replaced with /// `new_val`. - pub fn replace_values(&self, context: &mut Context, replace_map: &FxHashMap) { + pub fn replace_values( + &self, + context: &mut Context, + replace_map: &FxHashMap, + ) -> bool { + let mut modified = false; + for ins_idx in 0..context.blocks[self.0].instructions.len() { let ins = context.blocks[self.0].instructions[ins_idx]; - ins.replace_instruction_values(context, replace_map); + modified |= ins.replace_instruction_values(context, replace_map); } + + modified } /// Remove an instruction from this block. @@ -433,10 +441,13 @@ impl Block { /// extra checks should probably be performed here to avoid corruption! Ideally we use get a /// user/uses system implemented. Using `Vec::remove()` is also O(n) which we may want to /// avoid someday. - pub fn remove_instruction(&self, context: &mut Context, instr_val: Value) { + pub fn remove_instruction(&self, context: &mut Context, instr_val: Value) -> bool { let ins = &mut context.blocks[self.0].instructions; if let Some(pos) = ins.iter().position(|iv| *iv == instr_val) { ins.remove(pos); + true + } else { + false } } @@ -458,9 +469,18 @@ impl Block { } /// Remove instructions from block that satisfy a given predicate. - pub fn remove_instructions bool>(&self, context: &mut Context, pred: T) { + pub fn remove_instructions bool>( + &self, + context: &mut Context, + pred: T, + ) -> bool { let ins = &mut context.blocks[self.0].instructions; + + let len_before = ins.len(); ins.retain(|value| !pred(*value)); + let len_after = ins.len(); + + len_before != len_after } /// Clear the current instruction list and take the one provided. diff --git a/sway-ir/src/error.rs b/sway-ir/src/error.rs index 832aa2535a8..249b8d32239 100644 --- a/sway-ir/src/error.rs +++ b/sway-ir/src/error.rs @@ -90,6 +90,12 @@ pub enum IrError { VerifyInitAggrUnknownInitializerType(usize), VerifyInitAggrMismatchedStructFieldType(usize, String, String), VerifyInitAggrMismatchedArrayElementType(usize, String, String), + + InvalidPassModified { + pass: String, + returned: bool, + comparison: bool, + }, } impl IrError { pub(crate) fn get_problematic_value(&self) -> Option<&Value> { @@ -575,6 +581,13 @@ impl fmt::Display for IrError { "Verification failed: init_aggr instruction has an initializer with a type mismatch for array element at index {idx}. Expected element type: {element_ty}, found initializer type: {initializer_ty}." ) } + + IrError::InvalidPassModified { pass, returned, comparison } => { + write!( + f, + "Verification failed: {pass} returned `modified: {returned}` but its IR comparison says `{comparison}`", + ) + } } } } diff --git a/sway-ir/src/function.rs b/sway-ir/src/function.rs index 35790c8ba2e..4645afb62fb 100644 --- a/sway-ir/src/function.rs +++ b/sway-ir/src/function.rs @@ -24,11 +24,24 @@ use crate::{ }; use crate::{Constant, InstOp}; +#[derive(Clone, Debug)] +pub enum IrMutability { + Mutable, + Immutable, +} + /// A wrapper around an [ECS](https://github.com/orlp/slotmap) handle into the /// [`Context`]. #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub struct Function(pub slotmap::DefaultKey); +#[derive(Clone)] +pub struct FunctionArgContent { + pub mutability: IrMutability, + pub name: String, + pub value: Value, +} + #[doc(hidden)] pub struct FunctionContent { pub name: String, @@ -41,7 +54,7 @@ pub struct FunctionContent { // a premature optimization, considering that even for large // project we compile <1500 functions. pub abi_errors_display: String, - pub arguments: Vec<(String, Value)>, + pub arguments: Vec, pub return_type: Type, pub blocks: Vec, pub module: Module, @@ -73,7 +86,7 @@ impl Function { module: Module, name: String, abi_errors_display: String, - args: Vec<(String, Type, Option)>, + args: Vec<(IrMutability, String, Type, Option)>, return_type: Type, selector: Option<[u8; 4]>, is_public: bool, @@ -116,10 +129,11 @@ impl Function { let arguments: Vec<_> = args .into_iter() .enumerate() - .map(|(idx, (name, ty, arg_metadata))| { - ( + .map( + |(idx, (mutability, name, ty, arg_metadata))| FunctionArgContent { + mutability, name, - Value::new_argument( + value: Value::new_argument( context, BlockArgument { block: entry_block, @@ -129,16 +143,18 @@ impl Function { }, ) .add_metadatum(context, arg_metadata), - ) - }) + }, + ) .collect(); + context .functions .get_mut(func.0) .unwrap() .arguments .clone_from(&arguments); - let (_, arg_vals): (Vec<_>, Vec<_>) = arguments.iter().cloned().unzip(); + + let arg_vals = arguments.iter().map(|x| x.value).collect(); context.blocks.get_mut(entry_block.0).unwrap().args = arg_vals; func @@ -387,20 +403,31 @@ impl Function { context.functions[self.0] .arguments .iter() - .find_map(|(arg_name, val)| (arg_name == name).then_some(val)) - .copied() + .find_map(|arg| (arg.name == name).then_some(arg.value)) } /// Append an extra argument to the function signature. /// /// NOTE: `arg` must be a `BlockArgument` value with the correct index otherwise `add_arg` will /// panic. - pub fn add_arg>(&self, context: &mut Context, name: S, arg: Value) { + pub fn add_arg>( + &self, + context: &mut Context, + mutability: IrMutability, + name: S, + arg: Value, + ) { match context.values[arg.0].value { ValueDatum::Argument(BlockArgument { idx, .. }) if idx == context.functions[self.0].arguments.len() => { - context.functions[self.0].arguments.push((name.into(), arg)); + context.functions[self.0] + .arguments + .push(FunctionArgContent { + mutability, + name: name.into(), + value: arg, + }); } _ => panic!("Inconsistent function argument being added"), } @@ -411,18 +438,21 @@ impl Function { context.functions[self.0] .arguments .iter() - .find_map(|(name, arg_val)| (arg_val == value).then_some(name)) + .find_map(|arg| (arg.value == *value).then_some(&arg.name)) } /// Return an iterator for each of the function arguments. - pub fn args_iter<'a>(&self, context: &'a Context) -> impl Iterator { + pub fn args_iter<'a>( + &self, + context: &'a Context, + ) -> impl Iterator { context.functions[self.0].arguments.iter() } /// Is argument `i` marked immutable? pub fn is_arg_immutable(&self, context: &Context, i: usize) -> bool { - if let Some((_, val)) = context.functions[self.0].arguments.get(i) { - if let ValueDatum::Argument(arg) = &context.values[val.0].value { + if let Some(arg) = context.functions[self.0].arguments.get(i) { + if let ValueDatum::Argument(arg) = &context.values[arg.value.0].value { return arg.is_immutable; } } @@ -506,12 +536,17 @@ impl Function { } /// Remove given list of locals - pub fn remove_locals(&self, context: &mut Context, removals: &Vec) { + pub fn remove_locals(&self, context: &mut Context, removals: &Vec) -> bool { + let mut modified = false; + for remove in removals { if let Some(local) = context.functions[self.0].local_storage.remove(remove) { + modified = true; context.local_vars.remove(local.0); } } + + modified } /// Merge values from another [`Function`] into this one. @@ -606,7 +641,9 @@ impl Function { context: &mut Context, replace_map: &FxHashMap, starting_block: Option, - ) { + ) -> bool { + let mut modified = false; + let mut block_iter = self.block_iter(context).peekable(); if let Some(ref starting_block) = starting_block { @@ -618,8 +655,10 @@ impl Function { } for block in block_iter { - block.replace_values(context, replace_map); + modified |= block.replace_values(context, replace_map); } + + modified } pub fn replace_value( diff --git a/sway-ir/src/instruction.rs b/sway-ir/src/instruction.rs index a3428868a60..71be685b2ca 100644 --- a/sway-ir/src/instruction.rs +++ b/sway-ir/src/instruction.rs @@ -39,7 +39,7 @@ impl Instruction { self.op.get_type(context) } /// Replace `old_val` with `new_val` if it is referenced by this instruction's arguments. - pub fn replace_values(&mut self, replace_map: &FxHashMap) { + pub fn replace_values(&mut self, replace_map: &FxHashMap) -> bool { self.op.replace_values(replace_map) } /// Get the function containing this instruction @@ -1264,16 +1264,20 @@ impl InstOp { } /// Replace `old_val` with `new_val` if it is referenced by this instruction's arguments. - pub fn replace_values(&mut self, replace_map: &FxHashMap) { - let replace = |val: &mut Value| { + pub fn replace_values(&mut self, replace_map: &FxHashMap) -> bool { + let mut modified = false; + + let mut replace = |val: &mut Value| { while let Some(new_val) = replace_map.get(val) { *val = *new_val; + modified = true; } }; + match self { InstOp::AsmBlock(_, args) => args .iter_mut() - .for_each(|asm_arg| asm_arg.initializer.iter_mut().for_each(replace)), + .for_each(|asm_arg| asm_arg.initializer.iter_mut().for_each(&mut replace)), InstOp::BitCast(value, _) => replace(value), InstOp::UnaryOp { op: _, arg } => { replace(arg); @@ -1283,9 +1287,9 @@ impl InstOp { replace(arg2); } InstOp::Branch(block) => { - block.args.iter_mut().for_each(replace); + block.args.iter_mut().for_each(&mut replace); } - InstOp::Call(_, args) => args.iter_mut().for_each(replace), + InstOp::Call(_, args) => args.iter_mut().for_each(&mut replace), InstOp::CastPtr(val, _ty) => replace(val), InstOp::Cmp(_, lhs_val, rhs_val) => { replace(lhs_val); @@ -1297,8 +1301,8 @@ impl InstOp { false_block, } => { replace(cond_value); - true_block.args.iter_mut().for_each(replace); - false_block.args.iter_mut().for_each(replace); + true_block.args.iter_mut().for_each(&mut replace); + false_block.args.iter_mut().for_each(&mut replace); } InstOp::ContractCall { params, @@ -1322,7 +1326,7 @@ impl InstOp { indices, } => { replace(base); - indices.iter_mut().for_each(replace); + indices.iter_mut().for_each(&mut replace); } InstOp::Alloc { ty: _, count } => replace(count), InstOp::IntToPtr(value, _) => replace(value), @@ -1488,11 +1492,11 @@ impl InstOp { initializers, }) => { replace(aggr_ptr); - initializers.iter_mut().for_each(|init| { - replace(init); - }); + initializers.iter_mut().for_each(&mut replace); } } + + modified } pub fn may_have_side_effect(&self) -> bool { diff --git a/sway-ir/src/module.rs b/sway-ir/src/module.rs index cbad346d8cc..46e338cb03a 100644 --- a/sway-ir/src/module.rs +++ b/sway-ir/src/module.rs @@ -171,16 +171,21 @@ impl Module { .map(|(key, _)| key.as_str()) } - /// Removed a function from the module. Returns true if function was found and removed. + /// Removes a function from the module. Returns true if function was found and removed. /// /// **Use with care! Be sure the function is not an entry point nor called at any stage.** - pub fn remove_function(&self, context: &mut Context, function: &Function) { - context + pub fn remove_function(&self, context: &mut Context, function: &Function) -> bool { + let fns = &mut context .modules .get_mut(self.0) .expect("Module must exist in context.") - .functions - .retain(|mod_fn| mod_fn != function); + .functions; + + let len_before = fns.len(); + fns.retain(|mod_fn| mod_fn != function); + let len_after = fns.len(); + + len_before != len_after } pub fn iter_configs<'a>(&'a self, context: &'a Context) -> impl Iterator + 'a { diff --git a/sway-ir/src/optimize/arg_demotion.rs b/sway-ir/src/optimize/arg_demotion.rs index 1b67c16e1ca..21968d95fbf 100644 --- a/sway-ir/src/optimize/arg_demotion.rs +++ b/sway-ir/src/optimize/arg_demotion.rs @@ -49,8 +49,8 @@ fn fn_arg_demotion(context: &mut Context, function: Function) -> Result Result { + let mut modified = false; + let dom_tree: &DomTree = analyses.get_analysis_result(function); // In the set of blocks dominated by `key`, replace all uses of `val.0` with `val.1`. @@ -76,8 +78,9 @@ pub fn ccp( if let Some(cur_replacement) = cur_replacement_opt { replacements.insert(cur_replacement.0, cur_replacement.1); } + // walk the current block. - block.replace_values(context, &replacements); + modified |= block.replace_values(context, &replacements); } // walk children. @@ -95,5 +98,5 @@ pub fn ccp( } } - Ok(true) + Ok(modified) } diff --git a/sway-ir/src/optimize/cse.rs b/sway-ir/src/optimize/cse.rs index 5467f14dbf5..1212d31eb46 100644 --- a/sway-ir/src/optimize/cse.rs +++ b/sway-ir/src/optimize/cse.rs @@ -223,7 +223,9 @@ pub fn cse( // Function arg values map to themselves. for arg in function.args_iter(context) { - vntable.value_map.insert(arg.1, ValueNumber::Number(arg.1)); + vntable + .value_map + .insert(arg.value, ValueNumber::Number(arg.value)); } // Map all other arg values map to Top. diff --git a/sway-ir/src/optimize/dce.rs b/sway-ir/src/optimize/dce.rs index aed157c0b18..565137a84e0 100644 --- a/sway-ir/src/optimize/dce.rs +++ b/sway-ir/src/optimize/dce.rs @@ -152,7 +152,7 @@ pub fn dce( if let NumSymbolLoaded::Known(known_num_symbol_loaded) = &mut num_symbol_loaded { for sym in function .args_iter(context) - .flat_map(|arg| get_gep_referred_symbols(context, arg.1)) + .flat_map(|arg| get_gep_referred_symbols(context, arg.value)) { known_num_symbol_loaded .entry(sym) @@ -242,6 +242,7 @@ pub fn dce( { continue; } + // Process dead's operands. let opds = get_operands(dead, context); for opd in opds { @@ -295,8 +296,6 @@ pub fn dce( let count = num_local_uses.get_mut(&local).unwrap(); *count -= 1; } - - modified = true; } // Remove all dead instructions and arguments. @@ -308,32 +307,47 @@ pub fn dce( .arg_iter(context) .map(|arg| cemetery.contains(arg)) .collect_vec(); + for pred in block.pred_iter(context).cloned().collect_vec() { let params = pred .get_succ_params_mut(context, &block) .expect("Invalid IR"); let mut index = 0; + // Remove parameters passed to a dead argument. + let params_len_before = params.len(); params.retain(|_| { let retain = !dead_args[index]; index += 1; retain }); + let params_len_after = params.len(); + modified |= params_len_before != params_len_after; } + // Remove the dead argument itself. let mut index = 0; + let block_args_len_before = context.blocks[block.0].args.len(); context.blocks[block.0].args.retain(|_| { let retain = !dead_args[index]; index += 1; retain }); + let block_args_len_after = context.blocks[block.0].args.len(); + modified |= block_args_len_before != block_args_len_after; + // Update the self-index stored in each arg. for (arg_idx, arg) in block.arg_iter(context).cloned().enumerate().collect_vec() { let arg = arg.get_argument_mut(context).unwrap(); - arg.idx = arg_idx; + + if arg.idx != arg_idx { + arg.idx = arg_idx; + modified = true; + } } } - block.remove_instructions(context, |inst| cemetery.contains(&inst)); + + modified |= block.remove_instructions(context, |inst| cemetery.contains(&inst)); } let local_removals: Vec<_> = function @@ -342,9 +356,9 @@ pub fn dce( (num_local_uses.get(local).cloned().unwrap_or(0) == 0).then_some(name.clone()) }) .collect(); + if !local_removals.is_empty() { - modified = true; - function.remove_locals(context, &local_removals); + modified |= function.remove_locals(context, &local_removals); } Ok(modified) diff --git a/sway-ir/src/optimize/fn_dedup.rs b/sway-ir/src/optimize/fn_dedup.rs index d326aade76a..fc0f3aca60c 100644 --- a/sway-ir/src/optimize/fn_dedup.rs +++ b/sway-ir/src/optimize/fn_dedup.rs @@ -313,6 +313,7 @@ pub fn dedup_fns( ignore_metadata: bool, ) -> Result { let mut modified = false; + let eq_class = &mut EqClass { hash_set_map: FxHashMap::default(), function_hash_map: FxHashMap::default(), @@ -361,11 +362,9 @@ pub fn dedup_fns( dups_to_delete.push(*callee); replacements.push((inst, args.clone(), callee_rep)); } - if !replacements.is_empty() { - modified = true; - } + for (inst, args, callee_rep) in replacements { - inst.replace( + modified |= inst.replace( context, crate::ValueDatum::Instruction(Instruction { op: InstOp::Call(*callee_rep, args.clone()), @@ -401,7 +400,7 @@ pub fn dedup_fns( // Remove replaced functions for function in dups_to_delete { - module.remove_function(context, &function); + modified |= module.remove_function(context, &function); } Ok(modified) diff --git a/sway-ir/src/optimize/inline.rs b/sway-ir/src/optimize/inline.rs index 45be4adc2fe..7433b03e845 100644 --- a/sway-ir/src/optimize/inline.rs +++ b/sway-ir/src/optimize/inline.rs @@ -314,12 +314,12 @@ pub fn inline_function_call( .. }) = &context.values[call_site.0].value { - for (arg_val, passed_val) in context.functions[inlined_function.0] + for (arg, passed_val) in context.functions[inlined_function.0] .arguments .iter() .zip(passed_vals.iter()) { - value_map.insert(arg_val.1, *passed_val); + value_map.insert(arg.value, *passed_val); } } diff --git a/sway-ir/src/optimize/mem2reg.rs b/sway-ir/src/optimize/mem2reg.rs index 597afbe5ba5..fffee2a2428 100644 --- a/sway-ir/src/optimize/mem2reg.rs +++ b/sway-ir/src/optimize/mem2reg.rs @@ -191,14 +191,16 @@ fn promote_globals(context: &mut Context, function: &Function) -> Result>(); - function.replace_values(context, &replacements, None); + modified |= function.replace_values(context, &replacements, None); - Ok(true) + Ok(modified) } /// Promote memory values that are accessed via load/store to SSA registers. @@ -258,6 +260,7 @@ pub fn promote_locals( } } } + // Transitively add PHIs, till nothing more to do. while let Some((local, ty, known_def)) = worklist.pop() { for df in dom_fronts[&known_def].iter() { @@ -272,140 +275,11 @@ pub fn promote_locals( } } - // We're just left with rewriting the loads and stores into SSA. - // For efficiency, we first collect the rewrites - // and then apply them all together in the next step. - #[allow(clippy::too_many_arguments)] - fn record_rewrites( - context: &mut Context, - function: &Function, - dom_tree: &DomTree, - node: Block, - safe_locals: &HashSet, - phi_to_local: &FxHashMap, - name_stack: &mut MappedStack, - rewrites: &mut FxHashMap, - deletes: &mut Vec<(Block, Value)>, - ) { - // Whatever new definitions we find in this block, they must be popped - // when we're done. So let's keep track of that locally as a count. - let mut num_local_pushes = IndexMap::::new(); - - // Start with relevant block args, they are new definitions. - for arg in node.arg_iter(context) { - if let Some(local) = phi_to_local.get(arg) { - name_stack.push(local.clone(), *arg); - num_local_pushes - .entry(local.clone()) - .and_modify(|count| *count += 1) - .or_insert(1); - } - } - - for inst in node.instruction_iter(context) { - match context.values[inst.0].value { - ValueDatum::Instruction(Instruction { - op: InstOp::Load(ptr), - .. - }) => { - let local_var = get_validate_local_var(context, function, &ptr); - match local_var { - Some((local, var)) if safe_locals.contains(&local) => { - // We should replace all uses of inst with new_stack[local]. - let new_val = match name_stack.get(&local) { - Some(val) => *val, - None => { - // Nothing on the stack, let's attempt to get the initializer - let constant = *var - .get_initializer(context) - .expect("We're dealing with an uninitialized value"); - Value::new_constant(context, constant) - } - }; - rewrites.insert(inst, new_val); - deletes.push((node, inst)); - } - _ => (), - } - } - ValueDatum::Instruction(Instruction { - op: - InstOp::Store { - dst_val_ptr, - stored_val, - }, - .. - }) => { - let local_var = get_validate_local_var(context, function, &dst_val_ptr); - match local_var { - Some((local, _)) if safe_locals.contains(&local) => { - // Henceforth, everything that's dominated by this inst must use stored_val - // instead of loading from dst_val. - name_stack.push(local.clone(), stored_val); - num_local_pushes - .entry(local) - .and_modify(|count| *count += 1) - .or_insert(1); - deletes.push((node, inst)); - } - _ => (), - } - } - _ => (), - } - } - - // Update arguments to successor blocks (i.e., PHI args). - for BranchToWithArgs { block: succ, .. } in node.successors(context) { - let args: Vec<_> = succ.arg_iter(context).copied().collect(); - // For every arg of succ, if it's in phi_to_local, - // we pass, as arg, the top value of local - for arg in args { - if let Some(local) = phi_to_local.get(&arg) { - let ptr = function.get_local_var(context, local).unwrap(); - let new_val = match name_stack.get(local) { - Some(val) => *val, - None => { - // Nothing on the stack, let's attempt to get the initializer - let constant = *ptr - .get_initializer(context) - .expect("We're dealing with an uninitialized value"); - Value::new_constant(context, constant) - } - }; - let params = node.get_succ_params_mut(context, &succ).unwrap(); - params.push(new_val); - } - } - } - - // Process dominator children. - for child in dom_tree.children(node) { - record_rewrites( - context, - function, - dom_tree, - child, - safe_locals, - phi_to_local, - name_stack, - rewrites, - deletes, - ); - } - - // Pop from the names stack. - for (local, pushes) in num_local_pushes.iter() { - for _ in 0..*pushes { - name_stack.pop(local); - } - } - } - let mut name_stack = MappedStack::::default(); let mut value_replacement = FxHashMap::::default(); let mut delete_insts = Vec::<(Block, Value)>::new(); - record_rewrites( + + let mut modified = record_rewrites( context, &function, dom_tree, @@ -418,11 +292,148 @@ pub fn promote_locals( ); // Apply the rewrites. - function.replace_values(context, &value_replacement, None); + modified |= function.replace_values(context, &value_replacement, None); + // Delete the loads and stores. for (block, inst) in delete_insts { - block.remove_instruction(context, inst); + modified |= block.remove_instruction(context, inst); + } + + Ok(modified) +} + +// We're just left with rewriting the loads and stores into SSA. +// For efficiency, we first collect the rewrites +// and then apply them all together in the next step. +#[allow(clippy::too_many_arguments)] +fn record_rewrites( + context: &mut Context, + function: &Function, + dom_tree: &DomTree, + node: Block, + safe_locals: &HashSet, + phi_to_local: &FxHashMap, + name_stack: &mut MappedStack, + rewrites: &mut FxHashMap, + deletes: &mut Vec<(Block, Value)>, +) -> bool { + let mut modified = false; + + // Whatever new definitions we find in this block, they must be popped + // when we're done. So let's keep track of that locally as a count. + let mut num_local_pushes = IndexMap::::new(); + + // Start with relevant block args, they are new definitions. + for arg in node.arg_iter(context) { + if let Some(local) = phi_to_local.get(arg) { + name_stack.push(local.clone(), *arg); + num_local_pushes + .entry(local.clone()) + .and_modify(|count| *count += 1) + .or_insert(1); + } + } + + for inst in node.instruction_iter(context) { + match context.values[inst.0].value { + ValueDatum::Instruction(Instruction { + op: InstOp::Load(ptr), + .. + }) => { + let local_var = get_validate_local_var(context, function, &ptr); + match local_var { + Some((local, var)) if safe_locals.contains(&local) => { + // We should replace all uses of inst with new_stack[local]. + let new_val = match name_stack.get(&local) { + Some(val) => *val, + None => { + // Nothing on the stack, let's attempt to get the initializer + let constant = *var + .get_initializer(context) + .expect("We're dealing with an uninitialized value"); + Value::new_constant(context, constant) + } + }; + rewrites.insert(inst, new_val); + deletes.push((node, inst)); + } + _ => (), + } + } + ValueDatum::Instruction(Instruction { + op: + InstOp::Store { + dst_val_ptr, + stored_val, + }, + .. + }) => { + let local_var = get_validate_local_var(context, function, &dst_val_ptr); + match local_var { + Some((local, _)) if safe_locals.contains(&local) => { + // Henceforth, everything that's dominated by this inst must use stored_val + // instead of loading from dst_val. + name_stack.push(local.clone(), stored_val); + num_local_pushes + .entry(local) + .and_modify(|count| *count += 1) + .or_insert(1); + deletes.push((node, inst)); + } + _ => (), + } + } + _ => (), + } + } + + // Update arguments to successor blocks (i.e., PHI args). + for BranchToWithArgs { block: succ, .. } in node.successors(context) { + let args: Vec<_> = succ.arg_iter(context).copied().collect(); + // For every arg of succ, if it's in phi_to_local, + // we pass, as arg, the top value of local + for arg in args { + if let Some(local) = phi_to_local.get(&arg) { + let ptr = function.get_local_var(context, local).unwrap(); + let new_val = match name_stack.get(local) { + Some(val) => *val, + None => { + // Nothing on the stack, let's attempt to get the initializer + let constant = *ptr + .get_initializer(context) + .expect("We're dealing with an uninitialized value"); + Value::new_constant(context, constant) + } + }; + + modified = true; + let params = node.get_succ_params_mut(context, &succ).unwrap(); + params.push(new_val); + } + } + } + + // Process dominator children. + for child in dom_tree.children(node) { + modified |= record_rewrites( + context, + function, + dom_tree, + child, + safe_locals, + phi_to_local, + name_stack, + rewrites, + deletes, + ); + } + + // Pop from the names stack. + for (local, pushes) in num_local_pushes.iter() { + for _ in 0..*pushes { + name_stack.pop(local); + } } - Ok(true) + modified } diff --git a/sway-ir/src/optimize/memcpyopt.rs b/sway-ir/src/optimize/memcpyopt.rs index b663fb65985..0a99af6f7de 100644 --- a/sway-ir/src/optimize/memcpyopt.rs +++ b/sway-ir/src/optimize/memcpyopt.rs @@ -34,21 +34,38 @@ pub fn mem_copy_opt( modified |= local_copy_prop_prememcpy(context, analyses, function)?; modified |= load_store_to_memcopy(context, function)?; modified |= local_copy_prop(context, analyses, function)?; - Ok(modified) } +struct InstInfo { + // The block containing the instruction. + block: Block, + // Relative (use only for comparison) position of instruction in `block`. + pos: usize, +} + +// If the source is an Arg, we replace uses of destination with Arg. +// Otherwise (`get_local`), we replace the local symbol in-place. +enum ReplaceWith { + InPlaceLocal(LocalVar), + Value(Value), +} + +// If we have A replaces B and B replaces C, then A must replace C also. +// Recursively searches for the final replacement for the `local`. +// Returns `None` if the `local` cannot be replaced. +fn get_replace_with(candidates: &FxHashMap, local: &Symbol) -> Option { + candidates + .get(local) + .map(|replace_with| get_replace_with(candidates, replace_with).unwrap_or(*replace_with)) +} + fn local_copy_prop_prememcpy( context: &mut Context, analyses: &AnalysisResults, function: Function, ) -> Result { - struct InstInfo { - // The block containing the instruction. - block: Block, - // Relative (use only for comparison) position of instruction in `block`. - pos: usize, - } + let mut modified = false; // If the analysis result is incomplete we cannot do any safe optimizations here. // Calculating the candidates below relies on complete result of an escape analysis. @@ -214,22 +231,6 @@ fn local_copy_prop_prememcpy( }) .collect(); - // If we have A replaces B and B replaces C, then A must replace C also. - // Recursively searches for the final replacement for the `local`. - // Returns `None` if the `local` cannot be replaced. - fn get_replace_with(candidates: &FxHashMap, local: &Symbol) -> Option { - candidates - .get(local) - .map(|replace_with| get_replace_with(candidates, replace_with).unwrap_or(*replace_with)) - } - - // If the source is an Arg, we replace uses of destination with Arg. - // Otherwise (`get_local`), we replace the local symbol in-place. - enum ReplaceWith { - InPlaceLocal(LocalVar), - Value(Value), - } - // Because we can't borrow context for both iterating and replacing, do it in 2 steps. // `replaces` are the original GetLocal instructions with the corresponding replacements // of their arguments. @@ -265,31 +266,35 @@ fn local_copy_prop_prememcpy( else { panic!("earlier match now fails"); }; - if redundant_var.is_mutable(context) { + + if redundant_var.is_mutable(context) && !replacement_var.is_mutable(context) { + modified = true; replacement_var.set_mutable(context, true); } - value.replace( + + modified |= value.replace( context, ValueDatum::Instruction(Instruction { op: InstOp::GetLocal(replacement_var), parent, }), - ) + ); } ReplaceWith::Value(replace_with) => { value_replace.insert(value, replace_with); } } } - function.replace_values(context, &value_replace, None); + + modified |= function.replace_values(context, &value_replace, None); // Delete stores to the replaced local. let blocks: Vec = function.block_iter(context).collect(); for block in blocks { - block.remove_instructions(context, |value| to_delete.contains(&value)); + modified |= block.remove_instructions(context, |value| to_delete.contains(&value)); } - Ok(true) + Ok(modified) } // Deconstruct a memcpy into (dst_val_ptr, src_val_ptr, copy_len). @@ -474,6 +479,7 @@ fn local_copy_prop( if escaped_symbols.contains(&src_sym) { return false; } + for memcpy in dest_to_copies .get(&src_sym) .iter() @@ -481,6 +487,7 @@ fn local_copy_prop( { let (dst_ptr_memcpy, src_ptr_memcpy, copy_len) = deconstruct_memcpy(context, *memcpy).expect("Expected copy instruction"); + // If the location where we're loading from exactly matches the destination of // the memcpy, just load from the source pointer of the memcpy. // TODO: In both the arms below, we check that the pointer type diff --git a/sway-ir/src/optimize/ret_demotion.rs b/sway-ir/src/optimize/ret_demotion.rs index 3af9ea2e0c3..67a586b7f0c 100644 --- a/sway-ir/src/optimize/ret_demotion.rs +++ b/sway-ir/src/optimize/ret_demotion.rs @@ -7,7 +7,8 @@ /// The return value is mem_copied to the new argument instead of being returned by value. use crate::{ AnalysisResults, BlockArgument, ConstantContent, Context, Function, InstOp, Instruction, - InstructionInserter, IrError, Module, Pass, PassMutability, ScopedPass, Type, Value, + InstructionInserter, IrError, IrMutability, Module, Pass, PassMutability, ScopedPass, Type, + Value, }; pub const RET_DEMOTION_NAME: &str = "ret-demotion"; @@ -77,7 +78,7 @@ pub fn ret_val_demotion( is_immutable: false, }, ); - function.add_arg(context, "__ret_value", ptr_arg_val); + function.add_arg(context, IrMutability::Mutable, "__ret_value", ptr_arg_val); entry_block.add_arg(context, ptr_arg_val); ptr_arg_val }; diff --git a/sway-ir/src/parser.rs b/sway-ir/src/parser.rs index c966ea60e31..24e02e97717 100644 --- a/sway-ir/src/parser.rs +++ b/sway-ir/src/parser.rs @@ -29,6 +29,7 @@ pub fn parse<'eng>( // ------------------------------------------------------------------------------------------------- mod ir_builder { + use crate::function::IrMutability; use slotmap::KeyData; use sway_features::ExperimentalFeatures; use sway_types::{ident::Ident, span::Span, u256::U256, SourceEngine}; @@ -178,9 +179,9 @@ mod ir_builder { string_to_hex::<4>(s) } - rule block_arg() -> (IrAstTy, String, Option) - = name:id() mdi:metadata_idx()? ":" _ ty:ast_ty() { - (ty, name, mdi) + rule block_arg() -> (IrMutability, IrAstTy, String, Option) + = m:("mut" _)? _ name:id() mdi:metadata_idx()? ":" _ ty:ast_ty() { + (if m.is_some() { IrMutability::Mutable } else { IrMutability::Immutable }, ty, name, mdi) } rule fn_local() -> (IrAstTy, String, Option, bool) @@ -870,7 +871,7 @@ mod ir_builder { #[derive(Debug)] struct IrAstFnDecl { name: String, - args: Vec<(IrAstTy, String, Option)>, + args: Vec<(IrMutability, IrAstTy, String, Option)>, ret_type: IrAstTy, is_public: bool, metadata: Option, @@ -885,7 +886,7 @@ mod ir_builder { #[derive(Debug)] struct IrAstBlock { label: String, - args: Vec<(IrAstTy, String, Option)>, + args: Vec<(IrMutability, IrAstTy, String, Option)>, instructions: Vec, } @@ -1209,11 +1210,16 @@ mod ir_builder { let convert_md_idx = |opt_md_idx: &Option| { opt_md_idx.and_then(|mdi| self.md_map.get(&mdi).copied()) }; - let args: Vec<(String, Type, Option)> = fn_decl + let args: Vec<(IrMutability, String, Type, Option)> = fn_decl .args .iter() - .map(|(ty, name, md_idx)| { - (name.into(), ty.to_ir_type(context), convert_md_idx(md_idx)) + .map(|(mutability, ty, name, md_idx)| { + ( + mutability.clone(), + name.into(), + ty.to_ir_type(context), + convert_md_idx(md_idx), + ) }) .collect(); let ret_type = fn_decl.ret_type.to_ir_type(context); @@ -1259,7 +1265,9 @@ mod ir_builder { func.get_entry_block(context) } else { let irblock = func.create_block(context, Some(block.label.clone())); - for (idx, (arg_ty, _, md)) in block.args.iter().enumerate() { + for (idx, (immutability, arg_ty, _, md)) in + block.args.iter().enumerate() + { let ty = arg_ty.to_ir_type(context); let arg = Value::new_argument( context, @@ -1267,8 +1275,10 @@ mod ir_builder { block: irblock, idx, ty, - // TODO: Support immutable flag on block arguments. - is_immutable: false, + is_immutable: match immutability { + IrMutability::Immutable => true, + IrMutability::Mutable => false, + }, }, ) .add_metadatum(context, convert_md_idx(md)); @@ -1280,9 +1290,9 @@ mod ir_builder { })); for block in fn_decl.blocks { - for (idx, arg) in block.args.iter().enumerate() { + for (idx, (_, _, name, _)) in block.args.iter().enumerate() { arg_map.insert( - arg.1.clone(), + name.clone(), named_blocks[&block.label].get_arg(context, idx).unwrap(), ); } diff --git a/sway-ir/src/pass_manager.rs b/sway-ir/src/pass_manager.rs index f4b6a42dfd1..d6620cd8352 100644 --- a/sway-ir/src/pass_manager.rs +++ b/sway-ir/src/pass_manager.rs @@ -380,28 +380,6 @@ impl PassManager { print_opts: &PrintPassesOpts, verify_opts: &VerifyPassesOpts, ) -> Result { - // Empty IRs are result of compiling dependencies. We don't want to print those. - fn ir_is_empty(ir: &Context) -> bool { - ir.functions.is_empty() - && ir.blocks.is_empty() - && ir.values.is_empty() - && ir.local_vars.is_empty() - } - - fn print_ir_after_pass(ir: &Context, pass: &Pass) { - if !ir_is_empty(ir) { - println!("// IR: [{}] {}", pass.name, pass.descr); - println!("{ir}"); - } - } - - fn print_initial_or_final_ir(ir: &Context, initial_or_final: &'static str) { - if !ir_is_empty(ir) { - println!("// IR: {initial_or_final}"); - println!("{ir}"); - } - } - if print_opts.initial { print_initial_or_final_ir(ir, "Initial"); } @@ -412,11 +390,32 @@ impl PassManager { let mut global_modified = false; + // Make it easy for tests to run IR verification in all steps + let force_verify: String = + std::env::var("SWAY_FORCE_VERIFY_IR").unwrap_or_else(|_| "false".to_string()); + let force_verify: bool = force_verify.parse().unwrap_or(false); + for _ in 0..2 { let mut iter_modified = false; for pass in passes.flatten_pass_group() { + // Save IR before optimisation only when forcing verification + let ir_before = if force_verify { + ir.to_string() + } else { + String::new() + }; + + // run the pass let modified = self.actually_run(ir, pass)?; + + // Save IR after optimisation only when forcing verification + let ir_after = if force_verify { + ir.to_string() + } else { + String::new() + }; + iter_modified |= modified; if print_opts.passes.contains(pass) && (!print_opts.modified_only || modified) { @@ -426,6 +425,21 @@ impl PassManager { if verify_opts.passes.contains(pass) && (!verify_opts.modified_only || modified) { ir.verify()?; } + + if force_verify { + // Verify IR + ir.verify()?; + + // Verify pass correctly return modified + let ir_modified = ir_before != ir_after; + if modified != ir_modified { + return Err(IrError::InvalidPassModified { + pass: pass.to_string(), + returned: modified, + comparison: ir_modified, + }); + } + } } global_modified |= iter_modified; @@ -462,6 +476,28 @@ impl PassManager { } } +// Empty IRs are result of compiling dependencies. We don't want to print those. +fn ir_is_empty(ir: &Context) -> bool { + ir.functions.is_empty() + && ir.blocks.is_empty() + && ir.values.is_empty() + && ir.local_vars.is_empty() +} + +fn print_ir_after_pass(ir: &Context, pass: &Pass) { + if !ir_is_empty(ir) { + println!("// IR: [{}] {}", pass.name, pass.descr); + println!("{ir}"); + } +} + +fn print_initial_or_final_ir(ir: &Context, initial_or_final: &'static str) { + if !ir_is_empty(ir) { + println!("// IR: {initial_or_final}"); + println!("{ir}"); + } +} + /// A group of passes. /// Can contain sub-groups. #[derive(Default)] diff --git a/sway-ir/src/printer.rs b/sway-ir/src/printer.rs index 8ef35548496..084aca8c922 100644 --- a/sway-ir/src/printer.rs +++ b/sway-ir/src/printer.rs @@ -436,18 +436,25 @@ fn function_to_doc<'a>( function .arguments .iter() - .map(|(name, arg_val)| { + .map(|arg| { if let ValueContent { value: ValueDatum::Argument(BlockArgument { ty, .. }), metadata, .. - } = &context.values[arg_val.0] + } = &context.values[arg.value.0] { - Doc::text(name) - .append( - Doc::Space.and(md_namer.md_idx_to_doc_no_comma(context, metadata)), - ) - .append(Doc::text(format!(": {}", ty.as_string(context)))) + Doc::text(match arg.mutability { + crate::IrMutability::Mutable => "mut ", + crate::IrMutability::Immutable => "", + }) + .append( + Doc::text(arg.name.to_string()) + .append( + Doc::Space + .and(md_namer.md_idx_to_doc_no_comma(context, metadata)), + ) + .append(Doc::text(format!(": {}", ty.as_string(context)))), + ) } else { unreachable!("Unexpected non argument value for function arguments.") } @@ -519,7 +526,13 @@ fn block_to_doc( block .arg_iter(context) .map(|arg_val| { - Doc::text(namer.name(context, arg_val)).append(Doc::text(format!( + Doc::text(if arg_val.get_argument(context).unwrap().is_immutable { + "" + } else { + "mut " + }) + .append(Doc::text(namer.name(context, arg_val))) + .append(Doc::text(format!( ": {}", arg_val.get_type(context).unwrap().as_string(context) ))) diff --git a/sway-ir/src/value.rs b/sway-ir/src/value.rs index c8e02ef6ba6..d85aa7766c7 100644 --- a/sway-ir/src/value.rs +++ b/sway-ir/src/value.rs @@ -115,7 +115,12 @@ impl Value { /// If this value is an instruction and if any of its parameters is `old_val` then replace them /// with `new_val`. - pub fn replace_instruction_value(&self, context: &mut Context, old_val: Value, new_val: Value) { + pub fn replace_instruction_value( + &self, + context: &mut Context, + old_val: Value, + new_val: Value, + ) -> bool { self.replace_instruction_values(context, &FxHashMap::from_iter([(old_val, new_val)])) } @@ -125,17 +130,22 @@ impl Value { &self, context: &mut Context, replace_map: &FxHashMap, - ) { + ) -> bool { + let mut modified = false; + if let ValueDatum::Instruction(instruction) = &mut context.values.get_mut(self.0).unwrap().value { - instruction.op.replace_values(replace_map); + modified |= instruction.op.replace_values(replace_map); } + + modified } /// Replace this value with another one, in-place. - pub fn replace(&self, context: &mut Context, other: ValueDatum) { + pub fn replace(&self, context: &mut Context, other: ValueDatum) -> bool { context.values[self.0].value = other; + true } /// Get a reference to this value as an instruction, iff it is one. diff --git a/sway-ir/src/verify.rs b/sway-ir/src/verify.rs index 0040c96568c..01e6b279eb8 100644 --- a/sway-ir/src/verify.rs +++ b/sway-ir/src/verify.rs @@ -96,8 +96,8 @@ impl Context<'_> { if function.num_args(self) != entry_block.num_args(self) { return Err(IrError::VerifyBlockArgMalformed); } - for ((_, func_arg), block_arg) in function.args_iter(self).zip(entry_block.arg_iter(self)) { - if func_arg != block_arg { + for (arg, block_arg) in function.args_iter(self).zip(entry_block.arg_iter(self)) { + if &arg.value != block_arg { return Err(IrError::VerifyBlockArgMalformed); } } @@ -629,9 +629,9 @@ impl InstructionVerifier<'_, '_> { let callee_arg_types = callee_content .arguments .iter() - .map(|(_, arg_val)| { + .map(|arg| { if let ValueDatum::Argument(BlockArgument { ty, .. }) = - &self.context.values[arg_val.0].value + &self.context.values[arg.value.0].value { Ok(*ty) } else { diff --git a/sway-ir/tests/ccp/ccp1.ir b/sway-ir/tests/ccp/ccp1.ir index 38256fdf6d1..2c70b892dc1 100644 --- a/sway-ir/tests/ccp/ccp1.ir +++ b/sway-ir/tests/ccp/ccp1.ir @@ -1,48 +1,29 @@ -// regex: ID=[[:alpha:]_0-9]+ - script { - // check: fn $ID($(param=$ID): u64) -> u64 fn test1(p: u64) -> u64 { entry(p: u64): - // check: $(c=$ID) = const u64 100 v0 = const u64 100 - // check: cmp eq $c $param v2 = cmp eq v0 p - // check: $ID, $(true_block=$ID)(), $(false_block=$ID)() cbr v2, get_0_block0(), get_0_block1() - // check: $true_block(): get_0_block0(): - // check: $(one=$ID) = const u64 1 v5 = const u64 1 - // check: add $one, $c v6 = add v5, p ret u64 v6 - // check: $false_block(): get_0_block1(): v7 = const u64 111 - // check: add $ID, $param v8 = add v7, p ret u64 v8 } - // check: fn $ID($(param=$ID): u64) -> u64 fn must_not_optimize(p: u64) -> u64 { - // check: entry($(p=$ID): u64) entry(p: u64): - // check: $(c=$ID) = const u64 100 v0 = const u64 100 - // check: cmp eq $c $param v2 = cmp eq v0 p - // check: $ID, $(true_block=$ID)(), $(false_block=$ID)() cbr v2, get_0_block0(), get_0_block0() - // check: $false_block(): get_0_block0(): - // check: $(one=$ID) = const u64 1 v5 = const u64 1 - // check: $(ID) = add $one, $p v6 = add v5, p ret u64 v6 } diff --git a/sway-ir/tests/ccp/ccp1.ir.snap b/sway-ir/tests/ccp/ccp1.ir.snap index 8dff6421cb8..0c57e04bab3 100644 --- a/sway-ir/tests/ccp/ccp1.ir.snap +++ b/sway-ir/tests/ccp/ccp1.ir.snap @@ -5,7 +5,7 @@ Modified: true script { fn test1(p: u64) -> u64 { - entry(p: u64): + entry(mut p: u64): v2v1 = const u64 100 v3v1 = cmp eq v2v1 p cbr v3v1, get_0_block0(), get_0_block1() @@ -23,7 +23,7 @@ script { } fn must_not_optimize(p: u64) -> u64 { - entry(p: u64): + entry(mut p: u64): v12v1 = const u64 100 v13v1 = cmp eq v12v1 p cbr v13v1, get_0_block0(), get_0_block0() diff --git a/sway-ir/tests/constants/cbr_cmp_fold.ir b/sway-ir/tests/constants/cbr_cmp_fold.ir index 071f3be9a4a..734726d7520 100644 --- a/sway-ir/tests/constants/cbr_cmp_fold.ir +++ b/sway-ir/tests/constants/cbr_cmp_fold.ir @@ -1,19 +1,12 @@ -// regex: ID=[[:alpha:]_0-9]+ - script { fn test1() -> u64 { entry(): v0 = const bool false v1 = const bool false - // not: cmp eq v2 = cmp eq v0 v1 - // not: cbr - // check: br $(dest=$ID) cbr v2, get_0_block0(), get_0_block1() - // check: $dest(): get_0_block0(): - // check: const u64 101 v5 = const u64 101 ret u64 v5 diff --git a/sway-ir/tests/constants/u256_cmp.ir b/sway-ir/tests/constants/u256_cmp.ir index c19110ce831..fd7ddcfb9e4 100644 --- a/sway-ir/tests/constants/u256_cmp.ir +++ b/sway-ir/tests/constants/u256_cmp.ir @@ -1,5 +1,3 @@ -// regex: ID=[[:alpha:]_0-9]+ - script { fn main() -> bool { entry(): @@ -7,7 +5,6 @@ script { v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001 v10 = cmp eq v0 v0 -//check: $ID = const bool true ret bool v10 } -} \ No newline at end of file +} diff --git a/sway-ir/tests/constants/u256_ops.ir b/sway-ir/tests/constants/u256_ops.ir index 05ac132c052..61544b56d15 100644 --- a/sway-ir/tests/constants/u256_ops.ir +++ b/sway-ir/tests/constants/u256_ops.ir @@ -1,5 +1,3 @@ -// regex: ID=[[:alpha:]_0-9]+ - script { fn main() -> u256 { entry(): @@ -24,10 +22,6 @@ script { v18 = not v17 v19 = not v18 v20 = xor v19, v6 -// check: entry -// nextln: $ID = const u256 0x0000000000000000000000000000000000000000000000000000000000000002 -// check-not: const -// check: ret ret u256 v20 } -} \ No newline at end of file +} diff --git a/sway-ir/tests/cse/cse1.ir b/sway-ir/tests/cse/cse1.ir index 25c1a7a395f..147b121e302 100644 --- a/sway-ir/tests/cse/cse1.ir +++ b/sway-ir/tests/cse/cse1.ir @@ -1,18 +1,13 @@ -// regex: ID=[[:alpha:]0-9]+ -// regex: VAR=v\d+v\d+ script { fn main() -> bool { entry(): v0 = const u64 11 v1 = const u64 0 - // check: $(v3=$VAR) = add v3 = add v0, v1 - // check: $(v4=$VAR) = add v4 = add v0, v1 v10 = const u64 10 v11 = add v1, v0 - // check: cmp eq $v3 $v3 v2 = cmp eq v3 v4 v3 = cmp eq v11 v3 v4 = cmp eq v2 v3 diff --git a/sway-ir/tests/cse/cse2.ir b/sway-ir/tests/cse/cse2.ir index 64e910c7bff..de49c7a6378 100644 --- a/sway-ir/tests/cse/cse2.ir +++ b/sway-ir/tests/cse/cse2.ir @@ -1,21 +1,13 @@ -// regex: ID=[[:alpha:]0-9]+ -// regex: VAR=v\d+v\d+ - script { fn main() -> bool { entry(): v0 = const u64 11 v0_dup = const u64 11 v1 = const u64 0 - // check: $(v3=$VAR) = add v3 = add v0, v1 - // check: $(v4=$VAR) = add v4 = add v0, v1 - // check: $(v5=$VAR) = sub v5 = sub v0, v3 - // check: $(v6=$VAR) = sub v6 = sub v0_dup, v4 - // check: cmp eq $v5 $v5 v2 = cmp eq v5 v6 ret bool v2 } diff --git a/sway-ir/tests/cse/cse3.ir b/sway-ir/tests/cse/cse3.ir index 4d33e74173e..91453733bfa 100644 --- a/sway-ir/tests/cse/cse3.ir +++ b/sway-ir/tests/cse/cse3.ir @@ -1,25 +1,18 @@ -// regex: ID=[[:alpha:]0-9]+ -// regex: VAR=v\d+v\d+ - script { entry fn main(a: u64, b: u64) -> () { entry(a: u64, b: u64): - // check: $(v5=$VAR) = add a, b v5 = add a, b v6 = const u64 0 br while(v6, v5) while(v3: u64, v4: u64): - // check: cmp lt $VAR $v5 v8 = cmp lt v3 v4 cbr v8, while_body(), end_while() while_body(): - // check: $(v10=$VAR) = add a, b v10 = add a, b v11 = const u64 1 v12 = add v3, v11 - // check: br while($VAR, $v5) br while(v12, v10) end_while(): diff --git a/sway-ir/tests/cse/cse3.ir.snap b/sway-ir/tests/cse/cse3.ir.snap index 229293d7edb..3c63da3b964 100644 --- a/sway-ir/tests/cse/cse3.ir.snap +++ b/sway-ir/tests/cse/cse3.ir.snap @@ -5,12 +5,12 @@ Modified: true script { entry fn main(a: u64, b: u64) -> () { - entry(a: u64, b: u64): + entry(mut a: u64, mut b: u64): v5v1 = add a, b v6v1 = const u64 0 br while(v6v1, v5v1) - while(v3v1: u64, v4v1: u64): + while(mut v3v1: u64, mut v4v1: u64): - v8v1 = cmp lt v3v1 v4v1 + v8v1 = cmp lt v3v1 v5v1 cbr v8v1, while_body(), end_while() diff --git a/sway-ir/tests/cse/cse4.ir b/sway-ir/tests/cse/cse4.ir index 44c60dda712..efb81a016e1 100644 --- a/sway-ir/tests/cse/cse4.ir +++ b/sway-ir/tests/cse/cse4.ir @@ -1,6 +1,3 @@ -// regex: VAR=v\d+v\d+ -// regex: ID=[[:alpha:]0-9_]+ - // Two `get_local` of the same local are congruent. CSE rewrites the uses of the // second one to the first; the now-dead second `get_local` is removed later by DCE. @@ -9,17 +6,14 @@ script { local { u64, u64 } s entry(): - // check: $(l0=$VAR) = get_local __ptr { u64, u64 }, s v0 = get_local __ptr { u64, u64 }, s v1 = const u64 0 - // check: get_elem_ptr $l0, __ptr u64, $ID v2 = get_elem_ptr v0, __ptr u64, v1 v3 = const u64 7 store v3 to v2 v4 = get_local __ptr { u64, u64 }, s v5 = const u64 1 // The second get_elem_ptr's base must be rewritten to the first get_local ($l0). - // check: get_elem_ptr $l0, __ptr u64, $ID v6 = get_elem_ptr v4, __ptr u64, v5 v7 = load v6 ret u64 v7 diff --git a/sway-ir/tests/dce/copy_prop_1.ir b/sway-ir/tests/dce/copy_prop_1.ir index 3918ab097a1..c2dd9d99aaf 100644 --- a/sway-ir/tests/dce/copy_prop_1.ir +++ b/sway-ir/tests/dce/copy_prop_1.ir @@ -15,7 +15,3 @@ script { ret u64 v6 } } - -// regex: VAL=v\d+v\d+ - -// not: mem_copy_val $VAL, $VAL diff --git a/sway-ir/tests/dce/copy_prop_2.ir b/sway-ir/tests/dce/copy_prop_2.ir index 9b8eb9d39ed..89fded29ef1 100644 --- a/sway-ir/tests/dce/copy_prop_2.ir +++ b/sway-ir/tests/dce/copy_prop_2.ir @@ -15,7 +15,3 @@ script { ret u64 v6 } } - -// regex: VAL=v\d+v\d+ - -// not: mem_copy_val $VAL, $VAL diff --git a/sway-ir/tests/dce/copy_prop_3.ir b/sway-ir/tests/dce/copy_prop_3.ir index 802319d0ca6..68a2b3f433c 100644 --- a/sway-ir/tests/dce/copy_prop_3.ir +++ b/sway-ir/tests/dce/copy_prop_3.ir @@ -16,7 +16,3 @@ script { ret u64 v7 } } - -// regex: VAL=v\d+v\d+ - -// not: mem_copy_val $VAL, $VAL diff --git a/sway-ir/tests/dce/copy_prop_3.ir.snap b/sway-ir/tests/dce/copy_prop_3.ir.snap index ab798ce6484..bd90bc9b93a 100644 --- a/sway-ir/tests/dce/copy_prop_3.ir.snap +++ b/sway-ir/tests/dce/copy_prop_3.ir.snap @@ -8,7 +8,7 @@ script { local [u64; 8] __anon_0 - local [u64; 8] __anon_468 - entry(v101: u64): + entry(mut v101: u64): - v2v1 = get_local __ptr [u64; 8], __anon_0 - v3v1 = get_local __ptr [u64; 8], __anon_468 - mem_copy_val v3v1, v2v1 diff --git a/sway-ir/tests/dce/dce1.ir b/sway-ir/tests/dce/dce1.ir index 5067a82229a..89e7f69bc9a 100644 --- a/sway-ir/tests/dce/dce1.ir +++ b/sway-ir/tests/dce/dce1.ir @@ -1,11 +1,8 @@ -// regex: ID=[[:alpha:]0-9]+ - script { fn main() -> bool { entry(): v0 = const u64 11 v1 = const u64 0 -// not: cmp v2 = cmp eq v0 v1 br block0() diff --git a/sway-ir/tests/dce/dce2.ir b/sway-ir/tests/dce/dce2.ir index aa661661118..e5e1efccadc 100644 --- a/sway-ir/tests/dce/dce2.ir +++ b/sway-ir/tests/dce/dce2.ir @@ -1,10 +1,7 @@ -// regex: ID=[[:alpha:]0-9]+ - script { fn main() -> bool { -// not: local u64 i local u64 i - + entry(): v9 = const bool false ret bool v9 diff --git a/sway-ir/tests/dce/dce3.ir b/sway-ir/tests/dce/dce3.ir index 5fdd2f5f570..b4ed4c25320 100644 --- a/sway-ir/tests/dce/dce3.ir +++ b/sway-ir/tests/dce/dce3.ir @@ -25,15 +25,12 @@ script { ret bool v11 } - // check: function_0 fn function_0(state: __ptr u64) -> () { entry(state: __ptr u64): v0 = const u64 42 - // check: store store v0 to state v1 = const unit () - // not: add v2 = add v0, v0 ret () v1 } -} \ No newline at end of file +} diff --git a/sway-ir/tests/dce/dce3.ir.snap b/sway-ir/tests/dce/dce3.ir.snap index d76758bbd61..3b195e3045e 100644 --- a/sway-ir/tests/dce/dce3.ir.snap +++ b/sway-ir/tests/dce/dce3.ir.snap @@ -31,7 +31,7 @@ script { } fn function_0(state: __ptr u64) -> () { - entry(state: __ptr u64): + entry(mut state: __ptr u64): v18v1 = const u64 42 store v18v1 to state - v21v1 = add v18v1, v18v1 diff --git a/sway-ir/tests/dce/dce_cast_ptr.ir b/sway-ir/tests/dce/dce_cast_ptr.ir index 596530874dd..977dfd136da 100644 --- a/sway-ir/tests/dce/dce_cast_ptr.ir +++ b/sway-ir/tests/dce/dce_cast_ptr.ir @@ -7,10 +7,10 @@ script { entry fn main() -> u64 { local u64 S local u64 dummy - + entry(): br block0() - + block0(): c0 = const u64 123 p = get_local __ptr u64, S @@ -22,16 +22,13 @@ script { res = call test(p_val_res) ret u64 res } - + fn test(arg: u64) -> u64 { entry(arg: u64): br block0(arg) - + block0(arg: __ptr u64): v0 = load arg ret u64 v0 } } - -// check: entry fn main() -> u64 { -// nextln: local u64 S diff --git a/sway-ir/tests/dce/dce_cast_ptr.ir.snap b/sway-ir/tests/dce/dce_cast_ptr.ir.snap index c77d8d44171..8fb739e285d 100644 --- a/sway-ir/tests/dce/dce_cast_ptr.ir.snap +++ b/sway-ir/tests/dce/dce_cast_ptr.ir.snap @@ -24,10 +24,10 @@ script { } fn test(arg: u64) -> u64 { - entry(arg: u64): + entry(mut arg: u64): br block0(arg) - block0(v12v1: __ptr u64): + block0(mut v12v1: __ptr u64): v14v1 = load v12v1 ret u64 v14v1 } diff --git a/sway-ir/tests/dce/dce_dead_arg1.ir b/sway-ir/tests/dce/dce_dead_arg1.ir index 8ef051f0069..2a37b92243d 100644 --- a/sway-ir/tests/dce/dce_dead_arg1.ir +++ b/sway-ir/tests/dce/dce_dead_arg1.ir @@ -1,23 +1,14 @@ -// regex: ID=[[:alpha:]0-9]+ - script { fn main() -> bool { - // check: entry entry(): - // not: const v3v1 = const u64 0 v2v1 = const u64 11 - // not: cmp v4v1 = cmp eq v3v1 v2v1 - // check: br $(block=$ID)() br block0(v4v1) - // check: $block() block0(v1v1: bool): v6v1 = const bool false - // not: cmp v11 = cmp eq v1v1 v6v1 - // check: ret ret bool v6v1 } } diff --git a/sway-ir/tests/dce/dce_dead_arg1.ir.snap b/sway-ir/tests/dce/dce_dead_arg1.ir.snap index 4bfb98815eb..f9728c5a740 100644 --- a/sway-ir/tests/dce/dce_dead_arg1.ir.snap +++ b/sway-ir/tests/dce/dce_dead_arg1.ir.snap @@ -12,7 +12,7 @@ script { - br block0(v4v1) + br block0() -- block0(v1v1: bool): +- block0(mut v1v1: bool): + block0(): v6v1 = const bool false - v7v1 = cmp eq v1v1 v6v1 diff --git a/sway-ir/tests/dce/dce_dead_asm_block.ir b/sway-ir/tests/dce/dce_dead_asm_block.ir index b69ee7bade9..3352aa9dc0f 100644 --- a/sway-ir/tests/dce/dce_dead_asm_block.ir +++ b/sway-ir/tests/dce/dce_dead_asm_block.ir @@ -11,68 +11,55 @@ // poke(asm() { }); // poke(asm() { zero }); // poke(asm() { zero: () }); -// +// // let arg = 11u64; // asm(a: arg, b: arg, res) { // add res a b; // }; -// +// // asm(a: arg, b: arg, res) { // add res a b; // res // }; -// +// // // ----------- -// +// // asm () { } // asm () { zero } // asm() { zero: () } -// +// // asm(arg: arg) { }; // asm(arg: arg) { arg }; -// +// // let a = asm() { }; // let b = asm() { zero }; // let c = asm(arg: arg) { }; // let d = asm(arg: arg) { arg }; // let e = asm(arg: arg) { arg: u32 }; -// +// // let f = asm(arg: function()) { arg }; // } -// regex: VAL=v\d+v\d+ - script { entry fn main() -> () { - // check: local u64 arg local u64 arg - // not: local () a local () a - // not: local u64 b local u64 b - // not: local () c local () c - // not: local u64 d local u64 d - // not: local u64 e local u64 e - // not: local u64 f local u64 f - // check: entry() entry(): - // check: = asm() -> () v0 = asm() -> () { } v1 = call poke_1(v0) - // check: = asm() -> u64 zero v2 = asm() -> u64 zero { } v3 = call poke_2(v2) - // check: = asm() -> () zero v4 = asm() -> () zero { } v5 = call poke_1(v4) @@ -85,7 +72,6 @@ script { v10 = get_local __ptr u64, arg v11 = load v10 - // check: = asm(a: $VAL, b: $VAL, res) -> () v12 = asm(a: v9, b: v11, res) -> () { add res a b } @@ -95,16 +81,12 @@ script { v15 = get_local __ptr u64, arg v16 = load v15 - // check: = asm(a: $VAL, b: $VAL, res) -> u64 res v17 = asm(a: v14, b: v16, res) -> u64 res { add res a b } // ----------- - - // not: asm - // check: = asm() -> u64 zero v2 = asm() -> u64 zero { } v3 = call poke_2(v2) @@ -150,7 +132,6 @@ script { v42 = get_local __ptr u64, e store v41 to v42 - // check: call function() v43 = call function() v44 = asm(arg: v43) -> u64 arg { } @@ -158,9 +139,6 @@ script { store v44 to v45 v46 = const unit () - // not: asm - - // check: ret () ret () v46 } diff --git a/sway-ir/tests/dce/dce_dead_asm_block.ir.snap b/sway-ir/tests/dce/dce_dead_asm_block.ir.snap index 66f8504d566..c86d648e765 100644 --- a/sway-ir/tests/dce/dce_dead_asm_block.ir.snap +++ b/sway-ir/tests/dce/dce_dead_asm_block.ir.snap @@ -93,13 +93,13 @@ script { } fn poke_1(_x: ()) -> () { - entry(_x: ()): + entry(mut _x: ()): v59v1 = const unit () ret () v59v1 } fn poke_2(_x: u64) -> () { - entry(_x: u64): + entry(mut _x: u64): v62v1 = const unit () ret () v62v1 } diff --git a/sway-ir/tests/dce/dce_dead_config_assignment.ir b/sway-ir/tests/dce/dce_dead_config_assignment.ir index 7228944d957..096131a30ec 100644 --- a/sway-ir/tests/dce/dce_dead_config_assignment.ir +++ b/sway-ir/tests/dce/dce_dead_config_assignment.ir @@ -4,9 +4,9 @@ // abi Abi { // fn assign_config_call_pass_config(); // } -// +// // configurable { CONFIG: u64 = 1234 } -// +// // impl Abi for Contract { // fn assign_config_call_pass_config() { // let x = CONFIG; @@ -44,13 +44,3 @@ contract { ret () v0 } } - -// regex: VAL=v\d+v\d+ - -// check: pub entry fn assign_config_call_pass_config -// nextln: entry(): -// nextln: $(v0=$VAL) = get_config __ptr u64, CONFIG -// nextln: $(v1=$VAL) = load $v0 -// nextln: $(v2=$VAL) = call poke_0($v1) -// not: store -// check: ret () diff --git a/sway-ir/tests/dce/dce_dead_config_assignment.ir.snap b/sway-ir/tests/dce/dce_dead_config_assignment.ir.snap index 6f017309174..63980bcf870 100644 --- a/sway-ir/tests/dce/dce_dead_config_assignment.ir.snap +++ b/sway-ir/tests/dce/dce_dead_config_assignment.ir.snap @@ -7,7 +7,7 @@ contract { CONFIG = config u64, abi_decode_in_place_0, 0x00000000000004d2 pub fn abi_decode_in_place_0(__ptr: u64, len: u64, target: u64) -> () { - entry(__ptr: u64, len: u64, target: u64): + entry(mut __ptr: u64, mut len: u64, mut target: u64): v4v1 = const unit () ret () v4v1 } @@ -28,7 +28,7 @@ contract { } fn poke_0(_x: u64) -> () { - entry(_x: u64): + entry(mut _x: u64): v16v1 = const unit () ret () v16v1 } diff --git a/sway-ir/tests/dce/dce_dead_constant_assignment.ir b/sway-ir/tests/dce/dce_dead_constant_assignment.ir index 158e7efb6b6..0e7f6f26445 100644 --- a/sway-ir/tests/dce/dce_dead_constant_assignment.ir +++ b/sway-ir/tests/dce/dce_dead_constant_assignment.ir @@ -34,11 +34,3 @@ script { ret () v11 } } - -// regex: VAL=v\d+v\d+ - -// check: entry fn main() -> () { -// nextln: entry(): -// nextln: $(v0=$VAL) = const unit () -// nextln: ret () $v0 -// nextln: } diff --git a/sway-ir/tests/dce/dce_int_to_ptr.ir b/sway-ir/tests/dce/dce_int_to_ptr.ir index 95d55193fc6..8e12c149cdb 100644 --- a/sway-ir/tests/dce/dce_int_to_ptr.ir +++ b/sway-ir/tests/dce/dce_int_to_ptr.ir @@ -41,12 +41,3 @@ script { ret bool v2_5 } } - -// check: local mut u64 x -// check: local mut u64 y -// not: local mut u64 y -// check: block2 -// check: store -// not: get_local __ptr u64, dummy -// not: store -// check: ret bool diff --git a/sway-ir/tests/dce/dce_int_to_ptr.ir.snap b/sway-ir/tests/dce/dce_int_to_ptr.ir.snap index 75b73c79b39..f6aa564b94b 100644 --- a/sway-ir/tests/dce/dce_int_to_ptr.ir.snap +++ b/sway-ir/tests/dce/dce_int_to_ptr.ir.snap @@ -35,7 +35,7 @@ script { v20v1 = ptr_to_int v19v1 to u64 br block2(v20v1) - block2(v1v1: u64): + block2(mut v1v1: u64): v22v1 = int_to_ptr v1v1 to __ptr u64 v23v1 = const u64 42 store v23v1 to v22v1 diff --git a/sway-ir/tests/dce/dce_load_from_b256.ir b/sway-ir/tests/dce/dce_load_from_b256.ir index c6f0f82623d..e49cca2f1a0 100644 --- a/sway-ir/tests/dce/dce_load_from_b256.ir +++ b/sway-ir/tests/dce/dce_load_from_b256.ir @@ -30,9 +30,3 @@ script { ret b256 v0 } } - -// check: entry fn main() -> () { -// not: local b256 x -// check: entry(): -// not: get_local __ptr b256, x -// check: ret () diff --git a/sway-ir/tests/dce/dce_load_from_b256.ir.snap b/sway-ir/tests/dce/dce_load_from_b256.ir.snap index 4ba747637d6..ed2b2f476a9 100644 --- a/sway-ir/tests/dce/dce_load_from_b256.ir.snap +++ b/sway-ir/tests/dce/dce_load_from_b256.ir.snap @@ -22,7 +22,7 @@ script { } fn take_b256_2(_x: b256) -> b256 { - entry(_x: b256): + entry(mut _x: b256): v12v1 = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 ret b256 v12v1 } diff --git a/sway-ir/tests/dce/dce_load_from_struct.ir b/sway-ir/tests/dce/dce_load_from_struct.ir index b889e029113..c34269b8e25 100644 --- a/sway-ir/tests/dce/dce_load_from_struct.ir +++ b/sway-ir/tests/dce/dce_load_from_struct.ir @@ -43,9 +43,3 @@ script { ret { u64, u64 } v1 } } - -// check: entry fn main() -> () { -// not: local { u64, u64 } x -// check: entry(): -// not: get_local __ptr { u64, u64 }, x -// check: ret () diff --git a/sway-ir/tests/dce/dce_load_from_struct.ir.snap b/sway-ir/tests/dce/dce_load_from_struct.ir.snap index f9f62767f74..dee9d7e821b 100644 --- a/sway-ir/tests/dce/dce_load_from_struct.ir.snap +++ b/sway-ir/tests/dce/dce_load_from_struct.ir.snap @@ -34,7 +34,7 @@ script { fn take_struct_2(_x: { u64, u64 }) -> { u64, u64 } { local { u64, u64 } __anon_0 - entry(_x: { u64, u64 }): + entry(mut _x: { u64, u64 }): v21v1 = get_local __ptr { u64, u64 }, __anon_0 v22v1 = load v21v1 ret { u64, u64 } v22v1 diff --git a/sway-ir/tests/dce/dce_mem_clear_val_removal.ir b/sway-ir/tests/dce/dce_mem_clear_val_removal.ir index b12d9b8eff0..d6736d5226b 100644 --- a/sway-ir/tests/dce/dce_mem_clear_val_removal.ir +++ b/sway-ir/tests/dce/dce_mem_clear_val_removal.ir @@ -18,9 +18,3 @@ script { ret bool v224v1 } } - -// regex: VAL=v\d+v\d+ - -// not: local { u64 } -// not: get_local __ptr { u64 } -// not: mem_clear_val $VAL diff --git a/sway-ir/tests/demote_arg/demote_arg00.ir b/sway-ir/tests/demote_arg/demote_arg00.ir index 03178cf8c1d..37a5bc42269 100644 --- a/sway-ir/tests/demote_arg/demote_arg00.ir +++ b/sway-ir/tests/demote_arg/demote_arg00.ir @@ -17,11 +17,3 @@ script { ret bool v0 } } - -// regex: ID=[[:alpha:]_0-9]+ - -// check: fn foo($ID: __ptr b256) -> bool -// check: entry($ID: __ptr b256): - -// check: fn bar($ID: __ptr b256, $ID: u64) -> bool -// check: entry($ID: __ptr b256, $ID: u64): diff --git a/sway-ir/tests/demote_arg/demote_arg00.ir.snap b/sway-ir/tests/demote_arg/demote_arg00.ir.snap index 297563928ac..5bc873a31e2 100644 --- a/sway-ir/tests/demote_arg/demote_arg00.ir.snap +++ b/sway-ir/tests/demote_arg/demote_arg00.ir.snap @@ -11,18 +11,18 @@ script { } - fn foo(e: b256) -> bool { -- entry(e: b256): +- entry(mut e: b256): + fn foo(e: __ptr b256) -> bool { -+ entry(e: __ptr b256): ++ entry(mut e: __ptr b256): + v11v1 = load e v4v1 = const bool false ret bool v4v1 } - fn bar(i: b256, j: u64) -> bool { -- entry(i: b256, j: u64): +- entry(mut i: b256, mut j: u64): + fn bar(i: __ptr b256, j: u64) -> bool { -+ entry(i: __ptr b256, j: u64): ++ entry(mut i: __ptr b256, mut j: u64): + v13v1 = load i v8v1 = const bool false ret bool v8v1 diff --git a/sway-ir/tests/demote_arg/demote_arg01.ir b/sway-ir/tests/demote_arg/demote_arg01.ir index 83c9183c0fd..d310558d018 100644 --- a/sway-ir/tests/demote_arg/demote_arg01.ir +++ b/sway-ir/tests/demote_arg/demote_arg01.ir @@ -19,13 +19,3 @@ script { ret () v1 } } - -// regex: ID=[[:alpha:]_0-9]+ - -// check: fn main -// check: local b256 $(tmp_arg=$ID) - -// check: $(load_val=$ID) = load $ID -// check: $(get_loc_val=$ID) = get_local __ptr b256, $tmp_arg -// check: store $load_val to $get_loc_val -// check: call foo($get_loc_val, $ID) diff --git a/sway-ir/tests/demote_arg/demote_arg01.ir.snap b/sway-ir/tests/demote_arg/demote_arg01.ir.snap index 86a44860740..afde93211bb 100644 --- a/sway-ir/tests/demote_arg/demote_arg01.ir.snap +++ b/sway-ir/tests/demote_arg/demote_arg01.ir.snap @@ -21,9 +21,9 @@ script { } - fn foo(x: b256, y: u64) -> () { -- entry(x: b256, y: u64): +- entry(mut x: b256, mut y: u64): + fn foo(x: __ptr b256, y: u64) -> () { -+ entry(x: __ptr b256, y: u64): ++ entry(mut x: __ptr b256, mut y: u64): + v14v1 = load x v9v1 = const u64 0 log u64 y, v9v1 diff --git a/sway-ir/tests/demote_arg/demote_arg02.ir b/sway-ir/tests/demote_arg/demote_arg02.ir index c64288d85e5..d8d23f6236f 100644 --- a/sway-ir/tests/demote_arg/demote_arg02.ir +++ b/sway-ir/tests/demote_arg/demote_arg02.ir @@ -42,26 +42,3 @@ script { ret () v1 } } - -// regex: ID=[[:alpha:]_0-9]+ - -// check: fn main -// check: local b256 $(tmp_arg0=$ID) -// check: local b256 $(tmp_arg1=$ID) - -// check: $(tmp_arg0_ptr=$ID) = get_local __ptr b256, $tmp_arg0 -// check: call foo($tmp_arg0_ptr, $ID) - -// check: $(tmp_arg1_ptr=$ID) = get_local __ptr b256, $tmp_arg1 -// check: call foo($tmp_arg1_ptr, $ID) - -// check: fn bar -// check: local b256 $(tmp_arg0=$ID) -// check: local b256 $(tmp_arg1=$ID) - -// check: $(tmp_arg0_ptr=$ID) = get_local __ptr b256, $tmp_arg0 -// check: call foo($tmp_arg0_ptr, $ID) - -// check: $(tmp_arg1_ptr=$ID) = get_local __ptr b256, $tmp_arg1 -// check: call foo($tmp_arg1_ptr, $ID) - diff --git a/sway-ir/tests/demote_arg/demote_arg02.ir.snap b/sway-ir/tests/demote_arg/demote_arg02.ir.snap index c88dfbee88c..c9902ac9b7d 100644 --- a/sway-ir/tests/demote_arg/demote_arg02.ir.snap +++ b/sway-ir/tests/demote_arg/demote_arg02.ir.snap @@ -56,9 +56,9 @@ script { } - fn foo(x: b256, y: u64) -> () { -- entry(x: b256, y: u64): +- entry(mut x: b256, mut y: u64): + fn foo(x: __ptr b256, y: u64) -> () { -+ entry(x: __ptr b256, y: u64): ++ entry(mut x: __ptr b256, mut y: u64): + v29v1 = load x v24v1 = const u64 3 log u64 y, v24v1 diff --git a/sway-ir/tests/demote_arg/demote_arg03.ir b/sway-ir/tests/demote_arg/demote_arg03.ir index c258cc96214..a72c9ec7057 100644 --- a/sway-ir/tests/demote_arg/demote_arg03.ir +++ b/sway-ir/tests/demote_arg/demote_arg03.ir @@ -28,24 +28,3 @@ script { ret b256 v0 } } - -// regex: ID=[[:alpha:]_0-9]+ - -// check: fn a(p: bool, $(a_arg=$ID): __ptr b256, $(b_arg=$ID): __ptr b256) -> b256 { -// check: local b256 $(tmp_blk_arg=$ID) - -// check: entry(p: bool, $a_arg: __ptr b256, $b_arg: __ptr b256): -// check: $(load_a_val=$ID) = load $a_arg -// check: $(load_b_val=$ID) = load $b_arg -// check: $(get_local_val=$ID) = get_local __ptr b256, $tmp_blk_arg -// check: store $load_a_val to $get_local_val -// check: cbr p, block2($get_local_val), block1() - -// check: block1(): -// check: $(get_local_val=$ID) = get_local __ptr b256, $tmp_blk_arg -// check: store $load_b_val to $get_local_val -// check: br block2($get_local_val) - -// check: block2($(block2_arg=$ID): __ptr b256): -// check: $(load_val=$ID) = load $block2_arg -// check: ret b256 $load_val diff --git a/sway-ir/tests/demote_arg/demote_arg03.ir.snap b/sway-ir/tests/demote_arg/demote_arg03.ir.snap index fab4a39694e..4fa571d7e2d 100644 --- a/sway-ir/tests/demote_arg/demote_arg03.ir.snap +++ b/sway-ir/tests/demote_arg/demote_arg03.ir.snap @@ -31,12 +31,12 @@ script { } - fn a(p: bool, a: b256, b: b256) -> b256 { -- entry(p: bool, a: b256, b: b256): +- entry(mut p: bool, mut a: b256, mut b: b256): - cbr p, block2(a), block1() + fn a(p: bool, a: __ptr b256, b: __ptr b256) -> b256 { + local b256 __tmp_block_arg -+ entry(p: bool, a: __ptr b256, b: __ptr b256): ++ entry(mut p: bool, mut a: __ptr b256, mut b: __ptr b256): + v20v1 = load a + v21v1 = load b + v29v1 = get_local __ptr b256, __tmp_block_arg @@ -49,9 +49,9 @@ script { + store v21v1 to v31v1 + br block2(v31v1) -- block2(v14v1: b256): +- block2(mut v14v1: b256): - ret b256 v14v1 -+ block2(v27v1: __ptr b256): ++ block2(mut v27v1: __ptr b256): + v28v1 = load v27v1 + ret b256 v28v1 } diff --git a/sway-ir/tests/demote_arg/demote_arg04.ir b/sway-ir/tests/demote_arg/demote_arg04.ir index 20bd37cf336..749f91725ee 100644 --- a/sway-ir/tests/demote_arg/demote_arg04.ir +++ b/sway-ir/tests/demote_arg/demote_arg04.ir @@ -1,5 +1,3 @@ -// regex: ID=[[:alpha:]_0-9]+ - script { entry fn main() -> () { local b256 ones = const b256 0x1111111111111111111111111111111111111111111111111111111111111111 @@ -24,34 +22,14 @@ script { block1(v10: b256, v11: bool, v12: b256): br block3(v12) -// check: block1($(b10=$ID): __ptr b256, $ID: bool, $(b12=$ID): __ptr b256): -// check: $ID = load $b10 -// check: $(load_val=$ID) = load $b12 -// check: $(get_loc_val=$ID) = get_local __ptr b256, $ID -// check: store $load_val to $get_loc_val -// check: br block3($get_loc_val) - block2(v13: b256, v14: bool, v15: b256): br block3(v15) -// check: block2($(b20=$ID): __ptr b256, $ID: bool, $(b22=$ID): __ptr b256): -// check: $ID = load $b20 -// check: $(load_val=$ID) = load $b22 -// check: $(get_loc_val=$ID) = get_local __ptr b256, $ID -// check: store $load_val to $get_loc_val -// check: br block3($get_loc_val) - block3(v16: b256): v17 = get_local __ptr b256, tmp store v16 to v17 br exit() -// check: block3($(b30=$ID): __ptr b256): -// check: $(load_val=$ID) = load $b30 -// check: $(get_local_val=$ID) = get_local __ptr b256, $ID -// check: store $load_val to $get_local_val -// check: br exit() - exit(): v18 = const unit () ret () v18 diff --git a/sway-ir/tests/demote_arg/demote_arg04.ir.snap b/sway-ir/tests/demote_arg/demote_arg04.ir.snap index 7c1b5a4c4e6..37a3be9be73 100644 --- a/sway-ir/tests/demote_arg/demote_arg04.ir.snap +++ b/sway-ir/tests/demote_arg/demote_arg04.ir.snap @@ -38,26 +38,26 @@ script { - cbr v16v1, block1(v9v1, v17v1, v11v1), block2(v13v1, v17v1, v15v1) + cbr v16v1, block1(v30v1, v17v1, v32v1), block2(v38v1, v17v1, v40v1) -- block1(v1v1: b256, v2v1: bool, v3v1: b256): +- block1(mut v1v1: b256, mut v2v1: bool, mut v3v1: b256): - br block3(v3v1) -+ block1(v26v1: __ptr b256, v2v1: bool, v28v1: __ptr b256): ++ block1(mut v26v1: __ptr b256, mut v2v1: bool, mut v28v1: __ptr b256): + v27v1 = load v26v1 + v29v1 = load v28v1 + v44v1 = get_local __ptr b256, __tmp_block_arg3 + store v29v1 to v44v1 + br block3(v44v1) -- block2(v4v1: b256, v5v1: bool, v6v1: b256): +- block2(mut v4v1: b256, mut v5v1: bool, mut v6v1: b256): - br block3(v6v1) -+ block2(v34v1: __ptr b256, v5v1: bool, v36v1: __ptr b256): ++ block2(mut v34v1: __ptr b256, mut v5v1: bool, mut v36v1: __ptr b256): + v35v1 = load v34v1 + v37v1 = load v36v1 + v46v1 = get_local __ptr b256, __tmp_block_arg3 + store v37v1 to v46v1 + br block3(v46v1) -- block3(v7v1: b256): -+ block3(v42v1: __ptr b256): +- block3(mut v7v1: b256): ++ block3(mut v42v1: __ptr b256): + v43v1 = load v42v1 v21v1 = get_local __ptr b256, tmp - store v7v1 to v21v1 diff --git a/sway-ir/tests/demote_const/demote_const00.ir b/sway-ir/tests/demote_const/demote_const00.ir index c8de27f32f7..1151f8e6613 100644 --- a/sway-ir/tests/demote_const/demote_const00.ir +++ b/sway-ir/tests/demote_const/demote_const00.ir @@ -1,17 +1,7 @@ -// regex: ID=[[:alpha:]0-9_]+ - script { entry fn main() -> b256 { -// check: local b256 $(loc=$ID) = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b - entry(): v0 = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b - -// not: const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b -// check: $(loc_var=$ID) = get_local __ptr b256, $loc -// check: $(loc_val=$ID) = load $loc_var - ret b256 v0 -// check: ret b256 $loc_val } } diff --git a/sway-ir/tests/demote_const/demote_const01.ir b/sway-ir/tests/demote_const/demote_const01.ir index 1497cf2ec00..bf73e595c5e 100644 --- a/sway-ir/tests/demote_const/demote_const01.ir +++ b/sway-ir/tests/demote_const/demote_const01.ir @@ -1,17 +1,7 @@ -// regex: ID=[[:alpha:]0-9_]+ - script { entry fn main() -> { u64, bool } { -// check: local { u64, bool } $(loc=$ID) = const { u64, bool } { u64 42, bool false } - entry(): v0 = const { u64, bool } { u64 42, bool false } - -// not: const { u64, bool } { u64 42, bool false } -// check: $(loc_var=$ID) = get_local __ptr { u64, bool }, $loc -// check: $(loc_val=$ID) = load $loc_var - ret { u64, bool } v0 -// check: ret { u64, bool } $loc_val } } diff --git a/sway-ir/tests/demote_misc/demote_asm_block_arg.ir b/sway-ir/tests/demote_misc/demote_asm_block_arg.ir index 35487c51c94..dd55ab1b631 100644 --- a/sway-ir/tests/demote_misc/demote_asm_block_arg.ir +++ b/sway-ir/tests/demote_misc/demote_asm_block_arg.ir @@ -10,16 +10,3 @@ script { ret bool v2 } } - -// regex: VAL=v\d+v\d+ -// regex: ID=[[:alpha:]0-9_]+ - -// check: $(arg_0=$VAL) = get_local __ptr b256, $ID -// check: $(cval_0=$VAL) = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b -// check: store $cval_0 to $arg_0 - -// check: $(arg_1=$VAL) = get_local __ptr b256, __asm_arg0 -// check: $(cval_1=$VAL) = const b256 0x2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c -// check: store $cval_1 to $arg_1 - -// check: $VAL = asm(r1: $arg_0, r2: $arg_1, r3, r4) -> bool r4 diff --git a/sway-ir/tests/demote_misc/demote_asm_block_ret.ir b/sway-ir/tests/demote_misc/demote_asm_block_ret.ir index f5c17fc4a18..d0c36a45759 100644 --- a/sway-ir/tests/demote_misc/demote_asm_block_ret.ir +++ b/sway-ir/tests/demote_misc/demote_asm_block_ret.ir @@ -6,12 +6,3 @@ script { ret b256 v2 } } - -// regex: VAL=v\d+v\d+ -// regex: ID=[[:alpha:]0-9_]+ - -// check: $(tmp_ptr=$VAL) = get_local __ptr b256, $ID -// check: store $VAL to $tmp_ptr -// check: $(asm_ret_ptr=$VAL) = asm(pointer: $tmp_ptr) -> __ptr b256 pointer -// check: $(asm_val=$VAL) = load $asm_ret_ptr -// check: ret b256 $asm_val diff --git a/sway-ir/tests/demote_misc/demote_log.ir b/sway-ir/tests/demote_misc/demote_log.ir index c06be582922..50aedff9353 100644 --- a/sway-ir/tests/demote_misc/demote_log.ir +++ b/sway-ir/tests/demote_misc/demote_log.ir @@ -8,12 +8,3 @@ script { ret () v2 } } - -// regex: VAL=v\d+v\d+ -// regex: ID=[[:alpha:]0-9_]+ - -// check: local b256 $(loc_name=$ID) - -// check: $(arg_ptr=$VAL) = get_local __ptr b256, $loc_name -// check: store $VAL to $arg_ptr -// check: log __ptr b256 $arg_ptr, $VAL diff --git a/sway-ir/tests/demote_misc/demote_wide_binary_ops_constants.ir b/sway-ir/tests/demote_misc/demote_wide_binary_ops_constants.ir index faf7920678e..c0e70051128 100644 --- a/sway-ir/tests/demote_misc/demote_wide_binary_ops_constants.ir +++ b/sway-ir/tests/demote_misc/demote_wide_binary_ops_constants.ir @@ -9,15 +9,3 @@ script { ret u256 v2 } } - -// regex: VAL=v\d+v\d+ - -// check: $(v0=$VAL) = get_local __ptr u256, __wide_lhs -// check: $(v1=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000001 -// check: store $v1 to $v0 -// check: $(v2=$VAL) = get_local __ptr u256, __wide_rhs -// check: $(v3=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000002 -// check: store $v3 to $v2 -// check: $(v4=$VAL) = get_local __ptr u256, __wide_result -// check: wide add $v0, $v2 to $v4 -// check: $(v5=$VAL) = load $v4 diff --git a/sway-ir/tests/demote_misc/demote_wide_binary_ops_loads.ir b/sway-ir/tests/demote_misc/demote_wide_binary_ops_loads.ir index a5d0f5fb1a7..9113f4018e5 100644 --- a/sway-ir/tests/demote_misc/demote_wide_binary_ops_loads.ir +++ b/sway-ir/tests/demote_misc/demote_wide_binary_ops_loads.ir @@ -11,24 +11,3 @@ script { ret u256 v4 } } - -// regex: VAL=v\d+v\d+ - -// check: local u256 __wide_lhs -// check: local mut u256 __wide_result -// check: local u256 __wide_rhs -// check: local u256 lhs -// check: local u256 rhs -// check: entry(): -// check: $(v0=$VAL) = get_local __ptr u256, lhs -// check: $(v1=$VAL) = load $v0 -// check: $(v2=$VAL) = get_local __ptr u256, rhs -// check: $(v3=$VAL) = load $v2 -// check: $(v4=$VAL) = get_local __ptr u256, __wide_lhs -// check: store $v1 to $v4 -// check: $(v5=$VAL) = get_local __ptr u256, __wide_rhs -// check: store $v3 to $v5 -// check: $(v6=$VAL) = get_local __ptr u256, __wide_result -// check: wide add $v4, $v5 to $v6 -// check: $(v7=$VAL) = load $v6 -// check: ret u256 $v7 diff --git a/sway-ir/tests/demote_misc/demote_wide_cmp_constants.ir b/sway-ir/tests/demote_misc/demote_wide_cmp_constants.ir index 891bf13da47..76bf53dc29b 100644 --- a/sway-ir/tests/demote_misc/demote_wide_cmp_constants.ir +++ b/sway-ir/tests/demote_misc/demote_wide_cmp_constants.ir @@ -7,13 +7,3 @@ script { ret bool v2 } } - -// regex: VAL=v\d+v\d+ - -// check: $(v0=$VAL) = get_local __ptr u256, __wide_lhs -// check: $(v1=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000001 -// check: store $v1 to $v0 -// check: $(v2=$VAL) = get_local __ptr u256, __wide_rhs -// check: $(v3=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000002 -// check: store $v3 to $v2 -// check: $(v4=$VAL) = wide cmp eq $v0 $v2 diff --git a/sway-ir/tests/demote_misc/demote_wide_mod_constants.ir b/sway-ir/tests/demote_misc/demote_wide_mod_constants.ir index 511e15ba1f8..a00c4679df1 100644 --- a/sway-ir/tests/demote_misc/demote_wide_mod_constants.ir +++ b/sway-ir/tests/demote_misc/demote_wide_mod_constants.ir @@ -11,25 +11,3 @@ script { ret u256 v4 } } - -// regex: VAL=v\d+v\d+ - -// check: local u256 __wide_lhs -// check: local mut u256 __wide_result -// check: local u256 __wide_rhs -// check: local u256 lhs -// check: local u256 rhs -// check: entry(): -// check: $(v0=$VAL) = get_local __ptr u256, lhs -// check: $(v1=$VAL) = load $v0 -// check: $(v2=$VAL) = get_local __ptr u256, rhs -// check: $(v3=$VAL) = load $v2 -// check: $(v4=$VAL) = get_local __ptr u256, __wide_lhs -// check: store $v1 to $v4 -// check: $(v5=$VAL) = get_local __ptr u256, __wide_zero -// check: $(v6=$VAL) = get_local __ptr u256, __wide_rhs -// check: store $v3 to $v6 -// check: $(v7=$VAL) = get_local __ptr u256, __wide_result -// check: wide mod $v4, $v5, $v6 to $v7 -// check: $(v8=$VAL) = load $v7 -// check: ret u256 $v8 diff --git a/sway-ir/tests/demote_misc/demote_wide_not_constants.ir b/sway-ir/tests/demote_misc/demote_wide_not_constants.ir index 0ef5fae939b..88db81e0081 100644 --- a/sway-ir/tests/demote_misc/demote_wide_not_constants.ir +++ b/sway-ir/tests/demote_misc/demote_wide_not_constants.ir @@ -7,11 +7,3 @@ script { ret bool v2 } } - -// regex: VAL=v\d+v\d+ - -// check: $(v0=$VAL) = get_local __ptr u256, __wide_lhs -// check: $(v1=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000001 -// check: store $v1 to $v0 -// check: $(v2=$VAL) = get_local __ptr u256, __wide_result -// check: wide not $v0 to $v2 diff --git a/sway-ir/tests/demote_ret/demote_ret00.ir b/sway-ir/tests/demote_ret/demote_ret00.ir index 4e79d01d8c6..72dd7e1c593 100644 --- a/sway-ir/tests/demote_ret/demote_ret00.ir +++ b/sway-ir/tests/demote_ret/demote_ret00.ir @@ -1,32 +1,17 @@ -// regex: ID=[[:alpha:]0-9_]+ - script { entry fn main() -> () { -// check: local b256 $(ret_var=$ID) - entry(): v0 = call a() - -// check: $(local_val=$ID) = get_local __ptr b256, $ret_var -// check: $ID = call a($local_val) -// check: $ID = load $local_val - v1 = const unit () ret () v1 } fn a() -> b256 { -// check: fn a($(ret_arg_val=$ID): __ptr b256) -> () { local b256 __const = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b entry(): v0 = get_local __ptr b256, __const v1 = load v0 ret b256 v1 - -// check: $(twobee=$ID) = get_local __ptr b256, __const -// check: $(load_val=$ID) = load $twobee -// check: store $load_val to $ret_arg_val -// check: ret () } } diff --git a/sway-ir/tests/demote_ret/demote_ret00.ir.snap b/sway-ir/tests/demote_ret/demote_ret00.ir.snap index cfd72448946..0443280b9ee 100644 --- a/sway-ir/tests/demote_ret/demote_ret00.ir.snap +++ b/sway-ir/tests/demote_ret/demote_ret00.ir.snap @@ -17,11 +17,11 @@ script { } - fn a() -> b256 { -+ fn a(__ret_value: __ptr b256) -> () { ++ fn a(mut __ret_value: __ptr b256) -> () { local b256 __const = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b - entry(): -+ entry(__ret_value: __ptr b256): ++ entry(mut __ret_value: __ptr b256): v4v1 = get_local __ptr b256, __const v5v1 = load v4v1 - ret b256 v5v1 diff --git a/sway-ir/tests/demote_ret/demote_ret01.ir b/sway-ir/tests/demote_ret/demote_ret01.ir index 8a2ddcbb443..93fd611cef8 100644 --- a/sway-ir/tests/demote_ret/demote_ret01.ir +++ b/sway-ir/tests/demote_ret/demote_ret01.ir @@ -1,5 +1,3 @@ -// regex: ID=[[:alpha:]0-9_]+ - script { entry fn main() -> () { local b256 tmp @@ -9,23 +7,12 @@ script { v1 = const bool true v2 = call c(v0, v1) v3 = get_local __ptr b256, tmp -// check: $(ptr_arg_val=$ID) = get_local __ptr b256, $ID store v2 to v3 - -// check: $ID = call c($ID, $ID, $ptr_arg_val) -// check: $(load_val=$ID) = load $ptr_arg_val -// check: $(tmp_val=$ID) = get_local __ptr b256, tmp -// check: store $load_val to $tmp_val - v4 = const unit () ret () v4 } fn c(p: bool, q: bool) -> b256 { -// check: local b256 $(ret_val=$ID) -// check: local b256 $(ret_val0=$ID) -// check: local b256 $(ret_val1=$ID) - entry(p: bool, q: bool): cbr p, block0(), block1() @@ -33,29 +20,16 @@ script { v0 = call a() br block5(v0) -// check: $(ptr_arg_val=$ID) = get_local __ptr b256, $ret_val -// check: $(ret_val=$ID) = call a($ptr_arg_val) -// check: $(load_val=$ID) = load $ptr_arg_val -// check: br block5($load_val) - block1(): cbr q, block2(), block3() block2(): v1 = call a() br block5(v1) -// check: $(ptr_arg_val=$ID) = get_local __ptr b256, $ret_val0 -// check: $ID = call a($ptr_arg_val) -// check: $(load_val=$ID) = load $ptr_arg_val -// check: br block5($load_val) block3(): v2 = call b() br block5(v2) -// check: $(ptr_arg_val=$ID) = get_local __ptr b256, $ret_val1 -// check: $ID = call b($ptr_arg_val) -// check: $(load_val=$ID) = load $ptr_arg_val -// check: br block5($load_val) block5(v3: b256): ret b256 v3 diff --git a/sway-ir/tests/demote_ret/demote_ret01.ir.snap b/sway-ir/tests/demote_ret/demote_ret01.ir.snap index 9e6f73c8e1f..9d30c8ce8d0 100644 --- a/sway-ir/tests/demote_ret/demote_ret01.ir.snap +++ b/sway-ir/tests/demote_ret/demote_ret01.ir.snap @@ -23,13 +23,13 @@ script { } - fn c(p: bool, q: bool) -> b256 { -- entry(p: bool, q: bool): -+ fn c(p: bool, q: bool, __ret_value: __ptr b256) -> () { +- entry(mut p: bool, mut q: bool): ++ fn c(p: bool, q: bool, mut __ret_value: __ptr b256) -> () { + local b256 __ret_val + local b256 __ret_val0 + local b256 __ret_val1 + -+ entry(p: bool, q: bool, __ret_value: __ptr b256): ++ entry(mut p: bool, mut q: bool, mut __ret_value: __ptr b256): cbr p, block0(), block1() block0(): @@ -59,7 +59,7 @@ script { + v49v1 = load v47v1 + br block5(v49v1) - block5(v10v1: b256): + block5(mut v10v1: b256): - ret b256 v10v1 + store v10v1 to __ret_value + v28v1 = const unit () @@ -67,11 +67,11 @@ script { } - fn a() -> b256 { -+ fn a(__ret_value: __ptr b256) -> () { ++ fn a(mut __ret_value: __ptr b256) -> () { local b256 twobee = const b256 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b - entry(): -+ entry(__ret_value: __ptr b256): ++ entry(mut __ret_value: __ptr b256): v20v1 = get_local __ptr b256, twobee v21v1 = load v20v1 - ret b256 v21v1 @@ -81,11 +81,11 @@ script { } - fn b() -> b256 { -+ fn b(__ret_value: __ptr b256) -> () { ++ fn b(mut __ret_value: __ptr b256) -> () { local b256 dada = const b256 0xdadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadada - entry(): -+ entry(__ret_value: __ptr b256): ++ entry(mut __ret_value: __ptr b256): v23v1 = get_local __ptr b256, dada v24v1 = load v23v1 - ret b256 v24v1 diff --git a/sway-ir/tests/fn_dedup/debug/debug-dce.ir b/sway-ir/tests/fn_dedup/debug/debug-dce.ir index 2d0be2e1187..526f7722d95 100644 --- a/sway-ir/tests/fn_dedup/debug/debug-dce.ir +++ b/sway-ir/tests/fn_dedup/debug/debug-dce.ir @@ -1,5 +1,3 @@ -// regex: FOONAME=fn (foo_1|foo_3) - script { entry fn main() -> bool, !1 { entry(): @@ -18,7 +16,6 @@ script { ret bool v6 } - // check: $(FOONAME) fn foo_1(t1 !9: u64, t2 !10: u64) -> bool, !13 { entry(t1: u64, t2: u64): v0 = call eq_2(t1, t2), !14 @@ -31,7 +28,6 @@ script { ret bool v0 } - // not: $(FOONAME) fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !19 { entry(t1: u64, t2: u64): v0 = call eq_4(t1, t2), !14 diff --git a/sway-ir/tests/fn_dedup/debug/debug-dce.ir.snap b/sway-ir/tests/fn_dedup/debug/debug-dce.ir.snap index 9276fbefd96..3c17a701d72 100644 --- a/sway-ir/tests/fn_dedup/debug/debug-dce.ir.snap +++ b/sway-ir/tests/fn_dedup/debug/debug-dce.ir.snap @@ -18,31 +18,31 @@ script { v8v1 = call foo_3(v6v1, v7v1), !8 br block1(v8v1), !5 - block1(v1v1: bool): + block1(mut v1v1: bool): ret bool v1v1 } - fn foo_1(t1 !9: u64, t2 !10: u64) -> bool, !13 { + fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !13 { - entry(t1: u64, t2: u64): + entry(mut t1: u64, mut t2: u64): - v13v1 = call eq_2(t1, t2), !14 - ret bool v13v1 - } - - pub fn eq_2(self !16: u64, other !17: u64) -> bool, !18 { -- entry(self: u64, other: u64): +- entry(mut self: u64, mut other: u64): - v17v1 = cmp eq self other - ret bool v17v1 - } - - fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !19 { -- entry(t1: u64, t2: u64): +- entry(mut t1: u64, mut t2: u64): v21v1 = call eq_4(t1, t2), !14 ret bool v21v1 } pub fn eq_4(self !16: u64, other !17: u64) -> bool, !18 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): v25v1 = cmp eq self other ret bool v25v1 } diff --git a/sway-ir/tests/fn_dedup/debug/debug-nodce.ir b/sway-ir/tests/fn_dedup/debug/debug-nodce.ir index bd6b25f51be..c9d2c944c62 100644 --- a/sway-ir/tests/fn_dedup/debug/debug-nodce.ir +++ b/sway-ir/tests/fn_dedup/debug/debug-nodce.ir @@ -1,5 +1,3 @@ -// regex: FOONAME=fn (foo_1|foo_3) - script { entry fn main() -> bool, !1 { entry(): @@ -18,7 +16,6 @@ script { ret bool v6 } - // check: $(FOONAME) fn foo_1(t1 !9: u64, t2 !10: u64) -> bool, !13 { entry(t1: u64, t2: u64): v0 = call eq_2(t1, t2), !14 @@ -31,7 +28,6 @@ script { ret bool v0 } - // check: $(FOONAME) fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !19 { entry(t1: u64, t2: u64): v0 = call eq_4(t1, t2), !20 diff --git a/sway-ir/tests/fn_dedup/debug/debug-nodce.ir.snap b/sway-ir/tests/fn_dedup/debug/debug-nodce.ir.snap index 77bec7e6fc1..e78b32450f2 100644 --- a/sway-ir/tests/fn_dedup/debug/debug-nodce.ir.snap +++ b/sway-ir/tests/fn_dedup/debug/debug-nodce.ir.snap @@ -17,26 +17,26 @@ script { v8v1 = call foo_3(v6v1, v7v1), !8 br block1(v8v1), !5 - block1(v1v1: bool): + block1(mut v1v1: bool): ret bool v1v1 } fn foo_1(t1 !9: u64, t2 !10: u64) -> bool, !13 { - entry(t1: u64, t2: u64): + entry(mut t1: u64, mut t2: u64): - v13v1 = call eq_2(t1, t2), !14 + v13v1 = call eq_4(t1, t2), !14 ret bool v13v1 } - pub fn eq_2(self !16: u64, other !17: u64) -> bool, !18 { -- entry(self: u64, other: u64): +- entry(mut self: u64, mut other: u64): - v17v1 = cmp eq self other - ret bool v17v1 - } - - fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !19 { + fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !15 { - entry(t1: u64, t2: u64): + entry(mut t1: u64, mut t2: u64): - v21v1 = call eq_4(t1, t2), !20 + v21v1 = call eq_4(t1, t2), !16 ret bool v21v1 @@ -44,7 +44,7 @@ script { - pub fn eq_4(self !16: u64, other !17: u64) -> bool, !18 { + pub fn eq_4(self !18: u64, other !19: u64) -> bool, !20 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): v25v1 = cmp eq self other ret bool v25v1 } diff --git a/sway-ir/tests/fn_dedup/release/fuelvm-ops.ir b/sway-ir/tests/fn_dedup/release/fuelvm-ops.ir index c4441045b83..0b8148becc4 100644 --- a/sway-ir/tests/fn_dedup/release/fuelvm-ops.ir +++ b/sway-ir/tests/fn_dedup/release/fuelvm-ops.ir @@ -1,6 +1,5 @@ script { - // check: fn main entry fn main() -> u64 { entry(): v0 = call foo() @@ -11,7 +10,6 @@ script { ret u64 v2 } - // check: fn foo fn foo() -> u64 { entry(): v0 = const u64 0 @@ -26,7 +24,6 @@ script { ret u64 v4 } - // not: fn foo_dup fn foo_dup() -> u64 { entry(): v0 = const u64 0 @@ -41,7 +38,6 @@ script { ret u64 v4 } - // check: fn bar fn bar() -> u64 { entry(): v0 = const u64 0 diff --git a/sway-ir/tests/fn_dedup/release/release-dce.ir b/sway-ir/tests/fn_dedup/release/release-dce.ir index b2d61194444..c9d2c944c62 100644 --- a/sway-ir/tests/fn_dedup/release/release-dce.ir +++ b/sway-ir/tests/fn_dedup/release/release-dce.ir @@ -1,6 +1,3 @@ -// regex: FOONAME=fn foo_[0-9]+ -// regex: EQNAME=fn eq_[0-9]+ - script { entry fn main() -> bool, !1 { entry(): @@ -19,28 +16,24 @@ script { ret bool v6 } - // check: $(FOONAME) fn foo_1(t1 !9: u64, t2 !10: u64) -> bool, !13 { entry(t1: u64, t2: u64): v0 = call eq_2(t1, t2), !14 ret bool v0 } - // check: $(EQNAME) pub fn eq_2(self !16: u64, other !17: u64) -> bool, !18 { entry(self: u64, other: u64): v0 = cmp eq self other ret bool v0 } - // not: $(FOONAME) fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !19 { entry(t1: u64, t2: u64): v0 = call eq_4(t1, t2), !20 ret bool v0 } - // not: $(EQNAME) pub fn eq_4(self !16: u64, other !17: u64) -> bool, !18 { entry(self: u64, other: u64): v0 = cmp eq self other diff --git a/sway-ir/tests/fn_dedup/release/release-dce.ir.snap b/sway-ir/tests/fn_dedup/release/release-dce.ir.snap index fe7a18d6ba7..704ad1abd86 100644 --- a/sway-ir/tests/fn_dedup/release/release-dce.ir.snap +++ b/sway-ir/tests/fn_dedup/release/release-dce.ir.snap @@ -18,32 +18,32 @@ script { v8v1 = call foo_3(v6v1, v7v1), !8 br block1(v8v1), !5 - block1(v1v1: bool): + block1(mut v1v1: bool): ret bool v1v1 } - fn foo_1(t1 !9: u64, t2 !10: u64) -> bool, !13 { + fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !13 { - entry(t1: u64, t2: u64): + entry(mut t1: u64, mut t2: u64): - v13v1 = call eq_2(t1, t2), !14 - ret bool v13v1 - } - - pub fn eq_2(self !16: u64, other !17: u64) -> bool, !18 { -- entry(self: u64, other: u64): +- entry(mut self: u64, mut other: u64): - v17v1 = cmp eq self other - ret bool v17v1 - } - - fn foo_3(t1 !9: u64, t2 !10: u64) -> bool, !19 { -- entry(t1: u64, t2: u64): +- entry(mut t1: u64, mut t2: u64): - v21v1 = call eq_4(t1, t2), !20 + v21v1 = call eq_4(t1, t2), !14 ret bool v21v1 } pub fn eq_4(self !16: u64, other !17: u64) -> bool, !18 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): v25v1 = cmp eq self other ret bool v25v1 } diff --git a/sway-ir/tests/globals_dce/dce_dead_global.ir b/sway-ir/tests/globals_dce/dce_dead_global.ir index 7e9625989ed..a212d4deb2d 100644 --- a/sway-ir/tests/globals_dce/dce_dead_global.ir +++ b/sway-ir/tests/globals_dce/dce_dead_global.ir @@ -10,5 +10,3 @@ contract { ret u64 v1 } } - -// not: global X diff --git a/sway-ir/tests/inline/big_asm_blocks.ir b/sway-ir/tests/inline/big_asm_blocks.ir index 4bde773b71d..0ddaec3a46b 100644 --- a/sway-ir/tests/inline/big_asm_blocks.ir +++ b/sway-ir/tests/inline/big_asm_blocks.ir @@ -6,60 +6,43 @@ // `testf` must not be inlined. Although it has only a single `asm` instruction, that // one has a large number of instructions. -// regex: VAR=v\d+ -// regex: LABEL=[[:alpha:]0-9_]+ - script { - // check: entry fn main() -> () entry fn main() -> () { entry(): - // check: call testf() - // not: call test_function1() v0 = call test_function1() - - // check: call testf() - // not: call test_function2() + v1 = call test_function2() - - // check: call testf() - // not: call test_function3() + v2 = call test_function3() v3 = const unit () ret () v3 } - // check: fn test_function1() -> () fn test_function1() -> () { entry(): - // check: call testf() v0 = call testf() v1 = const unit () ret () v1 } - // check: fn test_function2() -> bool fn test_function2() -> bool { entry(): - // check: call testf() v0 = call testf() v1 = const bool true ret bool v1 } - // check: fn test_function3() -> u64 fn test_function3() -> u64 { entry(): - // check: call testf() v0 = call testf() v1 = const u64 0 ret u64 v1 } - // check: fn testf() -> () fn testf() -> () { entry(): v0 = asm(r1, r2) -> () { diff --git a/sway-ir/tests/inline/big_asm_blocks.ir.snap b/sway-ir/tests/inline/big_asm_blocks.ir.snap index 0c385341260..d502ce42ca4 100644 --- a/sway-ir/tests/inline/big_asm_blocks.ir.snap +++ b/sway-ir/tests/inline/big_asm_blocks.ir.snap @@ -13,17 +13,17 @@ script { + v7v1 = const unit () + br block0(v7v1) + -+ block0(v18v1: ()): ++ block0(mut v18v1: ()): + v2v3 = call testf() + v10v1 = const bool true + br block1(v10v1) + -+ block1(v20v1: bool): ++ block1(mut v20v1: bool): + v3v3 = call testf() + v13v1 = const u64 0 + br block2(v13v1) + -+ block2(v22v1: u64): ++ block2(mut v22v1: u64): v4v1 = const unit () ret () v4v1 } diff --git a/sway-ir/tests/inline/bigger.ir b/sway-ir/tests/inline/bigger.ir index 817e340bbdf..bf739568611 100644 --- a/sway-ir/tests/inline/bigger.ir +++ b/sway-ir/tests/inline/bigger.ir @@ -19,9 +19,6 @@ // x // } -// regex: VAR=v\d+v\d+ -// regex: ID=[[:alpha:]0-9_]+ - script { fn a(b: bool) -> u64 { local u64 x @@ -49,7 +46,6 @@ script { // inlined and used for CBR and the two blocks in a() too, and then followed by what's after the // call. -// check: fn main fn main() -> u64 { local u64 x @@ -58,17 +54,10 @@ script { v1 = const u64 0 store v1 to v0 -// check: $(arg=$VAR) = const bool true v2 = const bool true -// not: call v3 = call a(v2) -// check: cbr $arg, $(t=$ID)(), $(f=$ID)() -// check: $t(): -// check: $f(): - -// check: get_local __ptr u64, x v4 = get_local __ptr u64, x store v3 to v4 v5 = get_local __ptr u64, x diff --git a/sway-ir/tests/inline/bigger.ir.snap b/sway-ir/tests/inline/bigger.ir.snap index 3f339ca3db7..82aab88118c 100644 --- a/sway-ir/tests/inline/bigger.ir.snap +++ b/sway-ir/tests/inline/bigger.ir.snap @@ -7,7 +7,7 @@ script { fn a(b: bool) -> u64 { local u64 x - entry(b: bool): + entry(mut b: bool): v3v1 = get_local __ptr u64, x v4v1 = const u64 10 store v4v1 to v3v1 @@ -22,7 +22,7 @@ script { v10v1 = const u64 1 br block2(v10v1) - block2(v2v1: u64): + block2(mut v2v1: u64): ret u64 v2v1 } @@ -50,10 +50,10 @@ script { + v10v1 = const u64 1 + br a_block2(v10v1) + -+ a_block2(v17v3: u64): ++ a_block2(mut v17v3: u64): + br block0(v17v3) + -+ block0(v23v1: u64): ++ block0(mut v23v1: u64): v18v1 = get_local __ptr u64, x - store v17v1 to v18v1 + store v23v1 to v18v1 diff --git a/sway-ir/tests/inline/by_block_and_instr_count.ir b/sway-ir/tests/inline/by_block_and_instr_count.ir index 4e1b603633b..d1bb71ac417 100644 --- a/sway-ir/tests/inline/by_block_and_instr_count.ir +++ b/sway-ir/tests/inline/by_block_and_instr_count.ir @@ -59,19 +59,14 @@ script { } fn main() -> bool { -// check: fn main() -> bool entry(): // This is the only call which should be inlined. v0 = call two_blocks_four_instrs() -// not: call two_blocks_four_instrs() v1 = call two_blocks_five_instrs() -// check: call two_blocks_five_instrs() v2 = call three_blocks_four_instrs() -// check: call three_blocks_four_instrs() v3 = call three_blocks_five_instrs() -// check: call three_blocks_five_instrs() ret bool v3 } diff --git a/sway-ir/tests/inline/by_block_and_instr_count.ir.snap b/sway-ir/tests/inline/by_block_and_instr_count.ir.snap index 74312258843..0c8eff15085 100644 --- a/sway-ir/tests/inline/by_block_and_instr_count.ir.snap +++ b/sway-ir/tests/inline/by_block_and_instr_count.ir.snap @@ -9,7 +9,7 @@ script { v2v1 = const bool true br block(v2v1) - block(v1v1: bool): + block(mut v1v1: bool): v4v1 = const bool false v5v1 = cmp eq v1v1 v4v1 v6v1 = cmp eq v4v1 v5v1 @@ -21,7 +21,7 @@ script { v9v1 = const bool true br block(v9v1) - block(v8v1: bool): + block(mut v8v1: bool): v11v1 = const bool false v12v1 = cmp eq v8v1 v11v1 v13v1 = cmp eq v11v1 v12v1 @@ -31,7 +31,7 @@ script { } fn three_blocks_four_instrs(b: bool) -> bool { - entry(b: bool): + entry(mut b: bool): v18v1 = const bool false v19v1 = cmp eq b v18v1 cbr v19v1, then_block(), else_block() @@ -46,7 +46,7 @@ script { } fn three_blocks_five_instrs(b: bool) -> bool { - entry(b: bool): + entry(mut b: bool): v26v1 = const bool false v27v1 = cmp eq b v26v1 v28v1 = cmp eq b v27v1 @@ -67,13 +67,13 @@ script { + v2v1 = const bool true + br two_blocks_four_instrs_block(v2v1) + -+ two_blocks_four_instrs_block(v34v3: bool): ++ two_blocks_four_instrs_block(mut v34v3: bool): + v4v1 = const bool false + v41v1 = cmp eq v34v3 v4v1 + v42v1 = cmp eq v4v1 v41v1 + br block0(v42v1) + -+ block0(v39v1: bool): ++ block0(mut v39v1: bool): v35v1 = call two_blocks_five_instrs() v36v1 = call three_blocks_four_instrs() v37v1 = call three_blocks_five_instrs() diff --git a/sway-ir/tests/inline/by_block_count.ir b/sway-ir/tests/inline/by_block_count.ir index 2c044ee2d6b..f845e8b81d6 100644 --- a/sway-ir/tests/inline/by_block_count.ir +++ b/sway-ir/tests/inline/by_block_count.ir @@ -30,19 +30,13 @@ script { } fn main() -> bool { -// check: fn main() -> bool entry(): v0 = call one_block() -// not: call one_block() -// check: const bool false v1 = call two_blocks() -// not: call two_blocks() -// check: const bool true v2 = call three_blocks(v1) -// check: call three_blocks ret bool v2 } } diff --git a/sway-ir/tests/inline/by_block_count.ir.snap b/sway-ir/tests/inline/by_block_count.ir.snap index e734121e9d1..72d935c9776 100644 --- a/sway-ir/tests/inline/by_block_count.ir.snap +++ b/sway-ir/tests/inline/by_block_count.ir.snap @@ -15,12 +15,12 @@ script { v4v1 = const bool true br block(v4v1) - block(v3v1: bool): + block(mut v3v1: bool): ret bool v3v1 } fn three_blocks(b: bool) -> bool { - entry(b: bool): + entry(mut b: bool): cbr b, then_block(), else_block() then_block(): @@ -40,14 +40,14 @@ script { + v1v1 = const bool false + br block0(v1v1) + -+ block0(v17v1: bool): ++ block0(mut v17v1: bool): + v4v1 = const bool true + br two_blocks_block(v4v1) + -+ two_blocks_block(v14v3: bool): ++ two_blocks_block(mut v14v3: bool): + br block1(v14v3) + -+ block1(v18v1: bool): ++ block1(mut v18v1: bool): + v15v1 = call three_blocks(v18v1) ret bool v15v1 } diff --git a/sway-ir/tests/inline/by_instr_count.ir b/sway-ir/tests/inline/by_instr_count.ir index 610a6553d5b..b9fc9eebc9c 100644 --- a/sway-ir/tests/inline/by_instr_count.ir +++ b/sway-ir/tests/inline/by_instr_count.ir @@ -89,39 +89,20 @@ script { } fn main() -> bool { -// check: fn main() -> bool entry(): v0 = call less_one_block() -// not: call less_one_block -// check: const u64 11 v1 = call less_two_blocks() -// not: call less_two_blocks -// check: const u64 22 v2 = const bool true v3 = call less_three_blocks(v2) -// not: call less_three_blocks -// check: const u64 33 -// check: const u64 44 v4 = call more_one_block() -// check: call more_one_block -// not: const u64 55 -// not: const u64 66 v5 = call more_two_blocks() -// check: call more_two_blocks -// not: const u64 77 -// not: const u64 88 v6 = call more_three_blocks(v5) -// check: call more_three_blocks -// not: const u64 99 -// not: const u64 1010 -// not: const u64 1111 -// not: const u64 1212 ret bool v6 } diff --git a/sway-ir/tests/inline/by_instr_count.ir.snap b/sway-ir/tests/inline/by_instr_count.ir.snap index 87bd1d696b2..ccd0842f2f5 100644 --- a/sway-ir/tests/inline/by_instr_count.ir.snap +++ b/sway-ir/tests/inline/by_instr_count.ir.snap @@ -15,12 +15,12 @@ script { v4v1 = const u64 22 br block(v4v1) - block(v3v1: u64): + block(mut v3v1: u64): ret u64 v3v1 } fn less_three_blocks(b: bool) -> u64 { - entry(b: bool): + entry(mut b: bool): cbr b, then_block(), else_block() then_block(): @@ -59,12 +59,12 @@ script { v32v1 = cmp eq v30v1 v31v1 br block(v32v1) - block(v23v1: bool): + block(mut v23v1: bool): ret bool v23v1 } fn more_three_blocks(b: bool) -> bool { - entry(b: bool): + entry(mut b: bool): cbr b, then_block(), else_block() then_block(): @@ -91,14 +91,14 @@ script { + v1v1 = const u64 11 + br block0(v1v1) + -+ block0(v57v1: u64): ++ block0(mut v57v1: u64): + v4v1 = const u64 22 + br less_two_blocks_block(v4v1) + -+ less_two_blocks_block(v50v3: u64): ++ less_two_blocks_block(mut v50v3: u64): + br block1(v50v3) + -+ block1(v58v1: u64): ++ block1(mut v58v1: u64): v51v1 = const bool true - v52v1 = call less_three_blocks(v51v1) + cbr v51v1, less_three_blocks_then_block(), less_three_blocks_else_block() @@ -111,7 +111,7 @@ script { + v11v1 = const u64 44 + br block2(v11v1) + -+ block2(v61v1: u64): ++ block2(mut v61v1: u64): v53v1 = call more_one_block() v54v1 = call more_two_blocks() v55v1 = call more_three_blocks(v54v1) diff --git a/sway-ir/tests/inline/by_stack_count.ir b/sway-ir/tests/inline/by_stack_count.ir index b9174d085d2..f5cfccb2472 100644 --- a/sway-ir/tests/inline/by_stack_count.ir +++ b/sway-ir/tests/inline/by_stack_count.ir @@ -63,36 +63,21 @@ script { } fn main() -> u64 { -// check: fn main() -> u64 entry(): v0 = call one_local() -// not: call one_local() -// check: const u64 11 v1 = call two_locals() -// not: call two_locals() -// check: const u64 22 v2 = call three_locals() -// check: call three_locals() -// not: const u64 33 v3 = call two_struct_locals() -// not: call two_struct_locals() -// check: const u64 44 v4 = call three_struct_locals() -// check: call three_struct_locals() -// not: const u64 55 v5 = call two_mixed_locals() -// not: call two_mixed_locals() -// check: const u64 66 v6 = call three_mixed_locals() -// check: call three_mixed_locals() -// not: const u64 77 ret u64 v6 } diff --git a/sway-ir/tests/inline/by_stack_count.ir.snap b/sway-ir/tests/inline/by_stack_count.ir.snap index 5c980f9198e..00945ecff35 100644 --- a/sway-ir/tests/inline/by_stack_count.ir.snap +++ b/sway-ir/tests/inline/by_stack_count.ir.snap @@ -79,23 +79,23 @@ script { + v1v1 = const u64 11 + br block0(v1v1) + -+ block0(v23v1: u64): ++ block0(mut v23v1: u64): + v3v1 = const u64 22 + br block1(v3v1) + -+ block1(v24v1: u64): ++ block1(mut v24v1: u64): v17v1 = call three_locals() - v18v1 = call two_struct_locals() + v7v1 = const u64 44 + br block2(v7v1) + -+ block2(v25v1: u64): ++ block2(mut v25v1: u64): v19v1 = call three_struct_locals() - v20v1 = call two_mixed_locals() + v11v1 = const u64 66 + br block3(v11v1) + -+ block3(v26v1: u64): ++ block3(mut v26v1: u64): v21v1 = call three_mixed_locals() ret u64 v21v1 } diff --git a/sway-ir/tests/inline/fiddly.ir b/sway-ir/tests/inline/fiddly.ir index 5b24a42c948..958051fcdd2 100644 --- a/sway-ir/tests/inline/fiddly.ir +++ b/sway-ir/tests/inline/fiddly.ir @@ -15,10 +15,6 @@ // not(true) || not(false) // } -// regex: ID=[[:alpha:]0-9_]+ -// regex: LABEL=[[:alpha:]0-9_]+\(.*\): -// regex: VAR=v\d+v\d+ - script { fn not(v: bool) -> bool { entry(v: bool): @@ -36,42 +32,17 @@ script { ret bool v2 } -// check: fn main fn main() -> bool { entry(): v0 = const bool true -// not: call v1 = call not(v0) -// * Confirm both the blocks from not() are here, they branch to the same block and that block has a -// phi from each of them. -// check: cbr -// check: $(bl0_lab=$LABEL) -// check: const bool false -// check: br $(bl0_to=$ID) -// check: $(bl1_lab=$LABEL) -// check: const bool true -// check: br $bl0_to -// check: $bl0_to - -// * Match this cbr to not be confused with the inlined cbr below. A more unique marker in not() -// would be better... -// check: cbr cbr v1, block1(v1), block0(v1) block0(v2: bool): v3 = const bool false -// not: call v4 = call not(v3) -// * Check same again for this inlined instance. The consts are re-used so can't check them. -// check: cbr -// check: $(bl2_lab=$LABEL) -// check: br $(bl2_to=$ID) -// check: $(bl3_lab=$LABEL) -// check: br $bl2_to -// check: $bl2_to($VAR: bool): - br block1(v4) block1(v5: bool): diff --git a/sway-ir/tests/inline/fiddly.ir.snap b/sway-ir/tests/inline/fiddly.ir.snap index fc11ffaac68..de4dd695374 100644 --- a/sway-ir/tests/inline/fiddly.ir.snap +++ b/sway-ir/tests/inline/fiddly.ir.snap @@ -5,7 +5,7 @@ Modified: true script { fn not(v: bool) -> bool { - entry(v: bool): + entry(mut v: bool): cbr v, block0(), block1() block0(): @@ -16,7 +16,7 @@ script { v6v1 = const bool true br block2(v6v1) - block2(v2v1: bool): + block2(mut v2v1: bool): ret bool v2v1 } @@ -35,13 +35,13 @@ script { + v6v1 = const bool true + br not_block2(v6v1) + -+ not_block2(v12v3: bool): ++ not_block2(mut v12v3: bool): + br block01(v12v3) + -+ block01(v18v1: bool): ++ block01(mut v18v1: bool): + cbr v18v1, block1(v18v1), block0(v18v1) + - block0(v9v1: bool): + block0(mut v9v1: bool): v14v1 = const bool false - v15v1 = call not(v14v1) - br block1(v15v1) @@ -53,13 +53,13 @@ script { + not_block14(): + br not_block25(v6v1) + -+ not_block25(v15v3: bool): ++ not_block25(mut v15v3: bool): + br block2(v15v3) + -+ block2(v23v1: bool): ++ block2(mut v23v1: bool): + br block1(v23v1) + - block1(v10v1: bool): + block1(mut v10v1: bool): ret bool v10v1 } } diff --git a/sway-ir/tests/inline/int_to_ptr.ir b/sway-ir/tests/inline/int_to_ptr.ir index 2352f45cf69..91a5dd117f0 100644 --- a/sway-ir/tests/inline/int_to_ptr.ir +++ b/sway-ir/tests/inline/int_to_ptr.ir @@ -1,7 +1,4 @@ // all -// -// regex: VAR=v\d+v\d+ -// regex: LABEL=[[:alpha:]0-9_]+ script { fn a(b: u64, __ret_value: __ptr b256) -> __ptr b256 { @@ -12,25 +9,14 @@ script { } fn main() -> __ptr b256 { -// check: fn main local b256 __ret_val_a entry(): v0 = get_local __ptr b256, __ret_val_a v1 = const u64 11 -// check: $(retv=$VAR) = get_local __ptr b256, __ret_val_a -// check: $(arg0=$VAR) = const u64 11 - v2 = call a(v1, v0) -// not: call - -// check: $(ret_ptr=$VAR) = int_to_ptr $arg0 to __ptr b256 -// check: mem_copy_val $retv, $ret_ptr -// check: br $(ret_block=$LABEL)($retv) ret __ptr b256 v2 -// check: $ret_block($VAR: __ptr b256) -// check: ret __ptr b256 } } diff --git a/sway-ir/tests/inline/int_to_ptr.ir.snap b/sway-ir/tests/inline/int_to_ptr.ir.snap index 146febb3283..06f94d10ac5 100644 --- a/sway-ir/tests/inline/int_to_ptr.ir.snap +++ b/sway-ir/tests/inline/int_to_ptr.ir.snap @@ -5,7 +5,7 @@ Modified: true script { fn a(b: u64, __ret_value: __ptr b256) -> __ptr b256 { - entry(b: u64, __ret_value: __ptr b256): + entry(mut b: u64, mut __ret_value: __ptr b256): v3v1 = int_to_ptr b to __ptr b256 mem_copy_val __ret_value, v3v1 ret __ptr b256 __ret_value @@ -23,7 +23,7 @@ script { + mem_copy_val v6v1, v8v3 + br block0(v6v1) + -+ block0(v10v1: __ptr b256): ++ block0(mut v10v1: __ptr b256): + ret __ptr b256 v10v1 } } diff --git a/sway-ir/tests/inline/recursive-1.ir b/sway-ir/tests/inline/recursive-1.ir index be2cb8b7ec8..caac76a4a69 100644 --- a/sway-ir/tests/inline/recursive-1.ir +++ b/sway-ir/tests/inline/recursive-1.ir @@ -1,8 +1,3 @@ -// -// regex: VAR=v\d+v\d+ -// regex: LABEL=[[:alpha:]0-9_]+ -// regex: PING=(ping|id_from_ping) -// regex: PONG=(pong|id_from_pong) script { fn id_from_foo(b: u64) -> u64, !1 { @@ -10,13 +5,10 @@ script { ret u64 b } - // check: fn foo fn foo(b: u64) -> u64 { entry(b: u64): - // check: call id_from_foo v1 = call id_from_foo(b) - // check: call foo v0 = call foo(v1) ret u64 v0 } @@ -31,41 +23,33 @@ script { ret u64 b } - // check: fn main fn main() -> u64 { entry(): v0 = const u64 11 - // check: call foo v1 = call foo(v0) - // check: $PING v2 = call ping(v1) v3 = add v1, v2 ret u64 v3 } - // check: fn ping fn ping(b: u64) -> u64 { entry(b: u64): - // check: id_from_ping v1 = call id_from_ping(b) v0 = call pong(v1) ret u64 v0 } - // check: fn pong fn pong(b: u64) -> u64 { entry(b: u64): - // check: $PONG v1 = call id_from_pong(b) v0 = call ping(v1) ret u64 v0 } - } !1 = inline "never" diff --git a/sway-ir/tests/inline/recursive-1.ir.snap b/sway-ir/tests/inline/recursive-1.ir.snap index 892a35ca931..f6c15f1166b 100644 --- a/sway-ir/tests/inline/recursive-1.ir.snap +++ b/sway-ir/tests/inline/recursive-1.ir.snap @@ -5,24 +5,24 @@ Modified: true script { fn id_from_foo(b: u64) -> u64, !0 { - entry(b: u64): + entry(mut b: u64): ret u64 b } fn foo(b: u64) -> u64 { - entry(b: u64): + entry(mut b: u64): v4v1 = call id_from_foo(b) v5v1 = call foo(v4v1) ret u64 v5v1 } fn id_from_ping(b: u64) -> u64, !0 { - entry(b: u64): + entry(mut b: u64): ret u64 b } fn id_from_pong(b: u64) -> u64, !0 { - entry(b: u64): + entry(mut b: u64): ret u64 b } @@ -36,18 +36,18 @@ script { + v25v1 = call foo(v12v3) + br block0(v25v1) + -+ block0(v24v1: u64): ++ block0(mut v24v1: u64): + v13v3 = call id_from_ping(v24v1) + v28v1 = call pong(v13v3) + br block1(v28v1) + -+ block1(v27v1: u64): ++ block1(mut v27v1: u64): + v14v1 = add v24v1, v27v1 ret u64 v14v1 } fn ping(b: u64) -> u64 { - entry(b: u64): + entry(mut b: u64): v17v1 = call id_from_ping(b) - v18v1 = call pong(v17v1) - ret u64 v18v1 @@ -55,12 +55,12 @@ script { + v31v1 = call ping(v18v3) + br block0(v31v1) + -+ block0(v30v1: u64): ++ block0(mut v30v1: u64): + ret u64 v30v1 } fn pong(b: u64) -> u64 { - entry(b: u64): + entry(mut b: u64): v21v1 = call id_from_pong(b) - v22v1 = call ping(v21v1) - ret u64 v22v1 @@ -69,10 +69,10 @@ script { + v36v1 = call ping(v35v1) + br ping_block0(v36v1) + -+ ping_block0(v22v3: u64): ++ ping_block0(mut v22v3: u64): + br block0(v22v3) + -+ block0(v33v1: u64): ++ block0(mut v33v1: u64): + ret u64 v33v1 } } diff --git a/sway-ir/tests/inline/simple.ir b/sway-ir/tests/inline/simple.ir index b88503b3008..16077f5a878 100644 --- a/sway-ir/tests/inline/simple.ir +++ b/sway-ir/tests/inline/simple.ir @@ -13,36 +13,21 @@ // a(22) // } -// regex: VAR=v\d+v\d+ -// regex: LABEL=[[:alpha:]0-9_]+ - script { fn a(b: u64) -> u64 { entry(b: u64): ret u64 b } - -// check: fn main fn main() -> u64 { entry(): -// check: $(arg0=$VAR) = const u64 11 v0 = const u64 11 -// not: call v1 = call a(v0) -// check: br $(lbl0=$LABEL)($arg0) -// check: $(lbl0)($(arg2=$VAR): u64) -// check: $(arg1=$VAR) = const u64 22 v2 = const u64 22 -// not: call v3 = call a(v2) -// check: br $(lbl1=$LABEL)($arg1) - -// check: $(lbl1)($(arg3=$VAR): u64) ret u64 v3 } } - diff --git a/sway-ir/tests/inline/simple.ir.snap b/sway-ir/tests/inline/simple.ir.snap index 0329a07514a..d13e079e384 100644 --- a/sway-ir/tests/inline/simple.ir.snap +++ b/sway-ir/tests/inline/simple.ir.snap @@ -5,7 +5,7 @@ Modified: true script { fn a(b: u64) -> u64 { - entry(b: u64): + entry(mut b: u64): ret u64 b } @@ -15,13 +15,13 @@ script { - v4v1 = call a(v3v1) + br block0(v3v1) + -+ block0(v8v1: u64): ++ block0(mut v8v1: u64): v5v1 = const u64 22 - v6v1 = call a(v5v1) - ret u64 v6v1 + br block1(v5v1) + -+ block1(v9v1: u64): ++ block1(mut v9v1: u64): + ret u64 v9v1 } } diff --git a/sway-ir/tests/mem2reg/global_simple.ir b/sway-ir/tests/mem2reg/global_simple.ir index 1455359c564..60c70e8ad08 100644 --- a/sway-ir/tests/mem2reg/global_simple.ir +++ b/sway-ir/tests/mem2reg/global_simple.ir @@ -1,14 +1,9 @@ -// regex: VAR=v\d+v\d+ -// regex: ID=[[:alpha:]0-9_]+ - script { global sway3::F1 : u64 = const u64 11 pub entry fn main_0() -> u64, !15 { entry(): v0 = get_global __ptr u64, sway3::F1, !16 v1 = load v0 - // check: $(res=$VAR) = const u64 11 - // check ret u64 $res ret u64 v1 } -} \ No newline at end of file +} diff --git a/sway-ir/tests/mem2reg/is_prime.ir b/sway-ir/tests/mem2reg/is_prime.ir index fb4ca44446a..fea976b54dc 100644 --- a/sway-ir/tests/mem2reg/is_prime.ir +++ b/sway-ir/tests/mem2reg/is_prime.ir @@ -1,6 +1,3 @@ -// regex: VAR=v\d+v\d+ -// regex: ID=[[:alpha:]0-9_]+ - script { fn main() -> bool, !1 { entry(): @@ -113,7 +110,6 @@ script { ret bool v0 } - // check: fn check_prime_4(n fn check_prime_4(n !59: u64) -> bool, !3 { local u64 i local bool is_not_prime @@ -136,22 +132,16 @@ script { br block7(v5) block3(): - // check: $(v6=$VAR) = get_local __ptr bool, is_not_prime v6 = get_local __ptr bool, is_not_prime, !66 v7 = const bool false, !67 - // not: store $VAR to $v6 store v7 to v6, !66 - // check: $(v8=$VAR) = get_local __ptr u64, i v8 = get_local __ptr u64, i, !68 v9 = const u64 2, !69 - // not: store $VAR to $v8 store v9 to v8, !68 br while() while(): - // check: $(v10=$VAR) = get_local __ptr u64, i v10 = get_local __ptr u64, i, !70 - // not: load $v10 v11 = load v10, !70 v12 = call lt_8(v11, n), !71 cbr v12, while_body(), end_while() @@ -165,22 +155,16 @@ script { cbr v17, block4(), block5(), !75 end_while(): - // check: $(v18=$VAR) = get_local __ptr bool, is_not_prime v18 = get_local __ptr bool, is_not_prime, !76 - // not: load $v18 v19 = load v18, !76 v20 = call not_9(v19), !77 br block7(v20) block4(): - // check: $(v21=$VAR) = get_local __ptr bool, is_not_prime v21 = get_local __ptr bool, is_not_prime, !78 v22 = const bool true, !79 - // not: store $VAR to $v21 store v22 to v21, !78 - // check: $(v23=$VAR) = get_local __ptr u64, i v23 = get_local __ptr u64, i, !80 - // not: store $VAR to $v23 store n to v23, !80 v24 = const unit () br block6(v24) @@ -190,15 +174,11 @@ script { br block6(v25) block6(v26: ()): - // check: $(v27=$VAR) = get_local __ptr u64, i v27 = get_local __ptr u64, i, !81 - // check: $(v28=$VAR) = get_local __ptr u64, i v28 = get_local __ptr u64, i, !82 - // not: load $v28 v29 = load v28, !82 v30 = const u64 1, !83 v31 = call add_7(v29, v30), !84 - // not: store $VAR to $v27 store v31 to v27, !81 br while() diff --git a/sway-ir/tests/mem2reg/is_prime.ir.snap b/sway-ir/tests/mem2reg/is_prime.ir.snap index 3367bf46a9a..5e64f5eccab 100644 --- a/sway-ir/tests/mem2reg/is_prime.ir.snap +++ b/sway-ir/tests/mem2reg/is_prime.ir.snap @@ -78,7 +78,7 @@ script { } fn assert_0(condition !45: bool) -> (), !7 { - entry(condition: bool): + entry(mut condition: bool): v72v1 = call not_1(condition), !46 cbr v72v1, block0(), block1(), !46 @@ -92,25 +92,25 @@ script { v78v1 = const unit () br block2(v78v1) - block2(v71v1: ()): + block2(mut v71v1: ()): v80v1 = const unit () ret () v80v1 } fn not_1(self !51: bool) -> bool, !52 { - entry(self: bool): + entry(mut self: bool): v83v1 = const bool false, !53 v84v1 = cmp eq self v83v1 ret bool v84v1 } fn revert_2(code !54: u64) -> (), !49 { - entry(code: u64): + entry(mut code: u64): revert code, !55 } fn eq_3(self !56: bool, other !57: bool) -> bool, !58 { - entry(self: bool, other: bool): + entry(mut self: bool, mut other: bool): v90v1 = cmp eq self other ret bool v90v1 } @@ -119,7 +119,7 @@ script { local u64 i local bool is_not_prime - entry(n: u64): + entry(mut n: u64): v96v1 = const u64 0, !60 v97v1 = call eq_5(n, v96v1), !61 cbr v97v1, block1(v97v1), block0(), !62 @@ -129,7 +129,7 @@ script { v100v1 = call eq_5(n, v99v1), !64 br block1(v100v1), !62 - block1(v93v1: bool): + block1(mut v93v1: bool): cbr v93v1, block2(), block3(), !62 block2(): @@ -150,7 +150,7 @@ script { + br while(v109v1, v106v1) - while(): -+ while(v163v1: u64, v166v1: bool): ++ while(mut v163v1: u64, mut v166v1: bool): v112v1 = get_local __ptr u64, i, !70 - v113v1 = load v112v1, !70 - v114v1 = call lt_8(v113v1, n), !71 @@ -190,8 +190,8 @@ script { - br block6(v133v1) + br block6(v133v1, v163v1, v166v1) -- block6(v94v1: ()): -+ block6(v94v1: (), v164v1: u64, v165v1: bool): +- block6(mut v94v1: ()): ++ block6(mut v94v1: (), mut v164v1: u64, mut v165v1: bool): v135v1 = get_local __ptr u64, i, !81 v136v1 = get_local __ptr u64, i, !82 - v137v1 = load v136v1, !82 @@ -202,18 +202,18 @@ script { + v139v1 = call add_7(v164v1, v138v1), !84 + br while(v139v1, v165v1) - block7(v95v1: bool): + block7(mut v95v1: bool): ret bool v95v1 } fn eq_5(self !85: u64, other !86: u64) -> bool, !87 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): v145v1 = cmp eq self other ret bool v145v1 } fn modulo_6(self !88: u64, other !89: u64) -> u64, !90 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): v149v1 = asm(r1: self, r2: other, r3) -> u64 r3, !91 { mod r3 r1 r2, !92 } @@ -221,13 +221,13 @@ script { } fn add_7(self !93: u64, other !94: u64) -> u64, !95 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): v153v1 = add self, other ret u64 v153v1 } fn lt_8(self !96: u64, other !97: u64) -> bool, !98 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): v157v1 = asm(r1: self, r2: other, r3) -> bool r3, !99 { lt r3 r1 r2, !100 } @@ -235,7 +235,7 @@ script { } fn not_9(self !51: bool) -> bool, !52 { - entry(self: bool): + entry(mut self: bool): v160v1 = const bool false, !53 v161v1 = cmp eq self v160v1 ret bool v161v1 diff --git a/sway-ir/tests/mem2reg/while_loops.ir b/sway-ir/tests/mem2reg/while_loops.ir index 12a50190e1c..5807635f040 100644 --- a/sway-ir/tests/mem2reg/while_loops.ir +++ b/sway-ir/tests/mem2reg/while_loops.ir @@ -1,6 +1,3 @@ -// regex: VAR=v\d+v\d+ -// regex: ID=[[:alpha:]0-9_]+ - script { fn main() -> bool, !1 { local u64 counter @@ -10,104 +7,66 @@ script { local u64 counter_5 local () result - // check: entry() entry(): - // check: $(v0=$VAR) = get_local __ptr u64, counter v0 = get_local __ptr u64, counter, !2 v1 = const u64 0, !3 - // not: store $VAR to $v0 store v1 to v0, !2 br while() - // check: while($(v3=$VAR): u64): while(): - // check: $(v2=$VAR) = get_local __ptr u64, counter v2 = get_local __ptr u64, counter, !4 - // not: load $v2 v3 = load v2, !4 v4 = const u64 10, !5 - // check: call lt_1($v3, $VAR) v5 = call lt_1(v3, v4), !6 cbr v5, while_body(), end_while() - // check: while_body(): while_body(): v6 = get_local __ptr u64, counter, !7 - // check: $(v7=$VAR) = get_local __ptr u64, counter v7 = get_local __ptr u64, counter, !8 - // not: load $v7 v8 = load v7, !8 v9 = const u64 1, !9 - // check: call add_0($v3, $VAR) v10 = call add_0(v8, v9), !10 store v10 to v6, !7 br while() - // check: end_while(): end_while(): - // check: $(v11=$VAR) = get_local __ptr u64, counter v11 = get_local __ptr u64, counter, !11 - // not: load $v11 v12 = load v11, !11 - // check: $(v13=$VAR) = const u64 10 v13 = const u64 10, !12 - // check: call eq_5($v3, $v13) v14 = call eq_5(v12, v13), !13 v15 = call assert_2(v14), !15 - // check: $(v16=$VAR) = get_local __ptr u64, counter_2 v16 = get_local __ptr u64, counter_2, !16 v17 = const u64 0, !17 - // not: store $VAR to $v16 store v17 to v16, !16 - // check: $(v18=$VAR) = get_local __ptr u64, counter_3 v18 = get_local __ptr u64, counter_3, !18 v19 = const u64 0, !19 - // not: store $VAR to $v18 store v19 to v18, !18 br while0() - // check: while0($(p1=$VAR): u64, $(p2=$VAR): u64): while0(): - // check: $(v20=$VAR) = get_local __ptr u64, counter_2 v20 = get_local __ptr u64, counter_2, !20 - // not: load $v20 v21 = load v20, !20 - // check: $(v22=$VAR) = const u64 10 v22 = const u64 10, !21 - // check: call lt_1($p1, $v22) v23 = call lt_1(v21, v22), !22 cbr v23, while_body1(), end_while2() - // check while_body1(): while_body1(): - // check: $(v24=$VAR) = get_local __ptr u64, counter_2 v24 = get_local __ptr u64, counter_2, !23 - // not: load $v24 v25 = load v24, !23 - // check: $(v26=$VAR) = const u64 3 v26 = const u64 3, !24 - // call eq_5($p1, $v26) v27 = call eq_5(v25, v26), !25 cbr v27, block3(), block4(), !25 - // check: end_while2(): end_while2(): - // check: $(v28=$VAR) = get_local __ptr u64, counter_2 v28 = get_local __ptr u64, counter_2, !26 - // not: load $v28 v29 = load v28, !26 - // check: $(v30=$VAR) = const u64 10 v30 = const u64 10, !27 - // call eq_5($p1, $v30) v31 = call eq_5(v29, v30), !28 cbr v31, block6(), block7(v31), !29 - // check: block3(): block3(): - // check: $(v32=$VAR) = get_local __ptr u64, counter_2 v32 = get_local __ptr u64, counter_2, !30 v33 = const u64 10, !31 - // not: store $VAR to $v32 store v33 to v32, !30 v34 = const unit () br block5(v34) diff --git a/sway-ir/tests/mem2reg/while_loops.ir.snap b/sway-ir/tests/mem2reg/while_loops.ir.snap index 9fc581c9833..5eac85ec5d4 100644 --- a/sway-ir/tests/mem2reg/while_loops.ir.snap +++ b/sway-ir/tests/mem2reg/while_loops.ir.snap @@ -20,7 +20,7 @@ script { + br while(v4v1) - while(): -+ while(v153v1: u64): ++ while(mut v153v1: u64): v7v1 = get_local __ptr u64, counter, !4 - v8v1 = load v7v1, !4 v9v1 = const u64 10, !5 @@ -58,7 +58,7 @@ script { + br while0(v25v1, v28v1) - while0(): -+ while0(v155v1: u64, v157v1: u64): ++ while0(mut v155v1: u64, mut v157v1: u64): v31v1 = get_local __ptr u64, counter_2, !20 - v32v1 = load v31v1, !20 v33v1 = const u64 10, !21 @@ -110,9 +110,9 @@ script { - br block5(v63v1) + br block5(v63v1, v55v1, v61v1) -- block5(v1v1: ()): +- block5(mut v1v1: ()): - br while0() -+ block5(v1v1: (), v154v1: u64, v156v1: u64): ++ block5(mut v1v1: (), mut v154v1: u64, mut v156v1: u64): + br while0(v154v1, v156v1) block6(): @@ -123,7 +123,7 @@ script { + v69v1 = call eq_5(v157v1, v68v1), !42 br block7(v69v1), !29 - block7(v2v1: bool): + block7(mut v2v1: bool): v71v1 = call assert_2(v2v1), !15 v72v1 = get_local __ptr u64, counter_4, !43 - v73v1 = const u64 0, !44 @@ -138,7 +138,7 @@ script { + br while8(v76v1, v73v1) - while8(): -+ while8(v159v1: u64, v160v1: u64): ++ while8(mut v159v1: u64, mut v160v1: u64): v79v1 = get_local __ptr u64, counter_4, !47 - v80v1 = load v79v1, !47 v81v1 = const u64 7, !48 @@ -166,7 +166,7 @@ script { br while14() - while11(): -+ while11(v158v1: u64): ++ while11(mut v158v1: u64): v96v1 = get_local __ptr u64, counter_5, !56 - v97v1 = load v96v1, !56 v98v1 = const u64 11, !57 @@ -214,14 +214,14 @@ script { - fn add_0(self !72: u64, other !73: u64) -> u64, !74 { + fn add_0(self !71: u64, other !72: u64) -> u64, !73 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): v125v1 = add self, other ret u64 v125v1 } - fn lt_1(self !75: u64, other !76: u64) -> bool, !77 { + fn lt_1(self !74: u64, other !75: u64) -> bool, !76 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): - v129v1 = asm(r1: self, r2: other, r3) -> bool r3, !78 { - lt r3 r1 r2, !79 + v129v1 = asm(r1: self, r2: other, r3) -> bool r3, !77 { @@ -232,7 +232,7 @@ script { - fn assert_2(condition !80: bool) -> (), !15 { + fn assert_2(condition !79: bool) -> (), !15 { - entry(condition: bool): + entry(mut condition: bool): - v133v1 = call not_3(condition), !81 - cbr v133v1, block0(), block1(), !81 + v133v1 = call not_3(condition), !80 @@ -250,14 +250,14 @@ script { v139v1 = const unit () br block2(v139v1) - block2(v132v1: ()): + block2(mut v132v1: ()): v141v1 = const unit () ret () v141v1 } - fn not_3(self !85: bool) -> bool, !86 { + fn not_3(self !84: bool) -> bool, !85 { - entry(self: bool): + entry(mut self: bool): - v144v1 = const bool false, !87 + v144v1 = const bool false, !86 v145v1 = cmp eq self v144v1 @@ -266,14 +266,14 @@ script { - fn revert_4(code !88: u64) -> (), !84 { + fn revert_4(code !87: u64) -> (), !83 { - entry(code: u64): + entry(mut code: u64): - revert code, !89 + revert code, !88 } - fn eq_5(self !90: u64, other !91: u64) -> bool, !92 { + fn eq_5(self !89: u64, other !90: u64) -> bool, !91 { - entry(self: u64, other: u64): + entry(mut self: u64, mut other: u64): v151v1 = cmp eq self other ret bool v151v1 } diff --git a/sway-ir/tests/memcpy_prop/memcpy_prop.ir b/sway-ir/tests/memcpy_prop/memcpy_prop.ir index cf50e9f9205..acc5666f4ec 100644 --- a/sway-ir/tests/memcpy_prop/memcpy_prop.ir +++ b/sway-ir/tests/memcpy_prop/memcpy_prop.ir @@ -83,11 +83,3 @@ script { ret () v4 } } - -// check: fn wrapper_1 -// check: entry -// check-not: mem_copy_val -// check: cbr -// check: unwrap_2_block0 -// check: fn return_option_5 -// check-not: mem_copy_val diff --git a/sway-ir/tests/memcpy_prop/memcpy_prop.ir.snap b/sway-ir/tests/memcpy_prop/memcpy_prop.ir.snap index a65f31b1b4f..b6a713dec6e 100644 --- a/sway-ir/tests/memcpy_prop/memcpy_prop.ir.snap +++ b/sway-ir/tests/memcpy_prop/memcpy_prop.ir.snap @@ -44,7 +44,7 @@ script { local { u64, ( () | { b256 } ) } __ret_val local { u64, ( () | { b256 } ) } self_ - entry(__ret_value: __ptr { b256 }): + entry(mut __ret_value: __ptr { b256 }): - v22v1 = get_local __ptr { u64, ( () | { b256 } ) }, __ret_val + v22v1 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4 v23v1 = call return_option_5(v22v1) @@ -81,7 +81,7 @@ script { fn return_option_5(__ret_value: __ptr { u64, ( () | { b256 } ) }) -> () { local { u64, ( () | { b256 } ) } __anon_0 - entry(__ret_value: __ptr { u64, ( () | { b256 } ) }): + entry(mut __ret_value: __ptr { u64, ( () | { b256 } ) }): v46v1 = get_local __ptr { u64, ( () | { b256 } ) }, __anon_0 v47v1 = const u64 0 - v48v1 = get_elem_ptr v46v1, __ptr u64, v47v1 diff --git a/sway-ir/tests/memcpyopt/copy_prop_1.ir b/sway-ir/tests/memcpyopt/copy_prop_1.ir index e1f3f376fcf..d272d6fff34 100644 --- a/sway-ir/tests/memcpyopt/copy_prop_1.ir +++ b/sway-ir/tests/memcpyopt/copy_prop_1.ir @@ -11,13 +11,8 @@ script { v26 = const u64 0 v27 = get_elem_ptr v25, __ptr u64, v26 mem_copy_val v27, v15 + // The optimization should replace the load's source to be the memcpy's source. v0 = load v27 ret u64 v0 } } - -// regex: VAL=v\d+v\d+ - -// check: mem_copy_val $(mem_cpy_dest=$VAL), $(mem_cpy_src=$VAL) -// The optimization should replace the load's source to be the memcpy's source. -// check: $VAL = load $(mem_cpy_src) diff --git a/sway-ir/tests/memcpyopt/copy_prop_2.ir b/sway-ir/tests/memcpyopt/copy_prop_2.ir index e2efabc3118..e6f11246458 100644 --- a/sway-ir/tests/memcpyopt/copy_prop_2.ir +++ b/sway-ir/tests/memcpyopt/copy_prop_2.ir @@ -8,16 +8,9 @@ script { v25 = get_local __ptr { u64, u64, u64, u64 }, __anon_468 mem_copy_val v25, v13 v26 = const u64 0 + // The optimization should introduce a GEP into __anon_0 v27 = get_elem_ptr v25, __ptr u64, v26 v0 = load v27 ret u64 v0 } } - -// regex: VAL=v\d+v\d+ - -// check: mem_copy_val $VAL, $VAL -// The optimization should introduce a GEP into __anon_0 -// check: $(local=$VAL) = get_local __ptr { u64, u64, u64, u64 }, __anon_0 -// check: $(gep=$VAL) = get_elem_ptr $local, __ptr u64, $VAL -// check: $VAL = load $gep diff --git a/sway-ir/tests/memcpyopt/copy_prop_3.ir b/sway-ir/tests/memcpyopt/copy_prop_3.ir index 3f9df365a6f..2c35cb4db94 100644 --- a/sway-ir/tests/memcpyopt/copy_prop_3.ir +++ b/sway-ir/tests/memcpyopt/copy_prop_3.ir @@ -8,18 +8,10 @@ script { v25 = get_local __ptr [u64; 8], __anon_468 mem_copy_val v25, v13 v26 = const u64 1 + // The optimization should introduce a GEP into __anon_0 vidx = add v101, v26 v27 = get_elem_ptr v25, __ptr u64, vidx v0 = load v27 ret u64 v0 } } - -// regex: VAL=v\d+v\d+ - -// check: mem_copy_val $VAL, $VAL -// The optimization should introduce a GEP into __anon_0 -// check: $(idx=$VAL) = add v101, $VAL -// check: $(local=$VAL) = get_local __ptr [u64; 8], __anon_0 -// check: $(gep=$VAL) = get_elem_ptr $local, __ptr u64, $idx -// check: $VAL = load $gep diff --git a/sway-ir/tests/memcpyopt/copy_prop_3.ir.snap b/sway-ir/tests/memcpyopt/copy_prop_3.ir.snap index 271730014d8..821fec14a7f 100644 --- a/sway-ir/tests/memcpyopt/copy_prop_3.ir.snap +++ b/sway-ir/tests/memcpyopt/copy_prop_3.ir.snap @@ -8,7 +8,7 @@ script { local [u64; 8] __anon_0 local [u64; 8] __anon_468 - entry(v101: u64): + entry(mut v101: u64): v2v1 = get_local __ptr [u64; 8], __anon_0 v3v1 = get_local __ptr [u64; 8], __anon_468 mem_copy_val v3v1, v2v1 diff --git a/sway-ir/tests/memcpyopt/copy_prop_mut.ir b/sway-ir/tests/memcpyopt/copy_prop_mut.ir index 501126d5af8..b29b4fe4ada 100644 --- a/sway-ir/tests/memcpyopt/copy_prop_mut.ir +++ b/sway-ir/tests/memcpyopt/copy_prop_mut.ir @@ -7,6 +7,7 @@ script { ret () v2 } + // For the single propagation since `b` was mutable it must now make `a` mutable. fn test_single() -> b256 { local b256 a = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 local mut b256 b @@ -20,6 +21,8 @@ script { ret b256 v3 } + + // For the double propagation since `c` was mutable is must now make `a` mutable. fn test_double() -> b256 { local b256 a = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 local b256 b @@ -37,34 +40,3 @@ script { ret b256 v5 } } - -// regex: VAL=v\d+v\d+ - -// For the single propagation since `b` was mutable it must now make `a` mutable. - -// check: fn test_single() -// check: local mut b256 a = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 - -// Now dead: -// check: $VAL = get_local __ptr b256, a - -// check: $(a_loc=$VAL) = get_local __ptr b256, a -// check: $(a_val=$VAL) = load $a_loc -// check: ret b256 $a_val - -// For the double propagation since `c` was mutable is must now make `a` mutable. - -// check: fn test_double() -// check: local mut b256 a = const b256 0x0000000000000000000000000000000000000000000000000000000000000000 - -// Now dead: -// check: $VAL = get_local __ptr b256, a -// check: $VAL = get_local __ptr b256, a - -// check: $(a_loc=$VAL) = get_local __ptr b256, a - -// Also dead. -// check: $VAL = load $VAL - -// check: $(a_val=$VAL) = load $a_loc -// check: ret b256 $a_val diff --git a/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir b/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir index b10de119d8f..30a8e73e445 100644 --- a/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir +++ b/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir @@ -6,9 +6,11 @@ script { entry(): v0 = get_local __ptr u64, x v1 = get_local __ptr u64, y - + v2 = load v0 v3 = call escape(v0) // `v0` escapes here. + + // The `store` instruction must not be optimized away. store v2 to v1 v4 = load v1 @@ -22,14 +24,3 @@ script { ret u64 z } } - -// The `store` instruction must not be optimized away. - -// regex: VAL=v\d+v\d+ - -// check: $(v0=$VAL) = get_local __ptr u64, x -// check: $(v1=$VAL) = get_local __ptr u64, y -// check: $(v2=$VAL) = load $v0 -// check: $(v3=$VAL) = call escape($v0) -// check: store $v2 to $v1 -// check: $(v4=$VAL) = load $v1 diff --git a/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir.snap b/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir.snap index 42c41b28bf8..4c290ef5f41 100644 --- a/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir.snap +++ b/sway-ir/tests/memcpyopt/no_copy_prop_src_ptr_escapes.ir.snap @@ -1,7 +1,7 @@ --- source: sway-ir/tests/tests.rs --- -Modified: true +Modified: false script { entry fn main() -> u64 { @@ -19,7 +19,7 @@ script { } fn escape(a: __ptr u64) -> u64 { - entry(a: __ptr u64): + entry(mut a: __ptr u64): v9v1 = const u64 0 store v9v1 to a ret u64 v9v1 diff --git a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir index 12b90e0f5aa..7f50e48898a 100644 --- a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir +++ b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir @@ -1,5 +1,3 @@ -// regex: VAL=v\d+v\d+ - script { entry fn main() -> u256 { local u256 x @@ -18,5 +16,3 @@ script { ret u256 v3 } } - -// check: load diff --git a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir.snap b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir.snap index 8743dd39680..f8657e356af 100644 --- a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir.snap +++ b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir.snap @@ -1,7 +1,7 @@ --- source: sway-ir/tests/tests.rs --- -Modified: true +Modified: false script { entry fn main() -> u256 { diff --git a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir index 34c4ab06a2e..fcf4fa4f723 100644 --- a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir +++ b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir @@ -1,5 +1,3 @@ -// regex: VAL=v\d+v\d+ - script { entry fn main() -> u256 { local u256 x @@ -18,5 +16,3 @@ script { ret u256 v3 } } - -// check: load diff --git a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir.snap b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir.snap index e193b6c05f7..e726bd1e76a 100644 --- a/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir.snap +++ b/sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir.snap @@ -1,7 +1,7 @@ --- source: sway-ir/tests/tests.rs --- -Modified: true +Modified: false script { entry fn main() -> u256 { diff --git a/sway-ir/tests/memcpyopt/ret_value.ir b/sway-ir/tests/memcpyopt/ret_value.ir index 4313e86a853..298b3e8d17a 100644 --- a/sway-ir/tests/memcpyopt/ret_value.ir +++ b/sway-ir/tests/memcpyopt/ret_value.ir @@ -17,21 +17,3 @@ script { ret __ptr { u64, u64 } __ret_value } } - -// regex: VAL=v\d+v\d+ -// regex: ID=[[:alpha:]0-9_]+ - -// check: fn main($(ret_value=$ID): __ptr { u64, u64 }) -> __ptr { u64, u64 } - -// check: $(temp_ptr=$VAL) = get_local __ptr { u64, u64 }, __anon_0 - -// check: $(field_0_ptr=$VAL) = get_elem_ptr $temp_ptr, __ptr u64, $VAL -// check: $(elev=$VAL) = const u64 11 -// check: store $elev to $field_0_ptr - -// check: $(field_1_ptr=$VAL) = get_elem_ptr $temp_ptr, __ptr u64, $VAL -// check: $(ttwo=$VAL) = const u64 22 -// check: store $ttwo to $field_1_ptr - -// not: store -// check: mem_copy_val $ret_value, $temp_ptr diff --git a/sway-ir/tests/memcpyopt/ret_value.ir.snap b/sway-ir/tests/memcpyopt/ret_value.ir.snap index 3aa32b3d473..4171a48f4f8 100644 --- a/sway-ir/tests/memcpyopt/ret_value.ir.snap +++ b/sway-ir/tests/memcpyopt/ret_value.ir.snap @@ -7,7 +7,7 @@ script { entry fn main(__ret_value: __ptr { u64, u64 }) -> __ptr { u64, u64 } { local { u64, u64 } __anon_0 - entry(__ret_value: __ptr { u64, u64 }): + entry(mut __ret_value: __ptr { u64, u64 }): v2v1 = get_local __ptr { u64, u64 }, __anon_0 v3v1 = const u64 0 v4v1 = get_elem_ptr v2v1, __ptr u64, v3v1 diff --git a/sway-ir/tests/serialize/asm_block.ir b/sway-ir/tests/serialize/asm_block.ir index ef37a8da783..954e9df6f16 100644 --- a/sway-ir/tests/serialize/asm_block.ir +++ b/sway-ir/tests/serialize/asm_block.ir @@ -1,19 +1,15 @@ script { - // check: main() -> u64 entry fn main() -> u64 { entry(): c0 = const u64 0 - // check: = asm() -> () { v0 = asm() -> () { } - // check: = asm() -> () zero { v1 = asm() -> () zero { } - // check: = asm() -> u64 zero { v2 = asm() -> u64 zero { } diff --git a/sway-ir/tests/serialize/entry.ir b/sway-ir/tests/serialize/entry.ir index 6c6b50dfc7c..6a6a5f2a565 100644 --- a/sway-ir/tests/serialize/entry.ir +++ b/sway-ir/tests/serialize/entry.ir @@ -1,15 +1,12 @@ script { - // check: foo() -> u64 entry fn foo() -> u64 { entry(): } - // check: bar() -> u64 pub entry fn bar() -> u64 { entry(): } - // check: baz() -> u64 pub fn baz() -> u64 { entry(): } diff --git a/sway-ir/tests/serialize/get_storage_key.ir b/sway-ir/tests/serialize/get_storage_key.ir index cc02f9de275..7e8cd2e9d92 100644 --- a/sway-ir/tests/serialize/get_storage_key.ir +++ b/sway-ir/tests/serialize/get_storage_key.ir @@ -1,19 +1,10 @@ -// regex: VAR=v\d+v\d+ - contract { - // check: storage_key storage.a = 0xeb7ceb95f655d60faa3ae0cd0de1ff1af784e38a3b25a88f2be480f15478907f storage_key storage.a = 0xeb7ceb95f655d60faa3ae0cd0de1ff1af784e38a3b25a88f2be480f15478907f - // nextln: storage_key storage.a.b = 0xeb7ceb95f655d60faa3ae0cd0de1ff1af784e38a3b25a88f2be480f15478907f : 0 : 0x9cb84a7467ade86aea47c23daff70a989ae56e1466ffbb2e04aba9255b262fc6 storage_key storage.a.b = 0xeb7ceb95f655d60faa3ae0cd0de1ff1af784e38a3b25a88f2be480f15478907f : 0 : 0x9cb84a7467ade86aea47c23daff70a989ae56e1466ffbb2e04aba9255b262fc6 - // nextln: storage_key storage.b = 0x1111111111111111111111111111111111111111111111111111111111111111 storage_key storage.b = 0x1111111111111111111111111111111111111111111111111111111111111111 : 0 : 0x1111111111111111111111111111111111111111111111111111111111111111 - // nextln: storage_key storage.c = 0x2222222222222222222222222222222222222222222222222222222222222222 : 2 storage_key storage.c = 0x2222222222222222222222222222222222222222222222222222222222222222 : 2 : 0x2222222222222222222222222222222222222222222222222222222222222222 - // nextln: storage_key storage::n1.a = 0xbde9a42c506e6c3dd71dcf63c89e2d066b3fea525afe68f1ddc47d58bad97337 storage_key storage::n1.a = 0xbde9a42c506e6c3dd71dcf63c89e2d066b3fea525afe68f1ddc47d58bad97337 - // nextln: storage_key storage::n1::n2.a = 0xdf79747c92e7208309fd8865d0fd592109b7bf72667bccfcaaabf9b12ac8c5d3 : 3 storage_key storage::n1::n2.a = 0xdf79747c92e7208309fd8865d0fd592109b7bf72667bccfcaaabf9b12ac8c5d3 : 3 - // nextln: storage_key storage::n1::n2.a.b.c = 0x8888888888888888888888888888888888888888888888888888888888888888 : 2 storage_key storage::n1::n2.a.b.c = 0x8888888888888888888888888888888888888888888888888888888888888888 : 2 pub entry fn all_in_one<0e615b65>() -> () { @@ -25,31 +16,26 @@ contract { entry(): - // check: $VAR = get_storage_key __ptr { b256, u64, b256 }, storage.a v0 = get_storage_key __ptr { b256, u64, b256 }, storage.a v1 = get_local __ptr { b256, u64, b256 }, __tmp_arg mem_copy_val v1, v0 v2 = call poke_0(v1) - // check: $VAR = get_storage_key __ptr { b256, u64, b256 }, storage.a.b v3 = get_storage_key __ptr { b256, u64, b256 }, storage.a.b v4 = get_local __ptr { b256, u64, b256 }, __tmp_arg0 mem_copy_val v4, v3 v5 = call poke_0(v4) - // check: $VAR = get_storage_key __ptr { b256, u64, b256 }, storage::n1.a v6 = get_storage_key __ptr { b256, u64, b256 }, storage::n1.a v7 = get_local __ptr { b256, u64, b256 }, __tmp_arg1 mem_copy_val v7, v6 v8 = call poke_0(v7) - // check: $VAR = get_storage_key __ptr { b256, u64, b256 }, storage::n1::n2.a v9 = get_storage_key __ptr { b256, u64, b256 }, storage::n1::n2.a v10 = get_local __ptr { b256, u64, b256 }, __tmp_arg2 mem_copy_val v10, v9 v11 = call poke_0(v10) - // check: $VAR = get_storage_key __ptr { b256, u64, b256 }, storage::n1::n2.a.b.c v12 = get_storage_key __ptr { b256, u64, b256 }, storage::n1::n2.a.b.c v13 = get_local __ptr { b256, u64, b256 }, __tmp_arg3 mem_copy_val v13, v12 diff --git a/sway-ir/tests/serialize/get_storage_key.ir.snap b/sway-ir/tests/serialize/get_storage_key.ir.snap index ec3de6b0273..c61730a26b8 100644 --- a/sway-ir/tests/serialize/get_storage_key.ir.snap +++ b/sway-ir/tests/serialize/get_storage_key.ir.snap @@ -45,7 +45,7 @@ contract { } fn poke_0(_t: __ptr { b256, u64, b256 }) -> () { - entry(_t: __ptr { b256, u64, b256 }): + entry(mut _t: __ptr { b256, u64, b256 }): v24v1 = const unit () ret () v24v1 } diff --git a/sway-ir/tests/serialize/intrinsic_addr_of.ir b/sway-ir/tests/serialize/intrinsic_addr_of.ir index 512c08cd317..e0d817e7cb4 100644 --- a/sway-ir/tests/serialize/intrinsic_addr_of.ir +++ b/sway-ir/tests/serialize/intrinsic_addr_of.ir @@ -1,18 +1,12 @@ -// regex: VAR=v\d+v\d+ - script { - // check: main() -> u64 fn main() -> u64 { local { u64, ( { b256 } | { b256 } ) } sender entry(): - // check: = get_local v0 = get_local __ptr { u64, ( { b256 } | { b256 } ) }, sender v1 = const { u64, ( { b256 } | { b256 } ) } { u64 0, { b256 } { b256 0x0100000000000000000000000000000000000000000000000000000000000010 } } store v1 to v0 - // check: $(arg0=$VAR) = get_local v2 = get_local __ptr { u64, ( { b256 } | { b256 } ) }, sender - // check: ptr_to_int $arg0 v3 = ptr_to_int v2 to u64 ret u64 v3 } diff --git a/sway-ir/tests/serialize/log_event_metadata.ir b/sway-ir/tests/serialize/log_event_metadata.ir index 7b93f89953a..6505b0193d7 100644 --- a/sway-ir/tests/serialize/log_event_metadata.ir +++ b/sway-ir/tests/serialize/log_event_metadata.ir @@ -1,25 +1,15 @@ -// regex: VAR=v\d+v\d+ - script { fn main() -> () { entry(): - // check: $(v0=$VAR) = const v0 = const u64 0 - // check: $(v1=$VAR) = const v1 = const u64 1 - // check: log u64 $v0, $v1 log u64 v0, v1 - // check: $(v2=$VAR) = const v2 = const u64 2 - // check: $(v3=$VAR) = const v3 = const u64 3 - // check: log u64 $v2, $v3 log_data(version: 0, is_event: true, is_indexed: true, event_type_size: 8, num_elements: 2) log u64 v2, v3 log_data(version: 0, is_event: true, is_indexed: true, event_type_size: 8, num_elements: 2) - // check: $(v4=$VAR) = const unit v4 = const unit () - // check: ret () $v4 ret () v4 } } diff --git a/sway-ir/tests/serialize/mem_copy.ir b/sway-ir/tests/serialize/mem_copy.ir index cbfc07857f2..0eb8efd4e96 100644 --- a/sway-ir/tests/serialize/mem_copy.ir +++ b/sway-ir/tests/serialize/mem_copy.ir @@ -1,5 +1,4 @@ script { -// check: fn main fn main() -> () { local b256 addr_a = const b256 0x1111111111111111111111111111111111111111111111111111111111111111 local b256 addr_b diff --git a/sway-ir/tests/serialize/metadata.ir b/sway-ir/tests/serialize/metadata.ir index 1acb1556c14..801bc62d0e9 100644 --- a/sway-ir/tests/serialize/metadata.ir +++ b/sway-ir/tests/serialize/metadata.ir @@ -1,25 +1,17 @@ -// regex: VAR=v\d+v\d+ - script { - // check: fn main() -> bool, !1 { fn main() -> bool, !1 { entry(): - // check: $(v0=$VAR) = const bool true, !2 v0 = const bool true, !2 - // check: cbr $v0, block1($v0), block0($v0), !3 cbr v0, block1(v0), block0(v0), !3 block0(v1: bool): - // check: $(v2=$VAR) = call f(), !4 v2 = call f(), !4 - // check: br block1($v2), !3 br block1(v2), !3 block1(v3: bool): ret bool v3 } - // check: fn f() -> bool, !4 { fn f() -> bool, !4 { entry(): v0 = const bool false @@ -27,12 +19,6 @@ script { } } -// check: !0 = "a string\\n" -// check: !1 = !0 -// check: !2 = a_struct !0 11 22 !1 -// check: !3 = (!1 !2) -// check: !4 = 12345 - !0 = "a string\\n" !1 = !0 !2 = a_struct !0 11 22 !1 diff --git a/sway-ir/tests/serialize/metadata.ir.snap b/sway-ir/tests/serialize/metadata.ir.snap index 2af959c11a0..29bff0696ea 100644 --- a/sway-ir/tests/serialize/metadata.ir.snap +++ b/sway-ir/tests/serialize/metadata.ir.snap @@ -9,11 +9,11 @@ script { v3v1 = const bool true, !2 cbr v3v1, block1(v3v1), block0(v3v1), !3 - block0(v1v1: bool): + block0(mut v1v1: bool): v5v1 = call f(), !4 br block1(v5v1), !3 - block1(v2v1: bool): + block1(mut v2v1: bool): ret bool v2v1 } diff --git a/sway-ir/tests/serialize/storage_clear.ir b/sway-ir/tests/serialize/storage_clear.ir index fca90d0c8f6..5be22e33a6a 100644 --- a/sway-ir/tests/serialize/storage_clear.ir +++ b/sway-ir/tests/serialize/storage_clear.ir @@ -1,7 +1,4 @@ -// regex: VAR=v\d+v\d+ - script { -// check: fn main fn main() -> () { local b256 key_for_x @@ -10,10 +7,8 @@ script { v1 = const b256 0x7fbd1192666bfac3767b890bd4d048c940879d316071e20c7c8c81bce2ca41c5 store v1 to v0 v_num_of_slots = const u64 1 -// check: $VAR = state_clear key $VAR, $VAR v3 = state_clear key v0, v_num_of_slots -// check: state_clear_slots key $VAR, $VAR state_clear_slots key v0, v_num_of_slots v_ret = const unit () diff --git a/sway-ir/tests/serialize/storage_load.ir b/sway-ir/tests/serialize/storage_load.ir index 36b289fb936..eb9854a2857 100644 --- a/sway-ir/tests/serialize/storage_load.ir +++ b/sway-ir/tests/serialize/storage_load.ir @@ -1,7 +1,4 @@ -// regex: VAR=v\d+v\d+ - script { -// check: fn main fn main() -> () { local b256 key_for_x local b256 key_for_y @@ -15,7 +12,6 @@ script { v1 = const b256 0x7fbd1192666bfac3767b890bd4d048c940879d316071e20c7c8c81bce2ca41c5 store v1 to v0 v2 = get_local __ptr u64, value_for_x -// check: $VAR = state_load_word key $VAR, 0 v3 = state_load_word key v0, 0 store v3 to v2 @@ -28,7 +24,6 @@ script { store v8 to v7 v9 = get_local __ptr b256, value_for_y v10 = const u64 1 -//check: state_load_quad_word $VAR, key $VAR, $VAR v_load_res = state_load_quad_word v9, key v7, v10 v11 = get_local __ptr b256, value_for_y v12 = load v11 @@ -38,7 +33,6 @@ script { v_zero = const u64 0 v_len = const u64 32 v_untyped_v9 = cast_ptr v9 to ptr -//check: state_read_slot $VAR, key $VAR, $VAR, $VAR state_read_slot v_untyped_v9, key v7, v_zero, v_len v14 = const unit () diff --git a/sway-ir/tests/serialize/storage_preload.ir b/sway-ir/tests/serialize/storage_preload.ir index 05c228ea542..499c05dadd7 100644 --- a/sway-ir/tests/serialize/storage_preload.ir +++ b/sway-ir/tests/serialize/storage_preload.ir @@ -1,7 +1,4 @@ -// regex: VAR=v\d+v\d+ - script { -// check: fn main fn main() -> u64 { local b256 key_for_x @@ -9,7 +6,6 @@ script { v0 = get_local __ptr b256, key_for_x v1 = const b256 0x7fbd1192666bfac3767b890bd4d048c940879d316071e20c7c8c81bce2ca41c5 store v1 to v0 -// check: $VAR = state_preload key $VAR v3 = state_preload key v0 ret u64 v3 diff --git a/sway-ir/tests/serialize/storage_store.ir b/sway-ir/tests/serialize/storage_store.ir index 48e1b0c1500..16f425c6489 100644 --- a/sway-ir/tests/serialize/storage_store.ir +++ b/sway-ir/tests/serialize/storage_store.ir @@ -1,7 +1,4 @@ -// regex: VAR=v\d+v\d+ - contract { -// check: main fn main() -> () { local b256 key_for_x local u64 value_for_x @@ -16,7 +13,6 @@ contract { v3 = const b256 0x7fbd1192666bfac3767b890bd4d048c940879d316071e20c7c8c81bce2ca41c5 store v3 to v2 v4 = const u64 0 -// check: state_store_word $VAR, key $VAR state_store_word v4, key v2 v_0 = get_local __ptr b256, value_for_y @@ -27,15 +23,12 @@ contract { store v_3 to v_2 v_4 = get_local __ptr b256, value_for_y v_5 = const u64 1 -// check: state_store_quad_word $VAR, key $VAR, $VAR state_store_quad_word v_4, key v_2, v_5 v_untyped_v_4 = cast_ptr v_4 to ptr v_len = const u64 32 -// check: state_write_slot $VAR, key $VAR, $VAR state_write_slot v_untyped_v_4, key v_2, v_len -// check: state_update_slot $VAR, key $VAR, $VAR, $VAR state_update_slot v_untyped_v_4, key v_2, v1, v_len v_6 = const unit () diff --git a/sway-ir/tests/serialize/str_slice.ir b/sway-ir/tests/serialize/str_slice.ir index fca57357793..f60a1a0b361 100644 --- a/sway-ir/tests/serialize/str_slice.ir +++ b/sway-ir/tests/serialize/str_slice.ir @@ -4,7 +4,6 @@ script { local slice __anon_1 local slice a local string<3> __anon_2 -// check: local slice a entry(): v0 = const string<3> "abc" @@ -15,7 +14,7 @@ script { v3 = const u64 0 v4 = get_elem_ptr v2, __ptr u64, v3 store v1 to v4, !2 - + v5 = const u64 1 v6 = get_elem_ptr v2, __ptr u64, v5 v7 = const u64 3 @@ -27,9 +26,9 @@ script { v9 = load v8 v10 = get_local __ptr slice, a, !3 store v9 to v10, !3 - + v11 = get_local __ptr slice, a, !4 v12 = load v11 ret slice v12 } -} \ No newline at end of file +} diff --git a/sway-ir/tests/serialize/test.ir b/sway-ir/tests/serialize/test.ir index aa65c81563f..db9f64fdc57 100644 --- a/sway-ir/tests/serialize/test.ir +++ b/sway-ir/tests/serialize/test.ir @@ -1,29 +1,17 @@ -// regex: VAR=v\d+v\d+ - script { - // check: fn main() -> (), !1 { fn main() -> (), !1 { entry(): - // check: $VAR = const unit () v0 = const unit () ret () v0 } - // check: fn my_test_func() -> (), !4 { fn my_test_func() -> (), !4 { entry(): - // check: $VAR = const unit () v0 = const unit () ret () v0 } } -// check: !0 = "a string\\n" -// check: !1 = span !0 -// check: !2 = span !0 -// check: !3 = decl_index 4 -// check: !4 = (!2 !3) - !0 = "a string\\n" !1 = span !0 9 21 !2 = span !0 307 341 diff --git a/sway-ir/tests/serialize/untyped_arg_to_call.ir b/sway-ir/tests/serialize/untyped_arg_to_call.ir index 107bc1cd7b2..b897e0ef4ab 100644 --- a/sway-ir/tests/serialize/untyped_arg_to_call.ir +++ b/sway-ir/tests/serialize/untyped_arg_to_call.ir @@ -3,7 +3,6 @@ // Based on the `v2 = call a(v1)` line script { -// check: fn main fn main() -> bool { entry(): v0 = const bool true diff --git a/sway-ir/tests/serialize/untyped_arg_to_call.ir.snap b/sway-ir/tests/serialize/untyped_arg_to_call.ir.snap index 81c7b77f924..c02a7a7ad74 100644 --- a/sway-ir/tests/serialize/untyped_arg_to_call.ir.snap +++ b/sway-ir/tests/serialize/untyped_arg_to_call.ir.snap @@ -13,7 +13,7 @@ script { } fn a(x: bool) -> bool { - entry(x: bool): + entry(mut x: bool): v6v1 = const bool true ret bool v6v1 } diff --git a/sway-ir/tests/serialize/wide_ops.ir b/sway-ir/tests/serialize/wide_ops.ir index 7ee45777c68..1b590ec8651 100644 --- a/sway-ir/tests/serialize/wide_ops.ir +++ b/sway-ir/tests/serialize/wide_ops.ir @@ -1,58 +1,40 @@ -// regex: VAR=v\d+v\d+ - script { fn main() -> () { local u256 a entry(): -// check: $(v0=$VAR) = get_local __ptr u256, a v0 = get_local __ptr u256, a wide add v0, v0 to v0 -// check: wide add $v0, $v0 to $v0 wide sub v0, v0 to v0 -// check: wide sub $v0, $v0 to $v0 wide mul v0, v0 to v0 -// check: wide mul $v0, $v0 to $v0 wide div v0, v0 to v0 -// check: wide div $v0, $v0 to $v0 wide mod v0, v0 to v0 -// check: wide mod $v0, $v0 to $v0 -// check: $(v1=$VAR) = const u64 2 v1 = const u64 2 wide lsh v0, v1 to v0 -// check: wide lsh $v0, $v1 to $v0 wide rsh v0, v1 to v0 -// check: wide rsh $v0, $v1 to $v0 wide not v0 to v0 -// check: wide not $v0 to $v0 wide and v0, v0 to v0 -// check: wide and $v0, $v0 to $v0 wide or v0, v0 to v0 -// check: wide or $v0, $v0 to $v0 wide xor v0, v0 to v0 -// check: wide xor $v0, $v0 to $v0 v2 = wide cmp eq v0 v0 -// check: $(v2=$VAR) = wide cmp eq $v0 $v0 v3 = wide cmp lt v0 v0 -// check: $(v3=$VAR) = wide cmp lt $v0 $v0 v4 = wide cmp gt v0 v0 -// check: $(v4=$VAR) = wide cmp gt $v0 $v0 v5 = const unit () ret () v5 } -} \ No newline at end of file +} diff --git a/sway-ir/tests/simplify_cfg/dead_blocks.ir b/sway-ir/tests/simplify_cfg/dead_blocks.ir index 4dfc6cad77d..992636ce360 100644 --- a/sway-ir/tests/simplify_cfg/dead_blocks.ir +++ b/sway-ir/tests/simplify_cfg/dead_blocks.ir @@ -1,5 +1,3 @@ -// regex: ID=[[:alpha:]0-9]+ - script { fn main() -> u64 { local u64 x @@ -9,20 +7,17 @@ script { call bar() call baz() v0 = get_local __ptr u64, x -// check: const u64 11 v1 = const u64 11 store v1 to v0 br block1(v1) // Dead block, no predecessors. block0(v1: u64): -// not: const u64 22 v2 = const u64 22 store v2 to v0 br block1(v2) block1(v3: u64): -// check: const u64 33 v4 = const u64 33 ret u64 v4 } @@ -30,12 +25,10 @@ script { // Although block0 is empty here, it mustn't be removed // as it acts as a way to produce different values for the PHI. fn foo(b: bool) -> bool { - // check: entry entry(b: bool): c2 = const u64 100 cbr b, block0(), block1(c2) - // check: block0(): block0(): c1 = const u64 333 br block1(c1) @@ -45,19 +38,14 @@ script { } fn bar(b: bool) -> bool { - // check: entry entry(b: bool): c2 = const u64 100 cbr b, block0(), block2(c2) - // check: block0(): block0(): // The const from block1 will come here when block1 goes. - // check: const u64 333 - // check: br block2 br block1() - // not: block1(): block1(): c1 = const u64 333 br block2(c1) @@ -67,26 +55,18 @@ script { } fn baz(b: bool) -> bool { - // check: entry entry(b: bool): - // check: $(v=$ID) = const u64 100 c2 = const u64 100 - // check: cbr b, $ID(), $(block2=$ID)($v) cbr b, block0(), block2(c2) block0(): - // check: $(v2=$ID) = const u64 11 v3 = const u64 11 - // check: br $(block1=$ID)($v2) br block1(v3) - // not: ($block1)($ID: u64): block1(v2: u64): br block2(v2) - // check: $block2($ID: u64): block2(v1: u64): ret bool b } } - diff --git a/sway-ir/tests/simplify_cfg/dead_blocks.ir.snap b/sway-ir/tests/simplify_cfg/dead_blocks.ir.snap index 2720557b185..7c01456eb30 100644 --- a/sway-ir/tests/simplify_cfg/dead_blocks.ir.snap +++ b/sway-ir/tests/simplify_cfg/dead_blocks.ir.snap @@ -16,18 +16,18 @@ script { store v7v1 to v6v1 - br block1(v7v1) - -- block0(v1v1: u64): +- block0(mut v1v1: u64): - v10v1 = const u64 22 - store v10v1 to v6v1 - br block1(v10v1) - -- block1(v2v1: u64): +- block1(mut v2v1: u64): v13v1 = const u64 33 ret u64 v13v1 } fn foo(b: bool) -> bool { - entry(b: bool): + entry(mut b: bool): v17v1 = const u64 100 cbr b, block0(), block1(v17v1) @@ -35,12 +35,12 @@ script { v19v1 = const u64 333 br block1(v19v1) - block1(v16v1: u64): + block1(mut v16v1: u64): ret bool b } fn bar(b: bool) -> bool { - entry(b: bool): + entry(mut b: bool): v24v1 = const u64 100 cbr b, block0(), block2(v24v1) @@ -51,12 +51,12 @@ script { v27v1 = const u64 333 br block2(v27v1) - block2(v23v1: u64): + block2(mut v23v1: u64): ret bool b } fn baz(b: bool) -> bool { - entry(b: bool): + entry(mut b: bool): v33v1 = const u64 100 cbr b, block0(), block2(v33v1) @@ -65,10 +65,10 @@ script { - br block1(v35v1) + br block2(v35v1) -- block1(v31v1: u64): +- block1(mut v31v1: u64): - br block2(v31v1) - - block2(v32v1: u64): + block2(mut v32v1: u64): ret bool b } } diff --git a/sway-ir/tests/simplify_cfg/merge_all_blocks.ir b/sway-ir/tests/simplify_cfg/merge_all_blocks.ir index db2eca7c7ec..2f28ec10e20 100644 --- a/sway-ir/tests/simplify_cfg/merge_all_blocks.ir +++ b/sway-ir/tests/simplify_cfg/merge_all_blocks.ir @@ -1,33 +1,22 @@ -// regex: ID=[[:alpha:]0-9]+ - script { fn main() -> bool { entry(): -// check: const u64 11 v0 = const u64 11 v1 = const u64 0 v2 = cmp eq v0 v1 -// not: br br block0(v2) block0(v3: bool): -// check: const u64 22 v4 = const u64 22 v5 = cmp eq v4 v1 -// not: br br block1(v5) -// not: block1: block1(v6: bool): -// check: const u64 33 v7 = const u64 33 v8 = cmp eq v7 v1 -// not: br br block2(v8) block2(v9: bool): -// not: phi(block1: v8) ret bool v9 } } - diff --git a/sway-ir/tests/simplify_cfg/merge_all_blocks.ir.snap b/sway-ir/tests/simplify_cfg/merge_all_blocks.ir.snap index 86356017a95..32c181c7890 100644 --- a/sway-ir/tests/simplify_cfg/merge_all_blocks.ir.snap +++ b/sway-ir/tests/simplify_cfg/merge_all_blocks.ir.snap @@ -11,17 +11,17 @@ script { v6v1 = cmp eq v4v1 v5v1 - br block0(v6v1) - -- block0(v1v1: bool): +- block0(mut v1v1: bool): v8v1 = const u64 22 v9v1 = cmp eq v8v1 v5v1 - br block1(v9v1) - -- block1(v2v1: bool): +- block1(mut v2v1: bool): v11v1 = const u64 33 v12v1 = cmp eq v11v1 v5v1 - br block2(v12v1) - -- block2(v3v1: bool): +- block2(mut v3v1: bool): - ret bool v3v1 + ret bool v12v1 } diff --git a/sway-ir/tests/sroa/nested_struct_array.ir b/sway-ir/tests/sroa/nested_struct_array.ir index 9abbfe96b47..6b7f3ef1e48 100644 --- a/sway-ir/tests/sroa/nested_struct_array.ir +++ b/sway-ir/tests/sroa/nested_struct_array.ir @@ -1,10 +1,6 @@ -// regex: VAR=v\d+ -// regex: ID=[[:alpha:]0-9_]+ - script { entry fn main() -> u64, !1 { local [u64; 4] __anon_0 - // not: local { u64, u64 } local { u64, u64 } __anon_1 local { u64, u64, [u64; 4], { u64, u64 } } __anon_2 diff --git a/sway-ir/tests/sroa/struct_unused_field.ir b/sway-ir/tests/sroa/struct_unused_field.ir index b1dab669c63..2f620d3f6f3 100644 --- a/sway-ir/tests/sroa/struct_unused_field.ir +++ b/sway-ir/tests/sroa/struct_unused_field.ir @@ -1,10 +1,5 @@ -// regex: VAR=v\d+ -// regex: ID=[[:alpha:]0-9_]+ - script { - // check: entry fn main() entry fn main() -> u64, !1 { - // not: local { u64, u64 } local { u64, u64 } __anon_0 entry(): diff --git a/sway-ir/tests/tests.rs b/sway-ir/tests/tests.rs index acd491875d8..57560d5accf 100644 --- a/sway-ir/tests/tests.rs +++ b/sway-ir/tests/tests.rs @@ -155,11 +155,6 @@ fn run_tests bool>(sub_dir: &str, opt_fn: F) { } run_insta(&path, clean_output(&snapshot)); - assert!( - r, - "Pass returned false (no changes made to {}).", - path.display() - ); ir.verify().unwrap_or_else(|err| { println!("{err}"); panic!(); @@ -171,21 +166,18 @@ fn run_tests bool>(sub_dir: &str, opt_fn: F) { .text(&input) .unwrap() .finish(); - if chkr.is_empty() { - println!("{output}"); - panic!("No filecheck directives found in test: {}", path.display()); - } - - match chkr.explain(&output, filecheck::NO_VARIABLES) { - Ok((success, report)) if !success => { - println!("--- FILECHECK FAILED FOR {}", path.display()); - println!("{report}"); - panic!() - } - Err(e) => { - panic!("filecheck directive error while checking: {e}"); + if !chkr.is_empty() { + match chkr.explain(&output, filecheck::NO_VARIABLES) { + Ok((success, report)) if !success => { + println!("--- FILECHECK FAILED FOR {}", path.display()); + println!("{report}"); + panic!() + } + Err(e) => { + panic!("filecheck directive error while checking: {e}"); + } + _ => (), } - _ => (), } } } @@ -295,9 +287,11 @@ fn inline() { if params.contains(&"all") { // Just inline everything, replacing all CALL instructions. - funcs.into_iter().fold(false, |acc, func| { - opt::inline_all_function_calls(ir, &func).unwrap() || acc - }) + let mut changed = false; + for func in funcs.into_iter() { + changed |= opt::inline_all_function_calls(ir, &func).unwrap(); + } + changed } else { // Get the parameters from the first line. See the inline/README.md for details. If // there aren't any found then there won't be any constraints and it'll be the diff --git a/sway-lsp/src/capabilities/code_lens.rs b/sway-lsp/src/capabilities/code_lens.rs index 628c4ad131b..2c90df382aa 100644 --- a/sway-lsp/src/capabilities/code_lens.rs +++ b/sway-lsp/src/capabilities/code_lens.rs @@ -22,6 +22,6 @@ pub fn code_lens(runnables: &RunnableMap, url: &Url) -> Vec { }) .unwrap_or_default(); // Sort the results - result.sort_by(|a, b| a.range.start.line.cmp(&b.range.start.line)); + result.sort_by_key(|a| a.range.start.line); result } diff --git a/sway-lsp/src/capabilities/rename.rs b/sway-lsp/src/capabilities/rename.rs index 99b39d834a4..88a5fffa0bf 100644 --- a/sway-lsp/src/capabilities/rename.rs +++ b/sway-lsp/src/capabilities/rename.rs @@ -90,7 +90,7 @@ pub fn rename( existing.append(&mut v); // Sort the TextEdits by their range in reverse order so the client applies edits // from the end of the document to the beginning, preventing issues with offset changes. - existing.sort_unstable_by(|a, b| b.range.start.cmp(&a.range.start)); + existing.sort_unstable_by_key(|b| std::cmp::Reverse(b.range.start)); }) .or_insert(v); map diff --git a/sway-lsp/src/core/session.rs b/sway-lsp/src/core/session.rs index 2d9d82bf3db..9f8ab1e2ed6 100644 --- a/sway-lsp/src/core/session.rs +++ b/sway-lsp/src/core/session.rs @@ -132,7 +132,7 @@ pub fn token_ranges( .map(|item| item.key().range) .collect(); - token_ranges.sort_by(|a, b| a.start.line.cmp(&b.start.line)); + token_ranges.sort_by_key(|a| a.start.line); Some(token_ranges) } diff --git a/sway-lsp/tests/integration/lsp.rs b/sway-lsp/tests/integration/lsp.rs index 144d5d9409e..6440d97066b 100644 --- a/sway-lsp/tests/integration/lsp.rs +++ b/sway-lsp/tests/integration/lsp.rs @@ -505,8 +505,8 @@ pub(crate) async fn references_request(server: &ServerState, uri: &Url) { create_location(3, 5, 9), create_location(14, 8, 12), ]; - response.sort_by(|a, b| a.range.start.cmp(&b.range.start)); - expected.sort_by(|a, b| a.range.start.cmp(&b.range.start)); + response.sort_by_key(|a| a.range.start); + expected.sort_by_key(|a| a.range.start); assert_eq!(expected, response); } diff --git a/sway-parse/src/parser.rs b/sway-parse/src/parser.rs index edf308e5c2d..7cd497e789b 100644 --- a/sway-parse/src/parser.rs +++ b/sway-parse/src/parser.rs @@ -334,11 +334,7 @@ impl<'a, 'e> Parser<'a, 'e> { /// /// To calculate lines the original source code needs to be transversed. pub fn consume_while_line_equals(&mut self, line: usize) { - loop { - let Some(current_token) = self.token_trees.first() else { - break; - }; - + while let Some(current_token) = self.token_trees.first() { let current_span = current_token.span(); let current_span_line = current_span.start_line_col_one_index().line; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/array/array_repeat/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/array/array_repeat/stdout.snap index ba6bb3c1d1f..474276f67cc 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/array/array_repeat/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/array/array_repeat/stdout.snap @@ -110,78 +110,78 @@ script { ret () v813v1 } - fn array_repeat_zero_small_u8_1(__ret_value: __ptr [u8; 5]) -> (), !48 { - entry(__ret_value: __ptr [u8; 5]): + fn array_repeat_zero_small_u8_1(mut __ret_value: __ptr [u8; 5]) -> (), !48 { + entry(mut __ret_value: __ptr [u8; 5]): mem_clear_val __ret_value, !49 v1925v1 = const unit () ret () v1925v1 } - fn array_repeat_zero_small_u16_2(__ret_value: __ptr [u64; 5]) -> (), !52 { - entry(__ret_value: __ptr [u64; 5]): + fn array_repeat_zero_small_u16_2(mut __ret_value: __ptr [u64; 5]) -> (), !52 { + entry(mut __ret_value: __ptr [u64; 5]): mem_clear_val __ret_value, !53 v1932v1 = const unit () ret () v1932v1 } - fn array_repeat_zero_small_u256_5(__ret_value: __ptr [u256; 5]) -> (), !56 { - entry(__ret_value: __ptr [u256; 5]): + fn array_repeat_zero_small_u256_5(mut __ret_value: __ptr [u256; 5]) -> (), !56 { + entry(mut __ret_value: __ptr [u256; 5]): mem_clear_val __ret_value, !57 v1945v1 = const unit () ret () v1945v1 } - fn array_repeat_zero_small_b256_6(__ret_value: __ptr [b256; 5]) -> (), !60 { - entry(__ret_value: __ptr [b256; 5]): + fn array_repeat_zero_small_b256_6(mut __ret_value: __ptr [b256; 5]) -> (), !60 { + entry(mut __ret_value: __ptr [b256; 5]): mem_clear_val __ret_value, !61 v1952v1 = const unit () ret () v1952v1 } - fn array_repeat_zero_small_bool_7(__ret_value: __ptr [bool; 5]) -> (), !64 { - entry(__ret_value: __ptr [bool; 5]): + fn array_repeat_zero_small_bool_7(mut __ret_value: __ptr [bool; 5]) -> (), !64 { + entry(mut __ret_value: __ptr [bool; 5]): mem_clear_val __ret_value, !65 v1959v1 = const unit () ret () v1959v1 } - fn array_repeat_zero_big_u8_8(__ret_value: __ptr [u8; 25]) -> (), !68 { - entry(__ret_value: __ptr [u8; 25]): + fn array_repeat_zero_big_u8_8(mut __ret_value: __ptr [u8; 25]) -> (), !68 { + entry(mut __ret_value: __ptr [u8; 25]): mem_clear_val __ret_value, !69 v1966v1 = const unit () ret () v1966v1 } - fn array_repeat_zero_big_u32_10(__ret_value: __ptr [u64; 25]) -> (), !72 { - entry(__ret_value: __ptr [u64; 25]): + fn array_repeat_zero_big_u32_10(mut __ret_value: __ptr [u64; 25]) -> (), !72 { + entry(mut __ret_value: __ptr [u64; 25]): mem_clear_val __ret_value, !73 v1973v1 = const unit () ret () v1973v1 } - fn array_repeat_zero_big_u256_12(__ret_value: __ptr [u256; 25]) -> (), !76 { - entry(__ret_value: __ptr [u256; 25]): + fn array_repeat_zero_big_u256_12(mut __ret_value: __ptr [u256; 25]) -> (), !76 { + entry(mut __ret_value: __ptr [u256; 25]): mem_clear_val __ret_value, !77 v1986v1 = const unit () ret () v1986v1 } - fn array_repeat_zero_big_b256_13(__ret_value: __ptr [b256; 25]) -> (), !80 { - entry(__ret_value: __ptr [b256; 25]): + fn array_repeat_zero_big_b256_13(mut __ret_value: __ptr [b256; 25]) -> (), !80 { + entry(mut __ret_value: __ptr [b256; 25]): mem_clear_val __ret_value, !81 v1993v1 = const unit () ret () v1993v1 } - fn array_repeat_zero_big_bool_14(__ret_value: __ptr [bool; 25]) -> (), !84 { - entry(__ret_value: __ptr [bool; 25]): + fn array_repeat_zero_big_bool_14(mut __ret_value: __ptr [bool; 25]) -> (), !84 { + entry(mut __ret_value: __ptr [bool; 25]): mem_clear_val __ret_value, !85 v2000v1 = const unit () ret () v2000v1 } - fn small_array_repeat_15(__ret_value: __ptr [bool; 5]) -> (), !88 { - entry(__ret_value: __ptr [bool; 5]): + fn small_array_repeat_15(mut __ret_value: __ptr [bool; 5]) -> (), !88 { + entry(mut __ret_value: __ptr [bool; 5]): v831v1 = const u64 0 v832v1 = get_elem_ptr __ret_value, __ptr bool, v831v1, !89 v117v1 = const bool true @@ -202,12 +202,12 @@ script { ret () v2007v1 } - fn big_array_repeat_16(__ret_value: __ptr [bool; 25]) -> (), !92 { - entry(__ret_value: __ptr [bool; 25]): + fn big_array_repeat_16(mut __ret_value: __ptr [bool; 25]) -> (), !92 { + entry(mut __ret_value: __ptr [bool; 25]): v847v1 = const u64 0 br array_init_loop(v847v1) - array_init_loop(v846v1: u64): + array_init_loop(mut v846v1: u64): v849v1 = get_elem_ptr __ret_value, __ptr bool, v846v1 v125v1 = const bool true store v125v1 to v849v1, !93 @@ -222,8 +222,8 @@ script { ret () v2014v1 } - fn u8_array_bigger_than_18_bits_17(__ret_value: __ptr [u8; 262145]) -> (), !96 { - entry(__ret_value: __ptr [u8; 262145]): + fn u8_array_bigger_than_18_bits_17(mut __ret_value: __ptr [u8; 262145]) -> (), !96 { + entry(mut __ret_value: __ptr [u8; 262145]): mem_clear_val __ret_value, !97 v2021v1 = const unit () ret () v2021v1 @@ -235,14 +235,14 @@ script { ret () v191v1 } - fn decode_array_19(__ret_value: __ptr [u8; 1]) -> (), !103 { + fn decode_array_19(mut __ret_value: __ptr [u8; 1]) -> (), !103 { local { ptr, u64 } __anon_00 local [u8; 1] __array_init_0 local slice __ret_val local slice s local slice slice_0 - entry(__ret_value: __ptr [u8; 1]): + entry(mut __ret_value: __ptr [u8; 1]): v244v1 = get_local __ptr [u8; 1], __array_init_0, !104 v874v1 = const u64 0 v875v1 = get_elem_ptr v244v1, __ptr u8, v874v1, !104 @@ -285,12 +285,12 @@ script { ret () v2028v1 } - fn to_slice_20(array: __ptr [u8; 1], __ret_value: __ptr slice) -> (), !123 { + fn to_slice_20(mut array: __ptr [u8; 1], mut __ret_value: __ptr slice) -> (), !123 { local mut slice __aggr_memcpy_0 local [u8; 1] array_ local { ptr, u64 } parts_ - entry(array: __ptr [u8; 1], __ret_value: __ptr slice): + entry(array: __ptr [u8; 1], mut __ret_value: __ptr slice): v197v1 = get_local __ptr [u8; 1], array_ mem_copy_val v197v1, array v239v1 = cast_ptr v197v1 to ptr, !124 @@ -311,12 +311,12 @@ script { ret () v2035v1 } - pub fn log_47(value !134: u8) -> (), !137 { + pub fn log_47(mut value !134: u8) -> (), !137 { local { __ptr u8, u64 } __anon_0 local slice __log_arg local u8 value_ - entry(value: u8): + entry(mut value: u8): v632v1 = get_local __ptr u8, value_ store value to v632v1 v1821v1 = get_local __ptr { __ptr u8, u64 }, __anon_0, !140 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap index a8bbf3994a3..f5a7895c354 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap @@ -16,8 +16,8 @@ script { TUPLE = config { u64 }, abi_decode_in_place_0, 0x0000000000000002, !1 WRAPPED = config { u64 }, abi_decode_in_place_0, 0x0000000000000001, !2 - pub fn abi_decode_in_place_0(ptr !4: ptr, len !5: u64, target !6: ptr) -> (), !9 { - entry(ptr: ptr, len: u64, target: ptr): + pub fn abi_decode_in_place_0(mut ptr !4: ptr, mut len !5: u64, mut target !6: ptr) -> (), !9 { + entry(mut ptr: ptr, mut len: u64, mut target: ptr): v149v1 = asm(src: ptr, target: target, len: len) -> (), !10 { mcp target src len, !11 } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/if/inline_if_expr_const/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/if/inline_if_expr_const/stdout.snap index c3905f67fc4..fec3d7e5569 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/if/inline_if_expr_const/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/if/inline_if_expr_const/stdout.snap @@ -20,10 +20,10 @@ test result: OK. 1 passed; 0 failed; finished in ??? > forc build --path test/src/e2e_vm_tests/test_programs/should_pass/language/if/inline_if_expr_const --ir initial | filter-fn inline_if_expr_const if_ -fn if_not_const_5(cond: bool) -> u64 { +fn if_not_const_5(mut cond: bool) -> u64 { local bool cond_ - entry(cond: bool): + entry(mut cond: bool): v80v1 = get_local __ptr bool, cond_ store cond to v80v1 v82v1 = get_local __ptr bool, cond_ @@ -38,7 +38,7 @@ fn if_not_const_5(cond: bool) -> u64 { v87v1 = const u64 20 br block2(v87v1) - block2(v79v1: u64): + block2(mut v79v1: u64): ret u64 v79v1 } @@ -82,7 +82,7 @@ fn if_const_generic_8() -> u64 { v107v1 = const u64 20 br block2(v107v1) - block2(v100v1: u64): + block2(mut v100v1: u64): ret u64 v100v1 } @@ -102,17 +102,17 @@ fn if_const_generic_9() -> u64 { v117v1 = const u64 20 br block2(v117v1) - block2(v110v1: u64): + block2(mut v110v1: u64): ret u64 v110v1 } > forc build --path test/src/e2e_vm_tests/test_programs/should_pass/language/if/inline_if_expr_const --ir final --asm final | filter-fn inline_if_expr_const if_ -fn if_not_const_5(cond: bool) -> u64 { +fn if_not_const_5(mut cond: bool) -> u64 { local bool cond_ - entry(cond: bool): + entry(mut cond: bool): v99v1 = get_local __ptr bool, cond_ store cond to v99v1 v101v1 = get_local __ptr bool, cond_ @@ -124,7 +124,7 @@ fn if_not_const_5(cond: bool) -> u64 { v105v1 = const u64 20 br block2(v105v1) - block2(v98v1: u64): + block2(mut v98v1: u64): ret u64 v98v1 } @@ -166,7 +166,7 @@ fn if_const_generic_8() -> u64 { v126v1 = const u64 20 br block2(v126v1) - block2(v112v1: u64): + block2(mut v112v1: u64): ret u64 v112v1 } @@ -194,7 +194,7 @@ fn if_const_generic_9() -> u64 { v143v1 = const u64 20 br block2(v143v1) - block2(v129v1: u64): + block2(mut v129v1: u64): ret u64 v129v1 } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/intrinsics/transmute/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/intrinsics/transmute/stdout.snap index 694a2d3c598..2d88cf933c7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/intrinsics/transmute/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/intrinsics/transmute/stdout.snap @@ -3,12 +3,12 @@ source: test/src/snapshot/mod.rs --- > forc build --path test/src/e2e_vm_tests/test_programs/should_pass/language/intrinsics/transmute --ir final --asm final | filter-fn transmute transmute_by_reference_7 -fn transmute_by_reference_7(__ret_value: __ptr u256) -> () { +fn transmute_by_reference_7(mut __ret_value: __ptr u256) -> () { local [u8; 32] __array_init_0 local mut [u8; 32] bytes local __ptr u256 v - entry(__ret_value: __ptr u256): + entry(mut __ret_value: __ptr u256): v790v1 = get_local __ptr [u8; 32], __array_init_0 mem_clear_val v790v1 v792v1 = get_local __ptr [u8; 32], bytes diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/stdout.snap index e6e4567553c..7ad93cb370a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/stdout.snap @@ -139,12 +139,12 @@ script { ret u64 v1377v1 } - fn local_log_1(item !69: u64) -> (), !73 { + fn local_log_1(mut item !69: u64) -> (), !73 { local { __ptr u64, u64 } __anon_0 local slice __log_arg local u64 item_ - entry(item: u64): + entry(mut item: u64): v18v1 = get_local __ptr u64, item_ store item to v18v1 v1536v1 = get_local __ptr { __ptr u64, u64 }, __anon_0, !76 @@ -164,7 +164,7 @@ script { ret () v165v1 } - pub fn abi_encode_5(self !81: u64, buffer: __ptr { { ptr, u64, u64 } }, __ret_value: __ptr { { ptr, u64, u64 } }) -> (), !84 { + pub fn abi_encode_5(mut self !81: u64, mut buffer: __ptr { { ptr, u64, u64 } }, mut __ret_value: __ptr { { ptr, u64, u64 } }) -> (), !84 { local mut { ptr, u64, u64 } __aggr_memcpy_0 local mut { ptr, u64, u64 } __aggr_memcpy_00 local { ptr, u64, u64 } __anon_0 @@ -172,7 +172,7 @@ script { local { { ptr, u64, u64 } } __struct_init_0 local { { ptr, u64, u64 } } buffer_ - entry(self: u64, buffer: __ptr { { ptr, u64, u64 } }, __ret_value: __ptr { { ptr, u64, u64 } }): + entry(mut self: u64, buffer: __ptr { { ptr, u64, u64 } }, mut __ret_value: __ptr { { ptr, u64, u64 } }): v46v1 = get_local __ptr { { ptr, u64, u64 } }, buffer_ mem_copy_val v46v1, buffer v48v1 = get_local __ptr { { ptr, u64, u64 } }, __struct_init_0, !85 @@ -198,7 +198,7 @@ script { v71v1 = cmp gt v70v1 v61v1 cbr v71v1, block1(), block0(v58v1, v61v1) - block0(v68v1: ptr, v69v1: u64): + block0(mut v68v1: ptr, mut v69v1: u64): v79v1 = add v68v1, v64v1 v80v1 = cast_ptr v79v1 to __ptr u64 store self to v80v1 @@ -234,12 +234,12 @@ script { br block0(v76v1, v75v1) } - pub fn new_6(__ret_value: __ptr { { ptr, u64, u64 } }) -> (), !89 { + pub fn new_6(mut __ret_value: __ptr { { ptr, u64, u64 } }) -> (), !89 { local mut { ptr, u64, u64 } __aggr_memcpy_0 local { ptr, u64, u64 } __anon_0 local { { ptr, u64, u64 } } __struct_init_0 - entry(__ret_value: __ptr { { ptr, u64, u64 } }): + entry(mut __ret_value: __ptr { { ptr, u64, u64 } }): v101v1 = get_local __ptr { { ptr, u64, u64 } }, __struct_init_0, !90 v102v1 = const u64 1024 v103v1 = asm(cap: v102v1) -> ptr hp { @@ -268,12 +268,12 @@ script { ret () v3808v1 } - pub fn as_raw_slice_7(self: __ptr { { ptr, u64, u64 } }, __ret_value: __ptr slice) -> (), !93 { + pub fn as_raw_slice_7(mut self: __ptr { { ptr, u64, u64 } }, mut __ret_value: __ptr slice) -> (), !93 { local mut slice __aggr_memcpy_00 local { ptr, u64 } __anon_1 local { { ptr, u64, u64 } } self_ - entry(self: __ptr { { ptr, u64, u64 } }, __ret_value: __ptr slice): + entry(self: __ptr { { ptr, u64, u64 } }, mut __ret_value: __ptr slice): v124v1 = get_local __ptr { { ptr, u64, u64 } }, self_ mem_copy_val v124v1, self v127v1 = const u64 0 @@ -302,8 +302,8 @@ script { ret () v3821v1 } - pub fn push_11(self !94: __ptr { { ptr, u64 }, u64 }, value !95: u64) -> (), !98 { - entry(self: __ptr { { ptr, u64 }, u64 }, value: u64): + pub fn push_11(mut self !94: __ptr { { ptr, u64 }, u64 }, mut value !95: u64) -> (), !98 { + entry(mut self: __ptr { { ptr, u64 }, u64 }, mut value: u64): v211v1 = const u64 1 v212v1 = get_elem_ptr self, __ptr u64, v211v1, !99 v213v1 = load v212v1 @@ -328,7 +328,7 @@ script { v1723v1 = mul v243v1, v1718v1, !117 br grow_13_block2(v1723v1), !107 - grow_13_block2(v1696v1: u64): + grow_13_block2(mut v1696v1: u64): v338v1 = const u64 0 v1729v1 = get_elem_ptr v216v1, __ptr ptr, v338v1, !119 v1730v1 = load v1729v1, !107 @@ -350,7 +350,7 @@ script { } br grow_13_realloc_15_block5(v1752v1), !143 - grow_13_realloc_15_block5(v1703v1: ptr): + grow_13_realloc_15_block5(mut v1703v1: ptr): store v1703v1 to v1729v1, !145 store v1696v1 to v218v1, !147 br block2() @@ -374,7 +374,7 @@ script { ret () v479v1 } - fn local_log_21(item: __ptr { u64, u64, u64, u8, { { ptr, u64 }, u64 }, slice, u256 }) -> (), !160 { + fn local_log_21(mut item: __ptr { u64, u64, u64, u8, { { ptr, u64 }, u64 }, slice, u256 }) -> (), !160 { local mut { ptr, u64, u64 } __aggr_memcpy_0 local mut { ptr, u64, u64 } __aggr_memcpy_00 local mut { ptr, u64, u64 } __aggr_memcpy_01 @@ -460,20 +460,20 @@ script { v532v1 = const bool false, !170 br encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block9(v532v1), !171 - encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block9(v2771v1: bool): + encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block9(mut v2771v1: bool): cbr v2771v1, encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block10(), encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block11(v2771v1), !173 encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block10(): br encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block11(v532v1), !174 - encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block11(v2774v1: bool): + encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block11(mut v2774v1: bool): cbr v2774v1, encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block12(), encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block13(v2774v1), !176 encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block12(): v524v1 = const bool true, !177 br encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block13(v524v1), !178 - encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block13(v2777v1: bool): + encode_allow_alias_22_is_encode_trivial_23_is_encode_trivial_24_block13(mut v2777v1: bool): cbr v2777v1, encode_allow_alias_22_block0(), encode_allow_alias_22_block1(), !179 encode_allow_alias_22_block0(): @@ -535,7 +535,7 @@ script { v2878v1 = cmp gt v2877v1 v2873v1, !210 cbr v2878v1, encode_allow_alias_22_abi_encode_37_abi_encode_38_block1(), encode_allow_alias_22_abi_encode_37_abi_encode_38_block0(v2871v1, v2873v1), !211 - encode_allow_alias_22_abi_encode_37_abi_encode_38_block0(v2780v1: ptr, v2781v1: u64): + encode_allow_alias_22_abi_encode_37_abi_encode_38_block0(mut v2780v1: ptr, mut v2781v1: u64): v2885v1 = get_local __ptr u64, __anon_1, !212 mem_copy_val v2885v1, v2856v1 v626v1 = const u64 4 @@ -600,7 +600,7 @@ script { } br encode_allow_alias_22_abi_encode_37_abi_encode_38_block0(v2883v1, v2882v1), !249 - encode_allow_alias_22_abi_encode_37_abi_encode_39_block0(v2783v1: ptr, v2784v1: u64): + encode_allow_alias_22_abi_encode_37_abi_encode_39_block0(mut v2783v1: ptr, mut v2784v1: u64): v2937v1 = get_local __ptr u64, __anon_10, !250 mem_copy_val v2937v1, v2908v1 v696v1 = const u64 6 @@ -666,7 +666,7 @@ script { } br encode_allow_alias_22_abi_encode_37_abi_encode_39_block0(v2935v1, v2934v1), !288 - encode_allow_alias_22_abi_encode_37_abi_encode_40_block0(v2786v1: ptr, v2787v1: u64): + encode_allow_alias_22_abi_encode_37_abi_encode_40_block0(mut v2786v1: ptr, mut v2787v1: u64): v2989v1 = add v2786v1, v2979v1, !289 v2990v1 = cast_ptr v2989v1 to __ptr u8, !290 store v2961v1 to v2990v1, !291 @@ -759,7 +759,7 @@ script { } br encode_allow_alias_22_abi_encode_37_abi_encode_40_block0(v2987v1, v2986v1), !346 - encode_allow_alias_22_abi_encode_37_abi_encode_41_append_raw_42_block0(v2790v1: ptr, v2791v1: u64): + encode_allow_alias_22_abi_encode_37_abi_encode_41_append_raw_42_block0(mut v2790v1: ptr, mut v2791v1: u64): v3077v1 = get_local __ptr { ptr, u64 }, __anon_21, !347 mem_copy_val v3077v1, v3048v1 v3079v1 = add v2790v1, v3062v1, !348 @@ -840,7 +840,7 @@ script { } br encode_allow_alias_22_abi_encode_37_abi_encode_41_append_raw_42_block0(v3075v1, v3074v1), !387 - encode_allow_alias_22_abi_encode_37_abi_encode_43_block0(v2794v1: ptr, v2795v1: u64): + encode_allow_alias_22_abi_encode_37_abi_encode_43_block0(mut v2794v1: ptr, mut v2795v1: u64): v3135v1 = get_local __ptr slice, __anon_22, !388 mem_copy_val v3135v1, v3981v1 v3137v1 = add v2794v1, v3118v1, !389 @@ -912,7 +912,7 @@ script { } br encode_allow_alias_22_abi_encode_37_abi_encode_43_block0(v3133v1, v3132v1), !424 - encode_allow_alias_22_abi_encode_37_abi_encode_44_block0(v2797v1: ptr, v2798v1: u64): + encode_allow_alias_22_abi_encode_37_abi_encode_44_block0(mut v2797v1: ptr, mut v2798v1: u64): v3186v1 = get_local __ptr u256, __anon_14, !425 mem_copy_val v3186v1, v3159v1 v3188v1 = add v2797v1, v3175v1, !426 @@ -957,7 +957,7 @@ script { } br encode_allow_alias_22_abi_encode_37_abi_encode_44_block0(v3184v1, v3183v1), !444 - encode_allow_alias_22_block2(v3738v1: __ptr slice): + encode_allow_alias_22_block2(mut v3738v1: __ptr slice): v3852v1 = get_local __ptr slice, __log_arg mem_copy_val v3852v1, v3738v1 v1059v1 = const u64 4579537983717831593 @@ -966,7 +966,7 @@ script { ret () v1063v1 } - fn local_log_46(item: __ptr { u64 }) -> (), !445 { + fn local_log_46(mut item: __ptr { u64 }) -> (), !445 { local { __ptr { u64 }, u64 } __anon_0 local slice __log_arg local { u64 } item_ @@ -991,7 +991,7 @@ script { ret () v1162v1 } - fn local_log_51(item: __ptr { u64, ( { u64 } | () ) }) -> (), !451 { + fn local_log_51(mut item: __ptr { u64, ( { u64 } | () ) }) -> (), !451 { local slice __log_arg local { u64, ( { u64 } | () ) } __matched_value_1 local { { ptr, u64, u64 } } __tmp_block_arg @@ -1041,7 +1041,7 @@ script { v1256v1 = const u64 14757395258967588866, !470 revert v1256v1, !471 - encode_allow_alias_52_abi_encode_57_block5(v3766v1: __ptr { { ptr, u64, u64 } }): + encode_allow_alias_52_abi_encode_57_block5(mut v3766v1: __ptr { { ptr, u64, u64 } }): v3826v1 = get_local __ptr slice, __log_arg v3827v1 = call as_raw_slice_7(v3766v1, v3826v1) v1287v1 = const u64 5087777005172090899 @@ -1050,7 +1050,7 @@ script { ret () v1291v1 } - fn local_log_58(item: __ptr { }) -> (), !472 { + fn local_log_58(mut item: __ptr { }) -> (), !472 { local slice __log_arg local { { ptr, u64, u64 } } buffer local { { ptr, u64, u64 } } buffer_ diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_one_u64/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_one_u64/stdout.snap index f0c9a549cb8..b6d3056efec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_one_u64/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_one_u64/stdout.snap @@ -48,8 +48,8 @@ script { retd v156v1 v166v1, !25 } - entry_orig fn main_11(baba !27: u64) -> u64, !30 { - entry(baba: u64): + entry_orig fn main_11(mut baba !27: u64) -> u64, !30 { + entry(mut baba: u64): v148v1 = const u64 1, !31 v379v1 = add baba, v148v1, !34 ret u64 v379v1 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_ref/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_ref/stdout.snap index 03596623100..ddcea5d22d8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_ref/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_ref/stdout.snap @@ -85,10 +85,10 @@ script { v46v1 = const bool true, !58 br decode_script_data_0_decode_from_raw_ptr_1_is_decode_trivial_2_is_decode_trivial_3_is_decode_trivial_5_is_decode_trivial_6_block1(v46v1), !59 - decode_script_data_0_decode_from_raw_ptr_1_is_decode_trivial_2_is_decode_trivial_3_is_decode_trivial_5_is_decode_trivial_6_block1(v703v1: bool): + decode_script_data_0_decode_from_raw_ptr_1_is_decode_trivial_2_is_decode_trivial_3_is_decode_trivial_5_is_decode_trivial_6_block1(mut v703v1: bool): br decode_script_data_0_decode_from_raw_ptr_1_is_decode_trivial_2_is_decode_trivial_3_block1(v703v1), !60 - decode_script_data_0_decode_from_raw_ptr_1_is_decode_trivial_2_is_decode_trivial_3_block1(v706v1: bool): + decode_script_data_0_decode_from_raw_ptr_1_is_decode_trivial_2_is_decode_trivial_3_block1(mut v706v1: bool): v753v1 = get_local __ptr bool, r_, !62 store v706v1 to v753v1, !63 v755v1 = get_local __ptr bool, r_, !65 @@ -171,7 +171,7 @@ script { mem_copy_val v855v1, v849v1 br decode_script_data_0_decode_from_raw_ptr_1_block2(v855v1), !145 - decode_script_data_0_decode_from_raw_ptr_1_block2(v851v1: __ptr { { u64 } }): + decode_script_data_0_decode_from_raw_ptr_1_block2(mut v851v1: __ptr { { u64 } }): v859v1 = get_local __ptr { { u64 } }, __tmp_block_arg2 mem_copy_val v859v1, v851v1 v863v1 = get_local __ptr { { u64 } }, __tmp_block_arg3 @@ -202,7 +202,7 @@ script { retd v839v1 v841v1, !166 } - entry_orig fn main_15(baba: __ptr { u64 }) -> u64, !170 { + entry_orig fn main_15(mut baba: __ptr { u64 }) -> u64, !170 { local u64 other_ entry(baba: __ptr { u64 }): diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_two_u64/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_two_u64/stdout.snap index 1d619aa6c41..1e65b6bca62 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_two_u64/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_two_u64/stdout.snap @@ -54,8 +54,8 @@ script { retd v175v1 v185v1, !26 } - entry_orig fn main_11(baba !28: u64, keke !29: u64) -> u64, !32 { - entry(baba: u64, keke: u64): + entry_orig fn main_11(mut baba !28: u64, mut keke !29: u64) -> u64, !32 { + entry(mut baba: u64, mut keke: u64): v379v1 = add baba, keke, !35 ret u64 v379v1 } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/stdout.snap index d332491cee4..009c3e6f698 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/stdout.snap @@ -72,7 +72,7 @@ script { v217v1 = const u64 0, !33 br decode_script_data_0_decode_from_raw_ptr_1_abi_decode_15_abi_decode_16_while(v217v1), !34 - decode_script_data_0_decode_from_raw_ptr_1_abi_decode_15_abi_decode_16_while(v4141v1: u64): + decode_script_data_0_decode_from_raw_ptr_1_abi_decode_15_abi_decode_16_while(mut v4141v1: u64): v235v1 = const u64 2 v4243v1 = cmp lt v4141v1 v235v1, !37 cbr v4243v1, decode_script_data_0_decode_from_raw_ptr_1_abi_decode_15_abi_decode_16_while_body(), decode_script_data_0_decode_from_raw_ptr_1_abi_decode_15_abi_decode_16_end_while(), !38 @@ -192,7 +192,7 @@ script { v426v1 = const u64 0, !137 revert v426v1, !139 - decode_script_data_0_decode_from_raw_ptr_1_abi_decode_15_abi_decode_16_decode_18_abi_decode_19_abi_decode_26_block5(v4446v1: __ptr { u64, ( u64 | u64 ) }): + decode_script_data_0_decode_from_raw_ptr_1_abi_decode_15_abi_decode_16_decode_18_abi_decode_19_abi_decode_26_block5(mut v4446v1: __ptr { u64, ( u64 | u64 ) }): v1171v1 = const u64 0 v4368v1 = get_elem_ptr v4262v1, __ptr { string<3> }, v1171v1, !140 mem_copy_val v4368v1, v4265v1 @@ -224,7 +224,7 @@ script { retd v1137v1 v1147v1, !154 } - entry_orig fn main_32(ops: __ptr [{ { string<3> }, { u64, ( u64 | u64 ) } }; 2], __ret_value: __ptr { u64 }) -> (), !157 { + entry_orig fn main_32(mut ops: __ptr [{ { string<3> }, { u64, ( u64 | u64 ) } }; 2], mut __ret_value: __ptr { u64 }) -> (), !157 { local mut { ptr, u64, u64 } __aggr_memcpy_0 local mut { ptr, u64, u64 } __aggr_memcpy_00 local mut { ptr, u64, u64 } __aggr_memcpy_01 @@ -284,7 +284,7 @@ script { local [{ { string<3> }, { u64, ( u64 | u64 ) } }; 2] self_2 local { { ptr, u64, u64 } } self_3 - entry(ops: __ptr [{ { string<3> }, { u64, ( u64 | u64 ) } }; 2], __ret_value: __ptr { u64 }): + entry(ops: __ptr [{ { string<3> }, { u64, ( u64 | u64 ) } }; 2], mut __ret_value: __ptr { u64 }): v506v1 = get_local __ptr [{ { string<3> }, { u64, ( u64 | u64 ) } }; 2], ops_ mem_copy_val v506v1, ops v3847v1 = get_local __ptr { { ptr, u64, u64 } }, __struct_init_00, !162 @@ -319,7 +319,7 @@ script { v598v1 = const u64 0, !178 br encode_allow_alias_33_abi_encode_46_while(v598v1), !179 - encode_allow_alias_33_abi_encode_46_while(v3779v1: u64): + encode_allow_alias_33_abi_encode_46_while(mut v3779v1: u64): v604v1 = const u64 2 v3876v1 = cmp lt v3779v1 v604v1, !182 cbr v3876v1, encode_allow_alias_33_abi_encode_46_while_body(), encode_allow_alias_33_abi_encode_46_end_while(), !183 @@ -365,7 +365,7 @@ script { v3952v1 = cmp gt v3951v1 v3946v1, !214 cbr v3952v1, encode_allow_alias_33_abi_encode_46_abi_encode_47_abi_encode_48_abi_encode_49_block1(), encode_allow_alias_33_abi_encode_46_abi_encode_47_abi_encode_48_abi_encode_49_block0(v3944v1, v3946v1), !215 - encode_allow_alias_33_abi_encode_46_abi_encode_47_abi_encode_48_abi_encode_49_block0(v3781v1: ptr, v3782v1: u64): + encode_allow_alias_33_abi_encode_46_abi_encode_47_abi_encode_48_abi_encode_49_block0(mut v3781v1: ptr, mut v3782v1: u64): v3959v1 = get_local __ptr string<3>, __anon_10, !216 mem_copy_val v3959v1, v3932v1 v3961v1 = add v3781v1, v3948v1, !217 @@ -471,7 +471,7 @@ script { v819v1 = const u64 14757395258967588866, !238 revert v819v1, !272 - encode_allow_alias_33_abi_encode_46_abi_encode_47_abi_encode_50_block5(v4457v1: __ptr { { ptr, u64, u64 } }): + encode_allow_alias_33_abi_encode_46_abi_encode_47_abi_encode_50_block5(mut v4457v1: __ptr { { ptr, u64, u64 } }): v4055v1 = get_local __ptr { { ptr, u64, u64 } }, buffer______, !274 mem_copy_val v4055v1, v4457v1 v4060v1 = get_local __ptr { { ptr, u64, u64 } }, buffer___, !276 @@ -645,7 +645,7 @@ script { revert v1118v1, !360 } - pub fn abi_encode_51(self !361: u64, buffer: __ptr { { ptr, u64, u64 } }, __ret_value: __ptr { { ptr, u64, u64 } }) -> (), !364 { + pub fn abi_encode_51(mut self !361: u64, mut buffer: __ptr { { ptr, u64, u64 } }, mut __ret_value: __ptr { { ptr, u64, u64 } }) -> (), !364 { local mut { ptr, u64, u64 } __aggr_memcpy_0 local mut { ptr, u64, u64 } __aggr_memcpy_00 local { ptr, u64, u64 } __anon_0 @@ -653,7 +653,7 @@ script { local { { ptr, u64, u64 } } __struct_init_0 local { { ptr, u64, u64 } } buffer_ - entry(self: u64, buffer: __ptr { { ptr, u64, u64 } }, __ret_value: __ptr { { ptr, u64, u64 } }): + entry(mut self: u64, buffer: __ptr { { ptr, u64, u64 } }, mut __ret_value: __ptr { { ptr, u64, u64 } }): v724v1 = get_local __ptr { { ptr, u64, u64 } }, buffer_ mem_copy_val v724v1, buffer v726v1 = get_local __ptr { { ptr, u64, u64 } }, __struct_init_0, !365 @@ -679,7 +679,7 @@ script { v749v1 = cmp gt v748v1 v739v1 cbr v749v1, block1(), block0(v736v1, v739v1) - block0(v746v1: ptr, v747v1: u64): + block0(mut v746v1: ptr, mut v747v1: u64): v757v1 = add v746v1, v742v1 v758v1 = cast_ptr v757v1 to __ptr u64 store self to v758v1 @@ -715,7 +715,7 @@ script { br block0(v754v1, v753v1) } - fn eq_str_3_57(a: __ptr string<3>, b: __ptr slice) -> bool, !368 { + fn eq_str_3_57(mut a: __ptr string<3>, mut b: __ptr slice) -> bool, !368 { local { ptr, u64 } __tuple_1_ local string<3> a_ local slice self_ diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_all/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_all/stdout.snap index 133d1732da5..390c995a9c8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_all/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_all/stdout.snap @@ -11,7 +11,7 @@ output: > forc build --path test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_all --ir final --asm final --release | filter-fn match_expressions_all return_match_on_str_slice -fn return_match_on_str_slice_8(param: __ptr slice) -> u64 { +fn return_match_on_str_slice_8(mut param: __ptr slice) -> u64 { local { ptr, u64 } __anon_0 local slice __anon_1 local { ptr, u64 } __anon_2 @@ -20,7 +20,7 @@ fn return_match_on_str_slice_8(param: __ptr slice) -> u64 { local slice __anon_5 local slice __matched_value_1 - entry(param: __ptr slice): + entry(mut param: __ptr slice): v263v1 = get_local __ptr slice, __matched_value_1 mem_copy_val v263v1, param v265v1 = get_global __ptr string<5>, __const_global @@ -77,13 +77,13 @@ fn return_match_on_str_slice_8(param: __ptr slice) -> u64 { v310v1 = const u64 1000 br block6(v310v1) - block6(v260v1: u64): + block6(mut v260v1: u64): br block7(v260v1) - block7(v261v1: u64): + block7(mut v261v1: u64): br block8(v261v1) - block8(v262v1: u64): + block8(mut v262v1: u64): ret u64 v262v1 } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/optimisations/leaf_fns/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/optimisations/leaf_fns/stdout.snap index 16bd8dcb26b..fe74de554bc 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/optimisations/leaf_fns/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/optimisations/leaf_fns/stdout.snap @@ -10,8 +10,8 @@ fn leaf_fn_0_1() -> () { } -fn leaf_fn_6_2(a: u64, b: u64, c: u64, d: u64, e: u64, f: u64) -> u64 { - entry(a: u64, b: u64, c: u64, d: u64, e: u64, f: u64): +fn leaf_fn_6_2(mut a: u64, mut b: u64, mut c: u64, mut d: u64, mut e: u64, mut f: u64) -> u64 { + entry(mut a: u64, mut b: u64, mut c: u64, mut d: u64, mut e: u64, mut f: u64): v32v1 = add a, b v33v1 = add v32v1, c v34v1 = add v33v1, d @@ -21,8 +21,8 @@ fn leaf_fn_6_2(a: u64, b: u64, c: u64, d: u64, e: u64, f: u64) -> u64 { } -fn leaf_fn_7_4(a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64) -> u64 { - entry(a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64): +fn leaf_fn_7_4(mut a: u64, mut b: u64, mut c: u64, mut d: u64, mut e: u64, mut f: u64, mut g: u64) -> u64 { + entry(mut a: u64, mut b: u64, mut c: u64, mut d: u64, mut e: u64, mut f: u64, mut g: u64): v45v1 = add a, b v46v1 = add v45v1, c v47v1 = add v46v1, d diff --git a/test/src/ir_generation/tests/enum_struct_string.sw b/test/src/ir_generation/tests/enum_struct_string.sw index 9813953c1cc..c504a729b37 100644 --- a/test/src/ir_generation/tests/enum_struct_string.sw +++ b/test/src/ir_generation/tests/enum_struct_string.sw @@ -39,4 +39,4 @@ fn main() -> u64 { // check: $(tag_matches=$VAL) = call $(eq_fn=$ID)($b_val_tag, $zero) // check: cbr $tag_matches -// check: fn $eq_fn(self $MD: u64, other $MD: u64) -> bool +// check: fn $eq_fn(mut self $MD: u64, mut other $MD: u64) -> bool diff --git a/test/src/ir_generation/tests/fn_call.sw b/test/src/ir_generation/tests/fn_call.sw index 6e5543925a3..351b86257f7 100644 --- a/test/src/ir_generation/tests/fn_call.sw +++ b/test/src/ir_generation/tests/fn_call.sw @@ -27,12 +27,12 @@ fn main() -> u64 { // check: call // check: ret u64 -// check: fn $ID(x $MD: u64) -> u64 -// check: entry(x: u64): +// check: fn $ID(mut x $MD: u64) -> u64 +// check: entry(mut x: u64): // check: ret u64 $VAL // check: } -// check: fn $ID(x $MD: u64, y $MD: u64) -> u64 +// check: fn $ID(mut x $MD: u64, mut y $MD: u64) -> u64 // check: local bool var // ::check-asm:: diff --git a/test/src/ir_generation/tests/fn_call_ret_by_ref_explicit.sw b/test/src/ir_generation/tests/fn_call_ret_by_ref_explicit.sw index 4b2c848f05d..f2813db6925 100644 --- a/test/src/ir_generation/tests/fn_call_ret_by_ref_explicit.sw +++ b/test/src/ir_generation/tests/fn_call_ret_by_ref_explicit.sw @@ -46,7 +46,7 @@ fn main() -> u64 { // fn a()... // -// check: fn $a_func($ID $MD: bool, $ID $MD: u64, $ID $MD: u64, $(ret_val_arg=$ID): __ptr { u64, u64, u64 }) -> () +// check: fn $a_func(mut $ID $MD: bool, mut $ID $MD: u64, mut $ID $MD: u64, mut $(ret_val_arg=$ID): __ptr { u64, u64, u64 }) -> () // check: cbr $ID, $(block_0=$ID)(), $(block_1=$ID)() // check: $block_0(): diff --git a/test/src/ir_generation/tests/fn_call_ret_by_ref_implicit.sw b/test/src/ir_generation/tests/fn_call_ret_by_ref_implicit.sw index db85d38edeb..01fb1433a02 100644 --- a/test/src/ir_generation/tests/fn_call_ret_by_ref_implicit.sw +++ b/test/src/ir_generation/tests/fn_call_ret_by_ref_implicit.sw @@ -35,7 +35,7 @@ fn main() -> u64 { // check: $(field_2_val=$VAL) = load $field_2_ptr // check: ret u64 $field_2_val -// check: fn $a_fn($(x_arg=$ID) $MD: u64, $(ret_val_arg_ptr=$ID): __ptr { u64, u64, u64 }) -> () +// check: fn $a_fn(mut $(x_arg=$ID) $MD: u64, mut $(ret_val_arg_ptr=$ID): __ptr { u64, u64, u64 }) -> () // check: $(temp_ptr=$VAL) = get_local __ptr { u64, u64, u64 }, $(=__tuple_init_\d+) diff --git a/test/src/ir_generation/tests/fn_dedup.sw b/test/src/ir_generation/tests/fn_dedup.sw index 5f89b84e4fa..f020a398690 100644 --- a/test/src/ir_generation/tests/fn_dedup.sw +++ b/test/src/ir_generation/tests/fn_dedup.sw @@ -26,9 +26,8 @@ fn main() { // ::check-ir:: // regex: NUM=[0-9]+ -// check: fn getter_$NUM(self !$NUM: { u64 }, b !$NUM: u64) -> u64, !$NUM { -// not: fn getter_$NUM(self !$NUM: { u64 }, b !$NUM: u64) -> u64, !$NUM { - -// check: fn func_$NUM(u !$NUM: u64) -> u64, !$NUM { -// not: fn func_$NUM(u !$NUM: u64) -> u64, !$NUM { +// check: fn getter_$NUM(mut self !$NUM: { u64 }, mut b !$NUM: u64) -> u64, !$NUM { +// not: fn getter_$NUM(mut self !$NUM: { u64 }, mut b !$NUM: u64) -> u64, !$NUM { +// check: fn func_$NUM(mut u !$NUM: u64) -> u64, !$NUM { +// not: fn func_$NUM(mut u !$NUM: u64) -> u64, !$NUM { diff --git a/test/src/ir_generation/tests/if_expr.sw b/test/src/ir_generation/tests/if_expr.sw index e99d34f8344..a8227ca29b0 100644 --- a/test/src/ir_generation/tests/if_expr.sw +++ b/test/src/ir_generation/tests/if_expr.sw @@ -18,5 +18,5 @@ fn main() -> u64 { // check: $(bl1_val=$VAL) = const u64 42 // check: br $bl2($bl1_val) -// check: $bl2($(ret_val=$VAL): u64): +// check: $bl2(mut $(ret_val=$VAL): u64): // check: ret u64 $ret_val diff --git a/test/src/ir_generation/tests/if_let_simple.sw b/test/src/ir_generation/tests/if_let_simple.sw index 99b6090ea5a..a3367f93ab6 100644 --- a/test/src/ir_generation/tests/if_let_simple.sw +++ b/test/src/ir_generation/tests/if_let_simple.sw @@ -51,7 +51,7 @@ fn main() -> u64 { // check: $(zero=$VAL) = const u64 0 // check: br $block2($zero) -// check: $block2($(res=$VAL): u64): +// check: $block2(mut $(res=$VAL): u64): // check: ret u64 $res -// check: fn $eq_fn(self $MD: u64, other $MD: u64) -> bool +// check: fn $eq_fn(mut self $MD: u64, mut other $MD: u64) -> bool diff --git a/test/src/ir_generation/tests/impl_self_reassignment.sw b/test/src/ir_generation/tests/impl_self_reassignment.sw index 2e10afca614..6ece838d3bb 100644 --- a/test/src/ir_generation/tests/impl_self_reassignment.sw +++ b/test/src/ir_generation/tests/impl_self_reassignment.sw @@ -22,8 +22,8 @@ fn main() { // check: $(a_var=$VAL) = get_local __ptr { u64 }, a // check: call $(f_method=$ID)($a_var) -// check: fn $f_method(self $MD: __ptr { u64 }) -> () -// check: entry(self: __ptr { u64 }): +// check: fn $f_method(mut self $MD: __ptr { u64 }) -> () +// check: entry(mut self: __ptr { u64 }): // check: $(idx_0=$VAL) = const u64 0 // check: $(a_ptr=$VAL) = get_elem_ptr $VAL, __ptr u64, $idx_0 diff --git a/test/src/ir_generation/tests/lazy_binops.sw b/test/src/ir_generation/tests/lazy_binops.sw index 61147260b33..5795cf1c617 100644 --- a/test/src/ir_generation/tests/lazy_binops.sw +++ b/test/src/ir_generation/tests/lazy_binops.sw @@ -12,12 +12,12 @@ fn main() -> bool { // check: $(bl0_val=$VAL) = const bool true // check: br $bl1($bl0_val) -// check: $bl1($(bl1_val=$VAL): bool) +// check: $bl1(mut $(bl1_val=$VAL): bool) // check: cbr $bl1_val, $(bl3=$ID)($bl1_val), $(bl2=$ID)() // check: $bl2() // check: $(true_val=$VAL) = const bool true // check: br $bl3 -// check: $bl3($(ret_val=$VAL): bool) +// check: $bl3(mut $(ret_val=$VAL): bool) // check: ret bool $ret_val diff --git a/test/src/ir_generation/tests/let_reassign_while_loop.sw b/test/src/ir_generation/tests/let_reassign_while_loop.sw index 20237a6bc3a..b121f9ea118 100644 --- a/test/src/ir_generation/tests/let_reassign_while_loop.sw +++ b/test/src/ir_generation/tests/let_reassign_while_loop.sw @@ -22,7 +22,7 @@ fn main() -> bool { // check: $block0(): // check: br $(block1=$ID)($VAL) -// check: $block1($VAL: bool): +// check: $block1(mut $VAL: bool): // check: br $while // check: $end_while(): diff --git a/test/src/ir_generation/tests/return_stmt.sw b/test/src/ir_generation/tests/return_stmt.sw index 309ddf38c54..bf519673cc7 100644 --- a/test/src/ir_generation/tests/return_stmt.sw +++ b/test/src/ir_generation/tests/return_stmt.sw @@ -25,4 +25,4 @@ fn main() -> u64 { // check: $(unit_val=$VAL) = const unit () // check: br $(block2=$ID)($unit_val) -// check: $block2($VAL: ()): +// check: $block2(mut $VAL: ()): diff --git a/test/src/ir_generation/tests/revert.sw b/test/src/ir_generation/tests/revert.sw index 4475cce9d64..6e95d9ecf8f 100644 --- a/test/src/ir_generation/tests/revert.sw +++ b/test/src/ir_generation/tests/revert.sw @@ -17,7 +17,7 @@ fn main() { // check: $(value=$VAL) = const u64 42 // check: call revert_0($value) -// check: fn revert_0($(foo=$ID) -// check: entry($foo: u64): +// check: fn revert_0(mut $(foo=$ID) +// check: entry(mut $foo: u64): // checj: revert $foo -// check: } +// check: } diff --git a/test/src/ir_generation/tests/shadowed_locals.sw b/test/src/ir_generation/tests/shadowed_locals.sw index 231048e20e9..8119da16842 100644 --- a/test/src/ir_generation/tests/shadowed_locals.sw +++ b/test/src/ir_generation/tests/shadowed_locals.sw @@ -19,7 +19,7 @@ fn main() -> u64 { // check: $(true=$VAL) = const bool true // check: store $true to $a_var -// check: $ID($(int_val=$VAL): u64): +// check: $ID(mut $(int_val=$VAL): u64): // check: $(a__var=$VAL) = get_local __ptr u64, a_ // check: store $int_val to $a__var @@ -36,4 +36,4 @@ fn main() -> u64 { // check: $(idx_val=$VAL) = const u64 0 // check: $(a_ptr=$VAL) = get_elem_ptr $a___var, __ptr u64, $idx_val // check: $(a_loaded=$VAL) = load $a_ptr -// check: ret u64 $a_loaded \ No newline at end of file +// check: ret u64 $a_loaded diff --git a/test/src/ir_generation/tests/shadowed_struct_init.sw b/test/src/ir_generation/tests/shadowed_struct_init.sw index c56e38182c4..40825f5d207 100644 --- a/test/src/ir_generation/tests/shadowed_struct_init.sw +++ b/test/src/ir_generation/tests/shadowed_struct_init.sw @@ -18,7 +18,7 @@ fn main() { new(true, false); } -// check: fn $ID(a $MD: bool, b $MD: bool) -> { bool, bool } +// check: fn $ID(mut a $MD: bool, mut b $MD: bool) -> { bool, bool } // check: local bool a__ // check: local bool b__ diff --git a/test/src/ir_generation/tests/simple_contract.sw b/test/src/ir_generation/tests/simple_contract.sw index f5bc8d1e2f0..1c783e4c1a4 100644 --- a/test/src/ir_generation/tests/simple_contract.sw +++ b/test/src/ir_generation/tests/simple_contract.sw @@ -33,9 +33,9 @@ impl Test for Contract { // ::check-ir:: // check: contract { -// check: fn get_b256<42123b96>($ID: __ptr b256) -> __ptr b256, -// check: fn get_s($ID $MD: u64, $ID: __ptr b256) -> __ptr { u64, b256 } -// check: fn get_u64<9890aef4>($ID $MD: u64) -> u64 +// check: fn get_b256<42123b96>(mut $ID: __ptr b256) -> __ptr b256, +// check: fn get_s(mut $ID $MD: u64, mut $ID: __ptr b256) -> __ptr { u64, b256 } +// check: fn get_u64<9890aef4>(mut $ID $MD: u64) -> u64 // ::check-asm:: diff --git a/test/src/ir_generation/tests/storage_metadata.sw b/test/src/ir_generation/tests/storage_metadata.sw index 9e67acb64c3..5feee41696e 100644 --- a/test/src/ir_generation/tests/storage_metadata.sw +++ b/test/src/ir_generation/tests/storage_metadata.sw @@ -46,8 +46,8 @@ impl Incrementor for Contract { // one is which, but should at least be deterministic for any particular version of the compiler. // check: fn get<75b70457>() -> u64, $(get_md=$MD) { -// check: fn increment(increment_by $MD: u64) -> u64, $(increment_md=$MD) { -// check: fn initialize<557ac400>(initial_value $MD: u64) -> u64, $(init_md=$MD) { +// check: fn increment(mut increment_by $MD: u64) -> u64, $(increment_md=$MD) { +// check: fn initialize<557ac400>(mut initial_value $MD: u64) -> u64, $(init_md=$MD) { // unordered: $(write_md=$MD) = purity "writes" // unordered: $(write_fn_name_md=$MD) = fn_name_span $MD 359 369 @@ -62,4 +62,4 @@ impl Incrementor for Contract { // unordered: $init_md = ($MD $write_md $write_fn_name_md) // unordered: $increment_md = ($MD $readwrite_md $readwrite_fn_name_md) -// unordered: $get_md = ($MD $read_md $read_fn_name_md) \ No newline at end of file +// unordered: $get_md = ($MD $read_md $read_fn_name_md) diff --git a/test/src/ir_generation/tests/takes_string_returns_string.sw b/test/src/ir_generation/tests/takes_string_returns_string.sw index 339c1a7ae64..685525e6085 100644 --- a/test/src/ir_generation/tests/takes_string_returns_string.sw +++ b/test/src/ir_generation/tests/takes_string_returns_string.sw @@ -14,10 +14,10 @@ impl MyContract for Contract { } } -// check: fn large_string<28c0f699>(s $MD: string<9>) -> string<9> -// check: entry(s: string<9>): +// check: fn large_string<28c0f699>(mut s $MD: string<9>) -> string<9> +// check: entry(mut s: string<9>): // check: ret string<9> $VAL -// check: fn small_string<80da70e2>(s $MD: string<7>) -> string<7> -// check: entry(s: string<7>): +// check: fn small_string<80da70e2>(mut s $MD: string<7>) -> string<7> +// check: entry(mut s: string<7>): // check: ret string<7> $VAL diff --git a/test/src/ir_generation/tests/trait.sw b/test/src/ir_generation/tests/trait.sw index 200f72fbf50..a362f384784 100644 --- a/test/src/ir_generation/tests/trait.sw +++ b/test/src/ir_generation/tests/trait.sw @@ -41,7 +41,7 @@ fn main() -> bool { // check: $(res=$VAL) = call $(pred_or=$ID)($foo_val, $bar_val) // check: ret bool $res -// check: fn $pred_or(self $MD: { bool }, other $MD: { bool }) -> bool +// check: fn $pred_or(mut self $MD: { bool }, mut other $MD: { bool }) -> bool // check: store self to $VAL // check: store other to $VAL // check: $(self_ptr=$VAL) = get_local __ptr { bool }, self_ @@ -55,5 +55,5 @@ fn main() -> bool { // check: $(other_pred=$VAL) = call $ID($other_val) // check: br $block1 -// check: $block1($(res=$VAL): bool): +// check: $block1(mut $(res=$VAL): bool): // check: ret bool $res diff --git a/test/src/snapshot/mod.rs b/test/src/snapshot/mod.rs index 5359a3d2733..bbbf00a4e83 100644 --- a/test/src/snapshot/mod.rs +++ b/test/src/snapshot/mod.rs @@ -388,6 +388,7 @@ fn run_cmds( let o = duct::cmd!("bash", "-c", cmd.clone()) .dir(repo_root.clone()) + .env("SWAY_FORCE_VERIFY_IR", "true") .stderr_to_stdout() .stdout_capture(); @@ -696,7 +697,7 @@ fn patch_file(object: &object::File, endian: gimli::RunTimeEndian, bin_file_path }; let code = std::fs::read_to_string(&path).unwrap(); - let line = line.checked_sub(1).unwrap_or_default(); + let line = line.saturating_sub(1); let line = code.lines().nth(line as usize).unwrap(); if let Some((_, rest)) = line.split_once("// PATCH: ") {