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

[refactor] replace lazy_static with LazyLock #5055

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

Conversation

cylewitruk
Copy link
Member

@cylewitruk cylewitruk commented Aug 7, 2024

Resolves #5035 however using std::sync::LazyLock instead of std::cell::LazyCell because most of the values are used as statics (LazyCell is for const-like behavior). Also changed a bunch of .unwrap()s to .expect()s to improve eventual error interpretation.

const + LazyCell could likely be used for a handful of the values, but to determine those the usage of each needs to be evaluated, so I opted for LazyLock for all of them as it most closely mimics static_lazy!.

@cylewitruk cylewitruk requested review from a team as code owners August 7, 2024 17:13
@cylewitruk cylewitruk requested a review from kantai August 7, 2024 17:13
@@ -39,7 +38,7 @@ tikv-jemallocator = {workspace = true}
[dev-dependencies]
ring = "0.16.19"
warp = "0.3.5"
tokio = "1.15"
tokio = { version = "1.15", features = ["rt-multi-thread"] }
Copy link
Member Author

Choose a reason for hiding this comment

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

Runtime::new() only exists when this feature is enabled, the tests wouldn't compile for me otherwise, hence why I added the rt-multi-thread feature.

.expect("Failed to create COMMANDS_PROCESSED")
});

pub static DGK_VOTES_SUBMITTED: LazyLock<IntCounter> = LazyLock::new(|| {
Copy link
Member Author

@cylewitruk cylewitruk Aug 7, 2024

Choose a reason for hiding this comment

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

I assume this is supposed to be DKG and not DGK? If so, it's also incorrect in the metric name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, definitely. I think it's fine to go ahead and fix that in this PR if you want.

@cylewitruk cylewitruk changed the title replace lazy_static with LazyLock [refactor] replace lazy_static with LazyLock Aug 7, 2024
@jbencin
Copy link
Contributor

jbencin commented Aug 9, 2024

Don't forget to update package.rust-version to 1.80 in Cargo.toml files where LazyLock is used

@cylewitruk
Copy link
Member Author

cylewitruk commented Aug 11, 2024

@jbencin I think all of your comments are resolved now. Really like const_format, good tip!

I went a step further and reverted to const LazyCell where appropriate, changed a bunch of statics to consts which didn't need to be static and did some other general cleanup.

I added rust-version to the workspace config and added rust-version.workspace = true to all of the package Cargo.toml files -- doesn't really make sense for this project for them to deviate from eachother imo.

@@ -1,5 +1,6 @@
[workspace]
resolver = "2"
package.rust-version = "1.80"
Copy link
Contributor

@jbencin jbencin Aug 12, 2024

Choose a reason for hiding this comment

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

I don't know about using a workspace-level MSRV... it's fine to require latest version for stacks-node, but we might want to be more conservative with Clarity, stacks-common and stackslib, as those are used by other projects

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 thought about that too, but now when clarity, stacks-common and stackslib all use LazyCell and/or LazyLock, they need to be at 1.80 in any case. We can keep the rust-version flag local to the packages if that's preferred, I just figured it's easier to keep the whole project at an announced MSRV 🤷 No strong opinions here.

Copy link
Contributor

Choose a reason for hiding this comment

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

While it's technically correct because the MSRV is 1.80 for all packages right now, and even though it can be overriden in package-level Cargo.toml files, this implies that we have some global MSRV policy which applies to all packages, which I don't think we want. So IMO it's better not to do this, but I don't really have strong feelings on it, and I'd approve either way

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's see if anyone else has any opinions on the matter -- otherwise it's just a couple of minutes to revert

Copy link
Member

Choose a reason for hiding this comment

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

@jbencin @obycode who need to weigh in here? Should the ClarityWASM folks and Clarinet folks weigh in? cc @hugocaillard

Copy link
Contributor

Choose a reason for hiding this comment

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

@jcnelson Hugo's on vacation right now, but I checked and Clarinet builds on Rust 1.80 without warnings. There are commit messages like this in the history:

445ea332 (4 weeks ago) Hugo C: fix: clippy warning v1.80 (#1518)

So this PR shouldn't be a problem for them

Copy link
Member

Choose a reason for hiding this comment

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

Alright, it's fine by me as long as its easy to change back if someone complains.

Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

lgtm!

.expect("Failed to create COMMANDS_PROCESSED")
});

pub static DGK_VOTES_SUBMITTED: LazyLock<IntCounter> = LazyLock::new(|| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, definitely. I think it's fine to go ahead and fix that in this PR if you want.

source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
Copy link
Member

Choose a reason for hiding this comment

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

What's with the bump?

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

Why are there so many bumps in the cargo.lock?

source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
Copy link
Member

Choose a reason for hiding this comment

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

I thought we were dropping this?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's still used by some of our dependencies though, like prometheus

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