authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2022-07-30 11:39:49+02:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2022-08-01 14:51:50+02:00
logcd8070f94f6865959949dbcec6e0e32cd88bb544
tree5eff505123ed4ea2eaefb159943f92748a8d2607
parentff125db53d8c18a63872ebdcdf6dd9653eb3f56b
signaturelock-open Commit is signed but in an unrecognized format.

Removed param_names from Fn inside Module.zig

Removed the copy of param_names inside of Fn and changed to implementation of getParamName to fetch to parameter name from the ZIR. The signature of getParamName was also changed to take an additional *Module argument.

9 files changed, 47 insertions(+), 30 deletions(-)

src/Module.zig+20-18
...@@ -1471,14 +1471,6 @@ pub const Fn = struct {...@@ -1471,14 +1471,6 @@ pub const Fn = struct {
1471 /// TODO apply the same enhancement for param_names below to this field.1471 /// TODO apply the same enhancement for param_names below to this field.
1472 anytype_args: [*]bool,1472 anytype_args: [*]bool,
14731473
1474 /// Prefer to use `getParamName` to access this because of the future improvement
1475 /// we want to do mentioned in the TODO below.
1476 /// Stored in gpa.
1477 /// TODO: change param ZIR instructions to be embedded inside the function
1478 /// ZIR instruction instead of before it, so that `zir_body_inst` can be used to
1479 /// determine param names rather than redundantly storing them here.
1480 param_names: []const [:0]const u8,
1481
1482 /// Precomputed hash for monomorphed_funcs.1474 /// Precomputed hash for monomorphed_funcs.
1483 /// This is important because it may be accessed when resizing monomorphed_funcs1475 /// This is important because it may be accessed when resizing monomorphed_funcs
1484 /// while this Fn has already been added to the set, but does not have the1476 /// while this Fn has already been added to the set, but does not have the
...@@ -1590,18 +1582,28 @@ pub const Fn = struct {...@@ -1590,18 +1582,28 @@ pub const Fn = struct {
1590 gpa.destroy(node);1582 gpa.destroy(node);
1591 it = next;1583 it = next;
1592 }1584 }
1593
1594 for (func.param_names) |param_name| {
1595 gpa.free(param_name);
1596 }
1597 gpa.free(func.param_names);
1598 }1585 }
15991586
1600 pub fn getParamName(func: Fn, index: u32) [:0]const u8 {1587 pub fn getParamName(func: Fn, mod: *Module, index: u32) [:0]const u8 {
1601 // TODO rework ZIR of parameters so that this function looks up1588 const file = mod.declPtr(func.owner_decl).getFileScope();
1602 // param names in ZIR instead of redundantly saving them into Fn.1589
1603 // const zir = func.owner_decl.getFileScope().zir;1590 const tags = file.zir.instructions.items(.tag);
1604 return func.param_names[index];1591 const data = file.zir.instructions.items(.data);
1592
1593 const param_body = file.zir.getParamBody(func.zir_body_inst);
1594 const param = param_body[index];
1595
1596 return switch (tags[param]) {
1597 .param, .param_comptime => blk: {
1598 const extra = file.zir.extraData(Zir.Inst.Param, data[param].pl_tok.payload_index);
1599 break :blk file.zir.nullTerminatedString(extra.data.name);
1600 },
1601 .param_anytype, .param_anytype_comptime => blk: {
1602 const param_data = data[param].str_tok;
1603 break :blk param_data.get(file.zir);
1604 },
1605 else => unreachable,
1606 };
1605 }1607 }
16061608
1607 pub fn hasInferredErrorSet(func: Fn, mod: *Module) bool {1609 pub fn hasInferredErrorSet(func: Fn, mod: *Module) bool {
src/Sema.zig-6
...@@ -7753,11 +7753,6 @@ fn funcCommon(...@@ -7753,11 +7753,6 @@ fn funcCommon(
7753 break :blk if (sema.comptime_args.len == 0) null else sema.comptime_args.ptr;7753 break :blk if (sema.comptime_args.len == 0) null else sema.comptime_args.ptr;
7754 } else null;7754 } else null;
77557755
7756 const param_names = try sema.gpa.alloc([:0]const u8, block.params.items.len);
7757 for (param_names) |*param_name, i| {
7758 param_name.* = try sema.gpa.dupeZ(u8, block.params.items[i].name);
7759 }
7760
7761 const hash = new_func.hash;7756 const hash = new_func.hash;
7762 const fn_payload = try sema.arena.create(Value.Payload.Function);7757 const fn_payload = try sema.arena.create(Value.Payload.Function);
7763 new_func.* = .{7758 new_func.* = .{
...@@ -7771,7 +7766,6 @@ fn funcCommon(...@@ -7771,7 +7766,6 @@ fn funcCommon(
7771 .rbrace_line = src_locs.rbrace_line,7766 .rbrace_line = src_locs.rbrace_line,
7772 .lbrace_column = @truncate(u16, src_locs.columns),7767 .lbrace_column = @truncate(u16, src_locs.columns),
7773 .rbrace_column = @truncate(u16, src_locs.columns >> 16),7768 .rbrace_column = @truncate(u16, src_locs.columns >> 16),
7774 .param_names = param_names,
7775 .branch_quota = default_branch_quota,7769 .branch_quota = default_branch_quota,
7776 .is_noinline = is_noinline,7770 .is_noinline = is_noinline,
7777 };7771 };
src/Zir.zig+21
...@@ -3909,6 +3909,27 @@ pub const FnInfo = struct {...@@ -3909,6 +3909,27 @@ pub const FnInfo = struct {
3909 total_params_len: u32,3909 total_params_len: u32,
3910};3910};
39113911
3912pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const u32 {
3913 const tags = zir.instructions.items(.tag);
3914 const datas = zir.instructions.items(.data);
3915 const inst_data = datas[fn_inst].pl_node;
3916
3917 const param_block_index = switch (tags[fn_inst]) {
3918 .func, .func_inferred => blk: {
3919 const extra = zir.extraData(Inst.Func, inst_data.payload_index);
3920 break :blk extra.data.param_block;
3921 },
3922 .func_fancy => blk: {
3923 const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index);
3924 break :blk extra.data.param_block;
3925 },
3926 else => unreachable,
3927 };
3928
3929 const param_block = zir.extraData(Inst.Block, datas[param_block_index].pl_node.payload_index);
3930 return zir.extra[param_block.end..][0..param_block.data.body_len];
3931}
3932
3912pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {3933pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
3913 const tags = zir.instructions.items(.tag);3934 const tags = zir.instructions.items(.tag);
3914 const datas = zir.instructions.items(.data);3935 const datas = zir.instructions.items(.data);
src/arch/arm/CodeGen.zig+1-1
...@@ -3372,7 +3372,7 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32, stack_byte_c...@@ -3372,7 +3372,7 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32, stack_byte_c
33723372
3373 const mcv = self.args[arg_index];3373 const mcv = self.args[arg_index];
3374 const ty = self.air.instructions.items(.data)[inst].ty;3374 const ty = self.air.instructions.items(.data)[inst].ty;
3375 const name = self.mod_fn.getParamName(arg_index);3375 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
3376 const name_with_null = name.ptr[0 .. name.len + 1];3376 const name_with_null = name.ptr[0 .. name.len + 1];
33773377
3378 switch (mcv) {3378 switch (mcv) {
src/arch/riscv64/CodeGen.zig+1-1
...@@ -1619,7 +1619,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1619,7 +1619,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
16191619
1620fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {1620fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {
1621 const ty = self.air.instructions.items(.data)[inst].ty;1621 const ty = self.air.instructions.items(.data)[inst].ty;
1622 const name = self.mod_fn.getParamName(arg_index);1622 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
1623 const name_with_null = name.ptr[0 .. name.len + 1];1623 const name_with_null = name.ptr[0 .. name.len + 1];
16241624
1625 switch (mcv) {1625 switch (mcv) {
src/arch/sparc64/CodeGen.zig+1-1
...@@ -2959,7 +2959,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live...@@ -2959,7 +2959,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
29592959
2960fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {2960fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {
2961 const ty = self.air.instructions.items(.data)[inst].ty;2961 const ty = self.air.instructions.items(.data)[inst].ty;
2962 const name = self.mod_fn.getParamName(arg_index);2962 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
2963 const name_with_null = name.ptr[0 .. name.len + 1];2963 const name_with_null = name.ptr[0 .. name.len + 1];
29642964
2965 switch (mcv) {2965 switch (mcv) {
src/arch/wasm/CodeGen.zig+1-1
...@@ -1991,7 +1991,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) InnerError!WValue {...@@ -1991,7 +1991,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
1991 switch (self.debug_output) {1991 switch (self.debug_output) {
1992 .dwarf => |dwarf| {1992 .dwarf => |dwarf| {
1993 // TODO: Get the original arg index rather than wasm arg index1993 // TODO: Get the original arg index rather than wasm arg index
1994 const name = self.mod_fn.getParamName(arg_index);1994 const name = self.mod_fn.getParamName(self.bin_file.base.options.module.?, arg_index);
1995 const leb_size = link.File.Wasm.getULEB128Size(arg.local);1995 const leb_size = link.File.Wasm.getULEB128Size(arg.local);
1996 const dbg_info = &dwarf.dbg_info;1996 const dbg_info = &dwarf.dbg_info;
1997 try dbg_info.ensureUnusedCapacity(3 + leb_size + 5 + name.len + 1);1997 try dbg_info.ensureUnusedCapacity(3 + leb_size + 5 + name.len + 1);
src/arch/x86_64/CodeGen.zig+1-1
...@@ -3789,7 +3789,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -3789,7 +3789,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
37893789
3790 const ty = self.air.typeOfIndex(inst);3790 const ty = self.air.typeOfIndex(inst);
3791 const mcv = self.args[arg_index];3791 const mcv = self.args[arg_index];
3792 const name = self.mod_fn.getParamName(arg_index);3792 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
3793 const name_with_null = name.ptr[0 .. name.len + 1];3793 const name_with_null = name.ptr[0 .. name.len + 1];
37943794
3795 if (self.liveness.isUnused(inst))3795 if (self.liveness.isUnused(inst))
src/codegen/llvm.zig+1-1
...@@ -7313,7 +7313,7 @@ pub const FuncGen = struct {...@@ -7313,7 +7313,7 @@ pub const FuncGen = struct {
7313 const lbrace_col = func.lbrace_column + 1;7313 const lbrace_col = func.lbrace_column + 1;
7314 const di_local_var = dib.createParameterVariable(7314 const di_local_var = dib.createParameterVariable(
7315 self.di_scope.?,7315 self.di_scope.?,
7316 func.getParamName(src_index).ptr, // TODO test 0 bit args7316 func.getParamName(self.dg.module, src_index).ptr, // TODO test 0 bit args
7317 self.di_file.?,7317 self.di_file.?,
7318 lbrace_line,7318 lbrace_line,
7319 try self.dg.object.lowerDebugType(inst_ty, .full),7319 try self.dg.object.lowerDebugType(inst_ty, .full),