mirror of
https://github.com/RGBCube/Site
synced 2025-08-01 13:37:49 +00:00
Clarify attrset ptr equality in Nix
This commit is contained in:
parent
95eba30a2c
commit
d7b896aff5
1 changed files with 21 additions and 5 deletions
|
@ -699,8 +699,24 @@ Normally, Functions in Nix cannot be compared. Comparing
|
||||||
two functions will _always_ return false, at least when done
|
two functions will _always_ return false, at least when done
|
||||||
directly.
|
directly.
|
||||||
|
|
||||||
However, Nix has a [really ugly hack]()
|
But if two attribute sets that are compared have the same address,
|
||||||
where comparing two attribute sets with a function member can be true,
|
Nix ignores this and does a pointer comparision, totally ignoring
|
||||||
assuming the underlying pointer of a struct field value points to the
|
all members. This is a hack.
|
||||||
same function, the princible described in the previous paragraph is
|
|
||||||
ignored.
|
[Link to code that does this.](https://github.com/NixOS/nix/blob/aa165301d1ae3b306319a6a834dc1d4e340a7112/src/libexpr/eval.cc#L2525-L2528)
|
||||||
|
Here's the snippet:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
bool EvalState::eqValues(Value & v1, Value & v2, const PosIdx pos, std::string_view errorCtx)
|
||||||
|
{
|
||||||
|
forceValue(v1, pos);
|
||||||
|
forceValue(v2, pos);
|
||||||
|
|
||||||
|
/* !!! Hack to support some old broken code that relies on pointer
|
||||||
|
equality tests between sets. (Specifically, builderDefs calls
|
||||||
|
uniqList on a list of sets.) Will remove this eventually. */
|
||||||
|
if (&v1 == &v2) return true;
|
||||||
|
```
|
||||||
|
|
||||||
|
This "temporary hack" was commited in 14 years ago. You can do whatever
|
||||||
|
you want with this information.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue