| ... | @@ -21,12 +21,11 @@ test "compile errors" { | ... | @@ -21,12 +21,11 @@ test "compile errors" { |
| 21 | } | 21 | } |
| 22 | | 22 | |
| 23 | const file1 = "1.zig"; | 23 | const file1 = "1.zig"; |
| | 24 | const allocator = std.heap.c_allocator; |
| 24 | | 25 | |
| 25 | const TestContext = struct { | 26 | const TestContext = struct { |
| 26 | loop: std.event.Loop, | 27 | loop: std.event.Loop, |
| 27 | zig_lib_dir: []u8, | 28 | zig_lib_dir: []u8, |
| 28 | direct_allocator: std.heap.DirectAllocator, | | |
| 29 | arena: std.heap.ArenaAllocator, | | |
| 30 | zig_cache_dir: []u8, | 29 | zig_cache_dir: []u8, |
| 31 | file_index: std.atomic.Int(usize), | 30 | file_index: std.atomic.Int(usize), |
| 32 | group: std.event.Group(error!void), | 31 | group: std.event.Group(error!void), |
| ... | @@ -37,8 +36,6 @@ const TestContext = struct { | ... | @@ -37,8 +36,6 @@ const TestContext = struct { |
| 37 | fn init(self: *TestContext) !void { | 36 | fn init(self: *TestContext) !void { |
| 38 | self.* = TestContext{ | 37 | self.* = TestContext{ |
| 39 | .any_err = {}, | 38 | .any_err = {}, |
| 40 | .direct_allocator = undefined, | | |
| 41 | .arena = undefined, | | |
| 42 | .loop = undefined, | 39 | .loop = undefined, |
| 43 | .zig_lib_dir = undefined, | 40 | .zig_lib_dir = undefined, |
| 44 | .zig_cache_dir = undefined, | 41 | .zig_cache_dir = undefined, |
| ... | @@ -46,36 +43,27 @@ const TestContext = struct { | ... | @@ -46,36 +43,27 @@ const TestContext = struct { |
| 46 | .file_index = std.atomic.Int(usize).init(0), | 43 | .file_index = std.atomic.Int(usize).init(0), |
| 47 | }; | 44 | }; |
| 48 | | 45 | |
| 49 | self.direct_allocator = std.heap.DirectAllocator.init(); | 46 | try self.loop.initMultiThreaded(allocator); |
| 50 | errdefer self.direct_allocator.deinit(); | | |
| 51 | | | |
| 52 | self.arena = std.heap.ArenaAllocator.init(&self.direct_allocator.allocator); | | |
| 53 | errdefer self.arena.deinit(); | | |
| 54 | | | |
| 55 | // TODO faster allocator for coroutines that is thread-safe/lock-free | | |
| 56 | try self.loop.initMultiThreaded(&self.direct_allocator.allocator); | | |
| 57 | errdefer self.loop.deinit(); | 47 | errdefer self.loop.deinit(); |
| 58 | | 48 | |
| 59 | self.group = std.event.Group(error!void).init(&self.loop); | 49 | self.group = std.event.Group(error!void).init(&self.loop); |
| 60 | errdefer self.group.cancelAll(); | 50 | errdefer self.group.cancelAll(); |
| 61 | | 51 | |
| 62 | self.zig_lib_dir = try introspect.resolveZigLibDir(&self.arena.allocator); | 52 | self.zig_lib_dir = try introspect.resolveZigLibDir(allocator); |
| 63 | errdefer self.arena.allocator.free(self.zig_lib_dir); | 53 | errdefer allocator.free(self.zig_lib_dir); |
| 64 | | 54 | |
| 65 | self.zig_cache_dir = try introspect.resolveZigCacheDir(&self.arena.allocator); | 55 | self.zig_cache_dir = try introspect.resolveZigCacheDir(allocator); |
| 66 | errdefer self.arena.allocator.free(self.zig_cache_dir); | 56 | errdefer allocator.free(self.zig_cache_dir); |
| 67 | | 57 | |
| 68 | try std.os.makePath(&self.arena.allocator, tmp_dir_name); | 58 | try std.os.makePath(allocator, tmp_dir_name); |
| 69 | errdefer std.os.deleteTree(&self.arena.allocator, tmp_dir_name) catch {}; | 59 | errdefer std.os.deleteTree(allocator, tmp_dir_name) catch {}; |
| 70 | } | 60 | } |
| 71 | | 61 | |
| 72 | fn deinit(self: *TestContext) void { | 62 | fn deinit(self: *TestContext) void { |
| 73 | std.os.deleteTree(&self.arena.allocator, tmp_dir_name) catch {}; | 63 | std.os.deleteTree(allocator, tmp_dir_name) catch {}; |
| 74 | self.arena.allocator.free(self.zig_cache_dir); | 64 | allocator.free(self.zig_cache_dir); |
| 75 | self.arena.allocator.free(self.zig_lib_dir); | 65 | allocator.free(self.zig_lib_dir); |
| 76 | self.loop.deinit(); | 66 | self.loop.deinit(); |
| 77 | self.arena.deinit(); | | |
| 78 | self.direct_allocator.deinit(); | | |
| 79 | } | 67 | } |
| 80 | | 68 | |
| 81 | fn run(self: *TestContext) !void { | 69 | fn run(self: *TestContext) !void { |
| ... | @@ -99,14 +87,14 @@ const TestContext = struct { | ... | @@ -99,14 +87,14 @@ const TestContext = struct { |
| 99 | ) !void { | 87 | ) !void { |
| 100 | var file_index_buf: [20]u8 = undefined; | 88 | var file_index_buf: [20]u8 = undefined; |
| 101 | const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.next()); | 89 | const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.next()); |
| 102 | const file1_path = try std.os.path.join(&self.arena.allocator, tmp_dir_name, file_index, file1); | 90 | const file1_path = try std.os.path.join(allocator, tmp_dir_name, file_index, file1); |
| 103 | | 91 | |
| 104 | if (std.os.path.dirname(file1_path)) |dirname| { | 92 | if (std.os.path.dirname(file1_path)) |dirname| { |
| 105 | try std.os.makePath(&self.arena.allocator, dirname); | 93 | try std.os.makePath(allocator, dirname); |
| 106 | } | 94 | } |
| 107 | | 95 | |
| 108 | // TODO async I/O | 96 | // TODO async I/O |
| 109 | try std.io.writeFile(&self.arena.allocator, file1_path, source); | 97 | try std.io.writeFile(allocator, file1_path, source); |
| 110 | | 98 | |
| 111 | var module = try Module.create( | 99 | var module = try Module.create( |
| 112 | &self.loop, | 100 | &self.loop, |