-
Notifications
You must be signed in to change notification settings - Fork 4
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
Clean up the associated constants #54
Conversation
One more important thing I should mention is that I added
to |
b909bd5
to
e7153d8
Compare
Almost forgot to run |
Codecov Report
@@ Coverage Diff @@
## master #54 +/- ##
==========================================
+ Coverage 75.74% 76.16% +0.42%
==========================================
Files 21 21
Lines 5363 5329 -34
==========================================
- Hits 4062 4059 -3
+ Misses 1301 1270 -31
Continue to review full report at Codecov.
|
I cleaned Travis CI caches and now it works again. |
Is it easy to add a CI bot that checks that the crate is formatted? |
Rust itself is trying to fix some associated constant related warts: rust-lang/rfcs#2700 |
I don't see anyway to make this more reviewable. This only changes the way
Previously in my crate reorganization suggestions, I had them used through an Other small structs that we expose to users are exposed at the crate root, and if we were to hypothetically expose |
Its been one month. I am curious about how long it takes you to review PRs. |
Sorry I forgot about it. :S Will review in the course of today (sunday) or tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, 1 question pls resolve
DataAccess::Ext(digits) => { | ||
let (last, rest) = digits.split_last().unwrap_or_else(|| unreachable!()); | ||
last.is_one() && rest.iter().all(|digit| digit.is_zero()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I prefer the is_one
version more because it is more readable imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I can keep is_one
as a method for internal Digit
use. Digit::ONE
is used often enough that it could stay.
I am thinking about removing all is_one
and creation of value 1 ApInt
s. The reason for this is the corner case where single bit signed interpretation ApInt
s can only represent negative one and zero. I thought about using this documentation:
/// Returns `true` if the **unsigned** interpretation `ApInt` represents the value one (`1`).
///
/// # Corner Case
///
/// Normally, both signed and unsigned `ApInt`s have the same representation for the value one.
/// However, the most significant and least significant bits are the same bit for
/// `ApInt`s with a bitwidth of 1. This means that signed `ApInt`s with bitwidth 1
/// can only represent negative one and zero. This function treats the
/// `ApInt` as unsigned in this corner case.
///
/// # Note
///
/// - One (`1`) is also called the multiplicative neutral element.
/// - This operation is more efficient than comparing two instances of `ApInt`
The corner case problems stack up when considering what Int
will do. Single bit ApInt
s with a set bit also fall under the more general case of ApInt::signed_min_value()
. I think I should add some documentation on the ApInt
struct or very high up about being careful with ApInt::signed_min_value()
in algorithms and mentioning single bit ApInt
s.
I think that zero, unsigned_min_value, unsigned_max_value, signed_min_value, and signed_max_value are the only special numbers that get their own functions.
Should I remove all public facing special is_one
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the documentation I could give an example of the proper way to handle magic numbers.
For example, handling creation of 1 can be handled ApInt::unsigned_max_value(bitwidth 1).unsigned_extension_fn...
or ApInt::from(123u8).extend...
which forces the user to consider what happens with small bitwidth values
This makes constants such as
digit::ZERO
anddigit::BITS
into associated constants, which makes more sense and eliminates several imports fordigit
. I also remove redundant functions such asDigit::zero()
andDigit::is_all_set()
. I decided to keepDigit::is_zero()
because of how often it is used and regularized all comparisons ofDigit::ZERO
.