<commit_before>#include "experimental-features.hh"
#include "nlohmann/json.hpp"

namespace nix {

std::map<ExperimentalFeature, std::string> stringifiedXpFeatures = {
    { Xp::CaDerivations, "ca-derivations" },
    { Xp::Flakes, "flakes" },
    { Xp::NixCommand, "nix-command" },
    { Xp::RecursiveNix, "recursive-nix" },
    { Xp::NoUrlLiterals, "no-url-literals" },
};

const std::optional<ExperimentalFeature> parseExperimentalFeature(const std::string_view & name)
{
    using ReverseXpMap = std::map<std::string_view, ExperimentalFeature>;
    static ReverseXpMap * reverseXpMap;
    if (!reverseXpMap) {
        reverseXpMap = new ReverseXpMap{};
        for (auto & [feature, name] : stringifiedXpFeatures)
            (*reverseXpMap)[name] = feature;
    }

    auto featureIter = reverseXpMap->find(name);
    if (featureIter == reverseXpMap->end())
        return std::nullopt;
    return {featureIter->second};
}

std::string_view showExperimentalFeature(const ExperimentalFeature feature)
{
    return stringifiedXpFeatures.at(feature);
}

std::set<ExperimentalFeature> parseFeatures(const std::set<std::string> & rawFeatures)
{
    std::set<ExperimentalFeature> res;
    for (auto & rawFeature : rawFeatures) {
        if (auto feature = parseExperimentalFeature(rawFeature))
            res.insert(*feature);
    }
    return res;
}

MissingExperimentalFeature::MissingExperimentalFeature(ExperimentalFeature feature)
    : Error("experimental Nix feature '%1%' is disabled; use '--extra-experimental-features %1%' to override", showExperimentalFeature(feature))
    , missingFeature(feature)
    {}<commit_msg>parseExperimentalFeature(): Initialize atomically<commit_after>#include "experimental-features.hh"
#include "util.hh"

#include "nlohmann/json.hpp"

namespace nix {

std::map<ExperimentalFeature, std::string> stringifiedXpFeatures = {
    { Xp::CaDerivations, "ca-derivations" },
    { Xp::Flakes, "flakes" },
    { Xp::NixCommand, "nix-command" },
    { Xp::RecursiveNix, "recursive-nix" },
    { Xp::NoUrlLiterals, "no-url-literals" },
};

const std::optional<ExperimentalFeature> parseExperimentalFeature(const std::string_view & name)
{
    using ReverseXpMap = std::map<std::string_view, ExperimentalFeature>;

    static auto reverseXpMap = []()
    {
        auto reverseXpMap = std::make_unique<ReverseXpMap>();
        for (auto & [feature, name] : stringifiedXpFeatures)
            (*reverseXpMap)[name] = feature;
        return reverseXpMap;
    }();

    if (auto feature = get(*reverseXpMap, name))
        return *feature;
    else
        return std::nullopt;
}

std::string_view showExperimentalFeature(const ExperimentalFeature feature)
{
    return stringifiedXpFeatures.at(feature);
}

std::set<ExperimentalFeature> parseFeatures(const std::set<std::string> & rawFeatures)
{
    std::set<ExperimentalFeature> res;
    for (auto & rawFeature : rawFeatures) {
        if (auto feature = parseExperimentalFeature(rawFeature))
            res.insert(*feature);
    }
    return res;
}

MissingExperimentalFeature::MissingExperimentalFeature(ExperimentalFeature feature)
    : Error("experimental Nix feature '%1%' is disabled; use '--extra-experimental-features %1%' to override", showExperimentalFeature(feature))
    , missingFeature(feature)
{}
{'fraction_non_alphanumeric': 0.13157095107869948, 'fraction_numerical': 0.001215436037678517, 'mean_word_length': 4.532773109243697, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '393368', 'n_tokens_mistral': 1037, 'n_tokens_neox': 981, 'n_words': 186}