-
Notifications
You must be signed in to change notification settings - Fork 168
make 'fn ptr()' APIs to be 'const fn ptr()' #235
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
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @therealprof (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
What's the use case for something like this? If we do this, we probably also want to change svd2rust accordingly, since it generates similar APIs. (aside: is there any reason why |
To be honest, I don't have a solid use case for this. My idea was just "Why not make these
Making This PR is rather a minor refactoring attempt that doesn't solve practical issues. |
I think we should generally try to be more idiomatic and expressive even without particular usecase or problem to address. Declaring constant functions as const makes a lot of sense from an expressive point of view, enables new uses and could even today lead to potentially better code generation in dev mode. So I'm all for such changes, especially if they don't require a MSRV bump. |
Not sure why that would be the case here, unless we fully move to an associated constant. |
There're plenty of cases where rustc decides to use a function call instead of simply inlining the code. My understanding is that |
Yet another use case (for svd2rust generated code, though): |
No, not at the moment. They're only evaluated at compile time if you initialize a @Disasm's use case looks interesting. I think it makes sense to move svd2rust over to associated constants as well as this crate (perhaps with a migration period in which we provide both). |
As discussed in the meeting having |
I think the idea was to add the associated constants now too, since they can be a non-breaking addition and are more generally useful, but then move to deprecating the |
@adamgreig I shouldn't have edited the second sentence in so sloppily. 😅 Of course I meant to say we're adding in the associated const right away. |
Should I add another commit to add in associated constants also?? |
@JOE1994 Yes, please. |
I think this PR is ready to be reviewed 😺 |
I'd instead call these constants with the same name for consistency ( |
Yes, those should all be called |
Now couldn't the |
One tiny little ask and then I'm happy: Would you please add an entry to the CHANGELOG? |
This commit introduces new associated constants to Core Peripherals. (pointers to the register block) This commit also adds a notice that 'ptr()' APIs will be deprecated in v0.7.
I did a rebase to update the CHANGELOG. |
CHANGELOG.md
Outdated
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). | |||
|
|||
- New `InterruptNumber` trait is now required on interrupt arguments to the | |||
various NVIC functions, replacing the previous use of `Nr` from bare-metal. | |||
- Associated const `PTR` is introduced to Core Peripherals to | |||
replace the existing `ptr()` API. `ptr()` API is to be removed in the |
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 the plan was to mark as deprecated in 0.7 and remove it for good in 1.0? Anyway I'd just leave it out for now, we can always tweak the deprecation/removal plan in a separate PR.
Co-authored-by: Daniel Egger <[email protected]>
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.
Excellent, thanks a lot!
bors r+
Build succeeded: |
cc rust-embedded/cortex-m#235 Signed-off-by: Daniel Egger <[email protected]>
457: Add associated const ptr `PTR` to each peripheral RegisterBlock r=adamgreig a=therealprof cc rust-embedded/cortex-m#235 Signed-off-by: Daniel Egger <[email protected]> Co-authored-by: Daniel Egger <[email protected]>
Per rust-embedded#370/rust-embedded#235, the const fn ptr() was supposed to be deprecated and subsequently removed. This PR removes it for the master branch tracking the 0.8 release
Per rust-embedded#370/rust-embedded#235, the const fn ptr() was supposed to be deprecated and subsequently removed. This PR removes it for the master branch tracking the 0.8 release
385: remove the ptr() function in favor of the PTR constant r=adamgreig a=TDHolmes Per #370/#235, the const fn ptr() was supposed to be deprecated and subsequently removed. This PR removes it for the master branch tracking the 0.8 release Co-authored-by: Tyler Holmes <[email protected]>
235: Document a possible reason for the 'interrupt vectors are missing' error r=korken89 a=Disasm This error happens when you have all the needed dependencies in Cargo.toml but do not use them yet in main.rs. Due to the fact that you already "have" a "svd2rust generated device crate", this error is quite confusing. Co-authored-by: Vadim Kaushan <[email protected]>
This PR changes functions like
ITM::ptr()
,DWT::ptr()
to becomeconst fn
s.ITM::ptr()
,DWT::ptr()
return pointers that are cast from constants,but currently these functions can't be used to define a constant. This PR will allow below code to compile.
I couldn't think of disadvantages that might accompany this change, but please correct me if I'm wrong.
Thank you for reviewing this PR 👍