diff options
author | Jade Lovelace <lix@jade.fyi> | 2024-08-22 22:44:29 -0700 |
---|---|---|
committer | Rebecca Turner <rbt@sent.as> | 2024-08-26 16:13:03 -0700 |
commit | 0cc285f87b25365b6050753fba76713332185012 (patch) | |
tree | 6465237250ec825a5f6cde593dad73e8c9563eac /src/libexpr/value.hh | |
parent | ca08f1217d8779971d4f2b306a19ad5622360372 (diff) |
treewide: fix a bunch of lints
Fixes:
- Identifiers starting with _ are prohibited
- Some driveby header dependency cleaning which wound up with doing some
extra fixups.
- Fucking C style casts, man. C++ made these 1000% worse by letting you
also do memory corruption with them with references.
- Remove casts to Expr * where ExprBlackHole is an incomplete type by
introducing an explicitly-cast eBlackHoleAddr as Expr *.
- An incredibly illegal cast of the text bytes of the StorePath hash
into a size_t directly. You can't DO THAT.
Replaced with actually parsing the hash so we get 100% of the bits
being entropy, then memcpying the start of the hash. If this shows
up in a profile we should just make the hash parser faster with a
lookup table or something sensible like that.
- This horrendous bit of UB which I thankfully slapped a deprecation
warning on, built, and it didn't trigger anywhere so it was dead
code and I just deleted it. But holy crap you *cannot* do that.
inline void mkString(const Symbol & s)
{
mkString(((const std::string &) s).c_str());
}
- Some wrong lints. Lots of wrong macro lints, one wrong
suspicious-sizeof lint triggered by the template being instantiated
with only pointers, but the calculation being correct for both
pointers and not-pointers.
- Exceptions in destructors strike again. I tried to catch the
exceptions that might actually happen rather than all the exceptions
imaginable. We can let the runtime hard-kill it on other exceptions
imo.
Change-Id: I71761620846cba64d66ee7ca231b20c061e69710
Diffstat (limited to 'src/libexpr/value.hh')
-rw-r--r-- | src/libexpr/value.hh | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/libexpr/value.hh b/src/libexpr/value.hh index 57485aa0a..e38b11cbf 100644 --- a/src/libexpr/value.hh +++ b/src/libexpr/value.hh @@ -136,7 +136,9 @@ class ExternalValueBase std::ostream & operator << (std::ostream & str, const ExternalValueBase & v); -extern ExprBlackHole eBlackHole; +/** This is just the address of eBlackHole. It exists because eBlackHole has an + * incomplete type at usage sites so is not possible to cast. */ +extern Expr *eBlackHoleAddr; struct NewValueAs { @@ -196,6 +198,7 @@ private: public: // Discount `using NewValueAs::*;` +// NOLINTNEXTLINE(bugprone-macro-parentheses) #define USING_VALUETYPE(name) using name = NewValueAs::name USING_VALUETYPE(integer_t); USING_VALUETYPE(floating_t); @@ -473,7 +476,7 @@ public: /// Constructs an evil thunk, whose evaluation represents infinite recursion. explicit Value(blackhole_t) : internalType(tThunk) - , thunk({ .env = nullptr, .expr = reinterpret_cast<Expr *>(&eBlackHole) }) + , thunk({ .env = nullptr, .expr = eBlackHoleAddr }) { } Value(Value const & rhs) = default; @@ -513,7 +516,10 @@ public: // type() == nThunk inline bool isThunk() const { return internalType == tThunk; }; inline bool isApp() const { return internalType == tApp; }; - inline bool isBlackhole() const; + inline bool isBlackhole() const + { + return internalType == tThunk && thunk.expr == eBlackHoleAddr; + } // type() == nFunction inline bool isLambda() const { return internalType == tLambda; }; @@ -669,11 +675,6 @@ public: void mkStringMove(const char * s, const NixStringContext & context); - inline void mkString(const Symbol & s) - { - mkString(((const std::string &) s).c_str()); - } - void mkPath(const SourcePath & path); inline void mkPath(const char * path) @@ -732,7 +733,11 @@ public: lambda.fun = f; } - inline void mkBlackhole(); + inline void mkBlackhole() + { + internalType = tThunk; + thunk.expr = eBlackHoleAddr; + } void mkPrimOp(PrimOp * p); @@ -832,18 +837,6 @@ public: } }; - -bool Value::isBlackhole() const -{ - return internalType == tThunk && thunk.expr == (Expr*) &eBlackHole; -} - -void Value::mkBlackhole() -{ - internalType = tThunk; - thunk.expr = (Expr*) &eBlackHole; -} - using ValueVector = GcVector<Value *>; using ValueMap = GcMap<Symbol, Value *>; using ValueVectorMap = std::map<Symbol, ValueVector>; |