Skip to content

Commit

Permalink
fix sotrage offset issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Oct 17, 2023
1 parent dcc7897 commit 636eaa5
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 164 deletions.
3 changes: 2 additions & 1 deletion sway-core/src/asm_generation/fuel/data_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl Entry {
pub(crate) fn equiv(&self, entry: &Entry) -> bool {
fn equiv_data(lhs: &Datum, rhs: &Datum) -> bool {
match (lhs, rhs) {
(Datum::Byte(l), Datum::Byte(r)) => l == r,
(Datum::Word(l), Datum::Word(r)) => l == r,
(Datum::ByteArray(l), Datum::ByteArray(r)) => l == r,

Expand Down Expand Up @@ -292,7 +293,7 @@ impl DataSection {
.map(|entry| entry.has_copy_type())
}

/// Returns whether a specific [DataId] value has a byte entry.
/// Returns whether a specific [DataId] value is a byte entry.
pub(crate) fn is_byte(&self, id: &DataId) -> Option<bool> {
self.value_pairs
.get(id.0 as usize)
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/ir_generation/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn convert_resolved_type(
}

Ok(match ast_type {
// All integers are `u64`, see comment in convert_literal_to_value() above.
// See comment in convert_literal_to_value() above.
TypeInfo::UnsignedInteger(IntegerBits::V256) => Type::get_uint256(context),
TypeInfo::UnsignedInteger(IntegerBits::Eight) => Type::get_uint8(context),
TypeInfo::UnsignedInteger(IntegerBits::Sixteen)
Expand Down
5 changes: 4 additions & 1 deletion sway-core/src/ir_generation/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2685,7 +2685,10 @@ impl<'eng> FnCompiler<'eng> {
ty_at_idx = field_type;
break;
}
offset += ir_type_size_in_bytes(context, &field_type);
offset += size_bytes_round_up_to_word_alignment!(ir_type_size_in_bytes(
context,
&field_type
));
}
}
Ok(offset / 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,7 @@ impl ty::TyExpression {
});
};

// start each element with the known array element type
let initial_type = match ctx.engines().te().get(ctx.type_annotation()) {
TypeInfo::Array(element_type, _) => ctx.engines().te().get(element_type.type_id),
_ => TypeInfo::Unknown,
Expand All @@ -1720,27 +1721,6 @@ impl ty::TyExpression {
.collect();

let elem_type = typed_contents[0].return_type;
// for typed_elem in &typed_contents[1..] {
// let h = Handler::default();
// ctx.by_ref()
// .with_type_annotation(elem_type)
// .unify_with_type_annotation(&h, typed_elem.return_type, &typed_elem.span);

// let (new_errors, new_warnings) = h.consume();
// let no_warnings = new_warnings.is_empty();
// let no_errors = new_errors.is_empty();
// for warn in new_warnings {
// handler.emit_warn(warn);
// }
// for err in new_errors {
// handler.emit_err(err);
// }
// // In both cases, if there are warnings or errors then break here, since we don't
// // need to spam type errors for every element once we have one.
// if !no_warnings && !no_errors {
// break;
// }
// }

let array_count = typed_contents.len();
Ok(ty::TyExpression {
Expand Down Expand Up @@ -2186,7 +2166,7 @@ mod tests {
let handler = Handler::default();
let _comp_res = do_type_check_for_boolx2(&handler, expr);
let (errors, _warnings) = handler.consume();
dbg!(&errors);

assert!(errors.len() == 2);
assert!(matches!(&errors[0],
CompileError::TypeError(TypeError::MismatchedType {
Expand Down
10 changes: 5 additions & 5 deletions sway-lib-std/src/array_conversions/u16.sw
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ impl u16 {

asm(input: self, off: 0xFF, i: 0x8, output: output, r1) {
and r1 input off;
sw output r1 i0;
sb output r1 i0;

srl r1 input i;
and r1 r1 off;
sw output r1 i1;
sb output r1 i1;

output: [u8; 2]
}
Expand Down Expand Up @@ -85,10 +85,10 @@ impl u16 {

asm(input: self, off: 0xFF, i: 0x8, output: output, r1) {
srl r1 input i;
sw output r1 i0;
sb output r1 i0;

and r1 input off;
sw output r1 i1;
sb output r1 i1;

output: [u8; 2]
}
Expand All @@ -102,7 +102,7 @@ impl u16 {
///
/// # Returns
///
/// * [u32] - The resulting `u16` value.
/// * [u16] - The resulting `u16` value.
///
/// # Examples
///
Expand Down
16 changes: 8 additions & 8 deletions sway-lib-std/src/array_conversions/u32.sw
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ impl u32 {

asm(input: self, off: 0xFF, i: 0x8, j: 0x10, k: 0x18, output: output, r1) {
and r1 input off;
sw output r1 i0;
sb output r1 i0;

srl r1 input i;
and r1 r1 off;
sw output r1 i1;
sb output r1 i1;

srl r1 input j;
and r1 r1 off;
sw output r1 i2;
sb output r1 i2;

srl r1 input k;
and r1 r1 off;
sw output r1 i3;
sb output r1 i3;

output: [u8; 4]
}
Expand Down Expand Up @@ -102,18 +102,18 @@ impl u32 {
asm(input: self, off: 0xFF, i: 0x8, j: 0x10, k: 0x18, output: output, r1) {
srl r1 input k;
and r1 r1 off;
sw output r1 i0;
sb output r1 i0;

srl r1 input j;
and r1 r1 off;
sw output r1 i1;
sb output r1 i1;

srl r1 input i;
and r1 r1 off;
sw output r1 i2;
sb output r1 i2;

and r1 input off;
sw output r1 i3;
sb output r1 i3;

output: [u8; 4]
}
Expand Down
32 changes: 16 additions & 16 deletions sway-lib-std/src/array_conversions/u64.sw
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,35 @@ impl u64 {

asm(input: self, off: 0xFF, i: 0x8, j: 0x10, k: 0x18, l: 0x20, m: 0x28, n: 0x30, o: 0x38, output: output, r1) {
and r1 input off;
sw output r1 i0;
sb output r1 i0;

srl r1 input i;
and r1 r1 off;
sw output r1 i1;
sb output r1 i1;

srl r1 input j;
and r1 r1 off;
sw output r1 i2;
sb output r1 i2;

srl r1 input k;
and r1 r1 off;
sw output r1 i3;
sb output r1 i3;

srl r1 input l;
and r1 r1 off;
sw output r1 i4;
sb output r1 i4;

srl r1 input m;
and r1 r1 off;
sw output r1 i5;
sb output r1 i5;

srl r1 input n;
and r1 r1 off;
sw output r1 i6;
sb output r1 i6;

srl r1 input o;
and r1 r1 off;
sw output r1 i7;
sb output r1 i7;

output: [u8; 8]
}
Expand Down Expand Up @@ -143,35 +143,35 @@ impl u64 {

asm(input: self, off: 0xFF, i: 0x8, j: 0x10, k: 0x18, l: 0x20, m: 0x28, n: 0x30, o: 0x38, output: output, r1) {
and r1 input off;
sw output r1 i7;
sb output r1 i7;

srl r1 input i;
and r1 r1 off;
sw output r1 i6;
sb output r1 i6;

srl r1 input j;
and r1 r1 off;
sw output r1 i5;
sb output r1 i5;

srl r1 input k;
and r1 r1 off;
sw output r1 i4;
sb output r1 i4;

srl r1 input l;
and r1 r1 off;
sw output r1 i3;
sb output r1 i3;

srl r1 input m;
and r1 r1 off;
sw output r1 i2;
sb output r1 i2;

srl r1 input n;
and r1 r1 off;
sw output r1 i1;
sb output r1 i1;

srl r1 input o;
and r1 r1 off;
sw output r1 i0;
sb output r1 i0;

output: [u8; 8]
}
Expand Down
7 changes: 0 additions & 7 deletions test/src/sdk-harness/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions test/src/sdk-harness/test_projects/hashing/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ impl MyContract for Contract {
}

fn keccak256_u8(value: u8) -> b256 {
log(value);
keccak256(value)
}

Expand Down Expand Up @@ -178,8 +177,6 @@ impl MyContract for Contract {
}

fn keccak256_tuple(value: (bool, u64)) -> b256 {
log(value.0);
log(value.1);
keccak256(value)
}

Expand Down
3 changes: 0 additions & 3 deletions test/src/sdk-harness/test_projects/messages/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ impl TestFuelCoin for Contract {
send_typed_message(recipient, msg_data, coins);
}
fn send_typed_message_string(recipient: b256, msg_data: str[4], coins: u64) {
log(recipient);
log(msg_data);
log(coins);
send_typed_message(recipient, msg_data, coins);
}
}
42 changes: 21 additions & 21 deletions test/src/sdk-harness/test_projects/parsing_logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,36 +106,36 @@ async fn test_parse_logs_generic_types() -> Result<()> {
let contract_methods = instance.methods();
let response = contract_methods.produce_logs_generic_types().call().await?;

// let log_struct = response.decode_logs_with_type::<StructWithGeneric<[_; 3]>>()?;
let log_struct = response.decode_logs_with_type::<StructWithGeneric<[_; 3]>>()?;
let log_enum = response.decode_logs_with_type::<EnumWithGeneric<[_; 3]>>()?;
// let log_struct_nested =
// response.decode_logs_with_type::<StructWithNestedGeneric<StructWithGeneric<[_; 3]>>>()?;
// let log_struct_deeply_nested = response.decode_logs_with_type::<StructDeeplyNestedGeneric<
// StructWithNestedGeneric<StructWithGeneric<[_; 3]>>,
// >>()?;
let log_struct_nested =
response.decode_logs_with_type::<StructWithNestedGeneric<StructWithGeneric<[_; 3]>>>()?;
let log_struct_deeply_nested = response.decode_logs_with_type::<StructDeeplyNestedGeneric<
StructWithNestedGeneric<StructWithGeneric<[_; 3]>>,
>>()?;

let l = [1u8, 2u8, 3u8];
let expected_struct = StructWithGeneric {
field_1: l,
field_2: 64,
};
let expected_enum = EnumWithGeneric::VariantOne(l);
// let expected_nested_struct = StructWithNestedGeneric {
// field_1: expected_struct.clone(),
// field_2: 64,
// };
// let expected_deeply_nested_struct = StructDeeplyNestedGeneric {
// field_1: expected_nested_struct.clone(),
// field_2: 64,
// };

// assert_eq!(log_struct, vec![expected_struct]);
let expected_nested_struct = StructWithNestedGeneric {
field_1: expected_struct.clone(),
field_2: 64,
};
let expected_deeply_nested_struct = StructDeeplyNestedGeneric {
field_1: expected_nested_struct.clone(),
field_2: 64,
};

assert_eq!(log_struct, vec![expected_struct]);
assert_eq!(log_enum, vec![expected_enum]);
// assert_eq!(log_struct_nested, vec![expected_nested_struct]);
// assert_eq!(
// log_struct_deeply_nested,
// vec![expected_deeply_nested_struct]
// );
assert_eq!(log_struct_nested, vec![expected_nested_struct]);
assert_eq!(
log_struct_deeply_nested,
vec![expected_deeply_nested_struct]
);

Ok(())
}
Expand Down
Loading

0 comments on commit 636eaa5

Please sign in to comment.