diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-02-17 22:20:49 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-02-18 16:56:12 -0700 |
| commit | 32edb9b55d0e41a58a11e0437149c4a9705c4699 (patch) | |
| tree | c0497c52c28ae9f97a9fcb5c57fa89e33838f5bd /src/Module.zig | |
| parent | dee96e2e2f464c3b8edc8ec3a63cd3b1860e3a9d (diff) | |
| download | zig-32edb9b55d0e41a58a11e0437149c4a9705c4699.tar.gz zig-32edb9b55d0e41a58a11e0437149c4a9705c4699.zip | |
stage2: eliminate ZIR arg instruction references to ZIR
Prior to this commit, the AIR arg instruction kept a reference to a ZIR
string index for the corresponding parameter name. This is used by DWARF
emitting code. However, this is a design flaw because we want AIR
objects to be independent from ZIR.
This commit saves the parameter names into memory managed by
`Module.Fn`. This is sub-optimal because we should be able to get the
parameter names from the ZIR for a function without having them
redundantly stored along with `Fn` memory. However the current way that
ZIR param instructions are encoded does not support this case. They
appear in the same ZIR body as the function instruction, just before it.
Instead, they should be embedded within the function instruction, which
will allow this TODO to be solved. That improvement is too big for this
commit, however.
After this there is one last dependency to untangle, which is for inline
assembly. The issue for that is #10784.
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/Module.zig b/src/Module.zig index 524e8402cd..15e90ab068 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1370,6 +1370,14 @@ pub const Fn = struct { /// ZIR instruction. zir_body_inst: Zir.Inst.Index, + /// 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, + /// Relative to owner Decl. lbrace_line: u32, /// Relative to owner Decl. @@ -1466,6 +1474,18 @@ 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]; } }; @@ -4606,15 +4626,11 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem runtime_param_index += 1; continue; } - const ty_ref = try sema.addType(param_type); const arg_index = @intCast(u32, sema.air_instructions.len); inner_block.instructions.appendAssumeCapacity(arg_index); sema.air_instructions.appendAssumeCapacity(.{ .tag = .arg, - .data = .{ .ty_str = .{ - .ty = ty_ref, - .str = param.name, - } }, + .data = .{ .ty = param_type }, }); sema.inst_map.putAssumeCapacityNoClobber(inst, Air.indexToRef(arg_index)); total_param_index += 1; |
