Skip to content

Commit 3c15aee

Browse files
authored
feat(fmt): solar bump + handle cmnts in non-informed params (#11901)
* feat: solar bump + handle cmnts between uninitialized params * chore: bump compilers to v0.19.5
1 parent 4d07808 commit 3c15aee

File tree

11 files changed

+183
-111
lines changed

11 files changed

+183
-111
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ foundry-linking = { path = "crates/linking" }
209209

210210
# solc & compilation utilities
211211
foundry-block-explorers = { version = "0.22.0", default-features = false }
212-
foundry-compilers = { version = "0.19.1", default-features = false, features = [
212+
foundry-compilers = { version = "0.19.5", default-features = false, features = [
213213
"rustls",
214214
"svm-solc",
215215
] }
216216
foundry-fork-db = "0.18"
217217
solang-parser = { version = "=0.3.9", package = "foundry-solang-parser" }
218-
solar = { package = "solar-compiler", version = "=0.1.7", default-features = false }
218+
solar = { package = "solar-compiler", version = "=0.1.8", default-features = false }
219219
svm = { package = "svm-rs", version = "0.5", default-features = false, features = [
220220
"rustls",
221221
] }
@@ -427,7 +427,7 @@ rexpect = { git = "https://github.com/rust-cli/rexpect", rev = "2ed0b1898d7edaf6
427427

428428
## foundry
429429
# foundry-block-explorers = { git = "https://github.com/foundry-rs/block-explorers.git", rev = "f5b46b2" }
430-
# foundry-compilers = { git = "https://github.com/foundry-rs/compilers.git", branch = "dani/bump-solar" }
430+
# foundry-compilers = { git = "https://github.com/foundry-rs/compilers.git", branch = "main" }
431431
# foundry-fork-db = { git = "https://github.com/foundry-rs/foundry-fork-db", rev = "eee6563" }
432432

433433
# solar

crates/evm/coverage/src/analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'ast> ast::Visit<'ast> for SourceVisitor<'_> {
367367
stmt.span,
368368
);
369369
}
370-
StmtKind::For { body, .. } => {
370+
StmtKind::For(yul::StmtFor { body, .. }) => {
371371
self.push_stmt(body.span);
372372
}
373373
StmtKind::Switch(switch) => {

crates/fmt/src/state/common.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl<'ast> State<'_, 'ast> {
212212
format: ListFormat,
213213
) where
214214
P: FnMut(&mut Self, &'a T),
215-
S: FnMut(&T) -> Option<Span> + Copy,
215+
S: FnMut(&T) -> Span,
216216
{
217217
if self.handle_span(Span::new(pos_lo, pos_hi), true) {
218218
return;
@@ -232,26 +232,24 @@ impl<'ast> State<'_, 'ast> {
232232
}
233233

234234
// Format single-item inline lists directly without boxes
235-
self.print_inside_parens(|state| match get_span(&values[0]) {
236-
Some(span) => {
237-
state.s.cbox(state.ind);
238-
let mut skip_break = true;
239-
if state.peek_comment_before(span.hi()).is_some() {
240-
state.hardbreak();
241-
skip_break = false;
242-
}
235+
self.print_inside_parens(|state| {
236+
let span = get_span(&values[0]);
237+
state.s.cbox(state.ind);
238+
let mut skip_break = true;
239+
if state.peek_comment_before(span.hi()).is_some() {
240+
state.hardbreak();
241+
skip_break = false;
242+
}
243243

244-
state.print_comments(span.lo(), CommentConfig::skip_ws().mixed_prev_space());
245-
print(state, &values[0]);
244+
state.print_comments(span.lo(), CommentConfig::skip_ws().mixed_prev_space());
245+
print(state, &values[0]);
246246

247-
if !state.print_trailing_comment(span.hi(), None) && skip_break {
248-
state.neverbreak();
249-
} else {
250-
state.break_offset_if_not_bol(0, -state.ind, false);
251-
}
252-
state.end();
247+
if !state.print_trailing_comment(span.hi(), None) && skip_break {
248+
state.neverbreak();
249+
} else {
250+
state.break_offset_if_not_bol(0, -state.ind, false);
253251
}
254-
None => print(state, &values[0]),
252+
state.end();
255253
});
256254
}
257255

@@ -263,7 +261,7 @@ impl<'ast> State<'_, 'ast> {
263261
get_span: S,
264262
) where
265263
P: FnMut(&mut Self, &'a T),
266-
S: FnMut(&T) -> Option<Span>,
264+
S: FnMut(&T) -> Span,
267265
{
268266
if self.handle_span(span, false) {
269267
return;
@@ -281,9 +279,9 @@ impl<'ast> State<'_, 'ast> {
281279
format: ListFormat,
282280
) -> bool
283281
where
284-
S: FnMut(&T) -> Option<Span>,
282+
S: FnMut(&T) -> Span,
285283
{
286-
let Some(span) = values.first().and_then(&mut get_span) else {
284+
let Some(span) = values.first().map(&mut get_span) else {
287285
return false;
288286
};
289287

@@ -357,7 +355,7 @@ impl<'ast> State<'_, 'ast> {
357355
format: ListFormat,
358356
) where
359357
P: FnMut(&mut Self, &'a T),
360-
S: FnMut(&T) -> Option<Span>,
358+
S: FnMut(&T) -> Span,
361359
{
362360
if values.is_empty() {
363361
return;
@@ -366,8 +364,8 @@ impl<'ast> State<'_, 'ast> {
366364
let first = get_span(&values[0]);
367365
// we can't simply check `peek_comment_before(pos_hi)` cause we would also account for
368366
// comments in the child expression, and those don't matter.
369-
let has_comments = self.peek_comment_before(first.map_or(pos_hi, |s| s.lo())).is_some()
370-
|| self.peek_comment_between(first.map_or(pos_hi, |s| s.hi()), pos_hi).is_some();
367+
let has_comments = self.peek_comment_before(first.lo()).is_some()
368+
|| self.peek_comment_between(first.hi(), pos_hi).is_some();
371369
let is_single_without_cmnts = values.len() == 1 && !format.break_single && !has_comments;
372370

373371
let skip_first_break = if format.with_delimiters || format.is_inline() {
@@ -399,10 +397,9 @@ impl<'ast> State<'_, 'ast> {
399397
is_single_without_cmnts || !format.with_delimiters || format.is_inline();
400398
for (i, value) in values.iter().enumerate() {
401399
let is_last = i == values.len() - 1;
402-
if let Some(span) = get_span(value)
403-
&& self
404-
.print_comments(span.lo(), CommentConfig::skip_ws().mixed_prev_space())
405-
.is_some_and(|cmnt| cmnt.is_mixed())
400+
if self
401+
.print_comments(get_span(value).lo(), CommentConfig::skip_ws().mixed_prev_space())
402+
.is_some_and(|cmnt| cmnt.is_mixed())
406403
&& format.breaks_cmnts
407404
{
408405
self.hardbreak(); // trailing and isolated comments already hardbreak
@@ -414,7 +411,7 @@ impl<'ast> State<'_, 'ast> {
414411
self.print_word(",");
415412
}
416413

417-
let next_span = if is_last { None } else { get_span(&values[i + 1]) };
414+
let next_span = if is_last { None } else { Some(get_span(&values[i + 1])) };
418415
let next_pos = next_span.map(Span::lo).unwrap_or(pos_hi);
419416

420417
if !is_last
@@ -447,7 +444,12 @@ impl<'ast> State<'_, 'ast> {
447444
&& !self.is_bol_or_only_ind()
448445
&& !self.inline_config.is_disabled(next_span)
449446
{
450-
format.print_break(false, values.len(), &mut self.s);
447+
if next_span.is_dummy() && !matches!(format.kind, ListFormatKind::AlwaysBreak) {
448+
// Don't add spaces between uninformed items (commas)
449+
self.zerobreak();
450+
} else {
451+
format.print_break(false, values.len(), &mut self.s);
452+
}
451453
}
452454
}
453455

crates/fmt/src/state/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,9 @@ impl<'sess> State<'sess, '_> {
702702
}
703703
CommentStyle::Isolated => {
704704
let Some(mut prefix) = cmnt.prefix() else { return };
705-
config.hardbreak_if_not_bol(self.is_bol_or_only_ind(), &mut self.s);
705+
if !config.iso_no_break {
706+
config.hardbreak_if_not_bol(self.is_bol_or_only_ind(), &mut self.s);
707+
}
706708

707709
if self.config.wrap_comments {
708710
// Merge and wrap comments

0 commit comments

Comments
 (0)