-
Notifications
You must be signed in to change notification settings - Fork 58
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
extra_trait_impls: Extra trait implementations #230
Conversation
…pe of Concat to Rhs.
# Conflicts: # src/uint/concat.rs
Sorry, saw the failing CI when it was too late yesterday, but should be good to merge now |
As a general note there's a lot of copied and pasted code that should be DRYed out. Really it's code that probably shouldn't have been in macros to begin with. But it definitely shouldn't be copied and pasted in nearly identical form into a second macro. Try to find a way to compose the macros, or failing that, extract the code into a named function the macro-written code can call. |
Honestly, I thought that about the previous macros in the first place, just went with your convention. If we'd have switched to proc macros, we might have been able to avoid all of these hundreds of macro invocations? I imagined code that simply iterates through the range But if we change that, I think it'd better to change the original macros as well. Is this too much ? |
I don't want to add a hard dependency on e.g. Also I don't see how a proc macro would even help here. You can't use custom derive, since types like |
The real solution to all of this is to better leverage const generics when the relevant functionality, namely Then we can have an actual generic implementation, rather than having to use macros and hardcoding to specific sizes. All of that is a workaround so we can support stable Rust. But this PR and #229 are pushing the scalability of that approach. |
So, how to proceed? What if we added a If not, should we continue on with the current implementation or do you have another suggestion? |
The code will require significant refactoring to make use of I think what you're doing mostly works if you can find a way to DRY out the impls. I can also take a shot at it. It would probably be worth refactoring the code prior to trying to expand it. |
If what you're aiming at is simply to reduce code duplication, I think I could do this refactoring. What I'm thinking of:
|
That seems like it would perform needless work? Perhaps LLVM could optimize it away. Otherwise that sounds fine. The main important thing is to avoid duplicating the implementation and having one place to make changes/optimizations to it. |
It does sound like that, which was why I didn't do it in the first place I guess. I'll avoid that. Don't know if we want to rely on compiler optimizations. Although this is really negligent work compared to big-int operations. |
…tra_trait_impls submodules
# Conflicts: # Cargo.toml # src/uint.rs
All done, however this introduced a new problem I'm not sure how to overcome: doing both I can only think of two options to solve this really
@tarcieri I'd love your thoughts on this, maybe you'll have a better option. |
These sorts of problems are exactly what I was worrying about with compile times, and why I wanted you to feature gate them. We may need to pick one or the other feature.
Ugh, I guess. This is adding a lot of complexity to the crate's API surface and will make the other features harder to discover for being buried in a bunch of size-specific features.
The macros add trait impls to While it would be possible to add macros that define a newtype and add trait impls to that, you won't be able to use them with other Another option is to (ab)use If you think it will work, try it, but I think you'll quickly discover it's a problematic approach. |
Yeah, I thought that was the reason, and don’t see a way we could overcome it (for 2) We could have This would allow me to e.g. multiply Ans this isn't limited to me, I'd argue that most use cases arise from multiplying powers of two. Maybe some are using e.g. Alt is to do per-size configs, which for the above mentioned reasons is not recommended. I guess if this crate survived so far on a per-need basis of size addition, we could do that, I just tried to solve the problem once and for all. |
55de29f
to
480a89c
Compare
@tarcieri I reverted the last commit that tried to have both I have tried to take the more generic path here with (In that case, I wouldn't actually need |
@@ -0,0 +1,48 @@ | |||
macro_rules! convert_internal { |
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 this is added to address issue #220, but resize()
should suffice for the conversion.
Resolves #225, #220, #209.
Replaces #224, #226, #219.