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

Generic Part1 #347

Merged
merged 1 commit into from
Aug 2, 2019
Merged

Generic Part1 #347

merged 1 commit into from
Aug 2, 2019

Conversation

burrbull
Copy link
Member

Rebased and reopened.

@rust-highfive
Copy link

r? @therealprof

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools labels Jul 29, 2019
@burrbull burrbull marked this pull request as ready for review July 31, 2019 07:14
@burrbull burrbull requested a review from a team as a code owner July 31, 2019 07:14
@burrbull
Copy link
Member Author

burrbull commented Jul 31, 2019

cc @therealprof

With this PR debug builds grow 1.5% (I think it is because Deref), but source now much cleaner.

Now all right.

It also depends on #358.

@burrbull burrbull force-pushed the generics-p1 branch 2 times, most recently from ef62cc3 to 9fd21ec Compare July 31, 2019 09:50
@burrbull
Copy link
Member Author

cc @Disasm

@burrbull
Copy link
Member Author

@therealprof I've rebased this on master. Test, please.

impl<U, REG> Reg<U, REG>
where
Self: Writable,
U: Copy + Default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this Default equals to "returns zero"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is for bool, u8, u16 u32 and u64.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but these types are not enforced I guess

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are enforced by size type of register or field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's possible to create a wrapper with the same size and a custom Default impl that returns reset value, for example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How? All fields are private. You can get register only from peripheral as it was before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, now I see. Thanks.

@Disasm
Copy link
Member

Disasm commented Jul 31, 2019

Send and !Sync were implemented on registers before, with this change they are not implemented.
UPD: I'm wrong, they are implemented for Reg, but with bounds on the generic parameters.

@burrbull
Copy link
Member Author

Send and !Sync were implemented on registers before, with this change they are not implemented.

It was auto-implementation?

@Disasm
Copy link
Member

Disasm commented Jul 31, 2019

Yes, I think that was due to the inner VolatileCell: it's also Send and !Sync.

@Disasm
Copy link
Member

Disasm commented Jul 31, 2019

As discussed on Matrix, documentation becomes even more difficult to understand with this change: it's unclear how to read and write registers, also there is no information about field variants.

@therealprof
Copy link
Contributor

TBH I'm not too sure whether we really need that VolatileCell anyway once we've remodelled everything. 😅

@Disasm
Copy link
Member

Disasm commented Jul 31, 2019

@therealprof Yes, but it's better to have Send and !Sync anyway, because they add important properties.

@burrbull
Copy link
Member Author

error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now

What to do with this?

@Disasm
Copy link
Member

Disasm commented Jul 31, 2019

I think that PhantomData with some weird type can help

@burrbull
Copy link
Member Author

Can you write how you see implementation for !Sync?

@Disasm
Copy link
Member

Disasm commented Jul 31, 2019

Seems like !Sync is already implemented for Reg, but as for Send it's difficult to say whether it's implemented or not for a specific register.

@burrbull
Copy link
Member Author

I've added Send and slightly improved docs.

@burrbull
Copy link
Member Author

What you mean there is no information about field variants?

@Disasm
Copy link
Member

Disasm commented Jul 31, 2019

@burrbull It's no longer accessible from the register documentation pages. Only on upper levels.

@burrbull
Copy link
Member Author

@burrbull It's no longer accessible from the register documentation pages. Only on upper levels.

Can you show example?

@Disasm
Copy link
Member

Disasm commented Jul 31, 2019

spi0::RegisterBlock -> CTRLR0 -> R -> WORK_MODER

@burrbull
Copy link
Member Author

Here is one breaking change (#354). Reader now have variant method:
изображение

same as writer:

изображение

And now you can use this enum for both read and write:

let v = spi.ctrl0.read().work_mode().variant();
...
spi.ctrl0.write(|w| w.work_mode().variant(v)); // Before now incompatible types error was here.

@burrbull
Copy link
Member Author

burrbull commented Aug 1, 2019

@therealprof I can't find where is source of this documentation https://docs.rs/svd2rust ?

@therealprof
Copy link
Contributor

@burrbull You mean src/lib.rs?

Disasm
Disasm previously approved these changes Aug 1, 2019
///Register size
type Size;
///Reset value of the register
fn reset_value() -> Self::Size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This associated type name is debatable, but I'm not going to force my point of view here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed Size on Type


let doc = format!("`read()` method returns [{0}::R]({0}::R) reader structure", &name_sc);
if can_read {
out.push(quote! {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not move the let doc = ... inside the if clause? Should be cheaper to compute and avoids the risk of accidentally using it in a wrong context.

});
}
let doc = format!("`write(|w| ..)` method takes [{0}::W]({0}::W) writer structure", &name_sc);
if can_write {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@therealprof
Copy link
Contributor

Also please rebase and make sure the commits have a meaningful commit message.

@burrbull
Copy link
Member Author

burrbull commented Aug 1, 2019

Rebased.

@therealprof
Copy link
Contributor

bors try

bors bot added a commit that referenced this pull request Aug 1, 2019
@bors
Copy link
Contributor

bors bot commented Aug 1, 2019

try

Build succeeded

@therealprof
Copy link
Contributor

@Disasm Still happy?

@Disasm
Copy link
Member

Disasm commented Aug 2, 2019

@therealprof yes, looks good.

@Disasm
Copy link
Member

Disasm commented Aug 2, 2019

In general, I'd improve documentation for generic methods (read/write/...), replacing references to the book with short examples.

@Disasm
Copy link
Member

Disasm commented Aug 2, 2019

bors r+

bors bot added a commit that referenced this pull request Aug 2, 2019
347: Generic Part1 r=Disasm a=burrbull

Rebased and reopened.

Co-authored-by: Andrey Zgarbul <[email protected]>
@bors
Copy link
Contributor

bors bot commented Aug 2, 2019

Build succeeded

@bors bors bot merged commit e7b3539 into rust-embedded:master Aug 2, 2019
@burrbull burrbull deleted the generics-p1 branch August 3, 2019 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants