-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Contract method with struct arguments don't work with IR #1146
Comments
I tried out the test above and yep, it fails. But it seems to me it's still just because the SDK is special casing structs to be by value when their size is 1 word. Each of the structs above are only 1 word in size and are passed around by value in the original ASM. As soon as you add second fields to these structs (and ignore them) the test starts passing. So I don't think the solution is anything more than to fix for always-by-reference structs in FuelLabs/fuels-rs#201 Am I still missing something? |
Edit... misread Toby's comment.. Checking again. |
You're right.. I tried various things and the moment you pass anything larger than a word, the test passes, regardless of how many arguments you have. However, something still doesn't add up because the way this check works: https://github.com/FuelLabs/fuels-rs/blob/7fda121547ee28de91145f8e8034db7e02b79b48/packages/fuels-contract/src/contract.rs#L341 doesn't seem to match the behaviour above, so maybe something else is going on. |
Ahh this is coming down to the checks we have in the new codegen regarding the size of the data, instead of checking the data type. For this simple test: contract;
pub struct StructOne {
foo: u64,
bar: u64,
}
abi MyTest {
fn something(input1: StructOne) -> u64;
}
impl MyTest for Contract {
fn something(input1: StructOne) -> u64 {
input1.foo
}
} If we remove That's why I was seeing the chain of Let me try to fix this. |
Here's an example:
with the following test harness:
The assert fails.
The problem is that nested structs are represented as pointers to pointers to pointers etc.. instead of just a pile of data with offsets (which is what the old codegen used to do). The SDK does not currently expect that. We should decide what's best to do here.
Speaking with @otrho , the best way forward seems to be a revamp of how
extract_value
works and maybe replace it with a combination ofget_ptr
andstore
.Edit: fix a bug in the SDK code.
The text was updated successfully, but these errors were encountered: