Skip to content
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

Update Rust to nightly-2024-02-22 (1.78.0-nightly) #948

Merged
merged 3 commits into from Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Expand Up @@ -12,6 +12,10 @@ members = [
"compiler/vm/fuzz",
]

[workspace.package]
edition = "2021"
rust-version = "1.78.0"

[profile.release]
# https://github.com/flamegraph-rs/flamegraph#usage-with-benchmarks
debug = true
3 changes: 2 additions & 1 deletion compiler/backend_inkwell/Cargo.toml
@@ -1,7 +1,8 @@
[package]
name = "candy_backend_inkwell"
version = "0.1.0"
edition = "2021"
edition.workspace = true
rust-version.workspace = true

[dependencies]
candy_frontend = { version = "0.1.0", path = "../frontend" }
Expand Down
13 changes: 10 additions & 3 deletions compiler/backend_inkwell/src/lib.rs
Expand Up @@ -857,7 +857,9 @@ impl<'ctx> CodeGen<'ctx> {
self.builder
.build_load(self.candy_value_pointer_type, it.as_pointer_value(), "")
});
if v.is_none() && let Some(index) = function_ctx.captured_ids.iter().position(|i| *i == id) {
if v.is_none()
&& let Some(index) = function_ctx.captured_ids.iter().position(|i| *i == id)
{
let env_ptr = function_ctx.function_value.get_last_param().unwrap();

let env_value = self
Expand All @@ -870,9 +872,14 @@ impl<'ctx> CodeGen<'ctx> {
)
.unwrap();

v = Some(self.builder.build_load(self.candy_value_pointer_type, env_value, ""));
v = Some(
self.builder
.build_load(self.candy_value_pointer_type, env_value, ""),
);
}
if v.is_none() && let Some(value) = self.locals.get(&id) {
if v.is_none()
&& let Some(value) = self.locals.get(&id)
{
v = Some(*value);
}
if self.unrepresented_ids.contains(&id) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/cli/Cargo.toml
@@ -1,8 +1,8 @@
[package]
name = "candy_cli"
version = "0.1.0"
edition = "2021"
rust-version = "1.56"
edition.workspace = true
rust-version.workspace = true
default-run = "candy"

[[bin]]
Expand Down
3 changes: 1 addition & 2 deletions compiler/cli/src/inkwell.rs
Expand Up @@ -74,7 +74,6 @@ pub fn compile(options: &Options) -> ProgramResult {
ExecutionTarget::MainFunction(module.clone()),
TracingConfig::off(),
)
.map(|(mir, errors)| (mir, errors))
.unwrap_or_else(|error| {
let payload = CompilerErrorPayload::Module(error);
let mir = Mir::build(|body| {
Expand All @@ -89,7 +88,7 @@ pub fn compile(options: &Options) -> ProgramResult {

if !errors.is_empty() {
for error in errors.as_ref() {
println!("{:?}", error);
println!("{error:?}");
}
std::process::exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/formatter/Cargo.toml
@@ -1,8 +1,8 @@
[package]
name = "candy_formatter"
version = "0.1.0"
edition = "2021"
rust-version = "1.56"
edition.workspace = true
rust-version.workspace = true

[lib]

Expand Down
11 changes: 6 additions & 5 deletions compiler/formatter/src/existing_whitespace.rs
Expand Up @@ -118,13 +118,15 @@ impl<'a> ExistingWhitespace<'a> {
edits: &mut TextEdits,
other: &mut ExistingWhitespace<'a>,
) {
if let Some(whitespace) = self.whitespace.first() && whitespace.kind.is_whitespace() {
if let Some(whitespace) = self.whitespace.first()
&& whitespace.kind.is_whitespace()
{
let span = match &mut self.whitespace {
Cow::Borrowed(whitespace) => {
let (first, remaining) = whitespace.split_first().unwrap();
*whitespace = remaining;
first.data.span.clone()
},
}
Cow::Owned(whitespace) => whitespace.remove(0).data.span,
};
self.start_offset = span.end;
Expand Down Expand Up @@ -586,9 +588,8 @@ mod test {
let mut csts = parse_rcst(source).to_csts();
assert_eq!(csts.len(), 1);

let cst = match csts.pop().unwrap().kind {
CstKind::Call { receiver, .. } => receiver,
_ => panic!("Expected a call"),
let CstKind::Call { receiver: cst, .. } = csts.pop().unwrap().kind else {
panic!("Expected a call");
};
let reduced_source = cst.to_string();

Expand Down
40 changes: 23 additions & 17 deletions compiler/formatter/src/format.rs
Expand Up @@ -412,11 +412,8 @@ pub fn format_cst<'a>(
};

let left_width = if let Some(right_first_line_width) = right_width.first_line_width()
&& (left_min_width
+ SinglelineWidth::SPACE
+ bar_width
+ right_first_line_width)
.fits(info.indentation)
&& (left_min_width + SinglelineWidth::SPACE + bar_width + right_first_line_width)
.fits(info.indentation)
{
left.into_trailing_with_space(edits)
} else {
Expand Down Expand Up @@ -710,12 +707,13 @@ pub fn format_cst<'a>(
..
}] if unparsable_input.is_empty(),
);
let (cases, last_case) = if !only_has_empty_error_case && let [cases @ .., last_case] = cases.as_slice() {
(cases, last_case)
} else {
let (percent_width, whitespace) = percent.split();
return FormattedCst::new(expression_width + percent_width, whitespace);
};
let (cases, last_case) =
if !only_has_empty_error_case && let [cases @ .., last_case] = cases.as_slice() {
(cases, last_case)
} else {
let (percent_width, whitespace) = percent.split();
return FormattedCst::new(expression_width + percent_width, whitespace);
};

let case_info = info
.resolve_for_expression_with_indented_lines(
Expand Down Expand Up @@ -994,18 +992,25 @@ pub fn format_cst<'a>(
body.first().unwrap().unwrap_whitespace_and_comment().kind,
CstKind::Assignment { .. },
);
let assignment_sign_trailing = if !contains_single_assignment && left_width.last_line_fits(
info.indentation,
assignment_sign.min_width(info.indentation) + SinglelineWidth::SPACE + body_width + body_whitespace_width,
) {
let assignment_sign_trailing = if !contains_single_assignment
&& left_width.last_line_fits(
info.indentation,
assignment_sign.min_width(info.indentation)
+ SinglelineWidth::SPACE
+ body_width
+ body_whitespace_width,
) {
TrailingWhitespace::Space
} else if !contains_single_assignment
&& !body_whitespace_has_comments
&& let Some(body_first_line_width) = body_width.first_line_width()
&& left_width.last_line_fits(
info.indentation,
assignment_sign.min_width(info.indentation) + SinglelineWidth::SPACE + body_first_line_width,
) {
assignment_sign.min_width(info.indentation)
+ SinglelineWidth::SPACE
+ body_first_line_width,
)
{
TrailingWhitespace::Space
} else {
TrailingWhitespace::Indentation(info.indentation.with_indent())
Expand Down Expand Up @@ -1059,6 +1064,7 @@ fn format_receiver<'a>(
}

struct Argument<'a> {
#[allow(clippy::struct_field_names)]
argument: MaybeSandwichLikeArgument<'a>,
precedence: Option<PrecedenceCategory>,
parentheses: ExistingParentheses<'a>,
Expand Down
20 changes: 10 additions & 10 deletions compiler/formatter/src/format_collection.rs
Expand Up @@ -49,20 +49,20 @@ pub fn format_collection<'a>(
let is_comma_required =
is_comma_required_due_to_single_item || !is_last_item || item.has_comments();
let info = if !is_comma_required && let Width::Singleline(min_width) = min_width {
// We're looking at the last item and everything might fit in one line.
let max_width = Width::MAX - min_width;
assert!(!max_width.is_empty());
// We're looking at the last item and everything might fit in one line.
let max_width = Width::MAX - min_width;
assert!(!max_width.is_empty());

item_info.with_trailing_comma_condition(
TrailingCommaCondition::UnlessFitsIn(max_width),
)
} else {
item_info.clone()
};
item_info
.with_trailing_comma_condition(TrailingCommaCondition::UnlessFitsIn(max_width))
} else {
item_info.clone()
};
let item = format_cst(edits, previous_width_for_items, item, &info);

if let Width::Singleline(old_min_width) = min_width
&& let Width::Singleline(item_min_width) = item.min_width(info.indentation) {
&& let Width::Singleline(item_min_width) = item.min_width(info.indentation)
{
let (item_min_width, max_width) = if is_last_item {
(item_min_width, Width::MAX)
} else {
Expand Down
3 changes: 1 addition & 2 deletions compiler/formatter/src/text_edits.rs
Expand Up @@ -50,8 +50,7 @@ impl TextEdits {
self.edits
.get(index)
// An edit contains this position.
.map(|it| it.range.contains(&offset))
.unwrap_or_default()
.is_some_and(|it| it.range.contains(&offset))
})
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/frontend/Cargo.toml
@@ -1,8 +1,8 @@
[package]
name = "candy_frontend"
version = "0.1.0"
edition = "2021"
rust-version = "1.56"
edition.workspace = true
rust-version.workspace = true

[lib]

Expand Down
2 changes: 1 addition & 1 deletion compiler/frontend/src/ast.rs
Expand Up @@ -275,7 +275,7 @@ impl AstKind {
Self::Identifier(Identifier(identifier)) => {
let entry = captured_identifiers
.entry(identifier.value.clone())
.or_insert_with(Vec::new);
.or_default();
entry.push(identifier.id.clone());
}
Self::Symbol(_) => {}
Expand Down
8 changes: 4 additions & 4 deletions compiler/frontend/src/ast_to_hir.rs
Expand Up @@ -372,7 +372,7 @@ impl Context<'_> {
AstKind::MatchCase(MatchCase { box pattern, body }) => {
let (pattern, pattern_identifiers) = scope.lower_pattern(pattern);

let (body, _) = scope.with_scope(None, |scope| {
let (body, ()) = scope.with_scope(None, |scope| {
for (name, (ast_id, identifier_id)) in
pattern_identifiers.clone()
{
Expand All @@ -392,7 +392,7 @@ impl Context<'_> {
errors: errors.clone(),
};

let (body, _) = scope.with_scope(None, |scope| {
let (body, ()) = scope.with_scope(None, |scope| {
scope.compile(&[]);
});

Expand Down Expand Up @@ -464,7 +464,7 @@ impl Context<'_> {
None,
);
let then_function_id = self.create_next_id(None, None);
let (then_body, _) = self.with_scope(then_function_id.clone(), |scope| {
let (then_body, ()) = self.with_scope(then_function_id.clone(), |scope| {
scope.push(None, Expression::Reference(hir.clone()), None);
});
let then_function = self.push_with_existing_id(
Expand All @@ -478,7 +478,7 @@ impl Context<'_> {
);

let else_function_id = self.create_next_id(None, None);
let (else_body, _) = self.with_scope(else_function_id.clone(), |scope| {
let (else_body, ()) = self.with_scope(else_function_id.clone(), |scope| {
scope.push(
None,
Expression::Call {
Expand Down
41 changes: 23 additions & 18 deletions compiler/frontend/src/comment/string_to_rcst.rs
Expand Up @@ -107,7 +107,9 @@ mod parse {

#[instrument]
fn newline(input: Vec<&str>) -> Option<(Vec<&str>, Rcst)> {
if let ["", remaining @ ..] = input.as_slice() && !remaining.is_empty() {
if let ["", remaining @ ..] = input.as_slice()
&& !remaining.is_empty()
{
Some((remaining.to_vec(), Rcst::Newline))
} else {
None
Expand Down Expand Up @@ -666,7 +668,8 @@ mod parse {
let mut formatting_state = vec![];

if let Some((line, remaining)) = input.split_first()
&& let Some((title_line, new_formatting_state)) = title_line(line, formatting_state) {
&& let Some((title_line, new_formatting_state)) = title_line(line, formatting_state)
{
input = recombine("", remaining);
title_lines.push(title_line);
formatting_state = new_formatting_state;
Expand All @@ -680,7 +683,9 @@ mod parse {
};

if let Some((line, remaining)) = new_input.split_first()
&& let Some((new_title_line, new_formatting_state)) = title_line(line, formatting_state) {
&& let Some((new_title_line, new_formatting_state)) =
title_line(line, formatting_state)
{
input = recombine("", remaining);
let previous_line = title_lines.pop().unwrap();
title_lines.push(previous_line.wrap_in_whitespace(whitespace));
Expand Down Expand Up @@ -1073,7 +1078,7 @@ mod parse {
false
};

let extra_indentation = format!("{}", number).len() + 1 + usize::from(has_trailing_space);
let extra_indentation = format!("{number}").len() + 1 + usize::from(has_trailing_space);

Some((
line,
Expand All @@ -1090,20 +1095,22 @@ mod parse {
mut indentation: usize,
list_type: Option<ListType>,
) -> Option<(Vec<&str>, Rcst, ListType)> {
let Some((line, remaining)) = input.split_first() else {
return None;
};
let (line, remaining) = input.split_first()?;
let allows_unordered = list_type.map_or(true, |it| it == ListType::Unordered);
let allows_ordered = list_type.map_or(true, |it| it == ListType::Ordered);
// TODO: move the `allow_…` before the match checks when Rust's MIR no longer breaks
let ((line, marker, extra_indentation), list_type) =
if let Some(marker) = unordered_list_item_marker(line) && allows_unordered {
(marker, ListType::Unordered)
} else if let Some(marker) = ordered_list_item_marker(line) && allows_ordered {
(marker, ListType::Ordered)
} else {
return None;
};
let ((line, marker, extra_indentation), list_type) = if let Some(marker) =
unordered_list_item_marker(line)
&& allows_unordered
{
(marker, ListType::Unordered)
} else if let Some(marker) = ordered_list_item_marker(line)
&& allows_ordered
{
(marker, ListType::Ordered)
} else {
return None;
};
input = recombine(line, remaining);
indentation += extra_indentation;

Expand All @@ -1114,9 +1121,7 @@ mod parse {
fn list(input: Vec<&str>, indentation: usize) -> Option<(Vec<&str>, Rcst)> {
let mut list_items = vec![];

let Some((mut input, first_item, list_type)) = list_item(input, indentation, None) else {
return None;
};
let (mut input, first_item, list_type) = list_item(input, indentation, None)?;
list_items.push(first_item);

loop {
Expand Down
3 changes: 2 additions & 1 deletion compiler/frontend/src/cst/tree_with_ids.rs
Expand Up @@ -224,7 +224,8 @@ impl TreeWithIds for Cst {
if let Some(part) = interpolation_index.map(|index| &parts[index])
&& part.kind.is_text_interpolation()
&& let Some(child) = part.find_by_offset(offset)
&& !child.kind.is_text_interpolation() {
&& !child.kind.is_text_interpolation()
{
(Some(child), false)
} else {
(None, false)
Expand Down