Skip to content

Commit

Permalink
Merge branch 'main' into fix-parser-error
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelGarus committed Feb 22, 2024
2 parents 07d45cd + 7f99bf4 commit b0b98e9
Show file tree
Hide file tree
Showing 71 changed files with 699 additions and 517 deletions.
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
- changed-files:
- any-glob-to-any-file:
- vscode_extension/**/*
'P: ComplexNumber':
- changed-files:
- any-glob-to-any-file:
- packages/ComplexNumber/**/*
'P: Core':
- changed-files:
- any-glob-to-any-file:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
repo-token: ${{ secrets.BOT_TOKEN }}

assign-author:
if: github.event.action == 'opened'
if: github.event.action == 'opened' && github.event.pull_request.user.login != 'dependabot[bot]'
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand All @@ -28,7 +28,7 @@ jobs:

automerge-pr:
if: >
github.base_ref == 'refs/heads/main'
github.base_ref == 'main'
&& (
(github.event.action == 'opened' && !github.event.pull_request.draft)
|| github.event.action == 'ready_for_review')
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

1 comment on commit b0b98e9

@jwbot
Copy link
Collaborator

@jwbot jwbot commented on b0b98e9 Feb 22, 2024

Choose a reason for hiding this comment

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

Compiler

Benchmark suite Current: b0b98e9 Previous: 7f99bf4 Ratio
Time: Compiler/hello_world 54854587 ns/iter (± 1071032) 54437870 ns/iter (± 852073) 1.01
Time: Compiler/fibonacci 253095660 ns/iter (± 3001089) 253139501 ns/iter (± 7237353) 1.00
Time: VM Runtime/hello_world 39118 ns/iter (± 83174) 38697 ns/iter (± 48869) 1.01
Time: VM Runtime/fibonacci/15 21317227 ns/iter (± 168886) 21246519 ns/iter (± 196076) 1.00
Time: VM Runtime/PLB/binarytrees/6 604841178 ns/iter (± 4462143) 620691701 ns/iter (± 8677387) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.