Skip to content

Commit 4b3593a

Browse files
committed
Merge remote-tracking branch 'origin/main' into roc-build-default-app
# Conflicts: # src/lir/lir_image.zig
2 parents 32c0eca + e15fff1 commit 4b3593a

33 files changed

Lines changed: 4382 additions & 90 deletions

.github/workflows/ci_zig_nix.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
- uses: cachix/install-nix-action@02a151ada4993995686f9ed4f1be7cfbb229e56f # ratchet:cachix/install-nix-action@v31
3434
with:
3535
nix_path: nixpkgs=channel:nixos-25.05
36+
extra_nix_config: |
37+
min-free = 1073741824
38+
max-free = 5368709120
39+
# When free space drops below min-free (1 GB), nix GCs until max-free (5 GB) is available. This avoids "No space left on device" on CI.
3640
3741
- name: Build inside a nix dev shell
3842
uses: ./.github/actions/flaky-retry

build.zig

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,6 +3831,51 @@ pub fn build(b: *std.Build) void {
38313831
);
38323832
run_lir_inline_test_step.dependOn(&run_lir_inline_test.step);
38333833

3834+
const trmc_lir_test = b.addTest(.{
3835+
.name = "trmc_lir_test",
3836+
.root_module = b.createModule(.{
3837+
.root_source_file = b.path("src/eval/test/trmc_lir_test.zig"),
3838+
.target = target,
3839+
.optimize = optimize,
3840+
.link_libc = true,
3841+
}),
3842+
.filters = test_filters,
3843+
});
3844+
roc_modules.addAll(trmc_lir_test);
3845+
trmc_lir_test.root_module.addImport("compiled_builtins", compiled_builtins_module);
3846+
trmc_lir_test.step.dependOn(&write_compiled_builtins.step);
3847+
try addLlvmSupportToStep(
3848+
b,
3849+
trmc_lir_test,
3850+
target,
3851+
use_system_llvm,
3852+
user_llvm_path,
3853+
roc_modules,
3854+
llvm_codegen_module,
3855+
llvm_embedded_module,
3856+
zstd,
3857+
);
3858+
if (trmc_lir_test.root_module.resolved_target.?.result.os.tag != .windows or
3859+
trmc_lir_test.root_module.resolved_target.?.result.abi != .msvc)
3860+
{
3861+
trmc_lir_test.root_module.link_libcpp = true;
3862+
}
3863+
add_tracy(b, roc_modules.build_options, trmc_lir_test, target, true, flag_enable_tracy);
3864+
build_test_zig_step.dependOn(&trmc_lir_test.step);
3865+
3866+
const run_trmc_lir_test = b.addRunArtifact(trmc_lir_test);
3867+
if (run_args.len != 0) {
3868+
run_trmc_lir_test.addArgs(run_args);
3869+
}
3870+
3871+
tests_summary.addRun(&run_trmc_lir_test.step);
3872+
3873+
const run_trmc_lir_test_step = b.step(
3874+
"run-test-zig-trmc-lir",
3875+
"Run TRMC LIR Zig tests",
3876+
);
3877+
run_trmc_lir_test_step.dependOn(&run_trmc_lir_test.step);
3878+
38343879
// Add CLI test
38353880
const enable_cli_tests = b.option(bool, "cli-tests", "Enable cli tests") orelse true;
38363881
if (enable_cli_tests) {

design.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,12 +2740,11 @@ that value kind must be added explicitly here with a checked cache rule.
27402740
- function values
27412741

27422742
Compile-time evaluation failures are owned by checking finalization because the
2743-
module has not been output yet. User-written compile-time crashes, exhausted
2744-
compile-time limits, invalid compile-time host interaction, and unsupported
2745-
compile-time operations become checking diagnostics attached to the checked root
2746-
being finalized. OOM remains OOM. A post-check invariant failure while lowering
2747-
or interpreting a compile-time root is still a compiler bug, not a user-facing
2748-
diagnostic.
2743+
module has not been output yet. User-written compile-time crashes, invalid
2744+
compile-time host interaction, and unsupported compile-time operations become
2745+
checking diagnostics attached to the checked root being finalized. OOM remains
2746+
OOM. A post-check invariant failure while lowering or interpreting a
2747+
compile-time root is still a compiler bug, not a user-facing diagnostic.
27492748

27502749
While storing an eval result, the builder may reserve a `ConstNodeId` before
27512750
storing its children so repeated references to the same acyclic runtime value

docs/langref/iterators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Iterators

docs/langref/loops.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,37 @@ Loops let you run the same code multiple times, in...well, in a loop.
44

55
## `for` Loops
66

7-
A `for` loop iterates over each item in a list:
7+
A `for` loop lets you run code on each item in an [iterator](iterators). For example:
88

99
```roc
1010
var $sum = 0
11+
12+
for n in 1.to(5) {
13+
$sum = $sum + n
14+
}
15+
```
16+
17+
> The `to` method returns a [range](numbers#ranges) which is an `Iter` of the number in question. For example, [`I64.to`](builtins/I64#to) returns `Iter(I64)`, and so `n` in this example would be an `I64`.
18+
19+
A loop body only includes statements; it does not have a final expression. The loop itself evaluates to `{}`.
20+
21+
### Iterating over types that have `iter`
22+
23+
`for` can also be used on types that have an `iter` method, as long as that method returns an [`Iter`](builtins/Iter). For example, [`List`](builtins/list) has (`List.iter`)[builtins/List#iter], so you can do a `for` loop over a list:
24+
25+
```roc
26+
var $sum = 0
27+
1128
for n in [1, 2, 3, 4] {
1229
$sum = $sum + n
1330
}
1431
```
1532

16-
The item can be destructured inline:
33+
At runtime, this `[1, 2, 3, 4]` code snippet is exactly as efficient as the earlier `1.to(5)` one. In one case, `1.to(5)` will be evaluated to an `Iter` at compile time, and in the other, `[1, 2, 3, 4].iter()` will be evaluated at compile time to an identical `Iter`. By the time either program actually runs, they will have the same memory contents and will be executing the same instructions.
34+
35+
### Pattern matching in `for`
36+
37+
Whatever you put between `for` and `in` is treated as a [pattern](pattern-matching), meaning (for example) that the item can be destructured inline:
1738

1839
```roc
1940
var $total = 0
@@ -22,7 +43,7 @@ for (x, y) in [(1, 2), (3, 4), (5, 6)] {
2243
}
2344
```
2445

25-
Use `_` if you don't want to name the item:
46+
As usual, you can nest patterns as much as you like, and can use `_` if you don't want to name a pattern:
2647

2748
```roc
2849
var $count = 0
@@ -31,7 +52,16 @@ for _ in items {
3152
}
3253
```
3354

34-
A loop body only includes statements; it does not have a final expression. The loop itself evaluates to `{}`.
55+
Just like with [assignments](statements#assignments), the pattern you use here must be [exhaustive](pattern-matching#exhaustiveness). For example, the following would give an exhaustiveness error because the loop body couldn't know what value to use for `amount_to_add` if the item was ever `Err` at runtime:
56+
57+
```roc
58+
var $count = 0
59+
for Ok(amount_to_add) in items {
60+
$count = $count + amount_to_add
61+
}
62+
```
63+
64+
If you can't write an exhaustive pattern-match, you can name the entire iterator item and then use [`match`](pattern-matching#match) on it inside the loop body.
3565

3666
## `while` Loops
3767

0 commit comments

Comments
 (0)