From dcb7917e9b1ae1de6f1a9e6420d40087a684f0ad Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Wed, 12 Apr 2023 15:53:21 +0100 Subject: [PATCH] Implements DCA warnings for function parameters. (#4406) ## Description With these changes we will have DCA warnings for function parameters. This PR also fixes tests that have unused function parameters. ## Checklist - [ ] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Mohammad Fawaz --- .../dead_code_analysis.rs | 141 +++++++++++++----- .../control_flow_analysis/flow_graph/mod.rs | 9 ++ sway-lib-core/src/never.sw | 6 +- sway-lib-std/src/tx.sw | 2 +- .../should_fail/simple_generics/test.toml | 4 + .../should_pass/dca/func_param/Forc.lock | 3 + .../should_pass/dca/func_param/Forc.toml | 6 + .../should_pass/dca/func_param/src/main.sw | 38 +++++ .../should_pass/dca/func_param/test.toml | 19 +++ .../generic_fn_trait_contraint/src/main.sw | 2 +- .../should_pass/dca/unused_fields/src/main.sw | 2 +- .../dca/unused_fields/src/utils.sw | 2 +- .../should_pass/dca/unused_trait/src/utils.sw | 2 +- .../language/basic_func_decl/src/main.sw | 2 +- .../language/generic_functions/src/main.sw | 6 +- .../generic_type_inference/src/utils.sw | 2 +- .../language/is_reference_type/src/main.sw | 2 +- .../src/main.sw | 2 +- .../src/main.sw | 6 +- .../where_clause_functions/src/main.sw | 6 +- .../src/main.sw | 2 +- .../src/main.sw | 2 +- .../src/main.sw | 2 +- .../should_pass/stdlib/intrinsics/src/main.sw | 2 +- .../json_abi_oracle.json | 12 +- .../abi_with_generic_types/src/main.sw | 12 +- .../json_abi_oracle.json | 6 +- .../abi_with_same_name_types/src/main.sw | 6 +- .../json_abi_oracle.json | 4 +- .../abi_with_tuples_contract/src/main.sw | 4 +- 30 files changed, 231 insertions(+), 83 deletions(-) create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.lock create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/test.toml diff --git a/sway-core/src/control_flow_analysis/dead_code_analysis.rs b/sway-core/src/control_flow_analysis/dead_code_analysis.rs index 4192b3fba80..3735605a1c7 100644 --- a/sway-core/src/control_flow_analysis/dead_code_analysis.rs +++ b/sway-core/src/control_flow_analysis/dead_code_analysis.rs @@ -41,26 +41,6 @@ impl<'cfg> ControlFlowGraph<'cfg> { } let is_dead_check = |n: &NodeIndex| { - if let ControlFlowGraphNode::ProgramNode { - node: - ty::TyAstNode { - content: ty::TyAstNodeContent::Declaration(ty::TyDecl::VariableDecl { .. }), - .. - }, - .. - } = &self.graph[*n] - { - // Consider variables declarations dead when count is not greater than 1 - connections_count - .get(n) - .cloned() - .map_or(true, |count| count <= 1) - } else { - false - } - }; - - let is_alive_check = |n: &NodeIndex| { match &self.graph[*n] { ControlFlowGraphNode::ProgramNode { node: @@ -71,11 +51,64 @@ impl<'cfg> ControlFlowGraph<'cfg> { }, .. } => { - // Consider variables declarations alive when count is greater than 1 + // Consider variables declarations dead when count is not greater than 1 connections_count .get(n) .cloned() - .map_or(false, |count| count > 1) + .map_or(true, |count| count <= 1) + } + ControlFlowGraphNode::FunctionParameter { .. } => { + // Consider variables declarations dead when count is not greater than 1 + // Function param always has the function pointing to them + connections_count + .get(n) + .cloned() + .map_or(true, |count| count <= 1) + } + _ => false, + } + }; + + let is_alive_check = |n: &NodeIndex| { + match &self.graph[*n] { + ControlFlowGraphNode::ProgramNode { + node: + ty::TyAstNode { + content: + ty::TyAstNodeContent::Declaration(ty::TyDecl::VariableDecl(decl)), + .. + }, + .. + } => { + if decl.name.as_str().starts_with('_') { + true + } else { + // Consider variables declarations alive when count is greater than 1 + // This is explicilty required because the variable may be considered dead + // when it is not connected from an entry point, while it may still be used by other dead code. + connections_count + .get(n) + .cloned() + .map_or(false, |count| count > 1) + } + } + ControlFlowGraphNode::FunctionParameter { + param_name, + is_self, + .. + } => { + if *is_self || param_name.as_str().starts_with('_') { + // self type parameter is always alive + true + } else { + // Consider param alive when count is greater than 1 + // This is explicilty required because the param may be considered dead + // when it is not connected from an entry point, while it may still be used by other dead code. + connections_count + .get(n) + .cloned() + .map_or(true, |count| count > 1) + } } ControlFlowGraphNode::ProgramNode { node: @@ -189,6 +222,12 @@ impl<'cfg> ControlFlowGraph<'cfg> { }) } ControlFlowGraphNode::OrganizationalDominator(..) => None, + ControlFlowGraphNode::FunctionParameter { param_name, .. } => { + Some(CompileWarning { + span: param_name.span(), + warning_content: Warning::DeadDeclaration, + }) + } } } }) @@ -851,6 +890,26 @@ fn connect_typed_fn_decl<'eng: 'cfg, 'cfg>( options: NodeConnectionOptions, ) -> Result<(), CompileError> { let type_engine = engines.te(); + + graph.namespace.push_code_block(); + for fn_param in fn_decl.parameters.iter() { + let fn_param_node = graph.add_node(ControlFlowGraphNode::FunctionParameter { + param_name: fn_param.name.clone(), + is_self: matches!( + type_engine.get(fn_param.type_argument.initial_type_id), + TypeInfo::SelfType + ), + }); + graph.add_edge(entry_node, fn_param_node, "".into()); + + graph.namespace.insert_variable( + fn_param.name.clone(), + VariableNamespaceEntry { + variable_decl_ix: fn_param_node, + }, + ) + } + let fn_exit_node = graph.add_node(format!("\"{}\" fn exit", fn_decl.name.as_str()).into()); let (_exit_nodes, _exit_node) = depth_first_insertion_code_block( engines, @@ -864,6 +923,8 @@ fn connect_typed_fn_decl<'eng: 'cfg, 'cfg>( parent_node: Some(entry_node), }, )?; + graph.namespace.pop_code_block(); + if let Some(exit_node) = exit_node { graph.add_edge(fn_exit_node, exit_node, "".into()); } @@ -1674,17 +1735,27 @@ fn connect_expression<'eng: 'cfg, 'cfg>( } Ok(vec![]) } - Reassignment(typed_reassignment) => connect_expression( - engines, - &typed_reassignment.rhs.expression, - graph, - leaves, - exit_node, - "variable reassignment", - tree_type, - typed_reassignment.rhs.clone().span, - options, - ), + Reassignment(typed_reassignment) => { + if let Some(variable_entry) = graph + .namespace + .get_variable(&typed_reassignment.lhs_base_name) + { + for leaf in leaves { + graph.add_edge(*leaf, variable_entry.variable_decl_ix, "".into()); + } + } + connect_expression( + engines, + &typed_reassignment.rhs.expression, + graph, + leaves, + exit_node, + "variable reassignment", + tree_type, + typed_reassignment.rhs.clone().span, + options, + ) + } StorageReassignment(typed_storage_reassignment) => connect_expression( engines, &typed_storage_reassignment.rhs.expression, @@ -1907,9 +1978,6 @@ fn construct_dead_code_warning_from_node( content: ty::TyAstNodeContent::Declaration(ty::TyDecl::VariableDecl(decl)), span, } => { - if decl.name.as_str().starts_with('_') { - return None; - } // In rare cases, variable declaration spans don't have a path, so we need to check for that if decl.name.span().path().is_some() { CompileWarning { @@ -2087,5 +2155,6 @@ fn allow_dead_code_node( } ControlFlowGraphNode::StorageField { .. } => false, ControlFlowGraphNode::OrganizationalDominator(..) => false, + ControlFlowGraphNode::FunctionParameter { .. } => false, } } diff --git a/sway-core/src/control_flow_analysis/flow_graph/mod.rs b/sway-core/src/control_flow_analysis/flow_graph/mod.rs index 34e976f657a..5bdcbc1545e 100644 --- a/sway-core/src/control_flow_analysis/flow_graph/mod.rs +++ b/sway-core/src/control_flow_analysis/flow_graph/mod.rs @@ -81,6 +81,10 @@ pub enum ControlFlowGraphNode<'cfg> { StorageField { field_name: Ident, }, + FunctionParameter { + param_name: Ident, + is_self: bool, + }, } impl<'cfg> GetDeclIdent for ControlFlowGraphNode<'cfg> { @@ -96,6 +100,7 @@ impl<'cfg> GetDeclIdent for ControlFlowGraphNode<'cfg> { struct_field_name, .. } => Some(struct_field_name.clone()), ControlFlowGraphNode::StorageField { field_name, .. } => Some(field_name.clone()), + ControlFlowGraphNode::FunctionParameter { param_name, .. } => Some(param_name.clone()), } } } @@ -156,6 +161,9 @@ impl<'cfg> DebugWithEngines for ControlFlowGraphNode<'cfg> { ControlFlowGraphNode::StorageField { field_name } => { format!("Storage field {}", field_name.as_str()) } + ControlFlowGraphNode::FunctionParameter { param_name, .. } => { + format!("Function param {}", param_name.as_str()) + } }; f.write_str(&text) } @@ -297,6 +305,7 @@ impl<'cfg> ControlFlowGraphNode<'cfg> { struct_field_name, .. } => Some(struct_field_name.span()), ControlFlowGraphNode::StorageField { field_name } => Some(field_name.span()), + ControlFlowGraphNode::FunctionParameter { param_name, .. } => Some(param_name.span()), } } } diff --git a/sway-lib-core/src/never.sw b/sway-lib-core/src/never.sw index 6bcbc798117..6c1a0c2c748 100644 --- a/sway-lib-core/src/never.sw +++ b/sway-lib-core/src/never.sw @@ -50,16 +50,16 @@ impl Not for Never { } impl Eq for Never { - fn eq(self, other: Self) -> bool { + fn eq(self, _other: Self) -> bool { self } } impl Ord for Never { - fn gt(self, other: Self) -> bool { + fn gt(self, _other: Self) -> bool { self } - fn lt(self, other: Self) -> bool { + fn lt(self, _other: Self) -> bool { self } } diff --git a/sway-lib-std/src/tx.sw b/sway-lib-std/src/tx.sw index 15223961b3e..f6a01534c94 100644 --- a/sway-lib-std/src/tx.sw +++ b/sway-lib-std/src/tx.sw @@ -111,7 +111,7 @@ pub fn tx_witnesses_count() -> u64 { // Get a pointer to the witness at index `index` for either `tx_type` /// (transaction-script or transaction-create). -pub fn tx_witness_pointer(index: u64) -> u64 { +pub fn tx_witness_pointer(_index: u64) -> u64 { match tx_type() { Transaction::Script => __gtf::(0, GTF_SCRIPT_WITNESS_AT_INDEX), Transaction::Create => __gtf::(0, GTF_CREATE_WITNESS_AT_INDEX), diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/simple_generics/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/simple_generics/test.toml index 8f91dee3158..ee35e906c19 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/simple_generics/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/simple_generics/test.toml @@ -1,5 +1,9 @@ category = "fail" +# check: fn generic(input: T) -> T { +# nextln: $()This declaration is never used. +# nextln: $()do_it(input) + # check: do_it(input) # nextln: $()Mismatched types. # nextln: $()expected: u64 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.lock new file mode 100644 index 00000000000..da6aa03877a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = 'func_param' +source = 'member' diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.toml new file mode 100644 index 00000000000..e237b841359 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "func_param" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/src/main.sw new file mode 100644 index 00000000000..3db214ce93e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/src/main.sw @@ -0,0 +1,38 @@ +script; + + +// Param `i` should have no warnings as `d` is still using it +fn unused_fn(i: u64) { + let d = i; +} + +fn f(i: u64) { +} + +struct A {} + +impl A { + fn g(i: u64) { + } + + fn h(self, i: u64) { + } +} + +fn i(_p: u64) { +} + +fn j(ref mut foo: u64) { + foo = 42; +} + +fn main() { + f(42); + A::g(42); + let a = A{}; + a.h(42); + i(42); + + let mut foo = 42; + j(foo); +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/test.toml new file mode 100644 index 00000000000..62a63369f03 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/test.toml @@ -0,0 +1,19 @@ +category = "compile" + +# check: $()fn unused_fn(i: u64) { +# nextln: $()This function is never called. +# nextln: $()let d = i; + +# check: $()let d = i; +# nextln: $()This declaration is never used. + +# check: $()fn f(i: u64) { +# nextln: $()This declaration is never used. + +# check: $()fn g(i: u64) { +# nextln: $()This declaration is never used. + +# check: $()fn h(self, i: u64) { +# nextln: $()This declaration is never used. + +expected_warnings = 5 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/generic_fn_trait_contraint/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/generic_fn_trait_contraint/src/main.sw index c39ebe16f31..3a43d10e53c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/generic_fn_trait_contraint/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/generic_fn_trait_contraint/src/main.sw @@ -5,7 +5,7 @@ pub trait MyEq { } impl MyEq for u64 { - fn my_eq(self, other: Self) { + fn my_eq(self, _other: Self) { } } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/main.sw index c179096b756..6e5ff7fdc12 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/main.sw @@ -8,7 +8,7 @@ struct Bar { value: u64 } -fn internal_fn(s: Bar) { +fn internal_fn(_s: Bar) { } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/utils.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/utils.sw index 8d962535a8d..6f7e3f6e457 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/utils.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/utils.sw @@ -4,6 +4,6 @@ pub struct Foo { value: u64 } -pub fn external_fn(s: Foo) { +pub fn external_fn(_s: Foo) { } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/utils.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/utils.sw index 0d0bc90114c..a0c6e8b379f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/utils.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/utils.sw @@ -2,6 +2,6 @@ library; use ::r#trait::Trait; -pub fn uses_trait(a: T) where T: Trait { +pub fn uses_trait(_a: T) where T: Trait { } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/basic_func_decl/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/basic_func_decl/src/main.sw index a134070432b..a25cdb4948a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/basic_func_decl/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/basic_func_decl/src/main.sw @@ -41,6 +41,6 @@ struct MyStructWithEnum { b: MyEnum, } -fn eight_args(a: MyStruct, b: MyEnum, c: MyStructWithEnum, d: str[5], e: bool, f: u64, g: u8, h: b256) { +fn eight_args(_a: MyStruct, _b: MyEnum, _c: MyStructWithEnum, _d: str[5], _e: bool, _f: u64, _g: u8, _h: b256) { return; } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_functions/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_functions/src/main.sw index 1149c857de9..b483a38d634 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_functions/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_functions/src/main.sw @@ -4,18 +4,18 @@ fn identity(x: T) -> T { x } -fn two_generics(a: A, b: B) -> B { +fn two_generics(_a: A, b: B) -> B { b } -fn three_generics(a: A, b: B, c: C) -> B { +fn three_generics(a: A, b: B, _c: C) -> B { let _a: A = a; b } fn main() -> bool { let a: bool = identity(true); - let b: u32 = identity(10); + let _b: u32 = identity(10); let _c: u64 = identity(42); let _e: str[3] = identity("foo"); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/utils.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/utils.sw index a01142f2add..5fad4c603b3 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/utils.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/utils.sw @@ -23,7 +23,7 @@ pub trait TryFrom { } impl TryFrom for u64 { - fn try_from(b: u64) -> Option { + fn try_from(_b: u64) -> Option { Option::Some(42) } } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/is_reference_type/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/is_reference_type/src/main.sw index 0fa7096d34f..79b5b48c495 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/is_reference_type/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/is_reference_type/src/main.sw @@ -8,7 +8,7 @@ enum E { Variant: (), } -fn arg_is_reference(a: T) -> bool { +fn arg_is_reference(_a: T) -> bool { __is_reference_type::() } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/left_to_right_func_args_evaluation/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/left_to_right_func_args_evaluation/src/main.sw index e7ffd304753..846e3f228d6 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/left_to_right_func_args_evaluation/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/left_to_right_func_args_evaluation/src/main.sw @@ -1,7 +1,7 @@ script; // This tests function, tuple, struct arguments are evaluated from left to right -fn func(a: u64, b: u64, c: u64, d: u64) -> u64 { +fn func(_a: u64, _b: u64, _c: u64, d: u64) -> u64 { d } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_inside_generic_functions/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_inside_generic_functions/src/main.sw index cf4e80aaeac..4b7a27a7d0f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_inside_generic_functions/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_inside_generic_functions/src/main.sw @@ -27,7 +27,7 @@ fn first_match(value: C) -> u64 { } } -fn third_if(value: D) -> u8 { +fn third_if(_value: D) -> u8 { if true { 5u8 } else { @@ -55,7 +55,7 @@ fn first_if(value: F) -> u64 { } } -fn double_double(first: Y, second: Z) -> Z { +fn double_double(_first: Y, second: Z) -> Z { second } @@ -69,7 +69,7 @@ fn generic_match(value: G) -> u64 { } } -fn generic_if(value: H) -> u64 { +fn generic_if(_value: H) -> u64 { if true { 3u64 } else { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/where_clause_functions/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/where_clause_functions/src/main.sw index 0f57b356f65..0eee40ca912 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/where_clause_functions/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/where_clause_functions/src/main.sw @@ -42,7 +42,7 @@ fn add_points(a: MyPoint, b: MyPoint) -> MyPoint where T: MyAdd { } } -fn add_points2(a: MyPoint, b: MyPoint) -> MyPoint where T: MyAdd, F: MyAdd { +fn add_points2(_a: MyPoint, b: MyPoint) -> MyPoint where T: MyAdd, F: MyAdd { MyPoint { x: b.x.my_add(b.x), y: b.y.my_add(b.y), @@ -84,7 +84,7 @@ fn mul_points(a: MyPoint, b: MyPoint) -> MyPoint where T: MyMul { } } -fn mul_points2(a: MyPoint, b: MyPoint) -> MyPoint where T: MyMul, F: MyMul { +fn mul_points2(_a: MyPoint, b: MyPoint) -> MyPoint where T: MyMul, F: MyMul { MyPoint { x: b.x.my_mul(b.x), y: b.y.my_mul(b.y), @@ -98,7 +98,7 @@ fn do_math(a: MyPoint, b: MyPoint) -> MyPoint where T: MyAdd + MyMul } } -fn do_math2(a: MyPoint, b: MyPoint) -> MyPoint where T: MyAdd + MyMul, F: MyMul + MyAdd { +fn do_math2(_a: MyPoint, b: MyPoint) -> MyPoint where T: MyAdd + MyMul, F: MyMul + MyAdd { MyPoint { x: b.x.my_add(b.x), y: b.y.my_mul(b.y), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_in_func_app-2/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_in_func_app-2/src/main.sw index 84ae073ece9..2c6a8059a80 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_in_func_app-2/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_in_func_app-2/src/main.sw @@ -7,7 +7,7 @@ abi TestAbi { fn deposit(amount: u64); } -fn pure_function(x: u64, y: u64) -> u64 { +fn pure_function(x: u64, _y: u64) -> u64 { x } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_in_func_app-3/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_in_func_app-3/src/main.sw index fde62aad288..adcf72a74f5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_in_func_app-3/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_in_func_app-3/src/main.sw @@ -8,7 +8,7 @@ abi TestAbi { } #[storage(write)] -fn do_something(x: u64) { +fn do_something(_x: u64) { // effect store(0x3dba0a4455b598b7655a7fb430883d96c9527ef275b49739e7b0ad12f8280eae, ()); } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_more_complex_logic/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_more_complex_logic/src/main.sw index 7ca4a1807e3..94a7c7ace3a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_more_complex_logic/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/static_analysis/cei_pattern_violation_more_complex_logic/src/main.sw @@ -47,7 +47,7 @@ pub fn transfer_nft(asset: u64, from: Identity, to: Identity) { impl EnglishAuction for Contract { #[storage(read, write)] - fn bid(auction_id: u64, bid_asset: AuctionAsset) { + fn bid(auction_id: u64, _bid_asset: AuctionAsset) { let auction = storage.auctions.get(auction_id); require(auction.is_some(), 42); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/intrinsics/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/intrinsics/src/main.sw index 903f4780d80..086d78a94cf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/intrinsics/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/intrinsics/src/main.sw @@ -6,7 +6,7 @@ struct TestStruct { field_1: bool, field_2: u64, } -fn is_ref_type(param: T) -> bool { +fn is_ref_type(_param: T) -> bool { is_reference_type::() } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_generic_types/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_generic_types/json_abi_oracle.json index ef70aa06893..1ecc0d70b0e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_generic_types/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_generic_types/json_abi_oracle.json @@ -5,7 +5,7 @@ "attributes": null, "inputs": [ { - "name": "arg1", + "name": "_arg1", "type": 22, "typeArguments": [ { @@ -21,17 +21,17 @@ ] }, { - "name": "arg2", + "name": "_arg2", "type": 6, "typeArguments": null }, { - "name": "arg3", + "name": "_arg3", "type": 1, "typeArguments": null }, { - "name": "arg4", + "name": "_arg4", "type": 21, "typeArguments": null } @@ -47,7 +47,7 @@ "attributes": null, "inputs": [ { - "name": "arg", + "name": "_arg", "type": 20, "typeArguments": [ { @@ -74,7 +74,7 @@ "attributes": null, "inputs": [ { - "name": "arg", + "name": "_arg", "type": 23, "typeArguments": [ { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_generic_types/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_generic_types/src/main.sw index 560de0a168b..a943164e7c5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_generic_types/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_generic_types/src/main.sw @@ -39,15 +39,15 @@ abi MyContract { impl MyContract for Contract { fn complex_function( - arg1: MyStruct<[b256; 3], u8>, - arg2: [MyStruct; 4], - arg3: (str[5], bool), - arg4: MyOtherStruct, + _arg1: MyStruct<[b256; 3], u8>, + _arg2: [MyStruct; 4], + _arg3: (str[5], bool), + _arg4: MyOtherStruct, ) -> str[6] { "fuel42" } - fn take_generic_array(arg: MyArrayStruct) -> u64 { + fn take_generic_array(_arg: MyArrayStruct) -> u64 { 0 } - fn take_generic_struct_containing_tuple(arg: MyStructWithTuple, u16, u32>) {} + fn take_generic_struct_containing_tuple(_arg: MyStructWithTuple, u16, u32>) {} } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/json_abi_oracle.json index 8ca5da046c7..d5deb14b893 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/json_abi_oracle.json @@ -5,17 +5,17 @@ "attributes": null, "inputs": [ { - "name": "arg1", + "name": "_arg1", "type": 4, "typeArguments": null }, { - "name": "arg2", + "name": "_arg2", "type": 6, "typeArguments": null }, { - "name": "arg3", + "name": "_arg3", "type": 1, "typeArguments": [ { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/main.sw index 5a139749fb5..32fdbbcb7c6 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/main.sw @@ -16,9 +16,9 @@ abi MyContract { impl MyContract for Contract { fn function( - arg1: MyStruct1, - arg2: MyStruct2, - arg3: Option, + _arg1: MyStruct1, + _arg2: MyStruct2, + _arg3: Option, ) -> str[6] { "fuel42" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/json_abi_oracle.json index 9a5b2671de7..57dd94d5065 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/json_abi_oracle.json @@ -5,7 +5,7 @@ "attributes": null, "inputs": [ { - "name": "param", + "name": "_param", "type": 1, "typeArguments": null } @@ -21,7 +21,7 @@ "attributes": null, "inputs": [ { - "name": "param", + "name": "_param", "type": 2, "typeArguments": null } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/src/main.sw index 92392d9b30e..0971fdcb79b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/src/main.sw @@ -3,11 +3,11 @@ contract; use abi_with_tuples::{MyContract, Person, Location}; impl MyContract for Contract { - fn bug1(param: (Person, u64)) -> bool { + fn bug1(_param: (Person, u64)) -> bool { true } - fn bug2(param: (Location, u64)) -> bool { + fn bug2(_param: (Location, u64)) -> bool { true } }