Fix tests on systems with a non-master git defaultBranch #1

Open
zebreus wants to merge 140 commits from fix-tests-without-master into main
64 changed files with 190 additions and 125 deletions
Showing only changes of commit 04f8a14833 - Show all commits

View file

@ -1,11 +1,7 @@
#include <cstdlib>
#include <cstring>
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <memory> #include <memory>
#include <string_view>
#include <tuple> #include <tuple>
#include <iomanip>
#if __APPLE__ #if __APPLE__
#include <sys/time.h> #include <sys/time.h>
#endif #endif
@ -18,6 +14,7 @@
#include "build-result.hh" #include "build-result.hh"
#include "store-api.hh" #include "store-api.hh"
#include "derivations.hh" #include "derivations.hh"
#include "strings.hh"
#include "local-store.hh" #include "local-store.hh"
#include "legacy.hh" #include "legacy.hh"
#include "experimental-features.hh" #include "experimental-features.hh"

View file

@ -1,6 +1,7 @@
#include "editor-for.hh" #include "editor-for.hh"
#include "environment-variables.hh" #include "environment-variables.hh"
#include "source-path.hh" #include "source-path.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -19,6 +19,7 @@
#include "gc-small-vector.hh" #include "gc-small-vector.hh"
#include "fetch-to-store.hh" #include "fetch-to-store.hh"
#include "flake/flakeref.hh" #include "flake/flakeref.hh"
#include "exit.hh"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>

View file

@ -12,6 +12,7 @@
#include "experimental-features.hh" #include "experimental-features.hh"
#include "search-path.hh" #include "search-path.hh"
#include "repl-exit-status.hh" #include "repl-exit-status.hh"
#include "backed-string-view.hh"
#include <map> #include <map>
#include <optional> #include <optional>
@ -791,4 +792,4 @@ static constexpr std::string_view corepkgsPrefix{"/__corepkgs__/"};
} }
#include "eval-inline.hh" #include "eval-inline.hh" // IWYU pragma: keep

View file

@ -11,6 +11,7 @@
#include "eval-error.hh" #include "eval-error.hh"
#include "pos-idx.hh" #include "pos-idx.hh"
#include "pos-table.hh" #include "pos-table.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -7,6 +7,8 @@
#include "path.hh" #include "path.hh"
#include "attrs.hh" #include "attrs.hh"
#include "url.hh" #include "url.hh"
#include "ref.hh"
#include "strings.hh"
#include <memory> #include <memory>

View file

@ -1,8 +1,9 @@
#include "progress-bar.hh" #include "progress-bar.hh"
#include "file-system.hh"
#include "sync.hh" #include "sync.hh"
#include "store-api.hh"
#include "names.hh" #include "names.hh"
#include "terminal.hh" #include "terminal.hh"
#include "strings.hh"
#include <map> #include <map>
#include <thread> #include <thread>

View file

@ -6,6 +6,8 @@
#include "loggers.hh" #include "loggers.hh"
#include "current-process.hh" #include "current-process.hh"
#include "terminal.hh" #include "terminal.hh"
#include "strings.hh"
#include "exit.hh"
#include <algorithm> #include <algorithm>
#include <exception> #include <exception>

View file

