Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
value.hh File Reference
#include <bit>
#include <cassert>
#include <cstddef>
#include <cstring>
#include <memory>
#include <memory_resource>
#include <exception>
#include <span>
#include <string_view>
#include <type_traits>
#include <concepts>
#include "nix/expr/eval-gc.hh"
#include "nix/expr/value/context.hh"
#include "nix/util/source-path.hh"
#include "nix/expr/print-options.hh"
#include "nix/util/checked-arithmetic.hh"
#include "nix/util/pos-idx.hh"
#include <boost/unordered/unordered_flat_map_fwd.hpp>
#include <nlohmann/json_fwd.hpp>

Go to the source code of this file.

Classes

class  nix::ExternalValueBase
class  nix::ListBuilder
class  nix::StringData
struct  nix::detail::ValueBase
struct  nix::detail::ValueBase::Symbol
struct  nix::detail::ValueBase::StringWithContext
struct  nix::detail::ValueBase::StringWithContext::Context
struct  nix::detail::ValueBase::Path
struct  nix::detail::ValueBase::Null
struct  nix::detail::ValueBase::ClosureThunk
struct  nix::detail::ValueBase::FunctionApplicationThunk
struct  nix::detail::ValueBase::PrimOpApplicationThunk
struct  nix::detail::ValueBase::Lambda
struct  nix::detail::ValueBase::List
struct  nix::detail::ValueBase::ExceptionRef
struct  nix::detail::ValueBase::Failed
struct  nix::detail::PayloadTypeToInternalType< T >
struct  nix::detail::PayloadTypeToInternalType< NixInt >
struct  nix::detail::PayloadTypeToInternalType< bool >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::StringWithContext >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::Path >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::Null >
struct  nix::detail::PayloadTypeToInternalType< const Bindings * >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::List >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::Symbol >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::SmallList >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::ClosureThunk >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::FunctionApplicationThunk >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::Lambda >
struct  nix::detail::PayloadTypeToInternalType< PrimOp * >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::PrimOpApplicationThunk >
struct  nix::detail::PayloadTypeToInternalType< ExternalValueBase * >
struct  nix::detail::PayloadTypeToInternalType< ValueBase::Failed * >
struct  nix::detail::PayloadTypeToInternalType< NixFloat >
class  nix::ValueStorage< ptrSize, Enable >
class  nix::ValueStorage< ptrSize, std::enable_if_t< detail::useBitPackedValueStorage< ptrSize > > >
class  nix::ListView
class  nix::ListView::iterator
struct  nix::Value

Macros

#define NIX_VALUE_STORAGE_FOR_EACH_FIELD(MACRO)
#define NIX_VALUE_PAYLOAD_TYPE(T, FIELD_NAME, DISCRIMINATOR)
#define NIX_VALUE_STORAGE_DEFINE_FIELD(T, FIELD_NAME, DISCRIMINATOR)
#define NIX_VALUE_STORAGE_GET_IMPL(K, FIELD_NAME, DISCRIMINATOR)
#define NIX_VALUE_STORAGE_SET_IMPL(K, FIELD_NAME, DISCRIMINATOR)
#define NIX_VALUE_STORAGE_DEF_PAIR_OF_PTRS(TYPE, MEMBER_A, MEMBER_B)

Typedefs

using nix::NixInt = checked::Checked<int64_t>
using nix::NixFloat = double
typedef std::vector< Value *, traceable_allocator< Value * > > nix::ValueVector
typedef boost::unordered_flat_map< Symbol, Value *, std::hash< Symbol >, std::equal_to< Symbol >, traceable_allocator< std::pair< const Symbol, Value * > > > nix::ValueMap
typedef std::map< Symbol, ValueVector, std::less< Symbol >, traceable_allocator< std::pair< const Symbol, ValueVector > > > nix::ValueVectorMap
typedef std::shared_ptr< Value * > nix::RootValue

Enumerations

enum  nix::InternalType {
  tUninitialized = 0 , tInt = 1 , tBool , tNull ,
  tFloat , tFailed , tExternal , tPrimOp ,
  tAttrs , tFirstPairOfPointers , tListSmall = tFirstPairOfPointers , tString ,
  tPath , tPrimOpApp , tApp , tThunk ,
  tLambda , tLastPairOfPointers = tLambda , tFirstSingleUntaggable , tListN = tFirstSingleUntaggable ,
  tSymbol , tNumberOfInternalTypes
}
enum  nix::ValueType {
  nThunk , nFailed , nInt , nFloat ,
  nBool , nString , nPath , nNull ,
  nAttrs , nList , nFunction , nExternal
}

Functions

std::ostream & nix::operator<< (std::ostream &str, const ExternalValueBase &v)
RootValue nix::allocRootValue (Value *v)
void nix::throwNullByteError (std::string_view s, const PosTable *positions, PosIdx pos)
void nix::forceNoNullByte (std::string_view s, const PosTable *positions=nullptr, PosIdx pos=noPos)

