Skip to content

Commit

Permalink
Merge branch 'main' into jared/improve-module-error
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredramirez authored Dec 23, 2024
2 parents 2055eb3 + a58b101 commit 82680e3
Show file tree
Hide file tree
Showing 31 changed files with 562 additions and 122 deletions.
38 changes: 38 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/rust
{
"name": "Rust",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye",

// Use 'mounts' to make the cargo cache persistent in a Docker Volume.
// "mounts": [
// {
// "source": "devcontainer-cargo-cache-${devcontainerId}",
// "target": "/usr/local/cargo",
// "type": "volume"
// }
// ]

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers-contrib/features/zig:1": {
"version": "0.13.0"
},
"ghcr.io/devcontainers-community/features/llvm:3": {
"version": 18
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "rustc --version",
"onCreateCommand": "sudo apt-get update && sudo apt-get install -y pkg-config libz-dev libzstd-dev valgrind"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ programs.gnupg.agent = {
<details>
<summary>Forgot to sign commits?</summary>

:exclamation: Make sure [to set up signing on your device](devtools/signing.md) first, then continue below.

You can view your commits on github, those without the "Verified" badge still need to be signed.
If any of those is a merge commit, follow [these steps](https://stackoverflow.com/a/9958215/4200103) instead of the ones below.

Expand Down
18 changes: 16 additions & 2 deletions crates/compiler/fmt/src/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ fn fmt_ty_ann(
}

TypeAnnotation::As(lhs, spaces, TypeHeader { name, vars }) => {
let write_parens = parens == Parens::InAsPattern;
let write_parens = parens == Parens::InAsPattern || parens == Parens::InApply;

buf.indent(indent);
if write_parens {
buf.push('(')
}

buf.indent(indent);
let lhs_indent = buf.cur_line_indent();
lhs.value
.format_with_options(buf, Parens::InAsPattern, Newlines::No, indent);
Expand Down Expand Up @@ -410,6 +410,7 @@ fn fmt_ty_ann(
buf.spaces(1);
}
for (i, has) in implements_clauses.iter().enumerate() {
buf.indent(indent);
buf.push_str(if i == 0 {
roc_parse::keyword::WHERE
} else {
Expand Down Expand Up @@ -1373,6 +1374,19 @@ impl<'a> Nodify<'a> for TypeAnnotation<'a> {
inner
}
}
TypeAnnotation::As(_left, _sp, _right) => {
let lifted = ann_lift_spaces(arena, self);
let item = Spaces {
before: lifted.before,
item: Node::TypeAnnotation(lifted.item),
after: lifted.after,
};
if parens == Parens::InApply || parens == Parens::InAsPattern {
parens_around_node(arena, item)
} else {
item
}
}
_ => {
let lifted = ann_lift_spaces(arena, self);
Spaces {
Expand Down
18 changes: 17 additions & 1 deletion crates/compiler/fmt/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,8 +1405,12 @@ fn fmt_binops<'a>(
expr_lift_spaces(Parens::InOperator, buf.text.bump(), &loc_left_side.value);
format_spaces(buf, lifted_left_side.before, Newlines::Yes, indent);

buf.indent(indent);
let line_indent = buf.cur_line_indent();

let need_parens = matches!(lifted_left_side.item, Expr::BinOps(..))
|| starts_with_unary_minus(lifted_left_side.item);
|| starts_with_unary_minus(lifted_left_side.item)
|| (ends_with_closure(&lifted_left_side.item) && line_indent < indent);

if need_parens {
fmt_parens(&lifted_left_side.item, buf, indent);
Expand Down Expand Up @@ -1451,6 +1455,17 @@ fn fmt_binops<'a>(
format_spaces(buf, lifted_right_side.after, Newlines::Yes, indent);
}

fn ends_with_closure(item: &Expr<'_>) -> bool {
match item {
Expr::Closure(..) => true,
Expr::Apply(expr, args, _) => args
.last()
.map(|a| ends_with_closure(&a.value))
.unwrap_or_else(|| ends_with_closure(&expr.value)),
_ => false,
}
}

fn starts_with_unary_minus(item: Expr<'_>) -> bool {
match item {
Expr::UnaryOp(
Expand Down Expand Up @@ -1616,6 +1631,7 @@ fn fmt_when<'a>(
}

if let Some(guard_expr) = &branch.guard {
buf.indent(indent + INDENT);
buf.push_str(" if");
buf.spaces(1);
guard_expr.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent + INDENT);
Expand Down
3 changes: 2 additions & 1 deletion crates/compiler/parse/src/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub const WHERE: &str = "where";
// These keywords are valid in headers
pub const PLATFORM: &str = "platform";

pub const KEYWORDS: [&str; 11] = [
pub const KEYWORDS: [&str; 12] = [
IF, THEN, ELSE, WHEN, AS, IS, DBG, IMPORT, EXPECT, RETURN, CRASH,
"expect!", // not itself a keyword, but it's problematic if we allow an identifier like this!
];
6 changes: 5 additions & 1 deletion crates/compiler/test_syntax/src/minimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ fn round_trip_once(input: Input<'_>, options: Options) -> Option<String> {
};

if actual.is_malformed() {
return Some("Initial parse is malformed".to_string());
if options.minimize_initial_parse_error {
return Some("Initial parse is malformed".to_string());
} else {
return None;
}
}

let output = actual.format();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expr(Start(@0), @0)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expr(When(Branch(Start(@13), @13), @0), @0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
when s
is
z->expect!%when s
is z->q
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\j -> (e \B -> B)
> s
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@0-16 SpaceAfter(
Closure(
[
@1-2 Identifier {
ident: "j",
},
],
@4-16 BinOps(
[
(
@4-12 SpaceAfter(
Apply(
@4-5 Var {
module_name: "",
ident: "e",
},
[
@5-12 Closure(
[
@6-7 SpaceAfter(
Tag(
"B",
),
[
Newline,
],
),
],
@11-12 Tag(
"B",
),
),
],
Space,
),
[
Newline,
],
),
@14-15 GreaterThan,
),
],
@15-16 Var {
module_name: "",
ident: "s",
},
),
),
[
Newline,
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\j->e\B
->B
>s

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
N : A (H as H) H
I
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@0-16 SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(0),
],
regions: [
@0-14,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [
Alias {
header: TypeHeader {
name: @0-1 "N",
vars: [],
},
ann: @2-14 Apply(
"",
"A",
[
@5-0 As(
@5-6 Apply(
"",
"H",
[],
),
[],
TypeHeader {
name: @10-11 "H",
vars: [],
},
),
@13-14 Apply(
"",
"H",
[],
),
],
),
},
],
value_defs: [],
},
@15-16 SpaceBefore(
Tag(
"I",
),
[
Newline,
],
),
),
[
Newline,
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
N:A((H)as H) H
I
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 : [N (* as S)]
_
Loading

0 comments on commit 82680e3

Please sign in to comment.