Skip to content
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

Feature request: ArrayView should have all the public methods that Array has #1013

Open
gmlewis opened this issue Sep 18, 2024 · 3 comments
Open
Labels
good first issue Good for newcomers

Comments

@gmlewis
Copy link
Contributor

gmlewis commented Sep 18, 2024

Discord discussion: https://discord.com/channels/1135479745207869510/1285600688197341287

Since it is not easy to create an Array from an ArrayView without copying, it would be nice if ArrayView could do everything that an Array can do.

Additionally, I often find myself in similar situations with these types that are closely related yet frequently incompatible without copying:

  • Bytes
  • FixedArray[Byte]
  • Array[Byte]
  • ArrayView[Byte]

Ideally, it should be easy to convert to/from any of these 4 types to any of the other 4 types WITHOUT any copying.

@peter-jerry-ye peter-jerry-ye added the good first issue Good for newcomers label Sep 23, 2024
@peter-jerry-ye
Copy link
Collaborator

The without any copying part is impossible to give guarantee.

For example, take the wasm-gc backend. There's possibility that Bytes and FixedArray[Byte] can be converted back and forth with array<u8>, but impossible with Array[Byte].

On the other hand, there's no difference between FixedArray and Array and JS native array. But still, it's impossible to convert ArrayView to Array without copying.

@gmlewis
Copy link
Contributor Author

gmlewis commented Sep 30, 2024

Thank you, @peter-jerry-ye, for the information.

Is it safe to say that anything that takes an Array as an argument would be more useful if it instead took an ArrayView?

For example, take Bytes::from_array:

Instead of:

pub fn Bytes::from_array(arr : Array[Byte]) -> Bytes { ... }

wouldn't it be more flexible if it were this?

pub fn Bytes::from_array(arr : ArrayView[Byte]) -> Bytes { ... }

And if that is true, would you want to make sweeping breaking API changes throughout the code base, or would you prefer two versions of every function where the Array version would call the (more flexible) ArrayView version?
(Or maybe instead deprecate the existing one and add a new one?)

If I were to take on this "good first issue", would it be OK to address it with baby-steps like this first Array/ArrayView step?

@peter-jerry-ye
Copy link
Collaborator

@gmlewis That's a good question. ArrayView is indeed more general than Array. We may need to take that into account. cc @bobzhang @Yoorkin

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

No branches or pull requests

2 participants