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

Add zeroed function to create a zeroed value of any type #1017

Closed
jfecher opened this issue Mar 21, 2023 · 0 comments · Fixed by #1048
Closed

Add zeroed function to create a zeroed value of any type #1017

jfecher opened this issue Mar 21, 2023 · 0 comments · Fixed by #1048
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Mar 21, 2023

Problem

As explained in Issue #988, adding a std::zeroed function in Noir to return a zeroed value of any type would be useful to create "uninitialized" values for constructs like enums which guarantee these values will note be used.

Another possible usecase for such a function is adding a BoundedVec type to Noir which is backed by an array internally and has the array's size as its capacity. The array would initially be filled with N instances of zeroed::<T>() for some T, and these would be gradually replaced by the actual elements of the vector each time it is pushed to.

Proposed solution

We should add std::zeroed to our stdlib. Perhaps with a Note explaining why users should be cautious using it (using it on an arbitrary struct could create a struct with invalid invariants if it is used).

Alternatives considered

No response

Additional context

No response

@jfecher jfecher added the enhancement New feature or request label Mar 21, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Mar 21, 2023
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant