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

A primop (or two) for canonicalizing a value #560

Open
copumpkin opened this issue Jun 18, 2015 · 4 comments · Fixed by cachix/devenv#561
Open

A primop (or two) for canonicalizing a value #560

copumpkin opened this issue Jun 18, 2015 · 4 comments · Fixed by cachix/devenv#561
Assignees
Labels
feature Feature request or proposal language The Nix expression language; parser, interpreter, primops, evaluation, etc

Comments

@copumpkin
Copy link
Member

I think it's fairly common for us to know that the order of elements in a list (or even possible duplicates) don't affect the semantics of an operation. Nonetheless, they do affect the hash of a derivation they get fed into. I'd normally be inclined to just call lib.sort in nixpkgs against the list, but that's kind of slow, and adding uniq on top of that is even slower.

It seems like it would make sense to make a couple of native-code primops to canonicalize a list before using it. One would sort, the other would sort and uniq. Does that make sense?

@pikajude also appeared to care on IRC

@pikajude
Copy link
Contributor

So like a Set type?

@copumpkin
Copy link
Member Author

Set and multiset, yep. If we can assume an attribute set has a canonical key ordering, going to and from would work and probably be fairly fast, but my sense was that attribute sets weren't ordered.

@stale
Copy link

stale bot commented Feb 15, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 15, 2021
@tomberek
Copy link
Contributor

tomberek commented Mar 24, 2022

Possible to implement something close to this with builtins.genericClosure? https://github.com/NixOS/nix/pull/6305/files

Close?

@stale stale bot removed the stale label Mar 24, 2022
@fricklerhandwerk fricklerhandwerk added feature Feature request or proposal language The Nix expression language; parser, interpreter, primops, evaluation, etc labels Sep 12, 2022
zolodev pushed a commit to zolodev/nix that referenced this issue Jan 1, 2024
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal language The Nix expression language; parser, interpreter, primops, evaluation, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants