Skip to content

Commit 62729ff

Browse files
committed
parser.y: pass all of Exprs in, not just alloc
1 parent 3ed42cd commit 62729ff

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

src/libexpr/eval.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3217,7 +3217,7 @@ Expr * EvalState::parse(
32173217
}
32183218

32193219
auto result = parseExprFromBuf(
3220-
text, length, origin, basePath, mem.exprs.alloc, symbols, settings, positions, *docComments, rootFS);
3220+
text, length, origin, basePath, mem.exprs, symbols, settings, positions, *docComments, rootFS);
32213221

32223222
result->bindVars(*this, staticEnv);
32233223

src/libexpr/include/nix/expr/parser-state.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct LexerState
7878
struct ParserState
7979
{
8080
const LexerState & lexerState;
81-
std::pmr::polymorphic_allocator<char> & alloc;
81+
Exprs & exprs;
8282
SymbolTable & symbols;
8383
PosTable & positions;
8484
Expr * result;
@@ -322,7 +322,7 @@ ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, st
322322

323323
// Ignore empty strings for a minor optimisation and AST simplification
324324
if (s2 != "") {
325-
es2.emplace_back(i->first, new ExprString(alloc, s2));
325+
es2.emplace_back(i->first, new ExprString(exprs.alloc, s2));
326326
}
327327
};
328328
for (; i != es.end(); ++i, --n) {
@@ -341,7 +341,7 @@ ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, st
341341
auto * const result = (es2)[0].second;
342342
return result;
343343
}
344-
return new ExprConcatStrings(alloc, pos, true, std::move(es2));
344+
return new ExprConcatStrings(exprs.alloc, pos, true, std::move(es2));
345345
}
346346

347347
inline PosIdx LexerState::at(const ParserLocation & loc)

src/libexpr/parser.y

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Expr * parseExprFromBuf(
6363
size_t length,
6464
Pos::Origin origin,
6565
const SourcePath & basePath,
66-
std::pmr::polymorphic_allocator<char> & alloc,
66+
Exprs & exprs,
6767
SymbolTable & symbols,
6868
const EvalSettings & settings,
6969
PosTable & positions,
@@ -186,23 +186,23 @@ expr_function
186186
| formal_set ':' expr_function[body]
187187
{
188188
state->validateFormals($formal_set);
189-
auto me = new ExprLambda(state->positions, state->alloc, CUR_POS, std::move($formal_set), $body);
189+
auto me = new ExprLambda(state->positions, state->exprs.alloc, CUR_POS, std::move($formal_set), $body);
190190
$$ = me;
191191
SET_DOC_POS(me, @1);
192192
}
193193
| formal_set '@' ID ':' expr_function[body]
194194
{
195195
auto arg = state->symbols.create($ID);
196196
state->validateFormals($formal_set, CUR_POS, arg);
197-
auto me = new ExprLambda(state->positions, state->alloc, CUR_POS, arg, std::move($formal_set), $body);
197+
auto me = new ExprLambda(state->positions, state->exprs.alloc, CUR_POS, arg, std::move($formal_set), $body);
198198
$$ = me;
199199
SET_DOC_POS(me, @1);
200200
}
201201
| ID '@' formal_set ':' expr_function[body]
202202
{
203203
auto arg = state->symbols.create($ID);
204204
state->validateFormals($formal_set, CUR_POS, arg);
205-
auto me = new ExprLambda(state->positions, state->alloc, CUR_POS, arg, std::move($formal_set), $body);
205+
auto me = new ExprLambda(state->positions, state->exprs.alloc, CUR_POS, arg, std::move($formal_set), $body);
206206
$$ = me;
207207
SET_DOC_POS(me, @1);
208208
}
@@ -251,9 +251,9 @@ expr_op
251251
| expr_op OR expr_op { $$ = new ExprOpOr(state->at(@2), $1, $3); }
252252
| expr_op IMPL expr_op { $$ = new ExprOpImpl(state->at(@2), $1, $3); }
253253
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(state->at(@2), $1, $3); }
254-
| expr_op '?' attrpath { $$ = new ExprOpHasAttr(state->alloc, $1, std::move($3)); }
254+
| expr_op '?' attrpath { $$ = new ExprOpHasAttr(state->exprs.alloc, $1, std::move($3)); }
255255
| expr_op '+' expr_op
256-
{ $$ = new ExprConcatStrings(state->alloc, state->at(@2), false, {{state->at(@1), $1}, {state->at(@3), $3}}); }
256+
{ $$ = new ExprConcatStrings(state->exprs.alloc, state->at(@2), false, {{state->at(@1), $1}, {state->at(@3), $3}}); }
257257
| expr_op '-' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.sub), {$1, $3}); }
258258
| expr_op '*' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.mul), {$1, $3}); }
259259
| expr_op '/' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.div), {$1, $3}); }
@@ -272,9 +272,9 @@ expr_app
272272

