From 7210ed1b87410a0df597c0c4efe642bf82cc2b06 Mon Sep 17 00:00:00 2001 From: piegames Date: Sun, 18 Aug 2024 16:02:23 +0200 Subject: libexpr: Soft-deprecate __overrides Change-Id: I787e69e1dad6edc5ccdb747b74a9ccd6e8e13bb3 --- src/libexpr/parser/parser.cc | 6 ++++++ src/libexpr/parser/state.hh | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'src/libexpr/parser') diff --git a/src/libexpr/parser/parser.cc b/src/libexpr/parser/parser.cc index d57c33a30..6e8ab2fe4 100644 --- a/src/libexpr/parser/parser.cc +++ b/src/libexpr/parser/parser.cc @@ -676,6 +676,12 @@ template<> struct BuildAST : change_head struct BuildAST : change_head { static void success(const auto & in, BindingsState & b, ExprState & s, State & ps) { + // Before inserting new attrs, check for __override and throw an error + // (the error will initially be a warning to ease migration) + if (!featureSettings.isEnabled(Dep::RecSetOverrides) && b.attrs.attrs.contains(ps.s.overrides)) { + ps.overridesFound(ps.at(in)); + } + b.attrs.pos = ps.at(in); b.attrs.recursive = true; s.pushExpr(b.attrs.pos, std::move(b.attrs)); diff --git a/src/libexpr/parser/state.hh b/src/libexpr/parser/state.hh index 9dddd28e1..1d57e2f5f 100644 --- a/src/libexpr/parser/state.hh +++ b/src/libexpr/parser/state.hh @@ -2,6 +2,7 @@ ///@file #include "eval.hh" +#include "logging.hh" namespace nix::parser { @@ -23,6 +24,7 @@ struct State void dupAttr(const AttrPath & attrPath, const PosIdx pos, const PosIdx prevPos); void dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos); + void overridesFound(const PosIdx pos); void addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_ptr e, const PosIdx pos); std::unique_ptr validateFormals(std::unique_ptr formals, PosIdx pos = noPos, Symbol arg = {}); std::unique_ptr stripIndentation(const PosIdx pos, @@ -58,6 +60,17 @@ inline void State::dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos) }); } +inline void State::overridesFound(const PosIdx pos) { + // Added 2024-09-18. Turn into an error at some point in the future. + // See the documentation on deprecated features for more details. + warn( + "%s found at %s. This feature is deprecated and will be removed in the future. Use %s to silence this warning.", + "__overrides", + positions[pos], + "--extra-deprecated-features rec-set-overrides" + ); +} + inline void State::addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_ptr e, const PosIdx pos) { AttrPath::iterator i; @@ -123,6 +136,12 @@ inline void State::addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_ dupAttr(attrPath, pos, j->second.pos); } } else { + // Before inserting new attrs, check for __override and throw an error + // (the error will initially be a warning to ease migration) + if (attrs->recursive && !featureSettings.isEnabled(Dep::RecSetOverrides) && i->symbol == s.overrides) { + overridesFound(pos); + } + // This attr path is not defined. Let's create it. e->setName(i->symbol); attrs->attrs.emplace(std::piecewise_construct, -- cgit v1.2.3