Skip to content

Commit 126f30d

Browse files
authored
Merge pull request #14366 from NixOS/const-fields
EvalState: Make some more fields const
2 parents 60f9489 + fdc5600 commit 126f30d

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/libexpr/eval.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,16 +3067,16 @@ Expr * EvalState::parseExprFromFile(const SourcePath & path)
30673067
return parseExprFromFile(path, staticBaseEnv);
30683068
}
30693069

3070-
Expr * EvalState::parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv)
3070+
Expr * EvalState::parseExprFromFile(const SourcePath & path, const std::shared_ptr<StaticEnv> & staticEnv)
30713071
{
30723072
auto buffer = path.resolveSymlinks().readFile();
30733073
// readFile hopefully have left some extra space for terminators
30743074
buffer.append("\0\0", 2);
30753075
return parse(buffer.data(), buffer.size(), Pos::Origin(path), path.parent(), staticEnv);
30763076
}
30773077

3078-
Expr *
3079-
EvalState::parseExprFromString(std::string s_, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv)
3078+
Expr * EvalState::parseExprFromString(
3079+
std::string s_, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv)
30803080
{
30813081
// NOTE this method (and parseStdin) must take care to *fully copy* their input
30823082
// into their respective Pos::Origin until the parser stops overwriting its input
@@ -3210,7 +3210,11 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
32103210
}
32113211

32123212
Expr * EvalState::parse(
3213-
char * text, size_t length, Pos::Origin origin, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv)
3213+
char * text,
3214+
size_t length,
3215+
Pos::Origin origin,
3216+
const SourcePath & basePath,
3217+
const std::shared_ptr<StaticEnv> & staticEnv)
32143218
{
32153219
DocCommentMap tmpDocComments; // Only used when not origin is not a SourcePath
32163220
DocCommentMap * docComments = &tmpDocComments;

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ std::ostream & operator<<(std::ostream & os, const ValueType t);
191191

192192
struct RegexCache;
193193

194-
std::shared_ptr<RegexCache> makeRegexCache();
194+
ref<RegexCache> makeRegexCache();
195195

196196
struct DebugTrace
197197
{
@@ -372,6 +372,7 @@ public:
372372

373373
const fetchers::Settings & fetchSettings;
374374
const EvalSettings & settings;
375+
375376
SymbolTable symbols;
376377
PosTable positions;
377378

@@ -418,7 +419,7 @@ public:
418419

419420
RootValue vImportedDrvToDerivation = nullptr;
420421

421-
ref<fetchers::InputCache> inputCache;
422+
const ref<fetchers::InputCache> inputCache;
422423

423424
/**
424425
* Debugger
@@ -471,18 +472,18 @@ private:
471472

472473
/* Cache for calls to addToStore(); maps source paths to the store
473474
paths. */
474-
ref<boost::concurrent_flat_map<SourcePath, StorePath>> srcToStore;
475+
const ref<boost::concurrent_flat_map<SourcePath, StorePath>> srcToStore;
475476

476477
/**
477478
* A cache that maps paths to "resolved" paths for importing Nix
478479
* expressions, i.e. `/foo` to `/foo/default.nix`.
479480
*/
480-
ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache;
481+
const ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache;
481482

482483
/**
483484
* A cache from resolved paths to values.
484485
*/
485-
ref<boost::concurrent_flat_map<
486+
const ref<boost::concurrent_flat_map<
486487
SourcePath,
487488
Value *,
488489
std::hash<SourcePath>,
@@ -504,7 +505,7 @@ private:
504505
/**
505506
* Cache used by prim_match().
506507
*/
507-
std::shared_ptr<RegexCache> regexCache;
508+
const ref<RegexCache> regexCache;
508509

509510
public:
510511

@@ -592,12 +593,13 @@ public:
592593
* Parse a Nix expression from the specified file.
593594
*/
594595
Expr * parseExprFromFile(const SourcePath & path);
595-
Expr * parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv);
596+
Expr * parseExprFromFile(const SourcePath & path, const std::shared_ptr<StaticEnv> & staticEnv);
596597

597598
/**
598599
* Parse a Nix expression from the specified string.
599600
*/
600-
Expr * parseExprFromString(std::string s, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv);
601+
Expr *
602+
parseExprFromString(std::string s, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv);
601603
Expr * parseExprFromString(std::string s, const SourcePath & basePath);
602604

603605
Expr * parseStdin();
@@ -766,7 +768,7 @@ public:
766768

767769
#if NIX_USE_BOEHMGC
768770
/** A GC root for the baseEnv reference. */
769-
std::shared_ptr<Env *> baseEnvP;
771+
const std::shared_ptr<Env *> baseEnvP;
770772
#endif
771773

772774
public:
@@ -780,7 +782,7 @@ public:
780782
/**
781783
* The same, but used during parsing to resolve variables.
782784
*/
783-
std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private
785+
const std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private
784786

785787
/**
786788
* Internal primops not exposed to the user.
@@ -862,7 +864,7 @@ private:
862864
size_t length,
863865
Pos::Origin origin,
864866
const SourcePath & basePath,
865-
std::shared_ptr<StaticEnv> & staticEnv);
867+
const std::shared_ptr<StaticEnv> & staticEnv);
866868

867869
/**
868870
* Current Nix call stack depth, used with `max-call-depth` setting to throw stack overflow hopefully before we run

src/libexpr/primops.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4611,9 +4611,9 @@ struct RegexCache
46114611
}
46124612
};
46134613

4614-
std::shared_ptr<RegexCache> makeRegexCache()
4614+
ref<RegexCache> makeRegexCache()
46154615
{
4616-
return std::make_shared<RegexCache>();
4616+
return make_ref<RegexCache>();
46174617
}
46184618

46194619
void prim_match(EvalState & state, const PosIdx pos, Value ** args, Value & v)

0 commit comments

Comments
 (0)