From 099f3c4039d5702b073639ef8b55881973b71c80 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 18 Feb 2024 18:28:39 -0800 Subject: std.builtin: make container layout fields lowercase --- src/Module.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 4ad760063b..01a4ed95b2 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -3310,7 +3310,7 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); assert(!small.has_captures_len); assert(!small.has_backing_int); - assert(small.layout == .Auto); + assert(small.layout == .auto); var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; const fields_len = if (small.has_fields_len) blk: { const fields_len = file.zir.extra[extra_index]; @@ -3327,7 +3327,7 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa const tracked_inst = try ip.trackZir(gpa, file, .main_struct_inst); const wip_ty = switch (try ip.getStructType(gpa, .{ - .layout = .Auto, + .layout = .auto, .fields_len = fields_len, .known_non_opv = small.known_non_opv, .requires_comptime = if (small.known_comptime_only) .yes else .unknown, @@ -5969,7 +5969,7 @@ pub fn typeToStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType { pub fn typeToPackedStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType { const s = mod.typeToStruct(ty) orelse return null; - if (s.layout != .Packed) return null; + if (s.layout != .@"packed") return null; return s; } @@ -6185,18 +6185,18 @@ pub fn structFieldAlignment( field_ty: Type, layout: std.builtin.Type.ContainerLayout, ) Alignment { - assert(layout != .Packed); + assert(layout != .@"packed"); if (explicit_alignment != .none) return explicit_alignment; switch (layout) { - .Packed => unreachable, - .Auto => { + .@"packed" => unreachable, + .auto => { if (mod.getTarget().ofmt == .c) { return structFieldAlignmentExtern(mod, field_ty); } else { return field_ty.abiAlignment(mod); } }, - .Extern => return structFieldAlignmentExtern(mod, field_ty), + .@"extern" => return structFieldAlignmentExtern(mod, field_ty), } } @@ -6224,7 +6224,7 @@ pub fn structPackedFieldBitOffset( field_index: u32, ) u16 { const ip = &mod.intern_pool; - assert(struct_type.layout == .Packed); + assert(struct_type.layout == .@"packed"); assert(struct_type.haveLayout(ip)); var bit_sum: u64 = 0; for (0..struct_type.field_types.len) |i| { -- cgit v1.2.3 From c260b4c753d1e5f947e0d33ce39ce173e497309f Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 18 Feb 2024 21:25:23 -0800 Subject: std.builtin: make global linkage fields lowercase --- doc/langref.html.in | 2 +- lib/compiler_rt/clear_cache.zig | 2 +- lib/compiler_rt/common.zig | 4 ++-- lib/std/builtin.zig | 12 ++++++------ lib/std/dynamic_library.zig | 2 +- src/Module.zig | 2 +- src/Sema.zig | 14 +++++++------- src/codegen/c.zig | 8 ++++---- src/codegen/llvm.zig | 8 ++++---- src/link/Coff.zig | 10 +++++----- src/link/Elf/ZigObject.zig | 8 ++++---- src/link/MachO/ZigObject.zig | 10 +++++----- src/link/Wasm/ZigObject.zig | 8 ++++---- test/link/elf.zig | 4 ++-- test/link/macho.zig | 2 +- 15 files changed, 48 insertions(+), 48 deletions(-) (limited to 'src/Module.zig') diff --git a/doc/langref.html.in b/doc/langref.html.in index 5161be8954..6dae425de1 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -8356,7 +8356,7 @@ test "main" {

{#code_begin|obj|export_builtin#} comptime { - @export(internalName, .{ .name = "foo", .linkage = .Strong }); + @export(internalName, .{ .name = "foo", .linkage = .strong }); } fn internalName() callconv(.C) void {} diff --git a/lib/compiler_rt/clear_cache.zig b/lib/compiler_rt/clear_cache.zig index 3f9ecc0132..33d34ee42d 100644 --- a/lib/compiler_rt/clear_cache.zig +++ b/lib/compiler_rt/clear_cache.zig @@ -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 { @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage }); diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig index ea588c0065..38088de7a0 100644 --- a/lib/compiler_rt/common.zig +++ b/lib/compiler_rt/common.zig @@ -2,12 +2,12 @@ const std = @import("std"); const builtin = @import("builtin"); 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. /// For WebAssembly this allows the symbol to be resolved to other modules, but will not /// export it to the host runtime. 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) { .eabi, .eabihf, diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 9006d316ad..587b79fea6 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -64,10 +64,10 @@ pub const StackTrace = struct { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const GlobalLinkage = enum { - Internal, - Strong, - Weak, - LinkOnce, + internal, + strong, + weak, + link_once, }; /// 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. pub const ExportOptions = struct { name: []const u8, - linkage: GlobalLinkage = .Strong, + linkage: GlobalLinkage = .strong, section: ?[]const u8 = null, visibility: SymbolVisibility = .default, }; @@ -669,7 +669,7 @@ pub const ExportOptions = struct { pub const ExternOptions = struct { name: []const u8, library_name: ?[]const u8 = null, - linkage: GlobalLinkage = .Strong, + linkage: GlobalLinkage = .strong, is_thread_local: bool = false, }; diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig index a37e4f6d40..f2a7bdc93b 100644 --- a/lib/std/dynamic_library.zig +++ b/lib/std/dynamic_library.zig @@ -8,7 +8,7 @@ const windows = std.os.windows; const system = std.os.system; 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 else DlDynLib, diff --git a/src/Module.zig b/src/Module.zig index 01a4ed95b2..7d20c0f023 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -279,7 +279,7 @@ pub const Export = struct { pub const Options = struct { name: InternPool.NullTerminatedString, - linkage: std.builtin.GlobalLinkage = .Strong, + linkage: std.builtin.GlobalLinkage = .strong, section: InternPool.OptionalNullTerminatedString = .none, visibility: std.builtin.SymbolVisibility = .default, }; diff --git a/src/Sema.zig b/src/Sema.zig index 1d540752a7..00dd409dd0 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -6274,7 +6274,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError .needed_comptime_reason = "export target must be comptime-known", }); const options = try sema.resolveExportOptions(block, options_src, extra.options); - if (options.linkage == .Internal) + if (options.linkage == .internal) return; if (operand.val.getFunction(mod)) |function| { const decl_index = function.owner_decl; @@ -6301,7 +6301,7 @@ pub fn analyzeExport( const gpa = sema.gpa; const mod = sema.mod; - if (options.linkage == .Internal) + if (options.linkage == .internal) return; try mod.ensureDeclAnalyzed(exported_decl_index); @@ -23802,7 +23802,7 @@ fn resolveExportOptions( 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}", .{ name, @tagName(visibility), }); @@ -25888,7 +25888,7 @@ fn resolveExternOptions( ) CompileError!struct { name: InternPool.NullTerminatedString, library_name: InternPool.OptionalNullTerminatedString = .none, - linkage: std.builtin.GlobalLinkage = .Strong, + linkage: std.builtin.GlobalLinkage = .strong, is_thread_local: bool = false, } { const mod = sema.mod; @@ -25938,7 +25938,7 @@ fn resolveExternOptions( 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", .{}); } @@ -25984,7 +25984,7 @@ fn zirBuiltinExtern( 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()); } const ptr_info = ty.ptrInfo(mod); @@ -26010,7 +26010,7 @@ fn zirBuiltinExtern( .is_extern = true, .is_const = ptr_info.flags.is_const, .is_threadlocal = options.is_thread_local, - .is_weak_linkage = options.linkage == .Weak, + .is_weak_linkage = options.linkage == .weak, } }), ), }, options.name); diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 3da58a48af..5b317e2889 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1999,7 +1999,7 @@ pub const DeclGen = struct { try fwd.writeAll(if (is_global) "zig_extern " else "static "); const maybe_exports = dg.module.decl_exports.get(decl_index); const export_weak_linkage = if (maybe_exports) |exports| - exports.items[0].opts.linkage == .Weak + exports.items[0].opts.linkage == .weak else false; 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())) { .func => return for (exports.items[1..], 1..) |@"export", i| { 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( fwd, decl_index, @@ -2707,7 +2707,7 @@ fn genExports(o: *Object) !void { }; for (exports.items[1..]) |@"export"| { 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); try o.dg.renderTypeAndName( fwd, @@ -2842,7 +2842,7 @@ pub fn genFunc(f: *Function) !void { try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static "); 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 fwd_decl_writer.writeAll(";\n"); try genExports(o); diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 1e8c2a90dd..562579cf71 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1873,10 +1873,10 @@ pub const Object = struct { if (comp.config.dll_export_fns) global_index.setDllStorageClass(.dllexport, &o.builder); global_index.setLinkage(switch (exports[0].opts.linkage) { - .Internal => unreachable, - .Strong => .external, - .Weak => .weak_odr, - .LinkOnce => .linkonce_odr, + .internal => unreachable, + .strong => .external, + .weak => .weak_odr, + .link_once => .linkonce_odr, }, &o.builder); global_index.setVisibility(switch (exports[0].opts.visibility) { .default => .default, diff --git a/src/link/Coff.zig b/src/link/Coff.zig index adea78ca73..206cf7348c 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -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( gpa, exp.getSrcLoc(mod), - "Unimplemented: GlobalLinkage.LinkOnce", + "Unimplemented: GlobalLinkage.link_once", .{}, )); continue; @@ -1633,11 +1633,11 @@ pub fn updateExports( sym.type = atom.getSymbol(self).type; switch (exp.opts.linkage) { - .Strong => { + .strong => { sym.storage_class = .EXTERNAL; }, - .Internal => @panic("TODO Internal"), - .Weak => @panic("TODO WeakExternal"), + .internal => @panic("TODO Internal"), + .weak => @panic("TODO WeakExternal"), else => unreachable, } diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index b6413f7d45..28b8acb51f 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -1436,10 +1436,10 @@ pub fn updateExports( } } const stb_bits: u8 = switch (exp.opts.linkage) { - .Internal => elf.STB_LOCAL, - .Strong => elf.STB_GLOBAL, - .Weak => elf.STB_WEAK, - .LinkOnce => { + .internal => elf.STB_LOCAL, + .strong => elf.STB_GLOBAL, + .weak => elf.STB_WEAK, + .link_once => { try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1); mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create( gpa, diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index fadf80b2c0..bfd02fbd78 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -1216,11 +1216,11 @@ pub fn updateExports( continue; } } - if (exp.opts.linkage == .LinkOnce) { + if (exp.opts.linkage == .link_once) { try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create( gpa, exp.getSrcLoc(mod), - "Unimplemented: GlobalLinkage.LinkOnce", + "Unimplemented: GlobalLinkage.link_once", .{}, )); continue; @@ -1242,12 +1242,12 @@ pub fn updateExports( self.symtab.items(.atom)[global_nlist_index] = self.symtab.items(.atom)[nlist_idx]; switch (exp.opts.linkage) { - .Internal => { + .internal => { // Symbol should be hidden, or in MachO lingo, private extern. global_nlist.n_type |= macho.N_PEXT; }, - .Strong => {}, - .Weak => { + .strong => {}, + .weak => { // Weak linkage is specified as part of n_desc field. // Symbol's n_type is like for a symbol with strong linkage. global_nlist.n_desc |= macho.N_WEAK_DEF; diff --git a/src/link/Wasm/ZigObject.zig b/src/link/Wasm/ZigObject.zig index 5b1c587a74..30aab49cb1 100644 --- a/src/link/Wasm/ZigObject.zig +++ b/src/link/Wasm/ZigObject.zig @@ -896,14 +896,14 @@ pub fn updateExports( sym.name = export_name; switch (exp.opts.linkage) { - .Internal => { + .internal => { sym.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); }, - .Weak => { + .weak => { sym.setFlag(.WASM_SYM_BINDING_WEAK); }, - .Strong => {}, // symbols are strong by default - .LinkOnce => { + .strong => {}, // symbols are strong by default + .link_once => { try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create( gpa, decl.srcLoc(mod), diff --git a/test/link/elf.zig b/test/link/elf.zig index 20cc95c92a..d872796cd4 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -799,8 +799,8 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step { \\} \\export var strongBar: usize = 100; \\comptime { - \\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .Weak }); - \\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .Strong }); + \\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .weak }); + \\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .strong }); \\} , }); diff --git a/test/link/macho.zig b/test/link/macho.zig index 9208995ae0..f2067dd70d 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -1153,7 +1153,7 @@ fn testReexportsZig(b: *Build, opts: Options) *Step { \\ return x; \\} \\comptime { - \\ @export(foo, .{ .name = "bar", .linkage = .Strong }); + \\ @export(foo, .{ .name = "bar", .linkage = .strong }); \\} }); -- cgit v1.2.3