std.builtin: make global linkage fields lowercase

This commit is contained in:
Tristan Ross 2024-02-18 21:25:23 -08:00
parent aab84a3dec
commit c260b4c753
No known key found for this signature in database
GPG key ID: B09C422035669AF8
15 changed files with 48 additions and 48 deletions

View file

@ -8356,7 +8356,7 @@ test "main" {
</p> </p>
{#code_begin|obj|export_builtin#} {#code_begin|obj|export_builtin#}
comptime { comptime {
@export(internalName, .{ .name = "foo", .linkage = .Strong }); @export(internalName, .{ .name = "foo", .linkage = .strong });
} }
fn internalName() callconv(.C) void {} fn internalName() callconv(.C) void {}

View file

@ -162,7 +162,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
} }
} }
const linkage = if (builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak; const linkage = if (builtin.is_test) std.builtin.GlobalLinkage.internal else std.builtin.GlobalLinkage.weak;
fn exportIt() void { fn exportIt() void {
@export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage }); @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage });

View file

@ -2,12 +2,12 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const native_endian = builtin.cpu.arch.endian(); const native_endian = builtin.cpu.arch.endian();
pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak; pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .weak;
/// Determines the symbol's visibility to other objects. /// Determines the symbol's visibility to other objects.
/// For WebAssembly this allows the symbol to be resolved to other modules, but will not /// For WebAssembly this allows the symbol to be resolved to other modules, but will not
/// export it to the host runtime. /// export it to the host runtime.
pub const visibility: std.builtin.SymbolVisibility = pub const visibility: std.builtin.SymbolVisibility =
if (builtin.target.isWasm() and linkage != .Internal) .hidden else .default; if (builtin.target.isWasm() and linkage != .internal) .hidden else .default;
pub const want_aeabi = switch (builtin.abi) { pub const want_aeabi = switch (builtin.abi) {
.eabi, .eabi,
.eabihf, .eabihf,

View file

@ -64,10 +64,10 @@ pub const StackTrace = struct {
/// This data structure is used by the Zig language code generation and /// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation. /// therefore must be kept in sync with the compiler implementation.
pub const GlobalLinkage = enum { pub const GlobalLinkage = enum {
Internal, internal,
Strong, strong,
Weak, weak,
LinkOnce, link_once,
}; };
/// This data structure is used by the Zig language code generation and /// This data structure is used by the Zig language code generation and
@ -659,7 +659,7 @@ pub const PrefetchOptions = struct {
/// therefore must be kept in sync with the compiler implementation. /// therefore must be kept in sync with the compiler implementation.
pub const ExportOptions = struct { pub const ExportOptions = struct {
name: []const u8, name: []const u8,
linkage: GlobalLinkage = .Strong, linkage: GlobalLinkage = .strong,
section: ?[]const u8 = null, section: ?[]const u8 = null,
visibility: SymbolVisibility = .default, visibility: SymbolVisibility = .default,
}; };
@ -669,7 +669,7 @@ pub const ExportOptions = struct {
pub const ExternOptions = struct { pub const ExternOptions = struct {
name: []const u8, name: []const u8,
library_name: ?[]const u8 = null, library_name: ?[]const u8 = null,
linkage: GlobalLinkage = .Strong, linkage: GlobalLinkage = .strong,
is_thread_local: bool = false, is_thread_local: bool = false,
}; };

View file

@ -8,7 +8,7 @@ const windows = std.os.windows;
const system = std.os.system; const system = std.os.system;
pub const DynLib = switch (builtin.os.tag) { pub const DynLib = switch (builtin.os.tag) {
.linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .Static) .linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .static)
ElfDynLib ElfDynLib
else else
DlDynLib, DlDynLib,

View file

@ -279,7 +279,7 @@ pub const Export = struct {
pub const Options = struct { pub const Options = struct {
name: InternPool.NullTerminatedString, name: InternPool.NullTerminatedString,
linkage: std.builtin.GlobalLinkage = .Strong, linkage: std.builtin.GlobalLinkage = .strong,
section: InternPool.OptionalNullTerminatedString = .none, section: InternPool.OptionalNullTerminatedString = .none,
visibility: std.builtin.SymbolVisibility = .default, visibility: std.builtin.SymbolVisibility = .default,
}; };

View file

@ -6274,7 +6274,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
.needed_comptime_reason = "export target must be comptime-known", .needed_comptime_reason = "export target must be comptime-known",
}); });
const options = try sema.resolveExportOptions(block, options_src, extra.options); const options = try sema.resolveExportOptions(block, options_src, extra.options);
if (options.linkage == .Internal) if (options.linkage == .internal)
return; return;
if (operand.val.getFunction(mod)) |function| { if (operand.val.getFunction(mod)) |function| {
const decl_index = function.owner_decl; const decl_index = function.owner_decl;
@ -6301,7 +6301,7 @@ pub fn analyzeExport(
const gpa = sema.gpa; const gpa = sema.gpa;
const mod = sema.mod; const mod = sema.mod;
if (options.linkage == .Internal) if (options.linkage == .internal)
return; return;
try mod.ensureDeclAnalyzed(exported_decl_index); try mod.ensureDeclAnalyzed(exported_decl_index);
@ -23802,7 +23802,7 @@ fn resolveExportOptions(
return sema.fail(block, name_src, "exported symbol name cannot be empty", .{}); return sema.fail(block, name_src, "exported symbol name cannot be empty", .{});
} }
if (visibility != .default and linkage == .Internal) { if (visibility != .default and linkage == .internal) {
return sema.fail(block, visibility_src, "symbol '{s}' exported with internal linkage has non-default visibility {s}", .{ return sema.fail(block, visibility_src, "symbol '{s}' exported with internal linkage has non-default visibility {s}", .{
name, @tagName(visibility), name, @tagName(visibility),
}); });
@ -25888,7 +25888,7 @@ fn resolveExternOptions(
) CompileError!struct { ) CompileError!struct {
name: InternPool.NullTerminatedString, name: InternPool.NullTerminatedString,
library_name: InternPool.OptionalNullTerminatedString = .none, library_name: InternPool.OptionalNullTerminatedString = .none,
linkage: std.builtin.GlobalLinkage = .Strong, linkage: std.builtin.GlobalLinkage = .strong,
is_thread_local: bool = false, is_thread_local: bool = false,
} { } {
const mod = sema.mod; const mod = sema.mod;
@ -25938,7 +25938,7 @@ fn resolveExternOptions(
return sema.fail(block, name_src, "extern symbol name cannot be empty", .{}); return sema.fail(block, name_src, "extern symbol name cannot be empty", .{});
} }
if (linkage != .Weak and linkage != .Strong) { if (linkage != .weak and linkage != .strong) {
return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{}); return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});
} }
@ -25984,7 +25984,7 @@ fn zirBuiltinExtern(
else => |e| return e, else => |e| return e,
}; };
if (options.linkage == .Weak and !ty.ptrAllowsZero(mod)) { if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {
ty = try mod.optionalType(ty.toIntern()); ty = try mod.optionalType(ty.toIntern());
} }
const ptr_info = ty.ptrInfo(mod); const ptr_info = ty.ptrInfo(mod);
@ -26010,7 +26010,7 @@ fn zirBuiltinExtern(
.is_extern = true, .is_extern = true,
.is_const = ptr_info.flags.is_const, .is_const = ptr_info.flags.is_const,
.is_threadlocal = options.is_thread_local, .is_threadlocal = options.is_thread_local,
.is_weak_linkage = options.linkage == .Weak, .is_weak_linkage = options.linkage == .weak,
} }), } }),
), ),
}, options.name); }, options.name);

