Skip to content

feat: use clarity-serialization in clarity #6310

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 34 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
83ae404
use clarity-serializaton in clarity
Jiloc Jul 21, 2025
96dddb8
use CodecError instead of SerializationError
Jiloc Jul 21, 2025
59d9bf2
add From<ClarityCodecError> for ClientError
Jiloc Jul 21, 2025
cfa3cf6
add CodecError conversions for stackslib
Jiloc Jul 21, 2025
04a9323
cargo fmt
Jiloc Jul 21, 2025
3eabeb4
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc Jul 21, 2025
1f1c190
update Cargo.lock
Jiloc Jul 21, 2025
7848406
fix cli tests
Jiloc Jul 21, 2025
738bea8
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc Jul 21, 2025
526cec1
remove hashbrown
Jiloc Jul 21, 2025
1944b20
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc Jul 21, 2025
47cfbfe
remove hashbrown from stackslib
Jiloc Jul 21, 2025
9475370
cargo format
Jiloc Jul 21, 2025
dd8ad84
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc Jul 21, 2025
228bdee
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc Jul 22, 2025
05931c8
Merge branch 'feat/move-clarity-serialization-to-root' into feat/clar…
Jiloc Jul 23, 2025
5462de1
add testing utils for conversion
Jiloc Jul 23, 2025
28036bc
cargo fmt
Jiloc Jul 23, 2025
9660ae2
Merge branch 'feat/move-clarity-serialization-to-root' into feat/clar…
Jiloc Jul 23, 2025
1c05004
Merge branch 'develop' into feat/clarity-depend-on-clarity-serialization
Jiloc Aug 1, 2025
4ba0a36
Merge branch 'develop' into feat/clarity-depend-on-clarity-serialization
Jiloc Aug 1, 2025
355d0ef
add wasm-web forwarding to clarity-serialization
Jiloc Aug 1, 2025
40a95ee
drop CodecError in favor of original clarity errors
Jiloc Aug 6, 2025
b0957e3
clippy
Jiloc Aug 6, 2025
fa6d7d7
remove old file
Jiloc Aug 6, 2025
aef2fe9
remove unnecessary map_err
Jiloc Aug 6, 2025
a1090c4
add comment for parsing traits
Jiloc Aug 6, 2025
454d7e0
revert to original implementation of parse_*_type_repr
Jiloc Aug 6, 2025
15ae223
remove redundant clarity-serialization dependency with testing flag
Jiloc Aug 6, 2025
7b42ca5
fix blockstack_cli tests
Jiloc Aug 6, 2025
9eabf67
add missing copyrights
Jiloc Aug 6, 2025
69a1941
Merge branch 'develop' into feat/clarity-depend-on-clarity-serialization
Jiloc Aug 7, 2025
abccbe9
add clarity to cargo check for wasm32
Jiloc Aug 7, 2025
4a35628
re-add rustqlite in testing
Jiloc Aug 7, 2025
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
3 changes: 2 additions & 1 deletion .github/workflows/cargo-hack-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ jobs:
- name: "Clarity & Stacks-Common WASM Web"
command: |
cargo hack check \
-p clarity \
-p clarity-serialization \
-p stacks-common \
--each-feature \
--no-dev-deps \
--exclude-features=default,rusqlite,ctrlc-handler,wasm-deterministic \
--exclude-features=default,rusqlite,ctrlc-handler,wasm-deterministic,testing \
--features=wasm-web

- name: "Clarity & Stacks-Common WASM Deterministic"
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion clarity-serialization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ readme = "README.md"
[dependencies]
lazy_static = { workspace = true }
regex = { version = "1", default-features = false }
rusqlite = { workspace = true, optional = true }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

needed for implementing ToSql and FromSql for ExecutionCost, and defining InterpreterError::SqliteError(IncomparableError<SqliteError>)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this might need some thought. I thought clarity-serialization was supposed to be able to run in WASM? If so, then rusqlite can't be a required dependency IIRC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't be a problem in this case, rustqlite will only be included if built with the rusqlite feature. If building this with

cargo build -p clarity-serialization --features "wasm-web" (for js support)
cargo build -p clarity-serialization --features "wasm-deterministic" (for deterministic environment like CosmWasm)

it will still work!

serde = { workspace = true }
serde_json = { version = "1.0", default-features = false }
serde_derive = { workspace = true }
slog = { workspace = true }
stacks_common = { package = "stacks-common", path = "../stacks-common", default-features = false }
thiserror = { workspace = true }

[dev-dependencies]
mutants = "0.0.3"
Expand All @@ -25,7 +26,9 @@ rstest = "0.17.0"
[features]
default = []
testing = []
developer-mode = ["stacks_common/developer-mode"]
slog_json = ["stacks_common/slog_json"]
rusqlite = ["stacks_common/rusqlite", "dep:rusqlite"]

# Wasm-specific features for easier configuration
wasm-web = ["stacks_common/wasm-web"]
Expand Down
90 changes: 90 additions & 0 deletions clarity-serialization/src/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (C) 2025 Stacks Open Internet Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use std::fmt;

use crate::representations::Span;

/// In a near future, we can go further in our static analysis and provide different levels
/// of diagnostics, such as warnings, hints, best practices, etc.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub enum Level {
Note,
Warning,
Error,
}

pub trait DiagnosableError {
fn message(&self) -> String;
fn suggestion(&self) -> Option<String>;
fn level(&self) -> Level {
Level::Error
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Diagnostic {
pub level: Level,
pub message: String,
pub spans: Vec<Span>,
pub suggestion: Option<String>,
}

impl Diagnostic {
pub fn err(error: &dyn DiagnosableError) -> Diagnostic {
Diagnostic {
spans: vec![],
level: Level::Error,
message: error.message(),
suggestion: error.suggestion(),
}
}

pub fn add_span(&mut self, start_line: u32, start_column: u32, end_line: u32, end_column: u32) {
self.spans.push(Span {
start_line,
start_column,
end_line,
end_column,
});
}
}

impl fmt::Display for Diagnostic {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self.level)?;
match self.spans.len().cmp(&1) {
std::cmp::Ordering::Equal => write!(
f,
" (line {}, column {})",
self.spans[0].start_line, self.spans[0].start_column
)?,
std::cmp::Ordering::Greater => {
let lines: Vec<String> = self
.spans
.iter()
.map(|s| format!("line: {}", s.start_line))
.collect();
write!(f, " ({})", lines.join(", "))?;
}
_ => {}
}
write!(f, ": {}.", &self.message)?;
if let Some(suggestion) = &self.suggestion {
write!(f, "\n{suggestion}")?;
}
writeln!(f)
}
}
129 changes: 0 additions & 129 deletions clarity-serialization/src/errors.rs

This file was deleted.

Loading
Loading