Skip to content

Commit

Permalink
Merge branch 'master' into IGI-111/forbid_bidi
Browse files Browse the repository at this point in the history
  • Loading branch information
IGI-111 authored Sep 26, 2023
2 parents 5b88441 + 8b3ed78 commit aed687c
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 40 deletions.
22 changes: 10 additions & 12 deletions sway-core/src/ir_generation/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ pub fn serialize_to_storage_slots(
),
)]
}
ConstantValue::U256(n) if ty.is_uint_of(context, 256) => {
ConstantValue::U256(b) if ty.is_uint_of(context, 256) => {
vec![StorageSlot::new(
get_storage_key(ix, indices),
Bytes32::new(n.to_be_bytes()),
Bytes32::new(b.to_be_bytes()),
)]
}
ConstantValue::B256(b) if ty.is_b256(context) => {
Expand Down Expand Up @@ -163,16 +163,14 @@ pub fn serialize_to_words(constant: &Constant, context: &Context, ty: &Type) ->
ConstantValue::Uint(n) if ty.is_uint(context) => {
vec![Bytes8::new(n.to_be_bytes())]
}
ConstantValue::U256(n) if ty.is_uint_of(context, 256) => n
.to_be_bytes()
.chunks_exact(8)
.map(|x| Bytes8::new(x.try_into().expect("unexpected array size")))
.collect(),
ConstantValue::B256(b) if ty.is_b256(context) => b
.to_be_bytes()
.chunks_exact(8)
.map(|x| Bytes8::new(x.try_into().expect("unexpected array size")))
.collect(),
ConstantValue::U256(b) if ty.is_uint_of(context, 256) => {
let b = b.to_be_bytes();
Vec::from_iter((0..4).map(|i| Bytes8::new(b[8 * i..8 * i + 8].try_into().unwrap())))
}
ConstantValue::B256(b) if ty.is_b256(context) => {
let b = b.to_be_bytes();
Vec::from_iter((0..4).map(|i| Bytes8::new(b[8 * i..8 * i + 8].try_into().unwrap())))
}
ConstantValue::String(s) if ty.is_string_array(context) => {
// Turn the bytes into serialized words (Bytes8).
let mut s = s.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,33 @@ fn type_check_trait_implementation(
let method = decl_engine.get_trait_fn(decl_ref);
let name = method.name.clone();
method_checklist.insert(name.clone(), method);
interface_item_refs.insert((name, self_type), item.clone());

// After monomorphization (and typechecking trait implementation
// works on a monomorphized version of a trait declaration), the
// newly produced [decl_id]s for interface methods can only be
// traced back to the original (non-monomorphized) trait
// declaration, which means that during [decl_id] substitutions
// of trait interface dummy functions for the corresponding
// interface method _implementations_, we need to refer to the
// original [decl_id]s of the non-monomorphized trait
// declaration.
let interface_item_parents = decl_engine.find_all_parents(engines, decl_ref.id());
match interface_item_parents.len() {
0 => { interface_item_refs.insert((name, self_type), item.clone()); },
1 => match interface_item_parents[0] {
AssociatedItemDeclId::TraitFn(parent_decl_id) => {
let parent_interface_item =
TyTraitInterfaceItem::TraitFn(DeclRef::new(name.clone(), parent_decl_id, decl_ref.span()));
interface_item_refs.insert((name, self_type), parent_interface_item);
}
_ => return Err(handler.emit_err(CompileError::Internal(
"A trait interface method's parent is expected to be another trait interface method",
name.span())))
}
_ => return Err(handler.emit_err(CompileError::Internal(
"A trait interface method is expected to have zero parents or one parent in the Declaration Engine",
name.span())))
}
}
TyTraitInterfaceItem::Constant(decl_ref) => {
let constant = decl_engine.get_constant(decl_ref);
Expand Down
5 changes: 4 additions & 1 deletion sway-core/src/type_system/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,10 @@ impl TypeInfo {
matches!(
self,
TypeInfo::Boolean
| TypeInfo::UnsignedInteger(_)
| TypeInfo::UnsignedInteger(IntegerBits::Eight)
| TypeInfo::UnsignedInteger(IntegerBits::Sixteen)
| TypeInfo::UnsignedInteger(IntegerBits::ThirtyTwo)
| TypeInfo::UnsignedInteger(IntegerBits::SixtyFour)
| TypeInfo::RawUntypedPtr
| TypeInfo::Numeric
) || self.is_unit()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "name_resolution_after_monomorphization"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "name_resolution_after_monomorphization"
implicit-std = false

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
script;

trait Eq<T> {
fn eq(self, other: Self) -> bool;
} {
fn neq(self, other: Self) -> bool {
__eq((self.eq(other)), false)
}
}

impl Eq<u64> for u64 {
fn eq(self, other: Self) -> bool {
__eq(self, other)
}
}

fn main() -> u64 {
// block const evaluation for `x` (it does not currently support asm-blocks)
let x = asm(x: 42u64) { x: u64 };
let y = 1u64;
if x.neq(y) {
2
} else {
101
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category = "run"
expected_result = { action = "return", value = 2 }
validate_abi = false
expected_warnings = 1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ script;
use basic_storage_abi::{BasicStorage, Quad};

fn main() -> u64 {
let addr = abi(BasicStorage, 0x2b30d419a93547d7dfd49efb63805fbaeefe72300c1d5028a313c998457c301d);

let addr = abi(BasicStorage, 0xf01862cb7b641c642815d71795e9ed7d7daf10158ef3a20e8e32045de97bee0a);
let key = 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
let value = 4242;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ script;
use increment_abi::Incrementor;

fn main() -> bool {
let the_abi = abi(Incrementor, 0x6c5be5390a29e256039d8a068bbaedddc04a9f95ad7da0c32c1394c1d9669657);
let the_abi = abi(Incrementor, 0xdeb965022530a5e114faa0a5214c7f7a19feba73c5218938615186c60feb9813);
the_abi.increment(5);
the_abi.increment(5);
let result = the_abi.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use storage_access_abi::*;
use std::hash::*;

fn main() -> bool {
let contract_id = 0xaaa573b599fe1519503e9d82cfc08c1fe7ef4ff2c136c178bc751165c8cb90b9;
let contract_id = 0xcbaac3d1670ec094eef042052fb49479f639d0120709ac58dad46a6b80cb6550;
let caller = abi(StorageAccess, contract_id);

// Test initializers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,44 +217,76 @@
"logId": 2,
"loggedType": {
"name": "",
"type": 8,
"type": 9,
"typeArguments": null
}
},
{
"logId": 3,
"loggedType": {
"name": "",
"type": 8,
"type": 9,
"typeArguments": null
}
},
{
"logId": 4,
"loggedType": {
"name": "",
"type": 1,
"type": 8,
"typeArguments": null
}
},
{
"logId": 5,
"loggedType": {
"name": "",
"type": 1,
"type": 8,
"typeArguments": null
}
},
{
"logId": 6,
"loggedType": {
"name": "",
"type": 1,
"type": 8,
"typeArguments": null
}
},
{
"logId": 7,
"loggedType": {
"name": "",
"type": 8,
"typeArguments": null
}
},
{
"logId": 8,
"loggedType": {
"name": "",
"type": 1,
"typeArguments": null
}
},
{
"logId": 9,
"loggedType": {
"name": "",
"type": 1,
"typeArguments": null
}
},
{
"logId": 10,
"loggedType": {
"name": "",
"type": 1,
"typeArguments": null
}
},
{
"logId": 11,
"loggedType": {
"name": "",
"type": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"key": "71217a24656901c411894bb65eb78a828dafa5a6844488ef5024eb5ac0cff79c",
"value": "0000000000000000000000000000000000000000000000000000000000000001"
"value": "0000000000000000000000000000000000000000000000000000000001234567"
},
{
"key": "7f91d1a929dce734e7f930bbb279ccfccdb5474227502ea8845815c74bd930a7",
Expand Down Expand Up @@ -41,7 +41,7 @@
},
{
"key": "c7e08cdde76020f08f4ce5c3257422ae67f9676992689b64b85f35aa58752d9e",
"value": "0000000000000000000000000000000000000000000000000000000000000001"
"value": "0000000000000000000000000000000000000000000000000000000001234567"
},
{
"key": "d02e07f5a716bd3b6670aaf9a73352164e6b946c24db14f72005b7029e67d96a",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use basic_storage_abi::*;
const C1 = 1;
const S5 = __to_str_array("aaaaa");

const CONST_U256 = 0x0000000000000000000000000000000000000000000000000000000000000001u256;
const CONST_B256 = 0x0000000000000000000000000000000000000000000000000000000000000001;

storage {
c1: u64 = C1,
str0: str[0] = __to_str_array(""),
Expand All @@ -21,9 +18,9 @@ storage {
str8: str[8] = __to_str_array("aaaaaaaa"),
str9: str[9] = __to_str_array("aaaaaaaaa"),
str10: str[10] = __to_str_array("aaaaaaaaaa"),
storage_u256: u256 = CONST_U256,
storage_b256: b256 = CONST_B256,

const_u256: u256 = 0x0000000000000000000000000000000000000000000000000000000001234567u256,
const_b256: b256 = 0x0000000000000000000000000000000000000000000000000000000001234567,
}

impl BasicStorage for Contract {
Expand Down Expand Up @@ -210,17 +207,17 @@ fn test_storage() {
assert_streq(storage.str9.read(), "aaaaaaaaa");
assert_streq(storage.str10.read(), "aaaaaaaaaa");

assert_streq(S5, "aaaaa");

assert_eq(storage.c1.read(), C1);
storage.c1.write(2);
assert_eq(storage.c1.read(), 2);

assert_eq(storage.const_u256.read(), 0x0000000000000000000000000000000000000000000000000000000001234567u256);
storage.const_u256.write(0x0000000000000000000000000000000000000000000000000000000012345678u256);
assert_eq(storage.const_u256.read(), 0x0000000000000000000000000000000000000000000000000000000012345678u256);

// assert_eq(storage.storage_u256.read(), CONST_U256);
storage.storage_u256.write(CONST_U256);
assert_eq(storage.storage_u256.read(), CONST_U256);

assert_eq(storage.storage_b256.read(), CONST_B256);
storage.storage_b256.write(CONST_B256);
assert_eq(storage.storage_b256.read(), CONST_B256);
assert_eq(storage.const_b256.read(), 0x0000000000000000000000000000000000000000000000000000000001234567);
storage.const_b256.write(0x0000000000000000000000000000000000000000000000000000000012345678);
assert_eq(storage.const_b256.read(), 0x0000000000000000000000000000000000000000000000000000000012345678);
}

// If these comparisons are done inline just above then it blows out the register allocator due to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
category = "compile"
validate_abi = true
validate_storage_slots = true
expected_warnings = 1

0 comments on commit aed687c

Please sign in to comment.