Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create some type aliases for string Contexts #6235

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ struct AttrDb
return {{rowId, attrs}};
}
case AttrType::String: {
std::vector<std::pair<Path, std::string>> context;
NixStringContext context;
if (!queryAttribute.isNull(3))
for (auto & s : tokenizeString<std::vector<std::string>>(queryAttribute.getStr(3), ";"))
context.push_back(decodeContext(s));
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-cache.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct misc_t {};
struct failed_t {};
typedef uint64_t AttrId;
typedef std::pair<AttrId, Symbol> AttrKey;
typedef std::pair<std::string, std::vector<std::pair<Path, std::string>>> string_t;
typedef std::pair<std::string, NixStringContext> string_t;

typedef std::variant<
std::vector<Symbol>,
Expand Down
6 changes: 3 additions & 3 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ std::string_view EvalState::forceString(Value & v, const Pos & pos)

/* Decode a context string ‘!<name>!<path>’ into a pair <path,
name>. */
std::pair<std::string, std::string> decodeContext(std::string_view s)
NixStringContextElem decodeContext(std::string_view s)
{
if (s.at(0) == '!') {
size_t index = s.find("!", 1);
Expand All @@ -1921,9 +1921,9 @@ void copyContext(const Value & v, PathSet & context)
}


std::vector<std::pair<Path, std::string>> Value::getContext()
NixStringContext Value::getContext()
{
std::vector<std::pair<Path, std::string>> res;
NixStringContext res;
assert(internalType == tString);
if (string.context)
for (const char * * p = string.context; *p; ++p)
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ std::string showType(const Value & v);

/* Decode a context string ‘!<name>!<path>’ into a pair <path,
name>. */
std::pair<std::string, std::string> decodeContext(std::string_view s);
NixStringContextElem decodeContext(std::string_view s);

/* If `path' refers to a directory, then append "/default.nix". */
Path resolveExprPath(Path path);
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/primops/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static void prim_getContext(EvalState & state, const Pos & pos, Value * * args,
drv = std::string(p, 1);
path = &drv;
} else if (p.at(0) == '!') {
std::pair<std::string, std::string> ctx = decodeContext(p);
NixStringContextElem ctx = decodeContext(p);
drv = ctx.first;
output = ctx.second;
path = &drv;
Expand Down
4 changes: 3 additions & 1 deletion src/libexpr/value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class JSONPlaceholder;

typedef int64_t NixInt;
typedef double NixFloat;
typedef std::pair<Path, std::string> NixStringContextElem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove this and use NixStringContext::value_type instead? Doesn’t change much, but I find it more explicit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe it should be this way to be consistent with SearchPathElem. which I had completely forgotten about in the time since I first wrote this code.

typedef std::vector<NixStringContextElem> NixStringContext;

/* External values must descend from ExternalValueBase, so that
* type-agnostic nix functions (e.g. showType) can be implemented
Expand Down Expand Up @@ -368,7 +370,7 @@ public:
non-trivial. */
bool isTrivial() const;

std::vector<std::pair<Path, std::string>> getContext();
NixStringContext getContext();

auto listItems()
{
Expand Down