mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
Merge pull request #11082 from DeterminateSystems/symbol-table-string-view
SymbolStr: Remove std::string conversion
This commit is contained in:
commit
b57c361097
15 changed files with 37 additions and 37 deletions
|
@ -289,10 +289,10 @@ void SourceExprCommand::completeInstallable(AddCompletions & completions, std::s
|
||||||
|
|
||||||
if (v2.type() == nAttrs) {
|
if (v2.type() == nAttrs) {
|
||||||
for (auto & i : *v2.attrs()) {
|
for (auto & i : *v2.attrs()) {
|
||||||
std::string name = state->symbols[i.name];
|
std::string_view name = state->symbols[i.name];
|
||||||
if (name.find(searchWord) == 0) {
|
if (name.find(searchWord) == 0) {
|
||||||
if (prefix_ == "")
|
if (prefix_ == "")
|
||||||
completions.add(name);
|
completions.add(std::string(name));
|
||||||
else
|
else
|
||||||
completions.add(prefix_ + "." + name);
|
completions.add(prefix_ + "." + name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,7 +383,7 @@ nix_value * nix_get_attr_byidx(
|
||||||
try {
|
try {
|
||||||
auto & v = check_value_in(value);
|
auto & v = check_value_in(value);
|
||||||
const nix::Attr & a = (*v.attrs())[i];
|
const nix::Attr & a = (*v.attrs())[i];
|
||||||
*name = ((const std::string &) (state->state.symbols[a.name])).c_str();
|
*name = state->state.symbols[a.name].c_str();
|
||||||
nix_gc_incref(nullptr, a.value);
|
nix_gc_incref(nullptr, a.value);
|
||||||
state->state.forceValue(*a.value, nix::noPos);
|
state->state.forceValue(*a.value, nix::noPos);
|
||||||
return as_nix_value_ptr(a.value);
|
return as_nix_value_ptr(a.value);
|
||||||
|
@ -399,7 +399,7 @@ nix_get_attr_name_byidx(nix_c_context * context, const nix_value * value, EvalSt
|
||||||
try {
|
try {
|
||||||
auto & v = check_value_in(value);
|
auto & v = check_value_in(value);
|
||||||
const nix::Attr & a = (*v.attrs())[i];
|
const nix::Attr & a = (*v.attrs())[i];
|
||||||
return ((const std::string &) (state->state.symbols[a.name])).c_str();
|
return state->state.symbols[a.name].c_str();
|
||||||
}
|
}
|
||||||
NIXC_CATCH_ERRS_NULL
|
NIXC_CATCH_ERRS_NULL
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ std::pair<Value *, PosIdx> findAlongAttrPath(EvalState & state, const std::strin
|
||||||
if (!a) {
|
if (!a) {
|
||||||
std::set<std::string> attrNames;
|
std::set<std::string> attrNames;
|
||||||
for (auto & attr : *v->attrs())
|
for (auto & attr : *v->attrs())
|
||||||
attrNames.insert(state.symbols[attr.name]);
|
attrNames.insert(std::string(state.symbols[attr.name]));
|
||||||
|
|
||||||
auto suggestions = Suggestions::bestMatches(attrNames, attr);
|
auto suggestions = Suggestions::bestMatches(attrNames, attr);
|
||||||
throw AttrPathNotFound(suggestions, "attribute '%1%' in selection path '%2%' not found", attr, attrPath);
|
throw AttrPathNotFound(suggestions, "attribute '%1%' in selection path '%2%' not found", attr, attrPath);
|
||||||
|
|
|
@ -484,7 +484,7 @@ Suggestions AttrCursor::getSuggestionsForAttr(Symbol name)
|
||||||
auto attrNames = getAttrs();
|
auto attrNames = getAttrs();
|
||||||
std::set<std::string> strAttrNames;
|
std::set<std::string> strAttrNames;
|
||||||
for (auto & name : attrNames)
|
for (auto & name : attrNames)
|
||||||
strAttrNames.insert(root->state.symbols[name]);
|
strAttrNames.insert(std::string(root->state.symbols[name]));
|
||||||
|
|
||||||
return Suggestions::bestMatches(strAttrNames, root->state.symbols[name]);
|
return Suggestions::bestMatches(strAttrNames, root->state.symbols[name]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -633,11 +633,11 @@ void mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const En
|
||||||
if (se.isWith && !env.values[0]->isThunk()) {
|
if (se.isWith && !env.values[0]->isThunk()) {
|
||||||
// add 'with' bindings.
|
// add 'with' bindings.
|
||||||
for (auto & j : *env.values[0]->attrs())
|
for (auto & j : *env.values[0]->attrs())
|
||||||
vm[st[j.name]] = j.value;
|
vm.insert_or_assign(std::string(st[j.name]), j.value);
|
||||||
} else {
|
} else {
|
||||||
// iterate through staticenv bindings and add them.
|
// iterate through staticenv bindings and add them.
|
||||||
for (auto & i : se.vars)
|
for (auto & i : se.vars)
|
||||||
vm[st[i.first]] = env.values[i.second];
|
vm.insert_or_assign(std::string(st[i.first]), env.values[i.second]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1338,7 +1338,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
||||||
if (!(j = vAttrs->attrs()->get(name))) {
|
if (!(j = vAttrs->attrs()->get(name))) {
|
||||||
std::set<std::string> allAttrNames;
|
std::set<std::string> allAttrNames;
|
||||||
for (auto & attr : *vAttrs->attrs())
|
for (auto & attr : *vAttrs->attrs())
|
||||||
allAttrNames.insert(state.symbols[attr.name]);
|
allAttrNames.insert(std::string(state.symbols[attr.name]));
|
||||||
auto suggestions = Suggestions::bestMatches(allAttrNames, state.symbols[name]);
|
auto suggestions = Suggestions::bestMatches(allAttrNames, state.symbols[name]);
|
||||||
state.error<EvalError>("attribute '%1%' missing", state.symbols[name])
|
state.error<EvalError>("attribute '%1%' missing", state.symbols[name])
|
||||||
.atPos(pos).withSuggestions(suggestions).withFrame(env, *this).debugThrow();
|
.atPos(pos).withSuggestions(suggestions).withFrame(env, *this).debugThrow();
|
||||||
|
@ -1496,7 +1496,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
|
||||||
if (!lambda.formals->has(i.name)) {
|
if (!lambda.formals->has(i.name)) {
|
||||||
std::set<std::string> formalNames;
|
std::set<std::string> formalNames;
|
||||||
for (auto & formal : lambda.formals->formals)
|
for (auto & formal : lambda.formals->formals)
|
||||||
formalNames.insert(symbols[formal.name]);
|
formalNames.insert(std::string(symbols[formal.name]));
|
||||||
auto suggestions = Suggestions::bestMatches(formalNames, symbols[i.name]);
|
auto suggestions = Suggestions::bestMatches(formalNames, symbols[i.name]);
|
||||||
error<TypeError>("function '%1%' called with unexpected argument '%2%'",
|
error<TypeError>("function '%1%' called with unexpected argument '%2%'",
|
||||||
(lambda.name ? std::string(symbols[lambda.name]) : "anonymous lambda"),
|
(lambda.name ? std::string(symbols[lambda.name]) : "anonymous lambda"),
|
||||||
|
|
|
@ -342,9 +342,9 @@ std::optional<PackageInfo> getDerivation(EvalState & state, Value & v,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static std::string addToPath(const std::string & s1, const std::string & s2)
|
static std::string addToPath(const std::string & s1, std::string_view s2)
|
||||||
{
|
{
|
||||||
return s1.empty() ? s2 : s1 + "." + s2;
|
return s1.empty() ? std::string(s2) : s1 + "." + s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1225,7 +1225,7 @@ static void derivationStrictInternal(
|
||||||
|
|
||||||
for (auto & i : attrs->lexicographicOrder(state.symbols)) {
|
for (auto & i : attrs->lexicographicOrder(state.symbols)) {
|
||||||
if (i->name == state.sIgnoreNulls) continue;
|
if (i->name == state.sIgnoreNulls) continue;
|
||||||
const std::string & key = state.symbols[i->name];
|
auto key = state.symbols[i->name];
|
||||||
vomit("processing attribute '%1%'", key);
|
vomit("processing attribute '%1%'", key);
|
||||||
|
|
||||||
auto handleHashMode = [&](const std::string_view s) {
|
auto handleHashMode = [&](const std::string_view s) {
|
||||||
|
@ -1309,7 +1309,7 @@ static void derivationStrictInternal(
|
||||||
|
|
||||||
if (i->name == state.sStructuredAttrs) continue;
|
if (i->name == state.sStructuredAttrs) continue;
|
||||||
|
|
||||||
(*jsonObject)[key] = printValueAsJSON(state, true, *i->value, pos, context);
|
jsonObject->emplace(key, printValueAsJSON(state, true, *i->value, pos, context));
|
||||||
|
|
||||||
if (i->name == state.sBuilder)
|
if (i->name == state.sBuilder)
|
||||||
drv.builder = state.forceString(*i->value, context, pos, context_below);
|
drv.builder = state.forceString(*i->value, context, pos, context_below);
|
||||||
|
|
|
@ -30,9 +30,9 @@ public:
|
||||||
return *s == s2;
|
return *s == s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator const std::string & () const
|
const char * c_str() const
|
||||||
{
|
{
|
||||||
return *s;
|
return s->c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
operator const std::string_view () const
|
operator const std::string_view () const
|
||||||
|
|
|
@ -58,7 +58,7 @@ json printValueAsJSON(EvalState & state, bool strict,
|
||||||
out = json::object();
|
out = json::object();
|
||||||
for (auto & a : v.attrs()->lexicographicOrder(state.symbols)) {
|
for (auto & a : v.attrs()->lexicographicOrder(state.symbols)) {
|
||||||
try {
|
try {
|
||||||
out[state.symbols[a->name]] = printValueAsJSON(state, strict, *a->value, a->pos, context, copyToStore);
|
out.emplace(state.symbols[a->name], printValueAsJSON(state, strict, *a->value, a->pos, context, copyToStore));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
e.addTrace(state.positions[a->pos],
|
e.addTrace(state.positions[a->pos],
|
||||||
HintFmt("while evaluating attribute '%1%'", state.symbols[a->name]));
|
HintFmt("while evaluating attribute '%1%'", state.symbols[a->name]));
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
static XMLAttrs singletonAttrs(const std::string & name, const std::string & value)
|
static XMLAttrs singletonAttrs(const std::string & name, std::string_view value)
|
||||||
{
|
{
|
||||||
XMLAttrs attrs;
|
XMLAttrs attrs;
|
||||||
attrs[name] = value;
|
attrs[name] = value;
|
||||||
|
|
|
@ -98,7 +98,7 @@ static std::map<FlakeId, FlakeInput> parseFlakeInputs(
|
||||||
const std::optional<Path> & baseDir, InputPath lockRootPath);
|
const std::optional<Path> & baseDir, InputPath lockRootPath);
|
||||||
|
|
||||||
static FlakeInput parseFlakeInput(EvalState & state,
|
static FlakeInput parseFlakeInput(EvalState & state,
|
||||||
const std::string & inputName, Value * value, const PosIdx pos,
|
std::string_view inputName, Value * value, const PosIdx pos,
|
||||||
const std::optional<Path> & baseDir, InputPath lockRootPath)
|
const std::optional<Path> & baseDir, InputPath lockRootPath)
|
||||||
{
|
{
|
||||||
expectType(state, nAttrs, *value, pos);
|
expectType(state, nAttrs, *value, pos);
|
||||||
|
@ -178,7 +178,7 @@ static FlakeInput parseFlakeInput(EvalState & state,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!input.follows && !input.ref)
|
if (!input.follows && !input.ref)
|
||||||
input.ref = FlakeRef::fromAttrs({{"type", "indirect"}, {"id", inputName}});
|
input.ref = FlakeRef::fromAttrs({{"type", "indirect"}, {"id", std::string(inputName)}});
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ static Flake readFlake(
|
||||||
for (auto & formal : outputs->value->payload.lambda.fun->formals->formals) {
|
for (auto & formal : outputs->value->payload.lambda.fun->formals->formals) {
|
||||||
if (formal.name != state.sSelf)
|
if (formal.name != state.sSelf)
|
||||||
flake.inputs.emplace(state.symbols[formal.name], FlakeInput {
|
flake.inputs.emplace(state.symbols[formal.name], FlakeInput {
|
||||||
.ref = parseFlakeRef(state.symbols[formal.name])
|
.ref = parseFlakeRef(std::string(state.symbols[formal.name]))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ int levenshteinDistance(std::string_view first, std::string_view second)
|
||||||
}
|
}
|
||||||
|
|
||||||
Suggestions Suggestions::bestMatches (
|
Suggestions Suggestions::bestMatches (
|
||||||
std::set<std::string> allMatches,
|
const std::set<std::string> & allMatches,
|
||||||
std::string query)
|
std::string_view query)
|
||||||
{
|
{
|
||||||
std::set<Suggestion> res;
|
std::set<Suggestion> res;
|
||||||
for (const auto & possibleMatch : allMatches) {
|
for (const auto & possibleMatch : allMatches) {
|
||||||
|
|
|
@ -35,8 +35,8 @@ public:
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
static Suggestions bestMatches (
|
static Suggestions bestMatches (
|
||||||
std::set<std::string> allMatches,
|
const std::set<std::string> & allMatches,
|
||||||
std::string query
|
std::string_view query
|
||||||
);
|
);
|
||||||
|
|
||||||
Suggestions& operator+=(const Suggestions & other);
|
Suggestions& operator+=(const Suggestions & other);
|
||||||
|
|
|
@ -165,7 +165,7 @@ struct CmdFlakeLock : FlakeCommand
|
||||||
};
|
};
|
||||||
|
|
||||||
static void enumerateOutputs(EvalState & state, Value & vFlake,
|
static void enumerateOutputs(EvalState & state, Value & vFlake,
|
||||||
std::function<void(const std::string & name, Value & vProvide, const PosIdx pos)> callback)
|
std::function<void(std::string_view name, Value & vProvide, const PosIdx pos)> callback)
|
||||||
{
|
{
|
||||||
auto pos = vFlake.determinePos(noPos);
|
auto pos = vFlake.determinePos(noPos);
|
||||||
state.forceAttrs(vFlake, pos, "while evaluating a flake to get its outputs");
|
state.forceAttrs(vFlake, pos, "while evaluating a flake to get its outputs");
|
||||||
|
@ -393,15 +393,15 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
|| (hasPrefix(name, "_") && name.substr(1) == expected);
|
|| (hasPrefix(name, "_") && name.substr(1) == expected);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto checkSystemName = [&](const std::string & system, const PosIdx pos) {
|
auto checkSystemName = [&](std::string_view system, const PosIdx pos) {
|
||||||
// FIXME: what's the format of "system"?
|
// FIXME: what's the format of "system"?
|
||||||
if (system.find('-') == std::string::npos)
|
if (system.find('-') == std::string::npos)
|
||||||
reportError(Error("'%s' is not a valid system type, at %s", system, resolve(pos)));
|
reportError(Error("'%s' is not a valid system type, at %s", system, resolve(pos)));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto checkSystemType = [&](const std::string & system, const PosIdx pos) {
|
auto checkSystemType = [&](std::string_view system, const PosIdx pos) {
|
||||||
if (!checkAllSystems && system != localSystem) {
|
if (!checkAllSystems && system != localSystem) {
|
||||||
omittedSystems.insert(system);
|
omittedSystems.insert(std::string(system));
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -450,7 +450,7 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto checkOverlay = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
|
auto checkOverlay = [&](std::string_view attrPath, Value & v, const PosIdx pos) {
|
||||||
try {
|
try {
|
||||||
Activity act(*logger, lvlInfo, actUnknown,
|
Activity act(*logger, lvlInfo, actUnknown,
|
||||||
fmt("checking overlay '%s'", attrPath));
|
fmt("checking overlay '%s'", attrPath));
|
||||||
|
@ -469,7 +469,7 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto checkModule = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
|
auto checkModule = [&](std::string_view attrPath, Value & v, const PosIdx pos) {
|
||||||
try {
|
try {
|
||||||
Activity act(*logger, lvlInfo, actUnknown,
|
Activity act(*logger, lvlInfo, actUnknown,
|
||||||
fmt("checking NixOS module '%s'", attrPath));
|
fmt("checking NixOS module '%s'", attrPath));
|
||||||
|
@ -480,9 +480,9 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::function<void(const std::string & attrPath, Value & v, const PosIdx pos)> checkHydraJobs;
|
std::function<void(std::string_view attrPath, Value & v, const PosIdx pos)> checkHydraJobs;
|
||||||
|
|
||||||
checkHydraJobs = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
|
checkHydraJobs = [&](std::string_view attrPath, Value & v, const PosIdx pos) {
|
||||||
try {
|
try {
|
||||||
Activity act(*logger, lvlInfo, actUnknown,
|
Activity act(*logger, lvlInfo, actUnknown,
|
||||||
fmt("checking Hydra job '%s'", attrPath));
|
fmt("checking Hydra job '%s'", attrPath));
|
||||||
|
@ -523,7 +523,7 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto checkTemplate = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
|
auto checkTemplate = [&](std::string_view attrPath, Value & v, const PosIdx pos) {
|
||||||
try {
|
try {
|
||||||
Activity act(*logger, lvlInfo, actUnknown,
|
Activity act(*logger, lvlInfo, actUnknown,
|
||||||
fmt("checking template '%s'", attrPath));
|
fmt("checking template '%s'", attrPath));
|
||||||
|
@ -579,7 +579,7 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
|
|
||||||
enumerateOutputs(*state,
|
enumerateOutputs(*state,
|
||||||
*vFlake,
|
*vFlake,
|
||||||
[&](const std::string & name, Value & vOutput, const PosIdx pos) {
|
[&](std::string_view name, Value & vOutput, const PosIdx pos) {
|
||||||
Activity act(*logger, lvlInfo, actUnknown,
|
Activity act(*logger, lvlInfo, actUnknown,
|
||||||
fmt("checking flake output '%s'", name));
|
fmt("checking flake output '%s'", name));
|
||||||
|
|
||||||
|
@ -603,7 +603,7 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
if (name == "checks") {
|
if (name == "checks") {
|
||||||
state->forceAttrs(vOutput, pos, "");
|
state->forceAttrs(vOutput, pos, "");
|
||||||
for (auto & attr : *vOutput.attrs()) {
|
for (auto & attr : *vOutput.attrs()) {
|
||||||
const auto & attr_name = state->symbols[attr.name];
|
std::string_view attr_name = state->symbols[attr.name];
|
||||||
checkSystemName(attr_name, attr.pos);
|
checkSystemName(attr_name, attr.pos);
|
||||||
if (checkSystemType(attr_name, attr.pos)) {
|
if (checkSystemType(attr_name, attr.pos)) {
|
||||||
state->forceAttrs(*attr.value, attr.pos, "");
|
state->forceAttrs(*attr.value, attr.pos, "");
|
||||||
|
|
|
@ -429,7 +429,7 @@ void mainWrapped(int argc, char * * argv)
|
||||||
b["doc"] = trim(stripIndentation(primOp->doc));
|
b["doc"] = trim(stripIndentation(primOp->doc));
|
||||||
if (primOp->experimentalFeature)
|
if (primOp->experimentalFeature)
|
||||||
b["experimental-feature"] = primOp->experimentalFeature;
|
b["experimental-feature"] = primOp->experimentalFeature;
|
||||||
builtinsJson[state.symbols[builtin.name]] = std::move(b);
|
builtinsJson.emplace(state.symbols[builtin.name], std::move(b));
|
||||||
}
|
}
|
||||||
for (auto & [name, info] : state.constantInfos) {
|
for (auto & [name, info] : state.constantInfos) {
|
||||||
auto b = nlohmann::json::object();
|
auto b = nlohmann::json::object();
|
||||||
|
|
Loading…
Reference in a new issue