Skip to content

Improve array decode #7342

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

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft

Improve array decode #7342

wants to merge 15 commits into from

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Aug 22, 2025

Description

Continuation of #6860.

This PR implements multiple small features focusing on improving AbiDecode for arrays.

1 - Before the implementation for AbiDecode for arrays was decoding the first element and creating an "repeat array". Depending on the size that would init with up to five store or would loop copying the first item over all slots.

Now we create an "repeat array" of zero of the required size. This will be initialized with just one MCLI/MCL. And then we transmute this into the desired array type;

2 - Array lengths can now be specified with const.

One limitation is that these lengths must be limited to simple const variables. Associated consts are still not working.
Another limitation is that we can't unify arrays lengths that use variables and literals. For example: let _: [u64; 1] = [0u64; A];

const GLOBAL_A: u64 = 1;
#[inline(never)]
fn arrays_with_const_length() {
    const A = 1;
    const B = A + 1;

    let _ = [0u64; A];
    let _: [u64; A] = [0u64];
    let _ = [0u64; GLOBAL_A];

    let _ = [0u64; B];
    let _: [u64; B] = [0u64, 1u64];
}

3 - const declarations can now use const generics in its expressions.

4 - __transmute can now transmute references.

convert_resolved_type_info

One of the biggest changes was that now convert_resolved_type_info needs to access the "context" that is being compiled, as the type can include expressions. At the moment only const variables and const generics variables. But soon enough we will be able to write expressions and it needs full access to available symbols.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@xunilrj xunilrj self-assigned this Aug 22, 2025
Copy link

codspeed-hq bot commented Aug 22, 2025

CodSpeed Performance Report

Merging #7342 will not alter performance

Comparing xunilrj/improve-array-decode (fbcef8a) with master (406251e)

Summary

✅ 25 untouched benchmarks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant