Skip to content

Commit

Permalink
Merge branch 'master' into xunilrj/implicit-std-env-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
IGI-111 authored Nov 2, 2023
2 parents 089097e + ae31213 commit 842a51d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 19 deletions.
6 changes: 5 additions & 1 deletion forc-plugins/forc-fmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ fn format_file(
// TODO: Support formatting for incomplete/invalid sway code.
// https://github.com/FuelLabs/sway/issues/5012
debug!("{}", err);
bail!("Failed to compile: {:?}", file);
if let Some(file) = file.to_str() {
bail!("Failed to compile {}\n{}", file, err);
} else {
bail!("Failed to compile.\n{}", err);
}
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions sway-ir/src/optimize/memcpyopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn local_copy_prop_prememcpy(context: &mut Context, function: Function) -> Resul
let mut loads_map = FxHashMap::<Symbol, Vec<Value>>::default();
let mut stores_map = FxHashMap::<Symbol, Vec<Value>>::default();
let mut instr_info_map = FxHashMap::<Value, InstInfo>::default();
let mut asm_uses = FxHashSet::<Symbol>::default();
let mut escaping_uses = FxHashSet::<Symbol>::default();

for (pos, (block, inst)) in function.instruction_iter(context).enumerate() {
let info = || InstInfo { block, pos };
Expand Down Expand Up @@ -81,11 +81,21 @@ fn local_copy_prop_prememcpy(context: &mut Context, function: Function) -> Resul
for arg in args {
if let Some(arg) = arg.initializer {
if let Some(local) = get_symbol(context, arg) {
asm_uses.insert(local);
escaping_uses.insert(local);
}
}
}
}
Instruction {
op: InstOp::Call(_, args),
..
} => {
for arg in args {
if let Some(local) = get_symbol(context, *arg) {
escaping_uses.insert(local);
}
}
}
_ => (),
}
}
Expand Down Expand Up @@ -151,7 +161,7 @@ fn local_copy_prop_prememcpy(context: &mut Context, function: Function) -> Resul
instr_info.block == block && instr_info.pos > pos
})
// We don't deal with ASM blocks.
|| asm_uses.contains(&dst_local)
|| escaping_uses.contains(&dst_local)
// We don't deal part copies.
|| dst_local.get_type(context) != src_local.get_type(context)
// We don't replace the destination when it's an arg.
Expand Down
10 changes: 5 additions & 5 deletions sway-lib-std/src/hash.sw
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Hasher {
self.write(bytes);
}

#![inline(never)]
#[inline(never)]
pub fn write_str_array<S>(ref mut self, s: S) {
__assert_is_str_array::<S>();
let str_size = __size_of_str_array::<S>();
Expand Down Expand Up @@ -159,7 +159,7 @@ impl Hash for str {
}

impl<A, B> Hash for (A, B) where A: Hash, B: Hash {
#![inline(never)]
#[inline(never)]
fn hash(self, ref mut state: Hasher) {
self.0.hash(state);
self.1.hash(state);
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<T> Hash for [T; 10] where T: Hash {
/// assert(result = 0xa80f942f4112036dfc2da86daf6d2ef6ede3164dd56d1000eb82fa87c992450f);
/// }
/// ```
#![inline(never)]
#[inline(never)]
pub fn sha256<T>(s: T) -> b256 where T: Hash {
let mut hasher = Hasher::new();
s.hash(hasher);
Expand All @@ -338,7 +338,7 @@ pub fn sha256<T>(s: T) -> b256 where T: Hash {
/// assert(result = 0xa80f942f4112036dfc2da86daf6d2ef6ede3164dd56d1000eb82fa87c992450f);
/// }
/// ```
#![inline(never)]
#[inline(never)]
pub fn sha256_str_array<S>(param: S) -> b256 {
__assert_is_str_array::<S>();
let str_size = __size_of_str_array::<S>();
Expand Down Expand Up @@ -374,7 +374,7 @@ pub fn sha256_str_array<S>(param: S) -> b256 {
/// assert(result = 0x4375c8bcdc904e5f51752581202ae9ae2bb6eddf8de05d5567d9a6b0ae4789ad);
/// }
/// ```
#![inline(never)]
#[inline(never)]
pub fn keccak256<T>(s: T) -> b256 where T: Hash {
let mut hasher = Hasher::new();
s.hash(hasher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"typeArguments": null
},
"name": "C0",
"offset": 3420
"offset": 3436
},
{
"configurableType": {
Expand All @@ -16,7 +16,7 @@
"typeArguments": null
},
"name": "C1",
"offset": 3428
"offset": 3444
},
{
"configurableType": {
Expand All @@ -25,7 +25,7 @@
"typeArguments": null
},
"name": "C2",
"offset": 3444
"offset": 3460
},
{
"configurableType": {
Expand All @@ -34,7 +34,7 @@
"typeArguments": []
},
"name": "C3",
"offset": 3476
"offset": 3492
},
{
"configurableType": {
Expand All @@ -43,7 +43,7 @@
"typeArguments": []
},
"name": "C4",
"offset": 3492
"offset": 3508
},
{
"configurableType": {
Expand All @@ -52,7 +52,7 @@
"typeArguments": []
},
"name": "C5",
"offset": 3508
"offset": 3524
},
{
"configurableType": {
Expand All @@ -61,7 +61,7 @@
"typeArguments": null
},
"name": "C6",
"offset": 3524
"offset": 3540
},
{
"configurableType": {
Expand All @@ -70,7 +70,7 @@
"typeArguments": null
},
"name": "C7",
"offset": 3540
"offset": 3556
},
{
"configurableType": {
Expand All @@ -79,7 +79,7 @@
"typeArguments": null
},
"name": "C9",
"offset": 3588
"offset": 3604
}
],
"functions": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = "core"
source = "path+from-root-1621225C7A88836C"

[[package]]
name = "memcpy"
source = "member"
dependencies = ["std"]

[[package]]
name = "std"
source = "path+from-root-1621225C7A88836C"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
license = "Apache-2.0"
name = "memcpy"
entry = "main.sw"

[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
script;

fn main() -> u64 {
let a = A { a: 11 };
let mut ptr_a = ptr(a);
ptr_a.write(A { a: 22 });
assert(a.a == 11);
a.a
}

struct A {
a: u64,
}

#[inline(never)]
fn ptr<T>(t: T) -> raw_ptr {
__addr_of(t)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category = "run"
expected_result = { action = "return", value = 11 }
validate_abi = false
expected_warnings=6
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ script;
use basic_storage_abi::{BasicStorage, Quad};

fn main() -> u64 {
let addr = abi(BasicStorage, 0x01e64bbd633f1e8cf9d9a712bc7b8f1003c7b8d9796a0d3cd234370881ea6f0a);
let addr = abi(BasicStorage, 0xafd842e74db4e85a770b0569a9df1226d1f57087cb331be88aa37387f6d8841d);
let key = 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
let value = 4242;

Expand Down

0 comments on commit 842a51d

Please sign in to comment.