Skip to content

Commit 3de2ca0

Browse files
committed
Merge remote-tracking branch 'origin/main' into import-syntax
2 parents 32210df + 551e627 commit 3de2ca0

File tree

79 files changed

+2169
-1041
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2169
-1041
lines changed

.github/workflows/ci_zig.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,20 @@ jobs:
144144
- name: zig snapshot tests
145145
run: zig build snapshot -- --debug
146146

147-
- name: build tests and repro executables
147+
- name: build and execute tests, build repro executables
148148
uses: ./.github/actions/flaky-retry
149149
with:
150150
command: 'zig build test -Dfuzz -Dsystem-afl=false'
151151
error_string_contains: 'double roundtrip bundle'
152152
retry_count: 3
153153

154+
- name: Build and execute tests, build repro executables. All in release mode.
155+
uses: ./.github/actions/flaky-retry
156+
with:
157+
command: 'zig build test -Doptimize=ReleaseFast -Dfuzz -Dsystem-afl=false'
158+
error_string_contains: 'double roundtrip bundle'
159+
retry_count: 3
160+
154161
- name: Check for snapshot changes
155162
run: |
156163
git diff --exit-code test/snapshots || {

.github/workflows/nightly_new_compiler_all_os.yml

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,58 @@ jobs:
7777
SHA: ${{ env.SHA }}
7878
run: echo "RELEASE_FOLDER_NAME=new_roc_nightly-${{ matrix.artifact_name }}-$DATE-$SHA" >> $GITHUB_ENV
7979

80-
- name: Package release (Unix)
80+
- name: Package release
8181
run: |
8282
mkdir -p ${{ env.RELEASE_FOLDER_NAME }}
8383
cp ./zig-out/bin/roc ${{ env.RELEASE_FOLDER_NAME }}/
8484
cp LICENSE legal_details ${{ env.RELEASE_FOLDER_NAME }}/
85-
tar -czvf "${{ env.RELEASE_FOLDER_NAME }}.tar.gz" ${{ env.RELEASE_FOLDER_NAME }}
8685
87-
- name: Calculate archive hash for security purposes
88-
shell: bash
86+
- name: Compress release (Unix)
87+
if: runner.os != 'Windows'
88+
run: tar -czvf "${{ env.RELEASE_FOLDER_NAME }}.tar.gz" ${{ env.RELEASE_FOLDER_NAME }}
89+
90+
- name: Compress release (Windows)
91+
if: runner.os == 'Windows'
92+
run: 7z a -tzip "${{ env.RELEASE_FOLDER_NAME }}.zip" ${{ env.RELEASE_FOLDER_NAME }}
93+
94+
- name: Calculate archive hash for security purposes (Unix)
95+
if: runner.os != 'Windows'
8996
run: sha256sum ${{ env.RELEASE_FOLDER_NAME }}.tar.gz
9097

91-
- name: Upload roc nightly tar
98+
- name: Calculate archive hash for security purposes (Windows)
99+
if: runner.os == 'Windows'
100+
run: sha256sum ${{ env.RELEASE_FOLDER_NAME }}.zip
101+
102+
- name: Upload roc nightly archive (Unix)
103+
if: runner.os != 'Windows'
92104
uses: actions/upload-artifact@v4
93105
with:
94106
name: ${{ env.RELEASE_FOLDER_NAME }}.tar.gz
95107
path: ${{ env.RELEASE_FOLDER_NAME }}.tar.gz
96108
retention-days: 4
109+
110+
- name: Upload roc nightly archive (Windows)
111+
if: runner.os == 'Windows'
112+
uses: actions/upload-artifact@v4
113+
with:
114+
name: ${{ env.RELEASE_FOLDER_NAME }}.zip
115+
path: ${{ env.RELEASE_FOLDER_NAME }}.zip
116+
retention-days: 4
117+
118+
- name: Clean workspace for test
119+
run: |
120+
find . -mindepth 1 -maxdepth 1 ! -name "${{ env.RELEASE_FOLDER_NAME }}.tar.gz" ! -name "${{ env.RELEASE_FOLDER_NAME }}.zip" ! -name "src" -exec rm -rf {} +
121+
find src -mindepth 1 ! -path "src/PROFILING*" -exec rm -rf {} +
122+
find src/PROFILING -mindepth 1 ! -name "bench_repeated_check.roc" -exec rm -rf {} +
123+
124+
- name: Test archive (Unix)
125+
if: runner.os != 'Windows'
126+
run: |
127+
tar -xzf "${{ env.RELEASE_FOLDER_NAME }}.tar.gz"
128+
./${{ env.RELEASE_FOLDER_NAME }}/roc check src/PROFILING/bench_repeated_check.roc
129+
130+
- name: Test archive (Windows)
131+
if: runner.os == 'Windows'
132+
run: |
133+
7z x "${{ env.RELEASE_FOLDER_NAME }}.zip"
134+
./${{ env.RELEASE_FOLDER_NAME }}/roc check src/PROFILING/bench_repeated_check.roc

build.zig

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -614,27 +614,28 @@ pub fn build(b: *std.Build) void {
614614
const ModuleTest = modules.ModuleTest;
615615

616616
fn discoverBuiltinRocFiles(b: *std.Build) ![]const []const u8 {
617-
var builtin_roc_dir = try std.fs.cwd().openDir("src/build/roc", .{ .iterate = true });
617+
const builtin_roc_path = try b.build_root.join(b.allocator, &.{ "src", "build", "roc" });
618+
var builtin_roc_dir = try std.fs.openDirAbsolute(builtin_roc_path, .{ .iterate = true });
618619
defer builtin_roc_dir.close();
619620

620-
var roc_files = std.array_list.Managed([]const u8).init(b.allocator);
621-
errdefer roc_files.deinit();
621+
var roc_files = std.ArrayList([]const u8).empty;
622+
errdefer roc_files.deinit(b.allocator);
622623

623624
var iter = builtin_roc_dir.iterate();
624625
while (try iter.next()) |entry| {
625626
if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".roc")) {
626627
const full_path = b.fmt("src/build/roc/{s}", .{entry.name});
627-
try roc_files.append(full_path);
628+
try roc_files.append(b.allocator, full_path);
628629
}
629630
}
630631

631-
return roc_files.toOwnedSlice();
632+
return roc_files.toOwnedSlice(b.allocator);
632633
}
633634

