aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-05-26 16:04:53 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:55 -0700
commit9cd0ca9f482ef7f76d3f3ca683913e9aceaa47fe (patch)
tree86e9cfb93f1cf8b68aebc83877bef7c24aed47a6 /src/codegen
parentd5f0ee0d62e48e623625779a0cf722c3f0f66921 (diff)
downloadzig-9cd0ca9f482ef7f76d3f3ca683913e9aceaa47fe.tar.gz
zig-9cd0ca9f482ef7f76d3f3ca683913e9aceaa47fe.zip
Module: rename functions to make ownership checks explicit
This makes the difference between `decl.getOwnedFunction` and `decl.val.getFunction` more clear when reading the code.
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig12
-rw-r--r--src/codegen/llvm.zig24
-rw-r--r--src/codegen/spirv.zig6
3 files changed, 21 insertions, 21 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 59d00f5849..ab69514ee1 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -549,12 +549,12 @@ pub const DeclGen = struct {
}
// Chase function values in order to be able to reference the original function.
- if (decl.getFunction(mod)) |func| if (func.owner_decl != decl_index)
+ if (decl.val.getFunction(mod)) |func| if (func.owner_decl != decl_index)
return dg.renderDeclValue(writer, ty, val, func.owner_decl, location);
- if (decl.getExternFunc(mod)) |extern_func| if (extern_func.decl != decl_index)
+ if (decl.val.getExternFunc(mod)) |extern_func| if (extern_func.decl != decl_index)
return dg.renderDeclValue(writer, ty, val, extern_func.decl, location);
- if (decl.getVariable(mod)) |variable| try dg.renderFwdDecl(decl_index, variable);
+ if (decl.val.getVariable(mod)) |variable| try dg.renderFwdDecl(decl_index, variable);
// We shouldn't cast C function pointers as this is UB (when you call
// them). The analysis until now should ensure that the C function
@@ -1580,7 +1580,7 @@ pub const DeclGen = struct {
else => unreachable,
}
}
- if (fn_decl.getFunction(mod)) |func| if (func.is_cold) try w.writeAll("zig_cold ");
+ if (fn_decl.val.getFunction(mod)) |func| if (func.is_cold) try w.writeAll("zig_cold ");
if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn ");
const trailing = try renderTypePrefix(
@@ -2740,13 +2740,13 @@ pub fn genDecl(o: *Object) !void {
const tv: TypedValue = .{ .ty = decl.ty, .val = decl.val };
if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return;
- if (decl.getExternFunc(mod)) |_| {
+ if (tv.val.getExternFunc(mod)) |_| {
const fwd_decl_writer = o.dg.fwd_decl.writer();
try fwd_decl_writer.writeAll("zig_extern ");
try o.dg.renderFunctionSignature(fwd_decl_writer, decl_c_value.decl, .forward, .{ .export_index = 0 });
try fwd_decl_writer.writeAll(";\n");
try genExports(o);
- } else if (decl.getVariable(mod)) |variable| {
+ } else if (tv.val.getVariable(mod)) |variable| {
try o.dg.renderFwdDecl(decl_c_value.decl, variable);
try genExports(o);
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index b84a8c8c07..1d3749f6a3 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1165,7 +1165,7 @@ pub const Object = struct {
di_file = try dg.object.getDIFile(gpa, mod.namespacePtr(decl.src_namespace).file_scope);
const line_number = decl.src_line + 1;
- const is_internal_linkage = decl.getExternFunc(mod) == null and
+ const is_internal_linkage = decl.val.getExternFunc(mod) == null and
!mod.decl_exports.contains(decl_index);
const noret_bit: c_uint = if (fn_info.return_type == .noreturn_type)
llvm.DIFlags.NoReturn
@@ -1274,7 +1274,7 @@ pub const Object = struct {
var free_decl_name = false;
const decl_name = decl_name: {
if (mod.getTarget().isWasm() and try decl.isFunction(mod)) {
- if (mod.intern_pool.stringToSliceUnwrap(decl.getExternFunc(mod).?.lib_name)) |lib_name| {
+ if (mod.intern_pool.stringToSliceUnwrap(decl.getOwnedExternFunc(mod).?.lib_name)) |lib_name| {
if (!std.mem.eql(u8, lib_name, "c")) {
free_decl_name = true;
break :decl_name try std.fmt.allocPrintZ(gpa, "{s}|{s}", .{ decl.name, lib_name });
@@ -1306,7 +1306,7 @@ pub const Object = struct {
di_global.replaceLinkageName(linkage_name);
}
}
- if (decl.getVariable(mod)) |variable| {
+ if (decl.val.getVariable(mod)) |variable| {
if (variable.is_threadlocal) {
llvm_global.setThreadLocalMode(.GeneralDynamicTLSModel);
} else {
@@ -1348,7 +1348,7 @@ pub const Object = struct {
defer gpa.free(section_z);
llvm_global.setSection(section_z);
}
- if (decl.getVariable(mod)) |variable| {
+ if (decl.val.getVariable(mod)) |variable| {
if (variable.is_threadlocal) {
llvm_global.setThreadLocalMode(.GeneralDynamicTLSModel);
}
@@ -1382,7 +1382,7 @@ pub const Object = struct {
llvm_global.setLinkage(.Internal);
if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.Default);
llvm_global.setUnnamedAddr(.True);
- if (decl.getVariable(mod)) |variable| {
+ if (decl.val.getVariable(mod)) |variable| {
const single_threaded = mod.comp.bin_file.options.single_threaded;
if (variable.is_threadlocal and !single_threaded) {
llvm_global.setThreadLocalMode(.GeneralDynamicTLSModel);
@@ -2452,7 +2452,7 @@ pub const DeclGen = struct {
log.debug("gen: {s} type: {}, value: {}", .{
decl.name, decl.ty.fmtDebug(), decl.val.fmtDebug(),
});
- if (decl.getExternFunc(mod)) |extern_func| {
+ if (decl.val.getExternFunc(mod)) |extern_func| {
_ = try dg.resolveLlvmFunction(extern_func.decl);
} else {
const target = mod.getTarget();
@@ -2460,7 +2460,7 @@ pub const DeclGen = struct {
global.setAlignment(decl.getAlignment(mod));
if (decl.@"linksection") |section| global.setSection(section);
assert(decl.has_tv);
- const init_val = if (decl.getVariable(mod)) |variable| init_val: {
+ const init_val = if (decl.val.getVariable(mod)) |variable| init_val: {
break :init_val variable.init.toValue();
} else init_val: {
global.setGlobalConstant(.True);
@@ -2555,7 +2555,7 @@ pub const DeclGen = struct {
} else {
if (target.isWasm()) {
dg.addFnAttrString(llvm_fn, "wasm-import-name", std.mem.sliceTo(decl.name, 0));
- if (mod.intern_pool.stringToSliceUnwrap(decl.getExternFunc(mod).?.lib_name)) |lib_name| {
+ if (mod.intern_pool.stringToSliceUnwrap(decl.getOwnedExternFunc(mod).?.lib_name)) |lib_name| {
if (!std.mem.eql(u8, lib_name, "c")) {
dg.addFnAttrString(llvm_fn, "wasm-import-module", lib_name);
}
@@ -2716,7 +2716,7 @@ pub const DeclGen = struct {
llvm_global.setValueName(decl.name);
llvm_global.setUnnamedAddr(.False);
llvm_global.setLinkage(.External);
- if (decl.getVariable(mod)) |variable| {
+ if (decl.val.getVariable(mod)) |variable| {
const single_threaded = mod.comp.bin_file.options.single_threaded;
if (variable.is_threadlocal and !single_threaded) {
llvm_global.setThreadLocalMode(.GeneralDynamicTLSModel);
@@ -3993,11 +3993,11 @@ pub const DeclGen = struct {
// ... &bar;
// `bar` is just an alias and we actually want to lower a reference to `foo`.
const decl = mod.declPtr(decl_index);
- if (decl.getFunction(mod)) |func| {
+ if (decl.val.getFunction(mod)) |func| {
if (func.owner_decl != decl_index) {
return self.lowerDeclRefValue(tv, func.owner_decl);
}
- } else if (decl.getExternFunc(mod)) |func| {
+ } else if (decl.val.getExternFunc(mod)) |func| {
if (func.decl != decl_index) {
return self.lowerDeclRefValue(tv, func.decl);
}
@@ -7939,7 +7939,7 @@ pub const FuncGen = struct {
}
const src_index = self.air.instructions.items(.data)[inst].arg.src_index;
- const func = self.dg.decl.getFunction(mod).?;
+ const func = self.dg.decl.getOwnedFunction(mod).?;
const lbrace_line = mod.declPtr(func.owner_decl).src_line + func.lbrace_line + 1;
const lbrace_col = func.lbrace_column + 1;
const di_local_var = dib.createParameterVariable(
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig
index 80e98dbcd3..64a0a7ec57 100644
--- a/src/codegen/spirv.zig
+++ b/src/codegen/spirv.zig
@@ -261,7 +261,7 @@ pub const DeclGen = struct {
const entry = try self.decl_link.getOrPut(decl_index);
if (!entry.found_existing) {
// TODO: Extern fn?
- const kind: SpvModule.DeclKind = if (decl.getFunctionIndex(self.module) != .none)
+ const kind: SpvModule.DeclKind = if (decl.val.getFunctionIndex(self.module) != .none)
.func
else
.global;
@@ -1544,7 +1544,7 @@ pub const DeclGen = struct {
const decl_id = self.spv.declPtr(spv_decl_index).result_id;
log.debug("genDecl: id = {}, index = {}, name = {s}", .{ decl_id.id, @enumToInt(spv_decl_index), decl.name });
- if (decl.getFunction(mod)) |_| {
+ if (decl.val.getFunction(mod)) |_| {
assert(decl.ty.zigTypeTag(mod) == .Fn);
const prototype_id = try self.resolveTypeId(decl.ty);
try self.func.prologue.emit(self.spv.gpa, .OpFunction, .{
@@ -1597,7 +1597,7 @@ pub const DeclGen = struct {
try self.generateTestEntryPoint(fqn, spv_decl_index);
}
} else {
- const init_val = if (decl.getVariable(mod)) |payload|
+ const init_val = if (decl.val.getVariable(mod)) |payload|
payload.init.toValue()
else
decl.val;