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: remove lazy-static #1679

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ version = "2.13.0"

[workspace.dependencies]
clarity = { git = "https://github.com/stacks-network/stacks-core.git", branch="feat/clarity-wasm-develop", package = "clarity", default-features = false }
lazy_static = { version = "1.5.0" }
reqwest = { version = "0.12", default-features = false, features = [
"json",
"rustls-tls",
Expand Down
1 change: 0 additions & 1 deletion components/clarinet-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ serde = { version = "1", features = ["derive"] }
serde_json = { version = "1.0.79", features = ["preserve_order"] }
serde_derive = "1"
tokio = { version = "1.35.1", features = ["full"] }
lazy_static = { workspace = true }
atty = "0.2.14"
crossterm = "0.27.0"
ratatui = { version = "0.27.0", default-features = false, features = ["crossterm"] }
Expand Down
2 changes: 0 additions & 2 deletions components/clarinet-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ extern crate serde_json;
#[macro_use]
extern crate hiro_system_kit;

extern crate lazy_static;

pub extern crate clarity_repl;

pub mod deployments;
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-deployments/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clarity_repl::clarity::vm::SymbolicExpression;
use clarity_repl::clarity::StacksEpochId;
use clarity_repl::repl::boot::BOOT_CONTRACTS_DATA;
use clarity_repl::repl::{ClarityCodeSource, ClarityContract, ContractDeployer};
use clarity_repl::repl::{DEFAULT_CLARITY_VERSION, DEFAULT_EPOCH};

Expand Down Expand Up @@ -32,7 +33,6 @@ use clarity_repl::clarity::vm::types::QualifiedContractIdentifier;
use clarity_repl::clarity::vm::ContractName;
use clarity_repl::clarity::vm::EvaluationResult;
use clarity_repl::clarity::vm::ExecutionResult;
use clarity_repl::repl::session::BOOT_CONTRACTS_DATA;
use clarity_repl::repl::Session;
use clarity_repl::repl::SessionSettings;
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-deployments/src/onchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use clarity_repl::clarity::vm::types::{
};
use clarity_repl::clarity::vm::{ClarityName, Value};
use clarity_repl::clarity::{ClarityVersion, ContractName, EvaluationResult};
use clarity_repl::repl::session::{
use clarity_repl::repl::boot::{
BOOT_MAINNET_ADDRESS, BOOT_TESTNET_ADDRESS, V1_BOOT_CONTRACTS, V2_BOOT_CONTRACTS,
V3_BOOT_CONTRACTS,
};
Expand Down
1 change: 0 additions & 1 deletion components/clarinet-files/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ toml = { version = "0.5.6", features = ["preserve_order"] }
url = { version = "2.2.2", features = ["serde"] }
bitcoin = { version = "0.31.2", optional = true }
libsecp256k1 = "0.7.0"
lazy_static = { workspace = true}
dirs = "6.0"

clarity = { workspace = true }
Expand Down
10 changes: 5 additions & 5 deletions components/clarinet-files/src/network_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::collections::BTreeMap;
use std::sync::LazyLock;

use clarinet_utils::{get_bip32_keys_from_mnemonic, mnemonic_from_phrase, random_mnemonic};
use clarity::address::AddressHashMode;
use clarity::types::chainstate::{StacksAddress, StacksPrivateKey};
use clarity::util::{hash::bytes_to_hex, secp256k1::Secp256k1PublicKey};
use clarity::vm::types::QualifiedContractIdentifier;
use lazy_static::lazy_static;
use libsecp256k1::PublicKey;
use serde::Serialize;
use toml::value::Value;
Expand Down Expand Up @@ -55,12 +55,12 @@ pub const DEFAULT_POX_PREPARE_LENGTH: u64 = 4;
pub const DEFAULT_POX_REWARD_LENGTH: u64 = 10;
pub const DEFAULT_FIRST_BURN_HEADER_HEIGHT: u64 = 100;

lazy_static! {
pub static ref DEFAULT_PRIVATE_KEYS: [StacksPrivateKey; 1] = [StacksPrivateKey::from_hex(
pub static DEFAULT_PRIVATE_KEYS: LazyLock<[StacksPrivateKey; 1]> = LazyLock::new(|| {
[StacksPrivateKey::from_hex(
"7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801",
)
.unwrap()];
}
.unwrap()]
});

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
Expand Down
4 changes: 3 additions & 1 deletion components/clarinet-sdk-wasm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use clarity_repl::clarity::{
Address, ClarityVersion, EvaluationResult, ExecutionResult, StacksEpochId, SymbolicExpression,
};
use clarity_repl::repl::clarity_values::{uint8_to_string, uint8_to_value};
use clarity_repl::repl::session::{CostsReport, BOOT_CONTRACTS_DATA};
use clarity_repl::repl::session::CostsReport;
use clarity_repl::repl::settings::RemoteDataSettings;
use clarity_repl::repl::{
clarity_values, ClarityCodeSource, ClarityContract, ContractDeployer, Session, SessionSettings,
Expand Down Expand Up @@ -1084,6 +1084,8 @@ impl SDK {
include_boot_contracts: bool,
boot_contracts_path: String,
) -> Result<SessionReport, String> {
use clarity_repl::repl::boot::BOOT_CONTRACTS_DATA;

let contracts_locations = self.contracts_locations.clone();
let session = self.get_session_mut();

Expand Down
1 change: 0 additions & 1 deletion components/clarity-jupyter-kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ categories = [

[dependencies]
clarity-repl = { path = "../clarity-repl" }
lazy_static = { workspace = true }
regex = "1.7"
sha2 = "0.8.1"
sha3 = "0.8.2"
Expand Down
2 changes: 0 additions & 2 deletions components/clarity-jupyter-kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#![allow(unused_mut)]
// todo(ludo): would love to eliminate these directives at some point.

#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate json;
#[macro_use]
Expand Down
1 change: 0 additions & 1 deletion components/clarity-lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version.workspace = true
edition = "2021"

[dependencies]
lazy_static = { workspace = true }
lsp-types = "0.94.0"
regex = "1.7"
serde = { version = "1", features = ["derive"] }
Expand Down
9 changes: 4 additions & 5 deletions components/clarity-lsp/src/common/requests/api_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use clarity_repl::clarity::{
variables::NativeVariables,
ClarityVersion,
};
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::sync::LazyLock;

fn code(code: &str) -> String {
["```clarity", code.trim(), "```"].join("\n")
Expand All @@ -26,8 +26,8 @@ fn format_removed_in(max_version: Option<ClarityVersion>) -> String {
.unwrap_or_default()
}

lazy_static! {
pub static ref API_REF: HashMap<String, (String, Option<FunctionAPI>)> = {
pub static API_REF: LazyLock<HashMap<String, (String, Option<FunctionAPI>)>> =
LazyLock::new(|| {
let mut api_references: HashMap<String, (String, Option<FunctionAPI>)> = HashMap::new();
let separator = "- - -";

Expand Down Expand Up @@ -96,5 +96,4 @@ lazy_static! {
}

api_references
};
}
});
83 changes: 45 additions & 38 deletions components/clarity-lsp/src/common/requests/completion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, vec};
use std::{collections::HashMap, sync::LazyLock, vec};

use clarity_repl::{
analysis::ast_visitor::{traverse, ASTVisitor, TypedVar},
Expand All @@ -12,7 +12,6 @@ use clarity_repl::{
},
repl::DEFAULT_EPOCH,
};
use lazy_static::lazy_static;
use lsp_types::{
CompletionItem, CompletionItemKind, Documentation, InsertTextFormat, MarkupContent, MarkupKind,
Position,
Expand All @@ -21,60 +20,68 @@ use regex::Regex;

use super::helpers::{get_function_at_position, is_position_within_span};

lazy_static! {
static ref COMPLETION_ITEMS_CLARITY_1: Vec<CompletionItem> =
build_default_native_keywords_list(ClarityVersion::Clarity1);
static ref COMPLETION_ITEMS_CLARITY_2: Vec<CompletionItem> =
build_default_native_keywords_list(ClarityVersion::Clarity2);
static ref COMPLETION_ITEMS_CLARITY_3: Vec<CompletionItem> =
build_default_native_keywords_list(ClarityVersion::Clarity3);
static ref VAR_FUNCTIONS: Vec<String> = vec![
static COMPLETION_ITEMS_CLARITY_1: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_default_native_keywords_list(ClarityVersion::Clarity1));
static COMPLETION_ITEMS_CLARITY_2: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_default_native_keywords_list(ClarityVersion::Clarity2));
static COMPLETION_ITEMS_CLARITY_3: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_default_native_keywords_list(ClarityVersion::Clarity3));
static VAR_FUNCTIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
vec![
NativeFunctions::SetVar.to_string(),
NativeFunctions::FetchVar.to_string(),
];
static ref MAP_FUNCTIONS: Vec<String> = vec![
]
});
static MAP_FUNCTIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
vec![
NativeFunctions::InsertEntry.to_string(),
NativeFunctions::FetchEntry.to_string(),
NativeFunctions::SetEntry.to_string(),
NativeFunctions::DeleteEntry.to_string(),
];
static ref FT_FUNCTIONS: Vec<String> = vec![
]
});
static FT_FUNCTIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
vec![
NativeFunctions::GetTokenBalance.to_string(),
NativeFunctions::GetTokenSupply.to_string(),
NativeFunctions::BurnToken.to_string(),
NativeFunctions::MintToken.to_string(),
NativeFunctions::TransferToken.to_string(),
];
static ref NFT_FUNCTIONS: Vec<String> = vec![
]
});
static NFT_FUNCTIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
vec![
NativeFunctions::GetAssetOwner.to_string(),
NativeFunctions::BurnAsset.to_string(),
NativeFunctions::MintAsset.to_string(),
NativeFunctions::TransferAsset.to_string(),
];
static ref ITERATOR_FUNCTIONS: Vec<String> = vec![
]
});
static ITERATOR_FUNCTIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
vec![
NativeFunctions::Map.to_string(),
NativeFunctions::Filter.to_string(),
NativeFunctions::Fold.to_string(),
];
static ref VALID_MAP_FUNCTIONS_CLARITY_1: Vec<CompletionItem> =
build_map_valid_cb_completion_items(ClarityVersion::Clarity1);
static ref VALID_MAP_FUNCTIONS_CLARITY_2: Vec<CompletionItem> =
build_map_valid_cb_completion_items(ClarityVersion::Clarity2);
static ref VALID_MAP_FUNCTIONS_CLARITY_3: Vec<CompletionItem> =
build_map_valid_cb_completion_items(ClarityVersion::Clarity3);
static ref VALID_FILTER_FUNCTIONS_CLARITY_1: Vec<CompletionItem> =
build_filter_valid_cb_completion_items(ClarityVersion::Clarity1);
static ref VALID_FILTER_FUNCTIONS_CLARITY_2: Vec<CompletionItem> =
build_filter_valid_cb_completion_items(ClarityVersion::Clarity2);
static ref VALID_FILTER_FUNCTIONS_CLARITY_3: Vec<CompletionItem> =
build_filter_valid_cb_completion_items(ClarityVersion::Clarity3);
static ref VALID_FOLD_FUNCTIONS_CLARITY_1: Vec<CompletionItem> =
build_fold_valid_cb_completion_items(ClarityVersion::Clarity1);
static ref VALID_FOLD_FUNCTIONS_CLARITY_2: Vec<CompletionItem> =
build_fold_valid_cb_completion_items(ClarityVersion::Clarity2);
static ref VALID_FOLD_FUNCTIONS_CLARITY_3: Vec<CompletionItem> =
build_fold_valid_cb_completion_items(ClarityVersion::Clarity3);
}
]
});
static VALID_MAP_FUNCTIONS_CLARITY_1: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_map_valid_cb_completion_items(ClarityVersion::Clarity1));
static VALID_MAP_FUNCTIONS_CLARITY_2: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_map_valid_cb_completion_items(ClarityVersion::Clarity2));
static VALID_MAP_FUNCTIONS_CLARITY_3: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_map_valid_cb_completion_items(ClarityVersion::Clarity3));
static VALID_FILTER_FUNCTIONS_CLARITY_1: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_filter_valid_cb_completion_items(ClarityVersion::Clarity1));
static VALID_FILTER_FUNCTIONS_CLARITY_2: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_filter_valid_cb_completion_items(ClarityVersion::Clarity2));
static VALID_FILTER_FUNCTIONS_CLARITY_3: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_filter_valid_cb_completion_items(ClarityVersion::Clarity3));
static VALID_FOLD_FUNCTIONS_CLARITY_1: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_fold_valid_cb_completion_items(ClarityVersion::Clarity1));
static VALID_FOLD_FUNCTIONS_CLARITY_2: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_fold_valid_cb_completion_items(ClarityVersion::Clarity2));
static VALID_FOLD_FUNCTIONS_CLARITY_3: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| build_fold_valid_cb_completion_items(ClarityVersion::Clarity3));

