-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Lint: enable empty_loop for no_std crates #6161
Comments
|
Agreed that this doesn't completely fix the issue. That hint currently only does something on:
It would be nice if that hint did fix the issue. I'll see about filing an issue upstream to make it so |
IMO we should just fix the LLVM bugs instead. |
@jonas-schievink I talk a bit in rust-lang/rust#77924 about why we might want |
It does not have side effects on any target. LLVM might treat it as such, but really it doesn't. |
I guess I'm confused, for the current implementation on x86, the hint alls the |
Enable empty_loop for no_std crates. Fixes #6161 This change: - Makes it so the `empty_loop` lint will fire for `no_std` crates, but with a `no_std`-specific message (mentioning [`spin_loop_hint`](https://doc.rust-lang.org/core/sync/atomic/fn..html)). - Updates the `std` message to also mention [`std::thread::yield_now`](https://doc.rust-lang.org/std/thread/fn.yield_now.html). - Updates the docs to also mention the [LLVM infinite loop bug](rust-lang/rust#28728) - Updates the tests/stderr files to test this change. changelog: Update `empty_loop` lint to work with `no_std` crates
Enable empty_loop for no_std crates. Fixes #6161 This change: - Makes it so the `empty_loop` lint will fire for `no_std` crates, but with a `no_std`-specific message (mentioning [`spin_loop_hint`](https://doc.rust-lang.org/core/sync/atomic/fn..html)). - Updates the `std` message to also mention [`std::thread::yield_now`](https://doc.rust-lang.org/std/thread/fn.yield_now.html). - Updates the docs to also mention the [LLVM infinite loop bug](rust-lang/rust#28728) - Updates the tests/stderr files to test this change. changelog: Update `empty_loop` lint to work with `no_std` crates
Enable empty_loop for no_std crates. Fixes #6161 This change: - Makes it so the `empty_loop` lint will fire for `no_std` crates, but with a `no_std`-specific message (mentioning [`spin_loop_hint`](https://doc.rust-lang.org/core/sync/atomic/fn..html)). - Updates the `std` message to also mention [`std::thread::yield_now`](https://doc.rust-lang.org/std/thread/fn.yield_now.html). - Updates the docs to also mention the [LLVM infinite loop bug](rust-lang/rust#28728) - Updates the tests/stderr files to test this change. changelog: Update `empty_loop` lint to work with `no_std` crates
Enable empty_loop for no_std crates. Fixes #6161 This change: - Makes it so the `empty_loop` lint will fire for `no_std` crates, but with a `no_std`-specific message (mentioning [`spin_loop_hint`](https://doc.rust-lang.org/core/sync/atomic/fn..html)). - Updates the `std` message to also mention [`std::thread::yield_now`](https://doc.rust-lang.org/std/thread/fn.yield_now.html). - Updates the docs to also mention the [LLVM infinite loop bug](rust-lang/rust#28728) - Updates the tests/stderr files to test this change. changelog: Update `empty_loop` lint to work with `no_std` crates
I've updated the description for this issue to make it clear this is no longer about undefined behavior. Now, this issue just tracks re-enabling the style lint for I think we should either:
EDIT: Implementation of (2) is up in #6205 |
Update empty_loop documentation/message. Originally part of #6161, but now this PR only deals with `std` crates This change: - Updates the `std` message . - Updates the docs to mention how the busy loops should be fixed - Gives examples of how to do this for `no_std` targets - Updates the tests/stderr files to test this change. changelog: Update `empty_loop` lint documentation
In my view the second is the correct approach as on no_std you can customary use an empty |
|
Is that something specific to Rust code? Or some specific boards/SoCs? Can you provide more details? I am yet to encounter such issues with JTAG debuggers in C code I worked with, and have limited experience with non-play embedded Rust code that would contain the main loop (making power saving instructions needed).
BTW, the issue is closed now, so if you have issues, you might want to follow up, as option 2 was implemented: abfa331#diff-43e58dc26b162ad6f137224e22f25d0a652e9c319ed6a7b7d74061110e5dea77 |
- Clippy warns about empty loops, rust-lang/rust-clippy#6161 - wfi allows to CPU to save some power WFI was avoided in examples for fear of ill interactions with debuggers. However the rp2040 debug port does continue to work, as long as the relevant clocks are not disabled in SLEEP_EN0/SLEEP_EN1. (By default, all clocks stay enabled in sleep mode.) This patch replaces several different workarounds with just calling wfi.
- Clippy warns about empty loops, rust-lang/rust-clippy#6161 - wfi allows to CPU to save some power WFI was avoided in examples for fear of ill interactions with debuggers. However the rp2040 debug port does continue to work, as long as the relevant clocks are not disabled in SLEEP_EN0/SLEEP_EN1. (By default, all clocks stay enabled in sleep mode.) This patch replaces several different workarounds with just calling wfi.
Right now, we have a style lint against the following code:
Note that this is no longer undefined behavior (since rust-lang/rust#77972).
Currently, there is no way to have a
no_std
binary or library use theempty_loop
lint.Even adding
#![deny(clippy::empty_loop)]
to a crate does nothing. This is because #5086 (fixing #3746), made the lint essentially not exist forno_std
crates.Furthermore, even in
no_std
crates, using a "hot" deadloop is almost always not what you want (as it burns a bunch of CPU, and can cause crashes). Even on ano_std
target, a user should either:halt
orpause
intrinsic.Note,
core::sync::atomic::spin_loop_hint
is not a good recommendation here, aspause
isn't meant for dead-loops (it's designed for spin-locks). See rust-lang/rust#77924In my opinion, we should:
empty_loop
lint forno_std
crates.no_std
specific help message.#[panic_handler]
sno_std
binaries (while keeping it on forno_std
libraries).#[panic_handler]
.Our documentation for fixing this (on
std
andno_std
) is part of #6162CC (people involved with this change last time): @therealprof, @oli-obk, @eddyp, @Areredify, @phansch
The text was updated successfully, but these errors were encountered: