| author | |
| committer | |
| log | 6dd4a276de7ea7c283d1d1ef6361a718225022d3 |
| tree | 589377b21fa3cb3b54b0f6c8a1966c607cf41c2b |
| parent | 110e575497595330ac94b4cc57c0f6dc47c9f519 |
| signature |
7 files changed, 136 insertions(+), 159 deletions(-)
src-self-hosted/codegen.zig+1-1| ... | ... | @@ -79,7 +79,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 79 | 79 | .builder = builder, |
| 80 | 80 | .dibuilder = dibuilder, |
| 81 | 81 | .context = context, |
| 82 | .lock = event.Lock.init(comp.loop), | |
| 82 | .lock = event.Lock.init(), | |
| 83 | 83 | .arena = &code.arena.allocator, |
| 84 | 84 | }; |
| 85 | 85 |
src-self-hosted/compilation.zig+52-55| ... | ... | @@ -35,9 +35,9 @@ const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB |
| 35 | 35 | |
| 36 | 36 | /// Data that is local to the event loop. |
| 37 | 37 | pub const ZigCompiler = struct { |
| 38 | loop: *event.Loop, | |
| 39 | 38 | llvm_handle_pool: std.atomic.Stack(*llvm.Context), |
| 40 | 39 | lld_lock: event.Lock, |
| 40 | allocator: *Allocator, | |
| 41 | 41 | |
| 42 | 42 | /// TODO pool these so that it doesn't have to lock |
| 43 | 43 | prng: event.Locked(std.rand.DefaultPrng), |
| ... | ... | @@ -46,7 +46,7 @@ pub const ZigCompiler = struct { |
| 46 | 46 | |
| 47 | 47 | var lazy_init_targets = std.lazyInit(void); |
| 48 | 48 | |
| 49 | pub fn init(loop: *event.Loop) !ZigCompiler { | |
| 49 | pub fn init(allocator: *Allocator) !ZigCompiler { | |
| 50 | 50 | lazy_init_targets.get() orelse { |
| 51 | 51 | Target.initializeAll(); |
| 52 | 52 | lazy_init_targets.resolve(); |
| ... | ... | @@ -57,11 +57,11 @@ pub const ZigCompiler = struct { |
| 57 | 57 | const seed = mem.readIntNative(u64, &seed_bytes); |
| 58 | 58 | |
| 59 | 59 | return ZigCompiler{ |
| 60 | .loop = loop, | |
| 61 | .lld_lock = event.Lock.init(loop), | |
| 60 | .allocator = allocator, | |
| 61 | .lld_lock = event.Lock.init(), | |
| 62 | 62 | .llvm_handle_pool = std.atomic.Stack(*llvm.Context).init(), |
| 63 | .prng = event.Locked(std.rand.DefaultPrng).init(loop, std.rand.DefaultPrng.init(seed)), | |
| 64 | .native_libc = event.Future(LibCInstallation).init(loop), | |
| 63 | .prng = event.Locked(std.rand.DefaultPrng).init(std.rand.DefaultPrng.init(seed)), | |
| 64 | .native_libc = event.Future(LibCInstallation).init(), | |
| 65 | 65 | }; |
| 66 | 66 | } |
| 67 | 67 | |
| ... | ... | @@ -70,7 +70,7 @@ pub const ZigCompiler = struct { |
| 70 | 70 | self.lld_lock.deinit(); |
| 71 | 71 | while (self.llvm_handle_pool.pop()) |node| { |
| 72 | 72 | llvm.ContextDispose(node.data); |
| 73 | self.loop.allocator.destroy(node); | |
| 73 | self.allocator.destroy(node); | |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| ... | ... | @@ -82,19 +82,19 @@ pub const ZigCompiler = struct { |
| 82 | 82 | const context_ref = llvm.ContextCreate() orelse return error.OutOfMemory; |
| 83 | 83 | errdefer llvm.ContextDispose(context_ref); |
| 84 | 84 | |
| 85 | const node = try self.loop.allocator.create(std.atomic.Stack(*llvm.Context).Node); | |
| 85 | const node = try self.allocator.create(std.atomic.Stack(*llvm.Context).Node); | |
| 86 | 86 | node.* = std.atomic.Stack(*llvm.Context).Node{ |
| 87 | 87 | .next = undefined, |
| 88 | 88 | .data = context_ref, |
| 89 | 89 | }; |
| 90 | errdefer self.loop.allocator.destroy(node); | |
| 90 | errdefer self.allocator.destroy(node); | |
| 91 | 91 | |
| 92 | 92 | return LlvmHandle{ .node = node }; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | pub async fn getNativeLibC(self: *ZigCompiler) !*LibCInstallation { |
| 96 | 96 | if (self.native_libc.start()) |ptr| return ptr; |
| 97 | try self.native_libc.data.findNative(self.loop); | |
| 97 | try self.native_libc.data.findNative(self.allocator); | |
| 98 | 98 | self.native_libc.resolve(); |
| 99 | 99 | return &self.native_libc.data; |
| 100 | 100 | } |
| ... | ... | @@ -122,7 +122,6 @@ pub const LlvmHandle = struct { |
| 122 | 122 | |
| 123 | 123 | pub const Compilation = struct { |
| 124 | 124 | zig_compiler: *ZigCompiler, |
| 125 | loop: *event.Loop, | |
| 126 | 125 | name: Buffer, |
| 127 | 126 | llvm_triple: Buffer, |
| 128 | 127 | root_src_path: ?[]const u8, |
| ... | ... | @@ -228,7 +227,7 @@ pub const Compilation = struct { |
| 228 | 227 | deinit_group: event.Group(void), |
| 229 | 228 | |
| 230 | 229 | // destroy_frame: @Frame(createAsync), |
| 231 | main_loop_frame: @Frame(Compilation.mainLoop), | |
| 230 | // main_loop_frame: @Frame(Compilation.mainLoop), | |
| 232 | 231 | main_loop_future: event.Future(void), |
| 233 | 232 | |
| 234 | 233 | have_err_ret_tracing: bool, |
| ... | ... | @@ -348,7 +347,7 @@ pub const Compilation = struct { |
| 348 | 347 | zig_lib_dir: []const u8, |
| 349 | 348 | ) !*Compilation { |
| 350 | 349 | var optional_comp: ?*Compilation = null; |
| 351 | const frame = async createAsync( | |
| 350 | var frame = async createAsync( | |
| 352 | 351 | &optional_comp, |
| 353 | 352 | zig_compiler, |
| 354 | 353 | name, |
| ... | ... | @@ -359,7 +358,7 @@ pub const Compilation = struct { |
| 359 | 358 | is_static, |
| 360 | 359 | zig_lib_dir, |
| 361 | 360 | ); |
| 362 | return optional_comp orelse await frame; | |
| 361 | return optional_comp orelse if (await frame) |_| unreachable else |err| err; | |
| 363 | 362 | } |
| 364 | 363 | |
| 365 | 364 | async fn createAsync( |
| ... | ... | @@ -374,10 +373,9 @@ pub const Compilation = struct { |
| 374 | 373 | zig_lib_dir: []const u8, |
| 375 | 374 | ) !void { |
| 376 | 375 | |
| 377 | const loop = zig_compiler.loop; | |
| 376 | const allocator = zig_compiler.allocator; | |
| 378 | 377 | var comp = Compilation{ |
| 379 | .loop = loop, | |
| 380 | .arena_allocator = std.heap.ArenaAllocator.init(loop.allocator), | |
| 378 | .arena_allocator = std.heap.ArenaAllocator.init(allocator), | |
| 381 | 379 | .zig_compiler = zig_compiler, |
| 382 | 380 | .events = undefined, |
| 383 | 381 | .root_src_path = root_src_path, |
| ... | ... | @@ -387,10 +385,10 @@ pub const Compilation = struct { |
| 387 | 385 | .build_mode = build_mode, |
| 388 | 386 | .zig_lib_dir = zig_lib_dir, |
| 389 | 387 | .zig_std_dir = undefined, |
| 390 | .tmp_dir = event.Future(BuildError![]u8).init(loop), | |
| 391 | .destroy_frame = @frame(), | |
| 392 | .main_loop_frame = undefined, | |
| 393 | .main_loop_future = event.Future(void).init(loop), | |
| 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(), | |
| 394 | 392 | |
| 395 | 393 | .name = undefined, |
| 396 | 394 | .llvm_triple = undefined, |
| ... | ... | @@ -419,7 +417,7 @@ pub const Compilation = struct { |
| 419 | 417 | .rpath_list = [_][]const u8{}, |
| 420 | 418 | .assembly_files = [_][]const u8{}, |
| 421 | 419 | .link_objects = [_][]const u8{}, |
| 422 | .fn_link_set = event.Locked(FnLinkSet).init(loop, FnLinkSet.init()), | |
| 420 | .fn_link_set = event.Locked(FnLinkSet).init(FnLinkSet.init()), | |
| 423 | 421 | .windows_subsystem_windows = false, |
| 424 | 422 | .windows_subsystem_console = false, |
| 425 | 423 | .link_libs_list = undefined, |
| ... | ... | @@ -431,14 +429,14 @@ pub const Compilation = struct { |
| 431 | 429 | .test_name_prefix = null, |
| 432 | 430 | .emit_file_type = Emit.Binary, |
| 433 | 431 | .link_out_file = null, |
| 434 | .exported_symbol_names = event.Locked(Decl.Table).init(loop, Decl.Table.init(loop.allocator)), | |
| 435 | .prelink_group = event.Group(BuildError!void).init(loop), | |
| 436 | .deinit_group = event.Group(void).init(loop), | |
| 437 | .compile_errors = event.Locked(CompileErrList).init(loop, CompileErrList.init(loop.allocator)), | |
| 438 | .int_type_table = event.Locked(IntTypeTable).init(loop, IntTypeTable.init(loop.allocator)), | |
| 439 | .array_type_table = event.Locked(ArrayTypeTable).init(loop, ArrayTypeTable.init(loop.allocator)), | |
| 440 | .ptr_type_table = event.Locked(PtrTypeTable).init(loop, PtrTypeTable.init(loop.allocator)), | |
| 441 | .fn_type_table = event.Locked(FnTypeTable).init(loop, FnTypeTable.init(loop.allocator)), | |
| 432 | .exported_symbol_names = event.Locked(Decl.Table).init(Decl.Table.init(allocator)), | |
| 433 | .prelink_group = event.Group(BuildError!void).init(allocator), | |
| 434 | .deinit_group = event.Group(void).init(allocator), | |
| 435 | .compile_errors = event.Locked(CompileErrList).init(CompileErrList.init(allocator)), | |
| 436 | .int_type_table = event.Locked(IntTypeTable).init(IntTypeTable.init(allocator)), | |
| 437 | .array_type_table = event.Locked(ArrayTypeTable).init(ArrayTypeTable.init(allocator)), | |
| 438 | .ptr_type_table = event.Locked(PtrTypeTable).init(PtrTypeTable.init(allocator)), | |
| 439 | .fn_type_table = event.Locked(FnTypeTable).init(FnTypeTable.init(allocator)), | |
| 442 | 440 | .c_int_types = undefined, |
| 443 | 441 | |
| 444 | 442 | .meta_type = undefined, |
| ... | ... | @@ -519,8 +517,8 @@ pub const Compilation = struct { |
| 519 | 517 | comp.target_layout_str = llvm.CopyStringRepOfTargetData(comp.target_data_ref) orelse return error.OutOfMemory; |
| 520 | 518 | defer llvm.DisposeMessage(comp.target_layout_str); |
| 521 | 519 | |
| 522 | comp.events = try event.Channel(Event).create(comp.loop, 0); | |
| 523 | defer comp.events.destroy(); | |
| 520 | comp.events.init([0]Event{}); | |
| 521 | defer comp.events.deinit(); | |
| 524 | 522 | |
| 525 | 523 | if (root_src_path) |root_src| { |
| 526 | 524 | const dirname = std.fs.path.dirname(root_src) orelse "."; |
| ... | ... | @@ -533,13 +531,13 @@ pub const Compilation = struct { |
| 533 | 531 | comp.root_package = try Package.create(comp.arena(), ".", ""); |
| 534 | 532 | } |
| 535 | 533 | |
| 536 | comp.fs_watch = try fs.Watch(*Scope.Root).create(loop, 16); | |
| 534 | comp.fs_watch = try fs.Watch(*Scope.Root).create(16); | |
| 537 | 535 | defer comp.fs_watch.destroy(); |
| 538 | 536 | |
| 539 | 537 | try comp.initTypes(); |
| 540 | 538 | defer comp.primitive_type_table.deinit(); |
| 541 | 539 | |
| 542 | comp.main_loop_frame = async comp.mainLoop() catch unreachable; | |
| 540 | // comp.main_loop_frame = async comp.mainLoop(); | |
| 543 | 541 | // Set this to indicate that initialization completed successfully. |
| 544 | 542 | // from here on out we must not return an error. |
| 545 | 543 | // This must occur before the first suspend/await. |
| ... | ... | @@ -552,7 +550,7 @@ pub const Compilation = struct { |
| 552 | 550 | |
| 553 | 551 | if (comp.tmp_dir.getOrNull()) |tmp_dir_result| if (tmp_dir_result.*) |tmp_dir| { |
| 554 | 552 | // TODO evented I/O? |
| 555 | std.fs.deleteTree(comp.arena(), tmp_dir) catch {}; | |
| 553 | std.fs.deleteTree(tmp_dir) catch {}; | |
| 556 | 554 | } else |_| {}; |
| 557 | 555 | } |
| 558 | 556 | |
| ... | ... | @@ -601,7 +599,7 @@ pub const Compilation = struct { |
| 601 | 599 | .ref_count = std.atomic.Int(usize).init(3), // 3 because it references itself twice |
| 602 | 600 | }, |
| 603 | 601 | .id = builtin.TypeId.Type, |
| 604 | .abi_alignment = Type.AbiAlignment.init(comp.loop), | |
| 602 | .abi_alignment = Type.AbiAlignment.init(), | |
| 605 | 603 | }, |
| 606 | 604 | .value = undefined, |
| 607 | 605 | }; |
| ... | ... | @@ -619,7 +617,7 @@ pub const Compilation = struct { |
| 619 | 617 | .ref_count = std.atomic.Int(usize).init(1), |
| 620 | 618 | }, |
| 621 | 619 | .id = builtin.TypeId.Void, |
| 622 | .abi_alignment = Type.AbiAlignment.init(comp.loop), | |
| 620 | .abi_alignment = Type.AbiAlignment.init(), | |
| 623 | 621 | }, |
| 624 | 622 | }; |
| 625 | 623 | assert((try comp.primitive_type_table.put(comp.void_type.base.name, &comp.void_type.base)) == null); |
| ... | ... | @@ -634,7 +632,7 @@ pub const Compilation = struct { |
| 634 | 632 | .ref_count = std.atomic.Int(usize).init(1), |
| 635 | 633 | }, |
| 636 | 634 | .id = builtin.TypeId.NoReturn, |
| 637 | .abi_alignment = Type.AbiAlignment.init(comp.loop), | |
| 635 | .abi_alignment = Type.AbiAlignment.init(), | |
| 638 | 636 | }, |
| 639 | 637 | }; |
| 640 | 638 | assert((try comp.primitive_type_table.put(comp.noreturn_type.base.name, &comp.noreturn_type.base)) == null); |
| ... | ... | @@ -649,7 +647,7 @@ pub const Compilation = struct { |
| 649 | 647 | .ref_count = std.atomic.Int(usize).init(1), |
| 650 | 648 | }, |
| 651 | 649 | .id = builtin.TypeId.ComptimeInt, |
| 652 | .abi_alignment = Type.AbiAlignment.init(comp.loop), | |
| 650 | .abi_alignment = Type.AbiAlignment.init(), | |
| 653 | 651 | }, |
| 654 | 652 | }; |
| 655 | 653 | assert((try comp.primitive_type_table.put(comp.comptime_int_type.base.name, &comp.comptime_int_type.base)) == null); |
| ... | ... | @@ -664,7 +662,7 @@ pub const Compilation = struct { |
| 664 | 662 | .ref_count = std.atomic.Int(usize).init(1), |
| 665 | 663 | }, |
| 666 | 664 | .id = builtin.TypeId.Bool, |
| 667 | .abi_alignment = Type.AbiAlignment.init(comp.loop), | |
| 665 | .abi_alignment = Type.AbiAlignment.init(), | |
| 668 | 666 | }, |
| 669 | 667 | }; |
| 670 | 668 | assert((try comp.primitive_type_table.put(comp.bool_type.base.name, &comp.bool_type.base)) == null); |
| ... | ... | @@ -718,7 +716,7 @@ pub const Compilation = struct { |
| 718 | 716 | .ref_count = std.atomic.Int(usize).init(1), |
| 719 | 717 | }, |
| 720 | 718 | .id = builtin.TypeId.Int, |
| 721 | .abi_alignment = Type.AbiAlignment.init(comp.loop), | |
| 719 | .abi_alignment = Type.AbiAlignment.init(), | |
| 722 | 720 | }, |
| 723 | 721 | .key = Type.Int.Key{ |
| 724 | 722 | .is_signed = cint.is_signed, |
| ... | ... | @@ -739,7 +737,7 @@ pub const Compilation = struct { |
| 739 | 737 | .ref_count = std.atomic.Int(usize).init(1), |
| 740 | 738 | }, |
| 741 | 739 | .id = builtin.TypeId.Int, |
| 742 | .abi_alignment = Type.AbiAlignment.init(comp.loop), | |
| 740 | .abi_alignment = Type.AbiAlignment.init(), | |
| 743 | 741 | }, |
| 744 | 742 | .key = Type.Int.Key{ |
| 745 | 743 | .is_signed = false, |
| ... | ... | @@ -751,8 +749,8 @@ pub const Compilation = struct { |
| 751 | 749 | } |
| 752 | 750 | |
| 753 | 751 | pub fn destroy(self: *Compilation) void { |
| 754 | await self.main_loop_frame; | |
| 755 | resume self.destroy_frame; | |
| 752 | // await self.main_loop_frame; | |
| 753 | // resume self.destroy_frame; | |
| 756 | 754 | } |
| 757 | 755 | |
| 758 | 756 | fn start(self: *Compilation) void { |
| ... | ... | @@ -794,7 +792,7 @@ pub const Compilation = struct { |
| 794 | 792 | } |
| 795 | 793 | |
| 796 | 794 | // First, get an item from the watch channel, waiting on the channel. |
| 797 | var group = event.Group(BuildError!void).init(self.loop); | |
| 795 | var group = event.Group(BuildError!void).init(self.gpa()); | |
| 798 | 796 | { |
| 799 | 797 | const ev = (self.fs_watch.channel.get()) catch |err| { |
| 800 | 798 | build_result = err; |
| ... | ... | @@ -826,7 +824,6 @@ pub const Compilation = struct { |
| 826 | 824 | async fn rebuildFile(self: *Compilation, root_scope: *Scope.Root) !void { |
| 827 | 825 | const tree_scope = blk: { |
| 828 | 826 | const source_code = fs.readFile( |
| 829 | self.loop, | |
| 830 | 827 | root_scope.realpath, |
| 831 | 828 | max_src_size, |
| 832 | 829 | ) catch |err| { |
| ... | ... | @@ -858,10 +855,10 @@ pub const Compilation = struct { |
| 858 | 855 | const locked_table = root_scope.decls.table.acquireWrite(); |
| 859 | 856 | defer locked_table.release(); |
| 860 | 857 | |
| 861 | var decl_group = event.Group(BuildError!void).init(self.loop); | |
| 858 | var decl_group = event.Group(BuildError!void).init(self.gpa()); | |
| 862 | 859 | defer decl_group.deinit(); |
| 863 | 860 | |
| 864 | try await try async self.rebuildChangedDecls( | |
| 861 | try self.rebuildChangedDecls( | |
| 865 | 862 | &decl_group, |
| 866 | 863 | locked_table.value, |
| 867 | 864 | root_scope.decls, |
| ... | ... | @@ -935,7 +932,7 @@ pub const Compilation = struct { |
| 935 | 932 | .id = Decl.Id.Fn, |
| 936 | 933 | .name = name, |
| 937 | 934 | .visib = parseVisibToken(tree_scope.tree, fn_proto.visib_token), |
| 938 | .resolution = event.Future(BuildError!void).init(self.loop), | |
| 935 | .resolution = event.Future(BuildError!void).init(), | |
| 939 | 936 | .parent_scope = &decl_scope.base, |
| 940 | 937 | .tree_scope = tree_scope, |
| 941 | 938 | }, |
| ... | ... | @@ -975,8 +972,8 @@ pub const Compilation = struct { |
| 975 | 972 | }; |
| 976 | 973 | defer root_scope.base.deref(self); |
| 977 | 974 | |
| 978 | assert((try await try async self.fs_watch.addFile(root_scope.realpath, root_scope)) == null); | |
| 979 | try await try async self.rebuildFile(root_scope); | |
| 975 | assert((try self.fs_watch.addFile(root_scope.realpath, root_scope)) == null); | |
| 976 | try self.rebuildFile(root_scope); | |
| 980 | 977 | } |
| 981 | 978 | } |
| 982 | 979 | |
| ... | ... | @@ -1039,7 +1036,7 @@ pub const Compilation = struct { |
| 1039 | 1036 | tree_scope: *Scope.AstTree, |
| 1040 | 1037 | scope: *Scope, |
| 1041 | 1038 | comptime_node: *ast.Node.Comptime, |
| 1042 | ) !void { | |
| 1039 | ) BuildError!void { | |
| 1043 | 1040 | const void_type = Type.Void.get(comp); |
| 1044 | 1041 | defer void_type.base.base.deref(comp); |
| 1045 | 1042 | |
| ... | ... | @@ -1062,7 +1059,7 @@ pub const Compilation = struct { |
| 1062 | 1059 | self: *Compilation, |
| 1063 | 1060 | decl: *Decl, |
| 1064 | 1061 | locked_table: *Decl.Table, |
| 1065 | ) !void { | |
| 1062 | ) BuildError!void { | |
| 1066 | 1063 | const is_export = decl.isExported(decl.tree_scope.tree); |
| 1067 | 1064 | |
| 1068 | 1065 | if (is_export) { |
| ... | ... | @@ -1166,14 +1163,14 @@ pub const Compilation = struct { |
| 1166 | 1163 | |
| 1167 | 1164 | /// cancels itself so no need to await or cancel the promise. |
| 1168 | 1165 | async fn startFindingNativeLibC(self: *Compilation) void { |
| 1169 | self.loop.yield(); | |
| 1166 | std.event.Loop.instance.?.yield(); | |
| 1170 | 1167 | // we don't care if it fails, we're just trying to kick off the future resolution |
| 1171 | 1168 | _ = (self.zig_compiler.getNativeLibC()) catch return; |
| 1172 | 1169 | } |
| 1173 | 1170 | |
| 1174 | 1171 | /// General Purpose Allocator. Must free when done. |
| 1175 | 1172 | fn gpa(self: Compilation) *mem.Allocator { |
| 1176 | return self.loop.allocator; | |
| 1173 | return self.zig_compiler.allocator; | |
| 1177 | 1174 | } |
| 1178 | 1175 | |
| 1179 | 1176 | /// Arena Allocator. Automatically freed when the Compilation is destroyed. |
src-self-hosted/libc_installation.zig+52-51| ... | ... | @@ -4,6 +4,7 @@ const event = std.event; |
| 4 | 4 | const Target = @import("target.zig").Target; |
| 5 | 5 | const c = @import("c.zig"); |
| 6 | 6 | const fs = std.fs; |
| 7 | const Allocator = std.mem.Allocator; | |
| 7 | 8 | |
| 8 | 9 | /// See the render function implementation for documentation of the fields. |
| 9 | 10 | pub const LibCInstallation = struct { |
| ... | ... | @@ -29,7 +30,7 @@ pub const LibCInstallation = struct { |
| 29 | 30 | |
| 30 | 31 | pub fn parse( |
| 31 | 32 | self: *LibCInstallation, |
| 32 | allocator: *std.mem.Allocator, | |
| 33 | allocator: *Allocator, | |
| 33 | 34 | libc_file: []const u8, |
| 34 | 35 | stderr: *std.io.OutStream(fs.File.WriteError), |
| 35 | 36 | ) !void { |
| ... | ... | @@ -141,10 +142,10 @@ pub const LibCInstallation = struct { |
| 141 | 142 | } |
| 142 | 143 | |
| 143 | 144 | /// Finds the default, native libc. |
| 144 | pub async fn findNative(self: *LibCInstallation, loop: *event.Loop) !void { | |
| 145 | pub async fn findNative(self: *LibCInstallation, allocator: *Allocator) !void { | |
| 145 | 146 | self.initEmpty(); |
| 146 | var group = event.Group(FindError!void).init(loop); | |
| 147 | errdefer group.deinit(); | |
| 147 | var group = event.Group(FindError!void).init(allocator); | |
| 148 | // errdefer group.deinit(); | |
| 148 | 149 | var windows_sdk: ?*c.ZigWindowsSDK = null; |
| 149 | 150 | errdefer if (windows_sdk) |sdk| c.zig_free_windows_sdk(@ptrCast(?[*]c.ZigWindowsSDK, sdk)); |
| 150 | 151 | |
| ... | ... | @@ -156,11 +157,11 @@ pub const LibCInstallation = struct { |
| 156 | 157 | windows_sdk = sdk; |
| 157 | 158 | |
| 158 | 159 | if (sdk.msvc_lib_dir_ptr != 0) { |
| 159 | self.msvc_lib_dir = try std.mem.dupe(loop.allocator, u8, sdk.msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len]); | |
| 160 | self.msvc_lib_dir = try std.mem.dupe(allocator, u8, sdk.msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len]); | |
| 160 | 161 | } |
| 161 | try group.call(findNativeKernel32LibDir, self, loop, sdk); | |
| 162 | try group.call(findNativeIncludeDirWindows, self, loop, sdk); | |
| 163 | try group.call(findNativeLibDirWindows, self, loop, sdk); | |
| 162 | try group.call(findNativeKernel32LibDir, self, sdk); | |
| 163 | try group.call(findNativeIncludeDirWindows, self, sdk); | |
| 164 | try group.call(findNativeLibDirWindows, self, sdk); | |
| 164 | 165 | }, |
| 165 | 166 | c.ZigFindWindowsSdkError.OutOfMemory => return error.OutOfMemory, |
| 166 | 167 | c.ZigFindWindowsSdkError.NotFound => return error.NotFound, |
| ... | ... | @@ -168,20 +169,20 @@ pub const LibCInstallation = struct { |
| 168 | 169 | } |
| 169 | 170 | }, |
| 170 | 171 | .linux => { |
| 171 | try group.call(findNativeIncludeDirLinux, self, loop); | |
| 172 | try group.call(findNativeLibDirLinux, self, loop); | |
| 173 | try group.call(findNativeStaticLibDir, self, loop); | |
| 174 | try group.call(findNativeDynamicLinker, self, loop); | |
| 172 | try group.call(findNativeIncludeDirLinux, self, allocator); | |
| 173 | try group.call(findNativeLibDirLinux, self, allocator); | |
| 174 | try group.call(findNativeStaticLibDir, self, allocator); | |
| 175 | try group.call(findNativeDynamicLinker, self, allocator); | |
| 175 | 176 | }, |
| 176 | 177 | .macosx, .freebsd, .netbsd => { |
| 177 | self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include"); | |
| 178 | self.include_dir = try std.mem.dupe(allocator, u8, "/usr/include"); | |
| 178 | 179 | }, |
| 179 | 180 | else => @compileError("unimplemented: find libc for this OS"), |
| 180 | 181 | } |
| 181 | 182 | return group.wait(); |
| 182 | 183 | } |
| 183 | 184 | |
| 184 | async fn findNativeIncludeDirLinux(self: *LibCInstallation, loop: *event.Loop) !void { | |
| 185 | async fn findNativeIncludeDirLinux(self: *LibCInstallation, allocator: *Allocator) FindError!void { | |
| 185 | 186 | const cc_exe = std.os.getenv("CC") orelse "cc"; |
| 186 | 187 | const argv = [_][]const u8{ |
| 187 | 188 | cc_exe, |
| ... | ... | @@ -191,7 +192,7 @@ pub const LibCInstallation = struct { |
| 191 | 192 | "/dev/null", |
| 192 | 193 | }; |
| 193 | 194 | // TODO make this use event loop |
| 194 | const errorable_result = std.ChildProcess.exec(loop.allocator, argv, null, null, 1024 * 1024); | |
| 195 | const errorable_result = std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024); | |
| 195 | 196 | const exec_result = if (std.debug.runtime_safety) blk: { |
| 196 | 197 | break :blk errorable_result catch unreachable; |
| 197 | 198 | } else blk: { |
| ... | ... | @@ -201,8 +202,8 @@ pub const LibCInstallation = struct { |
| 201 | 202 | }; |
| 202 | 203 | }; |
| 203 | 204 | defer { |
| 204 | loop.allocator.free(exec_result.stdout); | |
| 205 | loop.allocator.free(exec_result.stderr); | |
| 205 | allocator.free(exec_result.stdout); | |
| 206 | allocator.free(exec_result.stderr); | |
| 206 | 207 | } |
| 207 | 208 | |
| 208 | 209 | switch (exec_result.term) { |
| ... | ... | @@ -215,7 +216,7 @@ pub const LibCInstallation = struct { |
| 215 | 216 | } |
| 216 | 217 | |
| 217 | 218 | var it = std.mem.tokenize(exec_result.stderr, "\n\r"); |
| 218 | var search_paths = std.ArrayList([]const u8).init(loop.allocator); | |
| 219 | var search_paths = std.ArrayList([]const u8).init(allocator); | |
| 219 | 220 | defer search_paths.deinit(); |
| 220 | 221 | while (it.next()) |line| { |
| 221 | 222 | if (line.len != 0 and line[0] == ' ') { |
| ... | ... | @@ -231,11 +232,11 @@ pub const LibCInstallation = struct { |
| 231 | 232 | while (path_i < search_paths.len) : (path_i += 1) { |
| 232 | 233 | const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1); |
| 233 | 234 | const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " "); |
| 234 | const stdlib_path = try fs.path.join(loop.allocator, [_][]const u8{ search_path, "stdlib.h" }); | |
| 235 | defer loop.allocator.free(stdlib_path); | |
| 235 | const stdlib_path = try fs.path.join(allocator, [_][]const u8{ search_path, "stdlib.h" }); | |
| 236 | defer allocator.free(stdlib_path); | |
| 236 | 237 | |
| 237 | 238 | if (try fileExists(stdlib_path)) { |
| 238 | self.include_dir = try std.mem.dupe(loop.allocator, u8, search_path); | |
| 239 | self.include_dir = try std.mem.dupe(allocator, u8, search_path); | |
| 239 | 240 | return; |
| 240 | 241 | } |
| 241 | 242 | } |
| ... | ... | @@ -243,11 +244,11 @@ pub const LibCInstallation = struct { |
| 243 | 244 | return error.LibCStdLibHeaderNotFound; |
| 244 | 245 | } |
| 245 | 246 | |
| 246 | async fn findNativeIncludeDirWindows(self: *LibCInstallation, loop: *event.Loop, sdk: *c.ZigWindowsSDK) !void { | |
| 247 | async fn findNativeIncludeDirWindows(self: *LibCInstallation, allocator: *Allocator, sdk: *c.ZigWindowsSDK) !void { | |
| 247 | 248 | var search_buf: [2]Search = undefined; |
| 248 | 249 | const searches = fillSearch(&search_buf, sdk); |
| 249 | 250 | |
| 250 | var result_buf = try std.Buffer.initSize(loop.allocator, 0); | |
| 251 | var result_buf = try std.Buffer.initSize(allocator, 0); | |
| 251 | 252 | defer result_buf.deinit(); |
| 252 | 253 | |
| 253 | 254 | for (searches) |search| { |
| ... | ... | @@ -256,10 +257,10 @@ pub const LibCInstallation = struct { |
| 256 | 257 | try stream.print("{}\\Include\\{}\\ucrt", search.path, search.version); |
| 257 | 258 | |
| 258 | 259 | const stdlib_path = try fs.path.join( |
| 259 | loop.allocator, | |
| 260 | allocator, | |
| 260 | 261 | [_][]const u8{ result_buf.toSliceConst(), "stdlib.h" }, |
| 261 | 262 | ); |
| 262 | defer loop.allocator.free(stdlib_path); | |
| 263 | defer allocator.free(stdlib_path); | |
| 263 | 264 | |
| 264 | 265 | if (try fileExists(stdlib_path)) { |
| 265 | 266 | self.include_dir = result_buf.toOwnedSlice(); |
| ... | ... | @@ -270,11 +271,11 @@ pub const LibCInstallation = struct { |
| 270 | 271 | return error.LibCStdLibHeaderNotFound; |
| 271 | 272 | } |
| 272 | 273 | |
| 273 | async fn findNativeLibDirWindows(self: *LibCInstallation, loop: *event.Loop, sdk: *c.ZigWindowsSDK) FindError!void { | |
| 274 | async fn findNativeLibDirWindows(self: *LibCInstallation, allocator: *Allocator, sdk: *c.ZigWindowsSDK) FindError!void { | |
| 274 | 275 | var search_buf: [2]Search = undefined; |
| 275 | 276 | const searches = fillSearch(&search_buf, sdk); |
| 276 | 277 | |
| 277 | var result_buf = try std.Buffer.initSize(loop.allocator, 0); | |
| 278 | var result_buf = try std.Buffer.initSize(allocator, 0); | |
| 278 | 279 | defer result_buf.deinit(); |
| 279 | 280 | |
| 280 | 281 | for (searches) |search| { |
| ... | ... | @@ -288,10 +289,10 @@ pub const LibCInstallation = struct { |
| 288 | 289 | else => return error.UnsupportedArchitecture, |
| 289 | 290 | } |
| 290 | 291 | const ucrt_lib_path = try fs.path.join( |
| 291 | loop.allocator, | |
| 292 | allocator, | |
| 292 | 293 | [_][]const u8{ result_buf.toSliceConst(), "ucrt.lib" }, |
| 293 | 294 | ); |
| 294 | defer loop.allocator.free(ucrt_lib_path); | |
| 295 | defer allocator.free(ucrt_lib_path); | |
| 295 | 296 | if (try fileExists(ucrt_lib_path)) { |
| 296 | 297 | self.lib_dir = result_buf.toOwnedSlice(); |
| 297 | 298 | return; |
| ... | ... | @@ -300,15 +301,15 @@ pub const LibCInstallation = struct { |
| 300 | 301 | return error.LibCRuntimeNotFound; |
| 301 | 302 | } |
| 302 | 303 | |
| 303 | async fn findNativeLibDirLinux(self: *LibCInstallation, loop: *event.Loop) FindError!void { | |
| 304 | self.lib_dir = try ccPrintFileName(loop, "crt1.o", true); | |
| 304 | async fn findNativeLibDirLinux(self: *LibCInstallation, allocator: *Allocator) FindError!void { | |
| 305 | self.lib_dir = try ccPrintFileName(allocator, "crt1.o", true); | |
| 305 | 306 | } |
| 306 | 307 | |
| 307 | async fn findNativeStaticLibDir(self: *LibCInstallation, loop: *event.Loop) FindError!void { | |
| 308 | self.static_lib_dir = try ccPrintFileName(loop, "crtbegin.o", true); | |
| 308 | async fn findNativeStaticLibDir(self: *LibCInstallation, allocator: *Allocator) FindError!void { | |
| 309 | self.static_lib_dir = try ccPrintFileName(allocator, "crtbegin.o", true); | |
| 309 | 310 | } |
| 310 | 311 | |
| 311 | async fn findNativeDynamicLinker(self: *LibCInstallation, loop: *event.Loop) FindError!void { | |
| 312 | async fn findNativeDynamicLinker(self: *LibCInstallation, allocator: *Allocator) FindError!void { | |
| 312 | 313 | var dyn_tests = [_]DynTest{ |
| 313 | 314 | DynTest{ |
| 314 | 315 | .name = "ld-linux-x86-64.so.2", |
| ... | ... | @@ -319,10 +320,10 @@ pub const LibCInstallation = struct { |
| 319 | 320 | .result = null, |
| 320 | 321 | }, |
| 321 | 322 | }; |
| 322 | var group = event.Group(FindError!void).init(loop); | |
| 323 | var group = event.Group(FindError!void).init(allocator); | |
| 323 | 324 | errdefer group.deinit(); |
| 324 | 325 | for (dyn_tests) |*dyn_test| { |
| 325 | try group.call(testNativeDynamicLinker, self, loop, dyn_test); | |
| 326 | try group.call(testNativeDynamicLinker, self, allocator, dyn_test); | |
| 326 | 327 | } |
| 327 | 328 | try group.wait(); |
| 328 | 329 | for (dyn_tests) |*dyn_test| { |
| ... | ... | @@ -338,8 +339,8 @@ pub const LibCInstallation = struct { |
| 338 | 339 | result: ?[]const u8, |
| 339 | 340 | }; |
| 340 | 341 | |
| 341 | async fn testNativeDynamicLinker(self: *LibCInstallation, loop: *event.Loop, dyn_test: *DynTest) FindError!void { | |
| 342 | if (ccPrintFileName(loop, dyn_test.name, false)) |result| { | |
| 342 | async fn testNativeDynamicLinker(self: *LibCInstallation, allocator: *Allocator, dyn_test: *DynTest) FindError!void { | |
| 343 | if (ccPrintFileName(allocator, dyn_test.name, false)) |result| { | |
| 343 | 344 | dyn_test.result = result; |
| 344 | 345 | return; |
| 345 | 346 | } else |err| switch (err) { |
| ... | ... | @@ -348,11 +349,11 @@ pub const LibCInstallation = struct { |
| 348 | 349 | } |
| 349 | 350 | } |
| 350 | 351 | |
| 351 | async fn findNativeKernel32LibDir(self: *LibCInstallation, loop: *event.Loop, sdk: *c.ZigWindowsSDK) FindError!void { | |
| 352 | async fn findNativeKernel32LibDir(self: *LibCInstallation, allocator: *Allocator, sdk: *c.ZigWindowsSDK) FindError!void { | |
| 352 | 353 | var search_buf: [2]Search = undefined; |
| 353 | 354 | const searches = fillSearch(&search_buf, sdk); |
| 354 | 355 | |
| 355 | var result_buf = try std.Buffer.initSize(loop.allocator, 0); | |
| 356 | var result_buf = try std.Buffer.initSize(allocator, 0); | |
| 356 | 357 | defer result_buf.deinit(); |
| 357 | 358 | |
| 358 | 359 | for (searches) |search| { |
| ... | ... | @@ -366,10 +367,10 @@ pub const LibCInstallation = struct { |
| 366 | 367 | else => return error.UnsupportedArchitecture, |
| 367 | 368 | } |
| 368 | 369 | const kernel32_path = try fs.path.join( |
| 369 | loop.allocator, | |
| 370 | allocator, | |
| 370 | 371 | [_][]const u8{ result_buf.toSliceConst(), "kernel32.lib" }, |
| 371 | 372 | ); |
| 372 | defer loop.allocator.free(kernel32_path); | |
| 373 | defer allocator.free(kernel32_path); | |
| 373 | 374 | if (try fileExists(kernel32_path)) { |
| 374 | 375 | self.kernel32_lib_dir = result_buf.toOwnedSlice(); |
| 375 | 376 | return; |
| ... | ... | @@ -391,15 +392,15 @@ pub const LibCInstallation = struct { |
| 391 | 392 | }; |
| 392 | 393 | |
| 393 | 394 | /// caller owns returned memory |
| 394 | async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bool) ![]u8 { | |
| 395 | async fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool) ![]u8 { | |
| 395 | 396 | const cc_exe = std.os.getenv("CC") orelse "cc"; |
| 396 | const arg1 = try std.fmt.allocPrint(loop.allocator, "-print-file-name={}", o_file); | |
| 397 | defer loop.allocator.free(arg1); | |
| 397 | const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", o_file); | |
| 398 | defer allocator.free(arg1); | |
| 398 | 399 | const argv = [_][]const u8{ cc_exe, arg1 }; |
| 399 | 400 | |
| 400 | 401 | // TODO This simulates evented I/O for the child process exec |
| 401 | loop.yield(); | |
| 402 | const errorable_result = std.ChildProcess.exec(loop.allocator, argv, null, null, 1024 * 1024); | |
| 402 | std.event.Loop.instance.?.yield(); | |
| 403 | const errorable_result = std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024); | |
| 403 | 404 | const exec_result = if (std.debug.runtime_safety) blk: { |
| 404 | 405 | break :blk errorable_result catch unreachable; |
| 405 | 406 | } else blk: { |
| ... | ... | @@ -409,8 +410,8 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo |
| 409 | 410 | }; |
| 410 | 411 | }; |
| 411 | 412 | defer { |
| 412 | loop.allocator.free(exec_result.stdout); | |
| 413 | loop.allocator.free(exec_result.stderr); | |
| 413 | allocator.free(exec_result.stdout); | |
| 414 | allocator.free(exec_result.stderr); | |
| 414 | 415 | } |
| 415 | 416 | switch (exec_result.term) { |
| 416 | 417 | .Exited => |code| { |
| ... | ... | @@ -425,9 +426,9 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo |
| 425 | 426 | const dirname = fs.path.dirname(line) orelse return error.LibCRuntimeNotFound; |
| 426 | 427 | |
| 427 | 428 | if (want_dirname) { |
| 428 | return std.mem.dupe(loop.allocator, u8, dirname); | |
| 429 | return std.mem.dupe(allocator, u8, dirname); | |
| 429 | 430 | } else { |
| 430 | return std.mem.dupe(loop.allocator, u8, line); | |
| 431 | return std.mem.dupe(allocator, u8, line); | |
| 431 | 432 | } |
| 432 | 433 | } |
| 433 | 434 |
src-self-hosted/main.zig+25-39| ... | ... | @@ -26,6 +26,8 @@ var stderr_file: fs.File = undefined; |
| 26 | 26 | var stderr: *io.OutStream(fs.File.WriteError) = undefined; |
| 27 | 27 | var stdout: *io.OutStream(fs.File.WriteError) = undefined; |
| 28 | 28 | |
| 29 | pub const io_mode = .evented; | |
| 30 | ||
| 29 | 31 | pub const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB |
| 30 | 32 | |
| 31 | 33 | const usage = |
| ... | ... | @@ -386,11 +388,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 386 | 388 | |
| 387 | 389 | var override_libc: LibCInstallation = undefined; |
| 388 | 390 | |
| 389 | var loop: event.Loop = undefined; | |
| 390 | try loop.initMultiThreaded(allocator); | |
| 391 | defer loop.deinit(); | |
| 392 | ||
| 393 | var zig_compiler = try ZigCompiler.init(&loop); | |
| 391 | var zig_compiler = try ZigCompiler.init(allocator); | |
| 394 | 392 | defer zig_compiler.deinit(); |
| 395 | 393 | |
| 396 | 394 | var comp = try Compilation.create( |
| ... | ... | @@ -406,7 +404,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 406 | 404 | defer comp.destroy(); |
| 407 | 405 | |
| 408 | 406 | if (flags.single("libc")) |libc_path| { |
| 409 | parseLibcPaths(loop.allocator, &override_libc, libc_path); | |
| 407 | parseLibcPaths(allocator, &override_libc, libc_path); | |
| 410 | 408 | comp.override_libc = &override_libc; |
| 411 | 409 | } |
| 412 | 410 | |
| ... | ... | @@ -466,8 +464,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 466 | 464 | comp.link_objects = link_objects; |
| 467 | 465 | |
| 468 | 466 | comp.start(); |
| 469 | const frame = try async processBuildEvents(comp, color); | |
| 470 | loop.run(); | |
| 467 | const frame = async processBuildEvents(comp, color); | |
| 471 | 468 | } |
| 472 | 469 | |
| 473 | 470 | async fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void { |
| ... | ... | @@ -539,7 +536,7 @@ const Fmt = struct { |
| 539 | 536 | seen: event.Locked(SeenMap), |
| 540 | 537 | any_error: bool, |
| 541 | 538 | color: errmsg.Color, |
| 542 | loop: *event.Loop, | |
| 539 | allocator: *Allocator, | |
| 543 | 540 | |
| 544 | 541 | const SeenMap = std.StringHashMap(void); |
| 545 | 542 | }; |
| ... | ... | @@ -570,16 +567,10 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void { |
| 570 | 567 | }, |
| 571 | 568 | } |
| 572 | 569 | |
| 573 | var loop: event.Loop = undefined; | |
| 574 | try loop.initMultiThreaded(allocator); | |
| 575 | defer loop.deinit(); | |
| 576 | ||
| 577 | var zig_compiler = try ZigCompiler.init(&loop); | |
| 570 | var zig_compiler = try ZigCompiler.init(allocator); | |
| 578 | 571 | defer zig_compiler.deinit(); |
| 579 | 572 | |
| 580 | 573 | const frame = async findLibCAsync(&zig_compiler); |
| 581 | ||
| 582 | loop.run(); | |
| 583 | 574 | } |
| 584 | 575 | |
| 585 | 576 | async fn findLibCAsync(zig_compiler: *ZigCompiler) void { |
| ... | ... | @@ -656,15 +647,11 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 656 | 647 | process.exit(1); |
| 657 | 648 | } |
| 658 | 649 | |
| 659 | var loop: event.Loop = undefined; | |
| 660 | try loop.initMultiThreaded(allocator); | |
| 661 | defer loop.deinit(); | |
| 662 | ||
| 663 | 650 | return asyncFmtMain( |
| 651 | allocator, | |
| 664 | 652 | &flags, |
| 665 | 653 | color, |
| 666 | 654 | ); |
| 667 | // loop.run(); | |
| 668 | 655 | } |
| 669 | 656 | |
| 670 | 657 | const FmtError = error{ |
| ... | ... | @@ -690,20 +677,20 @@ const FmtError = error{ |
| 690 | 677 | } || fs.File.OpenError; |
| 691 | 678 | |
| 692 | 679 | async fn asyncFmtMain( |
| 693 | loop: *event.Loop, | |
| 680 | allocator: *Allocator, | |
| 694 | 681 | flags: *const Args, |
| 695 | 682 | color: errmsg.Color, |
| 696 | 683 | ) FmtError!void { |
| 697 | 684 | var fmt = Fmt{ |
| 698 | .seen = event.Locked(Fmt.SeenMap).init(loop, Fmt.SeenMap.init(loop.allocator)), | |
| 685 | .allocator = allocator, | |
| 686 | .seen = event.Locked(Fmt.SeenMap).init(Fmt.SeenMap.init(allocator)), | |
| 699 | 687 | .any_error = false, |
| 700 | 688 | .color = color, |
| 701 | .loop = loop, | |
| 702 | 689 | }; |
| 703 | 690 | |
| 704 | 691 | const check_mode = flags.present("check"); |
| 705 | 692 | |
| 706 | var group = event.Group(FmtError!void).init(loop); | |
| 693 | var group = event.Group(FmtError!void).init(allocator); | |
| 707 | 694 | for (flags.positionals.toSliceConst()) |file_path| { |
| 708 | 695 | try group.call(fmtPath, &fmt, file_path, check_mode); |
| 709 | 696 | } |
| ... | ... | @@ -714,8 +701,8 @@ async fn asyncFmtMain( |
| 714 | 701 | } |
| 715 | 702 | |
| 716 | 703 | async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void { |
| 717 | const file_path = try std.mem.dupe(fmt.loop.allocator, u8, file_path_ref); | |
| 718 | defer fmt.loop.allocator.free(file_path); | |
| 704 | const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref); | |
| 705 | defer fmt.allocator.free(file_path); | |
| 719 | 706 | |
| 720 | 707 | { |
| 721 | 708 | const held = fmt.seen.acquire(); |
| ... | ... | @@ -724,20 +711,19 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro |
| 724 | 711 | if (try held.value.put(file_path, {})) |_| return; |
| 725 | 712 | } |
| 726 | 713 | |
| 727 | const source_code = (await try async event.fs.readFile( | |
| 728 | fmt.loop, | |
| 714 | const source_code = event.fs.readFile( | |
| 729 | 715 | file_path, |
| 730 | 716 | max_src_size, |
| 731 | )) catch |err| switch (err) { | |
| 717 | ) catch |err| switch (err) { | |
| 732 | 718 | error.IsDir, error.AccessDenied => { |
| 733 | 719 | // TODO make event based (and dir.next()) |
| 734 | 720 | var dir = try fs.Dir.open(file_path); |
| 735 | 721 | defer dir.close(); |
| 736 | 722 | |
| 737 | var group = event.Group(FmtError!void).init(fmt.loop); | |
| 723 | var group = event.Group(FmtError!void).init(fmt.allocator); | |
| 738 | 724 | while (try dir.next()) |entry| { |
| 739 | 725 | if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) { |
| 740 | const full_path = try fs.path.join(fmt.loop.allocator, [_][]const u8{ file_path, entry.name }); | |
| 726 | const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name }); | |
| 741 | 727 | try group.call(fmtPath, fmt, full_path, check_mode); |
| 742 | 728 | } |
| 743 | 729 | } |
| ... | ... | @@ -750,9 +736,9 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro |
| 750 | 736 | return; |
| 751 | 737 | }, |
| 752 | 738 | }; |
| 753 | defer fmt.loop.allocator.free(source_code); | |
| 739 | defer fmt.allocator.free(source_code); | |
| 754 | 740 | |
| 755 | const tree = std.zig.parse(fmt.loop.allocator, source_code) catch |err| { | |
| 741 | const tree = std.zig.parse(fmt.allocator, source_code) catch |err| { | |
| 756 | 742 | try stderr.print("error parsing file '{}': {}\n", file_path, err); |
| 757 | 743 | fmt.any_error = true; |
| 758 | 744 | return; |
| ... | ... | @@ -761,8 +747,8 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro |
| 761 | 747 | |
| 762 | 748 | var error_it = tree.errors.iterator(0); |
| 763 | 749 | while (error_it.next()) |parse_error| { |
| 764 | const msg = try errmsg.Msg.createFromParseError(fmt.loop.allocator, parse_error, tree, file_path); | |
| 765 | defer fmt.loop.allocator.destroy(msg); | |
| 750 | const msg = try errmsg.Msg.createFromParseError(fmt.allocator, parse_error, tree, file_path); | |
| 751 | defer fmt.allocator.destroy(msg); | |
| 766 | 752 | |
| 767 | 753 | try msg.printToFile(stderr_file, fmt.color); |
| 768 | 754 | } |
| ... | ... | @@ -772,17 +758,17 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro |
| 772 | 758 | } |
| 773 | 759 | |
| 774 | 760 | if (check_mode) { |
| 775 | const anything_changed = try std.zig.render(fmt.loop.allocator, io.null_out_stream, tree); | |
| 761 | const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree); | |
| 776 | 762 | if (anything_changed) { |
| 777 | 763 | try stderr.print("{}\n", file_path); |
| 778 | 764 | fmt.any_error = true; |
| 779 | 765 | } |
| 780 | 766 | } else { |
| 781 | 767 | // TODO make this evented |
| 782 | const baf = try io.BufferedAtomicFile.create(fmt.loop.allocator, file_path); | |
| 768 | const baf = try io.BufferedAtomicFile.create(fmt.allocator, file_path); | |
| 783 | 769 | defer baf.destroy(); |
| 784 | 770 | |
| 785 | const anything_changed = try std.zig.render(fmt.loop.allocator, baf.stream(), tree); | |
| 771 | const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree); | |
| 786 | 772 | if (anything_changed) { |
| 787 | 773 | try stderr.print("{}\n", file_path); |
| 788 | 774 | try baf.finish(); |
src-self-hosted/scope.zig+1-1| ... | ... | @@ -184,7 +184,7 @@ pub const Scope = struct { |
| 184 | 184 | const self = try comp.gpa().create(Decls); |
| 185 | 185 | self.* = Decls{ |
| 186 | 186 | .base = undefined, |
| 187 | .table = event.RwLocked(Decl.Table).init(comp.loop, Decl.Table.init(comp.gpa())), | |
| 187 | .table = event.RwLocked(Decl.Table).init(Decl.Table.init(comp.gpa())), | |
| 188 | 188 | }; |
| 189 | 189 | self.base.init(Id.Decls, parent); |
| 190 | 190 | return self; |
src-self-hosted/test.zig+4-11| ... | ... | @@ -24,7 +24,6 @@ const file1 = "1.zig"; |
| 24 | 24 | const allocator = std.heap.c_allocator; |
| 25 | 25 | |
| 26 | 26 | pub const TestContext = struct { |
| 27 | loop: std.event.Loop, | |
| 28 | 27 | zig_compiler: ZigCompiler, |
| 29 | 28 | zig_lib_dir: []u8, |
| 30 | 29 | file_index: std.atomic.Int(usize), |
| ... | ... | @@ -36,20 +35,16 @@ pub const TestContext = struct { |
| 36 | 35 | fn init(self: *TestContext) !void { |
| 37 | 36 | self.* = TestContext{ |
| 38 | 37 | .any_err = {}, |
| 39 | .loop = undefined, | |
| 40 | 38 | .zig_compiler = undefined, |
| 41 | 39 | .zig_lib_dir = undefined, |
| 42 | 40 | .group = undefined, |
| 43 | 41 | .file_index = std.atomic.Int(usize).init(0), |
| 44 | 42 | }; |
| 45 | 43 | |
| 46 | try self.loop.initSingleThreaded(allocator); | |
| 47 | errdefer self.loop.deinit(); | |
| 48 | ||
| 49 | self.zig_compiler = try ZigCompiler.init(&self.loop); | |
| 44 | self.zig_compiler = try ZigCompiler.init(); | |
| 50 | 45 | errdefer self.zig_compiler.deinit(); |
| 51 | 46 | |
| 52 | self.group = std.event.Group(anyerror!void).init(&self.loop); | |
| 47 | self.group = std.event.Group(anyerror!void).init(allocator); | |
| 53 | 48 | errdefer self.group.deinit(); |
| 54 | 49 | |
| 55 | 50 | self.zig_lib_dir = try introspect.resolveZigLibDir(allocator); |
| ... | ... | @@ -63,13 +58,11 @@ pub const TestContext = struct { |
| 63 | 58 | std.fs.deleteTree(tmp_dir_name) catch {}; |
| 64 | 59 | allocator.free(self.zig_lib_dir); |
| 65 | 60 | self.zig_compiler.deinit(); |
| 66 | self.loop.deinit(); | |
| 67 | 61 | } |
| 68 | 62 | |
| 69 | 63 | fn run(self: *TestContext) !void { |
| 70 | const handle = try self.loop.call(waitForGroup, self); | |
| 71 | defer await handle; | |
| 72 | self.loop.run(); | |
| 64 | const handle = try std.event.Loop.instance.?.call(waitForGroup, self); | |
| 65 | await handle; | |
| 73 | 66 | return self.any_err; |
| 74 | 67 | } |
| 75 | 68 |
src-self-hosted/type.zig+1-1| ... | ... | @@ -178,7 +178,7 @@ pub const Type = struct { |
| 178 | 178 | }, |
| 179 | 179 | .id = id, |
| 180 | 180 | .name = name, |
| 181 | .abi_alignment = AbiAlignment.init(comp.loop), | |
| 181 | .abi_alignment = AbiAlignment.init(), | |
| 182 | 182 | }; |
| 183 | 183 | } |
| 184 | 184 |