authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-02-01 19:32:54+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-02-01 19:32:54+01:00
logbeb20d29db3fe945746581eba5d2f2cae1403cdb
treea5e7a1c3a098c93f5cf8fec062dfbf0f3a85c6af
parent46f54b23ae604c3f99f51ca719d9085530f6b59c

link: remove union types which are now internal to backends


5 files changed, 10 insertions(+), 97 deletions(-)

src/Module.zig+6-50
......@@ -328,8 +328,6 @@ pub const ErrorInt = u32;
328328pub const Export = struct {
329329 options: std.builtin.ExportOptions,
330330 src: LazySrcLoc,
331 /// Represents the position of the export, if any, in the output file.
332 link: link.File.Export,
333331 /// The Decl that performs the export. Note that this is *not* the Decl being exported.
334332 owner_decl: Decl.Index,
335333 /// The Decl containing the export statement. Inline function calls
......@@ -533,16 +531,8 @@ pub const Decl = struct {
533531 /// What kind of a declaration is this.
534532 kind: Kind,
535533
536 /// Represents the position of the code in the output file.
537 /// This is populated regardless of semantic analysis and code generation.
538 link: link.File.LinkBlock,
539
540 /// Represents the function in the linked output file, if the `Decl` is a function.
541 /// This is stored here and not in `Fn` because `Decl` survives across updates but
542 /// `Fn` does not.
543 /// TODO Look into making `Fn` a longer lived structure and moving this field there
544 /// to save on memory usage.
545 fn_link: link.File.LinkFn,
534 /// TODO remove this once Wasm backend catches up
535 fn_link: ?link.File.Wasm.FnData = null,
546536
547537 /// The shallow set of other decls whose typed_value could possibly change if this Decl's
548538 /// typed_value is modified.
......@@ -5258,27 +5248,9 @@ pub fn clearDecl(
52585248 if (decl.ty.isFnOrHasRuntimeBits()) {
52595249 mod.comp.bin_file.freeDecl(decl_index);
52605250
5261 // TODO instead of a union, put this memory trailing Decl objects,
5262 // and allow it to be variably sized.
5263 decl.link = switch (mod.comp.bin_file.tag) {
5264 .coff => .{ .coff = {} },
5265 .elf => .{ .elf = {} },
5266 .macho => .{ .macho = {} },
5267 .plan9 => .{ .plan9 = {} },
5268 .c => .{ .c = {} },
5269 .wasm => .{ .wasm = {} },
5270 .spirv => .{ .spirv = {} },
5271 .nvptx => .{ .nvptx = {} },
5272 };
52735251 decl.fn_link = switch (mod.comp.bin_file.tag) {
5274 .coff => .{ .coff = {} },
5275 .elf => .{ .elf = {} },
5276 .macho => .{ .macho = {} },
5277 .plan9 => .{ .plan9 = {} },
5278 .c => .{ .c = {} },
5279 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },
5280 .spirv => .{ .spirv = {} },
5281 .nvptx => .{ .nvptx = {} },
5252 .wasm => link.File.Wasm.FnData.empty,
5253 else => null,
52825254 };
52835255 }
52845256 if (decl.getInnerNamespace()) |namespace| {
......@@ -5680,25 +5652,9 @@ pub fn allocateNewDecl(
56805652 .deletion_flag = false,
56815653 .zir_decl_index = 0,
56825654 .src_scope = src_scope,
5683 .link = switch (mod.comp.bin_file.tag) {
5684 .coff => .{ .coff = {} },
5685 .elf => .{ .elf = {} },
5686 .macho => .{ .macho = {} },
5687 .plan9 => .{ .plan9 = {} },
5688 .c => .{ .c = {} },
5689 .wasm => .{ .wasm = {} },
5690 .spirv => .{ .spirv = {} },
5691 .nvptx => .{ .nvptx = {} },
5692 },
56935655 .fn_link = switch (mod.comp.bin_file.tag) {
5694 .coff => .{ .coff = {} },
5695 .elf => .{ .elf = {} },
5696 .macho => .{ .macho = {} },
5697 .plan9 => .{ .plan9 = {} },
5698 .c => .{ .c = {} },
5699 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },
5700 .spirv => .{ .spirv = {} },
5701 .nvptx => .{ .nvptx = {} },
5656 .wasm => link.File.Wasm.FnData.empty,
5657 else => null,
57025658 },
57035659 .generation = 0,
57045660 .is_pub = false,
src/Sema.zig-10
......@@ -5564,16 +5564,6 @@ pub fn analyzeExport(
55645564 .visibility = borrowed_options.visibility,
55655565 },
55665566 .src = src,
5567 .link = switch (mod.comp.bin_file.tag) {
5568 .coff => .{ .coff = {} },
5569 .elf => .{ .elf = {} },
5570 .macho => .{ .macho = {} },
5571 .plan9 => .{ .plan9 = {} },
5572 .c => .{ .c = {} },
5573 .wasm => .{ .wasm = {} },
5574 .spirv => .{ .spirv = {} },
5575 .nvptx => .{ .nvptx = {} },
5576 },
55775567 .owner_decl = sema.owner_decl_index,
55785568 .src_decl = block.src_decl,
55795569 .exported_decl = exported_decl_index,
src/arch/wasm/CodeGen.zig+3-3
......@@ -1194,7 +1194,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
11941194 const fn_info = func.decl.ty.fnInfo();
11951195 var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types, fn_info.return_type, func.target);
11961196 defer func_type.deinit(func.gpa);
1197 func.decl.fn_link.wasm.type_index = try func.bin_file.putOrGetFuncType(func_type);
1197 func.decl.fn_link.?.type_index = try func.bin_file.putOrGetFuncType(func_type);
11981198
11991199 var cc_result = try func.resolveCallingConventionValues(func.decl.ty);
12001200 defer cc_result.deinit(func.gpa);
......@@ -2129,12 +2129,12 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
21292129 defer func_type.deinit(func.gpa);
21302130 const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_fn.data.owner_decl);
21312131 const atom = func.bin_file.getAtomPtr(atom_index);
2132 ext_decl.fn_link.wasm.type_index = try func.bin_file.putOrGetFuncType(func_type);
2132 ext_decl.fn_link.?.type_index = try func.bin_file.putOrGetFuncType(func_type);
21332133 try func.bin_file.addOrUpdateImport(
21342134 mem.sliceTo(ext_decl.name, 0),
21352135 atom.getSymbolIndex().?,
21362136 ext_decl.getExternFn().?.lib_name,
2137 ext_decl.fn_link.wasm.type_index,
2137 ext_decl.fn_link.?.type_index,
21382138 );
21392139 break :blk extern_fn.data.owner_decl;
21402140 } else if (func_val.castTag(.decl_ref)) |decl_ref| {
src/link.zig-33
......@@ -261,39 +261,6 @@ pub const File = struct {
261261 /// of this linking operation.
262262 lock: ?Cache.Lock = null,
263263
264 pub const LinkBlock = union {
265 elf: void,
266 coff: void,
267 macho: void,
268 plan9: void,
269 c: void,
270 wasm: void,
271 spirv: void,
272 nvptx: void,
273 };
274
275 pub const LinkFn = union {
276 elf: void,
277 coff: void,
278 macho: void,
279 plan9: void,
280 c: void,
281 wasm: Wasm.FnData,
282 spirv: void,
283 nvptx: void,
284 };
285
286 pub const Export = union {
287 elf: void,
288 coff: void,
289 macho: void,
290 plan9: void,
291 c: void,
292 wasm: void,
293 spirv: void,
294 nvptx: void,
295 };
296
297264 /// Attempts incremental linking, if the file already exists. If
298265 /// incremental linking fails, falls back to truncating the file and
299266 /// rewriting it. A malicious file is detected as incremental link failure
src/link/Wasm.zig+1-1
......@@ -2829,7 +2829,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
28292829 if (decl.isExtern()) continue;
28302830 const atom_index = entry.value_ptr.*;
28312831 if (decl.ty.zigTypeTag() == .Fn) {
2832 try wasm.parseAtom(atom_index, .{ .function = decl.fn_link.wasm });
2832 try wasm.parseAtom(atom_index, .{ .function = decl.fn_link.? });
28332833 } else if (decl.getVariable()) |variable| {
28342834 if (!variable.is_mutable) {
28352835 try wasm.parseAtom(atom_index, .{ .data = .read_only });