Skip to content

Allow dynamic types in configurables #6760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,10 @@ vte = "0.13"
walkdir = "2.3"
whoami = "1.5"
wiremock = "0.6"

[patch.crates-io]
fuel-abi-types = { git = "https://github.com/FuelLabs/fuel-abi-types", branch = "xunilrj/indirect-configurables" }
fuels = { git = "https://github.com/FuelLabs/fuels-rs", branch = "hal3e/dynamic-configurables" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan to wait for the fuels branches to be merged this PR goes out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

fuels-core = { git = "https://github.com/FuelLabs/fuels-rs", branch = "hal3e/dynamic-configurables" }
fuels-accounts = { git = "https://github.com/FuelLabs/fuels-rs", branch = "hal3e/dynamic-configurables" }
fuels-code-gen = { git = "https://github.com/FuelLabs/fuels-rs", branch = "hal3e/dynamic-configurables" }
2 changes: 2 additions & 0 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,8 @@ fn report_assembly_information(
sway_core::asm_generation::Datum::Collection(items) => {
items.iter().map(calculate_entry_size).sum()
}

sway_core::asm_generation::Datum::OffsetOf(_) => std::mem::size_of::<u64>() as u64,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,62 +251,74 @@
{
"name": "BOOL",
"concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903",
"offset": 240
"offset": 240,
"indirect": false
},
{
"name": "U8",
"concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b",
"offset": 352
"offset": 352,
"indirect": false
},
{
"name": "U16",
"concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef",
"offset": 296
"offset": 296,
"indirect": false
},
{
"name": "U32",
"concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc",
"offset": 336
"offset": 336,
"indirect": false
},
{
"name": "U64",
"concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0",
"offset": 344
"offset": 344,
"indirect": false
},
{
"name": "U256",
"concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e",
"offset": 304
"offset": 304,
"indirect": false
},
{
"name": "B256",
"concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b",
"offset": 208
"offset": 208,
"indirect": false
},
{
"name": "STR_4",
"concreteTypeId": "94f0fa95c830be5e4f711963e83259fe7e8bc723278ab6ec34449e791a99b53a",
"offset": 280
"offset": 280,
"indirect": false
},
{
"name": "TUPLE",
"concreteTypeId": "e0128f7be9902d1fe16326cafe703b52038064a7997b03ebfc1c9dd607e1536c",
"offset": 288
"offset": 288,
"indirect": false
},
{
"name": "ARRAY",
"concreteTypeId": "d9fac01ab38fe10950758ae9604da330d6406a71fda3ef1ea818121261132d56",
"offset": 192
"offset": 192,
"indirect": false
},
{
"name": "STRUCT",
"concreteTypeId": "563310524b4f4447a10d0e50556310253dfb3b5eb4b29c3773222b737c8b7075",
"offset": 264
"offset": 264,
"indirect": false
},
{
"name": "ENUM",
"concreteTypeId": "37cd1cba311039a851ac8bfa614cc41359b4ad95c8656fcef2e8f504fe7a1272",
"offset": 248
"offset": 248,
"indirect": false
}
]
}
6 changes: 3 additions & 3 deletions forc-plugins/forc-client/tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,13 +1215,13 @@ async fn call_with_forc_generated_overrides(node_url: &str, contract_id: Contrac
// we are ensuring forc-deploy indeed generated the files we are basing our
// tests below.
let generated_loader_abi_path = tmp_dir.path().join("out/deployed_script-loader-abi.json");
let generated_loader_abi = fs::read_to_string(generated_loader_abi_path).unwrap();
let generated_loader_abi = fs::read_to_string(&generated_loader_abi_path).unwrap();

// this path is basically, `forc-plugins/forc-client/test/data/deployed_script/deployed_script-loader-abi.json`.
let used_loader_abi_path = project_dir.join("deployed_script-loader-abi.json");
let used_loader_abi = fs::read_to_string(used_loader_abi_path).unwrap();
let used_loader_abi = fs::read_to_string(&used_loader_abi_path).unwrap();

assert_eq!(generated_loader_abi, used_loader_abi);
pretty_assertions::assert_eq!(generated_loader_abi, used_loader_abi);

let generated_loader_bin = tmp_dir.path().join("out/deployed_script-loader.bin");
abigen!(Script(
Expand Down
1 change: 1 addition & 0 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ fn generate_configurables(
decl.type_ascription.type_id,
)?,
offset: 0,
indirect: decl.is_indirect(engines),
})
})
.collect::<Result<Vec<_>, _>>()
Expand Down
34 changes: 29 additions & 5 deletions sway-core/src/asm_generation/finalized_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,18 @@ fn to_bytecode_mut(
println!(".data_section:");

let offset = bytecode.len();

fn print_entry(indentation: usize, offset: usize, pair: &Entry) {
let ds_start = offset as u64;

fn print_entry(
ds: &DataSection,
indentation: usize,
ds_start: u64,
offset: usize,
entry: &Entry,
) {
print!("{}{:#010x} ", " ".repeat(indentation), offset);

match &pair.value {
match &entry.value {
Datum::Byte(w) => println!(".byte i{w}, as hex {w:02X}"),
Datum::Word(w) => {
println!(".word i{w}, as hex be bytes ({:02X?})", w.to_be_bytes())
Expand Down Expand Up @@ -351,15 +358,32 @@ fn to_bytecode_mut(
Datum::Collection(els) => {
println!(".collection");
for e in els {
print_entry(indentation + 1, offset, e);
print_entry(ds, indentation + 1, ds_start, offset, e);
}
}
Datum::OffsetOf(_) => {
let offset_as_bytes = entry.to_bytes(ds);
let offset_as_u64 =
u64::from_be_bytes(offset_as_bytes.as_slice().try_into().unwrap());
println!(
".offset of 0x{:08x}, as word {}, as hex be bytes ({:02X?})",
ds_start + offset_as_u64,
offset_as_u64,
offset_as_bytes
);
}
};
}

for (i, entry) in data_section.iter_all_entries().enumerate() {
let entry_offset = data_section.absolute_idx_to_offset(i);
print_entry(indentation, offset + entry_offset, &entry);
print_entry(
data_section,
indentation,
ds_start,
offset + entry_offset,
&entry,
);
}

println!(";; --- END OF TARGET BYTECODE ---\n");
Expand Down
Loading
Loading