View file

@ -1999,7 +1999,7 @@ pub const DeclGen = struct {
try fwd.writeAll(if (is_global) "zig_extern " else "static "); try fwd.writeAll(if (is_global) "zig_extern " else "static ");
const maybe_exports = dg.module.decl_exports.get(decl_index); const maybe_exports = dg.module.decl_exports.get(decl_index);
const export_weak_linkage = if (maybe_exports) |exports| const export_weak_linkage = if (maybe_exports) |exports|
exports.items[0].opts.linkage == .Weak exports.items[0].opts.linkage == .weak
else else
false; false;
if (variable.is_weak_linkage or export_weak_linkage) try fwd.writeAll("zig_weak_linkage "); if (variable.is_weak_linkage or export_weak_linkage) try fwd.writeAll("zig_weak_linkage ");
@ -2689,7 +2689,7 @@ fn genExports(o: *Object) !void {
const is_variable_const = switch (ip.indexToKey(tv.val.toIntern())) { const is_variable_const = switch (ip.indexToKey(tv.val.toIntern())) {
.func => return for (exports.items[1..], 1..) |@"export", i| { .func => return for (exports.items[1..], 1..) |@"export", i| {
try fwd.writeAll("zig_extern "); try fwd.writeAll("zig_extern ");
if (@"export".opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage_fn "); if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage_fn ");
try o.dg.renderFunctionSignature( try o.dg.renderFunctionSignature(
fwd, fwd,
decl_index, decl_index,
@ -2707,7 +2707,7 @@ fn genExports(o: *Object) !void {
}; };
for (exports.items[1..]) |@"export"| { for (exports.items[1..]) |@"export"| {
try fwd.writeAll("zig_extern "); try fwd.writeAll("zig_extern ");
if (@"export".opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage "); if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage ");
const export_name = ip.stringToSlice(@"export".opts.name); const export_name = ip.stringToSlice(@"export".opts.name);
try o.dg.renderTypeAndName( try o.dg.renderTypeAndName(
fwd, fwd,
@ -2842,7 +2842,7 @@ pub fn genFunc(f: *Function) !void {
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static "); try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
if (mod.decl_exports.get(decl_index)) |exports| if (mod.decl_exports.get(decl_index)) |exports|
if (exports.items[0].opts.linkage == .Weak) try fwd_decl_writer.writeAll("zig_weak_linkage_fn "); if (exports.items[0].opts.linkage == .weak) try fwd_decl_writer.writeAll("zig_weak_linkage_fn ");
try o.dg.renderFunctionSignature(fwd_decl_writer, decl_index, .forward, .{ .export_index = 0 }); try o.dg.renderFunctionSignature(fwd_decl_writer, decl_index, .forward, .{ .export_index = 0 });
try fwd_decl_writer.writeAll(";\n"); try fwd_decl_writer.writeAll(";\n");
try genExports(o); try genExports(o);

View file

@ -1873,10 +1873,10 @@ pub const Object = struct {
if (comp.config.dll_export_fns) if (comp.config.dll_export_fns)
global_index.setDllStorageClass(.dllexport, &o.builder); global_index.setDllStorageClass(.dllexport, &o.builder);
global_index.setLinkage(switch (exports[0].opts.linkage) { global_index.setLinkage(switch (exports[0].opts.linkage) {
.Internal => unreachable, .internal => unreachable,
.Strong => .external, .strong => .external,
.Weak => .weak_odr, .weak => .weak_odr,
.LinkOnce => .linkonce_odr, .link_once => .linkonce_odr,
}, &o.builder); }, &o.builder);
global_index.setVisibility(switch (exports[0].opts.visibility) { global_index.setVisibility(switch (exports[0].opts.visibility) {
.default => .default, .default => .default,

View file

@ -1599,11 +1599,11 @@ pub fn updateExports(
} }
} }
if (exp.opts.linkage == .LinkOnce) { if (exp.opts.linkage == .link_once) {
try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create( try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
gpa, gpa,
exp.getSrcLoc(mod), exp.getSrcLoc(mod),
"Unimplemented: GlobalLinkage.LinkOnce", "Unimplemented: GlobalLinkage.link_once",
.{}, .{},
)); ));
continue; continue;
@ -1633,11 +1633,11 @@ pub fn updateExports(
sym.type = atom.getSymbol(self).type; sym.type = atom.getSymbol(self).type;
switch (exp.opts.linkage) { switch (exp.opts.linkage) {
.Strong => { .strong => {
sym.storage_class = .EXTERNAL; sym.storage_class = .EXTERNAL;
}, },
.Internal => @panic("TODO Internal"), .internal => @panic("TODO Internal"),
.Weak => @panic("TODO WeakExternal"), .weak => @panic("TODO WeakExternal"),
else => unreachable, else => unreachable,
} }

View file

@ -1436,10 +1436,10 @@ pub fn updateExports(
} }
} }
const stb_bits: u8 = switch (exp.opts.linkage) { const stb_bits: u8 = switch (exp.opts.linkage) {
.Internal => elf.STB_LOCAL, .internal => elf.STB_LOCAL,
.Strong => elf.STB_GLOBAL, .strong => elf.STB_GLOBAL,
.Weak => elf.STB_WEAK, .weak => elf.STB_WEAK,
.LinkOnce => { .link_once => {
try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1); try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create( mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(
gpa, gpa,

View file

@ -1216,11 +1216,11 @@ pub fn updateExports(
continue; continue;
} }
} }
if (exp.opts.linkage == .LinkOnce) { if (exp.opts.linkage == .link_once) {
try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create( try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create(
gpa, gpa,
exp.getSrcLoc(mod), exp.getSrcLoc(mod),
"Unimplemented: GlobalLinkage.LinkOnce", "Unimplemented: GlobalLinkage.link_once",
.{}, .{},
)); ));
continue; continue;
@ -1242,12 +1242,12 @@ pub fn updateExports(
self.symtab.items(.atom)[global_nlist_index] = self.symtab.items(.atom)[nlist_idx]; self.symtab.items(.atom)[global_nlist_index] = self.symtab.items(.atom)[nlist_idx];
switch (exp.opts.linkage) { switch (exp.opts.linkage) {
.Internal => { .internal => {
// Symbol should be hidden, or in MachO lingo, private extern. // Symbol should be hidden, or in MachO lingo, private extern.
global_nlist.n_type |= macho.N_PEXT; global_nlist.n_type |= macho.N_PEXT;
}, },
.Strong => {}, .strong => {},
.Weak => { .weak => {
// Weak linkage is specified as part of n_desc field. // Weak linkage is specified as part of n_desc field.
// Symbol's n_type is like for a symbol with strong linkage. // Symbol's n_type is like for a symbol with strong linkage.
global_nlist.n_desc |= macho.N_WEAK_DEF; global_nlist.n_desc |= macho.N_WEAK_DEF;

View file

@ -896,14 +896,14 @@ pub fn updateExports(
sym.name = export_name; sym.name = export_name;
switch (exp.opts.linkage) { switch (exp.opts.linkage) {
.Internal => { .internal => {
sym.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); sym.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);
}, },
.Weak => { .weak => {
sym.setFlag(.WASM_SYM_BINDING_WEAK); sym.setFlag(.WASM_SYM_BINDING_WEAK);
}, },
.Strong => {}, // symbols are strong by default .strong => {}, // symbols are strong by default
.LinkOnce => { .link_once => {
try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create( try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
gpa, gpa,
decl.srcLoc(mod), decl.srcLoc(mod),

View file

@ -799,8 +799,8 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step {
\\} \\}
\\export var strongBar: usize = 100; \\export var strongBar: usize = 100;
\\comptime { \\comptime {
\\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .Weak }); \\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .weak });
\\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .Strong }); \\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .strong });
\\} \\}
, ,
}); });

View file

@ -1153,7 +1153,7 @@ fn testReexportsZig(b: *Build, opts: Options) *Step {
\\ return x; \\ return x;
\\} \\}
\\comptime { \\comptime {
\\ @export(foo, .{ .name = "bar", .linkage = .Strong }); \\ @export(foo, .{ .name = "bar", .linkage = .strong });
\\} \\}
}); });