diff options
| author | antlilja <liljaanton2001@gmail.com> | 2022-07-30 11:39:49 +0200 |
|---|---|---|
| committer | antlilja <liljaanton2001@gmail.com> | 2022-08-01 14:51:50 +0200 |
| commit | cd8070f94f6865959949dbcec6e0e32cd88bb544 (patch) | |
| tree | 5eff505123ed4ea2eaefb159943f92748a8d2607 /src/Module.zig | |
| parent | ff125db53d8c18a63872ebdcdf6dd9653eb3f56b (diff) | |
| download | zig-cd8070f94f6865959949dbcec6e0e32cd88bb544.tar.gz zig-cd8070f94f6865959949dbcec6e0e32cd88bb544.zip | |
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.
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/Module.zig b/src/Module.zig index 4ac2775515..b80e00ad59 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1471,14 +1471,6 @@ pub const Fn = struct { /// TODO apply the same enhancement for param_names below to this field. anytype_args: [*]bool, - /// Prefer to use `getParamName` to access this because of the future improvement - /// we want to do mentioned in the TODO below. - /// Stored in gpa. - /// TODO: change param ZIR instructions to be embedded inside the function - /// ZIR instruction instead of before it, so that `zir_body_inst` can be used to - /// determine param names rather than redundantly storing them here. - param_names: []const [:0]const u8, - /// Precomputed hash for monomorphed_funcs. /// This is important because it may be accessed when resizing monomorphed_funcs /// while this Fn has already been added to the set, but does not have the @@ -1590,18 +1582,28 @@ pub const Fn = struct { gpa.destroy(node); it = next; } - - for (func.param_names) |param_name| { - gpa.free(param_name); - } - gpa.free(func.param_names); } - pub fn getParamName(func: Fn, index: u32) [:0]const u8 { - // TODO rework ZIR of parameters so that this function looks up - // param names in ZIR instead of redundantly saving them into Fn. - // const zir = func.owner_decl.getFileScope().zir; - return func.param_names[index]; + pub fn getParamName(func: Fn, mod: *Module, index: u32) [:0]const u8 { + const file = mod.declPtr(func.owner_decl).getFileScope(); + + const tags = file.zir.instructions.items(.tag); + const data = file.zir.instructions.items(.data); + + const param_body = file.zir.getParamBody(func.zir_body_inst); + const param = param_body[index]; + + return switch (tags[param]) { + .param, .param_comptime => blk: { + const extra = file.zir.extraData(Zir.Inst.Param, data[param].pl_tok.payload_index); + break :blk file.zir.nullTerminatedString(extra.data.name); + }, + .param_anytype, .param_anytype_comptime => blk: { + const param_data = data[param].str_tok; + break :blk param_data.get(file.zir); + }, + else => unreachable, + }; } pub fn hasInferredErrorSet(func: Fn, mod: *Module) bool { |