634635
fn generateCompiledBuiltinsSource(b: *std.Build, roc_files: []const []const u8) ![]const u8 {
635-
var builtins_source = std.array_list.Managed(u8).init(b.allocator);
636-
errdefer builtins_source.deinit();
637-
const writer = builtins_source.writer();
636+
var builtins_source = std.ArrayList(u8).empty;
637+
errdefer builtins_source.deinit(b.allocator);
638+
const writer = builtins_source.writer(b.allocator);
638639

639640
for (roc_files) |roc_path| {
640641
const roc_basename = std.fs.path.basename(roc_path);
@@ -651,7 +652,7 @@ fn generateCompiledBuiltinsSource(b: *std.Build, roc_files: []const []const u8)
651652
// Also embed builtin_indices.bin
652653
try writer.writeAll("pub const builtin_indices_bin = @embedFile(\"builtin_indices.bin\");\n");
653654

654-
return builtins_source.toOwnedSlice();
655+
return builtins_source.toOwnedSlice(b.allocator);
655656
}
656657

657658
fn add_fuzz_target(
@@ -748,7 +749,7 @@ fn addMainExe(
748749
.root_source_file = b.path("test/str/platform/host.zig"),
749750
.target = target,
750751
.optimize = optimize,
751-
.strip = true,
752+
.strip = optimize != .Debug,
752753
.pic = true, // Enable Position Independent Code for PIE compatibility
753754
}),
754755
});
@@ -772,7 +773,7 @@ fn addMainExe(
772773
.root_source_file = b.path("test/int/platform/host.zig"),
773774
.target = target,
774775
.optimize = optimize,
775-
.strip = true,
776+
.strip = optimize != .Debug,
776777
.pic = true, // Enable Position Independent Code for PIE compatibility
777778
}),
778779
});
@@ -805,7 +806,7 @@ fn addMainExe(
805806
.root_source_file = b.path("test/int/platform/host.zig"),
806807
.target = cross_resolved_target,
807808
.optimize = optimize,
808-
.strip = true,
809+
.strip = optimize != .Debug,
809810
.pic = true,
810811
}),
811812
.linkage = .static,
@@ -850,7 +851,7 @@ fn addMainExe(
850851
.root_source_file = b.path("src/interpreter_shim/main.zig"),
851852
.target = target,
852853
.optimize = optimize,
853-
.strip = true,
854+
.strip = optimize != .Debug,
854855
.pic = true, // Enable Position Independent Code for PIE compatibility
855856
}),
856857
.linkage = .static,
@@ -928,13 +929,13 @@ const ParsedBuildArgs = struct {
928929
};
929930

930931
fn appendFilter(
931-
list: *std.array_list.Managed([]const u8),
932+
list: *std.ArrayList([]const u8),
932933
b: *std.Build,
933934
value: []const u8,
934935
) void {
935936
const trimmed = std.mem.trim(u8, value, " \t\n\r");
936937
if (trimmed.len == 0) return;
937-
list.append(b.dupe(trimmed)) catch @panic("OOM while parsing --test-filter value");
938+
list.append(b.allocator, b.dupe(trimmed)) catch @panic("OOM while parsing --test-filter value");
938939
}
939940

