Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Documenting vectors #255

Merged
merged 1 commit into from
Aug 2, 2023
Merged

Documenting vectors #255

merged 1 commit into from
Aug 2, 2023

Conversation

signorecello
Copy link
Collaborator

closes #231

Even to me, it's confusing the whole Array/Slices/Vector thing, but @critesjosh you're telling me that with the --experimental-ssa all slice methods will be array methods, maybe it would help with this?

@netlify
Copy link

netlify bot commented Jul 19, 2023

Deploy Preview for noir-docs ready!

Name Link
🔨 Latest commit 54d98d6
🔍 Latest deploy log https://app.netlify.com/sites/noir-docs/deploys/64b7bca9d3fc4e0008dba8d8
😎 Deploy Preview https://deploy-preview-255--noir-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@critesjosh
Copy link
Collaborator

I am not sure that all slice methods are array methods when using the flag. But I was chatting with @vezenovm and he said that once the experimental-ssa flag is the default, this will be the case. I am not sure if there are other changes that will be in the 0.9.0 release that will make this happen.

@Savio-Sou
Copy link
Contributor

it's confusing the whole Array/Slices/Vector thing

How I understand it is:

  • Arrays are, well, arrays.
  • Tuples are multi-type compatible arrays.
  • Slices are dynamically-sized arrays.
  • Vectors are mutable slices.

Rust often offers a wide set of possible nuances for devs to pick the best option for quick development vs safety & optimizations.

Hope it helps and happy to be corrected 🙌

@signorecello signorecello merged commit fe452a4 into master Aug 2, 2023
@signorecello signorecello deleted the zpedro/slices branch August 2, 2023 08:12
@vezenovm
Copy link
Contributor

vezenovm commented Aug 2, 2023

Hey @critesjosh @signorecello so after this PR: noir-lang/noir#2070, arrays and slices no longer have a subtyping relationship. On Noir master you will see that the array methods and slice methods are now separated again in the stdlib. There is now an as_slice method to convert an array into a slice.

This isn't a breaking change though as we automatically coerce arrays to slices in the compiler when needed. Here is a simple example:

fn foo(slice: [Field]) -> comptime Field {
  slice.len();
}

fn bar() {
 let arr = [0; 5];
 assert(foo(arr) == 5);
}

Apologies for the back-and-forth here, but removing the subtype relationship between slices and arrays was deemed the best solution as it solved some other issues for us.

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

Successfully merging this pull request may close these issues.

Document Vector type
4 participants