stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3.01k stars 667 forks source link

[refactor] replace lazy_static with LazyLock #5055

Open cylewitruk opened 1 month ago

cylewitruk commented 1 month ago

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!.

jbencin commented 1 month ago

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

cylewitruk commented 1 month ago

@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.