diff --git a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs index 9f519f8cb4b..067bcdea887 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs @@ -118,7 +118,7 @@ fn type_check_not( let t = engines.te().get(operand_expr.return_type); match t { - TypeInfo::B256 | TypeInfo::UnsignedInteger(_) => Ok(( + TypeInfo::B256 | TypeInfo::UnsignedInteger(_) | TypeInfo::Numeric => Ok(( ty::TyIntrinsicFunctionKind { kind, arguments: vec![operand_expr], @@ -1008,7 +1008,7 @@ fn type_check_bitwise_binary_op( let t = engines.te().get(lhs.return_type); match t { - TypeInfo::B256 | TypeInfo::UnsignedInteger(_) => Ok(( + TypeInfo::B256 | TypeInfo::UnsignedInteger(_) | TypeInfo::Numeric => Ok(( ty::TyIntrinsicFunctionKind { kind, arguments: vec![lhs, rhs], @@ -1081,7 +1081,7 @@ fn type_check_shift_binary_op( let t = engines.te().get(lhs.return_type); match t { - TypeInfo::B256 | TypeInfo::UnsignedInteger(_) => Ok(( + TypeInfo::B256 | TypeInfo::UnsignedInteger(_) | TypeInfo::Numeric => Ok(( ty::TyIntrinsicFunctionKind { kind, arguments: vec![lhs, rhs], diff --git a/sway-ir/src/optimize/misc_demotion.rs b/sway-ir/src/optimize/misc_demotion.rs index 614dee77a87..da5a4d447fa 100644 --- a/sway-ir/src/optimize/misc_demotion.rs +++ b/sway-ir/src/optimize/misc_demotion.rs @@ -345,7 +345,8 @@ fn wide_binary_op_demotion(context: &mut Context, function: Function) -> Result< op: B::Add | B::Sub | B::Mul | B::Div | B::Mod | B::And | B::Or | B::Xor, arg1, arg2, - } = instr_val.get_instruction(context)? else { + } = instr_val.get_instruction(context)? + else { return None; }; @@ -573,19 +574,30 @@ fn wide_cmp_demotion(context: &mut Context, function: Function) -> Result Some((block, instr_val)), - (Some(arg1_type), Some(arg2_type)) if arg1_type.is_b256(context) && arg2_type.is_b256(context) => Some((block, instr_val)), - _ => None + (Some(arg1_type), Some(arg2_type)) + if arg1_type.is_uint_of(context, 256) && arg2_type.is_uint_of(context, 256) => + { + Some((block, instr_val)) + } + (Some(arg1_type), Some(arg2_type)) + if arg1_type.is_b256(context) && arg2_type.is_b256(context) => + { + Some((block, instr_val)) + } + _ => None, } }) .collect::>(); @@ -726,12 +738,15 @@ fn wide_unary_op_demotion(context: &mut Context, function: Function) -> Result Some((block, instr_val)), + Some(t) if t.is_uint_of(context, 256) || t.is_b256(context) => { + Some((block, instr_val)) + } _ => None, } }) @@ -848,21 +863,30 @@ fn wide_shift_op_demotion(context: &mut Context, function: Function) -> Result Some((block, instr_val)), + if arg1_type.is_uint_of(context, 256) && arg2_type.is_uint64(context) => + { + Some((block, instr_val)) + } (Some(arg1_type), Some(arg2_type)) - if arg1_type.is_b256(context) && arg2_type.is_uint64(context) => Some((block, instr_val)), - _ => None + if arg1_type.is_b256(context) && arg2_type.is_uint64(context) => + { + Some((block, instr_val)) + } + _ => None, } }) .collect::>(); diff --git a/sway-ir/src/verify.rs b/sway-ir/src/verify.rs index d83b8f380af..82b88cfb6b9 100644 --- a/sway-ir/src/verify.rs +++ b/sway-ir/src/verify.rs @@ -407,7 +407,6 @@ impl<'a, 'eng> InstructionVerifier<'a, 'eng> { | BinaryOpKind::Or | BinaryOpKind::Xor | BinaryOpKind::Mod => { - dbg!(1); if !arg1_ty.is_ptr(self.context) || !arg2_ty.is_ptr(self.context) || !result_ty.is_ptr(self.context) @@ -472,7 +471,7 @@ impl<'a, 'eng> InstructionVerifier<'a, 'eng> { } BinaryOpKind::And | BinaryOpKind::Or | BinaryOpKind::Xor => { if !arg1_ty.eq(self.context, &arg2_ty) - || (!arg1_ty.is_uint(self.context) && !arg1_ty.is_b256(self.context)) + || !(arg1_ty.is_uint(self.context) || arg1_ty.is_b256(self.context)) { return Err(IrError::VerifyBinaryOpIncorrectArgType); } diff --git a/sway-types/src/b256.rs b/sway-types/src/b256.rs deleted file mode 100644 index 8fe98da2368..00000000000 --- a/sway-types/src/b256.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)] -pub struct B256([u64; 32]); - -impl B256 { - pub fn new(bytes: [u64; 32]) -> Self { - Self(bytes) - } -} diff --git a/sway-types/src/lib.rs b/sway-types/src/lib.rs index 3b264ca56ac..4e6b9d6a42d 100644 --- a/sway-types/src/lib.rs +++ b/sway-types/src/lib.rs @@ -8,7 +8,6 @@ use std::{io, iter, slice}; pub mod constants; -pub mod b256; pub mod ident; pub mod u256; pub use ident::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle.json index ce91a72dfde..fbb1defe2a9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle.json @@ -7,7 +7,7 @@ "typeArguments": null }, "name": "C0", - "offset": 8524 + "offset": 7308 }, { "configurableType": { @@ -16,7 +16,7 @@ "typeArguments": null }, "name": "C1", - "offset": 8532 + "offset": 7316 }, { "configurableType": { @@ -25,7 +25,7 @@ "typeArguments": null }, "name": "C2", - "offset": 8548 + "offset": 7332 }, { "configurableType": { @@ -34,7 +34,7 @@ "typeArguments": [] }, "name": "C3", - "offset": 8580 + "offset": 7364 }, { "configurableType": { @@ -43,7 +43,7 @@ "typeArguments": [] }, "name": "C4", - "offset": 8596 + "offset": 7380 }, { "configurableType": { @@ -52,7 +52,7 @@ "typeArguments": [] }, "name": "C5", - "offset": 8612 + "offset": 7396 }, { "configurableType": { @@ -61,7 +61,7 @@ "typeArguments": null }, "name": "C6", - "offset": 8628 + "offset": 7412 }, { "configurableType": { @@ -70,7 +70,7 @@ "typeArguments": null }, "name": "C7", - "offset": 8644 + "offset": 7428 }, { "configurableType": { @@ -79,7 +79,7 @@ "typeArguments": null }, "name": "C9", - "offset": 8692 + "offset": 7476 } ], "functions": [ diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw index 8b8c6b2a2ba..65810a9a7bb 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw @@ -2,7 +2,7 @@ script; use basic_storage_abi::{BasicStorage, Quad}; fn main() -> u64 { - let addr = abi(BasicStorage, 0xb870f1a5893135ee3d0d688f57577837050bb720452b7afe67caca22e6984127); + let addr = abi(BasicStorage, 0x3069f32c2759615911b885900468c1044ff4e4545de12921d82f49f7158cf50c); let key = 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; let value = 4242;