Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate away from bitflags #708

Closed
sunfishcode opened this issue Jun 28, 2023 · 2 comments
Closed

Migrate away from bitflags #708

sunfishcode opened this issue Jun 28, 2023 · 2 comments
Labels
semver bump Issues that will require a semver-incompatible fix

Comments

@sunfishcode
Copy link
Member

Bitflags' from_bits_truncate does more than just mask off a fixed set of bits; it insists that all multi-bit flags be either completely present or completely absent. This makes it unsuitable for mask constants that include multiple bits where the individual bits may not all be defined yet but which may be defined in the future. And, bitflags' complement clears any unknown bits, breaking the a & !b idiom if there are any flags that are not defined yet but which may be defined in the future. In general, bitflags appears to be trying to be two things at once, sometimes appearing to enforce invariants about unknown or multiple-bit flags, but other times not.

Rustix's use of bitflags is to describe flags that are defined externally by the OS. New flags may defined that rustix doesn't yet know about, and rustix should preserve these flags. And OS's have their own conventions around multiple-bit flags which aren't always the same as what bitflags expects. Consequently, rustix would be better served by a bitflags alternative which doesn't attempt to (even incompletely) enforce any invariants about unknown flags or multiple-bit flags.

@sunfishcode sunfishcode added the semver bump Issues that will require a semver-incompatible fix label Jun 28, 2023
@sunfishcode
Copy link
Member Author

With #787 we now use bitflags 2.4's const _ = !0 feature, which tells bitflags to treat all bits as "known" and avoid ever masking them out, so migrating off of bitflags is less urgent now.

@sunfishcode
Copy link
Member Author

As noted above, this is less urgent now. Bitflags still appears to be by far the most popular flags utility library, so I think it makes sense to continue using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver bump Issues that will require a semver-incompatible fix
Projects
None yet
Development

No branches or pull requests

1 participant