Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::Value Struct Reference

Public Member Functions

 USING_VALUETYPE (integer_t)
 USING_VALUETYPE (floating_t)
 USING_VALUETYPE (boolean_t)
 USING_VALUETYPE (string_t)
 USING_VALUETYPE (path_t)
 USING_VALUETYPE (list_t)
 USING_VALUETYPE (attrs_t)
 USING_VALUETYPE (thunk_t)
 USING_VALUETYPE (primop_t)
 USING_VALUETYPE (app_t)
 USING_VALUETYPE (null_t)
 USING_VALUETYPE (primOpApp_t)
 USING_VALUETYPE (lambda_t)
 USING_VALUETYPE (external_t)
 USING_VALUETYPE (blackhole_t)
 Value ()
 Value (integer_t, NixInt i)
 Value (floating_t, NixFloat f)
 Value (boolean_t, bool b)
 Value (string_t, char const *strPtr, char const **contextPtr=nullptr)
 Value (string_t, std::string_view copyFrom, NixStringContext const &context={})
 Value (string_t, char const *strPtr, NixStringContext const &context)
 Value (path_t, char const *strPtr)
 Value (path_t, SourcePath const &path)
 Value (list_t, std::span< Value * > items)
template<std::ranges::sized_range SizedIterableT, InvocableR< Value *, typename SizedIterableT::value_type const & > TransformerT>
 Value (list_t, SizedIterableT &items, TransformerT const &transformer)
 Value (null_t)
 Constructs a nix language value of the singleton type "null".
 Value (attrs_t, Bindings *bindings)
 Value (thunk_t, Env &env, Expr &expr)
 Value (primop_t, PrimOp &primop)
 Value (primOpApp_t, Value &lhs, Value &rhs)
 Value (app_t, Value &lhs, Value &rhs)
 Value (external_t, ExternalValueBase &external)
 Value (lambda_t, Env &env, ExprLambda &lambda)
 Value (blackhole_t)
 Constructs an evil thunk, whose evaluation represents infinite recursion.
 Value (Value const &rhs)=default
 Value (Value &&rhs)
Valueoperator= (Value const &rhs)=default
Valueoperator= (Value &&rhs)
void print (EvalState &state, std::ostream &str, PrintOptions options=PrintOptions {})
bool isThunk () const
bool isApp () const
bool isBlackhole () const
bool isLambda () const
bool isPrimOp () const
bool isPrimOpApp () const
ValueType type (bool invalidIsThunk=false) const
void clearValue ()
void mkInt (NixInt::Inner n)
void mkInt (NixInt n)
void mkBool (bool b)
void mkString (const char *s, const char **context=0)
void mkString (std::string_view s)
void mkString (std::string_view s, const NixStringContext &context)
void mkStringMove (const char *s, const NixStringContext &context)
void mkPath (const SourcePath &path)
void mkPath (const char *path)
void mkNull ()
void mkAttrs (Bindings *a)
ValuemkAttrs (BindingsBuilder &bindings)
void mkList (size_t size)
void mkThunk (Env *e, Expr &ex)
void mkApp (Value *l, Value *r)
void mkLambda (Env *e, ExprLambda *f)
void mkBlackhole ()
void mkPrimOp (PrimOp *p)
void mkPrimOpApp (Value *l, Value *r)
PrimOpprimOpAppPrimOp () const
void mkExternal (ExternalValueBase *e)
void mkFloat (NixFloat n)
bool isList () const
Value ** listElems ()
Value *const * listElems () const
size_t listSize () const
bool isTrivial () const
auto listItems ()
auto listItems () const
SourcePath path () const
std::string_view str () const

Public Attributes

union { 
   uintptr_t   _empty [2] 
   NixInt   integer 
   struct { 
      bool   boolean 
      uintptr_t   _bool_pad 
   } 
   struct { 
      const char *   s 
      const char **   context 
   }   string
   struct { 
      const char *   _path 
      uintptr_t   _path_pad 
   } 
   struct { 
      Bindings *   attrs 
      uintptr_t   _attrs_pad 
   } 
   struct { 
      size_t   size 
      Value **   elems 
   }   bigList
   Value *   smallList [2] 
   struct { 
      Env *   env 
      Expr *   expr 
   }   thunk
   struct { 
      Value *   left 
      Value *   right 
   }   app
   struct { 
      Env *   env 
      ExprLambda *   fun 
   }   lambda
   struct { 
      PrimOp *   primOp 
      uintptr_t   _primop_pad 
   } 
   struct { 
      Value *   left 
      Value *   right 
   }   primOpApp
   struct { 
      ExternalValueBase *   external 
      uintptr_t   _external_pad 
   } 
   struct { 
      NixFloat   fpoint 
      uintptr_t   _float_pad 
   } 
}; 

Static Public Attributes

static Value EMPTY_LIST {Value::list_t{}, {}}

Friends

std::string showType (const Value &v)

Constructor & Destructor Documentation

◆ Value() [1/19]

nix::Value::Value ( )
inline

Default constructor which is still used in the codebase but should not be used in new code. Zero initializes its members.

◆ Value() [2/19]

nix::Value::Value ( integer_t ,
NixInt i )
inline

Constructs a nix language value of type "int", with the integral value of i.

◆ Value() [3/19]

nix::Value::Value ( floating_t ,
NixFloat f )
inline

Constructs a nix language value of type "float", with the floating point value of f.

◆ Value() [4/19]

nix::Value::Value ( boolean_t ,
bool b )
inline

Constructs a nix language value of type "bool", with the boolean value of b.

◆ Value() [5/19]

nix::Value::Value ( string_t ,
char const * strPtr,
char const ** contextPtr = nullptr )
inline

Constructs a nix language value of type "string", with the value of the C-string pointed to by strPtr, and optionally with an array of string context pointed to by contextPtr.

Neither the C-string nor the context array are copied; this constructor assumes suitable memory has already been allocated (with the GC if enabled), and string and context data copied into that memory.

◆ Value() [6/19]

nix::Value::Value ( string_t ,
std::string_view copyFrom,
NixStringContext const & context = {} )
inline

Constructx a nix language value of type "string", with a copy of the string data viewed by copyFrom.

The string data is copied from copyFrom, and this constructor performs a dynamic (GC) allocation to do so.

◆ Value() [7/19]

nix::Value::Value ( string_t ,
char const * strPtr,
NixStringContext const & context )
inline

Constructx a nix language value of type "string", with the value of the C-string pointed to by strPtr, and optionally with a set of string context context.

The C-string is not copied; this constructor assumes suitable memory has already been allocated (with the GC if enabled), and string data has been copied into that memory. The context data is copied from context, and this constructor performs a dynamic (GC) allocation to do so.

◆ Value() [8/19]

nix::Value::Value ( path_t ,
char const * strPtr )
inline

Constructs a nix language value of type "path", with the value of the C-string pointed to by strPtr.

The C-string is not copied; this constructor assumes suitable memory has already been allocated (with the GC if enabled), and string data has been copied into that memory.

◆ Value() [9/19]

nix::Value::Value ( path_t ,
SourcePath const & path )
inline

Constructs a nix language value of type "path", with the path path.

The data from path is copied, and this constructor performs a dynamic (GC) allocation to do so.

◆ Value() [10/19]

nix::Value::Value ( list_t ,
std::span< Value * > items )
inline

Constructs a nix language value of type "list", with element array items.

Generally, the data in items is neither deep copied nor shallow copied. This construct assumes the std::span items is a region of memory that has already been allocated (with the GC if enabled), and an array of valid Value pointers has been copied into that memory.

Howver, as an implementation detail, if items is only 2 items or smaller, the list is stored inline, and the Value pointers in items are shallow copied into this structure, without dynamically allocating memory.

◆ Value() [11/19]

template<std::ranges::sized_range SizedIterableT, InvocableR< Value *, typename SizedIterableT::value_type const & > TransformerT>
nix::Value::Value ( list_t ,
SizedIterableT & items,
TransformerT const & transformer )
inline

Constructs a nix language value of type "list", with an element array initialized by applying transformer to each element in items.

This allows "in-place" construction of a nix list when some logic is needed to get each Value pointer. This constructor dynamically (GC) allocates memory for the size of items, and the Value pointers returned by transformer are shallow copied into it.

