authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-27 19:51:06+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-27 19:51:06+01:00
loga8987291390d80ad9e2bb45ba225313a108eed0b
tree47ff80a5d12a9f57808a83d5f965269686893289
parentb25efb86e1b1b2a9e8aa269bf83b717d54f7e276

self-hosted: remove allocateDeclIndexes from the public link.File API


4 files changed, 5 insertions(+), 66 deletions(-)

src/Module.zig-26
......@@ -4585,7 +4585,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
45854585 // We don't fully codegen the decl until later, but we do need to reserve a global
45864586 // offset table index for it. This allows us to codegen decls out of dependency
45874587 // order, increasing how many computations can be done in parallel.
4588 try mod.comp.bin_file.allocateDeclIndexes(decl_index);
45894588 try mod.comp.work_queue.writeItem(.{ .codegen_func = func });
45904589 if (type_changed and mod.emit_h != null) {
45914590 try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index });
......@@ -4697,7 +4696,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
46974696 // codegen backend wants full access to the Decl Type.
46984697 try sema.resolveTypeFully(decl.ty);
46994698
4700 try mod.comp.bin_file.allocateDeclIndexes(decl_index);
47014699 try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
47024700
47034701 if (type_changed and mod.emit_h != null) {
......@@ -5315,29 +5313,6 @@ pub fn deleteUnusedDecl(mod: *Module, decl_index: Decl.Index) void {
53155313 const decl = mod.declPtr(decl_index);
53165314 log.debug("deleteUnusedDecl {d} ({s})", .{ decl_index, decl.name });
53175315
5318 // TODO: remove `allocateDeclIndexes` and make the API that the linker backends
5319 // are required to notice the first time `updateDecl` happens and keep track
5320 // of it themselves. However they can rely on getting a `freeDecl` call if any
5321 // `updateDecl` or `updateFunc` calls happen. This will allow us to avoid any call
5322 // into the linker backend here, since the linker backend will never have been told
5323 // about the Decl in the first place.
5324 // Until then, we did call `allocateDeclIndexes` on this anonymous Decl and so we
5325 // must call `freeDecl` in the linker backend now.
5326 switch (mod.comp.bin_file.tag) {
5327 .coff,
5328 .elf,
5329 .macho,
5330 .c,
5331 .wasm,
5332 => {}, // this linker backend has already migrated to the new API
5333
5334 else => if (decl.has_tv) {
5335 if (decl.ty.isFnOrHasRuntimeBits()) {
5336 mod.comp.bin_file.freeDecl(decl_index);
5337 }
5338 },
5339 }
5340
53415316 assert(!mod.declIsRoot(decl_index));
53425317 assert(decl.src_namespace.anon_decls.swapRemove(decl_index));
53435318
......@@ -5822,7 +5797,6 @@ pub fn initNewAnonDecl(
58225797 // the Decl will be garbage collected by the `codegen_decl` task instead of sent
58235798 // to the linker.
58245799 if (typed_value.ty.isFnOrHasRuntimeBits()) {
5825 try mod.comp.bin_file.allocateDeclIndexes(new_decl_index);
58265800 try mod.comp.anon_work_queue.writeItem(.{ .codegen_decl = new_decl_index });
58275801 }
58285802}
src/Sema.zig-1
......@@ -7510,7 +7510,6 @@ fn resolveGenericInstantiationType(
75107510 // Queue up a `codegen_func` work item for the new Fn. The `comptime_args` field
75117511 // will be populated, ensuring it will have `analyzeBody` called with the ZIR
75127512 // parameters mapped appropriately.
7513 try mod.comp.bin_file.allocateDeclIndexes(new_decl_index);
75147513 try mod.comp.work_queue.writeItem(.{ .codegen_func = new_func });
75157514 return new_func;
75167515}
src/link.zig+3-32
......@@ -533,8 +533,7 @@ pub const File = struct {
533533 }
534534 }
535535
536 /// May be called before or after updateDeclExports but must be called
537 /// after allocateDeclIndexes for any given Decl.
536 /// May be called before or after updateDeclExports for any given Decl.
538537 pub fn updateDecl(base: *File, module: *Module, decl_index: Module.Decl.Index) UpdateDeclError!void {
539538 const decl = module.declPtr(decl_index);
540539 log.debug("updateDecl {*} ({s}), type={}", .{ decl, decl.name, decl.ty.fmtDebug() });
......@@ -557,8 +556,7 @@ pub const File = struct {
557556 }
558557 }
559558
560 /// May be called before or after updateDeclExports but must be called
561 /// after allocateDeclIndexes for any given Decl.
559 /// May be called before or after updateDeclExports for any given Decl.
562560 pub fn updateFunc(base: *File, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) UpdateDeclError!void {
563561 const owner_decl = module.declPtr(func.owner_decl);
564562 log.debug("updateFunc {*} ({s}), type={}", .{
......@@ -602,32 +600,6 @@ pub const File = struct {
602600 }
603601 }
604602
605 /// Must be called before any call to updateDecl or updateDeclExports for
606 /// any given Decl.
607 /// TODO we're transitioning to deleting this function and instead having
608 /// each linker backend notice the first time updateDecl or updateFunc is called, or
609 /// a callee referenced from AIR.
610 pub fn allocateDeclIndexes(base: *File, decl_index: Module.Decl.Index) error{OutOfMemory}!void {
611 const decl = base.options.module.?.declPtr(decl_index);
612 log.debug("allocateDeclIndexes {*} ({s})", .{ decl, decl.name });
613 if (build_options.only_c) {
614 assert(base.tag == .c);
615 return;
616 }
617 switch (base.tag) {
618 .plan9 => return @fieldParentPtr(Plan9, "base", base).allocateDeclIndexes(decl_index),
619
620 .coff,
621 .elf,
622 .macho,
623 .c,
624 .spirv,
625 .nvptx,
626 .wasm,
627 => {},
628 }
629 }
630
631603 pub fn releaseLock(self: *File) void {
632604 if (self.lock) |*lock| {
633605 lock.release();
......@@ -878,8 +850,7 @@ pub const File = struct {
878850 AnalysisFail,
879851 };
880852
881 /// May be called before or after updateDecl, but must be called after
882 /// allocateDeclIndexes for any given Decl.
853 /// May be called before or after updateDecl for any given Decl.
883854 pub fn updateDeclExports(
884855 base: *File,
885856 module: *Module,
src/link/Plan9.zig+2-7
......@@ -424,7 +424,7 @@ fn updateFinish(self: *Plan9, decl: *Module.Decl) !void {
424424 // write the internal linker metadata
425425 decl.link.plan9.type = sym_t;
426426 // write the symbol
427 // we already have the got index because that got allocated in allocateDeclIndexes
427 // we already have the got index
428428 const sym: aout.Sym = .{
429429 .value = undefined, // the value of stuff gets filled in in flushModule
430430 .type = decl.link.plan9.type,
......@@ -737,7 +737,7 @@ fn addDeclExports(
737737
738738pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void {
739739 // TODO audit the lifetimes of decls table entries. It's possible to get
740 // allocateDeclIndexes and then freeDecl without any updateDecl in between.
740 // freeDecl without any updateDecl in between.
741741 // However that is planned to change, see the TODO comment in Module.zig
742742 // in the deleteUnusedDecl function.
743743 const mod = self.base.options.module.?;
......@@ -959,11 +959,6 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
959959 }
960960}
961961
962/// this will be removed, moved to updateFinish
963pub fn allocateDeclIndexes(self: *Plan9, decl_index: Module.Decl.Index) !void {
964 _ = self;
965 _ = decl_index;
966}
967962/// Must be called only after a successful call to `updateDecl`.
968963pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl: *const Module.Decl) !void {
969964 _ = self;