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;...@@ -328,8 +328,6 @@ pub const ErrorInt = u32;
328pub const Export = struct {328pub const Export = struct {
329 options: std.builtin.ExportOptions,329 options: std.builtin.ExportOptions,
330 src: LazySrcLoc,330 src: LazySrcLoc,
331 /// Represents the position of the export, if any, in the output file.
332 link: link.File.Export,
333 /// The Decl that performs the export. Note that this is *not* the Decl being exported.331 /// The Decl that performs the export. Note that this is *not* the Decl being exported.
334 owner_decl: Decl.Index,332 owner_decl: Decl.Index,
335 /// The Decl containing the export statement. Inline function calls333 /// The Decl containing the export statement. Inline function calls
...@@ -533,16 +531,8 @@ pub const Decl = struct {...@@ -533,16 +531,8 @@ pub const Decl = struct {
533 /// What kind of a declaration is this.531 /// What kind of a declaration is this.
534 kind: Kind,532 kind: Kind,
535533
536 /// Represents the position of the code in the output file.534 /// TODO remove this once Wasm backend catches up
537 /// This is populated regardless of semantic analysis and code generation.535 fn_link: ?link.File.Wasm.FnData = null,
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,
546536
547 /// The shallow set of other decls whose typed_value could possibly change if this Decl's537 /// The shallow set of other decls whose typed_value could possibly change if this Decl's
548 /// typed_value is modified.538 /// typed_value is modified.
...@@ -5258,27 +5248,9 @@ pub fn clearDecl(...@@ -5258,27 +5248,9 @@ pub fn clearDecl(
5258 if (decl.ty.isFnOrHasRuntimeBits()) {5248 if (decl.ty.isFnOrHasRuntimeBits()) {
5259 mod.comp.bin_file.freeDecl(decl_index);5249 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 };
5273 decl.fn_link = switch (mod.comp.bin_file.tag) {5251 decl.fn_link = switch (mod.comp.bin_file.tag) {
5274 .coff => .{ .coff = {} },5252 .wasm => link.File.Wasm.FnData.empty,
5275 .elf => .{ .elf = {} },5253 else => null,
5276 .macho => .{ .macho = {} },
5277 .plan9 => .{ .plan9 = {} },
5278 .c => .{ .c = {} },
5279 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },
5280 .spirv => .{ .spirv = {} },
5281 .nvptx => .{ .nvptx = {} },
5282 };5254 };
5283 }5255 }
5284 if (decl.getInnerNamespace()) |namespace| {5256 if (decl.getInnerNamespace()) |namespace| {
...@@ -5680,25 +5652,9 @@ pub fn allocateNewDecl(...@@ -5680,25 +5652,9 @@ pub fn allocateNewDecl(
5680 .deletion_flag = false,5652 .deletion_flag = false,
5681 .zir_decl_index = 0,5653 .zir_decl_index = 0,
5682 .src_scope = src_scope,5654 .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 },
5693 .fn_link = switch (mod.comp.bin_file.tag) {5655 .fn_link = switch (mod.comp.bin_file.tag) {
5694 .coff => .{ .coff = {} },5656 .wasm => link.File.Wasm.FnData.empty,
5695 .elf => .{ .elf = {} },5657 else => null,
5696 .macho => .{ .macho = {} },
5697 .plan9 => .{ .plan9 = {} },
5698 .c => .{ .c = {} },
5699 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },
5700 .spirv => .{ .spirv = {} },
5701 .nvptx => .{ .nvptx = {} },
5702 },5658 },
5703 .generation = 0,5659 .generation = 0,
5704 .is_pub = false,5660 .is_pub = false,
src/Sema.zig-10
...@@ -5564,16 +5564,6 @@ pub fn analyzeExport(...@@ -5564,16 +5564,6 @@ pub fn analyzeExport(
5564 .visibility = borrowed_options.visibility,5564 .visibility = borrowed_options.visibility,
5565 },5565 },
5566 .src = src,5566 .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 },
5577 .owner_decl = sema.owner_decl_index,5567 .owner_decl = sema.owner_decl_index,
5578 .src_decl = block.src_decl,5568 .src_decl = block.src_decl,
5579 .exported_decl = exported_decl_index,5569 .exported_decl = exported_decl_index,
src/arch/wasm/CodeGen.zig+3-3
...@@ -1194,7 +1194,7 @@ fn genFunc(func: *CodeGen) InnerError!void {...@@ -1194,7 +1194,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
1194 const fn_info = func.decl.ty.fnInfo();1194 const fn_info = func.decl.ty.fnInfo();
1195 var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types, fn_info.return_type, func.target);1195 var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types, fn_info.return_type, func.target);
1196 defer func_type.deinit(func.gpa);1196 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
1199 var cc_result = try func.resolveCallingConventionValues(func.decl.ty);1199 var cc_result = try func.resolveCallingConventionValues(func.decl.ty);
1200 defer cc_result.deinit(func.gpa);1200 defer cc_result.deinit(func.gpa);
...@@ -2129,12 +2129,12 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2129,12 +2129,12 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2129 defer func_type.deinit(func.gpa);2129 defer func_type.deinit(func.gpa);
2130 const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_fn.data.owner_decl);2130 const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_fn.data.owner_decl);
2131 const atom = func.bin_file.getAtomPtr(atom_index);2131 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);
2133 try func.bin_file.addOrUpdateImport(2133 try func.bin_file.addOrUpdateImport(
2134 mem.sliceTo(ext_decl.name, 0),2134 mem.sliceTo(ext_decl.name, 0),
2135 atom.getSymbolIndex().?,2135 atom.getSymbolIndex().?,
2136 ext_decl.getExternFn().?.lib_name,2136 ext_decl.getExternFn().?.lib_name,
2137 ext_decl.fn_link.wasm.type_index,2137 ext_decl.fn_link.?.type_index,
2138 );2138 );
2139 break :blk extern_fn.data.owner_decl;2139 break :blk extern_fn.data.owner_decl;
2140 } else if (func_val.castTag(.decl_ref)) |decl_ref| {2140 } else if (func_val.castTag(.decl_ref)) |decl_ref| {
src/link.zig-33
...@@ -261,39 +261,6 @@ pub const File = struct {...@@ -261,39 +261,6 @@ pub const File = struct {
261 /// of this linking operation.261 /// of this linking operation.
262 lock: ?Cache.Lock = null,262 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
297 /// Attempts incremental linking, if the file already exists. If264 /// Attempts incremental linking, if the file already exists. If
298 /// incremental linking fails, falls back to truncating the file and265 /// incremental linking fails, falls back to truncating the file and
299 /// rewriting it. A malicious file is detected as incremental link failure266 /// 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...@@ -2829,7 +2829,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
2829 if (decl.isExtern()) continue;2829 if (decl.isExtern()) continue;
2830 const atom_index = entry.value_ptr.*;2830 const atom_index = entry.value_ptr.*;
2831 if (decl.ty.zigTypeTag() == .Fn) {2831 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.? });
2833 } else if (decl.getVariable()) |variable| {2833 } else if (decl.getVariable()) |variable| {
2834 if (!variable.is_mutable) {2834 if (!variable.is_mutable) {
2835 try wasm.parseAtom(atom_index, .{ .data = .read_only });2835 try wasm.parseAtom(atom_index, .{ .data = .read_only });