◆ Value() [12/19]

nix::Value::Value ( attrs_t ,
Bindings * bindings )
inline

Constructs a nix language value of type "set", with the attribute bindings pointed to by bindings.

The bindings are not not copied; this constructor assumes bindings has already been suitably allocated by something like nix::buildBindings.

◆ Value() [13/19]

nix::Value::Value ( thunk_t ,
Env & env,
Expr & expr )
inline

Constructs a nix language lazy delayed computation, or "thunk".

The thunk stores the environment it will be computed in env, and the expression that will need to be evaluated expr.

◆ Value() [14/19]

nix::Value::Value ( primop_t ,
PrimOp & primop )

Constructs a nix language value of type "lambda", which represents a builtin, primitive operation ("primop"), from the primop implemented by primop.

◆ Value() [15/19]

nix::Value::Value ( primOpApp_t ,
Value & lhs,
Value & rhs )
inline

Constructs a nix language value of type "lambda", which represents a partially applied primop.

◆ Value() [16/19]

nix::Value::Value ( app_t ,
Value & lhs,
Value & rhs )
inline

Constructs a nix language value of type "lambda", which represents a lazy partial application of another lambda.

◆ Value() [17/19]

nix::Value::Value ( external_t ,
ExternalValueBase & external )
inline

Constructs a nix language value of type "external", which is only used by plugins. Do any existing plugins even use this mechanism?

◆ Value() [18/19]

nix::Value::Value ( lambda_t ,
Env & env,
ExprLambda & lambda )
inline

Constructs a nix language value of type "lambda", which represents a run of the mill lambda defined in nix code.

This takes the environment the lambda is closed over env, and the lambda expression itself lambda, which will not be evaluated until it is applied.

◆ Value() [19/19]

nix::Value::Value ( Value && rhs)
inline

Move constructor. Does the same thing as the copy constructor, but also zeroes out the other Value.

Member Function Documentation

◆ clearValue()

void nix::Value::clearValue ( )
inline

After overwriting an app node, be sure to clear pointers in the Value to ensure that the target isn't kept alive unnecessarily.

◆ isTrivial()

bool nix::Value::isTrivial ( ) const

Check whether forcing this value requires a trivial amount of computation. In particular, function applications are non-trivial.

◆ operator=()

Value & nix::Value::operator= ( Value && rhs)
inline

Move assignment operator. Does the same thing as the copy assignment operator, but also zeroes out the rhs.

◆ primOpAppPrimOp()

PrimOp * nix::Value::primOpAppPrimOp ( ) const

For a tPrimOpApp value, get the original PrimOp value.

◆ type()

ValueType nix::Value::type ( bool invalidIsThunk = false) const
inline

Returns the normal type of a Value. This only returns nThunk if the Value hasn't been forceValue'd

Parameters
invalidIsThunkInstead of aborting an an invalid (probably 0, so uninitialized) internal type, return nThunk.

Member Data Documentation

◆ _empty

uintptr_t nix::Value::_empty[2]

Dummy field, which takes up as much space as the largest union variants to set the union's memory to zeroed memory.

◆ EMPTY_LIST

Value nix::Value::EMPTY_LIST {Value::list_t{}, {}}
static

Empty list constant.

◆ [struct]

struct { ... } nix::Value::string

Strings in the evaluator carry a so-called context which is a list of strings representing store paths. This is to allow users to write things like

"--with-freetype2-library=" + freetype + "/lib"

where freetype is a derivation (or a source to be copied to the store). If we just concatenated the strings without keeping track of the referenced store paths, then if the string is used as a derivation attribute, the derivation will not have the correct dependencies in its inputDrvs and inputSrcs.

The semantics of the context is as follows: when a string with context C is used as a derivation attribute, then the derivations in C will be added to the inputDrvs of the derivation, and the other store paths in C will be added to the inputSrcs of the derivations.

For canonicity, the store paths should be in sorted order.


The documentation for this struct was generated from the following files:
  • lix/libexpr/value.hh
  • lix/libexpr/attr-set.cc
  • lix/libexpr/value.cc