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

Add stacks-common to clippy CI and fix errors #5598

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

jferrant
Copy link
Collaborator

There were actually a bunch of compile errors (not just clippy errors) for this library if all-features flag was set. Tried my best to fix them. I verified that all the unit tests for stacks-common still pass.

@jferrant jferrant requested review from a team as code owners December 19, 2024 20:58
Copy link
Contributor

@hstove hstove left a comment

Choose a reason for hiding this comment

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

Small nits but LGTM!

stacks-common/src/types/mod.rs Show resolved Hide resolved
stacks-common/src/util/vrf.rs Outdated Show resolved Hide resolved
@jferrant jferrant changed the base branch from feat/clippy-ci to develop December 20, 2024 00:25
@jferrant jferrant requested a review from a team as a code owner December 20, 2024 00:25
Signed-off-by: Jacinta Ferrant <[email protected]>
Signed-off-by: Jacinta Ferrant <[email protected]>
@jferrant jferrant requested a review from hstove December 20, 2024 00:51
@jferrant jferrant changed the base branch from develop to feat/clippy-ci December 20, 2024 00:53
@jferrant jferrant changed the base branch from feat/clippy-ci to develop December 20, 2024 00:53
hstove
hstove previously approved these changes Dec 20, 2024
stacks-common/src/types/chainstate.rs Show resolved Hide resolved
stacks-common/src/types/mod.rs Outdated Show resolved Hide resolved
stacks-common/src/util/hash.rs Outdated Show resolved Hide resolved
assert!(CoinbaseInterval::check_order(&emissions_schedule));
emissions_schedule
});
// This static value is lazily initialized using `OnceLock` to avoid unnecessary
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the issue with LazyCell here? Using LazyCell (or LazyLock if you need thread safety) is more concise than OnceLock

Copy link
Collaborator Author

@jferrant jferrant Dec 20, 2024

Choose a reason for hiding this comment

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

Yes. If we used lazycell it caused errors related to mutability. I added the comment to better explain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't mind using lazyLock but once lock is the recommended over lazycell and lazylock. I can be persuaded otherwise but its the recommended standard.

Copy link
Contributor

Choose a reason for hiding this comment

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

You have the same interior mutability issues with OnceLock as LazyCell, as both provide a get_mut() function.

The reason the warning went away is that you changed COINBASE_INTERVALS_MAINNET from const to static, so now it doesn't trigger Clippy's declare_interior_mutable_const because there's no const

I'd stick with the LazyCell, it's cleaner and more efficient (not thread-safe, so no spinlock or mutex required to access it). Just make it static to kill the warning

Copy link
Collaborator Author

@jferrant jferrant Dec 21, 2024

Choose a reason for hiding this comment

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

I cannot make it static.

`UnsafeCell<cell::lazy::State<[CoinbaseInterval; 5], fn() -> [CoinbaseInterval; 5]>>` cannot be shared between threads safely
within `LazyCell<[CoinbaseInterval; 5]>`, the trait `Sync` is not implemented for `UnsafeCell<cell::lazy::State<[CoinbaseInterval; 5], fn() -> [CoinbaseInterval; 5]>>`, which is required by `LazyCell<[CoinbaseInterval; 5]>: Sync`
shared static variables must have a type that implements `Sync

I could just silence the warning if you prefer? But I cannot just declare it static and still use LazyCell

Copy link
Contributor

Choose a reason for hiding this comment

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

That error means it's shared by multiple threads and must use a Sync type, like LazyLock. OnceLock works also, it's just cumbersome and awkward to work with. We use LazyLock elsewhere in the code, it's basically the modern stdlib replacement for lazy_static!. See also PR #5055

Signed-off-by: Jacinta Ferrant <[email protected]>
@jferrant jferrant requested review from jbencin and obycode December 21, 2024 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants