Skip to content

chore: build clarity for wasm32-unknown-unknown #6268

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
29 changes: 14 additions & 15 deletions Cargo.lock

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

17 changes: 8 additions & 9 deletions clarity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ name = "clarity"
path = "./src/libclarity.rs"

[dependencies]
rand = { workspace = true }
rand_chacha = { workspace = true }
serde = "1"
serde_derive = "1"
serde_stacker = "0.1"
Expand All @@ -28,22 +26,23 @@ lazy_static = "1.4.0"
integer-sqrt = "0.1.3"
slog = { version = "2.5.2", features = [ "max_level_trace" ] }
stacks_common = { package = "stacks-common", path = "../stacks-common", default-features = false }
rstest = "0.17.0"
rstest_reuse = "0.5.0"
rstest = { version = "0.17.0", optional = true }
rstest_reuse = { version = "0.5.0", optional = true }
hashbrown = { workspace = true }
rusqlite = { workspace = true, optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[dependencies.serde_json]
version = "1.0"
features = ["arbitrary_precision", "unbounded_depth"]

[dependencies.time]
version = "0.2.23"
features = ["std"]

[dev-dependencies]
assert-json-diff = "1.0.0"
mutants = "0.0.3"
rstest = { version = "0.17.0" }
rstest_reuse = { version = "0.5.0" }
# a nightly rustc regression (35dbef235 2021-03-02) prevents criterion from compiling
# but it isn't necessary for tests: only benchmarks. therefore, commenting out for now.
# criterion = "0.3"
Expand All @@ -53,7 +52,7 @@ default = ["rusqlite"]
developer-mode = ["stacks_common/developer-mode"]
slog_json = ["stacks_common/slog_json"]
rusqlite = ["stacks_common/rusqlite", "dep:rusqlite"]
testing = []
testing = ["rstest", "rstest_reuse"]
devtools = []
rollback_value_check = []
disable-costs = []
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/type_checker/v2_05/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub fn no_type() -> TypeSignature {
}

impl<'a, 'b> TypeChecker<'a, 'b> {
fn new(
pub fn new(
db: &'a mut AnalysisDatabase<'b>,
cost_track: LimitedCostTracker,
build_type_map: bool,
Expand Down
19 changes: 19 additions & 0 deletions clarity/src/vm/costs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,25 @@ pub enum CostErrors {
ExecutionTimeExpired,
}

impl fmt::Display for CostErrors {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CostErrors::CostComputationFailed(ref s) => write!(f, "Cost computation failed: {}", s),
CostErrors::CostOverflow => write!(f, "Cost overflow"),
CostErrors::CostBalanceExceeded(ref total, ref limit) => {
write!(f, "Cost balance exceeded: total {}, limit {}", total, limit)
}
CostErrors::MemoryBalanceExceeded(ref used, ref limit) => {
write!(f, "Memory balance exceeded: used {}, limit {}", used, limit)
}
CostErrors::CostContractLoadFailure => write!(f, "Failed to load cost contract"),
CostErrors::InterpreterFailure => write!(f, "Interpreter failure"),
CostErrors::Expect(ref s) => write!(f, "Expectation failed: {}", s),
CostErrors::ExecutionTimeExpired => write!(f, "Execution time expired"),
}
}
}

impl CostErrors {
fn rejectable(&self) -> bool {
matches!(self, CostErrors::InterpreterFailure | CostErrors::Expect(_))
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/docs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2632,7 +2632,7 @@ pub fn make_api_reference(function: &NativeFunctions) -> FunctionAPI {
}
}

fn make_keyword_reference(variable: &NativeVariables) -> Option<KeywordAPI> {
pub fn make_keyword_reference(variable: &NativeVariables) -> Option<KeywordAPI> {
let keyword = match variable {
NativeVariables::TxSender => TX_SENDER_KEYWORD.clone(),
NativeVariables::ContractCaller => CONTRACT_CALLER_KEYWORD.clone(),
Expand Down
6 changes: 3 additions & 3 deletions clarity/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub mod clarity;
use std::collections::BTreeMap;

use costs::CostErrors;
use serde_json;
use stacks_common::types::StacksEpochId;

use self::analysis::ContractAnalysis;
Expand All @@ -77,6 +76,7 @@ pub use crate::vm::database::clarity_db::StacksEpoch;
use crate::vm::errors::{
CheckErrors, Error, InterpreterError, InterpreterResult as Result, RuntimeErrorType,
};
use crate::vm::events::StacksTransactionEvent;
use crate::vm::functions::define::DefineResult;
pub use crate::vm::functions::stx_transfer_consolidated;
pub use crate::vm::representations::{
Expand Down Expand Up @@ -118,12 +118,12 @@ pub enum EvaluationResult {
#[derive(Debug, Clone)]
pub struct ExecutionResult {
pub result: EvaluationResult,
pub events: Vec<serde_json::Value>,
pub events: Vec<StacksTransactionEvent>,
pub cost: Option<CostSynthesis>,
pub diagnostics: Vec<Diagnostic>,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize)]
pub struct CostSynthesis {
pub total: ExecutionCost,
pub limit: ExecutionCost,
Expand Down
15 changes: 7 additions & 8 deletions clarity/src/vm/representations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,17 @@ pub struct SymbolicExpression {
pub id: u64,

#[cfg(feature = "developer-mode")]
#[serde(default)]
pub span: Span,

#[cfg(feature = "developer-mode")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub pre_comments: Vec<(String, Span)>,
#[cfg(feature = "developer-mode")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub end_line_comment: Option<String>,
#[cfg(feature = "developer-mode")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub post_comments: Vec<(String, Span)>,
}

Expand Down Expand Up @@ -650,7 +654,7 @@ impl fmt::Display for SymbolicExpression {
}
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Span {
pub start_line: u32,
pub start_column: u32,
Expand All @@ -666,12 +670,7 @@ impl Span {
end_column: 0,
};

pub fn zero() -> Span {
Span {
start_line: 0,
start_column: 0,
end_line: 0,
end_column: 0,
}
pub fn zero() -> Self {
Self::default()
}
}
4 changes: 2 additions & 2 deletions pox-locking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ name = "pox_locking"
path = "src/lib.rs"

[dependencies]
clarity = { package = "clarity", path = "../clarity" }
stacks_common = { package = "stacks-common", path = "../stacks-common" }
clarity = { package = "clarity", path = "../clarity", default-features = false}
stacks_common = { package = "stacks-common", path = "../stacks-common", default-features = false}
slog = { version = "2.5.2", features = [ "max_level_trace" ] }

[dev-dependencies]
Expand Down
4 changes: 0 additions & 4 deletions stacks-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ workspace = true
version = "4.1.3"
features = ["serde"]

[dependencies.time]
version = "0.2.23"
features = ["std"]

[target.'cfg(not(target_family = "wasm"))'.dependencies]
secp256k1 = { version = "0.24.3", features = ["serde", "recovery"] }

Expand Down
13 changes: 0 additions & 13 deletions stacks-common/src/deps_common/bitcoin/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ pub mod hash;

use std::{error, fmt};

use secp256k1;

use crate::deps_common::bitcoin::network;
use crate::deps_common::bitcoin::network::serialize;

Expand Down Expand Up @@ -50,8 +48,6 @@ pub trait BitArray {
/// if appropriate.
#[derive(Debug)]
pub enum Error {
/// secp-related error
Secp256k1(secp256k1::Error),
/// Serialization error
Serialize(serialize::Error),
/// Network error
Expand All @@ -65,7 +61,6 @@ pub enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Secp256k1(ref e) => fmt::Display::fmt(e, f),
Error::Serialize(ref e) => fmt::Display::fmt(e, f),
Error::Network(ref e) => fmt::Display::fmt(e, f),
Error::SpvBadProofOfWork => f.write_str("target correct but not attained"),
Expand All @@ -77,21 +72,13 @@ impl fmt::Display for Error {
impl error::Error for Error {
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
Error::Secp256k1(ref e) => Some(e),
Error::Serialize(ref e) => Some(e),
Error::Network(ref e) => Some(e),
Error::SpvBadProofOfWork | Error::SpvBadTarget => None,
}
}
}

#[doc(hidden)]
impl From<secp256k1::Error> for Error {
fn from(e: secp256k1::Error) -> Error {
Error::Secp256k1(e)
}
}

#[doc(hidden)]
impl From<serialize::Error> for Error {
fn from(e: serialize::Error) -> Error {
Expand Down
1 change: 1 addition & 0 deletions stacks-common/src/deps_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

pub mod bech32;
pub mod bitcoin;
#[cfg(not(target_arch = "wasm32"))]
pub mod ctrlc;
pub mod httparse;

Expand Down
Loading