Skip to content

Commit 3bac0d7

Browse files
authored
Merge pull request #14635 from Radvendii/alloc-exprlet-exprattrs
libexpr: move the ExprLet::attrs allocations into the arena
2 parents 36419a6 + 60f0992 commit 3bac0d7

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/libexpr/include/nix/expr/nixexpr.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ struct ExprAttrs : Expr
438438
std::shared_ptr<const StaticEnv> bindInheritSources(EvalState & es, const std::shared_ptr<const StaticEnv> & env);
439439
Env * buildInheritFromEnv(EvalState & state, Env & up);
440440
void showBindings(const SymbolTable & symbols, std::ostream & str) const;
441+
void moveDataToAllocator(std::pmr::polymorphic_allocator<char> & alloc);
441442
};
442443

443444
struct ExprList : Expr
@@ -622,6 +623,7 @@ struct ExprCall : Expr
622623

623624
virtual void resetCursedOr() override;
624625
virtual void warnIfCursedOr(const SymbolTable & symbols, const PosTable & positions) override;
626+
void moveDataToAllocator(std::pmr::polymorphic_allocator<char> & alloc);
625627
COMMON_METHODS
626628
};
627629

src/libexpr/nixexpr.cc

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -399,18 +399,19 @@ ExprAttrs::bindInheritSources(EvalState & es, const std::shared_ptr<const Static
399399
return inner;
400400
}
401401

402+
void ExprAttrs::moveDataToAllocator(std::pmr::polymorphic_allocator<char> & alloc)
403+
{
404+
AttrDefs newAttrs{std::move(*attrs), alloc};
405+
attrs.emplace(std::move(newAttrs), alloc);
406+
DynamicAttrDefs newDynamicAttrs{std::move(*dynamicAttrs), alloc};
407+
dynamicAttrs.emplace(std::move(newDynamicAttrs), alloc);
408+
if (inheritFromExprs)
409+
inheritFromExprs = std::make_unique<std::pmr::vector<Expr *>>(std::move(*inheritFromExprs), alloc);
410+
}
411+
402412
void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
403413
{
404-
// Move storage into the Exprs arena
405-
{
406-
auto arena = es.mem.exprs.alloc;
407-
AttrDefs newAttrs{std::move(*attrs), arena};
408-
attrs.emplace(std::move(newAttrs), arena);
409-
DynamicAttrDefs newDynamicAttrs{std::move(*dynamicAttrs), arena};
410-
dynamicAttrs.emplace(std::move(newDynamicAttrs), arena);
411-
if (inheritFromExprs)
412-
inheritFromExprs = std::make_unique<std::pmr::vector<Expr *>>(std::move(*inheritFromExprs), arena);
413-
}
414+
moveDataToAllocator(es.mem.exprs.alloc);
414415

415416
if (es.debugRepl)
416417
es.exprEnvs.insert(std::make_pair(this, env));
@@ -484,14 +485,15 @@ void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
484485
body->bindVars(es, newEnv);
485486
}
486487

488+
void ExprCall::moveDataToAllocator(std::pmr::polymorphic_allocator<char> & alloc)
489+
{
490+
std::pmr::vector<Expr *> newArgs{std::move(*args), alloc};
491+
args.emplace(std::move(newArgs), alloc);
492+
}
493+
487494
void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
488495
{
489-
// Move storage into the Exprs arena
490-
{
491-
auto arena = es.mem.exprs.alloc;
492-
std::pmr::vector<Expr *> newArgs{std::move(*args), arena};
493-
args.emplace(std::move(newArgs), arena);
494-
}
496+
moveDataToAllocator(es.mem.exprs.alloc);
495497
if (es.debugRepl)
496498
es.exprEnvs.insert(std::make_pair(this, env));
497499

@@ -502,6 +504,7 @@ void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
502504

503505
void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
504506
{
507+
attrs->moveDataToAllocator(es.mem.exprs.alloc);
505508
auto newEnv = [&]() -> std::shared_ptr<const StaticEnv> {
506509
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, attrs->attrs->size());
507510

0 commit comments

Comments
 (0)