#[derive(Clone, Debug, Default)]
pub struct ContractDefinedData {
Expand Down
1 change: 0 additions & 1 deletion components/clarity-repl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ categories = [
ansi_term = "0.12.1" # to be replaced with colored in the future
chrono = "0.4.31"
colored = { workspace = true }
lazy_static = { workspace = true }
regex = "1.7"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1.0.47", features = ["unbounded_depth"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ use clarity::vm::{ClarityName, ClarityVersion, SymbolicExpressionType};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::iter::FromIterator;
use std::ops::{Deref, DerefMut};
use std::sync::LazyLock;

use super::ast_visitor::TypedVar;

lazy_static! {
pub static ref DEFAULT_NAME: ClarityName = ClarityName::from("placeholder");
}
pub static DEFAULT_NAME: LazyLock<ClarityName> = LazyLock::new(|| ClarityName::from("placeholder"));

pub struct ASTDependencyDetector<'a> {
dependencies: BTreeMap<QualifiedContractIdentifier, DependencySet>,
Expand Down
15 changes: 8 additions & 7 deletions components/clarity-repl/src/analysis/ast_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use clarity::vm::representations::{Span, TraitDefinition};
use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, TraitIdentifier, Value};
use clarity::vm::{ClarityName, ClarityVersion, SymbolicExpression, SymbolicExpressionType};
use std::collections::HashMap;
use std::sync::LazyLock;

#[derive(Clone)]
pub struct TypedVar<'a> {
Expand All @@ -16,13 +17,13 @@ pub struct TypedVar<'a> {
pub decl_span: Span,
}

lazy_static! {
// Since the AST Visitor may be used before other checks have been performed,
// we may need a default value for some expressions. This can be used for a
// missing `ClarityName`.
static ref DEFAULT_NAME: ClarityName = ClarityName::from("placeholder__");
static ref DEFAULT_EXPR: SymbolicExpression = SymbolicExpression::atom(DEFAULT_NAME.clone());
}
// Since the AST Visitor may be used before other checks have been performed,
// we may need a default value for some expressions. This can be used for a
// missing `ClarityName`.
pub static DEFAULT_NAME: LazyLock<ClarityName> =
LazyLock::new(|| ClarityName::from("placeholder__"));
pub static DEFAULT_EXPR: LazyLock<SymbolicExpression> =
LazyLock::new(|| SymbolicExpression::atom(DEFAULT_NAME.clone()));

pub trait ASTVisitor<'a> {
fn traverse_expr(&mut self, expr: &'a SymbolicExpression) -> bool {
Expand Down
2 changes: 0 additions & 2 deletions components/clarity-repl/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub mod test_fixtures;
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate prettytable;
Expand Down
2 changes: 0 additions & 2 deletions components/clarity-repl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pub extern crate prettytable;
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate hiro_system_kit;
Expand Down
Loading
Loading