From 2868acb4a54c9f09ee94289e950da31aa1b5d541 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 2 Jun 2022 17:01:28 +0200 Subject: [PATCH 1/5] tests/flakes.sh: Fix some ignored breakage --- tests/flakes.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/flakes.sh b/tests/flakes.sh index 9a1f0ab6a..36bffcf3b 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -32,7 +32,7 @@ for repo in $flake1Dir $flake2Dir $flake3Dir $flake7Dir $templatesDir $nonFlakeD rm -rf $repo $repo.tmp mkdir -p $repo - # Give one repo a non-master initial branch. + # Give one repo a non-main initial branch. extraArgs= if [[ $repo == $flake2Dir ]]; then extraArgs="--initial-branch=main" @@ -173,11 +173,11 @@ nix build -o $TEST_ROOT/result $flake2Dir#bar --no-write-lock-file nix build -o $TEST_ROOT/result $flake2Dir#bar --no-update-lock-file 2>&1 | grep 'requires lock file changes' nix build -o $TEST_ROOT/result $flake2Dir#bar --commit-lock-file [[ -e $flake2Dir/flake.lock ]] -[[ -z $(git -C $flake2Dir diff master) ]] +[[ -z $(git -C $flake2Dir diff main || echo failed) ]] # Rerunning the build should not change the lockfile. nix build -o $TEST_ROOT/result $flake2Dir#bar -[[ -z $(git -C $flake2Dir diff master) ]] +[[ -z $(git -C $flake2Dir diff main || echo failed) ]] # Building with a lockfile should not require a fetch of the registry. nix build -o $TEST_ROOT/result --flake-registry file:///no-registry.json $flake2Dir#bar --refresh @@ -186,7 +186,7 @@ nix build -o $TEST_ROOT/result --no-use-registries $flake2Dir#bar --refresh # Updating the flake should not change the lockfile. nix flake lock $flake2Dir -[[ -z $(git -C $flake2Dir diff master) ]] +[[ -z $(git -C $flake2Dir diff main || echo failed) ]] # Now we should be able to build the flake in pure mode. nix build -o $TEST_ROOT/result flake2#bar @@ -221,7 +221,7 @@ nix build -o $TEST_ROOT/result $flake3Dir#"sth sth" nix build -o $TEST_ROOT/result $flake3Dir#"sth%20sth" # Check whether it saved the lockfile -(! [[ -z $(git -C $flake3Dir diff master) ]]) +[[ -n $(git -C $flake3Dir diff master) ]] git -C $flake3Dir add flake.lock @@ -321,10 +321,10 @@ nix build -o $TEST_ROOT/result flake4#xyzzy # Test 'nix flake update' and --override-flake. nix flake lock $flake3Dir -[[ -z $(git -C $flake3Dir diff master) ]] +[[ -z $(git -C $flake3Dir diff master || echo failed) ]] nix flake update $flake3Dir --override-flake flake2 nixpkgs -[[ ! -z $(git -C $flake3Dir diff master) ]] +[[ ! -z $(git -C $flake3Dir diff master || echo failed) ]] # Make branch "removeXyzzy" where flake3 doesn't have xyzzy anymore git -C $flake3Dir checkout -b removeXyzzy From 81a486c607405027914d1f445bb570f19a4977b7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 2 Jun 2022 16:55:28 +0200 Subject: [PATCH 2/5] Shut up clang warnings --- src/libexpr/eval.hh | 4 ++-- src/libexpr/nixexpr.hh | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 7b8732169..4eaa3c9b0 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -150,7 +150,7 @@ public: if (debugRepl) runDebugRepl(&error, env, expr); - throw error; + throw std::move(error); } template @@ -165,7 +165,7 @@ public: runDebugRepl(&e, last.env, last.expr); } - throw e; + throw std::move(e); } diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 8813c61a9..5eb022770 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -150,16 +150,16 @@ struct Expr }; #define COMMON_METHODS \ - void show(const SymbolTable & symbols, std::ostream & str) const; \ - void eval(EvalState & state, Env & env, Value & v); \ - void bindVars(EvalState & es, const std::shared_ptr & env); + void show(const SymbolTable & symbols, std::ostream & str) const override; \ + void eval(EvalState & state, Env & env, Value & v) override; \ + void bindVars(EvalState & es, const std::shared_ptr & env) override; struct ExprInt : Expr { NixInt n; Value v; ExprInt(NixInt n) : n(n) { v.mkInt(n); }; - Value * maybeThunk(EvalState & state, Env & env); + Value * maybeThunk(EvalState & state, Env & env) override; COMMON_METHODS }; @@ -168,7 +168,7 @@ struct ExprFloat : Expr NixFloat nf; Value v; ExprFloat(NixFloat nf) : nf(nf) { v.mkFloat(nf); }; - Value * maybeThunk(EvalState & state, Env & env); + Value * maybeThunk(EvalState & state, Env & env) override; COMMON_METHODS }; @@ -177,7 +177,7 @@ struct ExprString : Expr std::string s; Value v; ExprString(std::string s) : s(std::move(s)) { v.mkString(this->s.data()); }; - Value * maybeThunk(EvalState & state, Env & env); + Value * maybeThunk(EvalState & state, Env & env) override; COMMON_METHODS }; @@ -186,7 +186,7 @@ struct ExprPath : Expr std::string s; Value v; ExprPath(std::string s) : s(std::move(s)) { v.mkPath(this->s.c_str()); }; - Value * maybeThunk(EvalState & state, Env & env); + Value * maybeThunk(EvalState & state, Env & env) override; COMMON_METHODS }; @@ -213,7 +213,7 @@ struct ExprVar : Expr ExprVar(Symbol name) : name(name) { }; ExprVar(const PosIdx & pos, Symbol name) : pos(pos), name(name) { }; - Value * maybeThunk(EvalState & state, Env & env); + Value * maybeThunk(EvalState & state, Env & env) override; PosIdx getPos() const override { return pos; } COMMON_METHODS }; @@ -326,7 +326,7 @@ struct ExprLambda : Expr : pos(pos), formals(formals), body(body) { } - void setName(Symbol name); + void setName(Symbol name) override; std::string showNamePos(const EvalState & state) const; inline bool hasFormals() const { return formals != nullptr; } PosIdx getPos() const override { return pos; } @@ -395,15 +395,15 @@ struct ExprOpNot : Expr Expr * e1, * e2; \ name(Expr * e1, Expr * e2) : e1(e1), e2(e2) { }; \ name(const PosIdx & pos, Expr * e1, Expr * e2) : pos(pos), e1(e1), e2(e2) { }; \ - void show(const SymbolTable & symbols, std::ostream & str) const \ + void show(const SymbolTable & symbols, std::ostream & str) const override \ { \ str << "("; e1->show(symbols, str); str << " " s " "; e2->show(symbols, str); str << ")"; \ } \ - void bindVars(EvalState & es, const std::shared_ptr & env) \ + void bindVars(EvalState & es, const std::shared_ptr & env) override \ { \ e1->bindVars(es, env); e2->bindVars(es, env); \ } \ - void eval(EvalState & state, Env & env, Value & v); \ + void eval(EvalState & state, Env & env, Value & v) override; \ PosIdx getPos() const override { return pos; } \ }; From 24b3a500a747cb984001c3ca4384525583966692 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 31 May 2022 15:32:46 +0200 Subject: [PATCH 3/5] Typo --- tests/fetchTree-file.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fetchTree-file.sh b/tests/fetchTree-file.sh index 1c0ce39ce..f0c530466 100644 --- a/tests/fetchTree-file.sh +++ b/tests/fetchTree-file.sh @@ -58,7 +58,7 @@ EOF nix eval --file - < Date: Mon, 9 May 2022 14:28:27 +0200 Subject: [PATCH 4/5] Add operator for concatenating strings and string_views --- src/libutil/util.hh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 09ccfa591..16fa6c54c 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -700,4 +700,19 @@ template overloaded(Ts...) -> overloaded; std::string showBytes(uint64_t bytes); +/* Provide an addition operator between strings and string_views + inexplicably omitted from the standard library. */ +inline std::string operator + (const std::string & s1, std::string_view s2) +{ + auto s = s1; + s.append(s2); + return s; +} + +inline std::string operator + (std::string && s, std::string_view s2) +{ + s.append(s2); + return s; +} + } From 28e08822a360d396260cec42d92704a3663e6aa9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 2 Jun 2022 16:48:53 +0200 Subject: [PATCH 5/5] Avoid unnecessary string copy --- src/libutil/util.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 16fa6c54c..90418b04d 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -712,7 +712,7 @@ inline std::string operator + (const std::string & s1, std::string_view s2) inline std::string operator + (std::string && s, std::string_view s2) { s.append(s2); - return s; + return std::move(s); } }