From b1ffae3ccdfe03ee8a4c199743ae330914236a8e Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 28 Sep 2025 00:02:20 +0200 Subject: [PATCH] libexpr: move null to auxiliary storage we only need the one object for it. there's no need to waste precious bits of the value internal type enum for this simple singleton datum. Change-Id: Ie314b5bf429015e518798d9d65ad8ab2bb84a38e --- lix/libexpr/eval.cc | 1 + lix/libexpr/value.cc | 2 ++ lix/libexpr/value.hh | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 202273202..84ed1130a 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -108,6 +108,7 @@ std::string showType(const Value & v) case Value::Acb::tExternal: return v.external()->showType(); case Value::Acb::tFloat: + case Value::Acb::tNull: return std::string(showType(v.type())); } #pragma GCC diagnostic pop diff --git a/lix/libexpr/value.cc b/lix/libexpr/value.cc index e8835808e..9c95a3c5d 100644 --- a/lix/libexpr/value.cc +++ b/lix/libexpr/value.cc @@ -12,6 +12,8 @@ namespace nix static const Value::List emptyListData{.size = 0}; Value Value::EMPTY_LIST{Value::list_t{}, &emptyListData}; +const Value::Null Value::NULL_ACB = {{Value::Acb::tNull}}; + static void copyContextToValue(Value::String & s, const NixStringContext & context) { if (!context.empty()) { diff --git a/lix/libexpr/value.hh b/lix/libexpr/value.hh index 7bccb785b..50a9b7b11 100644 --- a/lix/libexpr/value.hh +++ b/lix/libexpr/value.hh @@ -26,7 +26,6 @@ typedef enum { tInt = 1, tBool, tString, - tNull, tAttrs, tList, tThunk, @@ -214,6 +213,9 @@ public: struct String; struct Acb; + struct Null; + + static const Null NULL_ACB; // Discount `using NewValueAs::*;` // NOLINTNEXTLINE(bugprone-macro-parentheses) @@ -416,10 +418,7 @@ public: } /// Constructs a nix language value of the singleton type "null". - Value(null_t) - : internalType(tNull) - , _empty{0, 0} - { } + Value(null_t) : Value(NULL_ACB) {} /// Constructs a nix language value of type "set", with the attribute /// bindings pointed to by @ref bindings. @@ -640,6 +639,7 @@ public: enum { tExternal, tFloat, + tNull, } type; }; struct External : Acb @@ -650,6 +650,8 @@ public: { NixFloat value; }; + struct Null : Acb + {}; union { @@ -710,7 +712,6 @@ public: case tBool: return nBool; case tString: return _string->isPath() ? nPath : nString; - case tNull: return nNull; case tAttrs: return nAttrs; case tList: return nList; @@ -723,6 +724,8 @@ public: return nExternal; case Acb::tFloat: return nFloat; + case Acb::tNull: + return nNull; } case tThunk: return nThunk; @@ -790,8 +793,7 @@ public: inline void mkNull() { - clearValue(); - internalType = tNull; + *this = {NewValueAs::null}; } inline void mkAttrs(Bindings * a)