Variables

template<typename T>
constexpr InternalType nix::detail::payloadTypeToInternalType = PayloadTypeToInternalType<T>::value
template<std::size_t ptrSize>
constexpr bool nix::detail::useBitPackedValueStorage = (ptrSize == 8) && (__STDCPP_DEFAULT_NEW_ALIGNMENT__ >= 16)

Macro Definition Documentation

◆ NIX_VALUE_PAYLOAD_TYPE

#define NIX_VALUE_PAYLOAD_TYPE ( T,
FIELD_NAME,
DISCRIMINATOR )
Value:
template<> \
struct PayloadTypeToInternalType<T> \
{ \
static constexpr InternalType value = DISCRIMINATOR; \
};

◆ NIX_VALUE_STORAGE_DEF_PAIR_OF_PTRS

#define NIX_VALUE_STORAGE_DEF_PAIR_OF_PTRS ( TYPE,
MEMBER_A,
MEMBER_B )
Value:
\
void getStorage(TYPE & val) const noexcept \
{ \
getPairOfPointersPayload(val MEMBER_A, val MEMBER_B); \
} \
\
void setStorage(TYPE val) noexcept \
{ \
setPairOfPointersPayload<detail::payloadTypeToInternalType<TYPE>>(val MEMBER_A, val MEMBER_B); \
}

◆ NIX_VALUE_STORAGE_DEFINE_FIELD

#define NIX_VALUE_STORAGE_DEFINE_FIELD ( T,
FIELD_NAME,
DISCRIMINATOR )
Value:
T FIELD_NAME;

◆ NIX_VALUE_STORAGE_FOR_EACH_FIELD

#define NIX_VALUE_STORAGE_FOR_EACH_FIELD ( MACRO)
Value:
MACRO(NixInt, integer, tInt) \
MACRO(bool, boolean, tBool) \
MACRO(ValueBase::StringWithContext, string, tString) \
MACRO(ValueBase::Path, path, tPath) \
MACRO(ValueBase::Null, null_, tNull) \
MACRO(const Bindings *, attrs, tAttrs) \
MACRO(ValueBase::List, bigList, tListN) \
MACRO(ValueBase::Symbol, symbol, tSymbol) \
MACRO(ValueBase::SmallList, smallList, tListSmall) \
MACRO(ValueBase::ClosureThunk, thunk, tThunk) \
MACRO(ValueBase::FunctionApplicationThunk, app, tApp) \
MACRO(ValueBase::Lambda, lambda, tLambda) \
MACRO(PrimOp *, primOp, tPrimOp) \
MACRO(ValueBase::PrimOpApplicationThunk, primOpApp, tPrimOpApp) \
MACRO(ExternalValueBase *, external, tExternal) \
MACRO(ValueBase::Failed *, failed, tFailed) \
MACRO(NixFloat, fpoint, tFloat)

All stored types must be distinct (not type aliases) for the purposes of overload resolution in setStorage. This ensures there's a bijection from InternalType <-> C++ type.

◆ NIX_VALUE_STORAGE_GET_IMPL

#define NIX_VALUE_STORAGE_GET_IMPL ( K,
FIELD_NAME,
DISCRIMINATOR )
Value:
void getStorage(K & val) const noexcept \
{ \
assert(internalType == DISCRIMINATOR); \
val = payload.FIELD_NAME; \
}

◆ NIX_VALUE_STORAGE_SET_IMPL

#define NIX_VALUE_STORAGE_SET_IMPL ( K,
FIELD_NAME,
DISCRIMINATOR )
Value:
void setStorage(K val) noexcept \
{ \
payload.FIELD_NAME = val; \
internalType = DISCRIMINATOR; \
}

Typedef Documentation

◆ RootValue

typedef std::shared_ptr<Value *> nix::RootValue

A value allocated in traceable memory.

Enumeration Type Documentation

◆ InternalType

Internal type discriminator, which is more detailed than ValueType, as it specifies the exact representation used (for types that have multiple possible representations).

Warning
The ordering is very significant. See ValueStorage::getInternalType() for details about how this is mapped into the alignment bits to save significant memory. This also restricts the number of internal types represented with distinct memory layouts.

◆ ValueType

This type abstracts over all actual value types in the language, grouping together implementation details like tList*, different function types, and types in non-normal form (so thunks and co.)

Function Documentation

◆ forceNoNullByte()

void nix::forceNoNullByte ( std::string_view s,
const PosTable * positions = nullptr,
PosIdx pos = noPos )
inline

Throws if s contains a null byte, which is not supported by the whole codebase yet. If positions is given, the error points at pos. The position is only resolved if the check fails.

◆ throwNullByteError()

void nix::throwNullByteError ( std::string_view s,
const PosTable * positions = nullptr,
PosIdx pos = noPos )

Throws the error for a string that contains null bytes. If positions is given, the error points at pos.