1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-05 08:11:47 +02:00

Simplify RegisterPrimOp

This commit is contained in:
Eelco Dolstra 2025-05-05 08:26:29 +02:00
parent b7add9736c
commit 4de7a986d4
2 changed files with 13 additions and 14 deletions

View file

@ -27,7 +27,12 @@ constexpr size_t conservativeStackReservation = 16;
struct RegisterPrimOp struct RegisterPrimOp
{ {
typedef std::vector<PrimOp> PrimOps; typedef std::vector<PrimOp> PrimOps;
static PrimOps * primOps;
static PrimOps & primOps()
{
static PrimOps primOps;
return primOps;
}
/** /**
* You can register a constant by passing an arity of 0. fun * You can register a constant by passing an arity of 0. fun

View file

@ -4713,13 +4713,9 @@ static RegisterPrimOp primop_splitVersion({
*************************************************************/ *************************************************************/
RegisterPrimOp::PrimOps * RegisterPrimOp::primOps;
RegisterPrimOp::RegisterPrimOp(PrimOp && primOp) RegisterPrimOp::RegisterPrimOp(PrimOp && primOp)
{ {
if (!primOps) primOps = new PrimOps; primOps().push_back(std::move(primOp));
primOps->push_back(std::move(primOp));
} }
@ -4973,14 +4969,12 @@ void EvalState::createBaseEnv(const EvalSettings & evalSettings)
)", )",
}); });
if (RegisterPrimOp::primOps) for (auto & primOp : RegisterPrimOp::primOps())
for (auto & primOp : *RegisterPrimOp::primOps) if (experimentalFeatureSettings.isEnabled(primOp.experimentalFeature)) {
if (experimentalFeatureSettings.isEnabled(primOp.experimentalFeature)) auto primOpAdjusted = primOp;
{ primOpAdjusted.arity = std::max(primOp.args.size(), primOp.arity);
auto primOpAdjusted = primOp; addPrimOp(std::move(primOpAdjusted));
primOpAdjusted.arity = std::max(primOp.args.size(), primOp.arity); }
addPrimOp(std::move(primOpAdjusted));
}
for (auto & primOp : evalSettings.extraPrimOps) { for (auto & primOp : evalSettings.extraPrimOps) {
auto primOpAdjusted = primOp; auto primOpAdjusted = primOp;