1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Merge pull request #14366 from NixOS/const-fields

EvalState: Make some more fields const
This commit is contained in:
Eelco Dolstra 2025-10-27 17:47:21 +00:00 committed by GitHub
commit 126f30deb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 17 deletions

View file

@ -3067,7 +3067,7 @@ Expr * EvalState::parseExprFromFile(const SourcePath & path)
return parseExprFromFile(path, staticBaseEnv); return parseExprFromFile(path, staticBaseEnv);
} }
Expr * EvalState::parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv) Expr * EvalState::parseExprFromFile(const SourcePath & path, const std::shared_ptr<StaticEnv> & staticEnv)
{ {
auto buffer = path.resolveSymlinks().readFile(); auto buffer = path.resolveSymlinks().readFile();
// readFile hopefully have left some extra space for terminators // readFile hopefully have left some extra space for terminators
@ -3075,8 +3075,8 @@ Expr * EvalState::parseExprFromFile(const SourcePath & path, std::shared_ptr<Sta
return parse(buffer.data(), buffer.size(), Pos::Origin(path), path.parent(), staticEnv); return parse(buffer.data(), buffer.size(), Pos::Origin(path), path.parent(), staticEnv);
} }
Expr * Expr * EvalState::parseExprFromString(
EvalState::parseExprFromString(std::string s_, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv) std::string s_, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv)
{ {
// NOTE this method (and parseStdin) must take care to *fully copy* their input // NOTE this method (and parseStdin) must take care to *fully copy* their input
// into their respective Pos::Origin until the parser stops overwriting its input // into their respective Pos::Origin until the parser stops overwriting its input
@ -3210,7 +3210,11 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
} }
Expr * EvalState::parse( Expr * EvalState::parse(
char * text, size_t length, Pos::Origin origin, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv) char * text,
size_t length,
Pos::Origin origin,
const SourcePath & basePath,
const std::shared_ptr<StaticEnv> & staticEnv)
{ {
DocCommentMap tmpDocComments; // Only used when not origin is not a SourcePath DocCommentMap tmpDocComments; // Only used when not origin is not a SourcePath
DocCommentMap * docComments = &tmpDocComments; DocCommentMap * docComments = &tmpDocComments;

View file

@ -191,7 +191,7 @@ std::ostream & operator<<(std::ostream & os, const ValueType t);
struct RegexCache; struct RegexCache;
std::shared_ptr<RegexCache> makeRegexCache(); ref<RegexCache> makeRegexCache();
struct DebugTrace struct DebugTrace
{ {
@ -372,6 +372,7 @@ public:
const fetchers::Settings & fetchSettings; const fetchers::Settings & fetchSettings;
const EvalSettings & settings; const EvalSettings & settings;
SymbolTable symbols; SymbolTable symbols;
PosTable positions; PosTable positions;
@ -418,7 +419,7 @@ public:
RootValue vImportedDrvToDerivation = nullptr; RootValue vImportedDrvToDerivation = nullptr;
ref<fetchers::InputCache> inputCache; const ref<fetchers::InputCache> inputCache;
/** /**
* Debugger * Debugger
@ -471,18 +472,18 @@ private:
/* Cache for calls to addToStore(); maps source paths to the store /* Cache for calls to addToStore(); maps source paths to the store
paths. */ paths. */
ref<boost::concurrent_flat_map<SourcePath, StorePath>> srcToStore; const ref<boost::concurrent_flat_map<SourcePath, StorePath>> srcToStore;
/** /**
* A cache that maps paths to "resolved" paths for importing Nix * A cache that maps paths to "resolved" paths for importing Nix
* expressions, i.e. `/foo` to `/foo/default.nix`. * expressions, i.e. `/foo` to `/foo/default.nix`.
*/ */
ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache; const ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache;
/** /**
* A cache from resolved paths to values. * A cache from resolved paths to values.
*/ */
ref<boost::concurrent_flat_map< const ref<boost::concurrent_flat_map<
SourcePath, SourcePath,
Value *, Value *,
std::hash<SourcePath>, std::hash<SourcePath>,
@ -504,7 +505,7 @@ private:
/** /**
* Cache used by prim_match(). * Cache used by prim_match().
*/ */
std::shared_ptr<RegexCache> regexCache; const ref<RegexCache> regexCache;
public: public:
@ -592,12 +593,13 @@ public:
* Parse a Nix expression from the specified file. * Parse a Nix expression from the specified file.
*/ */
Expr * parseExprFromFile(const SourcePath & path); Expr * parseExprFromFile(const SourcePath & path);
Expr * parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv); Expr * parseExprFromFile(const SourcePath & path, const std::shared_ptr<StaticEnv> & staticEnv);
/** /**
* Parse a Nix expression from the specified string. * Parse a Nix expression from the specified string.
*/ */
Expr * parseExprFromString(std::string s, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv); Expr *
parseExprFromString(std::string s, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv);
Expr * parseExprFromString(std::string s, const SourcePath & basePath); Expr * parseExprFromString(std::string s, const SourcePath & basePath);
Expr * parseStdin(); Expr * parseStdin();
@ -766,7 +768,7 @@ public:
#if NIX_USE_BOEHMGC #if NIX_USE_BOEHMGC
/** A GC root for the baseEnv reference. */ /** A GC root for the baseEnv reference. */
std::shared_ptr<Env *> baseEnvP; const std::shared_ptr<Env *> baseEnvP;
#endif #endif
public: public:
@ -780,7 +782,7 @@ public:
/** /**
* The same, but used during parsing to resolve variables. * The same, but used during parsing to resolve variables.
*/ */
std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private const std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private
/** /**
* Internal primops not exposed to the user. * Internal primops not exposed to the user.
@ -862,7 +864,7 @@ private:
size_t length, size_t length,
Pos::Origin origin, Pos::Origin origin,
const SourcePath & basePath, const SourcePath & basePath,
std::shared_ptr<StaticEnv> & staticEnv); const std::shared_ptr<StaticEnv> & staticEnv);
/** /**
* Current Nix call stack depth, used with `max-call-depth` setting to throw stack overflow hopefully before we run * Current Nix call stack depth, used with `max-call-depth` setting to throw stack overflow hopefully before we run

View file

@ -4611,9 +4611,9 @@ struct RegexCache
} }
}; };
std::shared_ptr<RegexCache> makeRegexCache() ref<RegexCache> makeRegexCache()
{ {
return std::make_shared<RegexCache>(); return make_ref<RegexCache>();
} }
void prim_match(EvalState & state, const PosIdx pos, Value ** args, Value & v) void prim_match(EvalState & state, const PosIdx pos, Value ** args, Value & v)