Skip to content

Commit fcc51f4

Browse files
authored
update stacks-core/develop (#2207)
1 parent f84e5a5 commit fcc51f4

File tree

8 files changed

+98
-44
lines changed

8 files changed

+98
-44
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ default-members = ["components/clarinet-cli"]
2323
version = "3.14.0"
2424

2525
[workspace.dependencies]
26-
clarity = { git = "https://github.com/stacks-network/stacks-core.git", rev = "68c67034326bfcc4565d74e659c8c6144f5adebf", package = "clarity", default-features = false }
27-
clarity-types = { git = "https://github.com/stacks-network/stacks-core.git", rev = "68c67034326bfcc4565d74e659c8c6144f5adebf", package = "clarity-types" }
28-
stacks-common = { git = "https://github.com/stacks-network/stacks-core.git", rev = "68c67034326bfcc4565d74e659c8c6144f5adebf", package = "stacks-common", default-features = false }
29-
pox-locking = { git = "https://github.com/stacks-network/stacks-core.git", rev = "68c67034326bfcc4565d74e659c8c6144f5adebf", package = "pox-locking", default-features = false }
30-
stackslib = { git = "https://github.com/stacks-network/stacks-core.git", rev = "68c67034326bfcc4565d74e659c8c6144f5adebf", package = "stackslib", default-features = false }
26+
clarity = { git = "https://github.com/stacks-network/stacks-core.git", rev = "41bd9d0a15a08d8ab2603edf11774b0d21a616ec", package = "clarity", default-features = false }
27+
clarity-types = { git = "https://github.com/stacks-network/stacks-core.git", rev = "41bd9d0a15a08d8ab2603edf11774b0d21a616ec", package = "clarity-types" }
28+
stacks-common = { git = "https://github.com/stacks-network/stacks-core.git", rev = "41bd9d0a15a08d8ab2603edf11774b0d21a616ec", package = "stacks-common", default-features = false }
29+
pox-locking = { git = "https://github.com/stacks-network/stacks-core.git", rev = "41bd9d0a15a08d8ab2603edf11774b0d21a616ec", package = "pox-locking", default-features = false }
30+
stackslib = { git = "https://github.com/stacks-network/stacks-core.git", rev = "41bd9d0a15a08d8ab2603edf11774b0d21a616ec", package = "stackslib", default-features = false }
3131

3232
aes-gcm = "0.10"
3333
argon2 = "0.5.3"

components/clarinet-cli/src/frontend/cli.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use clarity_repl::clarity::vm::analysis::AnalysisDatabase;
2828
use clarity_repl::clarity::vm::costs::LimitedCostTracker;
2929
use clarity_repl::clarity::vm::diagnostic::Diagnostic;
3030
use clarity_repl::clarity::vm::types::QualifiedContractIdentifier;
31-
use clarity_repl::clarity::ClarityVersion;
31+
use clarity_repl::clarity::{ClarityVersion, StacksEpochId};
3232
use clarity_repl::frontend::Terminal;
3333
use clarity_repl::repl::diagnostic::output_diagnostic;
3434
use clarity_repl::repl::settings::{ApiUrl, RemoteDataSettings};
@@ -148,33 +148,41 @@ struct Formatter {
148148
}
149149

150150
impl Formatter {
151-
fn get_input_sources(&self) -> Vec<FormatterInputSource> {
151+
fn get_input_sources(&self, manifest: &ProjectManifest) -> Vec<FormatterInputSource> {
152152
if self.stdin {
153153
vec![FormatterInputSource::Stdin]
154154
} else if let Some(file) = &self.file {
155-
vec![FormatterInputSource::File(file.clone())]
155+
let epoch = manifest
156+
.contracts
157+
.values()
158+
.find(|c| from_code_source(c.code_source.clone()) == *file)
159+
.map(|c| c.epoch.resolve());
160+
vec![FormatterInputSource::File(file.clone(), epoch)]
156161
} else {
157-
// look for files at the default code path (./contracts/) if
158-
// cmd.manifest_path is not specified OR if cmd.file is not specified
159-
let manifest = load_manifest_or_exit(self.manifest_path.clone(), true);
160-
let contracts = manifest.contracts.values().cloned();
161-
contracts
162-
.map(|c| from_code_source(c.code_source))
163-
.map(FormatterInputSource::File)
162+
manifest
163+
.contracts
164+
.values()
165+
.cloned()
166+
.map(|c| {
167+
FormatterInputSource::File(
168+
from_code_source(c.code_source),
169+
Some(c.epoch.resolve()),
170+
)
171+
})
164172
.collect()
165173
}
166174
}
167175
}
168176

169177
enum FormatterInputSource {
170-
File(String),
178+
File(String, Option<StacksEpochId>),
171179
Stdin,
172180
}
173181

174182
impl FormatterInputSource {
175183
fn get_input(&self) -> String {
176184
match self {
177-
FormatterInputSource::File(path) => {
185+
FormatterInputSource::File(path, _) => {
178186
fs::read_to_string(path).unwrap_or_else(|e| panic!("Failed to read file: {e}"))
179187
}
180188
FormatterInputSource::Stdin => io::stdin()
@@ -187,7 +195,14 @@ impl FormatterInputSource {
187195

188196
fn file_path(&self) -> Option<&str> {
189197
match self {
190-
FormatterInputSource::File(path) => Some(path),
198+
FormatterInputSource::File(path, _) => Some(path),
199+
FormatterInputSource::Stdin => None,
200+
}
201+
}
202+
203+
fn epoch(&self) -> Option<StacksEpochId> {
204+
match self {
205+
FormatterInputSource::File(_, epoch) => *epoch,
191206
FormatterInputSource::Stdin => None,
192207
}
193208
}
@@ -1333,7 +1348,8 @@ pub fn main() {
13331348
"{}",
13341349
format_warn!("This command is in beta. Feedback is welcome!"),
13351350
);
1336-
let sources = cmd.get_input_sources();
1351+
let manifest = load_manifest_or_exit(cmd.manifest_path.clone(), false);
1352+
let sources = cmd.get_input_sources(&manifest);
13371353
let mut settings = formatter::Settings::default();
13381354

13391355
if let Some(max_line_length) = cmd.max_line_length {
@@ -1353,7 +1369,7 @@ pub fn main() {
13531369

13541370
for source in sources {
13551371
let input = source.get_input();
1356-
let output = formatter.format(&input);
1372+
let output = formatter.format(&input, source.epoch());
13571373

13581374
if cmd.check {
13591375
if let Some(file_path) = source.file_path() {

components/clarinet-format/src/formatter/mod.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::collections::HashMap;
66
use std::iter::Peekable;
77
use std::{fmt, slice};
88

9+
use clarity::types::StacksEpochId;
10+
use clarity::vm::ast::stack_depth_checker::StackDepthLimits;
911
use clarity::vm::functions::define::DefineFunctions;
1012
use clarity::vm::functions::NativeFunctions;
1113
use clarity::vm::representations::{PreSymbolicExpression, PreSymbolicExpressionType};
@@ -68,9 +70,13 @@ impl ClarityFormatter {
6870
Self { settings }
6971
}
7072
/// formatting for files to ensure a newline at the end
71-
pub fn format_file(&self, source: &str) -> String {
73+
pub fn format_file(&self, source: &str, epoch: Option<StacksEpochId>) -> String {
7274
let trimmed_source = source.trim_start_matches(['\n', '\r']);
73-
let pse = clarity::vm::ast::parser::v2::parse(trimmed_source).unwrap();
75+
let pse = clarity::vm::ast::parser::v2::parse(
76+
trimmed_source,
77+
StackDepthLimits::for_epoch(epoch.unwrap_or(StacksEpochId::latest())),
78+
)
79+
.unwrap();
7480
let agg = Aggregator::new(&self.settings, &pse, Some(trimmed_source));
7581
let result = agg.generate();
7682

@@ -83,12 +89,20 @@ impl ClarityFormatter {
8389
agg.generate()
8490
}
8591
/// Alias `format_file` to `format`
86-
pub fn format(&self, source: &str) -> String {
87-
self.format_file(source)
92+
pub fn format(&self, source: &str, epoch: Option<StacksEpochId>) -> String {
93+
self.format_file(source, epoch)
8894
}
8995
/// for range formatting within editors
90-
pub fn format_section(&self, source: &str) -> Result<String, String> {
91-
let pse = clarity::vm::ast::parser::v2::parse(source).map_err(|e| e.to_string())?;
96+
pub fn format_section(
97+
&self,
98+
source: &str,
99+
epoch: Option<StacksEpochId>,
100+
) -> Result<String, String> {
101+
let pse = clarity::vm::ast::parser::v2::parse(
102+
source,
103+
StackDepthLimits::for_epoch(epoch.unwrap_or(StacksEpochId::latest())),
104+
)
105+
.map_err(|e| e.to_string())?;
92106

93107
// range formatting specifies to the aggregator that we're
94108
// starting mid-source and thus should pre-populate
@@ -1889,6 +1903,8 @@ mod tests_formatter {
18891903
#[allow(unused_imports)]
18901904
use std::assert_eq;
18911905

1906+
use clarity::types::StacksEpochId;
1907+
use clarity::vm::ast::stack_depth_checker::StackDepthLimits;
18921908
use indoc::indoc;
18931909

18941910
use super::{ClarityFormatter, Settings};
@@ -1902,12 +1918,12 @@ mod tests_formatter {
19021918

19031919
fn format_with_default(source: &str) -> String {
19041920
let formatter = ClarityFormatter::new(Settings::default());
1905-
formatter.format_section(source).unwrap()
1921+
formatter.format_section(source, None).unwrap()
19061922
}
19071923

19081924
fn format_with(source: &str, settings: Settings) -> String {
19091925
let formatter = ClarityFormatter::new(settings);
1910-
formatter.format_section(source).unwrap()
1926+
formatter.format_section(source, None).unwrap()
19111927
}
19121928

19131929
#[test]
@@ -2743,7 +2759,11 @@ mod tests_formatter {
27432759
#[test]
27442760
fn format_ast_without_source() {
27452761
let src = "(define-private (noop) (begin (+ 1 2) (ok true)))";
2746-
let ast = clarity::vm::ast::parser::v2::parse(src).unwrap();
2762+
let ast = clarity::vm::ast::parser::v2::parse(
2763+
src,
2764+
StackDepthLimits::for_epoch(StacksEpochId::latest()),
2765+
)
2766+
.unwrap();
27472767
let formatter = ClarityFormatter::new(Settings::default());
27482768
let expected = format_with_default(src);
27492769
let result = formatter.format_ast(&ast);
@@ -2753,7 +2773,11 @@ mod tests_formatter {
27532773
#[test]
27542774
fn format_ast_without_source_handle_indentation() {
27552775
let src = " (begin (+ 1 2) (ok true))";
2756-
let ast = clarity::vm::ast::parser::v2::parse(src).unwrap();
2776+
let ast = clarity::vm::ast::parser::v2::parse(
2777+
src,
2778+
StackDepthLimits::for_epoch(StacksEpochId::latest()),
2779+
)
2780+
.unwrap();
27572781
let expected = format_with_default(src);
27582782
let formatter = ClarityFormatter::new(Settings::default());
27592783
let result = formatter.format_ast(&ast);
@@ -2879,7 +2903,11 @@ mod tests_formatter {
28792903
fn test_list_type_signature() {
28802904
fn assert_list_type_signature(src: &str, expected: bool) {
28812905
let settings = Settings::default();
2882-
let exprs = clarity::vm::ast::parser::v2::parse(src).unwrap();
2906+
let exprs = clarity::vm::ast::parser::v2::parse(
2907+
src,
2908+
StackDepthLimits::for_epoch(StacksEpochId::latest()),
2909+
)
2910+
.unwrap();
28832911
let aggregator = Aggregator::new(&settings, &exprs, Some(src));
28842912
let list_exprs = exprs[0].match_list().unwrap();
28852913
assert_eq!(aggregator.is_list_type_signature(list_exprs), expected);

components/clarinet-format/tests/golden.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::fs;
33
use std::path::Path;
44

55
use clarinet_format::formatter::{ClarityFormatter, Indentation, Settings};
6+
use clarity::types::StacksEpochId;
7+
use clarity::vm::ast::stack_depth_checker::StackDepthLimits;
68

79
/// This is strictly for reading top metadata from golden tests
810
fn from_metadata(metadata: &str) -> Settings {
@@ -45,7 +47,7 @@ fn format_file_with_metadata(source: &str) -> String {
4547

4648
let real_source = lines.collect::<Vec<&str>>().join("\n");
4749
let formatter = ClarityFormatter::new(settings);
48-
formatter.format_file(&real_source)
50+
formatter.format_file(&real_source, None)
4951
}
5052
#[test]
5153
fn test_irl_contracts() {
@@ -72,7 +74,10 @@ fn test_irl_contracts() {
7274
pretty_assertions::assert_eq!(result, intended, "Mismatch in file: {:?}", file_name);
7375
// parse resulting contract
7476
let (_statements, diagnostics, success) =
75-
clarity::vm::ast::parser::v2::parse_collect_diagnostics(&result);
77+
clarity::vm::ast::parser::v2::parse_collect_diagnostics(
78+
&result,
79+
StackDepthLimits::for_epoch(StacksEpochId::latest()),
80+
);
7681

7782
if !diagnostics.is_empty() {
7883
println!("Result of re-parsing file: {}", file_name.to_str().unwrap());

components/clarity-lsp/src/common/backend.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ pub fn process_request(
415415
};
416416

417417
let formatter = clarinet_format::formatter::ClarityFormatter::new(formatting_options);
418-
let formatted_result = formatter.format_file(source);
418+
let formatted_result = formatter.format_file(source, Some(contract_data.epoch));
419419
let text_edit = ls_types::TextEdit {
420420
range: ls_types::Range {
421421
start: ls_types::Position {
@@ -470,6 +470,7 @@ pub fn process_request(
470470
},
471471
max_line_length,
472472
};
473+
let epoch = Some(contract_data.epoch);
473474

474475
// extract the text of just this range
475476
let lines: Vec<&str> = source.lines().collect();
@@ -540,7 +541,7 @@ pub fn process_request(
540541
let formatter = clarinet_format::formatter::ClarityFormatter::new(formatting_options);
541542

542543
// Try to format the range text, but handle panics/errors gracefully
543-
let formatted_result = formatter.format_section(&range_text);
544+
let formatted_result = formatter.format_section(&range_text, epoch);
544545

545546
let formatted_result = match formatted_result {
546547
Ok(formatted_text) => {

components/clarity-repl/src/utils.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use ::clarity::types::StacksEpochId;
12
use ::clarity::vm::ast::parser;
3+
use ::clarity::vm::ast::stack_depth_checker::StackDepthLimits;
24
use ::clarity::vm::events::{FTEventType, NFTEventType, STXEventType, StacksTransactionEvent};
35
use ::clarity::vm::representations::PreSymbolicExpressionType::Comment;
46

@@ -71,8 +73,10 @@ pub fn serialize_event(event: &StacksTransactionEvent) -> serde_json::Value {
7173
}
7274

7375
pub fn remove_env_simnet(source: String) -> Result<String, String> {
74-
let (pre_expressions, mut _diagnostics, success) =
75-
parser::v2::parse_collect_diagnostics(&source);
76+
let (pre_expressions, mut _diagnostics, success) = parser::v2::parse_collect_diagnostics(
77+
&source,
78+
StackDepthLimits::for_epoch(StacksEpochId::latest()),
79+
);
7680

7781
if !success {
7882
return Err("failed to parse pre_expressions from source".to_string());

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# Hash for clarity git dependency - update this when Cargo.lock changes
2323
# Run `nix run .#check-git-dependencies-hash` to verify or get the new hash
24-
clarityHash = "sha256-6/IsZoFOl2qX7yyakQVKxrl3fNXwSRBb3nCnFFkaA/U=";
24+
clarityHash = "sha256-ktmxnwyId37u944Q9PsJmk7lR8jbLseHRsgEyxObMGk=";
2525

2626
clarinet = pkgs.rustPlatform.buildRustPackage {
2727
inherit pname version;

0 commit comments

Comments
 (0)