Skip to content

experimental/hash - #46

Closed
MarcWeber wants to merge 1 commit into
NixOS:masterfrom
MarcWeber:hash-function
Closed

MarcWeber wants to merge 1 commit into
NixOS:masterfrom
MarcWeber:hash-function

Conversation

@MarcWeber

Copy link
Copy Markdown
Contributor

adding primop function calculating hash of a string

Signed-off-by: Marc Weber [email protected]

Comment thread src/libexpr/primops.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use forceStringNoCtx() here.

@edolstra

Copy link
Copy Markdown
Member

Can you add a test case for "hash"? Thanks!

adding primop function calculating hash of a string

Signed-off-by: Marc Weber <[email protected]>
@MarcWeber

Copy link
Copy Markdown
Contributor Author

Now with test case. Also using forceStringNoCtx

@edolstra

Copy link
Copy Markdown
Member

Merged with some changes (renamed hash to hashString and added sha1 support)

@edolstra edolstra closed this Feb 11, 2013
tebowy pushed a commit to tebowy/nix that referenced this pull request Jul 11, 2024
-O3 does not measurably improve performance of the resulting binaries,
neither with lto enabled nor with lto disabled. what it does to however
is cause gcc warning spew in libstdc++ that we can't do anything
about (and that upon inspection of libstdc++ source looks like a gcc
bug).

with lto, -O3:

Benchmark 1: GC_INITIAL_HEAP_SIZE=10g nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'
    Time (mean ± σ):      4.608 s ±  0.027 s    [User: 3.866 s, System: 0.522 s]
    Range (min … max):    4.579 s …  4.640 s    10 runs

Benchmark 2:  nix eval -f <nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix>
    Time (mean ± σ):     408.1 ms ±  25.5 ms    [User: 360.0 ms, System: 28.1 ms]
    Range (min … max):   387.6 ms … 439.0 ms    10 runs

with lto, -O2:

Benchmark 1: GC_INITIAL_HEAP_SIZE=10g nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'
    Time (mean ± σ):      4.632 s ±  0.044 s    [User: 3.874 s, System: 0.544 s]
    Range (min … max):    4.563 s …  4.673 s    10 runs

Benchmark 2:  nix eval -f <nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix>
    Time (mean ± σ):     394.0 ms ±  23.9 ms    [User: 351.2 ms, System: 27.6 ms]
    Range (min … max):   377.8 ms … 429.3 ms    10 runs

without lto, -O3:

Benchmark 1: GC_INITIAL_HEAP_SIZE=10g nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'
    Time (mean ± σ):      4.700 s ±  0.024 s    [User: 3.906 s, System: 0.559 s]
    Range (min … max):    4.663 s …  4.717 s    10 runs

Benchmark 2:  nix eval -f <nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix>
    Time (mean ± σ):     400.4 ms ±  25.6 ms    [User: 353.7 ms, System: 26.8 ms]
    Range (min … max):   379.8 ms … 430.6 ms    10 runs

without lto, -O2:

Benchmark 1: GC_INITIAL_HEAP_SIZE=10g nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'
    Time (mean ± σ):      4.724 s ±  0.030 s    [User: 3.924 s, System: 0.570 s]
    Range (min … max):    4.687 s …  4.749 s    10 runs

Benchmark 2:  nix eval -f <nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix>
    Time (mean ± σ):     392.4 ms ±  24.3 ms    [User: 350.9 ms, System: 26.4 ms]
    Range (min … max):   376.9 ms … 428.0 ms    10 runs

fixes NixOS#46

Change-Id: Ib8afad8a07c278f57f2e3317d00cce4f9ec0f338
edolstra referenced this pull request in DeterminateSystems/nix-src Mar 5, 2025
ConnorBaker pushed a commit to ConnorBaker/nix that referenced this pull request Jul 25, 2025
…837432-a15d-4f23-9bb3-ef09aa99ce3c

Release v3.4.1
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
builtinBuildenv and builtinUnpackChannel each defined an identical
local getAttr lambda that wrapped drv.env.find with a "missing
attribute" error. Hoist it onto BuiltinBuilderContext as
getEnvAttr so the shared error string lives in one place.

builtins.hh ships via install_headers; the change is additive at the
public-API level (new const member function, no existing signature
touched, no struct-layout change since BuiltinBuilderContext gains
no data members), so external consumers compile unchanged.

The new getEnvAttr returns `const std::string &` rather than the
pre-batch buildenv.cc lambda's deduced `auto` (which yielded
`std::string` by value). At the two consuming call sites
(`tokenizeString<Strings>(getEnvAttr(...))` and
`createSymlink(getEnvAttr(...), ...)`) this is a no-op -- both bind
to either form -- but downstream patches that copy the lambda's
shape should know that the helper now returns by reference.
unpack-channel.cc's pre-batch lambda already returned `const std::string &`.

builtinFetchurl is intentionally not migrated: it uses `at()` and
`getOr` on optional fields, not the find-or-throw shape that
getEnvAttr captures. The candidate body's mention of fetchurl was
inaccurate; only buildenv and unpack-channel needed the lift.

Each builtin's body retains its irreducibly per-builtin behaviour;
only the lookup helper is shared.

Refs candidate NixOS#46.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
…kipped)

libstore session landed 7 of 8 queued candidates on
vibe-coding/cleanup/libstore.

