1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 14:21:48 +02:00

Merge remote-tracking branch 'origin/master' into flake-substitution

This commit is contained in:
Eelco Dolstra 2024-11-11 13:57:24 +01:00
commit 67a42e6240
37 changed files with 299 additions and 143 deletions

View file

@ -26,7 +26,7 @@ struct ExtraPathInfoFlake : ExtraPathInfoValue
Flake flake;
ExtraPathInfoFlake(Value && v, Flake && f)
: ExtraPathInfoValue(std::move(v)), flake(f)
: ExtraPathInfoValue(std::move(v)), flake(std::move(f))
{ }
};

View file

@ -59,7 +59,7 @@ struct ExtraPathInfoValue : ExtraPathInfo
Value value;
ExtraPathInfoValue(Value && v)
: value(v)
: value(std::move(v))
{ }
virtual ~ExtraPathInfoValue() = default;

View file

@ -857,6 +857,7 @@ std::vector<FlakeRef> RawInstallablesCommand::getFlakeRefsForCompletion()
{
applyDefaultInstallables(rawInstallables);
std::vector<FlakeRef> res;
res.reserve(rawInstallables.size());
for (auto i : rawInstallables)
res.push_back(parseFlakeRefWithFragment(
fetchSettings,

View file

@ -1736,7 +1736,7 @@ void EvalState::incrFunctionCall(ExprLambda * fun)
}
void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res)
void EvalState::autoCallFunction(const Bindings & args, Value & fun, Value & res)
{
auto pos = fun.determinePos(noPos);

View file

@ -703,7 +703,7 @@ public:
* Automatically call a function for which each argument has a
* default value or has a binding in the `args` map.
*/
void autoCallFunction(Bindings & args, Value & fun, Value & res);
void autoCallFunction(const Bindings & args, Value & fun, Value & res);
/**
* Allocation primitives.

View file

@ -91,6 +91,7 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS
/* Build/substitute the context. */
std::vector<DerivedPath> buildReqs;
buildReqs.reserve(drvs.size());
for (auto & d : drvs) buildReqs.emplace_back(DerivedPath { d });
buildStore->buildPaths(buildReqs, bmNormal, store);

View file

@ -141,7 +141,9 @@ public:
Value * * elems;
ListBuilder(EvalState & state, size_t size);
ListBuilder(ListBuilder && x)
// NOTE: Can be noexcept because we are just copying integral values and
// raw pointers.
ListBuilder(ListBuilder && x) noexcept
: size(x.size)
, inlineElems{x.inlineElems[0], x.inlineElems[1]}
, elems(size <= 2 ? inlineElems : x.elems)

View file

@ -66,6 +66,7 @@ std::vector<KeyedBuildResult> Store::buildPathsWithResults(
worker.run(goals);
std::vector<KeyedBuildResult> results;
results.reserve(state.size());
for (auto & [req, goalPtr] : state)
results.emplace_back(KeyedBuildResult {

View file

@ -298,6 +298,10 @@ struct BasicDerivation
std::string name;
BasicDerivation() = default;
BasicDerivation(BasicDerivation &&) = default;
BasicDerivation(const BasicDerivation &) = default;
BasicDerivation& operator=(BasicDerivation &&) = default;
BasicDerivation& operator=(const BasicDerivation &) = default;
virtual ~BasicDerivation() { };
bool isBuiltin() const;

View file

@ -153,7 +153,7 @@ struct curlFileTransfer : public FileTransfer
template<class T>
void fail(T && e)
{
failEx(std::make_exception_ptr(std::move(e)));
failEx(std::make_exception_ptr(std::forward<T>(e)));
}
LambdaSink finalSink;

View file

@ -33,7 +33,7 @@ Machine::Machine(
systemTypes(systemTypes),
sshKey(sshKey),
maxJobs(maxJobs),
speedFactor(speedFactor == 0.0f ? 1.0f : std::move(speedFactor)),
speedFactor(speedFactor == 0.0f ? 1.0f : speedFactor),
supportedFeatures(supportedFeatures),
mandatoryFeatures(mandatoryFeatures),
sshPublicHostKey(sshPublicHostKey)

View file

@ -176,17 +176,18 @@ struct ValidPathInfo : UnkeyedValidPathInfo {
*/
Strings shortRefs() const;
ValidPathInfo(const ValidPathInfo & other) = default;
ValidPathInfo(StorePath && path, UnkeyedValidPathInfo info) : UnkeyedValidPathInfo(info), path(std::move(path)) { };
ValidPathInfo(const StorePath & path, UnkeyedValidPathInfo info) : UnkeyedValidPathInfo(info), path(path) { };
ValidPathInfo(const Store & store,
std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
virtual ~ValidPathInfo() { }
};
static_assert(std::is_move_assignable_v<ValidPathInfo>);
static_assert(std::is_copy_assignable_v<ValidPathInfo>);
static_assert(std::is_copy_constructible_v<ValidPathInfo>);
static_assert(std::is_move_constructible_v<ValidPathInfo>);
using ValidPathInfos = std::map<StorePath, ValidPathInfo>;
}

View file

@ -37,6 +37,7 @@ DerivedPath StorePathWithOutputs::toDerivedPath() const
std::vector<DerivedPath> toDerivedPaths(const std::vector<StorePathWithOutputs> ss)
{
std::vector<DerivedPath> reqs;
reqs.reserve(ss.size());
for (auto & s : ss) reqs.push_back(s.toDerivedPath());
return reqs;
}

View file

@ -40,7 +40,7 @@ struct RemoteStore::ConnectionHandle
: handle(std::move(handle))
{ }
ConnectionHandle(ConnectionHandle && h)
ConnectionHandle(ConnectionHandle && h) noexcept
: handle(std::move(h.handle))
{ }

View file

@ -42,7 +42,8 @@ struct SQLite
SQLite(const Path & path, SQLiteOpenMode mode = SQLiteOpenMode::Normal);
SQLite(const SQLite & from) = delete;
SQLite& operator = (const SQLite & from) = delete;
SQLite& operator = (SQLite && from) { db = from.db; from.db = 0; return *this; }
// NOTE: This is noexcept since we are only copying and assigning raw pointers.
SQLite& operator = (SQLite && from) noexcept { db = from.db; from.db = 0; return *this; }
~SQLite();
operator sqlite3 * () { return db; }

View file

@ -21,7 +21,9 @@ public:
Callback(std::function<void(std::future<T>)> fun) : fun(fun) { }
Callback(Callback && callback) : fun(std::move(callback.fun))
// NOTE: std::function is noexcept move-constructible since C++20.
Callback(Callback && callback) noexcept(std::is_nothrow_move_constructible_v<decltype(fun)>)
: fun(std::move(callback.fun))
{
auto prev = callback.done.test_and_set();
if (prev) done.test_and_set();

View file

@ -35,7 +35,7 @@ ExecutablePath ExecutablePath::parse(const OsString & path)
std::make_move_iterator(strings.begin()),
std::make_move_iterator(strings.end()),
std::back_inserter(ret),
[](auto && str) {
[](OsString && str) {
return fs::path{
str.empty()
// "A zero-length prefix is a legacy feature that
@ -56,6 +56,7 @@ ExecutablePath ExecutablePath::parse(const OsString & path)
OsString ExecutablePath::render() const
{
std::vector<PathViewNG> path2;
path2.reserve(directories.size());
for (auto & p : directories)
path2.push_back(p.native());
return basicConcatStringsSep(path_var_separator, path2);

View file

@ -45,8 +45,9 @@ AutoCloseFD::AutoCloseFD() : fd{INVALID_DESCRIPTOR} {}
AutoCloseFD::AutoCloseFD(Descriptor fd) : fd{fd} {}
AutoCloseFD::AutoCloseFD(AutoCloseFD && that) : fd{that.fd}
// NOTE: This can be noexcept since we are just copying a value and resetting
// the file descriptor in the rhs.
AutoCloseFD::AutoCloseFD(AutoCloseFD && that) noexcept : fd{that.fd}
{
that.fd = INVALID_DESCRIPTOR;
}

View file

@ -155,7 +155,7 @@ public:
AutoCloseFD();
AutoCloseFD(Descriptor fd);
AutoCloseFD(const AutoCloseFD & fd) = delete;
AutoCloseFD(AutoCloseFD&& fd);
AutoCloseFD(AutoCloseFD&& fd) noexcept;
~AutoCloseFD();
AutoCloseFD& operator =(const AutoCloseFD & fd) = delete;
AutoCloseFD& operator =(AutoCloseFD&& fd);

View file

@ -20,7 +20,11 @@ public:
// Copying Finallys is definitely not a good idea and will cause them to be
// called twice.
Finally(Finally &other) = delete;
Finally(Finally &&other) : fun(std::move(other.fun)) {
// NOTE: Move constructor can be nothrow if the callable type is itself nothrow
// move-constructible.
Finally(Finally && other) noexcept(std::is_nothrow_move_constructible_v<Fn>)
: fun(std::move(other.fun))
{
other.movedFrom = true;
}
~Finally() noexcept(false)

View file

@ -109,7 +109,15 @@ public:
Handle(Pool & pool, std::shared_ptr<R> r) : pool(pool), r(r) { }
public:
Handle(Handle && h) : pool(h.pool), r(h.r) { h.r.reset(); }
// NOTE: Copying std::shared_ptr and calling a .reset() on it is always noexcept.
Handle(Handle && h) noexcept
: pool(h.pool)
, r(h.r)
{
static_assert(noexcept(h.r.reset()));
static_assert(noexcept(std::shared_ptr(h.r)));
h.r.reset();
}
Handle(const Handle & l) = delete;

View file

@ -9,7 +9,7 @@ Pos::Pos(const Pos * other)
}
line = other->line;
column = other->column;
origin = std::move(other->origin);
origin = other->origin;
}
Pos::operator std::shared_ptr<Pos>() const

View file

@ -18,11 +18,6 @@ private:
std::shared_ptr<T> p;
public:
ref(const ref<T> & r)
: p(r.p)
{ }
explicit ref(const std::shared_ptr<T> & p)
: p(p)
{
@ -75,8 +70,6 @@ public:
return ref<T2>((std::shared_ptr<T2>) p);
}
ref<T> & operator=(ref<T> const & rhs) = default;
bool operator == (const ref<T> & other) const
{
return p == other.p;

View file

@ -610,6 +610,7 @@ struct CmdDevelop : Common, MixEnvironment
else if (!command.empty()) {
std::vector<std::string> args;
args.reserve(command.size());
for (auto s : command)
args.push_back(shellEscape(s));
script += fmt("exec %s\n", concatStringsSep(" ", args));