From df21c81191089e42e7e47a80431b235954afdf6c Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Thu, 12 Feb 2026 20:51:38 +0300 Subject: [PATCH 1/2] libexpr: Fix some typos in value.hh --- src/libexpr/include/nix/expr/value.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libexpr/include/nix/expr/value.hh b/src/libexpr/include/nix/expr/value.hh index 479a4fddc..aef10b9c6 100644 --- a/src/libexpr/include/nix/expr/value.hh +++ b/src/libexpr/include/nix/expr/value.hh @@ -134,7 +134,7 @@ public: virtual bool operator==(const ExternalValueBase & b) const noexcept; /** - * Print the value as JSON. Defaults to unconvertable, i.e. throws an error + * Print the value as JSON. Defaults to unconvertible, i.e. throws an error */ virtual nlohmann::json printValueAsJSON(EvalState & state, bool strict, NixStringContext & context, bool copyToStore = true) const; @@ -587,7 +587,7 @@ class alignas(16) enum PrimaryDiscriminator : int { pdUninitialized = 0, pdSingleDWord, //< layout: Single/zero field payload - /* The order of these enumations must be the same as in InternalType. */ + /* The order of these enumerations must be the same as in InternalType. */ pdListN, //< layout: Single untaggable field. pdString, pdPath, From 7352205ce9dce17bc60a00a6a4a02b1627f44bad Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Thu, 12 Feb 2026 21:06:06 +0300 Subject: [PATCH 2/2] libexpr: Replace hardcoded cache line size with std::hardware_destructive_interference_size This expands to __GCC_DESTRUCTIVE_SIZE, which is also 64 (at least in the x86_64 stdenv). Let the compiler decide what's the appropriate cache line size is. Also, on aarch64-darwin the cache line size 128 bytes, so the previous fix didn't actually get rid of false sharing reliably. Clang does this [1] [2], so it overestimates the sizes somewhat, but that's still enough for avoiding false sharing on darwin. [1]: https://github.com/llvm/llvm-project/blob/a289341dedf4d73955faefbb0b3c13881e13dd06/clang/lib/Frontend/InitPreprocessor.cpp#L1331-L1339 [2]: https://github.com/llvm/llvm-project/blob/6f51f8e0f93e6ff2baf0ed2f60021308920a557f/clang/lib/Basic/Targets/AArch64.h#L262-L264 --- nix-meson-build-support/common/meson.build | 1 + src/libexpr/eval.cc | 1 - src/libexpr/include/nix/expr/counter.hh | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nix-meson-build-support/common/meson.build b/nix-meson-build-support/common/meson.build index 5fcf557e7..4488a1760 100644 --- a/nix-meson-build-support/common/meson.build +++ b/nix-meson-build-support/common/meson.build @@ -25,6 +25,7 @@ add_project_arguments( '-Wignored-qualifiers', '-Wimplicit-fallthrough', '-Wno-deprecated-declarations', + '-Wno-interference-size', # Used for C++ ABI only. We don't provide any guarantees about different march tunings. language : 'cpp', ) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 84f14198f..d9d8a986a 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -318,7 +318,6 @@ EvalState::EvalState( countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0"; static_assert(sizeof(Env) <= 16, "environment must be <= 16 bytes"); - static_assert(sizeof(Counter) == 64, "counters must be 64 bytes"); /* Construct the Nix expression search path. */ assert(lookupPath.elements.empty()); diff --git a/src/libexpr/include/nix/expr/counter.hh b/src/libexpr/include/nix/expr/counter.hh index efbf23de3..f679b23ca 100644 --- a/src/libexpr/include/nix/expr/counter.hh +++ b/src/libexpr/include/nix/expr/counter.hh @@ -11,7 +11,7 @@ namespace nix { * variable is set. This is to prevent contention on these counters * when multi-threaded evaluation is enabled. */ -struct alignas(64) Counter +struct alignas(std::hardware_destructive_interference_size) Counter { using value_type = uint64_t;