noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
823 stars 177 forks source link

Clean up misplaced items in stdlib #4845

Open TomAFrench opened 2 months ago

TomAFrench commented 2 months ago

It seems like a fair number of function have been placed a bit haphazardly, e.g.

We should do a pass of placing things where they should be to address these and similar issues. We can make this change non-breaking by adding reexports such as

// stdlib/lib.nr
mod sha256 {
    use crate::hash::sha256::digest
}
jfecher commented 2 months ago

It's also worth discussing if we want the hashers like crate::hash::poseidon2::Poseidon2Hasher to be in the same module as their actual hash function which is usually placed directly in crate::hash. Perhaps they should originate in the more specific modules and just be reexported into crate::hash, or maybe crate::hash should just be an empty module containing other more specific hash modules.

TomAFrench commented 2 months ago

Yeah, I was thinking along the same lines when writing this issue. I'm very much in favour of splitting a lot of these files out and using reexports liberally. I'd generally say that any trait in the stdlib should be in its own file due to the amount of boilerplate trait implementations for the primitive types it'll include, e.g. Eq and Ord

TomAFrench commented 2 months ago

Worth considering implementing #4860 around the same time.