| author | |
| committer | |
| log | 128034481ab6eb02da4114b4d49ec3cfd4f8451c |
| tree | 3c17b89ab0d8418f2f3005af73f838d12ac4037c |
| parent | 36849d8a7b5b0ed62d966ea9c402f192ade0cadf |
| signature |
8 files changed, 75 insertions(+), 54 deletions(-)
lib/std/event/fs.zig+14-12| ... | ... | @@ -735,24 +735,26 @@ pub fn Watch(comptime V: type) type { |
| 735 | 735 | allocator: *Allocator, |
| 736 | 736 | |
| 737 | 737 | const OsData = switch (builtin.os) { |
| 738 | .macosx, .freebsd, .netbsd, .dragonfly => struct { | |
| 739 | file_table: FileTable, | |
| 740 | table_lock: event.Lock, | |
| 741 | ||
| 742 | const FileTable = std.StringHashMap(*Put); | |
| 743 | const Put = struct { | |
| 744 | putter_frame: @Frame(kqPutEvents), | |
| 745 | cancelled: bool = false, | |
| 746 | value: V, | |
| 747 | }; | |
| 748 | }, | |
| 749 | ||
| 738 | // TODO https://github.com/ziglang/zig/issues/3778 | |
| 739 | .macosx, .freebsd, .netbsd, .dragonfly => KqOsData, | |
| 750 | 740 | .linux => LinuxOsData, |
| 751 | 741 | .windows => WindowsOsData, |
| 752 | 742 | |
| 753 | 743 | else => @compileError("Unsupported OS"), |
| 754 | 744 | }; |
| 755 | 745 | |
| 746 | const KqOsData = struct { | |
| 747 | file_table: FileTable, | |
| 748 | table_lock: event.Lock, | |
| 749 | ||
| 750 | const FileTable = std.StringHashMap(*Put); | |
| 751 | const Put = struct { | |
| 752 | putter_frame: @Frame(kqPutEvents), | |
| 753 | cancelled: bool = false, | |
| 754 | value: V, | |
| 755 | }; | |
| 756 | }; | |
| 757 | ||
| 756 | 758 | const WindowsOsData = struct { |
| 757 | 759 | table_lock: event.Lock, |
| 758 | 760 | dir_table: DirTable, |
src-self-hosted/compilation.zig+32-20| ... | ... | @@ -133,7 +133,7 @@ pub const Compilation = struct { |
| 133 | 133 | zig_std_dir: []const u8, |
| 134 | 134 | |
| 135 | 135 | /// lazily created when we need it |
| 136 | tmp_dir: event.Future(BuildError![]u8), | |
| 136 | tmp_dir: event.Future(BuildError![]u8) = event.Future(BuildError![]u8).init(), | |
| 137 | 137 | |
| 138 | 138 | version_major: u32 = 0, |
| 139 | 139 | version_minor: u32 = 0, |
| ... | ... | @@ -158,7 +158,7 @@ pub const Compilation = struct { |
| 158 | 158 | |
| 159 | 159 | /// functions that have their own objects that we need to link |
| 160 | 160 | /// it uses an optional pointer so that tombstone removals are possible |
| 161 | fn_link_set: event.Locked(FnLinkSet), | |
| 161 | fn_link_set: event.Locked(FnLinkSet) = event.Locked(FnLinkSet).init(FnLinkSet.init()), | |
| 162 | 162 | |
| 163 | 163 | pub const FnLinkSet = std.TailQueue(?*Value.Fn); |
| 164 | 164 | |
| ... | ... | @@ -227,9 +227,9 @@ pub const Compilation = struct { |
| 227 | 227 | /// need to wait on this group before deinitializing |
| 228 | 228 | deinit_group: event.Group(void), |
| 229 | 229 | |
| 230 | // destroy_frame: @Frame(createAsync), | |
| 231 | // main_loop_frame: @Frame(Compilation.mainLoop), | |
| 232 | main_loop_future: event.Future(void), | |
| 230 | destroy_frame: *@Frame(createAsync), | |
| 231 | main_loop_frame: *@Frame(Compilation.mainLoop), | |
| 232 | main_loop_future: event.Future(void) = event.Future(void).init(), | |
| 233 | 233 | |
| 234 | 234 | have_err_ret_tracing: bool = false, |
| 235 | 235 | |
| ... | ... | @@ -245,6 +245,8 @@ pub const Compilation = struct { |
| 245 | 245 | |
| 246 | 246 | fs_watch: *fs.Watch(*Scope.Root), |
| 247 | 247 | |
| 248 | cancelled: bool = false, | |
| 249 | ||
| 248 | 250 | const IntTypeTable = std.HashMap(*const Type.Int.Key, *Type.Int, Type.Int.Key.hash, Type.Int.Key.eql); |
| 249 | 251 | const ArrayTypeTable = std.HashMap(*const Type.Array.Key, *Type.Array, Type.Array.Key.hash, Type.Array.Key.eql); |
| 250 | 252 | const PtrTypeTable = std.HashMap(*const Type.Pointer.Key, *Type.Pointer, Type.Pointer.Key.hash, Type.Pointer.Key.eql); |
| ... | ... | @@ -348,7 +350,9 @@ pub const Compilation = struct { |
| 348 | 350 | zig_lib_dir: []const u8, |
| 349 | 351 | ) !*Compilation { |
| 350 | 352 | var optional_comp: ?*Compilation = null; |
| 351 | var frame = async createAsync( | |
| 353 | var frame = try zig_compiler.allocator.create(@Frame(createAsync)); | |
| 354 | errdefer zig_compiler.allocator.destroy(frame); | |
| 355 | frame.* = async createAsync( | |
| 352 | 356 | &optional_comp, |
| 353 | 357 | zig_compiler, |
| 354 | 358 | name, |
| ... | ... | @@ -385,15 +389,12 @@ pub const Compilation = struct { |
| 385 | 389 | .build_mode = build_mode, |
| 386 | 390 | .zig_lib_dir = zig_lib_dir, |
| 387 | 391 | .zig_std_dir = undefined, |
| 388 | .tmp_dir = event.Future(BuildError![]u8).init(), | |
| 389 | // .destroy_frame = @frame(), | |
| 390 | // .main_loop_frame = undefined, | |
| 391 | .main_loop_future = event.Future(void).init(), | |
| 392 | .destroy_frame = @frame(), | |
| 393 | .main_loop_frame = undefined, | |
| 392 | 394 | |
| 393 | 395 | .name = undefined, |
| 394 | 396 | .llvm_triple = undefined, |
| 395 | 397 | .is_static = is_static, |
| 396 | .fn_link_set = event.Locked(FnLinkSet).init(FnLinkSet.init()), | |
| 397 | 398 | .link_libs_list = undefined, |
| 398 | 399 | |
| 399 | 400 | .exported_symbol_names = event.Locked(Decl.Table).init(Decl.Table.init(allocator)), |
| ... | ... | @@ -505,7 +506,10 @@ pub const Compilation = struct { |
| 505 | 506 | try comp.initTypes(); |
| 506 | 507 | defer comp.primitive_type_table.deinit(); |
| 507 | 508 | |
| 508 | // comp.main_loop_frame = async comp.mainLoop(); | |
| 509 | comp.main_loop_frame = try allocator.create(@Frame(mainLoop)); | |
| 510 | defer allocator.destroy(comp.main_loop_frame); | |
| 511 | ||
| 512 | comp.main_loop_frame.* = async comp.mainLoop(); | |
| 509 | 513 | // Set this to indicate that initialization completed successfully. |
| 510 | 514 | // from here on out we must not return an error. |
| 511 | 515 | // This must occur before the first suspend/await. |
| ... | ... | @@ -718,8 +722,11 @@ pub const Compilation = struct { |
| 718 | 722 | } |
| 719 | 723 | |
| 720 | 724 | pub fn destroy(self: *Compilation) void { |
| 721 | // await self.main_loop_frame; | |
| 722 | // resume self.destroy_frame; | |
| 725 | const allocator = self.gpa(); | |
| 726 | self.cancelled = true; | |
| 727 | await self.main_loop_frame; | |
| 728 | resume self.destroy_frame; | |
| 729 | allocator.destroy(self.destroy_frame); | |
| 723 | 730 | } |
| 724 | 731 | |
| 725 | 732 | fn start(self: *Compilation) void { |
| ... | ... | @@ -732,7 +739,7 @@ pub const Compilation = struct { |
| 732 | 739 | |
| 733 | 740 | var build_result = self.initialCompile(); |
| 734 | 741 | |
| 735 | while (true) { | |
| 742 | while (!self.cancelled) { | |
| 736 | 743 | const link_result = if (build_result) blk: { |
| 737 | 744 | break :blk self.maybeLink(); |
| 738 | 745 | } else |err| err; |
| ... | ... | @@ -1130,11 +1137,10 @@ pub const Compilation = struct { |
| 1130 | 1137 | return link_lib; |
| 1131 | 1138 | } |
| 1132 | 1139 | |
| 1133 | /// cancels itself so no need to await or cancel the promise. | |
| 1134 | 1140 | async fn startFindingNativeLibC(self: *Compilation) void { |
| 1135 | std.event.Loop.instance.?.yield(); | |
| 1141 | event.Loop.startCpuBoundOperation(); | |
| 1136 | 1142 | // we don't care if it fails, we're just trying to kick off the future resolution |
| 1137 | _ = (self.zig_compiler.getNativeLibC()) catch return; | |
| 1143 | _ = self.zig_compiler.getNativeLibC() catch return; | |
| 1138 | 1144 | } |
| 1139 | 1145 | |
| 1140 | 1146 | /// General Purpose Allocator. Must free when done. |
| ... | ... | @@ -1215,7 +1221,10 @@ pub const Compilation = struct { |
| 1215 | 1221 | node: *ast.Node, |
| 1216 | 1222 | expected_type: *Type, |
| 1217 | 1223 | ) !*Value { |
| 1218 | const analyzed_code = try comp.genAndAnalyzeCode(tree_scope, scope, node, expected_type); | |
| 1224 | var frame = try comp.gpa().create(@Frame(genAndAnalyzeCode)); | |
| 1225 | defer comp.gpa().destroy(frame); | |
| 1226 | frame.* = async comp.genAndAnalyzeCode(tree_scope, scope, node, expected_type); | |
| 1227 | const analyzed_code = try await frame; | |
| 1219 | 1228 | defer analyzed_code.destroy(comp.gpa()); |
| 1220 | 1229 | |
| 1221 | 1230 | return analyzed_code.getCompTimeResult(comp); |
| ... | ... | @@ -1315,12 +1324,15 @@ fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void { |
| 1315 | 1324 | try fn_type.non_key.Normal.variable_list.append(var_scope); |
| 1316 | 1325 | } |
| 1317 | 1326 | |
| 1318 | const analyzed_code = try comp.genAndAnalyzeCode( | |
| 1327 | var frame = try comp.gpa().create(@Frame(Compilation.genAndAnalyzeCode)); | |
| 1328 | defer comp.gpa().destroy(frame); | |
| 1329 | frame.* = async comp.genAndAnalyzeCode( | |
| 1319 | 1330 | tree_scope, |
| 1320 | 1331 | fn_val.child_scope, |
| 1321 | 1332 | body_node, |
| 1322 | 1333 | fn_type.key.data.Normal.return_type, |
| 1323 | 1334 | ); |
| 1335 | const analyzed_code = try await frame; | |
| 1324 | 1336 | errdefer analyzed_code.destroy(comp.gpa()); |
| 1325 | 1337 | |
| 1326 | 1338 | assert(fn_val.block_scope != null); |
src-self-hosted/ir.zig+16-9| ... | ... | @@ -658,7 +658,7 @@ pub const Inst = struct { |
| 658 | 658 | const amt = try align_inst.getAsConstAlign(ira); |
| 659 | 659 | break :blk Type.Pointer.Align{ .Override = amt }; |
| 660 | 660 | } else blk: { |
| 661 | break :blk Type.Pointer.Align{ .Abi = {} }; | |
| 661 | break :blk .Abi; | |
| 662 | 662 | }; |
| 663 | 663 | const ptr_type = try Type.Pointer.get(ira.irb.comp, Type.Pointer.Key{ |
| 664 | 664 | .child_type = child_type, |
| ... | ... | @@ -1078,6 +1078,14 @@ pub const Builder = struct { |
| 1078 | 1078 | self.current_basic_block = basic_block; |
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | pub fn genNodeRecursive(irb: *Builder, node: *ast.Node, scope: *Scope, lval: LVal) Error!*Inst { | |
| 1082 | const alloc = irb.comp.gpa(); | |
| 1083 | var frame = try alloc.create(@Frame(genNode)); | |
| 1084 | defer alloc.destroy(frame); | |
| 1085 | frame.* = async irb.genNode(node, scope, lval); | |
| 1086 | return await frame; | |
| 1087 | } | |
| 1088 | ||
| 1081 | 1089 | pub async fn genNode(irb: *Builder, node: *ast.Node, scope: *Scope, lval: LVal) Error!*Inst { |
| 1082 | 1090 | switch (node.id) { |
| 1083 | 1091 | .Root => unreachable, |
| ... | ... | @@ -1157,7 +1165,7 @@ pub const Builder = struct { |
| 1157 | 1165 | }, |
| 1158 | 1166 | .GroupedExpression => { |
| 1159 | 1167 | const grouped_expr = @fieldParentPtr(ast.Node.GroupedExpression, "base", node); |
| 1160 | return irb.genNode(grouped_expr.expr, scope, lval); | |
| 1168 | return irb.genNodeRecursive(grouped_expr.expr, scope, lval); | |
| 1161 | 1169 | }, |
| 1162 | 1170 | .BuiltinCall => return error.Unimplemented, |
| 1163 | 1171 | .ErrorSetDecl => return error.Unimplemented, |
| ... | ... | @@ -1187,14 +1195,13 @@ pub const Builder = struct { |
| 1187 | 1195 | } |
| 1188 | 1196 | |
| 1189 | 1197 | fn genCall(irb: *Builder, suffix_op: *ast.Node.SuffixOp, call: *ast.Node.SuffixOp.Op.Call, scope: *Scope) !*Inst { |
| 1190 | async fn genCall(irb: *Builder, suffix_op: *ast.Node.SuffixOp, call: *ast.Node.SuffixOp.Op.Call, scope: *Scope) !*Inst { | |
| 1191 | const fn_ref = try irb.genNode(suffix_op.lhs, scope, .None); | |
| 1198 | const fn_ref = try irb.genNodeRecursive(suffix_op.lhs.node, scope, .None); | |
| 1192 | 1199 | |
| 1193 | 1200 | const args = try irb.arena().alloc(*Inst, call.params.len); |
| 1194 | 1201 | var it = call.params.iterator(0); |
| 1195 | 1202 | var i: usize = 0; |
| 1196 | 1203 | while (it.next()) |arg_node_ptr| : (i += 1) { |
| 1197 | args[i] = try irb.genNode(arg_node_ptr.*, scope, .None); | |
| 1204 | args[i] = try irb.genNodeRecursive(arg_node_ptr.*, scope, .None); | |
| 1198 | 1205 | } |
| 1199 | 1206 | |
| 1200 | 1207 | //bool is_async = node->data.fn_call_expr.is_async; |
| ... | ... | @@ -1239,7 +1246,7 @@ pub const Builder = struct { |
| 1239 | 1246 | //} else { |
| 1240 | 1247 | // align_value = nullptr; |
| 1241 | 1248 | //} |
| 1242 | const child_type = try irb.genNode(prefix_op.rhs, scope, .None); | |
| 1249 | const child_type = try irb.genNodeRecursive(prefix_op.rhs, scope, .None); | |
| 1243 | 1250 | |
| 1244 | 1251 | //uint32_t bit_offset_start = 0; |
| 1245 | 1252 | //if (node->data.pointer_type.bit_offset_start != nullptr) { |
| ... | ... | @@ -1438,7 +1445,7 @@ pub const Builder = struct { |
| 1438 | 1445 | child_scope = &defer_child_scope.base; |
| 1439 | 1446 | continue; |
| 1440 | 1447 | } |
| 1441 | const statement_value = try irb.genNode(statement_node, child_scope, .None); | |
| 1448 | const statement_value = try irb.genNodeRecursive(statement_node, child_scope, .None); | |
| 1442 | 1449 | |
| 1443 | 1450 | is_continuation_unreachable = statement_value.isNoReturn(); |
| 1444 | 1451 | if (is_continuation_unreachable) { |
| ... | ... | @@ -1534,7 +1541,7 @@ pub const Builder = struct { |
| 1534 | 1541 | |
| 1535 | 1542 | const outer_scope = irb.begin_scope.?; |
| 1536 | 1543 | const return_value = if (control_flow_expr.rhs) |rhs| blk: { |
| 1537 | break :blk try irb.genNode(rhs, scope, .None); | |
| 1544 | break :blk try irb.genNodeRecursive(rhs, scope, .None); | |
| 1538 | 1545 | } else blk: { |
| 1539 | 1546 | break :blk try irb.buildConstVoid(scope, src_span, true); |
| 1540 | 1547 | }; |
| ... | ... | @@ -1713,7 +1720,7 @@ pub const Builder = struct { |
| 1713 | 1720 | }; |
| 1714 | 1721 | if (generate) { |
| 1715 | 1722 | const defer_expr_scope = defer_scope.defer_expr_scope; |
| 1716 | const instruction = try irb.genNode( | |
| 1723 | const instruction = try irb.genNodeRecursive( | |
| 1717 | 1724 | defer_expr_scope.expr_node, |
| 1718 | 1725 | &defer_expr_scope.base, |
| 1719 | 1726 | .None, |
src-self-hosted/libc_installation.zig+1-1| ... | ... | @@ -400,7 +400,7 @@ fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool |
| 400 | 400 | const argv = [_][]const u8{ cc_exe, arg1 }; |
| 401 | 401 | |
| 402 | 402 | // TODO This simulates evented I/O for the child process exec |
| 403 | std.event.Loop.instance.?.yield(); | |
| 403 | event.Loop.startCpuBoundOperation(); | |
| 404 | 404 | const errorable_result = std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024); |
| 405 | 405 | const exec_result = if (std.debug.runtime_safety) blk: { |
| 406 | 406 | break :blk errorable_result catch unreachable; |
src-self-hosted/link.zig+4-5| ... | ... | @@ -623,16 +623,15 @@ fn constructLinkerArgsWasm(ctx: *Context) void { |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | fn addFnObjects(ctx: *Context) !void { |
| 626 | // at this point it's guaranteed nobody else has this lock, so we circumvent it | |
| 627 | // and avoid having to be an async function | |
| 628 | const fn_link_set = &ctx.comp.fn_link_set.private_data; | |
| 626 | const held = ctx.comp.fn_link_set.acquire(); | |
| 627 | defer held.release(); | |
| 629 | 628 | |
| 630 | var it = fn_link_set.first; | |
| 629 | var it = held.value.first; | |
| 631 | 630 | while (it) |node| { |
| 632 | 631 | const fn_val = node.data orelse { |
| 633 | 632 | // handle the tombstone. See Value.Fn.destroy. |
| 634 | 633 | it = node.next; |
| 635 | fn_link_set.remove(node); | |
| 634 | held.value.remove(node); | |
| 636 | 635 | ctx.comp.gpa().destroy(node); |
| 637 | 636 | continue; |
| 638 | 637 | }; |
src-self-hosted/main.zig+6-5| ... | ... | @@ -127,7 +127,7 @@ pub fn main() !void { |
| 127 | 127 | try stderr.print("unknown command: {}\n\n", args[1]); |
| 128 | 128 | try stderr.write(usage); |
| 129 | 129 | process.argsFree(allocator, args); |
| 130 | defer process.exit(1); | |
| 130 | process.exit(1); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | const usage_build_generic = |
| ... | ... | @@ -467,7 +467,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 467 | 467 | |
| 468 | 468 | fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void { |
| 469 | 469 | var count: usize = 0; |
| 470 | while (true) { // TODO(Vexu) | |
| 470 | while (!comp.cancelled) { | |
| 471 | 471 | const build_event = comp.events.get(); |
| 472 | 472 | count += 1; |
| 473 | 473 | |
| ... | ... | @@ -545,7 +545,7 @@ fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_fil |
| 545 | 545 | "Try running `zig libc` to see an example for the native target.\n", |
| 546 | 546 | libc_paths_file, |
| 547 | 547 | @errorName(err), |
| 548 | ) catch process.exit(1); | |
| 548 | ) catch {}; | |
| 549 | 549 | process.exit(1); |
| 550 | 550 | }; |
| 551 | 551 | } |
| ... | ... | @@ -568,7 +568,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void { |
| 568 | 568 | defer zig_compiler.deinit(); |
| 569 | 569 | |
| 570 | 570 | const libc = zig_compiler.getNativeLibC() catch |err| { |
| 571 | stderr.print("unable to find libc: {}\n", @errorName(err)) catch process.exit(1); | |
| 571 | stderr.print("unable to find libc: {}\n", @errorName(err)) catch {}; | |
| 572 | 572 | process.exit(1); |
| 573 | 573 | }; |
| 574 | 574 | libc.render(stdout) catch process.exit(1); |
| ... | ... | @@ -706,7 +706,8 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro |
| 706 | 706 | while (try it.next()) |entry| { |
| 707 | 707 | if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) { |
| 708 | 708 | const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name }); |
| 709 | try group.call(fmtPath, fmt, full_path, check_mode); | |
| 709 | @panic("TODO https://github.com/ziglang/zig/issues/3777"); | |
| 710 | // try group.call(fmtPath, fmt, full_path, check_mode); | |
| 710 | 711 | } |
| 711 | 712 | } |
| 712 | 713 | return group.wait(); |
src-self-hosted/util.zig+1-1| ... | ... | @@ -167,7 +167,7 @@ pub fn getDarwinArchString(self: Target) [:0]const u8 { |
| 167 | 167 | .powerpc64 => return "ppc64", |
| 168 | 168 | .powerpc64le => return "ppc64le", |
| 169 | 169 | // @tagName should be able to return sentinel terminated slice |
| 170 | else => @panic("TODO"), //return @tagName(arch), | |
| 170 | else => @panic("TODO https://github.com/ziglang/zig/issues/3779"), //return @tagName(arch), | |
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 |
src-self-hosted/value.zig+1-1| ... | ... | @@ -350,7 +350,7 @@ pub const Value = struct { |
| 350 | 350 | .mut = mut, |
| 351 | 351 | .vol = Type.Pointer.Vol.Non, |
| 352 | 352 | .size = size, |
| 353 | .alignment = Type.Pointer.Align.Abi, | |
| 353 | .alignment = .Abi, | |
| 354 | 354 | }); |
| 355 | 355 | var ptr_type_consumed = false; |
| 356 | 356 | errdefer if (!ptr_type_consumed) ptr_type.base.base.deref(comp); |