273273
expr_select
274274
: expr_simple '.' attrpath
275-
{ $$ = new ExprSelect(state->alloc, CUR_POS, $1, std::move($3), nullptr); }
275+
{ $$ = new ExprSelect(state->exprs.alloc, CUR_POS, $1, std::move($3), nullptr); }
276276
| expr_simple '.' attrpath OR_KW expr_select
277-
{ $$ = new ExprSelect(state->alloc, CUR_POS, $1, std::move($3), $5); $5->warnIfCursedOr(state->symbols, state->positions); }
277+
{ $$ = new ExprSelect(state->exprs.alloc, CUR_POS, $1, std::move($3), $5); $5->warnIfCursedOr(state->symbols, state->positions); }
278278
| /* Backwards compatibility: because Nixpkgs has a function named ‘or’,
279279
allow stuff like ‘map or [...]’. This production is problematic (see
280280
https://github.com/NixOS/nix/issues/11118) and will be refactored in the
@@ -299,7 +299,7 @@ expr_simple
299299
| FLOAT_LIT { $$ = new ExprFloat($1); }
300300
| '"' string_parts '"' {
301301
std::visit(overloaded{
302-
[&](std::string_view str) { $$ = new ExprString(state->alloc, str); },
302+
[&](std::string_view str) { $$ = new ExprString(state->exprs.alloc, str); },
303303
[&](Expr * expr) { $$ = expr; }},
304304
$2);
305305
}
@@ -309,14 +309,14 @@ expr_simple
309309
| path_start PATH_END
310310
| path_start string_parts_interpolated PATH_END {
311311
$2.insert($2.begin(), {state->at(@1), $1});
312-
$$ = new ExprConcatStrings(state->alloc, CUR_POS, false, std::move($2));
312+
$$ = new ExprConcatStrings(state->exprs.alloc, CUR_POS, false, std::move($2));
313313
}
314314
| SPATH {
315315
std::string_view path($1.p + 1, $1.l - 2);
316316
$$ = new ExprCall(CUR_POS,
317317
new ExprVar(state->s.findFile),
318318
{new ExprVar(state->s.nixPath),
319-
new ExprString(state->alloc, path)});
319+
new ExprString(state->exprs.alloc, path)});
320320
}
321321
| URI {
322322
static bool noURLLiterals = experimentalFeatureSettings.isEnabled(Xp::NoUrlLiterals);
@@ -325,35 +325,35 @@ expr_simple
325325
.msg = HintFmt("URL literals are disabled"),
326326
.pos = state->positions[CUR_POS]
327327
});
328-
$$ = new ExprString(state->alloc, $1);
328+
$$ = new ExprString(state->exprs.alloc, $1);
329329
}
330330
| '(' expr ')' { $$ = $2; }
331331
/* Let expressions `let {..., body = ...}' are just desugared
332332
into `(rec {..., body = ...}).body'. */
333333
| LET '{' binds '}'
334-
{ $3->recursive = true; $3->pos = CUR_POS; $$ = new ExprSelect(state->alloc, noPos, $3, state->s.body); }
334+
{ $3->recursive = true; $3->pos = CUR_POS; $$ = new ExprSelect(state->exprs.alloc, noPos, $3, state->s.body); }
335335
| REC '{' binds '}'
336336
{ $3->recursive = true; $3->pos = CUR_POS; $$ = $3; }
337337
| '{' binds1 '}'
338338
{ $2->pos = CUR_POS; $$ = $2; }
339339
| '{' '}'
340340
{ $$ = new ExprAttrs(CUR_POS); }
341-
| '[' list ']' { $$ = new ExprList(state->alloc, std::move($2)); }
341+
| '[' list ']' { $$ = new ExprList(state->exprs.alloc, std::move($2)); }
342342
;
343343