Landed:
  - NixOS#26   -- pathlocks: hoisted PathLocks::lockPaths and FdLock::FdLock
            into shared pathlocks.cc; portable getFileSize for
            staleness; the Windows two-region LockFileEx trick stays
            in the platform shim.  Linux build green; Windows untested
            under current CI scope.
  - NixOS#46   -- builtins: hoisted the getAttr lambda from buildenv and
            unpack-channel into BuiltinBuilderContext::getEnvAttr.
            The candidate's mention of fetchurl was inaccurate — that
            file uses at()/getOr on optional fields, not the if-end()
            lambda shape.
  - NixOS#80   -- LegacySSHStoreConfig::logFD: unified Setting<Descriptor>
            with a Windows-only BaseSetting<Descriptor> specialisation
            in the shipped header.  Latent Windows bug fixed: log-fd
            is now respected on Windows (previously silently dropped).
  - NixOS#83   -- validateRuntimeRoots helper extracted; the Roots /
            UncheckedRoots key alignment turned out to already be
            done in current source.
  - NixOS#85   -- two file-scope templates parseStoreReferenceCollection
            and renderStoreReferenceCollection cover the vector and
            set BaseSetting specialisations; appendOrSet bodies stay
            inline because vector end-extend and set merge-insert
            genuinely differ.
  - NixOS#100  -- forEachConfiguredSigner extracted, helper-only scope; the
            cache-keys-in-memory FIXME stays as a separate follow-up.
  - NixOS#135  -- option (a) flatten: GCSettings and AutoAllocateUidSettings
            virtual base structs dropped, members inlined into
            LocalSettings, all consumers migrated.  Re-derives B1's
            independence-from-NixOS#136 verification.

Skipped:
  - NixOS#84   -- UnkeyedValidPathInfoBuilder.  Read both parsers
            end-to-end; the prescription doesn't actually shrink
            either body.  The "shared" data is just struct-field
            assignments where each setter is a one-liner equivalent
            to info.X = ….  The only invariant the candidate hints at
            (self-reference rejection) doesn't currently exist in
            either parser; adding it would be a behaviour change
            orthogonal to a mechanical refactor.  Effort downgraded
            to medium pending a real invariant to centralise.

STATUS.md "Cleanup branches (live)" updated for libstore.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 24, 2026
builtinBuildenv and builtinUnpackChannel each defined an identical
local getAttr lambda that wrapped drv.env.find with a "missing
attribute" error. Hoist it onto BuiltinBuilderContext as
getEnvAttr so the shared error string lives in one place.

builtins.hh ships via install_headers; the change is additive at the
public-API level (new const member function, no existing signature
touched, no struct-layout change since BuiltinBuilderContext gains
no data members), so external consumers compile unchanged.

The new getEnvAttr returns `const std::string &` rather than the
pre-batch buildenv.cc lambda's deduced `auto` (which yielded
`std::string` by value). At the two consuming call sites
(`tokenizeString<Strings>(getEnvAttr(...))` and
`createSymlink(getEnvAttr(...), ...)`) this is a no-op -- both bind
to either form -- but downstream patches that copy the lambda's
shape should know that the helper now returns by reference.
unpack-channel.cc's pre-batch lambda already returned `const std::string &`.

builtinFetchurl is intentionally not migrated: it uses `at()` and
`getOr` on optional fields, not the find-or-throw shape that
getEnvAttr captures. The candidate body's mention of fetchurl was
inaccurate; only buildenv and unpack-channel needed the lift.

Each builtin's body retains its irreducibly per-builtin behaviour;
only the lookup helper is shared.

Refs candidate NixOS#46.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 25, 2026
builtinBuildenv and builtinUnpackChannel each defined an identical
local getAttr lambda that wrapped drv.env.find with a "missing
attribute" error. Hoist it onto BuiltinBuilderContext as
getEnvAttr so the shared error string lives in one place.

builtins.hh ships via install_headers; the change is additive at the
public-API level (new const member function, no existing signature
touched, no struct-layout change since BuiltinBuilderContext gains
no data members), so external consumers compile unchanged.

The new getEnvAttr returns `const std::string &` rather than the
pre-batch buildenv.cc lambda's deduced `auto` (which yielded
`std::string` by value). At the two consuming call sites
(`tokenizeString<Strings>(getEnvAttr(...))` and
`createSymlink(getEnvAttr(...), ...)`) this is a no-op -- both bind
to either form -- but downstream patches that copy the lambda's
shape should know that the helper now returns by reference.
unpack-channel.cc's pre-batch lambda already returned `const std::string &`.

builtinFetchurl is intentionally not migrated: it uses `at()` and
`getOr` on optional fields, not the find-or-throw shape that
getEnvAttr captures. The candidate body's mention of fetchurl was
inaccurate; only buildenv and unpack-channel needed the lift.

Each builtin's body retains its irreducibly per-builtin behaviour;
only the lookup helper is shared.

Refs candidate NixOS#46.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
roberth added a commit to roberth/nix that referenced this pull request Aug 9, 2026
…le, §10, §16)

Batches tasks NixOS#42, NixOS#44, NixOS#45, NixOS#46, NixOS#47, NixOS#48:
- Add WalkHit entry in §6 with {resultHash, terminalCur} shape
- Add EvolutionStep entry in §17 (was referenced, never defined)
- Retitle §14 'argAncestry' (drop 'the enclosing scope of a subject' — 'scope' was the word we eliminated)
- Trim §16 argCell redundant sentence
- Reword §10 opening ('probed the other way around' → 'the other side probes')
- Deduplicate §17 SubjectEvolutionEdge — schema now referenced from §18 rather than restated

Task NixOS#41 (define EvolutionStep) subsumed by the §17 addition.

Assisted-by: Claude Code (Claude Opus 4.6-4.7)
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.

3 participants