Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
timonkrebs authored Jan 3, 2025
2 parents 3de4277 + 1b15896 commit 88a2579
Show file tree
Hide file tree
Showing 112 changed files with 1,550 additions and 489 deletions.
18 changes: 9 additions & 9 deletions BUILDING_FROM_SOURCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,24 @@ sudo apt-get install libz-dev libzstd-dev

### Zig

**version: 0.11.0**
**version: 0.13.0**

For any OS, you can use [`zigup`](https://github.com/marler8997/zigup) to manage zig installations.

If you prefer a package manager, you can try the following:

- MacOS: `brew install zig@0.11.0`
- MacOS: `brew install zig`
- Systems with snap (such as Ubuntu): `snap install zig --classic --beta`
- Other systems: refer to the [zig documentation](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)

If you want to install it manually, you can [download the binary](https://ziglang.org/download/#release-0.11.0) and place it on your PATH.
If you want to install it manually, you can [download the binary](https://ziglang.org/download/#release-0.13.0) and place it on your PATH.
Apart from the binary, the archive contains a `lib` folder, which needs to be copied next to the binary.

> WINDOWS NOTE: when you unpack the Zig archive on windows, the result is nested in an extra directory. The instructions on the zig website will seem to not work. So, double-check that the path to zig executable does not include the same directory name twice.
### LLVM

**version: 16.0.x**
**version: 18.0.x**

See below for operating system specific installation instructions.

Expand Down Expand Up @@ -167,10 +167,10 @@ chmod +x llvm.sh
```

If you use this script, you'll need to add `clang` to your `PATH`.
By default, the script installs it as `clang-16`. You can address this with symlinks like so:
By default, the script installs it as `clang-18`. You can address this with symlinks like so:

```sh
sudo ln -s /usr/bin/clang-16 /usr/bin/clang
sudo ln -s /usr/bin/clang-18 /usr/bin/clang
```

There are also alternative installation options at <http://releases.llvm.org/download.html>
Expand Down Expand Up @@ -203,7 +203,7 @@ Add `export LLVM_SYS_180_PREFIX=/usr/lib/llvm-18` to your `~/.bashrc` or equival

For macOS, you can install LLVM 18 using `brew install llvm@18` and then adding
`$(brew --prefix llvm@18)/bin` to your `PATH`. You can confirm this worked by
running `llc --version` - it should mention "LLVM version 16.0.x" at the top.
running `llc --version` - it should mention "LLVM version 18.x.x" at the top.
You may also need to manually specify a prefix env var like so:

```sh
Expand Down Expand Up @@ -261,8 +261,8 @@ Create `~/.cargo/config.toml` if it does not exist and add this to it:
rustflags = ["-C", "link-arg=-fuse-ld=lld", "-C", "target-cpu=native"]
```

Then install `lld` version 16 (e.g. with `$ sudo apt-get install lld-16`)
Then install `lld` version 18 (e.g. with `$ sudo apt-get install lld-18`)
and add make sure there's a `ld.lld` executable on your `PATH` which
is symlinked to `lld-16`.
is symlinked to `lld-18`.

That's it! Enjoy the faster builds.
22 changes: 17 additions & 5 deletions crates/cli/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub enum FormatProblem {

pub fn format_src(arena: &Bump, src: &str, flags: MigrationFlags) -> Result<String, FormatProblem> {
let ast = arena.alloc(parse_all(arena, src).unwrap_or_else(|e| {
user_error!("Unexpected parse failure when parsing this formatting:\n\n{:?}\n\nParse error was:\n\n{:?}\n\n", src, e)
user_error!("Unexpected parse failure when parsing this formatting:\n\n{src}\n\nParse error was:\n\n{:#?}\n\n", e)
}));
let mut buf = Buf::new_in(arena, flags);
fmt_all(&mut buf, ast);
Expand Down Expand Up @@ -305,7 +305,10 @@ main =
fn test_single_file_needs_reformatting() {
let dir = tempdir().unwrap();
let file_path = setup_test_file(dir.path(), "test1.roc", UNFORMATTED_ROC);
let flags = MigrationFlags::new(false);
let flags = MigrationFlags {
snakify: false,
parens_and_commas: false,
};

let result = format_files(vec![file_path.clone()], FormatMode::CheckOnly, flags);
assert!(result.is_err());
Expand All @@ -325,7 +328,10 @@ main =
let dir = tempdir().unwrap();
let file1 = setup_test_file(dir.path(), "test1.roc", UNFORMATTED_ROC);
let file2 = setup_test_file(dir.path(), "test2.roc", UNFORMATTED_ROC);
let flags = MigrationFlags::new(false);
let flags = MigrationFlags {
snakify: false,
parens_and_commas: false,
};

let result = format_files(vec![file1, file2], FormatMode::CheckOnly, flags);
assert!(result.is_err());
Expand All @@ -339,7 +345,10 @@ main =
fn test_no_files_need_reformatting() {
let dir = tempdir().unwrap();
let file_path = setup_test_file(dir.path(), "formatted.roc", FORMATTED_ROC);
let flags = MigrationFlags::new(false);
let flags = MigrationFlags {
snakify: false,
parens_and_commas: false,
};

let result = format_files(vec![file_path], FormatMode::CheckOnly, flags);
assert!(result.is_ok());
Expand All @@ -353,7 +362,10 @@ main =
let file_formatted = setup_test_file(dir.path(), "formatted.roc", FORMATTED_ROC);
let file1_unformated = setup_test_file(dir.path(), "test1.roc", UNFORMATTED_ROC);
let file2_unformated = setup_test_file(dir.path(), "test2.roc", UNFORMATTED_ROC);
let flags = MigrationFlags::new(false);
let flags = MigrationFlags {
snakify: false,
parens_and_commas: false,
};

let result = format_files(
vec![file_formatted, file1_unformated, file2_unformated],
Expand Down
5 changes: 4 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ fn main() -> io::Result<()> {
false => FormatMode::WriteToFile,
}
};
let flags = MigrationFlags::new(migrate);
let flags = MigrationFlags {
snakify: migrate,
parens_and_commas: migrate,
};

if from_stdin && matches!(format_mode, FormatMode::WriteToFile) {
eprintln!("When using the --stdin flag, either the --check or the --stdout flag must also be specified. (Otherwise, it's unclear what filename to write to!)");
Expand Down
7 changes: 6 additions & 1 deletion crates/compiler/can/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use roc_error_macros::internal_error;
use roc_module::{called_via::CalledVia, symbol::Symbol};
use roc_parse::ast::{self, Collection};
use roc_parse::ast::{self, Collection, PatternApplyStyle};
use roc_region::all::{Loc, Region};

use crate::{env::Env, pattern::Pattern, scope::Scope};
Expand All @@ -27,6 +27,7 @@ fn to_encoder<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
DERIVED_REGION,
ast::Pattern::Identifier { ident: payload },
)]),
ast::PatternApplyStyle::Whitespace,
);

// Encode.toEncoder payload
Expand Down Expand Up @@ -132,6 +133,7 @@ fn hash<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
DERIVED_REGION,
ast::Pattern::Identifier { ident: payload },
)]),
PatternApplyStyle::Whitespace,
);

// Hash.hash hasher payload
Expand Down Expand Up @@ -178,6 +180,7 @@ fn is_eq<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
DERIVED_REGION,
ast::Pattern::Identifier { ident: payload1 },
)]),
PatternApplyStyle::Whitespace,
);
// \@Opaq payload2
let opaque2 = ast::Pattern::Apply(
Expand All @@ -186,6 +189,7 @@ fn is_eq<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
DERIVED_REGION,
ast::Pattern::Identifier { ident: payload2 },
)]),
PatternApplyStyle::Whitespace,
);

// Bool.isEq payload1 payload2
Expand Down Expand Up @@ -232,6 +236,7 @@ fn to_inspector<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
DERIVED_REGION,
ast::Pattern::Identifier { ident: payload },
)]),
PatternApplyStyle::Whitespace,
);

// Inspect.toInspector payload
Expand Down
21 changes: 15 additions & 6 deletions crates/compiler/can/src/desugar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use roc_module::called_via::{BinOp, CalledVia};
use roc_module::ident::ModuleName;
use roc_parse::ast::Expr::{self, *};
use roc_parse::ast::{
is_expr_suffixed, AssignedField, Collection, Defs, ModuleImportParams, Pattern, ResultTryKind,
StrLiteral, StrSegment, TryTarget, TypeAnnotation, ValueDef, WhenBranch,
is_expr_suffixed, AssignedField, Collection, Defs, ModuleImportParams, Pattern,
PatternApplyStyle, ResultTryKind, StrLiteral, StrSegment, TryTarget, TypeAnnotation, ValueDef,
WhenBranch,
};
use roc_problem::can::Problem;
use roc_region::all::{Loc, Region};
Expand Down Expand Up @@ -177,7 +178,11 @@ fn new_op_call_expr<'a>(
env.arena.alloc(Loc::at(left.region, Pattern::Tag("Ok")));
branch_1_patts.push(Loc::at(
left.region,
Pattern::Apply(branch_1_tag, branch_1_patts_args.into_bump_slice()),
Pattern::Apply(
branch_1_tag,
branch_1_patts_args.into_bump_slice(),
PatternApplyStyle::ParensAndCommas,
),
));
let branch_one: &WhenBranch<'_> = env.arena.alloc(WhenBranch {
patterns: branch_1_patts.into_bump_slice(),
Expand All @@ -198,7 +203,11 @@ fn new_op_call_expr<'a>(
env.arena.alloc(Loc::at(left.region, Pattern::Tag("Err")));
branch_2_patts.push(Loc::at(
right.region,
Pattern::Apply(branch_2_tag, branch_2_patts_args.into_bump_slice()),
Pattern::Apply(
branch_2_tag,
branch_2_patts_args.into_bump_slice(),
PatternApplyStyle::ParensAndCommas,
),
));
let branch_two: &WhenBranch<'_> = env.arena.alloc(WhenBranch {
patterns: branch_2_patts.into_bump_slice(),
Expand Down Expand Up @@ -1413,7 +1422,7 @@ fn desugar_pattern<'a>(env: &mut Env<'a>, scope: &mut Scope, pattern: Pattern<'a
| MalformedIdent(_, _)
| QualifiedIdentifier { .. } => pattern,

Apply(tag, arg_patterns) => {
Apply(tag, arg_patterns, style) => {
// Skip desugaring the tag, it should either be a Tag or OpaqueRef
let mut desugared_arg_patterns = Vec::with_capacity_in(arg_patterns.len(), env.arena);
for arg_pattern in arg_patterns.iter() {
Expand All @@ -1423,7 +1432,7 @@ fn desugar_pattern<'a>(env: &mut Env<'a>, scope: &mut Scope, pattern: Pattern<'a
});
}

Apply(tag, desugared_arg_patterns.into_bump_slice())
Apply(tag, desugared_arg_patterns.into_bump_slice(), style)
}
RecordDestructure(field_patterns) => {
RecordDestructure(desugar_record_destructures(env, scope, field_patterns))
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/can/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pub fn canonicalize_pattern<'a>(
)));
Pattern::UnsupportedPattern(region)
}
Apply(tag, patterns) => {
Apply(tag, patterns, _) => {
let mut can_patterns = Vec::with_capacity(patterns.len());
for loc_pattern in *patterns {
let can_pattern = canonicalize_pattern(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/compiler/can/tests/test_suffixed.rs
expression: snapshot
snapshot_kind: text
---
Defs {
tags: [
Expand Down Expand Up @@ -96,6 +97,7 @@ Defs {
ident: "success_BRANCH1_24_32",
},
],
ParensAndCommas,
),
],
value: @24-32 Var {
Expand All @@ -115,6 +117,7 @@ Defs {
"",
),
],
ParensAndCommas,
),
],
value: @36-39 Num(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Defs {
ident: "name",
},
],
Whitespace,
),
],
value: @125-154 Apply(
Expand Down
18 changes: 14 additions & 4 deletions crates/compiler/fmt/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ use crate::pattern::{pattern_lift_spaces, pattern_lift_spaces_before};
use crate::spaces::{
fmt_comments_only, fmt_default_newline, fmt_default_spaces, fmt_spaces, NewlineAt, INDENT,
};
use crate::Buf;
use crate::{Buf, MigrationFlags};
use bumpalo::Bump;
use roc_error_macros::internal_error;
use roc_parse::ast::{
AbilityMember, Defs, Expr, ExtractSpaces, ImportAlias, ImportAsKeyword, ImportExposingKeyword,
ImportedModuleName, IngestedFileAnnotation, IngestedFileImport, ModuleImport,
ModuleImportParams, Pattern, Spaceable, Spaces, SpacesAfter, SpacesBefore, StrLiteral,
TypeAnnotation, TypeDef, TypeHeader, ValueDef,
ModuleImportParams, Pattern, PatternApplyStyle, Spaceable, Spaces, SpacesAfter, SpacesBefore,
StrLiteral, TypeAnnotation, TypeDef, TypeHeader, ValueDef,
};
use roc_parse::expr::merge_spaces;
use roc_parse::header::Keyword;
Expand Down Expand Up @@ -564,14 +564,21 @@ impl<'a> Formattable for TypeHeader<'a> {
_newlines: Newlines,
indent: u16,
) {
let old_flags = buf.flags;
buf.flags = MigrationFlags {
parens_and_commas: false,
..old_flags
};
pattern_fmt_apply(
buf,
Pattern::Tag(self.name.value),
self.vars,
Parens::NotNeeded,
indent,
self.vars.iter().any(|v| v.is_multiline()),
PatternApplyStyle::Whitespace,
);
buf.flags = old_flags;
}
}

Expand All @@ -582,6 +589,7 @@ fn type_head_lift_spaces<'a, 'b: 'a>(
let pat = Pattern::Apply(
arena.alloc(Loc::at(head.name.region, Pattern::Tag(head.name.value))),
head.vars,
PatternApplyStyle::Whitespace,
);

pattern_lift_spaces(arena, &pat)
Expand Down Expand Up @@ -903,7 +911,9 @@ impl<'a> Formattable for ValueDef<'a> {
fn ann_pattern_needs_parens(value: &Pattern<'_>) -> bool {
match value.extract_spaces().item {
Pattern::Tag(_) => true,
Pattern::Apply(func, _args) if matches!(func.extract_spaces().item, Pattern::Tag(..)) => {
Pattern::Apply(func, _args, _style)
if matches!(func.extract_spaces().item, Pattern::Tag(..)) =>
{
true
}
_ => false,
Expand Down
Loading

0 comments on commit 88a2579

Please sign in to comment.