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

feat: Implement std::unsafe::zeroed #1048

Merged
merged 6 commits into from
Mar 30, 2023
Merged

feat: Implement std::unsafe::zeroed #1048

merged 6 commits into from
Mar 30, 2023

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Mar 28, 2023

Related issue(s)

Resolves #1017

Requires #1044 to work as it renames the unsafe keyword which is used by this PR as a module name.

Part of work to implement #988

Description

Summary of changes

Implements fn zeroed<T>() -> T to return a zeroed value of any type. This function is generally unsafe to use as the zeroed bit pattern is not guaranteed to be valid for all types. It can however, be useful in cases when the value is guaranteed not to be used such as in a BoundedVec library implementing a growable vector, up to a certain length, backed by an array. The array can be initialized with zeroed values which are guaranteed to be inaccessible until the vector is pushed to. Similarly, enumerations in noir can be implemented using this method by providing zeroed values for the unused variants.

Dependency additions / changes

Test additions / changes

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.

Documentation needs

  • This PR requires documentation updates when merged.

Add std::unsafe::zeroed to the documentation of the standard library. Its type signature and usecases should be noted (given above in this PR), and especially the note on its potential unsafeness.

Additional context

@jfecher jfecher changed the title Implement std::unsafe::zeroed feat: Implement std::unsafe::zeroed Mar 28, 2023
kevaundray
kevaundray previously approved these changes Mar 30, 2023
@kevaundray kevaundray added this pull request to the merge queue Mar 30, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 30, 2023
@jfecher jfecher added this pull request to the merge queue Mar 30, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 30, 2023
@jfecher jfecher added this pull request to the merge queue Mar 30, 2023
Merged via the queue into master with commit 9a43f85 Mar 30, 2023
@jfecher jfecher deleted the jf/zeroed branch March 30, 2023 14:07
TomAFrench added a commit that referenced this pull request Apr 3, 2023
* master:
  chore: handle public parameters and return values separately in evaluator (#1062)
  chore(ssa): Rename ObjectType::Pointer to ObjectType::ArrayPointer (#1077)
  chore(ssa): indent NumericType into ObjectType (#810)
  chore: apply spelling fixes (#1073)
  feat: Implement `std::unsafe::zeroed` (#1048)
  fix: crash when typechecking fields that don't exist (#1070)
  feat: Implement arrays of structs (#1068)
  feat(nargo): split `nargo` into core and cli packages (#1065)
  chore: split wasm crate into submodules (#1066)
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.

Add zeroed function to create a zeroed value of any type
2 participants