Skip to content

Commit 1f6ac88

Browse files
committed
Mark some fields in EvalState as const
1 parent bef3c37 commit 1f6ac88

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
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: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public:
418418

419419
RootValue vImportedDrvToDerivation = nullptr;
420420

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

423423
/**
424424
* Debugger
@@ -471,18 +471,18 @@ private:
471471

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

476476
/**
477477
* A cache that maps paths to "resolved" paths for importing Nix
478478
* expressions, i.e. `/foo` to `/foo/default.nix`.
479479
*/
480-
ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache;
480+
const ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache;
481481

482482
/**
483483
* A cache from resolved paths to values.
484484
*/
485-
ref<boost::concurrent_flat_map<
485+
const ref<boost::concurrent_flat_map<
486486
SourcePath,
487487
Value *,
488488
std::hash<SourcePath>,
@@ -592,12 +592,13 @@ public:
592592
* Parse a Nix expression from the specified file.
593593
*/
594594
Expr * parseExprFromFile(const SourcePath & path);
595-
Expr * parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv);
595+
Expr * parseExprFromFile(const SourcePath & path, const std::shared_ptr<StaticEnv> & staticEnv);
596596

597597
/**
598598
* Parse a Nix expression from the specified string.
599599
*/
600-
Expr * parseExprFromString(std::string s, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv);
600+
Expr *
601+
parseExprFromString(std::string s, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv);
601602
Expr * parseExprFromString(std::string s, const SourcePath & basePath);
602603

603604
Expr * parseStdin();
@@ -766,7 +767,7 @@ public:
766767

767768
#if NIX_USE_BOEHMGC
768769
/** A GC root for the baseEnv reference. */
769-
std::shared_ptr<Env *> baseEnvP;
770+
const std::shared_ptr<Env *> baseEnvP;
770771
#endif
771772

772773
public:
@@ -780,7 +781,7 @@ public:
780781
/**
781782
* The same, but used during parsing to resolve variables.
782783
*/
783-
std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private
784+
const std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private
784785

785786
/**
786787
* Internal primops not exposed to the user.
@@ -862,7 +863,7 @@ private:
862863
size_t length,
863864
Pos::Origin origin,
864865
const SourcePath & basePath,
865-
std::shared_ptr<StaticEnv> & staticEnv);
866+
const std::shared_ptr<StaticEnv> & staticEnv);
866867

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

0 commit comments

Comments
 (0)