@ -7,12 +7,10 @@
#include "path.hh" #include "path.hh"
#include "derived-path.hh" #include "derived-path.hh"
#include "processes.hh" #include "processes.hh"
#include "exit.hh" #include "strings.hh"
#include <signal.h> #include <signal.h>
#include <locale>
namespace nix { namespace nix {

View file

@ -10,6 +10,7 @@
#include "nar-accessor.hh" #include "nar-accessor.hh"
#include "thread-pool.hh" #include "thread-pool.hh"
#include "signals.hh" #include "signals.hh"
#include "strings.hh"
#include <chrono> #include <chrono>
#include <regex> #include <regex>

View file

@ -9,6 +9,7 @@
#include "logging-json.hh" #include "logging-json.hh"
#include "substitution-goal.hh" #include "substitution-goal.hh"
#include "drv-output-substitution-goal.hh" #include "drv-output-substitution-goal.hh"
#include "strings.hh"
#include <fstream> #include <fstream>
#include <sys/types.h> #include <sys/types.h>

View file

@ -2,6 +2,7 @@
#include "substitution-goal.hh" #include "substitution-goal.hh"
#include "derivation-goal.hh" #include "derivation-goal.hh"
#include "local-store.hh" #include "local-store.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -2,6 +2,7 @@
#include "file-system.hh" #include "file-system.hh"
#include "globals.hh" #include "globals.hh"
#include "hook-instance.hh" #include "hook-instance.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -1,15 +1,12 @@
#include "local-derivation-goal.hh" #include "local-derivation-goal.hh"
#include "indirect-root-store.hh" #include "indirect-root-store.hh"
#include "hook-instance.hh"
#include "machines.hh" #include "machines.hh"
#include "store-api.hh" #include "store-api.hh"
#include "worker.hh" #include "worker.hh"
#include "builtins.hh" #include "builtins.hh"
#include "builtins/buildenv.hh" #include "builtins/buildenv.hh"
#include "path-references.hh" #include "path-references.hh"
#include "finally.hh"
#include "archive.hh" #include "archive.hh"
#include "compression.hh"
#include "daemon.hh" #include "daemon.hh"
#include "topo-sort.hh" #include "topo-sort.hh"
#include "json-utils.hh" #include "json-utils.hh"
@ -19,6 +16,7 @@
#include "child.hh" #include "child.hh"
#include "unix-domain-socket.hh" #include "unix-domain-socket.hh"
#include "mount.hh" #include "mount.hh"
#include "strings.hh"
#include <regex> #include <regex>
#include <queue> #include <queue>

View file

@ -1,4 +1,5 @@
#include "buildenv.hh" #include "buildenv.hh"
#include "strings.hh"
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>

View file

@ -3,6 +3,7 @@
#include "store-api.hh" #include "store-api.hh"
#include "archive.hh" #include "archive.hh"
#include "compression.hh" #include "compression.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -1,6 +1,7 @@
#include "args.hh" #include "args.hh"
#include "content-address.hh" #include "content-address.hh"
#include "split.hh" #include "split.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -2,7 +2,7 @@
#include "monitor-fd.hh" #include "monitor-fd.hh"
#include "worker-protocol.hh" #include "worker-protocol.hh"
#include "worker-protocol-impl.hh" #include "worker-protocol-impl.hh"
#include "build-result.hh" #include "build-result.hh" // IWYU pragma: keep
#include "store-api.hh" #include "store-api.hh"
#include "store-cast.hh" #include "store-cast.hh"
#include "gc-store.hh" #include "gc-store.hh"
@ -12,6 +12,7 @@
#include "finally.hh" #include "finally.hh"
#include "archive.hh" #include "archive.hh"
#include "derivations.hh" #include "derivations.hh"
#include "strings.hh"
#include "args.hh" #include "args.hh"
#include <sstream> #include <sstream>

View file

@ -3,11 +3,12 @@
#include "store-api.hh" #include "store-api.hh"
#include "globals.hh" #include "globals.hh"
#include "types.hh" #include "types.hh"
#include "split.hh"
#include "common-protocol.hh" #include "common-protocol.hh"
#include "common-protocol-impl.hh" #include "common-protocol-impl.hh"
#include "fs-accessor.hh"
#include "json-utils.hh" #include "json-utils.hh"
#include "strings.hh"
#include "backed-string-view.hh"
#include <boost/container/small_vector.hpp> #include <boost/container/small_vector.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>

View file

@ -5,6 +5,7 @@
#include "path.hh" #include "path.hh"
#include "outputs-spec.hh" #include "outputs-spec.hh"
#include "comparator.hh" #include "comparator.hh"
#include "ref.hh"
#include <variant> #include <variant>

View file

@ -5,6 +5,7 @@
#include "s3.hh" #include "s3.hh"
#include "signals.hh" #include "signals.hh"
#include "compression.hh" #include "compression.hh"
#include "strings.hh"
#if ENABLE_S3 #if ENABLE_S3
#include <aws/core/client/ClientConfiguration.h> #include <aws/core/client/ClientConfiguration.h>

View file

@ -2,6 +2,7 @@
///@file ///@file
#include "box_ptr.hh" #include "box_ptr.hh"
#include "ref.hh"
#include "logging.hh" #include "logging.hh"
#include "serialise.hh" #include "serialise.hh"
#include "types.hh" #include "types.hh"

View file

@ -5,6 +5,7 @@
#include "signals.hh" #include "signals.hh"
#include "finally.hh" #include "finally.hh"
#include "unix-domain-socket.hh" #include "unix-domain-socket.hh"
#include "strings.hh"
#include <queue> #include <queue>
#include <regex> #include <regex>

View file

@ -9,6 +9,7 @@
#include "path-with-outputs.hh" #include "path-with-outputs.hh"
#include "ssh.hh" #include "ssh.hh"
#include "ssh-store.hh" #include "ssh-store.hh"
#include "strings.hh"
#include "derivations.hh" #include "derivations.hh"
namespace nix { namespace nix {

View file

@ -10,6 +10,7 @@
#include "signals.hh" #include "signals.hh"
#include "finally.hh" #include "finally.hh"
#include "compression.hh" #include "compression.hh"
#include "strings.hh"
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>

View file

@ -1,11 +1,10 @@
#pragma once #pragma once
///@file ///@file
#include "types.hh" #include <memory>
#include <optional>
#include <sys/types.h> #include <sys/types.h>
#include <vector>
namespace nix { namespace nix {

View file

@ -1,7 +1,9 @@
#pragma once #pragma once
///@file ///@file
#include "types.hh" #include "ref.hh"
#include <set>
#include <vector>
namespace nix { namespace nix {

View file

@ -1,5 +1,6 @@
#include "make-content-addressed.hh" #include "make-content-addressed.hh"
#include "references.hh" #include "references.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -1,12 +1,12 @@
#include "derivations.hh" #include "derivations.hh"
#include "parsed-derivations.hh" #include "parsed-derivations.hh"
#include "globals.hh" #include "globals.hh"
#include "local-store.hh"
#include "store-api.hh" #include "store-api.hh"
#include "thread-pool.hh" #include "thread-pool.hh"
#include "topo-sort.hh" #include "topo-sort.hh"
#include "closure.hh" #include "closure.hh"
#include "filetransfer.hh" #include "filetransfer.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -1,10 +1,12 @@
#pragma once #pragma once
///@file ///@file
#include "fs-accessor.hh"
#include "ref.hh"
#include <functional> #include <functional>
#include <nlohmann/json_fwd.hpp> #include <nlohmann/json_fwd.hpp>
#include "fs-accessor.hh"
namespace nix { namespace nix {

View file

@ -4,6 +4,7 @@
#include "sqlite.hh" #include "sqlite.hh"
#include "globals.hh" #include "globals.hh"
#include "users.hh" #include "users.hh"
#include "strings.hh"
#include <sqlite3.h> #include <sqlite3.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>

View file

@ -1,4 +1,4 @@
#include "globals.hh" #include "strings.hh"
#include "nar-info.hh" #include "nar-info.hh"
#include "store-api.hh" #include "store-api.hh"

View file

@ -1,6 +1,7 @@
#include "local-store.hh" #include "local-store.hh"
#include "globals.hh" #include "globals.hh"
#include "signals.hh" #include "signals.hh"
#include "strings.hh"
#include <cstring> #include <cstring>
#include <sys/types.h> #include <sys/types.h>

View file

@ -1,4 +1,5 @@
#include "parsed-derivations.hh" #include "parsed-derivations.hh"
#include "strings.hh"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <regex> #include <regex>

View file

@ -1,5 +1,6 @@
#include "path-info.hh" #include "path-info.hh"
#include "store-api.hh" #include "store-api.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -1,7 +1,6 @@
#include "path-with-outputs.hh" #include "path-with-outputs.hh"
#include "store-api.hh" #include "store-api.hh"
#include "strings.hh"
#include <regex>
namespace nix { namespace nix {

View file

@ -2,6 +2,7 @@
#include "signals.hh" #include "signals.hh"
#include "platform/darwin.hh" #include "platform/darwin.hh"
#include "regex.hh" #include "regex.hh"
#include "strings.hh"
#include <sys/proc_info.h> #include <sys/proc_info.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>

View file

@ -5,6 +5,7 @@
#include "signals.hh" #include "signals.hh"
#include "platform/linux.hh" #include "platform/linux.hh"
#include "regex.hh" #include "regex.hh"
#include "strings.hh"
#include <grp.h> #include <grp.h>
#include <regex> #include <regex>

View file

@ -1,12 +1,11 @@
#include "profiles.hh" #include "profiles.hh"
#include "store-api.hh"
#include "local-fs-store.hh" #include "local-fs-store.hh"
#include "users.hh" #include "users.hh"
#include "strings.hh"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <stdio.h> #include <stdio.h>

View file

@ -15,6 +15,8 @@
#include "finally.hh" #include "finally.hh"
#include "logging.hh" #include "logging.hh"
#include "filetransfer.hh" #include "filetransfer.hh"
#include "strings.hh"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
namespace nix { namespace nix {
@ -64,7 +66,7 @@ void RemoteStore::initConnection(Connection & conn)
{ {
/* Send the magic greeting, check for the reply. */ /* Send the magic greeting, check for the reply. */
try { try {
conn.from.endOfFileError = "Nix daemon disconnected unexpectedly (maybe it crashed?)"; conn.from.specialEndOfFileError = "Nix daemon disconnected unexpectedly (maybe it crashed?)";
conn.to << WORKER_MAGIC_1; conn.to << WORKER_MAGIC_1;
conn.to.flush(); conn.to.flush();

View file

@ -7,6 +7,7 @@
#include "globals.hh" #include "globals.hh"
#include "compression.hh" #include "compression.hh"
#include "filetransfer.hh" #include "filetransfer.hh"
#include "strings.hh"
#include <aws/core/Aws.h> #include <aws/core/Aws.h>
#include <aws/core/VersionConfig.h> #include <aws/core/VersionConfig.h>

View file

@ -1,13 +1,11 @@
#include "ssh-store.hh" #include "ssh-store.hh"
#include "store-api.hh" #include "store-api.hh"
#include "local-fs-store.hh"
#include "remote-store.hh" #include "remote-store.hh"
#include "remote-store-connection.hh" #include "remote-store-connection.hh"
#include "remote-fs-accessor.hh"
#include "archive.hh"
#include "worker-protocol.hh" #include "worker-protocol.hh"
#include "pool.hh" #include "pool.hh"
#include "ssh.hh" #include "ssh.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -5,10 +5,10 @@
#include "nar-info-disk-cache.hh" #include "nar-info-disk-cache.hh"
#include "thread-pool.hh" #include "thread-pool.hh"
#include "url.hh" #include "url.hh"
#include "references.hh"
#include "archive.hh" #include "archive.hh"
#include "remote-store.hh" #include "uds-remote-store.hh"
#include "signals.hh" #include "signals.hh"
#include "strings.hh"
// FIXME this should not be here, see TODO below on // FIXME this should not be here, see TODO below on
// `addMultipleToStore`. // `addMultipleToStore`.
#include "worker-protocol.hh" #include "worker-protocol.hh"

View file

@ -1,10 +1,11 @@
#include "args.hh" #include "args.hh"
#include "args/root.hh" #include "args/root.hh"
#include "hash.hh" #include "hash.hh"
#include "json-utils.hh" #include "strings.hh"
#include "json-utils.hh" // IWYU pragma: keep (instances)
#include "environment-variables.hh" #include "environment-variables.hh"
#include "experimental-features-json.hh" #include "experimental-features-json.hh" // IWYU pragma: keep (instances)
#include "logging.hh" #include "logging.hh"
#include <glob.h> #include <glob.h>

View file

@ -3,6 +3,8 @@
#include "experimental-features.hh" #include "experimental-features.hh"
#include "types.hh" #include "types.hh"
#include "ref.hh"
#include <functional> #include <functional>
#include <map> #include <map>
#include <memory> #include <memory>

View file

@ -0,0 +1,69 @@
#pragma once
/// @file String view that can be either owned or borrowed.
#include <variant>
#include <string>
#include <string_view>
/**
* This wants to be a little bit like rust's Cow type.
* Some parts of the evaluator benefit greatly from being able to reuse
* existing allocations for strings, but have to be able to also use
* newly allocated storage for values.
*
* We do not define implicit conversions, even with ref qualifiers,
* since those can easily become ambiguous to the reader and can degrade
* into copying behaviour we want to avoid.
*/
class BackedStringView {
private:
std::variant<std::string, std::string_view> data;
/**
* Needed to introduce a temporary since operator-> must return
* a pointer. Without this we'd need to store the view object
* even when we already own a string.
*/
class Ptr {
private:
std::string_view view;
public:
Ptr(std::string_view view): view(view) {}
const std::string_view * operator->() const { return &view; }
};
public:
BackedStringView(std::string && s): data(std::move(s)) {}
BackedStringView(std::string_view sv): data(sv) {}
template<size_t N>
BackedStringView(const char (& lit)[N]): data(std::string_view(lit)) {}
BackedStringView(const BackedStringView &) = delete;
BackedStringView & operator=(const BackedStringView &) = delete;
/**
* We only want move operations defined since the sole purpose of
* this type is to avoid copies.
*/
BackedStringView(BackedStringView && other) = default;
BackedStringView & operator=(BackedStringView && other) = default;
bool isOwned() const
{
return std::holds_alternative<std::string>(data);
}
std::string toOwned() &&
{
return isOwned()
? std::move(std::get<std::string>(data))
: std::string(std::get<std::string_view>(data));
}
std::string_view operator*() const
{
return isOwned()
? std::get<std::string>(data)
: std::get<std::string_view>(data);
}
Ptr operator->() const { return Ptr(**this); }
};

View file

@ -3,6 +3,7 @@
#include "logging.hh" #include "logging.hh"
#include "position.hh" #include "position.hh"
#include "terminal.hh" #include "terminal.hh"
#include "strings.hh"
#include <iostream> #include <iostream>
#include <optional> #include <optional>

View file

@ -10,6 +10,7 @@
#include "logging.hh" #include "logging.hh"
#include "serialise.hh" #include "serialise.hh"
#include "signals.hh" #include "signals.hh"
#include "strings.hh"
#include "types.hh" #include "types.hh"
#include "users.hh" #include "users.hh"

View file

@ -10,6 +10,7 @@
#include "charptr-cast.hh" #include "charptr-cast.hh"
#include "logging.hh" #include "logging.hh"
#include "split.hh" #include "split.hh"
#include "strings.hh"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>

View file

@ -53,6 +53,7 @@ libutil_headers = files(
'archive.hh', 'archive.hh',
'args/root.hh', 'args/root.hh',
'args.hh', 'args.hh',
'backed-string-view.hh',
'box_ptr.hh', 'box_ptr.hh',
'canon-path.hh', 'canon-path.hh',
'cgroup.hh', 'cgroup.hh',

View file

@ -3,6 +3,7 @@
#include "finally.hh" #include "finally.hh"
#include "logging.hh" #include "logging.hh"
#include "processes.hh" #include "processes.hh"
#include "strings.hh"
#include "serialise.hh" #include "serialise.hh"
#include "signals.hh" #include "signals.hh"

View file

@ -1,6 +1,9 @@
#include <string> #include <string>
#include <regex> #include <regex>
// Declared as extern in precompiled-headers.hh
template class std::basic_regex<char>;
namespace nix::regex { namespace nix::regex {
std::string quoteRegexChars(const std::string & raw) std::string quoteRegexChars(const std::string & raw)
{ {

View file

@ -9,6 +9,21 @@
namespace nix { namespace nix {
namespace {
/**
* Convert a little-endian integer to host order.
*/
template<typename T>
T readLittleEndian(unsigned char * p)
{
T x = 0;
for (size_t i = 0; i < sizeof(x); ++i, ++p) {
x |= ((T) *p) << (i * 8);
}
return x;
}
}
template<typename T> template<typename T>
T readNum(Source & source) T readNum(Source & source)
{ {
@ -152,7 +167,7 @@ size_t FdSource::readUnbuffered(char * data, size_t len)
n = ::read(fd, data, len); n = ::read(fd, data, len);
} while (n == -1 && errno == EINTR); } while (n == -1 && errno == EINTR);
if (n == -1) { _good = false; throw SysError("reading from file"); } if (n == -1) { _good = false; throw SysError("reading from file"); }
if (n == 0) { _good = false; throw EndOfFile(std::string(*endOfFileError)); } if (n == 0) { _good = false; throw EndOfFile(endOfFileError()); }
read += n; read += n;
return n; return n;
} }
@ -163,6 +178,11 @@ bool FdSource::good()
return _good; return _good;
} }
std::string FdSource::endOfFileError() const
{
return specialEndOfFileError.has_value() ? *specialEndOfFileError : "unexpected end-of-file";
}
size_t StringSource::read(char * data, size_t len) size_t StringSource::read(char * data, size_t len)
{ {

View file

@ -1,12 +1,10 @@
#pragma once #pragma once
///@file ///@file
#include <concepts>
#include <memory> #include <memory>
#include "charptr-cast.hh" #include "charptr-cast.hh"
#include "generator.hh" #include "generator.hh"
#include "strings.hh"
#include "types.hh" #include "types.hh"
#include "file-descriptor.hh" #include "file-descriptor.hh"
@ -153,7 +151,10 @@ struct FdSource : BufferedSource
{ {
int fd; int fd;
size_t read = 0; size_t read = 0;
BackedStringView endOfFileError{"unexpected end-of-file"}; /** Defaults to "unexpected end-of-file" */
std::optional<std::string> specialEndOfFileError;
std::string endOfFileError() const;
FdSource() : fd(-1) { } FdSource() : fd(-1) { }
FdSource(int fd) : fd(fd) { } FdSource(int fd) : fd(fd) { }

View file

@ -1,4 +1,5 @@
#include "source-path.hh" #include "source-path.hh"
#include "strings.hh"
namespace nix { namespace nix {

View file

@ -164,19 +164,6 @@ template<class N>
std::optional<N> string2Float(const std::string_view s); std::optional<N> string2Float(const std::string_view s);
/**
* Convert a little-endian integer to host order.
*/
template<typename T>
T readLittleEndian(unsigned char * p)
{
T x = 0;
for (size_t i = 0; i < sizeof(x); ++i, ++p) {
x |= ((T) *p) << (i * 8);
}
return x;
}
/** /**
* Convert a string to lower case. * Convert a string to lower case.
*/ */

View file

@ -1,17 +1,15 @@
#pragma once #pragma once
///@file ///@file
#include "ref.hh"
#include <list> #include <list>
#include <optional> #include <optional>
#include <set> #include <set>
#include <string> #include <string>
#include <limits> #include <string_view>
#include <map> #include <map>
#include <variant>
#include <vector> #include <vector>
#include <span> #include <span>
#include <stdint.h> // IWYU pragma: keep (this is used literally everywhere)
namespace nix { namespace nix {
@ -166,70 +164,4 @@ constexpr auto enumerate(T && iterable)
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; }; template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>; template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
/**
* This wants to be a little bit like rust's Cow type.
* Some parts of the evaluator benefit greatly from being able to reuse
* existing allocations for strings, but have to be able to also use
* newly allocated storage for values.
*
* We do not define implicit conversions, even with ref qualifiers,
* since those can easily become ambiguous to the reader and can degrade
* into copying behaviour we want to avoid.
*/
class BackedStringView {
private:
std::variant<std::string, std::string_view> data;
/**
* Needed to introduce a temporary since operator-> must return
* a pointer. Without this we'd need to store the view object
* even when we already own a string.
*/
class Ptr {
private:
std::string_view view;
public:
Ptr(std::string_view view): view(view) {}
const std::string_view * operator->() const { return &view; }
};
public:
BackedStringView(std::string && s): data(std::move(s)) {}
BackedStringView(std::string_view sv): data(sv) {}
template<size_t N>
BackedStringView(const char (& lit)[N]): data(std::string_view(lit)) {}
BackedStringView(const BackedStringView &) = delete;
BackedStringView & operator=(const BackedStringView &) = delete;
/**
* We only want move operations defined since the sole purpose of
* this type is to avoid copies.
*/
BackedStringView(BackedStringView && other) = default;
BackedStringView & operator=(BackedStringView && other) = default;
bool isOwned() const
{
return std::holds_alternative<std::string>(data);
}
std::string toOwned() &&
{
return isOwned()
? std::move(std::get<std::string>(data))
: std::string(std::get<std::string_view>(data));
}
std::string_view operator*() const
{
return isOwned()
? std::get<std::string>(data)
: std::get<std::string_view>(data);
}
Ptr operator->() const { return Ptr(**this); }
};
} }

View file

@ -1,6 +1,7 @@
#include "archive.hh" #include "archive.hh"
#include "derivations.hh" #include "derivations.hh"
#include "dotgraph.hh" #include "dotgraph.hh"
#include "exit.hh"
#include "globals.hh" #include "globals.hh"
#include "build-result.hh" #include "build-result.hh"
#include "store-cast.hh" #include "store-cast.hh"
@ -17,7 +18,6 @@
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <cstdio>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>

View file

@ -7,6 +7,7 @@
#include "store-api.hh" #include "store-api.hh"
#include "local-fs-store.hh" #include "local-fs-store.hh"
#include "worker-protocol.hh" #include "worker-protocol.hh"
#include "exit.hh"
using namespace nix; using namespace nix;

View file

@ -1,10 +1,9 @@
#include "command.hh" #include "command.hh"
#include "shared.hh" #include "shared.hh"
#include "store-api.hh" #include "store-api.hh"
#include "sync.hh"
#include "thread-pool.hh" #include "thread-pool.hh"
#include "signals.hh" #include "signals.hh"
#include "references.hh" #include "exit.hh"
#include <atomic> #include <atomic>

View file

@ -58,3 +58,19 @@
#include <unistd.h> #include <unistd.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
// This stuff is here to force the compiler to actually apply the extern
// template directives in all compilation units. To borrow a term, under
// complex microarchitectural conditions, clang ignores the extern template
// declaration, as revealed in the profile.
//
// In most cases, extern template works fine in the header itself. We don't
// have any idea why this happens.
// Here because of all the regexes everywhere (it is infeasible to block instantiation everywhere)
// For some reason this does not actually prevent the instantiation of
// regex::_M_compile, and the regex compiler (my interpretation of what this is
// supposed to do is make the template bits out-of-line), but it *does* prevent
// a bunch of codegen of regex stuff, which seems to save about 30s on-cpu.
// Instantiated in libutil/regex.cc.
extern template class std::basic_regex<char>;

View file

@ -1,8 +1,8 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "experimental-features.hh"
#include "derivations.hh" #include "derivations.hh"
#include "strings.hh"
#include "tests/libstore.hh" #include "tests/libstore.hh"
#include "tests/characterization.hh" #include "tests/characterization.hh"

View file

@ -1,6 +1,7 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "strings.hh"
#include "tests/libstore.hh" #include "tests/libstore.hh"
#include "tests/characterization.hh" #include "tests/characterization.hh"

View file

@ -1,4 +1,5 @@
#include "references.hh" #include "references.hh"
#include "strings.hh"
#include <gtest/gtest.h> #include <gtest/gtest.h>
namespace nix { namespace nix {