Skip to content

Additional arithmetic and bitwise primops #13000

@spacekitteh

Description

@spacekitteh

Is your feature request related to a problem?

Now that #11188 has made integer overflow an error instead of undefined behavior (which would manifest itself as just wrapping around), performing operations on IP and MAC addresses has become much more difficult. Additionally, until #11188, it had to be performed using an incredibly slow pure Nix implementation, which would make any non-trivial usage of such operations easily dominate the evaluation time of a NixOS configuration (e.g. #10387)

Proposed solution

  1. Implement more built-ins for bit manipulation, including left and right shifts. This can be implemented quite easily; e.g. this Lix patch is quite small, with about half of lines of code changed just being documentation and makefile updates.

  2. Implement a power function built-in. This would be very slightly trickier (but still trivial) due to checking whether the arguments are ints or floats. Ideally, it would also include a modulo argument.

Alternative solutions

One alternative to work around the specific issues in the linked issues/PRs would be to implement arbitrary-sized integers, e.g. by using the GNU MP library; but an ideal implementation of this would end up exposing the aforementioned built-ins anyway.

Additional context

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or proposal
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions