Skip to content

Commit

Permalink
Large integers in aggregates cannot be scalarised (#5442)
Browse files Browse the repository at this point in the history
Fixes #5377
  • Loading branch information
vaivaswatha authored Jan 9, 2024
1 parent f6d8710 commit 7109ca7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sway-ir/src/optimize/sroa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ fn is_processable_aggregate(context: &Context, ty: Type) -> bool {
match ty.get_content(context) {
crate::TypeContent::Unit => true,
crate::TypeContent::Bool => true,
crate::TypeContent::Uint(_) => true,
crate::TypeContent::Uint(width) => *width <= 64,
crate::TypeContent::B256 => false,
crate::TypeContent::Array(elm_ty, _) => check_sub_types(context, *elm_ty),
crate::TypeContent::Union(_) => false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[[package]]
name = "core"
source = "path+from-root-5C15EEA63C6F47D5"

[[package]]
name = "largeint_sroa"
source = "member"
dependencies = [
"core",
"std",
]

[[package]]
name = "std"
source = "path+from-root-5C15EEA63C6F47D5"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
name = "largeint_sroa"

[dependencies]
core = { path = "../../../../../../../sway-lib-core" }
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"configurables": [],
"functions": [
{
"attributes": null,
"inputs": [],
"name": "main",
"output": {
"name": "",
"type": 0,
"typeArguments": null
}
}
],
"loggedTypes": [],
"messagesTypes": [],
"types": [
{
"components": null,
"type": "bool",
"typeId": 0,
"typeParameters": null
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
script;

fn array_test() {
let mut a = [0x0111111111111111111111111111111111111111111111111111111111111111u256];
assert(a[0] == 0x0111111111111111111111111111111111111111111111111111111111111111u256);
a[0] = 0x0222222222222222222222222222222222222222222222222222222222222222u256;
}

struct S {
x: u256,
}

fn struct_test() {
let mut s = S { x: 0x0111111111111111111111111111111111111111111111111111111111111111u256 };
assert(s.x == 0x0111111111111111111111111111111111111111111111111111111111111111u256);
s.x = 0x0222222222222222222222222222222222222222222222222222222222222222u256;
}

fn tuple_test() {
let mut t = (0x0111111111111111111111111111111111111111111111111111111111111111u256,);
assert(t.0 == 0x0111111111111111111111111111111111111111111111111111111111111111u256);
t.0 = 0x0222222222222222222222222222222222222222222222222222222222222222u256;
}

fn main() {

}


#[test]
fn test() {
array_test();
struct_test();
tuple_test();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
category = "unit_tests_pass"
expected_warnings = 0

0 comments on commit 7109ca7

Please sign in to comment.