diff options
author | pennae <github@quasiparticle.net> | 2022-03-05 14:40:24 +0100 |
---|---|---|
committer | pennae <github@quasiparticle.net> | 2022-04-21 21:56:31 +0200 |
commit | 8775be33931ec3b1cad97035ff3d5370a97178a1 (patch) | |
tree | 0855d6b35e24153092738315176ea19aa72b9530 /src/libexpr/value.hh | |
parent | 00a32802328b58daa7af48ccac60f6154ef05639 (diff) |
store Symbols in a table as well, like positions
this slightly increases the amount of memory used for any given symbol, but this
increase is more than made up for if the symbol is referenced more than once in
the EvalState that holds it. on average every symbol should be referenced at
least twice (once to introduce a binding, once to use it), so we expect no
increase in memory on average.
symbol tables are limited to 2³² entries like position tables, and similar
arguments apply to why overflow is not likely: 2³² symbols would require as many
string instances (at 24 bytes each) and map entries (at 24 bytes or more each,
assuming that the map holds on average at most one item per bucket as the docs
say). a full symbol table would require at least 192GB of memory just for
symbols, which is well out of reach. (an ofborg eval of nixpks today creates
less than a million symbols!)
Diffstat (limited to 'src/libexpr/value.hh')
-rw-r--r-- | src/libexpr/value.hh | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/libexpr/value.hh b/src/libexpr/value.hh index dc875615c..c46dd4b73 100644 --- a/src/libexpr/value.hh +++ b/src/libexpr/value.hh @@ -55,7 +55,7 @@ struct Env; struct Expr; struct ExprLambda; struct PrimOp; -class Symbol; +class SymbolIdx; class PosIdx; struct Pos; class StorePath; @@ -121,11 +121,11 @@ private: friend std::string showType(const Value & v); - void print(std::ostream & str, std::set<const void *> * seen) const; + void print(const SymbolTable & symbols, std::ostream & str, std::set<const void *> * seen) const; public: - void print(std::ostream & str, bool showRepeated = false) const; + void print(const SymbolTable & symbols, std::ostream & str, bool showRepeated = false) const; // Functions needed to distinguish the type // These should be removed eventually, by putting the functionality that's @@ -253,7 +253,7 @@ public: inline void mkString(const Symbol & s) { - mkString(((const std::string &) s).c_str()); + mkString(std::string_view(s).data()); } inline void mkPath(const char * s) @@ -410,12 +410,12 @@ public: #if HAVE_BOEHMGC typedef std::vector<Value *, traceable_allocator<Value *> > ValueVector; -typedef std::map<Symbol, Value *, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, Value *> > > ValueMap; -typedef std::map<Symbol, ValueVector, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, ValueVector> > > ValueVectorMap; +typedef std::map<SymbolIdx, Value *, std::less<SymbolIdx>, traceable_allocator<std::pair<const SymbolIdx, Value *> > > ValueMap; +typedef std::map<SymbolIdx, ValueVector, std::less<SymbolIdx>, traceable_allocator<std::pair<const SymbolIdx, ValueVector> > > ValueVectorMap; #else typedef std::vector<Value *> ValueVector; -typedef std::map<Symbol, Value *> ValueMap; -typedef std::map<Symbol, ValueVector> ValueVectorMap; +typedef std::map<SymbolIdx, Value *> ValueMap; +typedef std::map<SymbolIdx, ValueVector> ValueVectorMap; #endif |