-
Notifications
You must be signed in to change notification settings - Fork 698
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
Jiloc
wants to merge
34
commits into
stacks-network:develop
Choose a base branch
from
Jiloc:feat/clarity-depend-on-clarity-serialization
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,187
−8,390
Open
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 96dddb8
use CodecError instead of SerializationError
Jiloc 59d9bf2
add From<ClarityCodecError> for ClientError
Jiloc cfa3cf6
add CodecError conversions for stackslib
Jiloc 04a9323
cargo fmt
Jiloc 3eabeb4
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc 1f1c190
update Cargo.lock
Jiloc 7848406
fix cli tests
Jiloc 738bea8
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc 526cec1
remove hashbrown
Jiloc 1944b20
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc 47cfbfe
remove hashbrown from stackslib
Jiloc 9475370
cargo format
Jiloc dd8ad84
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc 228bdee
Merge branch 'feat/clarity-serialization-crate' into feat/clarity-dep…
Jiloc 05931c8
Merge branch 'feat/move-clarity-serialization-to-root' into feat/clar…
Jiloc 5462de1
add testing utils for conversion
Jiloc 28036bc
cargo fmt
Jiloc 9660ae2
Merge branch 'feat/move-clarity-serialization-to-root' into feat/clar…
Jiloc 1c05004
Merge branch 'develop' into feat/clarity-depend-on-clarity-serialization
Jiloc 4ba0a36
Merge branch 'develop' into feat/clarity-depend-on-clarity-serialization
Jiloc 355d0ef
add wasm-web forwarding to clarity-serialization
Jiloc 40a95ee
drop CodecError in favor of original clarity errors
Jiloc b0957e3
clippy
Jiloc fa6d7d7
remove old file
Jiloc aef2fe9
remove unnecessary map_err
Jiloc a1090c4
add comment for parsing traits
Jiloc 454d7e0
revert to original implementation of parse_*_type_repr
Jiloc 15ae223
remove redundant clarity-serialization dependency with testing flag
Jiloc 7b42ca5
fix blockstack_cli tests
Jiloc 9eabf67
add missing copyrights
Jiloc 69a1941
Merge branch 'develop' into feat/clarity-depend-on-clarity-serialization
Jiloc abccbe9
add clarity to cargo check for wasm32
Jiloc 4a35628
re-add rustqlite in testing
Jiloc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed for implementing
ToSql
andFromSql
forExecutionCost
, and definingInterpreterError::SqliteError(IncomparableError<SqliteError>)
There was a problem hiding this comment.
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, thenrusqlite
can't be a required dependency IIRC.There was a problem hiding this comment.
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 withcargo 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!