344344
string_parts
345345
: STR { $$ = $1; }
346-
| string_parts_interpolated { $$ = new ExprConcatStrings(state->alloc, CUR_POS, true, std::move($1)); }
346+
| string_parts_interpolated { $$ = new ExprConcatStrings(state->exprs.alloc, CUR_POS, true, std::move($1)); }
347347
| { $$ = std::string_view(); }
348348
;
349349

350350
string_parts_interpolated
351351
: string_parts_interpolated STR
352-
{ $$ = std::move($1); $$.emplace_back(state->at(@2), new ExprString(state->alloc, $2)); }
352+
{ $$ = std::move($1); $$.emplace_back(state->at(@2), new ExprString(state->exprs.alloc, $2)); }
353353
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = std::move($1); $$.emplace_back(state->at(@2), $3); }
354354
| DOLLAR_CURLY expr '}' { $$.emplace_back(state->at(@1), $2); }
355355
| STR DOLLAR_CURLY expr '}' {
356-
$$.emplace_back(state->at(@1), new ExprString(state->alloc, $1));
356+
$$.emplace_back(state->at(@1), new ExprString(state->exprs.alloc, $1));
357357
$$.emplace_back(state->at(@2), $3);
358358
}
359359
;
@@ -379,8 +379,8 @@ path_start
379379
root filesystem accessor, rather than the accessor of the
380380
current Nix expression. */
381381
literal.front() == '/'
382-
? new ExprPath(state->alloc, state->rootFS, path)
383-
: new ExprPath(state->alloc, state->basePath.accessor, path);
382+
? new ExprPath(state->exprs.alloc, state->rootFS, path)
383+
: new ExprPath(state->exprs.alloc, state->basePath.accessor, path);
384384
}
385385
| HPATH {
386386
if (state->settings.pureEval) {
@@ -390,7 +390,7 @@ path_start
390390
);
391391
}
392392
Path path(getHome() + std::string($1.p + 1, $1.l - 1));
393-
$$ = new ExprPath(state->alloc, ref<SourceAccessor>(state->rootFS), path);
393+
$$ = new ExprPath(state->exprs.alloc, ref<SourceAccessor>(state->rootFS), path);
394394
}
395395
;
396396

@@ -432,7 +432,7 @@ binds1
432432
$accum->attrs.emplace(
433433
i.symbol,
434434
ExprAttrs::AttrDef(
435-
new ExprSelect(state->alloc, iPos, from, i.symbol),
435+
new ExprSelect(state->exprs.alloc, iPos, from, i.symbol),
436436
iPos,
437437
ExprAttrs::AttrDef::Kind::InheritedFrom));
438438
}
@@ -525,7 +525,7 @@ Expr * parseExprFromBuf(
525525
size_t length,
526526
Pos::Origin origin,
527527
const SourcePath & basePath,
528-
std::pmr::polymorphic_allocator<char> & alloc,
528+
Exprs & exprs,
529529
SymbolTable & symbols,
530530
const EvalSettings & settings,
531531
PosTable & positions,
@@ -540,7 +540,7 @@ Expr * parseExprFromBuf(
540540
};
541541
ParserState state {
542542
.lexerState = lexerState,
543-
.alloc = alloc,
543+
.exprs = exprs,
544544
.symbols = symbols,
545545
.positions = positions,
546546
.basePath = basePath,

0 commit comments

Comments
 (0)