-
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
Crate reorganization and upgrade to Rust 2018 #36
Conversation
Codecov Report
@@ Coverage Diff @@
## master #36 +/- ##
==========================================
+ Coverage 75.94% 77.48% +1.53%
==========================================
Files 22 29 +7
Lines 5117 5471 +354
==========================================
+ Hits 3886 4239 +353
- Misses 1231 1232 +1
Continue to review full report at Codecov.
|
Is this ready again for another review? If so I would try to do that on the upcoming weekend. :) I am also looking into writing some proper contribution guidelines and CI integration for |
That should fix most of the problems. This is ready for review. |
rustfmt.toml
Outdated
@@ -0,0 +1,24 @@ | |||
# all formatting is executed and checked on the developer's side |
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 would be very happy if you use the following rustfmt.toml file configuration and re-format the entire PR: https://github.com/Robbepop/pdsl/blob/master/.rustfmt.toml
This format config is well suited for reviewing PRs.
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.
Also I am thinking about adding the following extra compiler warnings and lints to improve the readability of the entire code base so that it becomes easier for users not familiar with the code base to hack on. After your changes and the new release we might see more users.
https://github.com/Robbepop/pdsl/blob/master/model/src/lib.rs#L19
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.
Besides that I am planning to extend the CI pipeline to include rustfmt checks as well as clippy lints.
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.
So it would be awesome if you could already check for clippy warnings in your PR if you didn't do that already. ;)
mod to_primitive; | ||
|
||
pub(crate) use self::to_primitive::PrimitiveTy; | ||
mod casting; |
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.
This git diff looks strange to me. What has changed here? Is it a preview bug?
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 what is happening here is that the newlines were \r\n
and all converted to \n
. Next time I will make the newline conversion a separate commit
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.
Okay thanks for clearing that up!
src/construction/casting.rs
Outdated
where | ||
W: Into<BitWidth>, | ||
{ | ||
where W: Into<BitWidth> { |
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.
This where
clause formatting is inferior to the previous one when it comes to easily edit a where clause which happens frequently during prototyping of new code. I am really a fan of the old formatting because of this reason.
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.
ok
src/construction/casting.rs
Outdated
@@ -198,8 +191,8 @@ impl ApInt { | |||
if target_width < actual_width { | |||
return Error::extension_bitwidth_too_small(target_width, actual_width) | |||
.with_annotation(format!( | |||
"Cannot sign-extend bit-width of {:?} to {:?} bits. \ | |||
Do you mean to truncate the instance instead?", | |||
"Cannot sign-extend bit-width of {:?} to {:?} bits. Do you mean to truncate \ |
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.
Are these reformattings of comments the result of rustfmt auto formatting?
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.
Yes. Do you not like them?
src/construction/casting.rs
Outdated
/// the given `ApInt` | ||
/// - [`sign_extend`](struct.ApInt.html#method.sign_extend) | ||
/// otherwise | ||
/// - [`truncate`](struct.ApInt.html#method.truncate) if `target_width` is less than or equal to |
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 have the feeling that this PR is only soooo immensely big because you merged reorganization with auto formatting. Please make PRs with a singular step in the future. So this one huge PR would be at least two PRs.
src/construction/casting.rs
Outdated
// ApInt::repeat_digit(width_512, 0x0000_FFFF_FFFF_0000), | ||
// ApInt::repeat_digit(width_512, 0x0000_0000_FFFF_FFFF), | ||
// ApInt::all_set(width_512), | ||
/* ApInt::zero(width_256), |
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 am strictly against having C-style comments in any Rust code base.
Please either remove this part completely since it seems to be not relevant since long time or revert the comment change.
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.
For some reason, rustfmt wants to do this. I will remove it.
src/construction/constructors.rs
Outdated
pub fn from_bool(bit: bool) -> ApInt { | ||
ApInt::new_inl(BitWidth::w1(), Digit(bit as DigitRepr)) | ||
} | ||
pub fn from_bool(bit: bool) -> ApInt { ApInt::new_inl(BitWidth::w1(), Digit(bit as DigitRepr)) } |
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 won't comment the following auto-formatting issues but to be honest I really dislike these single super long lines. I am very much in favor of short lines that make it easy to follow along and review in PRs.
I stopped reviewing this (again) giantic PR because it was just a mess to review all the changes properly if they are mixed with all the unrelevant rustfmt changes. |
488cad8
to
b833d82
Compare
It is ready to review again. Remember that the comment spacing fixing is going to be part of the rustfmt PR. |
mod to_primitive; | ||
|
||
pub(crate) use self::to_primitive::PrimitiveTy; | ||
mod casting; |
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.
Okay thanks for clearing that up!
src/data/apint.rs
Outdated
} | ||
} | ||
|
||
//this is put here to be able to constrict the publicity of `ApIntData` |
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.
What does that mean?
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.
The one problem we will have with the reorganization is that I could not make some of the fields of Apint
and ApIntData
private. I moved some test code (that used private fields) into that file so that I could constrict the visibility as much as I could. Everything except for the len
field is constricted to pub(in crate::data)
, and from there I searched the codebase manually to make sure the fields were only being directly accessed in the right places.
} | ||
zeros | ||
} | ||
} | ||
|
||
// =========================================================================== |
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.
Where have all these gone?
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.
Those went into the traits.rs
file along with all the other trait impls for ApInt
s
/// | ||
/// However, this function avoids allocation and has many optimized branches for different input | ||
/// sizes and shifts. | ||
pub fn rotate_left_assign<S>(&mut self, shift_amount: S) -> Result<()> |
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.
Could these implementations maybe profit from using https://doc.rust-lang.org/std/primitive.u64.html#method.rotate_left and https://doc.rust-lang.org/std/primitive.slice.html#method.rotate_left under the hood? I guess they could a lot!
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.
Funnily enough, I ended up not using any core bitwise rotate functions due to the way this algorithm played out. The single Digit
case, for example, did not use it because of support for odd width ApInt
s.
In the future, I will use the slice rotate function. I am keeping the current one for now because it is faster than the standard one for 1024 bit ApInt
s or less. I will eventually submit a PR to improve the standard library slice rotate function, and once that is approved I will submit a PR to simplify the apint
function a little.
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.
After your work on the standard rotation functions would this be worth a try again?
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.
The Digit
wise rotation code in question currently uses the standard rotation function, and thus will benefit. The rest of the code deals with bitwise stuff.
We get a lot more unused warnings when default features are disabled. Spamming |
I think maybe we could have a |
My free time is opening up again. I am preparing some commits to fix some issues you had when reviewing this PR. I noticed during cleaning up inconsistencies with the trait implementations that there is cloning going on in the ones with
|
Sounds good! |
This is ready for another round of review |
I can't do the parsing PR before I do the error refactor before I do the rustfmt refactor before this PR is reviewed and accepted. This is blocking all of my work on this crate now, just so you know. |
ae49071
to
2b0f493
Compare
I decided to replace the slice rotate i wrote with the standard library's |
Sounds like a really good idea! Looking forward to see progress on it. |
My performance improvements are almost in the standard library. |
Cool! Thanks for letting me know. |
I have been looking at my multiplication implementation to see if I could improve performance around negative numbers. In the case of the division operations, I could mutate both |
This, and we should only introduce this new function if the wins are actually significant. |
The link to the PR is here. It took a lot more work than expected to make an improvement nearly everywhere |
A recap on things this PR won't fix:
|
Please, for the sake of clarity create an issue for every TODO comment left so that we can track them and discuss them.
Are they a major problem? |
The warnings are all unused warnings or the one rand documentation warning. It isn't worth it to track each TODO, all 15 of them are pretty self-explanatory. I am not bothering with fixing them yet. |
Is there someone you know who could help review this? |
Would you rather me close this PR and start over from square one? I fear though that it would take the rest of this summer to get the state of this crate to where this PR is. |
I think the main problem with PRs like this is that they are just too big to be properly reviewed so that the reviewer actually get the grasp of the changes. Programming is hard enough after all and it is easy enough to get something wrong. Even though the state of this PR is not review friendly I am leaning in on merging it as soon as I am faithful in my review and understanding about it since you put so much work and energy into it. I wouldn't want to waste all that work. Since I do not know a single other person that could or would review this PR let's do the following: |
Co-Authored-By: Hero Bird <robbepop@web.de>
Co-Authored-By: Hero Bird <robbepop@web.de>
Co-Authored-By: Hero Bird <robbepop@web.de>
When you clone my branch and run I am going to be so glad when this finally gets merged and squashed. After this, we do some Rustfmt rounds, I run updated Clippy, and then we can finally get to business with smaller PRs. |
Is there more you can get done this weekend? |
My slice rotation code just got merged in rust PR #61937! |
Every few weeks I get tripped up by |
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.
Every few weeks I get tripped up by
excess_bits
, thinking that it returns the number of unused bits. You have some documentation saying "Note: A better name for this method has yet to be found!". I didn't want to rename itodd_bits
because of name collision with odd numbers.
After looking up synonyms, I think the best thing I can rename it isweird_bits
. Can I rename it this? I also want to add anunused_bits
function which does the opposite and does not use anOption
.
Excess bits state the intent clearer than "weird" or "odd" bits imo.
Just saw that I still had a pending PR from ages ago on this ....
I made a overflowing multiplication (not public currently) for the string functions I am working on, and in the process broke up the multiplication into more manageable chunks. |
I rushed that commit whoops |
cdb3f58
to
f029095
Compare
I was moving into my college dorm room and wanted to do one last commit before I left. Can you merge this PR before next week? |
I am at CCCamp from on tomorrow so won't have that much time this week. |
I am suddenly in need of a bunch of |
|
Hey, sorry for my late response to your latest comment. However, I do not feel like this PR is ever going to be merged in its current bloaty state. I am really sorry to say that because of all the work you have put into this PR (and others). I am willing to accept your changes but they have to be completely reorganized into many smaller PRs (this single PR would easily suffice to be split into 10 smaller PRs or so). Then we can simply review them in chunks and everything will be easy to review. Your other option is that you create a fork of this library with your changes so you can apply every change without my review. Of course this would be a disrution in the ecosystem if we have two similar crates instead of focussing efforts on a single one. The license, however, happily allows you to do so as well. Please do not feel rejected by my decision. Your work has been great and really appreciated by me. However, this PR went kind of sideways by simply trying to solve all problems at once. |
I don't understand. I know this crate inside out by now, and I thought we were really close to merging this. Of course something as big as this is going to have problems, but I have looked over everything multiple times and you have double checked and revealed some small issues which I fixed. I can't think of any problems with what this PR in its current state would do to master, except for the needed rustfmt and pasting a bunch of stuff into This PR brings stuff like the overflowing functions which I have not made public yet out of an abundance of caution. My conservative estimate is that we could put out a 0.3.0 by the end of the year, and close every one of the issues open now by 2020. If you commit to closing this PR, my conservative estimate regarding the rate at which you accept PRs is that I will be graduated and have some kind of job that consumes all my time before this crate ever gets close to the 0.3.x I envision, and development will be softlocked worse than it already is. |
Your work is not lost.
I see it quite contrary to this. To be honest the big PRs that touch nearly every bit of a codebase pretty much drained all my motivation to work on other stuff for the crate because everything is going to change anyway and touching everything also conflicts with everything which is a mess. Maybe that is a personal or subjective opinion but that's how it felt to me always. I will now work on some small things that are moving the crate into a better shape for contributions. |
Some things to note:
#[rustfmt::skip]
wherever I disagreed with Rustfmt.int.rs
anduint.rs
files to reflect the new functions and docs.rand
andcargo doc
, but it is probably due to our outdated dependency should be fixed in a future commit. I plan on updating all the dependencies after the upcoming PRs but before0.3.0
is released.Edit: uh-oh, Rustfmt did not fix the spacing between
//
and the rest of the comment. I will have to add on a commit to fix this