-
Notifications
You must be signed in to change notification settings - Fork 156
[WIP] DO NOT MERGE: Code reduction #303
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
Conversation
Signed-off-by: Daniel Egger <[email protected]>
Signed-off-by: Daniel Egger <[email protected]>
r? @ryankurte (rust_highfive has picked a reviewer for you, use r? to override) |
Those two changes reduce the file size of a |
Signed-off-by: Daniel Egger <[email protected]>
Signed-off-by: Daniel Egger <[email protected]>
Signed-off-by: Daniel Egger <[email protected]>
Now down to |
CC @adamgreig @jamesmunns @japaric Interested to learn what others think. Changes should be API compatible with what we have now but It would also be possible to move all of that code (and more) into a generic |
|
@burrbull I guess there're a few non-breaking uncontroversial changes which could still be applied. But at the moment this is not going to fly; it's not particularly pretty but also breaks the HAL impls due to the requirement to import the traits. I'm still looking into ways to generically express the individual registers in a way that would allow us have a default trait impl for |
I also made many experiments with traits to make default implementation and could not find good solution of the issue. The main problem is access to bits The only way I could reduce code size is using macros. |
This is the best I could think of. Traits could be moved to vcell crate:
Macros for code reduction:
Usage:
or
|
You forgot about 1bit-wise |
New implementation: #306 |
@burrbull That is very interesting! Lets see whether @japaric is happy to take the vcell change or whether we have to move it someplace else but I like your use of traits; feel free to move more of my code around if you see the chance; I'm not particularly fond of the set...bits functions, they're rather hacky. |
I would bring But in this case they must be |
@burrbull Maybe it'd be possible to use traits and default impls by using the trick here: https://github.com/dtolnay/inherent |
It depends on proc_macro2. It will take time to compile dependencies. |
@burrbull I did not necessarily mean the crate but the idea to avoid having to |
Incorporate where? |
In the generated code. |
I've applied #![feature(prelude_import)]
#![no_std]
#[prelude_import]
use ::std::prelude::v1::*;
#[macro_use]
extern crate std as std;
mod types {
use inherent::inherent;
trait Trait {
fn f(self);
}
pub struct Struct;
impl Struct {
pub fn f(self) {
<Self as Trait>::f(self)
}
}
impl Trait for Struct {
fn f(self) {}
}
}
fn main() {
types::Struct.f();
} it added
|
Yep, I was think along the lines of adding traits for register Read, Write, ... whatever and impls for that traits and those |
Looks like |
I'm still looking at the mechanism, not this particular crate. |
I have idea: The main change is to use generic writer/reader structures (AKA |
Nice! |
In any case, we must release |
Yes, we should do a release soon... |
I made some changes: https://gist.github.com/24a0d1a2e13bb464a7c579a07902a3c6 First part: #331 With better naming: |
I made draft of WProxy. See from 200 line: With const generics it will be: ///Writer Proxy
pub struct WProxy<'a, U, REG, N, FI, const: O: u8> {
w: &'a mut W<U, REG>,
_field: marker::PhantomData<(FI, N)>,
} |
I tried to use associated size type where it's possible and got very nice code: |
Let's close this superseded PR. |
Reduce code by eliminating duplication and boilerplating