diff options
author | Silvan Mosberger <contact@infinisil.com> | 2024-02-09 05:31:01 +0100 |
---|---|---|
committer | Silvan Mosberger <contact@infinisil.com> | 2024-02-09 05:45:31 +0100 |
commit | 27488b861c50f9354bf07e7228164f30c2e6d660 (patch) | |
tree | 976e446dee1c869ee95924053543a642f3e3ec91 /lib | |
parent | 442d407992384ed9c0e6d352de75b69079904e4e (diff) | |
download | nixlib-27488b861c50f9354bf07e7228164f30c2e6d660.tar nixlib-27488b861c50f9354bf07e7228164f30c2e6d660.tar.gz nixlib-27488b861c50f9354bf07e7228164f30c2e6d660.tar.bz2 nixlib-27488b861c50f9354bf07e7228164f30c2e6d660.tar.lz nixlib-27488b861c50f9354bf07e7228164f30c2e6d660.tar.xz nixlib-27488b861c50f9354bf07e7228164f30c2e6d660.tar.zst nixlib-27488b861c50f9354bf07e7228164f30c2e6d660.zip |
lib.trivial: Remove unneeded polyfills
Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/trivial.nix | 19 | ||||
-rw-r--r-- | lib/zip-int-bits.nix | 39 |
2 files changed, 2 insertions, 56 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix index 58620006de15..fa499cbbf028 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -95,21 +95,6 @@ in { /* boolean “and” */ and = x: y: x && y; - /* bitwise “and” */ - bitAnd = builtins.bitAnd - or (import ./zip-int-bits.nix - (a: b: if a==1 && b==1 then 1 else 0)); - - /* bitwise “or” */ - bitOr = builtins.bitOr - or (import ./zip-int-bits.nix - (a: b: if a==1 || b==1 then 1 else 0)); - - /* bitwise “xor” */ - bitXor = builtins.bitXor - or (import ./zip-int-bits.nix - (a: b: if a!=b then 1 else 0)); - /* bitwise “not” */ bitNot = builtins.sub (-1); @@ -165,8 +150,8 @@ in { inherit (builtins) pathExists readFile isBool isInt isFloat add sub lessThan - seq deepSeq genericClosure; - + seq deepSeq genericClosure + bitAnd bitOr bitXor; ## nixpkgs version strings diff --git a/lib/zip-int-bits.nix b/lib/zip-int-bits.nix deleted file mode 100644 index 53efd2bb0a04..000000000000 --- a/lib/zip-int-bits.nix +++ /dev/null @@ -1,39 +0,0 @@ -/* Helper function to implement a fallback for the bit operators - `bitAnd`, `bitOr` and `bitXor` on older nix version. - See ./trivial.nix -*/ -f: x: y: - let - # (intToBits 6) -> [ 0 1 1 ] - intToBits = x: - if x == 0 || x == -1 then - [] - else - let - headbit = if (x / 2) * 2 != x then 1 else 0; # x & 1 - tailbits = if x < 0 then ((x + 1) / 2) - 1 else x / 2; # x >> 1 - in - [headbit] ++ (intToBits tailbits); - - # (bitsToInt [ 0 1 1 ] 0) -> 6 - # (bitsToInt [ 0 1 0 ] 1) -> -6 - bitsToInt = l: signum: - if l == [] then - (if signum == 0 then 0 else -1) - else - (builtins.head l) + (2 * (bitsToInt (builtins.tail l) signum)); - - xsignum = if x < 0 then 1 else 0; - ysignum = if y < 0 then 1 else 0; - zipListsWith' = fst: snd: - if fst==[] && snd==[] then - [] - else if fst==[] then - [(f xsignum (builtins.head snd))] ++ (zipListsWith' [] (builtins.tail snd)) - else if snd==[] then - [(f (builtins.head fst) ysignum )] ++ (zipListsWith' (builtins.tail fst) [] ) - else - [(f (builtins.head fst) (builtins.head snd))] ++ (zipListsWith' (builtins.tail fst) (builtins.tail snd)); - in - assert (builtins.isInt x) && (builtins.isInt y); - bitsToInt (zipListsWith' (intToBits x) (intToBits y)) (f xsignum ysignum) |