diff --git a/examples/converting_types/src/to_u16.sw b/examples/converting_types/src/to_u16.sw index 69d86a2d7d4..4e5a330b4c4 100644 --- a/examples/converting_types/src/to_u16.sw +++ b/examples/converting_types/src/to_u16.sw @@ -14,10 +14,10 @@ pub fn convert_uint_to_u16() { let u16_from_u8: u16 = u8_1.as_u16(); - let u16_from_u32_1: Option = u32_1.try_as_u16(); + let u16_from_u32_1: Option = u32_1.try_into(); let u16_from_u32_2: Option = >::try_from(u32_1); - let u16_from_u64_1: Option = u64_1.try_as_u16(); + let u16_from_u64_1: Option = u64_1.try_into(); let u16_from_u64_2: Option = >::try_from(u64_1); let u16_from_u256: Option = >::try_from(u256_1); diff --git a/examples/converting_types/src/to_u32.sw b/examples/converting_types/src/to_u32.sw index dfa2d35fa08..f7c86994c00 100644 --- a/examples/converting_types/src/to_u32.sw +++ b/examples/converting_types/src/to_u32.sw @@ -16,7 +16,7 @@ pub fn convert_uint_to_u32() { let u32_from_u16: u32 = u16_1.as_u32(); - let u32_from_u64_1: Option = u64_1.try_as_u32(); + let u32_from_u64_1: Option = u64_1.try_into(); let u32_from_u64_2: Option = >::try_from(u64_1); let u32_from_u256: Option = >::try_from(u256_1); diff --git a/examples/converting_types/src/to_u8.sw b/examples/converting_types/src/to_u8.sw index 1c320a45d73..0b98733d4d7 100644 --- a/examples/converting_types/src/to_u8.sw +++ b/examples/converting_types/src/to_u8.sw @@ -12,13 +12,13 @@ pub fn convert_uint_to_u8() { let u64_1: u64 = 2; let u256_1: u256 = 0x0000000000000000000000000000000000000000000000000000000000000002u256; - let u8_from_u16_1: Option = u16_1.try_as_u8(); + let u8_from_u16_1: Option = u16_1.try_into(); let u8_from_u16_2: Option = >::try_from(u16_1); - let u8_from_u32_1: Option = u32_1.try_as_u8(); + let u8_from_u32_1: Option = u32_1.try_into(); let u8_from_u32_2: Option = >::try_from(u32_1); - let u8_from_u64_1: Option = u64_1.try_as_u8(); + let u8_from_u64_1: Option = u64_1.try_into(); let u8_from_u64_2: Option = >::try_from(u64_1); let u8_from_u256: Option = >::try_from(u256_1); diff --git a/sway-lib-std/src/primitive_conversions/u16.sw b/sway-lib-std/src/primitive_conversions/u16.sw index 9ea79166ca1..11755f989c3 100644 --- a/sway-lib-std/src/primitive_conversions/u16.sw +++ b/sway-lib-std/src/primitive_conversions/u16.sw @@ -4,18 +4,6 @@ use ::convert::{From, TryFrom}; use ::option::Option::{self, *}; use ::u128::U128; -impl u16 { - pub fn try_as_u8(self) -> Option { - if self <= u8::max().as_u16() { - Some(asm(input: self) { - input: u8 - }) - } else { - None - } - } -} - impl From for u16 { /// Casts a `u8` to a `u16`. /// diff --git a/sway-lib-std/src/primitive_conversions/u32.sw b/sway-lib-std/src/primitive_conversions/u32.sw index 5d34a275b7b..3c0e48e9b8c 100644 --- a/sway-lib-std/src/primitive_conversions/u32.sw +++ b/sway-lib-std/src/primitive_conversions/u32.sw @@ -4,28 +4,6 @@ use ::convert::{From, TryFrom}; use ::option::Option::{self, *}; use ::u128::U128; -impl u32 { - pub fn try_as_u8(self) -> Option { - if self <= u8::max().as_u32() { - Some(asm(input: self) { - input: u8 - }) - } else { - None - } - } - - pub fn try_as_u16(self) -> Option { - if self <= u16::max().as_u32() { - Some(asm(input: self) { - input: u16 - }) - } else { - None - } - } -} - impl From for u32 { /// Casts a `u8` to a `u32`. /// diff --git a/sway-lib-std/src/primitive_conversions/u64.sw b/sway-lib-std/src/primitive_conversions/u64.sw index 246066f4091..bd50b3d55ea 100644 --- a/sway-lib-std/src/primitive_conversions/u64.sw +++ b/sway-lib-std/src/primitive_conversions/u64.sw @@ -4,38 +4,6 @@ use ::convert::{TryFrom, TryInto, *}; use ::option::Option::{self, *}; use ::u128::U128; -impl u64 { - pub fn try_as_u8(self) -> Option { - if self <= u8::max().as_u64() { - Some(asm(input: self) { - input: u8 - }) - } else { - None - } - } - - pub fn try_as_u16(self) -> Option { - if self <= u16::max().as_u64() { - Some(asm(input: self) { - input: u16 - }) - } else { - None - } - } - - pub fn try_as_u32(self) -> Option { - if self <= u32::max().as_u64() { - Some(asm(input: self) { - input: u32 - }) - } else { - None - } - } -} - impl From for u64 { /// Casts a `u8` to a `u64`. /// diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/integer_type_inference/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/integer_type_inference/src/main.sw index f1d0fe1823b..485340346d6 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/integer_type_inference/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/integer_type_inference/src/main.sw @@ -79,9 +79,9 @@ fn main() { /* Make sure that the resulting types of variables are correct */ let x1: u8 = 4u8; - let x2: u8 = 4u16.try_as_u8().unwrap(); - let x3: u8 = 4u32.try_as_u8().unwrap(); - let x4: u8 = 4u64.try_as_u8().unwrap(); + let x2: u8 = 4u16.try_into().unwrap(); + let x3: u8 = 4u32.try_into().unwrap(); + let x4: u8 = 4u64.try_into().unwrap(); let x5: u8 = 4; let x6: Option = Option::Some(1); let x7: Option = OptionAlias::Some(1); @@ -89,15 +89,15 @@ fn main() { let y1: u16 = 4u8.as_u16(); let y2: u16 = 4u16; - let y3: u16 = 4u32.try_as_u16().unwrap(); - let y4: u16 = 4u64.try_as_u16().unwrap(); + let y3: u16 = 4u32.try_into().unwrap(); + let y4: u16 = 4u64.try_into().unwrap(); let y5: u16 = 4; let y6: Option = Option::Some(1); let z1: u32 = 4u8.as_u32(); let z2: u32 = 4u16.as_u32(); let z3: u32 = 4u32; - let z4: u32 = 4u64.try_as_u32().unwrap(); + let z4: u32 = 4u64.try_into().unwrap(); let z5: u32 = 4; let z6: Option = Option::Some(1); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/issue_1512_repro/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/issue_1512_repro/src/main.sw index a76cb9e624a..9b0c2db0d61 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/issue_1512_repro/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/issue_1512_repro/src/main.sw @@ -96,10 +96,10 @@ impl U128Duplicate { // Multiply two u64 values, producing a U128 pub fn mul64(a: u64, b: u64) -> U128Duplicate { // Split a and b into 32-bit lo and hi components - let a_lo = (a & 0x00000000ffffffff).try_as_u32().unwrap(); - let a_hi = (a >> 32).try_as_u32().unwrap(); - let b_lo = (b & 0x00000000ffffffff).try_as_u32().unwrap(); - let b_hi = (b >> 32).try_as_u32().unwrap(); + let a_lo: u32 = (a & 0x00000000ffffffff).try_into().unwrap(); + let a_hi: u32 = (a >> 32).try_into().unwrap(); + let b_lo: u32 = (b & 0x00000000ffffffff).try_into().unwrap(); + let b_hi: u32 = (b >> 32).try_into().unwrap(); // Calculate low, high, and mid multiplications let ab_hi = (a_hi * b_hi).as_u64(); @@ -110,9 +110,9 @@ pub fn mul64(a: u64, b: u64) -> U128Duplicate { // Calculate the carry bit let carry_bit = ( ( - ab_mid.try_as_u32().unwrap() + - ba_mid.try_as_u32().unwrap() + - (ab_lo >> 32).try_as_u32().unwrap() + ab_mid.try_into().unwrap() + + ba_mid.try_into().unwrap() + + (ab_lo >> 32).try_into().unwrap() ) >> 32 ).as_u64(); diff --git a/test/src/sdk-harness/test_projects/asset_ops/src/main.sw b/test/src/sdk-harness/test_projects/asset_ops/src/main.sw index 629110807c0..586e995f543 100644 --- a/test/src/sdk-harness/test_projects/asset_ops/src/main.sw +++ b/test/src/sdk-harness/test_projects/asset_ops/src/main.sw @@ -66,9 +66,9 @@ impl TestFuelCoin for Contract { fn send_message(recipient: b256, msg_data: Vec, coins: u64) { let mut data = Bytes::new(); if msg_data.len() > 0 { - data.push(msg_data.get(0).unwrap().try_as_u8().unwrap()); - data.push(msg_data.get(1).unwrap().try_as_u8().unwrap()); - data.push(msg_data.get(2).unwrap().try_as_u8().unwrap()); + data.push(msg_data.get(0).unwrap().try_into().unwrap()); + data.push(msg_data.get(1).unwrap().try_into().unwrap()); + data.push(msg_data.get(2).unwrap().try_into().unwrap()); } send_message(recipient, data, coins);