940941
fn parseBuildArgs(b: *std.Build) ParsedBuildArgs {
@@ -943,8 +944,8 @@ fn parseBuildArgs(b: *std.Build) ParsedBuildArgs {
943944
.test_filters = &.{},
944945
};
945946

946-
var run_args_list = std.array_list.Managed([]const u8).init(b.allocator);
947-
var filter_list = std.array_list.Managed([]const u8).init(b.allocator);
947+
var run_args_list = std.ArrayList([]const u8).empty;
948+
var filter_list = std.ArrayList([]const u8).empty;
948949

949950
var i: usize = 0;
950951
while (i < raw_args.len) {
@@ -969,12 +970,12 @@ fn parseBuildArgs(b: *std.Build) ParsedBuildArgs {
969970
continue;
970971
}
971972

972-
run_args_list.append(arg) catch @panic("OOM while recording build arguments");
973+
run_args_list.append(b.allocator, arg) catch @panic("OOM while recording build arguments");
973974
i += 1;
974975
}
975976

976-
const run_args = run_args_list.toOwnedSlice() catch @panic("OOM while finalizing build arguments");
977-
const test_filters = filter_list.toOwnedSlice() catch @panic("OOM while finalizing test filters");
977+
const run_args = run_args_list.toOwnedSlice(b.allocator) catch @panic("OOM while finalizing build arguments");
978+
const test_filters = filter_list.toOwnedSlice(b.allocator) catch @panic("OOM while finalizing test filters");
978979

979980
return .{ .run_args = run_args, .test_filters = test_filters };
980981
}
@@ -1398,10 +1399,10 @@ fn getCompilerVersion(b: *std.Build, optimize: OptimizeMode) []const u8 {
13981399
fn generateGlibcStub(b: *std.Build, target: ResolvedTarget, target_name: []const u8) ?*Step.UpdateSourceFiles {
13991400

14001401
// Generate assembly stub with comprehensive symbols using the new build module
1401-
var assembly_buf = std.array_list.Managed(u8).init(b.allocator);
1402-
defer assembly_buf.deinit();
1402+
var assembly_buf = std.ArrayList(u8).empty;
1403+
defer assembly_buf.deinit(b.allocator);
14031404

1404-
const writer = assembly_buf.writer();
1405+
const writer = assembly_buf.writer(b.allocator);
14051406
const target_arch = target.result.cpu.arch;
14061407
const target_abi = target.result.abi;
14071408

crates/compiler/builtins/roc/Str.roc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
##
5050
## Interpolation can be used in multiline strings, but the part inside the parentheses must still be on one line.
5151
##
52+
## ### Import Str from File
53+
##
54+
## To avoid verbose code to read the contents of a file into a Str, you can import it directly:
55+
##
56+
## ```
57+
## import "some-file.txt" as some_str : Str
58+
## ```
59+
##
60+
## Note: The file content is included in the Roc app executable, if you publish the executable, you do not need to provide the file alongside it.
61+
##
5262
## ### Escapes
5363
##
5464
## There are a few special escape sequences in strings:

src/base/Ident.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,13 +602,13 @@ test "Ident.Store comprehensive CompactWriter roundtrip" {
602602
.{ .text = "hello", .expected_idx = 1 }, // duplicate, should reuse
603603
};
604604

605-
var indices = std.array_list.Managed(Ident.Idx).init(gpa);
606-
defer indices.deinit();
605+
var indices = std.ArrayList(Ident.Idx).empty;
606+
defer indices.deinit(gpa);
607607

608608
for (test_idents) |test_ident| {
609609
const ident = Ident.for_text(test_ident.text);
610610
const idx = try original.insert(gpa, ident);
611-
try indices.append(idx);
611+
try indices.append(gpa, idx);
612612
// Verify the index matches expectation
613613
try std.testing.expectEqual(test_ident.expected_idx, idx.idx);
614614
}

src/base/Scratch.zig

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@ pub fn Scratch(comptime T: type) type {
2424
}
2525

2626
/// Returns the start position for a new Span of indexes in scratch
27-
pub fn top(self: *Self) u32 {
27+
pub fn top(self: *const Self) u32 {
2828
return @as(u32, @intCast(self.items.items.len));
2929
}
3030

31+
/// Check if a value is in the array
32+
pub fn contains(self: *const Self, val: T) bool {
33+
for (self.items.items) |item| {
34+
if (item == val) {
35+
return true;
36+
}
37+
}
38+
return false;
39+
}
40+
3141
/// Places a new index of type `T` in the scratch
3242
pub fn append(self: *Self, idx: T) std.mem.Allocator.Error!void {
3343
try self.items.append(idx);
@@ -48,6 +58,25 @@ pub fn Scratch(comptime T: type) type {
4858
return self.items.items[@intCast(start)..];
4959
}
5060

61+
/// Creates slice from the provided start index
62+
pub fn sliceFromSpan(self: *Self, span: DataSpan) []T {
63+
const start: usize = @intCast(span.start);
64+
const end: usize = @intCast(span.start + span.len);
65+
66+
std.debug.assert(start <= end);
67+
std.debug.assert(end <= self.items.items.len);
68+
69+
return self.items.items[start..end];
70+
}
71+
72+
/// Creates span from the provided start index to the end of the list
73+
pub fn spanFrom(self: *Self, start: u32) DataSpan {
74+
return DataSpan{
75+
.start = start,
76+
.len = @as(u32, @intCast(self.items.items.len)) - start,
77+
};
78+
}
79+
5180
/// Creates a new span starting at start. Moves the items from scratch
5281
/// to extra_data as appropriate.
5382
pub fn spanFromStart(self: *Self, start: u32, data: *std.array_list.Managed(u32)) std.mem.Allocator.Error!DataSpan {

src/base/SmallStringInterner.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@ test "SmallStringInterner basic CompactWriter roundtrip" {
305305
"duplicate", // Should reuse the same index
306306
};
307307

308-
var indices = std.array_list.Managed(SmallStringInterner.Idx).init(gpa);
309-
defer indices.deinit();
308+
var indices = std.ArrayList(SmallStringInterner.Idx).empty;
309+
defer indices.deinit(gpa);
310310

311311
for (test_strings) |str| {
312312
const idx = try original.insert(gpa, str);
313-
try indices.append(idx);
313+
try indices.append(gpa, idx);
314314
}
315315

316316
// Verify duplicate detection worked
@@ -507,12 +507,12 @@ test "SmallStringInterner edge cases CompactWriter roundtrip" {
507507
" start_with_space",
508508
};
509509

510-
var indices = std.array_list.Managed(SmallStringInterner.Idx).init(gpa);
511-
defer indices.deinit();
510+
var indices = std.ArrayList(SmallStringInterner.Idx).empty;
511+
defer indices.deinit(gpa);
512512

513513
for (edge_cases) |str| {
514514
const idx = try original.insert(gpa, str);
515-
try indices.append(idx);
515+
try indices.append(gpa, idx);
516516
}
517517

518518
// Create a temp file

src/base/StringLiteral.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ test "Store comprehensive CompactWriter roundtrip" {
257257
"very long string " ** 50, // long string
258258
};
259259

260-
var indices = std.array_list.Managed(Idx).init(gpa);
261-
defer indices.deinit();
260+
var indices = std.ArrayList(Idx).empty;
261+
defer indices.deinit(gpa);
262262

263263
for (test_strings) |str| {
264264
const idx = try original.insert(gpa, str);
265-
try indices.append(idx);
265+
try indices.append(gpa, idx);
266266
}
267267

268268
// Create a temp file

src/build/builtin_compiler/main.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ fn compileModule(
236236

237237
// 6. Type check
238238
// Build the list of other modules for type checking
239-
var imported_envs = std.array_list.Managed(*const ModuleEnv).init(gpa);
240-
defer imported_envs.deinit();
239+
var imported_envs = std.ArrayList(*const ModuleEnv).empty;
240+
defer imported_envs.deinit(gpa);
241241

242242
// Add dependencies
243243
for (deps) |dep| {
244-
try imported_envs.append(dep.env);
244+
try imported_envs.append(gpa, dep.env);
245245
}
246246

247247
var checker = try Check.init(

src/build/modules.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ fn extendWithAggregatorFilters(
4141
const extras = aggregatorFilters(module_type);
4242
if (extras.len == 0) return base;
4343

44-
var list = std.array_list.Managed([]const u8).init(b.allocator);
45-
list.ensureTotalCapacity(base.len + extras.len) catch @panic("OOM while extending module test filters");
46-
list.appendSlice(base) catch @panic("OOM while extending module test filters");
44+
var list = std.ArrayList([]const u8).empty;
45+
list.ensureTotalCapacity(b.allocator, base.len + extras.len) catch @panic("OOM while extending module test filters");
46+
list.appendSlice(b.allocator, base) catch @panic("OOM while extending module test filters");
4747

4848
for (extras) |extra| {
4949
if (filtersContain(base, extra)) continue;
50-
list.append(b.dupe(extra)) catch @panic("OOM while extending module test filters");
50+
list.append(b.allocator, b.dupe(extra)) catch @panic("OOM while extending module test filters");
5151
}
5252

53-
return list.toOwnedSlice() catch @panic("OOM while finalizing module test filters");
53+
return list.toOwnedSlice(b.allocator) catch @panic("OOM while finalizing module test filters");
5454
}
5555

5656
/// Represents a test module with its compilation and execution steps.

0 commit comments

Comments
 (0)