Merge pull request #22505 from mlugg/easier-modify-builtin

std.builtin.Type renames, and make it easier to modify std.builtin
This commit is contained in:
Matthew Lugg 2025-01-16 22:20:02 +00:00 committed by GitHub
commit 4d8c24c6c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
92 changed files with 1176 additions and 945 deletions

View file

@ -141,6 +141,7 @@ int main(int argc, char **argv) {
"pub const skip_non_native = false;\n"
"pub const force_gpa = false;\n"
"pub const dev = .core;\n"
"pub const value_interpret_mode = .direct;\n"
, zig_version);
if (written < 100)
panic("unable to write to config.zig file");

View file

@ -9,6 +9,7 @@ const fs = std.fs;
const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
const assert = std.debug.assert;
const DevEnv = @import("src/dev.zig").Env;
const ValueInterpretMode = enum { direct, by_name };
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 14, .patch = 0 };
const stack_size = 46 * 1024 * 1024;
@ -177,6 +178,7 @@ pub fn build(b: *std.Build) !void {
const strip = b.option(bool, "strip", "Omit debug information");
const valgrind = b.option(bool, "valgrind", "Enable valgrind integration");
const pie = b.option(bool, "pie", "Produce a Position Independent Executable");
const value_interpret_mode = b.option(ValueInterpretMode, "value-interpret-mode", "How the compiler translates between 'std.builtin' types and its internal datastructures") orelse .direct;
const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false;
const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: {
@ -234,6 +236,7 @@ pub fn build(b: *std.Build) !void {
exe_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa);
exe_options.addOption(bool, "force_gpa", force_gpa);
exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full);
exe_options.addOption(ValueInterpretMode, "value_interpret_mode", value_interpret_mode);
if (link_libc) {
exe.root_module.link_libc = true;
@ -620,6 +623,23 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
exe_options.addOption(bool, "value_tracing", false);
exe_options.addOption(DevEnv, "dev", .bootstrap);
// zig1 chooses to interpret values by name. The tradeoff is as follows:
//
// * We lose a small amount of performance. This is essentially irrelevant for zig1.
//
// * We lose the ability to perform trivial renames on certain `std.builtin` types without
// zig1.wasm updates. For instance, we cannot rename an enum from PascalCase fields to
// snake_case fields without an update.
//
// * We gain the ability to add and remove fields to and from `std.builtin` types without
// zig1.wasm updates. For instance, we can add a new tag to `CallingConvention` without
// an update.
//
// Because field renames only happen when we apply a breaking change to the language (which
// is becoming progressively rarer), but tags may be added to or removed from target-dependent
// types over time in response to new targets coming into use, we gain more than we lose here.
exe_options.addOption(ValueInterpretMode, "value_interpret_mode", .by_name);
const run_opt = b.addSystemCommand(&.{
"wasm-opt",
"-Oz",

View file

@ -144,13 +144,13 @@ fn putValue(config_header: *ConfigHeader, field_name: []const u8, comptime T: ty
.pointer => |ptr| {
switch (@typeInfo(ptr.child)) {
.array => |array| {
if (ptr.size == .One and array.child == u8) {
if (ptr.size == .one and array.child == u8) {
try config_header.values.put(field_name, .{ .string = v });
return;
}
},
.int => {
if (ptr.size == .Slice and ptr.child == u8) {
if (ptr.size == .slice and ptr.child == u8) {
try config_header.values.put(field_name, .{ .string = v });
return;
}

View file

@ -172,7 +172,7 @@ fn printType(options: *Options, out: anytype, comptime T: type, value: T, indent
return;
},
.pointer => |p| {
if (p.size != .Slice) {
if (p.size != .slice) {
@compileError("Non-slice pointers are not yet supported in build options");
}
@ -318,9 +318,7 @@ fn printStruct(options: *Options, out: anytype, comptime T: type, comptime val:
try out.print(" {p_}: {s}", .{ std.zig.fmtId(field.name), type_name });
}
if (field.default_value != null) {
const default_value = @as(*field.type, @ptrCast(@alignCast(@constCast(field.default_value.?)))).*;
if (field.defaultValue()) |default_value| {
try out.writeAll(" = ");
switch (@typeInfo(@TypeOf(default_value))) {
.@"enum" => try out.print(".{s},\n", .{@tagName(default_value)}),

View file

@ -1366,7 +1366,7 @@ fn maybeUpdateSize(resize_flag: bool) void {
}
}
fn handleSigWinch(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) void {
fn handleSigWinch(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {
_ = info;
_ = ctx_ptr;
assert(sig == posix.SIG.WINCH);

View file

@ -35,7 +35,7 @@ fillFn: *const fn (ptr: *anyopaque, buf: []u8) void,
pub fn init(pointer: anytype, comptime fillFn: fn (ptr: @TypeOf(pointer), buf: []u8) void) Random {
const Ptr = @TypeOf(pointer);
assert(@typeInfo(Ptr) == .pointer); // Must be a pointer
assert(@typeInfo(Ptr).pointer.size == .One); // Must be a single-item pointer
assert(@typeInfo(Ptr).pointer.size == .one); // Must be a single-item pointer
assert(@typeInfo(@typeInfo(Ptr).pointer.child) == .@"struct"); // Must point to a struct
const gen = struct {
fn fill(ptr: *anyopaque, buf: []u8) void {

View file

@ -607,16 +607,24 @@ pub const Type = union(enum) {
/// The type of the sentinel is the element type of the pointer, which is
/// the value of the `child` field in this struct. However there is no way
/// to refer to that type here, so we use pointer to `anyopaque`.
sentinel: ?*const anyopaque,
/// to refer to that type here, so we use `*const anyopaque`.
/// See also: `sentinel`
sentinel_ptr: ?*const anyopaque,
/// Loads the pointer type's sentinel value from `sentinel_ptr`.
/// Returns `null` if the pointer type has no sentinel.
pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child {
const sp: *const ptr.child = @ptrCast(@alignCast(ptr.sentinel_ptr orelse return null));
return sp.*;
}
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Size = enum(u2) {
One,
Many,
Slice,
C,
one,
many,
slice,
c,
};
};
@ -628,8 +636,16 @@ pub const Type = union(enum) {
/// The type of the sentinel is the element type of the array, which is
/// the value of the `child` field in this struct. However there is no way
/// to refer to that type here, so we use pointer to `anyopaque`.
sentinel: ?*const anyopaque,
/// to refer to that type here, so we use `*const anyopaque`.
/// See also: `sentinel`.
sentinel_ptr: ?*const anyopaque,
/// Loads the array type's sentinel value from `sentinel_ptr`.
/// Returns `null` if the array type has no sentinel.
pub inline fn sentinel(comptime arr: Array) ?arr.child {
const sp: *const arr.child = @ptrCast(@alignCast(arr.sentinel_ptr orelse return null));
return sp.*;
}
};
/// This data structure is used by the Zig language code generation and
@ -645,9 +661,20 @@ pub const Type = union(enum) {
pub const StructField = struct {
name: [:0]const u8,
type: type,
default_value: ?*const anyopaque,
/// The type of the default value is the type of this struct field, which
/// is the value of the `type` field in this struct. However there is no
/// way to refer to that type here, so we use `*const anyopaque`.
/// See also: `defaultValue`.
default_value_ptr: ?*const anyopaque,
is_comptime: bool,
alignment: comptime_int,
/// Loads the field's default value from `default_value_ptr`.
/// Returns `null` if the field has no default value.
pub inline fn defaultValue(comptime sf: StructField) ?sf.type {
const dp: *const sf.type = @ptrCast(@alignCast(sf.default_value_ptr orelse return null));
return dp.*;
}
};
/// This data structure is used by the Zig language code generation and

View file

@ -2733,8 +2733,8 @@ pub const Sigaction = switch (native_os) {
=> if (builtin.target.isMusl())
linux.Sigaction
else if (builtin.target.ptrBitWidth() == 64) extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
flags: c_uint,
handler: extern union {
@ -2742,10 +2742,10 @@ pub const Sigaction = switch (native_os) {
sigaction: ?sigaction_fn,
},
mask: sigset_t,
restorer: ?*const fn () callconv(.C) void = null,
restorer: ?*const fn () callconv(.c) void = null,
} else extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
flags: c_uint,
handler: extern union {
@ -2753,12 +2753,12 @@ pub const Sigaction = switch (native_os) {
sigaction: ?sigaction_fn,
},
mask: sigset_t,
restorer: ?*const fn () callconv(.C) void = null,
restorer: ?*const fn () callconv(.c) void = null,
__resv: [1]c_int = .{0},
},
.s390x => if (builtin.abi == .gnu) extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
handler: extern union {
handler: ?handler_fn,
@ -2766,15 +2766,15 @@ pub const Sigaction = switch (native_os) {
},
__glibc_reserved0: c_int = 0,
flags: c_uint,
restorer: ?*const fn () callconv(.C) void = null,
restorer: ?*const fn () callconv(.c) void = null,
mask: sigset_t,
} else linux.Sigaction,
else => linux.Sigaction,
},
.emscripten => emscripten.Sigaction,
.netbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
handler: extern union {
handler: ?handler_fn,
@ -2784,8 +2784,8 @@ pub const Sigaction = switch (native_os) {
flags: c_uint,
},
.dragonfly, .freebsd => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
/// signal handler
handler: extern union {
@ -2798,8 +2798,8 @@ pub const Sigaction = switch (native_os) {
mask: sigset_t,
},
.solaris, .illumos => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
/// signal options
flags: c_uint,
@ -2812,8 +2812,8 @@ pub const Sigaction = switch (native_os) {
mask: sigset_t,
},
.haiku => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
/// signal handler
handler: extern union {
@ -2831,8 +2831,8 @@ pub const Sigaction = switch (native_os) {
userdata: *allowzero anyopaque = undefined,
},
.openbsd => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
/// signal handler
handler: extern union {
@ -6410,7 +6410,7 @@ pub const EAI = switch (native_os) {
else => void,
};
pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.c) c_int;
pub const Stat = switch (native_os) {
.linux => switch (native_arch) {
@ -9396,7 +9396,7 @@ pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
pub extern "c" fn pthread_create(
noalias newthread: *pthread_t,
noalias attr: ?*const pthread_attr_t,
start_routine: *const fn (?*anyopaque) callconv(.C) ?*anyopaque,
start_routine: *const fn (?*anyopaque) callconv(.c) ?*anyopaque,
noalias arg: ?*anyopaque,
) E;
pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E;
@ -9408,13 +9408,13 @@ pub extern "c" fn pthread_self() pthread_t;
pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*anyopaque) E;
pub extern "c" fn pthread_detach(thread: pthread_t) E;
pub extern "c" fn pthread_atfork(
prepare: ?*const fn () callconv(.C) void,
parent: ?*const fn () callconv(.C) void,
child: ?*const fn () callconv(.C) void,
prepare: ?*const fn () callconv(.c) void,
parent: ?*const fn () callconv(.c) void,
child: ?*const fn () callconv(.c) void,
) c_int;
pub extern "c" fn pthread_key_create(
key: *pthread_key_t,
destructor: ?*const fn (value: *anyopaque) callconv(.C) void,
destructor: ?*const fn (value: *anyopaque) callconv(.c) void,
) E;
pub extern "c" fn pthread_key_delete(key: pthread_key_t) E;
pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*anyopaque;
@ -9530,12 +9530,12 @@ pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E;
pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E;
pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E;
pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.c) E;
pub const pthread_t = *opaque {};
pub const FILE = opaque {};

View file

@ -379,7 +379,7 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {
};
extern "c" var mach_task_self_: mach_port_t;
pub fn mach_task_self() callconv(.C) mach_port_t {
pub fn mach_task_self() callconv(.c) mach_port_t {
return mach_task_self_;
}
@ -873,7 +873,7 @@ pub const DISPATCH_TIME_FOREVER = ~@as(dispatch_time_t, 0);
pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t;
const dispatch_once_t = usize;
const dispatch_function_t = fn (?*anyopaque) callconv(.C) void;
const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;
pub extern fn dispatch_once_f(
predicate: *dispatch_once_t,
context: ?*anyopaque,

View file

@ -156,7 +156,7 @@ pub const E = enum(u16) {
pub const BADSIG = SIG.ERR;
pub const sig_t = *const fn (i32) callconv(.C) void;
pub const sig_t = *const fn (i32) callconv(.c) void;
pub const cmsghdr = extern struct {
len: socklen_t,

View file

@ -164,7 +164,7 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
// with default values
var expected_fields: usize = 0;
inline for (comptime meta.fields(HashResult)) |p| {
if (@typeInfo(p.type) != .optional and p.default_value == null) {
if (@typeInfo(p.type) != .optional and p.default_value_ptr == null) {
expected_fields += 1;
}
}

View file

@ -133,7 +133,7 @@ fn setupPthreadAtforkAndFill(buffer: []u8) void {
return initAndFill(buffer);
}
fn childAtForkHandler() callconv(.C) void {
fn childAtForkHandler() callconv(.c) void {
// The atfork handler is global, this function may be called after
// fork()-ing threads that never initialized the CSPRNG context.
if (wipe_mem.len == 0) return;

View file

@ -1269,7 +1269,7 @@ fn resetSegfaultHandler() void {
updateSegfaultHandler(&act);
}
fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) noreturn {
fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) noreturn {
// Reset to the default handler so that if a segfault happens in this handler it will crash
// the process. Also when this handler returns, the original instruction will be repeated
// and the resulting segfault will crash the process rather than continually dump stack traces.

View file

@ -19,7 +19,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def
struct_field.* = .{
.name = enum_field.name ++ "",
.type = Data,
.default_value = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null,
.default_value_ptr = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null,
.is_comptime = false,
.alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,
};

View file

@ -434,7 +434,7 @@ pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @T
switch (@typeInfo(T)) {
.pointer => |info| {
try writer.writeAll(@typeName(info.child) ++ "@");
if (info.size == .Slice)
if (info.size == .slice)
try formatInt(@intFromPtr(value.ptr), 16, .lower, FormatOptions{}, writer)
else
try formatInt(@intFromPtr(value), 16, .lower, FormatOptions{}, writer);
@ -460,12 +460,12 @@ pub fn defaultSpec(comptime T: type) [:0]const u8 {
switch (@typeInfo(T)) {
.array, .vector => return ANY,
.pointer => |ptr_info| switch (ptr_info.size) {
.One => switch (@typeInfo(ptr_info.child)) {
.one => switch (@typeInfo(ptr_info.child)) {
.array => return ANY,
else => {},
},
.Many, .C => return "*",
.Slice => return ANY,
.many, .c => return "*",
.slice => return ANY,
},
.optional => |info| return "?" ++ defaultSpec(info.child),
.error_union => |info| return "!" ++ defaultSpec(info.payload),
@ -624,16 +624,16 @@ pub fn formatType(
try writer.writeAll(" }");
},
.pointer => |ptr_info| switch (ptr_info.size) {
.One => switch (@typeInfo(ptr_info.child)) {
.one => switch (@typeInfo(ptr_info.child)) {
.array, .@"enum", .@"union", .@"struct" => {
return formatType(value.*, actual_fmt, options, writer, max_depth);
},
else => return format(writer, "{s}@{x}", .{ @typeName(ptr_info.child), @intFromPtr(value) }),
},
.Many, .C => {
.many, .c => {
if (actual_fmt.len == 0)
@compileError("cannot format pointer without a specifier (i.e. {s} or {*})");
if (ptr_info.sentinel) |_| {
if (ptr_info.sentinel() != null) {
return formatType(mem.span(value), actual_fmt, options, writer, max_depth);
}
if (actual_fmt[0] == 's' and ptr_info.child == u8) {
@ -641,7 +641,7 @@ pub fn formatType(
}
invalidFmtError(fmt, value);
},
.Slice => {
.slice => {
if (actual_fmt.len == 0)
@compileError("cannot format slice without a specifier (i.e. {s} or {any})");
if (max_depth == 0) {

View file

@ -23,13 +23,13 @@ pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy)
const info = @typeInfo(@TypeOf(key));
switch (info.pointer.size) {
.One => switch (strat) {
.one => switch (strat) {
.Shallow => hash(hasher, @intFromPtr(key), .Shallow),
.Deep => hash(hasher, key.*, .Shallow),
.DeepRecursive => hash(hasher, key.*, .DeepRecursive),
},
.Slice => {
.slice => {
switch (strat) {
.Shallow => {
hashPointer(hasher, key.ptr, .Shallow);
@ -40,8 +40,8 @@ pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy)
hash(hasher, key.len, .Shallow);
},
.Many,
.C,
.many,
.c,
=> switch (strat) {
.Shallow => hash(hasher, @intFromPtr(key), .Shallow),
else => @compileError(
@ -167,7 +167,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
inline fn typeContainsSlice(comptime K: type) bool {
return switch (@typeInfo(K)) {
.pointer => |info| info.size == .Slice,
.pointer => |info| info.size == .slice,
inline .@"struct", .@"union" => |info| {
inline for (info.fields) |field| {

View file

@ -805,7 +805,7 @@ pub fn PollFiles(comptime StreamEnum: type) type {
struct_field.* = .{
.name = enum_field.name ++ "",
.type = fs.File,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(fs.File),
};

View file

@ -118,14 +118,14 @@ fn Slice(comptime T: type) type {
.pointer => |ptr_info| {
var new_ptr_info = ptr_info;
switch (ptr_info.size) {
.Slice => {},
.One => switch (@typeInfo(ptr_info.child)) {
.slice => {},
.one => switch (@typeInfo(ptr_info.child)) {
.array => |info| new_ptr_info.child = info.child,
else => @compileError("invalid type given to fixedBufferStream"),
},
else => @compileError("invalid type given to fixedBufferStream"),
}
new_ptr_info.size = .Slice;
new_ptr_info.size = .slice;
return @Type(.{ .pointer = new_ptr_info });
},
else => @compileError("invalid type given to fixedBufferStream"),

View file

@ -451,12 +451,12 @@ pub fn innerParse(
.pointer => |ptrInfo| {
switch (ptrInfo.size) {
.One => {
.one => {
const r: *ptrInfo.child = try allocator.create(ptrInfo.child);
r.* = try innerParse(ptrInfo.child, allocator, source, options);
return r;
},
.Slice => {
.slice => {
switch (try source.peekNextTokenType()) {
.array_begin => {
_ = try source.next();
@ -476,9 +476,8 @@ pub fn innerParse(
arraylist.appendAssumeCapacity(try innerParse(ptrInfo.child, allocator, source, options));
}
if (ptrInfo.sentinel) |some| {
const sentinel_value = @as(*align(1) const ptrInfo.child, @ptrCast(some)).*;
return try arraylist.toOwnedSliceSentinel(sentinel_value);
if (ptrInfo.sentinel()) |s| {
return try arraylist.toOwnedSliceSentinel(s);
}
return try arraylist.toOwnedSlice();
@ -487,11 +486,11 @@ pub fn innerParse(
if (ptrInfo.child != u8) return error.UnexpectedToken;
// Dynamic length string.
if (ptrInfo.sentinel) |sentinel_ptr| {
if (ptrInfo.sentinel()) |s| {
// Use our own array list so we can append the sentinel.
var value_list = ArrayList(u8).init(allocator);
_ = try source.allocNextIntoArrayList(&value_list, .alloc_always);
return try value_list.toOwnedSliceSentinel(@as(*const u8, @ptrCast(sentinel_ptr)).*);
return try value_list.toOwnedSliceSentinel(s);
}
if (ptrInfo.is_const) {
switch (try source.nextAllocMax(allocator, options.allocate.?, options.max_value_len.?)) {
@ -706,16 +705,16 @@ pub fn innerParseFromValue(
.pointer => |ptrInfo| {
switch (ptrInfo.size) {
.One => {
.one => {
const r: *ptrInfo.child = try allocator.create(ptrInfo.child);
r.* = try innerParseFromValue(ptrInfo.child, allocator, source, options);
return r;
},
.Slice => {
.slice => {
switch (source) {
.array => |array| {
const r = if (ptrInfo.sentinel) |sentinel_ptr|
try allocator.allocSentinel(ptrInfo.child, array.items.len, @as(*align(1) const ptrInfo.child, @ptrCast(sentinel_ptr)).*)
const r = if (ptrInfo.sentinel()) |sentinel|
try allocator.allocSentinel(ptrInfo.child, array.items.len, sentinel)
else
try allocator.alloc(ptrInfo.child, array.items.len);
@ -729,8 +728,8 @@ pub fn innerParseFromValue(
if (ptrInfo.child != u8) return error.UnexpectedToken;
// Dynamic length string.
const r = if (ptrInfo.sentinel) |sentinel_ptr|
try allocator.allocSentinel(ptrInfo.child, s.len, @as(*align(1) const ptrInfo.child, @ptrCast(sentinel_ptr)).*)
const r = if (ptrInfo.sentinel()) |sentinel|
try allocator.allocSentinel(ptrInfo.child, s.len, sentinel)
else
try allocator.alloc(ptrInfo.child, s.len);
@memcpy(r[0..], s);
@ -787,8 +786,7 @@ fn sliceToEnum(comptime T: type, slice: []const u8) !T {
fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".fields.len]bool) !void {
inline for (@typeInfo(T).@"struct".fields, 0..) |field, i| {
if (!fields_seen[i]) {
if (field.default_value) |default_ptr| {
const default = @as(*align(1) const field.type, @ptrCast(default_ptr)).*;
if (field.defaultValue()) |default| {
@field(r, field.name) = default;
} else {
return error.MissingField;

View file

@ -631,7 +631,7 @@ pub fn WriteStream(
},
.error_set => return self.stringValue(@errorName(value)),
.pointer => |ptr_info| switch (ptr_info.size) {
.One => switch (@typeInfo(ptr_info.child)) {
.one => switch (@typeInfo(ptr_info.child)) {
.array => {
// Coerce `*[N]T` to `[]const T`.
const Slice = []const std.meta.Elem(ptr_info.child);
@ -641,10 +641,10 @@ pub fn WriteStream(
return self.write(value.*);
},
},
.Many, .Slice => {
if (ptr_info.size == .Many and ptr_info.sentinel == null)
.many, .slice => {
if (ptr_info.size == .many and ptr_info.sentinel() == null)
@compileError("unable to stringify type '" ++ @typeName(T) ++ "' without sentinel");
const slice = if (ptr_info.size == .Many) std.mem.span(value) else value;
const slice = if (ptr_info.size == .many) std.mem.span(value) else value;
if (ptr_info.child == u8) {
// This is a []const u8, or some similar Zig string.

View file

@ -262,9 +262,9 @@ pub fn zeroes(comptime T: type) T {
},
.pointer => |ptr_info| {
switch (ptr_info.size) {
.Slice => {
if (ptr_info.sentinel) |sentinel| {
if (ptr_info.child == u8 and @as(*const u8, @ptrCast(sentinel)).* == 0) {
.slice => {
if (ptr_info.sentinel()) |sentinel| {
if (ptr_info.child == u8 and sentinel == 0) {
return ""; // A special case for the most common use-case: null-terminated strings.
}
@compileError("Can't set a sentinel slice to zero. This would require allocating memory.");
@ -272,21 +272,17 @@ pub fn zeroes(comptime T: type) T {
return &[_]ptr_info.child{};
}
},
.C => {
.c => {
return null;
},
.One, .Many => {
.one, .many => {
if (ptr_info.is_allowzero) return @ptrFromInt(0);
@compileError("Only nullable and allowzero pointers can be set to zero.");
},
}
},
.array => |info| {
if (info.sentinel) |sentinel_ptr| {
const sentinel = @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*;
return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
}
return [_]info.child{zeroes(info.child)} ** info.len;
return @splat(zeroes(info.child));
},
.vector => |info| {
return @splat(zeroes(info.child));
@ -456,9 +452,8 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
@field(value, field.name) = @field(init, field.name);
},
}
} else if (field.default_value) |default_value_ptr| {
const default_value = @as(*align(1) const field.type, @ptrCast(default_value_ptr)).*;
@field(value, field.name) = default_value;
} else if (field.defaultValue()) |val| {
@field(value, field.name) = val;
} else {
switch (@typeInfo(field.type)) {
.@"struct" => {
@ -781,14 +776,14 @@ fn Span(comptime T: type) type {
.pointer => |ptr_info| {
var new_ptr_info = ptr_info;
switch (ptr_info.size) {
.C => {
new_ptr_info.sentinel = &@as(ptr_info.child, 0);
.c => {
new_ptr_info.sentinel_ptr = &@as(ptr_info.child, 0);
new_ptr_info.is_allowzero = false;
},
.Many => if (ptr_info.sentinel == null) @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
.One, .Slice => @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
.many => if (ptr_info.sentinel() == null) @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
.one, .slice => @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
}
new_ptr_info.size = .Slice;
new_ptr_info.size = .slice;
return @Type(.{ .pointer = new_ptr_info });
},
else => {},
@ -822,8 +817,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
const Result = Span(@TypeOf(ptr));
const l = len(ptr);
const ptr_info = @typeInfo(Result).pointer;
if (ptr_info.sentinel) |s_ptr| {
const s = @as(*align(1) const ptr_info.child, @ptrCast(s_ptr)).*;
if (ptr_info.sentinel()) |s| {
return ptr[0..l :s];
} else {
return ptr[0..l];
@ -845,40 +839,38 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type {
},
.pointer => |ptr_info| {
var new_ptr_info = ptr_info;
new_ptr_info.size = .Slice;
new_ptr_info.size = .slice;
switch (ptr_info.size) {
.One => switch (@typeInfo(ptr_info.child)) {
.one => switch (@typeInfo(ptr_info.child)) {
.array => |array_info| {
new_ptr_info.child = array_info.child;
// The return type must only be sentinel terminated if we are guaranteed
// to find the value searched for, which is only the case if it matches
// the sentinel of the type passed.
if (array_info.sentinel) |sentinel_ptr| {
const sentinel = @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*;
if (end == sentinel) {
new_ptr_info.sentinel = &end;
if (array_info.sentinel()) |s| {
if (end == s) {
new_ptr_info.sentinel_ptr = &end;
} else {
new_ptr_info.sentinel = null;
new_ptr_info.sentinel_ptr = null;
}
}
},
else => {},
},
.Many, .Slice => {
.many, .slice => {
// The return type must only be sentinel terminated if we are guaranteed
// to find the value searched for, which is only the case if it matches
// the sentinel of the type passed.
if (ptr_info.sentinel) |sentinel_ptr| {
const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*;
if (end == sentinel) {
new_ptr_info.sentinel = &end;
if (ptr_info.sentinel()) |s| {
if (end == s) {
new_ptr_info.sentinel_ptr = &end;
} else {
new_ptr_info.sentinel = null;
new_ptr_info.sentinel_ptr = null;
}
}
},
.C => {
new_ptr_info.sentinel = &end;
.c => {
new_ptr_info.sentinel_ptr = &end;
// C pointers are always allowzero, but we don't want the return type to be.
assert(new_ptr_info.is_allowzero);
new_ptr_info.is_allowzero = false;
@ -906,8 +898,7 @@ pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo(
const Result = SliceTo(@TypeOf(ptr), end);
const length = lenSliceTo(ptr, end);
const ptr_info = @typeInfo(Result).pointer;
if (ptr_info.sentinel) |s_ptr| {
const s = @as(*align(1) const ptr_info.child, @ptrCast(s_ptr)).*;
if (ptr_info.sentinel()) |s| {
return ptr[0..length :s];
} else {
return ptr[0..length];
@ -957,11 +948,10 @@ test sliceTo {
fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {
switch (@typeInfo(@TypeOf(ptr))) {
.pointer => |ptr_info| switch (ptr_info.size) {
.One => switch (@typeInfo(ptr_info.child)) {
.one => switch (@typeInfo(ptr_info.child)) {
.array => |array_info| {
if (array_info.sentinel) |sentinel_ptr| {
const sentinel = @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*;
if (sentinel == end) {
if (array_info.sentinel()) |s| {
if (s == end) {
return indexOfSentinel(array_info.child, end, ptr);
}
}
@ -969,27 +959,25 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {
},
else => {},
},
.Many => if (ptr_info.sentinel) |sentinel_ptr| {
const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*;
if (sentinel == end) {
.many => if (ptr_info.sentinel()) |s| {
if (s == end) {
return indexOfSentinel(ptr_info.child, end, ptr);
}
// We're looking for something other than the sentinel,
// but iterating past the sentinel would be a bug so we need
// to check for both.
var i: usize = 0;
while (ptr[i] != end and ptr[i] != sentinel) i += 1;
while (ptr[i] != end and ptr[i] != s) i += 1;
return i;
},
.C => {
.c => {
assert(ptr != null);
return indexOfSentinel(ptr_info.child, end, ptr);
},
.Slice => {
if (ptr_info.sentinel) |sentinel_ptr| {
const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*;
if (sentinel == end) {
return indexOfSentinel(ptr_info.child, sentinel, ptr);
.slice => {
if (ptr_info.sentinel()) |s| {
if (s == end) {
return indexOfSentinel(ptr_info.child, s, ptr);
}
}
return indexOfScalar(ptr_info.child, ptr, end) orelse ptr.len;
@ -1039,13 +1027,12 @@ test lenSliceTo {
pub fn len(value: anytype) usize {
switch (@typeInfo(@TypeOf(value))) {
.pointer => |info| switch (info.size) {
.Many => {
const sentinel_ptr = info.sentinel orelse
.many => {
const sentinel = info.sentinel() orelse
@compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value)));
const sentinel = @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*;
return indexOfSentinel(info.child, sentinel, value);
},
.C => {
.c => {
assert(value != null);
return indexOfSentinel(info.child, 0, value);
},
@ -3582,19 +3569,19 @@ fn ReverseIterator(comptime T: type) type {
const Pointer = blk: {
switch (@typeInfo(T)) {
.pointer => |ptr_info| switch (ptr_info.size) {
.One => switch (@typeInfo(ptr_info.child)) {
.one => switch (@typeInfo(ptr_info.child)) {
.array => |array_info| {
var new_ptr_info = ptr_info;
new_ptr_info.size = .Many;
new_ptr_info.size = .many;
new_ptr_info.child = array_info.child;
new_ptr_info.sentinel = array_info.sentinel;
new_ptr_info.sentinel_ptr = array_info.sentinel_ptr;
break :blk @Type(.{ .pointer = new_ptr_info });
},
else => {},
},
.Slice => {
.slice => {
var new_ptr_info = ptr_info;
new_ptr_info.size = .Many;
new_ptr_info.size = .many;
break :blk @Type(.{ .pointer = new_ptr_info });
},
else => {},
@ -3606,9 +3593,9 @@ fn ReverseIterator(comptime T: type) type {
const Element = std.meta.Elem(Pointer);
const ElementPointer = @Type(.{ .pointer = ptr: {
var ptr = @typeInfo(Pointer).pointer;
ptr.size = .One;
ptr.size = .one;
ptr.child = Element;
ptr.sentinel = null;
ptr.sentinel_ptr = null;
break :ptr ptr;
} });
return struct {
@ -3912,7 +3899,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
const T = @TypeOf(ptr);
const info = @typeInfo(T);
if (info != .pointer or info.pointer.size != .Many)
if (info != .pointer or info.pointer.size != .many)
@compileError("expected many item pointer, got " ++ @typeName(T));
// Do nothing if the pointer is already well-aligned.
@ -3979,16 +3966,16 @@ fn CopyPtrAttrs(
.alignment = info.alignment,
.address_space = info.address_space,
.child = child,
.sentinel = null,
.sentinel_ptr = null,
},
});
}
fn AsBytesReturnType(comptime P: type) type {
const pointer = @typeInfo(P).pointer;
assert(pointer.size == .One);
assert(pointer.size == .one);
const size = @sizeOf(pointer.child);
return CopyPtrAttrs(P, .One, [size]u8);
return CopyPtrAttrs(P, .one, [size]u8);
}
/// Given a pointer to a single item, returns a slice of the underlying bytes, preserving pointer attributes.
@ -4071,7 +4058,7 @@ test toBytes {
}
fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
return CopyPtrAttrs(B, .One, T);
return CopyPtrAttrs(B, .one, T);
}
/// Given a pointer to an array of bytes, returns a pointer to a value of the specified type
@ -4150,7 +4137,7 @@ test bytesToValue {
}
fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type {
return CopyPtrAttrs(bytesType, .Slice, T);
return CopyPtrAttrs(bytesType, .slice, T);
}
/// Given a slice of bytes, returns a slice of the specified type
@ -4162,7 +4149,7 @@ pub fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T,
return &[0]T{};
}
const cast_target = CopyPtrAttrs(@TypeOf(bytes), .Many, T);
const cast_target = CopyPtrAttrs(@TypeOf(bytes), .many, T);
return @as(cast_target, @ptrCast(bytes))[0..@divExact(bytes.len, @sizeOf(T))];
}
@ -4237,7 +4224,7 @@ test "bytesAsSlice preserves pointer attributes" {
}
fn SliceAsBytesReturnType(comptime Slice: type) type {
return CopyPtrAttrs(Slice, .Slice, u8);
return CopyPtrAttrs(Slice, .slice, u8);
}
/// Given a slice, returns a slice of the underlying bytes, preserving pointer attributes.
@ -4251,7 +4238,7 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
// it may be equal to zero and fail a null check
if (slice.len == 0 and std.meta.sentinel(Slice) == null) return &[0]u8{};
const cast_target = CopyPtrAttrs(Slice, .Many, u8);
const cast_target = CopyPtrAttrs(Slice, .many, u8);
return @as(cast_target, @ptrCast(slice))[0 .. slice.len * @sizeOf(std.meta.Elem(Slice))];
}
@ -4540,14 +4527,14 @@ fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) t
const info = @typeInfo(AttributeSource).pointer;
return @Type(.{
.pointer = .{
.size = .Slice,
.size = .slice,
.is_const = info.is_const,
.is_volatile = info.is_volatile,
.is_allowzero = info.is_allowzero,
.alignment = new_alignment,
.address_space = info.address_space,
.child = info.child,
.sentinel = null,
.sentinel_ptr = null,
},
});
}

View file

@ -110,7 +110,7 @@ pub fn create(self: Allocator, comptime T: type) Error!*T {
/// have the same address and alignment property.
pub fn destroy(self: Allocator, ptr: anytype) void {
const info = @typeInfo(@TypeOf(ptr)).pointer;
if (info.size != .One) @compileError("ptr must be a single item pointer");
if (info.size != .one) @compileError("ptr must be a single item pointer");
const T = info.child;
if (@sizeOf(T) == 0) return;
const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));
@ -307,7 +307,7 @@ pub fn reallocAdvanced(
pub fn free(self: Allocator, memory: anytype) void {
const Slice = @typeInfo(@TypeOf(memory)).pointer;
const bytes = mem.sliceAsBytes(memory);
const bytes_len = bytes.len + if (Slice.sentinel != null) @sizeOf(Slice.child) else 0;
const bytes_len = bytes.len + if (Slice.sentinel() != null) @sizeOf(Slice.child) else 0;
if (bytes_len == 0) return;
const non_const_ptr = @constCast(bytes.ptr);
// TODO: https://github.com/ziglang/zig/issues/4298

View file

@ -103,12 +103,12 @@ pub fn Elem(comptime T: type) type {
.array => |info| return info.child,
.vector => |info| return info.child,
.pointer => |info| switch (info.size) {
.One => switch (@typeInfo(info.child)) {
.one => switch (@typeInfo(info.child)) {
.array => |array_info| return array_info.child,
.vector => |vector_info| return vector_info.child,
else => {},
},
.Many, .C, .Slice => return info.child,
.many, .c, .slice => return info.child,
},
.optional => |info| return Elem(info.child),
else => {},
@ -132,21 +132,12 @@ test Elem {
/// Result is always comptime-known.
pub inline fn sentinel(comptime T: type) ?Elem(T) {
switch (@typeInfo(T)) {
.array => |info| {
const sentinel_ptr = info.sentinel orelse return null;
return @as(*const info.child, @ptrCast(sentinel_ptr)).*;
},
.array => |info| return info.sentinel(),
.pointer => |info| {
switch (info.size) {
.Many, .Slice => {
const sentinel_ptr = info.sentinel orelse return null;
return @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*;
},
.One => switch (@typeInfo(info.child)) {
.array => |array_info| {
const sentinel_ptr = array_info.sentinel orelse return null;
return @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*;
},
.many, .slice => return info.sentinel(),
.one => switch (@typeInfo(info.child)) {
.array => |array_info| return array_info.sentinel(),
else => {},
},
else => {},
@ -178,7 +169,7 @@ fn testSentinel() !void {
pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
switch (@typeInfo(T)) {
.pointer => |info| switch (info.size) {
.One => switch (@typeInfo(info.child)) {
.one => switch (@typeInfo(info.child)) {
.array => |array_info| return @Type(.{
.pointer = .{
.size = info.size,
@ -190,16 +181,16 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
.array = .{
.len = array_info.len,
.child = array_info.child,
.sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
.sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
},
}),
.is_allowzero = info.is_allowzero,
.sentinel = info.sentinel,
.sentinel_ptr = info.sentinel_ptr,
},
}),
else => {},
},
.Many, .Slice => return @Type(.{
.many, .slice => return @Type(.{
.pointer = .{
.size = info.size,
.is_const = info.is_const,
@ -208,14 +199,14 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
.address_space = info.address_space,
.child = info.child,
.is_allowzero = info.is_allowzero,
.sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
.sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
},
}),
else => {},
},
.optional => |info| switch (@typeInfo(info.child)) {
.pointer => |ptr_info| switch (ptr_info.size) {
.Many => return @Type(.{
.many => return @Type(.{
.optional = .{
.child = @Type(.{
.pointer = .{
@ -226,7 +217,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
.address_space = ptr_info.address_space,
.child = ptr_info.child,
.is_allowzero = ptr_info.is_allowzero,
.sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
.sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
},
}),
},
@ -786,8 +777,8 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {
},
.pointer => |info| {
return switch (info.size) {
.One, .Many, .C => a == b,
.Slice => a.ptr == b.ptr and a.len == b.len,
.one, .many, .c => a == b,
.slice => a.ptr == b.ptr and a.len == b.len,
};
},
.optional => {
@ -1018,7 +1009,7 @@ fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type {
tuple_fields[i] = .{
.name = std.fmt.bufPrintZ(&num_buf, "{d}", .{i}) catch unreachable,
.type = T,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
};
@ -1090,7 +1081,7 @@ test "Tuple deduplication" {
test "ArgsTuple forwarding" {
const T1 = std.meta.Tuple(&.{ u32, f32, i8 });
const T2 = std.meta.ArgsTuple(fn (u32, f32, i8) void);
const T3 = std.meta.ArgsTuple(fn (u32, f32, i8) callconv(.C) noreturn);
const T3 = std.meta.ArgsTuple(fn (u32, f32, i8) callconv(.c) noreturn);
if (T1 != T2) {
@compileError("std.meta.ArgsTuple produces different types than std.meta.Tuple");
@ -1144,8 +1135,8 @@ test hasFn {
pub inline fn hasMethod(comptime T: type, comptime name: []const u8) bool {
return switch (@typeInfo(T)) {
.pointer => |P| switch (P.size) {
.One => hasFn(P.child, name),
.Many, .Slice, .C => false,
.one => hasFn(P.child, name),
.many, .slice, .c => false,
},
else => hasFn(T, name),
};
@ -1200,12 +1191,12 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
.int => |info| @sizeOf(T) * 8 == info.bits,
.pointer => |info| info.size != .Slice,
.pointer => |info| info.size != .slice,
.optional => |info| switch (@typeInfo(info.child)) {
.pointer => |ptr| !ptr.is_allowzero and switch (ptr.size) {
.Slice, .C => false,
.One, .Many => true,
.slice, .c => false,
.one, .many => true,
},
else => false,
},

View file

@ -25,7 +25,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
fields[i] = Type.StructField{
.name = struct_field.name,
.type = ?struct_field.type,
.default_value = &@as(?struct_field.type, null),
.default_value_ptr = &@as(?struct_field.type, null),
.is_comptime = false,
.alignment = @alignOf(?struct_field.type),
};

View file

@ -571,7 +571,7 @@ pub fn MultiArrayList(comptime T: type) type {
for (&entry_fields, sizes.fields) |*entry_field, i| entry_field.* = .{
.name = fields[i].name ++ "_ptr",
.type = *fields[i].type,
.default_value = null,
.default_value_ptr = null,
.is_comptime = fields[i].is_comptime,
.alignment = fields[i].alignment,
};

View file

@ -12,7 +12,7 @@ const c = std.c;
pub const FILE = c.FILE;
var __stack_chk_guard: usize = 0;
fn __stack_chk_fail() callconv(.C) void {
fn __stack_chk_fail() callconv(.c) void {
std.debug.print("stack smashing detected: terminated\n", .{});
emscripten_force_exit(127);
}
@ -547,8 +547,8 @@ pub const SIG = struct {
};
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
handler: extern union {
handler: ?handler_fn,
@ -556,7 +556,7 @@ pub const Sigaction = extern struct {
},
mask: sigset_t,
flags: c_uint,
restorer: ?*const fn () callconv(.C) void = null,
restorer: ?*const fn () callconv(.c) void = null,
};
pub const sigset_t = [1024 / 32]u32;
@ -909,23 +909,23 @@ pub const LOG = struct {
pub const INFO = 512;
};
pub const em_callback_func = ?*const fn () callconv(.C) void;
pub const em_arg_callback_func = ?*const fn (?*anyopaque) callconv(.C) void;
pub const em_str_callback_func = ?*const fn ([*:0]const u8) callconv(.C) void;
pub const em_callback_func = ?*const fn () callconv(.c) void;
pub const em_arg_callback_func = ?*const fn (?*anyopaque) callconv(.c) void;
pub const em_str_callback_func = ?*const fn ([*:0]const u8) callconv(.c) void;
pub extern "c" fn emscripten_async_wget(url: [*:0]const u8, file: [*:0]const u8, onload: em_str_callback_func, onerror: em_str_callback_func) void;
pub const em_async_wget_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.C) void;
pub const em_async_wget_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.c) void;
pub extern "c" fn emscripten_async_wget_data(url: [*:0]const u8, arg: ?*anyopaque, onload: em_async_wget_onload_func, onerror: em_arg_callback_func) void;
pub const em_async_wget2_onload_func = ?*const fn (c_uint, ?*anyopaque, [*:0]const u8) callconv(.C) void;
pub const em_async_wget2_onstatus_func = ?*const fn (c_uint, ?*anyopaque, c_int) callconv(.C) void;
pub const em_async_wget2_onload_func = ?*const fn (c_uint, ?*anyopaque, [*:0]const u8) callconv(.c) void;
pub const em_async_wget2_onstatus_func = ?*const fn (c_uint, ?*anyopaque, c_int) callconv(.c) void;
pub extern "c" fn emscripten_async_wget2(url: [*:0]const u8, file: [*:0]const u8, requesttype: [*:0]const u8, param: [*:0]const u8, arg: ?*anyopaque, onload: em_async_wget2_onload_func, onerror: em_async_wget2_onstatus_func, onprogress: em_async_wget2_onstatus_func) c_int;
pub const em_async_wget2_data_onload_func = ?*const fn (c_uint, ?*anyopaque, ?*anyopaque, c_uint) callconv(.C) void;
pub const em_async_wget2_data_onerror_func = ?*const fn (c_uint, ?*anyopaque, c_int, [*:0]const u8) callconv(.C) void;
pub const em_async_wget2_data_onprogress_func = ?*const fn (c_uint, ?*anyopaque, c_int, c_int) callconv(.C) void;
pub const em_async_wget2_data_onload_func = ?*const fn (c_uint, ?*anyopaque, ?*anyopaque, c_uint) callconv(.c) void;
pub const em_async_wget2_data_onerror_func = ?*const fn (c_uint, ?*anyopaque, c_int, [*:0]const u8) callconv(.c) void;
pub const em_async_wget2_data_onprogress_func = ?*const fn (c_uint, ?*anyopaque, c_int, c_int) callconv(.c) void;
pub extern "c" fn emscripten_async_wget2_data(url: [*:0]const u8, requesttype: [*:0]const u8, param: [*:0]const u8, arg: ?*anyopaque, free: c_int, onload: em_async_wget2_data_onload_func, onerror: em_async_wget2_data_onerror_func, onprogress: em_async_wget2_data_onprogress_func) c_int;
pub extern "c" fn emscripten_async_wget2_abort(handle: c_int) void;
@ -944,8 +944,8 @@ pub extern "c" fn emscripten_pause_main_loop() void;
pub extern "c" fn emscripten_resume_main_loop() void;
pub extern "c" fn emscripten_cancel_main_loop() void;
pub const em_socket_callback = ?*const fn (c_int, ?*anyopaque) callconv(.C) void;
pub const em_socket_error_callback = ?*const fn (c_int, c_int, [*:0]const u8, ?*anyopaque) callconv(.C) void;
pub const em_socket_callback = ?*const fn (c_int, ?*anyopaque) callconv(.c) void;
pub const em_socket_error_callback = ?*const fn (c_int, c_int, [*:0]const u8, ?*anyopaque) callconv(.c) void;
pub extern "c" fn emscripten_set_socket_error_callback(userData: ?*anyopaque, callback: em_socket_error_callback) void;
pub extern "c" fn emscripten_set_socket_open_callback(userData: ?*anyopaque, callback: em_socket_callback) void;
@ -968,11 +968,11 @@ pub extern "c" fn emscripten_set_canvas_size(width: c_int, height: c_int) void;
pub extern "c" fn emscripten_get_canvas_size(width: *c_int, height: *c_int, isFullscreen: *c_int) void;
pub extern "c" fn emscripten_get_now() f64;
pub extern "c" fn emscripten_random() f32;
pub const em_idb_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.C) void;
pub const em_idb_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.c) void;
pub extern "c" fn emscripten_idb_async_load(db_name: [*:0]const u8, file_id: [*:0]const u8, arg: ?*anyopaque, onload: em_idb_onload_func, onerror: em_arg_callback_func) void;
pub extern "c" fn emscripten_idb_async_store(db_name: [*:0]const u8, file_id: [*:0]const u8, ptr: ?*anyopaque, num: c_int, arg: ?*anyopaque, onstore: em_arg_callback_func, onerror: em_arg_callback_func) void;
pub extern "c" fn emscripten_idb_async_delete(db_name: [*:0]const u8, file_id: [*:0]const u8, arg: ?*anyopaque, ondelete: em_arg_callback_func, onerror: em_arg_callback_func) void;
pub const em_idb_exists_func = ?*const fn (?*anyopaque, c_int) callconv(.C) void;
pub const em_idb_exists_func = ?*const fn (?*anyopaque, c_int) callconv(.c) void;
pub extern "c" fn emscripten_idb_async_exists(db_name: [*:0]const u8, file_id: [*:0]const u8, arg: ?*anyopaque, oncheck: em_idb_exists_func, onerror: em_arg_callback_func) void;
pub extern "c" fn emscripten_idb_load(db_name: [*:0]const u8, file_id: [*:0]const u8, pbuffer: *?*anyopaque, pnum: *c_int, perror: *c_int) void;
pub extern "c" fn emscripten_idb_store(db_name: [*:0]const u8, file_id: [*:0]const u8, buffer: *anyopaque, num: c_int, perror: *c_int) void;
@ -983,13 +983,13 @@ pub extern "c" fn emscripten_idb_store_blob(db_name: [*:0]const u8, file_id: [*:
pub extern "c" fn emscripten_idb_read_from_blob(blob: c_int, start: c_int, num: c_int, buffer: ?*anyopaque) void;
pub extern "c" fn emscripten_idb_free_blob(blob: c_int) void;
pub extern "c" fn emscripten_run_preload_plugins(file: [*:0]const u8, onload: em_str_callback_func, onerror: em_str_callback_func) c_int;
pub const em_run_preload_plugins_data_onload_func = ?*const fn (?*anyopaque, [*:0]const u8) callconv(.C) void;
pub const em_run_preload_plugins_data_onload_func = ?*const fn (?*anyopaque, [*:0]const u8) callconv(.c) void;
pub extern "c" fn emscripten_run_preload_plugins_data(data: [*]u8, size: c_int, suffix: [*:0]const u8, arg: ?*anyopaque, onload: em_run_preload_plugins_data_onload_func, onerror: em_arg_callback_func) void;
pub extern "c" fn emscripten_lazy_load_code() void;
pub const worker_handle = c_int;
pub extern "c" fn emscripten_create_worker(url: [*:0]const u8) worker_handle;
pub extern "c" fn emscripten_destroy_worker(worker: worker_handle) void;
pub const em_worker_callback_func = ?*const fn ([*]u8, c_int, ?*anyopaque) callconv(.C) void;
pub const em_worker_callback_func = ?*const fn ([*]u8, c_int, ?*anyopaque) callconv(.c) void;
pub extern "c" fn emscripten_call_worker(worker: worker_handle, funcname: [*:0]const u8, data: [*]u8, size: c_int, callback: em_worker_callback_func, arg: ?*anyopaque) void;
pub extern "c" fn emscripten_worker_respond(data: [*]u8, size: c_int) void;
pub extern "c" fn emscripten_worker_respond_provisionally(data: [*]u8, size: c_int) void;
@ -1003,10 +1003,10 @@ pub extern "c" fn emscripten_get_preloaded_image_data_from_FILE(file: *FILE, w:
pub extern "c" fn emscripten_log(flags: c_int, format: [*:0]const u8, ...) void;
pub extern "c" fn emscripten_get_callstack(flags: c_int, out: ?[*]u8, maxbytes: c_int) c_int;
pub extern "c" fn emscripten_print_double(x: f64, to: ?[*]u8, max: c_int) c_int;
pub const em_scan_func = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.C) void;
pub const em_scan_func = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void;
pub extern "c" fn emscripten_scan_registers(func: em_scan_func) void;
pub extern "c" fn emscripten_scan_stack(func: em_scan_func) void;
pub const em_dlopen_callback = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.C) void;
pub const em_dlopen_callback = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void;
pub extern "c" fn emscripten_dlopen(filename: [*:0]const u8, flags: c_int, user_data: ?*anyopaque, onsuccess: em_dlopen_callback, onerror: em_arg_callback_func) void;
pub extern "c" fn emscripten_dlopen_promise(filename: [*:0]const u8, flags: c_int) em_promise_t;
pub extern "c" fn emscripten_throw_number(number: f64) void;
@ -1024,7 +1024,7 @@ pub const struct__em_promise = opaque {};
pub const em_promise_t = ?*struct__em_promise;
pub const enum_em_promise_result_t = c_uint;
pub const em_promise_result_t = enum_em_promise_result_t;
pub const em_promise_callback_t = ?*const fn (?*?*anyopaque, ?*anyopaque, ?*anyopaque) callconv(.C) em_promise_result_t;
pub const em_promise_callback_t = ?*const fn (?*?*anyopaque, ?*anyopaque, ?*anyopaque) callconv(.c) em_promise_result_t;
pub extern "c" fn emscripten_promise_create() em_promise_t;
pub extern "c" fn emscripten_promise_destroy(promise: em_promise_t) void;

View file

@ -67,7 +67,7 @@ pub const syscall_pipe = syscall_bits.syscall_pipe;
pub const syscall_fork = syscall_bits.syscall_fork;
pub fn clone(
func: *const fn (arg: usize) callconv(.C) u8,
func: *const fn (arg: usize) callconv(.c) u8,
stack: usize,
flags: u32,
arg: usize,
@ -77,14 +77,14 @@ pub fn clone(
) usize {
// Can't directly call a naked function; cast to C calling convention first.
return @as(*const fn (
*const fn (arg: usize) callconv(.C) u8,
*const fn (arg: usize) callconv(.c) u8,
usize,
u32,
usize,
?*i32,
usize,
?*i32,
) callconv(.C) usize, @ptrCast(&syscall_bits.clone))(func, stack, flags, arg, ptid, tp, ctid);
) callconv(.c) usize, @ptrCast(&syscall_bits.clone))(func, stack, flags, arg, ptid, tp, ctid);
}
pub const ARCH = arch_bits.ARCH;
@ -494,7 +494,7 @@ pub const getauxval = if (extern_getauxval) struct {
extern fn getauxval(index: usize) usize;
}.getauxval else getauxvalImpl;
fn getauxvalImpl(index: usize) callconv(.C) usize {
fn getauxvalImpl(index: usize) callconv(.c) usize {
const auxv = elf_aux_maybe orelse return 0;
var i: usize = 0;
while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
@ -1485,7 +1485,7 @@ pub fn flock(fd: fd_t, operation: i32) usize {
}
// We must follow the C calling convention when we call into the VDSO
const VdsoClockGettime = *align(1) const fn (clockid_t, *timespec) callconv(.C) usize;
const VdsoClockGettime = *align(1) const fn (clockid_t, *timespec) callconv(.c) usize;
var vdso_clock_gettime: ?VdsoClockGettime = &init_vdso_clock_gettime;
pub fn clock_gettime(clk_id: clockid_t, tp: *timespec) usize {
@ -1502,7 +1502,7 @@ pub fn clock_gettime(clk_id: clockid_t, tp: *timespec) usize {
return syscall2(.clock_gettime, @intFromEnum(clk_id), @intFromPtr(tp));
}
fn init_vdso_clock_gettime(clk: clockid_t, ts: *timespec) callconv(.C) usize {
fn init_vdso_clock_gettime(clk: clockid_t, ts: *timespec) callconv(.c) usize {
const ptr: ?VdsoClockGettime = @ptrFromInt(vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM));
// Note that we may not have a VDSO at all, update the stub address anyway
// so that clock_gettime will fall back on the good old (and slow) syscall
@ -5070,8 +5070,8 @@ pub const all_mask: sigset_t = [_]u32{0xffffffff} ** @typeInfo(sigset_t).array.l
pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;
const k_sigaction_funcs = struct {
const handler = ?*align(1) const fn (i32) callconv(.C) void;
const restorer = *const fn () callconv(.C) void;
const handler = ?*align(1) const fn (i32) callconv(.c) void;
const restorer = *const fn () callconv(.c) void;
};
pub const k_sigaction = switch (native_arch) {
@ -5097,8 +5097,8 @@ pub const k_sigaction = switch (native_arch) {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
handler: extern union {
handler: ?handler_fn,
@ -5106,7 +5106,7 @@ pub const Sigaction = extern struct {
},
mask: sigset_t,
flags: c_uint,
restorer: ?*const fn () callconv(.C) void = null,
restorer: ?*const fn () callconv(.c) void = null,
};
const sigset_len = @typeInfo(sigset_t).array.len;

View file

@ -233,7 +233,7 @@ pub const restore = restore_rt;
// Need to use C ABI here instead of naked
// to prevent an infinite loop when calling rt_sigreturn.
pub fn restore_rt() callconv(.C) void {
pub fn restore_rt() callconv(.c) void {
return asm volatile ("t 0x6d"
:
: [number] "{g1}" (@intFromEnum(SYS.rt_sigreturn)),

View file

@ -186,8 +186,8 @@ pub const empty_sigset = 0;
pub const siginfo_t = c_long;
// TODO plan9 doesn't have sigaction_fn. Sigaction is not a union, but we include it here to be compatible.
pub const Sigaction = extern struct {
pub const handler_fn = *const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
handler: extern union {
handler: ?handler_fn,

View file

@ -149,11 +149,11 @@ pub const BootServices = extern struct {
/// Installs one or more protocol interfaces into the boot services environment
// TODO: use callconv(cc) instead once that works
installMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.C) Status,
installMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.c) Status,
/// Removes one or more protocol interfaces into the boot services environment
// TODO: use callconv(cc) instead once that works
uninstallMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.C) Status,
uninstallMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.c) Status,
/// Computes and returns a 32-bit CRC for a data buffer.
calculateCrc32: *const fn (data: [*]const u8, data_size: usize, *u32) callconv(cc) Status,

View file

@ -5552,7 +5552,7 @@ pub fn dl_iterate_phdr(
if (builtin.link_libc) {
switch (system.dl_iterate_phdr(struct {
fn callbackC(info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int {
fn callbackC(info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.c) c_int {
const context_ptr: *const Context = @ptrCast(@alignCast(data));
callback(info, size, context_ptr.*) catch |err| return @intFromError(err);
return 0;

View file

@ -849,7 +849,7 @@ test "sigaction" {
const S = struct {
var handler_called_count: u32 = 0;
fn handler(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) void {
fn handler(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {
_ = ctx_ptr;
// Check that we received the correct signal.
switch (native_os) {

View file

@ -100,13 +100,13 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
.pointer => |pointer| {
switch (pointer.size) {
.One, .Many, .C => {
.one, .many, .c => {
if (actual != expected) {
print("expected {*}, found {*}\n", .{ expected, actual });
return error.TestExpectedEqual;
}
},
.Slice => {
.slice => {
if (actual.ptr != expected.ptr) {
print("expected slice ptr {*}, found {*}\n", .{ expected.ptr, actual.ptr });
return error.TestExpectedEqual;
@ -726,13 +726,13 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
.pointer => |pointer| {
switch (pointer.size) {
// We have no idea what is behind those pointers, so the best we can do is `==` check.
.C, .Many => {
.c, .many => {
if (actual != expected) {
print("expected {*}, found {*}\n", .{ expected, actual });
return error.TestExpectedEqual;
}
},
.One => {
.one => {
// Length of those pointers are runtime value, so the best we can do is `==` check.
switch (@typeInfo(pointer.child)) {
.@"fn", .@"opaque" => {
@ -744,7 +744,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
else => try expectEqualDeep(expected.*, actual.*),
}
},
.Slice => {
.slice => {
if (expected.len != actual.len) {
print("Slice len not the same, expected {d}, found {d}\n", .{ expected.len, actual.len });
return error.TestExpectedEqual;

View file

@ -2157,14 +2157,13 @@ fn fullFnProtoComponents(tree: Ast, info: full.FnProto.Components) full.FnProto
fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType {
const token_tags = tree.tokens.items(.tag);
const Size = std.builtin.Type.Pointer.Size;
const size: Size = switch (token_tags[info.main_token]) {
const size: std.builtin.Type.Pointer.Size = switch (token_tags[info.main_token]) {
.asterisk,
.asterisk_asterisk,
=> .One,
=> .one,
.l_bracket => switch (token_tags[info.main_token + 1]) {
.asterisk => if (token_tags[info.main_token + 2] == .identifier) Size.C else Size.Many,
else => Size.Slice,
.asterisk => if (token_tags[info.main_token + 2] == .identifier) .c else .many,
else => .slice,
},
else => unreachable,
};
@ -2180,7 +2179,7 @@ fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType
// positives. Therefore, start after a sentinel if there is one and
// skip over any align node and bit range nodes.
var i = if (info.sentinel != 0) tree.lastToken(info.sentinel) + 1 else switch (size) {
.Many, .C => info.main_token + 1,
.many, .c => info.main_token + 1,
else => info.main_token,
};
const end = tree.firstToken(info.child_type);

View file

@ -3917,7 +3917,7 @@ fn ptrType(
node: Ast.Node.Index,
ptr_info: Ast.full.PtrType,
) InnerError!Zir.Inst.Ref {
if (ptr_info.size == .C and ptr_info.allowzero_token != null) {
if (ptr_info.size == .c and ptr_info.allowzero_token != null) {
return gz.astgen.failTok(ptr_info.allowzero_token.?, "C pointers always allow address zero", .{});
}
@ -3946,7 +3946,7 @@ fn ptrType(
.{ .rl = .{ .ty = elem_type } },
ptr_info.ast.sentinel,
switch (ptr_info.size) {
.Slice => .slice_sentinel,
.slice => .slice_sentinel,
else => .pointer_sentinel,
},
);

View file

@ -170,7 +170,7 @@ pub fn sizeof(target: anytype) usize {
}
},
.pointer => |ptr| {
if (ptr.size == .Slice) {
if (ptr.size == .slice) {
@compileError("Cannot use C sizeof on slice type " ++ @typeName(T));
}
// for strings, sizeof("a") returns 2.
@ -178,12 +178,9 @@ pub fn sizeof(target: anytype) usize {
// in the .array case above, but strings remain literals
// and are therefore always pointers, so they need to be
// specially handled here.
if (ptr.size == .One and ptr.is_const and @typeInfo(ptr.child) == .array) {
if (ptr.size == .one and ptr.is_const and @typeInfo(ptr.child) == .array) {
const array_info = @typeInfo(ptr.child).array;
if ((array_info.child == u8 or array_info.child == u16) and
array_info.sentinel != null and
@as(*align(1) const array_info.child, @ptrCast(array_info.sentinel.?)).* == 0)
{
if ((array_info.child == u8 or array_info.child == u16) and array_info.sentinel() == 0) {
// length of the string plus one for the null terminator.
return (array_info.len + 1) * @sizeOf(array_info.child);
}
@ -341,14 +338,14 @@ pub fn FlexibleArrayType(comptime SelfType: type, comptime ElementType: type) ty
switch (@typeInfo(SelfType)) {
.pointer => |ptr| {
return @Type(.{ .pointer = .{
.size = .C,
.size = .c,
.is_const = ptr.is_const,
.is_volatile = ptr.is_volatile,
.alignment = @alignOf(ElementType),
.address_space = .generic,
.child = ElementType,
.is_allowzero = true,
.sentinel = null,
.sentinel_ptr = null,
} });
},
else => |info| @compileError("Invalid self type \"" ++ @tagName(info) ++ "\" for flexible array getter: " ++ @typeName(SelfType)),

View file

@ -552,7 +552,7 @@ test "zig fmt: trailing comma in fn parameter list" {
\\pub fn f(
\\ a: i32,
\\ b: i32,
\\) callconv(.C) i32 {}
\\) callconv(.c) i32 {}
\\pub fn f(
\\ a: i32,
\\ b: i32,
@ -560,15 +560,15 @@ test "zig fmt: trailing comma in fn parameter list" {
\\pub fn f(
\\ a: i32,
\\ b: i32,
\\) align(8) callconv(.C) i32 {}
\\) align(8) callconv(.c) i32 {}
\\pub fn f(
\\ a: i32,
\\ b: i32,
\\) align(8) linksection(".text") callconv(.C) i32 {}
\\) align(8) linksection(".text") callconv(.c) i32 {}
\\pub fn f(
\\ a: i32,
\\ b: i32,
\\) linksection(".text") callconv(.C) i32 {}
\\) linksection(".text") callconv(.c) i32 {}
\\
);
}

View file

@ -938,7 +938,7 @@ fn renderArrayType(
fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!void {
const tree = r.tree;
switch (ptr_type.size) {
.One => {
.one => {
// Since ** tokens exist and the same token is shared by two
// nested pointer types, we check to see if we are the parent
// in such a relationship. If so, skip rendering anything for
@ -951,7 +951,7 @@ fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!voi
}
try renderToken(r, ptr_type.ast.main_token, .none); // asterisk
},
.Many => {
.many => {
if (ptr_type.ast.sentinel == 0) {
try renderToken(r, ptr_type.ast.main_token, .none); // lbracket
try renderToken(r, ptr_type.ast.main_token + 1, .none); // asterisk
@ -964,13 +964,13 @@ fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!voi
try renderToken(r, tree.lastToken(ptr_type.ast.sentinel) + 1, .none); // rbracket
}
},
.C => {
.c => {
try renderToken(r, ptr_type.ast.main_token, .none); // lbracket
try renderToken(r, ptr_type.ast.main_token + 1, .none); // asterisk
try renderToken(r, ptr_type.ast.main_token + 2, .none); // c
try renderToken(r, ptr_type.ast.main_token + 3, .none); // rbracket
},
.Slice => {
.slice => {
if (ptr_type.ast.sentinel == 0) {
try renderToken(r, ptr_type.ast.main_token, .none); // lbracket
try renderToken(r, ptr_type.ast.main_token + 1, .none); // rbracket

View file

@ -475,7 +475,7 @@ const CpuidLeaf = packed struct {
/// This is a workaround for the C backend until zig has the ability to put
/// C code in inline assembly.
extern fn zig_x86_cpuid(leaf_id: u32, subid: u32, eax: *u32, ebx: *u32, ecx: *u32, edx: *u32) callconv(.C) void;
extern fn zig_x86_cpuid(leaf_id: u32, subid: u32, eax: *u32, ebx: *u32, ecx: *u32, edx: *u32) callconv(.c) void;
fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf {
// valid for both x86 and x86_64
@ -502,7 +502,7 @@ fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf {
/// This is a workaround for the C backend until zig has the ability to put
/// C code in inline assembly.
extern fn zig_x86_get_xcr0() callconv(.C) u32;
extern fn zig_x86_get_xcr0() callconv(.c) u32;
// Read control register 0 (XCR0). Used to detect features such as AVX.
fn getXCR0() u32 {

View file

@ -1134,7 +1134,7 @@ const Local = struct {
for (&new_fields, elem_fields) |*new_field, elem_field| new_field.* = .{
.name = elem_field.name,
.type = *[len]elem_field.type,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
};
@ -1162,9 +1162,9 @@ const Local = struct {
.address_space = .generic,
.child = elem_field.type,
.is_allowzero = false,
.sentinel = null,
.sentinel_ptr = null,
} }),
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
};
@ -1176,17 +1176,17 @@ const Local = struct {
} });
}
pub fn addOne(mutable: Mutable) Allocator.Error!PtrElem(.{ .size = .One }) {
pub fn addOne(mutable: Mutable) Allocator.Error!PtrElem(.{ .size = .one }) {
try mutable.ensureUnusedCapacity(1);
return mutable.addOneAssumeCapacity();
}
pub fn addOneAssumeCapacity(mutable: Mutable) PtrElem(.{ .size = .One }) {
pub fn addOneAssumeCapacity(mutable: Mutable) PtrElem(.{ .size = .one }) {
const index = mutable.mutate.len;
assert(index < mutable.list.header().capacity);
mutable.mutate.len = index + 1;
const mutable_view = mutable.view().slice();
var ptr: PtrElem(.{ .size = .One }) = undefined;
var ptr: PtrElem(.{ .size = .one }) = undefined;
inline for (fields) |field| {
@field(ptr, @tagName(field)) = &mutable_view.items(field)[index];
}
@ -1206,7 +1206,7 @@ const Local = struct {
pub fn appendSliceAssumeCapacity(
mutable: Mutable,
slice: PtrElem(.{ .size = .Slice, .is_const = true }),
slice: PtrElem(.{ .size = .slice, .is_const = true }),
) void {
if (fields.len == 0) return;
const start = mutable.mutate.len;
@ -1253,17 +1253,17 @@ const Local = struct {
return ptr_array;
}
pub fn addManyAsSlice(mutable: Mutable, len: usize) Allocator.Error!PtrElem(.{ .size = .Slice }) {
pub fn addManyAsSlice(mutable: Mutable, len: usize) Allocator.Error!PtrElem(.{ .size = .slice }) {
try mutable.ensureUnusedCapacity(len);
return mutable.addManyAsSliceAssumeCapacity(len);
}
pub fn addManyAsSliceAssumeCapacity(mutable: Mutable, len: usize) PtrElem(.{ .size = .Slice }) {
pub fn addManyAsSliceAssumeCapacity(mutable: Mutable, len: usize) PtrElem(.{ .size = .slice }) {
const start = mutable.mutate.len;
assert(len <= mutable.list.header().capacity - start);
mutable.mutate.len = @intCast(start + len);
const mutable_view = mutable.view().slice();
var slice: PtrElem(.{ .size = .Slice }) = undefined;
var slice: PtrElem(.{ .size = .slice }) = undefined;
inline for (fields) |field| {
@field(slice, @tagName(field)) = mutable_view.items(field)[start..][0..len];
}
@ -2060,7 +2060,7 @@ pub const Key = union(enum) {
};
pub const Flags = packed struct(u32) {
size: Size = .One,
size: Size = .one,
/// `none` indicates the ABI alignment of the pointee_type. In this
/// case, this field *must* be set to `none`, otherwise the
/// `InternPool` equality and hashing functions will return incorrect
@ -4891,7 +4891,7 @@ pub const Index = enum(u32) {
checkField(name ++ ".?", info.child);
},
.pointer => |info| {
assert(info.size == .Slice);
assert(info.size == .slice);
checkConfig(name ++ ".len");
checkField(name ++ "[0]", info.child);
},
@ -5016,7 +5016,7 @@ pub const static_keys = [_]Key{
.{ .ptr_type = .{
.child = .u8_type,
.flags = .{
.size = .Many,
.size = .many,
},
} },
@ -5024,7 +5024,7 @@ pub const static_keys = [_]Key{
.{ .ptr_type = .{
.child = .u8_type,
.flags = .{
.size = .Many,
.size = .many,
.is_const = true,
},
} },
@ -5034,7 +5034,7 @@ pub const static_keys = [_]Key{
.child = .u8_type,
.sentinel = .zero_u8,
.flags = .{
.size = .Many,
.size = .many,
.is_const = true,
},
} },
@ -5043,7 +5043,7 @@ pub const static_keys = [_]Key{
.{ .ptr_type = .{
.child = .comptime_int_type,
.flags = .{
.size = .One,
.size = .one,
.is_const = true,
},
} },
@ -5052,7 +5052,7 @@ pub const static_keys = [_]Key{
.{ .ptr_type = .{
.child = .u8_type,
.flags = .{
.size = .Slice,
.size = .slice,
.is_const = true,
},
} },
@ -5062,7 +5062,7 @@ pub const static_keys = [_]Key{
.child = .u8_type,
.sentinel = .zero_u8,
.flags = .{
.size = .Slice,
.size = .slice,
.is_const = true,
},
} },
@ -6749,7 +6749,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
const many_ptr_item = many_ptr_unwrapped.getItem(ip);
assert(many_ptr_item.tag == .type_pointer);
var ptr_info = extraData(many_ptr_unwrapped.getExtra(ip), Tag.TypePointer, many_ptr_item.data);
ptr_info.flags.size = .Slice;
ptr_info.flags.size = .slice;
return .{ .ptr_type = ptr_info };
},
@ -7572,10 +7572,10 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All
assert(ptr_type.child != .none);
assert(ptr_type.sentinel == .none or ip.typeOf(ptr_type.sentinel) == ptr_type.child);
if (ptr_type.flags.size == .Slice) {
if (ptr_type.flags.size == .slice) {
gop.cancel();
var new_key = key;
new_key.ptr_type.flags.size = .Many;
new_key.ptr_type.flags.size = .many;
const ptr_type_index = try ip.get(gpa, tid, new_key);
gop = try ip.getOrPutKey(gpa, tid, key);
@ -7588,7 +7588,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All
}
var ptr_type_adjusted = ptr_type;
if (ptr_type.flags.size == .C) ptr_type_adjusted.flags.is_allowzero = true;
if (ptr_type.flags.size == .c) ptr_type_adjusted.flags.is_allowzero = true;
items.appendAssumeCapacity(.{
.tag = .type_pointer,
@ -7731,8 +7731,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All
},
.slice => |slice| {
assert(ip.indexToKey(slice.ty).ptr_type.flags.size == .Slice);
assert(ip.indexToKey(ip.typeOf(slice.ptr)).ptr_type.flags.size == .Many);
assert(ip.indexToKey(slice.ty).ptr_type.flags.size == .slice);
assert(ip.indexToKey(ip.typeOf(slice.ptr)).ptr_type.flags.size == .many);
items.appendAssumeCapacity(.{
.tag = .ptr_slice,
.data = try addExtra(extra, PtrSlice{
@ -7745,7 +7745,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All
.ptr => |ptr| {
const ptr_type = ip.indexToKey(ptr.ty).ptr_type;
assert(ptr_type.flags.size != .Slice);
assert(ptr_type.flags.size != .slice);
items.appendAssumeCapacity(switch (ptr.base_addr) {
.nav => |nav| .{
.tag = .ptr_nav,
@ -7804,9 +7804,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All
.arr_elem, .field => |base_index| {
const base_ptr_type = ip.indexToKey(ip.typeOf(base_index.base)).ptr_type;
switch (ptr.base_addr) {
.arr_elem => assert(base_ptr_type.flags.size == .Many),
.arr_elem => assert(base_ptr_type.flags.size == .many),
.field => {
assert(base_ptr_type.flags.size == .One);
assert(base_ptr_type.flags.size == .one);
switch (ip.indexToKey(base_ptr_type.child)) {
.tuple_type => |tuple_type| {
assert(ptr.base_addr == .field);
@ -7823,7 +7823,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All
},
.ptr_type => |slice_type| {
assert(ptr.base_addr == .field);
assert(slice_type.flags.size == .Slice);
assert(slice_type.flags.size == .slice);
assert(base_index.index < 2);
},
else => unreachable,
@ -10314,12 +10314,12 @@ pub fn getCoerced(
} });
if (ip.isPointerType(new_ty)) switch (ip.indexToKey(new_ty).ptr_type.flags.size) {
.One, .Many, .C => return ip.get(gpa, tid, .{ .ptr = .{
.one, .many, .c => return ip.get(gpa, tid, .{ .ptr = .{
.ty = new_ty,
.base_addr = .int,
.byte_offset = 0,
} }),
.Slice => return ip.get(gpa, tid, .{ .slice = .{
.slice => return ip.get(gpa, tid, .{ .slice = .{
.ty = new_ty,
.ptr = try ip.get(gpa, tid, .{ .ptr = .{
.ty = ip.slicePtrType(new_ty),
@ -10408,7 +10408,7 @@ pub fn getCoerced(
},
else => {},
},
.slice => |slice| if (ip.isPointerType(new_ty) and ip.indexToKey(new_ty).ptr_type.flags.size == .Slice)
.slice => |slice| if (ip.isPointerType(new_ty) and ip.indexToKey(new_ty).ptr_type.flags.size == .slice)
return ip.get(gpa, tid, .{ .slice = .{
.ty = new_ty,
.ptr = try ip.getCoerced(gpa, tid, slice.ptr, ip.slicePtrType(new_ty)),
@ -10416,7 +10416,7 @@ pub fn getCoerced(
} })
else if (ip.isIntegerType(new_ty))
return ip.getCoerced(gpa, tid, slice.ptr, new_ty),
.ptr => |ptr| if (ip.isPointerType(new_ty) and ip.indexToKey(new_ty).ptr_type.flags.size != .Slice)
.ptr => |ptr| if (ip.isPointerType(new_ty) and ip.indexToKey(new_ty).ptr_type.flags.size != .slice)
return ip.get(gpa, tid, .{ .ptr = .{
.ty = new_ty,
.base_addr = ptr.base_addr,
@ -10433,12 +10433,12 @@ pub fn getCoerced(
.opt => |opt| switch (ip.indexToKey(new_ty)) {
.ptr_type => |ptr_type| return switch (opt.val) {
.none => switch (ptr_type.flags.size) {
.One, .Many, .C => try ip.get(gpa, tid, .{ .ptr = .{
.one, .many, .c => try ip.get(gpa, tid, .{ .ptr = .{
.ty = new_ty,
.base_addr = .int,
.byte_offset = 0,
} }),
.Slice => try ip.get(gpa, tid, .{ .slice = .{
.slice => try ip.get(gpa, tid, .{ .slice = .{
.ty = new_ty,
.ptr = try ip.get(gpa, tid, .{ .ptr = .{
.ty = ip.slicePtrType(new_ty),

File diff suppressed because it is too large Load diff

View file

@ -192,16 +192,16 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
const info = ty.ptrInfo(zcu);
if (info.sentinel != .none) switch (info.flags.size) {
.One, .C => unreachable,
.Many => try writer.print("[*:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),
.Slice => try writer.print("[:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),
.one, .c => unreachable,
.many => try writer.print("[*:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),
.slice => try writer.print("[:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),
} else switch (info.flags.size) {
.One => try writer.writeAll("*"),
.Many => try writer.writeAll("[*]"),
.C => try writer.writeAll("[*c]"),
.Slice => try writer.writeAll("[]"),
.one => try writer.writeAll("*"),
.many => try writer.writeAll("[*]"),
.c => try writer.writeAll("[*c]"),
.slice => try writer.writeAll("[]"),
}
if (info.flags.is_allowzero and info.flags.size != .C) try writer.writeAll("allowzero ");
if (info.flags.is_allowzero and info.flags.size != .c) try writer.writeAll("allowzero ");
if (info.flags.alignment != .none or
info.packed_offset.host_size != 0 or
info.flags.vector_index != .none)
@ -686,7 +686,7 @@ pub fn hasWellDefinedLayout(ty: Type, zcu: *const Zcu) bool {
.array_type => |array_type| Type.fromInterned(array_type.child).hasWellDefinedLayout(zcu),
.opt_type => ty.isPtrLikeOptional(zcu),
.ptr_type => |ptr_type| ptr_type.flags.size != .Slice,
.ptr_type => |ptr_type| ptr_type.flags.size != .slice,
.simple_type => |t| switch (t) {
.f16,
@ -1303,7 +1303,7 @@ pub fn abiSizeInner(
return .{ .scalar = intAbiSize(int_type.bits, target, use_llvm) };
},
.ptr_type => |ptr_type| switch (ptr_type.flags.size) {
.Slice => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 },
.slice => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 },
else => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) },
},
.anyframe_type => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) },
@ -1741,7 +1741,7 @@ pub fn bitSizeInner(
switch (ip.indexToKey(ty.toIntern())) {
.int_type => |int_type| return int_type.bits,
.ptr_type => |ptr_type| switch (ptr_type.flags.size) {
.Slice => return target.ptrBitWidth() * 2,
.slice => return target.ptrBitWidth() * 2,
else => return target.ptrBitWidth(),
},
.anyframe_type => return target.ptrBitWidth(),
@ -1903,7 +1903,7 @@ pub fn layoutIsResolved(ty: Type, zcu: *const Zcu) bool {
pub fn isSinglePointer(ty: Type, zcu: *const Zcu) bool {
return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
.ptr_type => |ptr_info| ptr_info.flags.size == .One,
.ptr_type => |ptr_info| ptr_info.flags.size == .one,
else => false,
};
}
@ -1923,7 +1923,7 @@ pub fn ptrSizeOrNull(ty: Type, zcu: *const Zcu) ?std.builtin.Type.Pointer.Size {
pub fn isSlice(ty: Type, zcu: *const Zcu) bool {
return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
.ptr_type => |ptr_type| ptr_type.flags.size == .Slice,
.ptr_type => |ptr_type| ptr_type.flags.size == .slice,
else => false,
};
}
@ -1960,7 +1960,7 @@ pub fn isAllowzeroPtr(ty: Type, zcu: *const Zcu) bool {
pub fn isCPtr(ty: Type, zcu: *const Zcu) bool {
return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
.ptr_type => |ptr_type| ptr_type.flags.size == .C,
.ptr_type => |ptr_type| ptr_type.flags.size == .c,
else => false,
};
}
@ -1968,13 +1968,13 @@ pub fn isCPtr(ty: Type, zcu: *const Zcu) bool {
pub fn isPtrAtRuntime(ty: Type, zcu: *const Zcu) bool {
return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
.ptr_type => |ptr_type| switch (ptr_type.flags.size) {
.Slice => false,
.One, .Many, .C => true,
.slice => false,
.one, .many, .c => true,
},
.opt_type => |child| switch (zcu.intern_pool.indexToKey(child)) {
.ptr_type => |p| switch (p.flags.size) {
.Slice, .C => false,
.Many, .One => !p.flags.is_allowzero,
.slice, .c => false,
.many, .one => !p.flags.is_allowzero,
},
else => false,
},
@ -1995,11 +1995,11 @@ pub fn ptrAllowsZero(ty: Type, zcu: *const Zcu) bool {
pub fn optionalReprIsPayload(ty: Type, zcu: *const Zcu) bool {
return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
.opt_type => |child_type| child_type == .anyerror_type or switch (zcu.intern_pool.indexToKey(child_type)) {
.ptr_type => |ptr_type| ptr_type.flags.size != .C and !ptr_type.flags.is_allowzero,
.ptr_type => |ptr_type| ptr_type.flags.size != .c and !ptr_type.flags.is_allowzero,
.error_set_type, .inferred_error_set_type => true,
else => false,
},
.ptr_type => |ptr_type| ptr_type.flags.size == .C,
.ptr_type => |ptr_type| ptr_type.flags.size == .c,
else => false,
};
}
@ -2009,11 +2009,11 @@ pub fn optionalReprIsPayload(ty: Type, zcu: *const Zcu) bool {
/// This function must be kept in sync with `Sema.typePtrOrOptionalPtrTy`.
pub fn isPtrLikeOptional(ty: Type, zcu: *const Zcu) bool {
return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
.ptr_type => |ptr_type| ptr_type.flags.size == .C,
.ptr_type => |ptr_type| ptr_type.flags.size == .c,
.opt_type => |child| switch (zcu.intern_pool.indexToKey(child)) {
.ptr_type => |ptr_type| switch (ptr_type.flags.size) {
.Slice, .C => false,
.Many, .One => !ptr_type.flags.is_allowzero,
.slice, .c => false,
.many, .one => !ptr_type.flags.is_allowzero,
},
else => false,
},
@ -2044,8 +2044,8 @@ pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {
pub fn elemType2(ty: Type, zcu: *const Zcu) Type {
return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
.ptr_type => |ptr_type| switch (ptr_type.flags.size) {
.One => Type.fromInterned(ptr_type.child).shallowElemType(zcu),
.Many, .C, .Slice => Type.fromInterned(ptr_type.child),
.one => Type.fromInterned(ptr_type.child).shallowElemType(zcu),
.many, .c, .slice => Type.fromInterned(ptr_type.child),
},
.anyframe_type => |child| {
assert(child != .none);
@ -2079,7 +2079,7 @@ pub fn optionalChild(ty: Type, zcu: *const Zcu) Type {
return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
.opt_type => |child| Type.fromInterned(child),
.ptr_type => |ptr_type| b: {
assert(ptr_type.flags.size == .C);
assert(ptr_type.flags.size == .c);
break :b ty;
},
else => unreachable,
@ -2991,8 +2991,8 @@ pub fn isIndexable(ty: Type, zcu: *const Zcu) bool {
return switch (ty.zigTypeTag(zcu)) {
.array, .vector => true,
.pointer => switch (ty.ptrSize(zcu)) {
.Slice, .Many, .C => true,
.One => switch (ty.childType(zcu).zigTypeTag(zcu)) {
.slice, .many, .c => true,
.one => switch (ty.childType(zcu).zigTypeTag(zcu)) {
.array, .vector => true,
.@"struct" => ty.childType(zcu).isTuple(zcu),
else => false,
@ -3007,9 +3007,9 @@ pub fn indexableHasLen(ty: Type, zcu: *const Zcu) bool {
return switch (ty.zigTypeTag(zcu)) {
.array, .vector => true,
.pointer => switch (ty.ptrSize(zcu)) {
.Many, .C => false,
.Slice => true,
.One => switch (ty.childType(zcu).zigTypeTag(zcu)) {
.many, .c => false,
.slice => true,
.one => switch (ty.childType(zcu).zigTypeTag(zcu)) {
.array, .vector => true,
.@"struct" => ty.childType(zcu).isTuple(zcu),
else => false,
@ -4049,7 +4049,7 @@ pub fn elemPtrType(ptr_ty: Type, offset: ?usize, pt: Zcu.PerThread) !Type {
host_size: u16 = 0,
alignment: Alignment = .none,
vector_index: VI = .none,
} = if (parent_ty.isVector(zcu) and ptr_info.flags.size == .One) blk: {
} = if (parent_ty.isVector(zcu) and ptr_info.flags.size == .one) blk: {
const elem_bits = elem_ty.bitSize(zcu);
if (elem_bits == 0) break :blk .{};
const is_packed = elem_bits < 8 or !std.math.isPowerOfTwo(elem_bits);

View file

@ -1,5 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const build_options = @import("build_options");
const Type = @import("Type.zig");
const assert = std.debug.assert;
const BigIntConst = std.math.big.int.Const;
@ -3724,7 +3725,7 @@ pub fn ptrOptPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
const parent_ptr_ty = parent_ptr.typeOf(zcu);
const opt_ty = parent_ptr_ty.childType(zcu);
assert(parent_ptr_ty.ptrSize(zcu) == .One);
assert(parent_ptr_ty.ptrSize(zcu) == .one);
assert(opt_ty.zigTypeTag(zcu) == .optional);
const result_ty = try pt.ptrTypeSema(info: {
@ -3742,7 +3743,7 @@ pub fn ptrOptPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
return pt.getCoerced(parent_ptr, result_ty);
}
const base_ptr = try parent_ptr.canonicalizeBasePtr(.One, opt_ty, pt);
const base_ptr = try parent_ptr.canonicalizeBasePtr(.one, opt_ty, pt);
return Value.fromInterned(try pt.intern(.{ .ptr = .{
.ty = result_ty.toIntern(),
.base_addr = .{ .opt_payload = base_ptr.toIntern() },
@ -3758,7 +3759,7 @@ pub fn ptrEuPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
const parent_ptr_ty = parent_ptr.typeOf(zcu);
const eu_ty = parent_ptr_ty.childType(zcu);
assert(parent_ptr_ty.ptrSize(zcu) == .One);
assert(parent_ptr_ty.ptrSize(zcu) == .one);
assert(eu_ty.zigTypeTag(zcu) == .error_union);
const result_ty = try pt.ptrTypeSema(info: {
@ -3771,7 +3772,7 @@ pub fn ptrEuPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
if (parent_ptr.isUndef(zcu)) return pt.undefValue(result_ty);
const base_ptr = try parent_ptr.canonicalizeBasePtr(.One, eu_ty, pt);
const base_ptr = try parent_ptr.canonicalizeBasePtr(.one, eu_ty, pt);
return Value.fromInterned(try pt.intern(.{ .ptr = .{
.ty = result_ty.toIntern(),
.base_addr = .{ .eu_payload = base_ptr.toIntern() },
@ -3789,7 +3790,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
const aggregate_ty = parent_ptr_ty.childType(zcu);
const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu);
assert(parent_ptr_info.flags.size == .One);
assert(parent_ptr_info.flags.size == .one);
// Exiting this `switch` indicates that the `field` pointer representation should be used.
// `field_align` may be `.none` to represent the natural alignment of `field_ty`, but is not necessarily.
@ -3920,7 +3921,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
if (parent_ptr.isUndef(zcu)) return pt.undefValue(result_ty);
const base_ptr = try parent_ptr.canonicalizeBasePtr(.One, aggregate_ty, pt);
const base_ptr = try parent_ptr.canonicalizeBasePtr(.one, aggregate_ty, pt);
return Value.fromInterned(try pt.intern(.{ .ptr = .{
.ty = result_ty.toIntern(),
.base_addr = .{ .field = .{
@ -3937,8 +3938,8 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value {
const zcu = pt.zcu;
const parent_ptr = switch (orig_parent_ptr.typeOf(zcu).ptrSize(zcu)) {
.One, .Many, .C => orig_parent_ptr,
.Slice => orig_parent_ptr.slicePtr(zcu),
.one, .many, .c => orig_parent_ptr,
.slice => orig_parent_ptr.slicePtr(zcu),
};
const parent_ptr_ty = parent_ptr.typeOf(zcu);
@ -3959,7 +3960,7 @@ pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value
};
const strat: PtrStrat = switch (parent_ptr_ty.ptrSize(zcu)) {
.One => switch (elem_ty.zigTypeTag(zcu)) {
.one => switch (elem_ty.zigTypeTag(zcu)) {
.vector => .{ .offset = field_idx * @divExact(try elem_ty.childType(zcu).bitSizeSema(pt), 8) },
.array => strat: {
const arr_elem_ty = elem_ty.childType(zcu);
@ -3971,12 +3972,12 @@ pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value
else => unreachable,
},
.Many, .C => if (try elem_ty.comptimeOnlySema(pt))
.many, .c => if (try elem_ty.comptimeOnlySema(pt))
.{ .elem_ptr = elem_ty }
else
.{ .offset = field_idx * (try elem_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar },
.Slice => unreachable,
.slice => unreachable,
};
switch (strat) {
@ -4004,7 +4005,7 @@ pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value
},
else => {},
}
const base_ptr = try parent_ptr.canonicalizeBasePtr(.Many, arr_base_ty, pt);
const base_ptr = try parent_ptr.canonicalizeBasePtr(.many, arr_base_ty, pt);
return Value.fromInterned(try pt.intern(.{ .ptr = .{
.ty = result_ty.toIntern(),
.base_addr = .{ .arr_elem = .{
@ -4234,7 +4235,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
.child = parent_ptr_info.child,
.flags = flags: {
var flags = parent_ptr_info.flags;
flags.size = .One;
flags.size = .one;
break :flags flags;
},
});
@ -4304,8 +4305,8 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
if (!cur_ty.isPtrLikeOptional(zcu)) break :ptr_opt;
if (need_child.zigTypeTag(zcu) != .pointer) break :ptr_opt;
switch (need_child.ptrSize(zcu)) {
.One, .Many => {},
.Slice, .C => break :ptr_opt,
.one, .many => {},
.slice, .c => break :ptr_opt,
}
const parent = try arena.create(PointerDeriveStep);
parent.* = cur_derive;
@ -4323,7 +4324,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
const elem_size = elem_ty.abiSize(zcu);
const start_idx = cur_offset / elem_size;
const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size;
if (end_idx == start_idx + 1 and ptr_ty_info.flags.size == .One) {
if (end_idx == start_idx + 1 and ptr_ty_info.flags.size == .one) {
const parent = try arena.create(PointerDeriveStep);
parent.* = cur_derive;
cur_derive = .{ .elem_ptr = .{
@ -4531,6 +4532,20 @@ pub fn resolveLazy(
}
}
const InterpretMode = enum {
/// In this mode, types are assumed to match what the compiler was built with in terms of field
/// order, field types, etc. This improves compiler performance. However, it means that certain
/// modifications to `std.builtin` will result in compiler crashes.
direct,
/// In this mode, various details of the type are allowed to differ from what the compiler was built
/// with. Fields are matched by name rather than index; added struct fields are ignored, and removed
/// struct fields use their default value if one exists. This is slower than `.direct`, but permits
/// making certain changes to `std.builtin` (in particular reordering/adding/removing fields), so it
/// is useful when applying breaking changes.
by_name,
};
const interpret_mode: InterpretMode = @field(InterpretMode, @tagName(build_options.value_interpret_mode));
/// Given a `Value` representing a comptime-known value of type `T`, unwrap it into an actual `T` known to the compiler.
/// This is useful for accessing `std.builtin` structures received from comptime logic.
/// `val` must be fully resolved.
@ -4583,11 +4598,20 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe
else
null,
.@"enum" => zcu.toEnum(T, val),
.@"enum" => switch (interpret_mode) {
.direct => {
const int = val.getUnsignedInt(zcu) orelse return error.TypeMismatch;
return std.meta.intToEnum(T, int) catch error.TypeMismatch;
},
.by_name => {
const field_index = ty.enumTagFieldIndex(val, zcu) orelse return error.TypeMismatch;
const field_name = ty.enumFieldName(field_index, zcu);
return std.meta.stringToEnum(T, field_name.toSlice(ip)) orelse error.TypeMismatch;
},
},
.@"union" => |@"union"| {
const union_obj = zcu.typeToUnion(ty) orelse return error.TypeMismatch;
if (union_obj.field_types.len != @"union".fields.len) return error.TypeMismatch;
// No need to handle `interpret_mode`, because the `.@"enum"` handling already deals with it.
const tag_val = val.unionTag(zcu) orelse return error.TypeMismatch;
const tag = try tag_val.interpret(@"union".tag_type.?, pt);
return switch (tag) {
@ -4599,14 +4623,28 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe
};
},
.@"struct" => |@"struct"| {
if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch;
var result: T = undefined;
inline for (@"struct".fields, 0..) |field, field_idx| {
const field_val = try val.fieldValue(pt, field_idx);
@field(result, field.name) = try field_val.interpret(field.type, pt);
}
return result;
.@"struct" => |@"struct"| switch (interpret_mode) {
.direct => {
if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch;
var result: T = undefined;
inline for (@"struct".fields, 0..) |field, field_idx| {
const field_val = try val.fieldValue(pt, field_idx);
@field(result, field.name) = try field_val.interpret(field.type, pt);
}
return result;
},
.by_name => {
const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch;
var result: T = undefined;
inline for (@"struct".fields) |field| {
const field_name_ip = try ip.getOrPutString(zcu.gpa, pt.tid, field.name, .no_embedded_nulls);
@field(result, field.name) = if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| f: {
const field_val = try val.fieldValue(pt, field_idx);
break :f try field_val.interpret(field.type, pt);
} else (field.defaultValue() orelse return error.TypeMismatch);
}
return result;
},
},
};
}
@ -4618,6 +4656,7 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory
const T = @TypeOf(val);
const zcu = pt.zcu;
const ip = &zcu.intern_pool;
if (ty.zigTypeTag(zcu) != @typeInfo(T)) return error.TypeMismatch;
return switch (@typeInfo(T)) {
@ -4657,9 +4696,17 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory
else
try pt.nullValue(ty),
.@"enum" => try pt.enumValue(ty, (try uninterpret(@intFromEnum(val), ty.intTagType(zcu), pt)).toIntern()),
.@"enum" => switch (interpret_mode) {
.direct => try pt.enumValue(ty, (try uninterpret(@intFromEnum(val), ty.intTagType(zcu), pt)).toIntern()),
.by_name => {
const field_name_ip = try ip.getOrPutString(zcu.gpa, pt.tid, @tagName(val), .no_embedded_nulls);
const field_idx = ty.enumFieldIndex(field_name_ip, zcu) orelse return error.TypeMismatch;
return pt.enumValueFieldIndex(ty, field_idx);
},
},
.@"union" => |@"union"| {
// No need to handle `interpret_mode`, because the `.@"enum"` handling already deals with it.
const tag: @"union".tag_type.? = val;
const tag_val = try uninterpret(tag, ty.unionTagType(zcu).?, pt);
const field_ty = ty.unionFieldType(tag_val, zcu) orelse return error.TypeMismatch;
@ -4672,17 +4719,44 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory
};
},
.@"struct" => |@"struct"| {
if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch;
var field_vals: [@"struct".fields.len]InternPool.Index = undefined;
inline for (&field_vals, @"struct".fields, 0..) |*field_val, field, field_idx| {
const field_ty = ty.fieldType(field_idx, zcu);
field_val.* = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern();
}
return .fromInterned(try pt.intern(.{ .aggregate = .{
.ty = ty.toIntern(),
.storage = .{ .elems = &field_vals },
} }));
.@"struct" => |@"struct"| switch (interpret_mode) {
.direct => {
if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch;
var field_vals: [@"struct".fields.len]InternPool.Index = undefined;
inline for (&field_vals, @"struct".fields, 0..) |*field_val, field, field_idx| {
const field_ty = ty.fieldType(field_idx, zcu);
field_val.* = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern();
}
return .fromInterned(try pt.intern(.{ .aggregate = .{
.ty = ty.toIntern(),
.storage = .{ .elems = &field_vals },
} }));
},
.by_name => {
const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch;
const want_fields_len = struct_obj.field_types.len;
const field_vals = try zcu.gpa.alloc(InternPool.Index, want_fields_len);
defer zcu.gpa.free(field_vals);
@memset(field_vals, .none);
inline for (@"struct".fields) |field| {
const field_name_ip = try ip.getOrPutString(zcu.gpa, pt.tid, field.name, .no_embedded_nulls);
if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| {
const field_ty = ty.fieldType(field_idx, zcu);
field_vals[field_idx] = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern();
}
}
for (field_vals, 0..) |*field_val, field_idx| {
if (field_val.* == .none) {
const default_init = struct_obj.field_inits.get(ip)[field_idx];
if (default_init == .none) return error.TypeMismatch;
field_val.* = default_init;
}
}
return .fromInterned(try pt.intern(.{ .aggregate = .{
.ty = ty.toIntern(),
.storage = .{ .elems = field_vals },
} }));
},
},
};
}

View file

@ -3486,10 +3486,6 @@ pub fn funcInfo(zcu: *const Zcu, func_index: InternPool.Index) InternPool.Key.Fu
return zcu.intern_pool.toFunc(func_index);
}
pub fn toEnum(zcu: *const Zcu, comptime E: type, val: Value) E {
return zcu.intern_pool.toEnum(E, val.toIntern());
}
pub const UnionLayout = struct {
abi_size: u64,
abi_align: Alignment,

View file

@ -3068,7 +3068,7 @@ pub fn populateTestFunctions(
.child = test_fn_ty.toIntern(),
.flags = .{
.is_const = true,
.size = .Slice,
.size = .slice,
},
});
const new_init = try pt.intern(.{ .slice = .{
@ -3303,7 +3303,7 @@ pub fn optionalType(pt: Zcu.PerThread, child_type: InternPool.Index) Allocator.E
pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!Type {
var canon_info = info;
if (info.flags.size == .C) canon_info.flags.is_allowzero = true;
if (info.flags.size == .c) canon_info.flags.is_allowzero = true;
// Canonicalize non-zero alignment. If it matches the ABI alignment of the pointee
// type, we change it to 0 here. If this causes an assertion trip because the
@ -3360,7 +3360,7 @@ pub fn manyConstPtrType(pt: Zcu.PerThread, child_type: Type) Allocator.Error!Typ
return pt.ptrType(.{
.child = child_type.toIntern(),
.flags = .{
.size = .Many,
.size = .many,
.is_const = true,
},
});

View file

@ -2398,7 +2398,7 @@ fn ptrArithmetic(
const ptr_ty = lhs_ty;
const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
.One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
.one => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
else => ptr_ty.childType(zcu),
};
const elem_size = elem_ty.abiSize(zcu);

View file

@ -3919,7 +3919,7 @@ fn ptrArithmetic(
const ptr_ty = lhs_ty;
const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
.One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
.one => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
else => ptr_ty.childType(zcu),
};
const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));

View file

@ -7843,15 +7843,15 @@ fn airMemset(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
if (elem_abi_size == 1) {
const ptr: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
// TODO: this only handles slices stored in the stack
.Slice => dst_ptr,
.One => dst_ptr,
.C, .Many => unreachable,
.slice => dst_ptr,
.one => dst_ptr,
.c, .many => unreachable,
};
const len: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
// TODO: this only handles slices stored in the stack
.Slice => dst_ptr.address().offset(8).deref(),
.One => .{ .immediate = dst_ptr_ty.childType(zcu).arrayLen(zcu) },
.C, .Many => unreachable,
.slice => dst_ptr.address().offset(8).deref(),
.one => .{ .immediate = dst_ptr_ty.childType(zcu).arrayLen(zcu) },
.c, .many => unreachable,
};
const len_lock: ?RegisterLock = switch (len) {
.register => |reg| func.register_manager.lockRegAssumeUnused(reg),
@ -7867,8 +7867,8 @@ fn airMemset(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
// Length zero requires a runtime check - so we handle arrays specially
// here to elide it.
switch (dst_ptr_ty.ptrSize(zcu)) {
.Slice => return func.fail("TODO: airMemset Slices", .{}),
.One => {
.slice => return func.fail("TODO: airMemset Slices", .{}),
.one => {
const elem_ptr_ty = try pt.singleMutPtrType(elem_ty);
const len = dst_ptr_ty.childType(zcu).arrayLen(zcu);
@ -7889,7 +7889,7 @@ fn airMemset(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
const bytes_to_copy: MCValue = .{ .immediate = elem_abi_size * (len - 1) };
try func.genInlineMemcpy(second_elem_ptr_mcv, dst_ptr, bytes_to_copy);
},
.C, .Many => unreachable,
.c, .many => unreachable,
}
}
return func.finishAir(inst, .unreach, .{ bin_op.lhs, bin_op.rhs, .none });
@ -7906,7 +7906,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void {
const dst_ty = func.typeOf(bin_op.lhs);
const len_mcv: MCValue = switch (dst_ty.ptrSize(zcu)) {
.Slice => len: {
.slice => len: {
const len_reg, const len_lock = try func.allocReg(.int);
defer func.register_manager.unlockReg(len_lock);
@ -7921,7 +7921,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void {
);
break :len .{ .register = len_reg };
},
.One => len: {
.one => len: {
const array_ty = dst_ty.childType(zcu);
break :len .{ .immediate = array_ty.arrayLen(zcu) * array_ty.childType(zcu).abiSize(zcu) };
},

View file

@ -109,7 +109,7 @@ pub fn classifySystem(ty: Type, zcu: *Zcu) [8]SystemClass {
return result;
},
.pointer => switch (ty.ptrSize(zcu)) {
.Slice => {
.slice => {
result[0] = .integer;
result[1] = .integer;
return result;

View file

@ -2953,7 +2953,7 @@ fn binOp(
.pointer => {
const ptr_ty = lhs_ty;
const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
.One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
.one => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
else => ptr_ty.childType(zcu),
};
const elem_size = elem_ty.abiSize(zcu);

View file

@ -4726,7 +4726,7 @@ fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
const offset = try cg.resolveInst(bin_op.rhs);
const ptr_ty = cg.typeOf(bin_op.lhs);
const pointee_ty = switch (ptr_ty.ptrSize(zcu)) {
.One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
.one => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
else => ptr_ty.childType(zcu),
};
@ -4756,12 +4756,12 @@ fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
const ptr_ty = cg.typeOf(bin_op.lhs);
const value = try cg.resolveInst(bin_op.rhs);
const len = switch (ptr_ty.ptrSize(zcu)) {
.Slice => try cg.sliceLen(ptr),
.One => @as(WValue, .{ .imm32 = @as(u32, @intCast(ptr_ty.childType(zcu).arrayLen(zcu))) }),
.C, .Many => unreachable,
.slice => try cg.sliceLen(ptr),
.one => @as(WValue, .{ .imm32 = @as(u32, @intCast(ptr_ty.childType(zcu).arrayLen(zcu))) }),
.c, .many => unreachable,
};
const elem_ty = if (ptr_ty.ptrSize(zcu) == .One)
const elem_ty = if (ptr_ty.ptrSize(zcu) == .one)
ptr_ty.childType(zcu).childType(zcu)
else
ptr_ty.childType(zcu);
@ -5688,7 +5688,7 @@ fn airMemcpy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
const src = try cg.resolveInst(bin_op.rhs);
const src_ty = cg.typeOf(bin_op.rhs);
const len = switch (dst_ty.ptrSize(zcu)) {
.Slice => blk: {
.slice => blk: {
const slice_len = try cg.sliceLen(dst);
if (ptr_elem_ty.abiSize(zcu) != 1) {
try cg.emitWValue(slice_len);
@ -5698,10 +5698,10 @@ fn airMemcpy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
}
break :blk slice_len;
},
.One => @as(WValue, .{
.one => @as(WValue, .{
.imm32 = @as(u32, @intCast(ptr_elem_ty.arrayLen(zcu) * ptr_elem_ty.childType(zcu).abiSize(zcu))),
}),
.C, .Many => unreachable,
.c, .many => unreachable,
};
const dst_ptr = try cg.sliceOrArrayPtr(dst, dst_ty);
const src_ptr = try cg.sliceOrArrayPtr(src, src_ty);

View file

@ -9607,13 +9607,13 @@ fn genMulDivBinOp(
const manyptr_u32_ty = try pt.ptrType(.{
.child = .u32_type,
.flags = .{
.size = .Many,
.size = .many,
},
});
const manyptr_const_u32_ty = try pt.ptrType(.{
.child = .u32_type,
.flags = .{
.size = .Many,
.size = .many,
.is_const = true,
},
});
@ -16614,15 +16614,15 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
if (elem_abi_size == 1) {
const ptr: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
// TODO: this only handles slices stored in the stack
.Slice => dst_ptr,
.One => dst_ptr,
.C, .Many => unreachable,
.slice => dst_ptr,
.one => dst_ptr,
.c, .many => unreachable,
};
const len: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
// TODO: this only handles slices stored in the stack
.Slice => dst_ptr.address().offset(8).deref(),
.One => .{ .immediate = dst_ptr_ty.childType(zcu).arrayLen(zcu) },
.C, .Many => unreachable,
.slice => dst_ptr.address().offset(8).deref(),
.one => .{ .immediate = dst_ptr_ty.childType(zcu).arrayLen(zcu) },
.c, .many => unreachable,
};
const len_lock: ?RegisterLock = switch (len) {
.register => |reg| self.register_manager.lockRegAssumeUnused(reg),
@ -16638,7 +16638,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
// Length zero requires a runtime check - so we handle arrays specially
// here to elide it.
switch (dst_ptr_ty.ptrSize(zcu)) {
.Slice => {
.slice => {
const slice_ptr_ty = dst_ptr_ty.slicePtrFieldType(zcu);
// TODO: this only handles slices stored in the stack
@ -16681,7 +16681,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
self.performReloc(skip_reloc);
},
.One => {
.one => {
const elem_ptr_ty = try pt.singleMutPtrType(elem_ty);
const len = dst_ptr_ty.childType(zcu).arrayLen(zcu);
@ -16704,7 +16704,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
const bytes_to_copy: MCValue = .{ .immediate = elem_abi_size * (len - 1) };
try self.genInlineMemcpy(second_elem_ptr_mcv, dst_ptr, bytes_to_copy);
},
.C, .Many => unreachable,
.c, .many => unreachable,
}
}
return self.finishAir(inst, .unreach, .{ bin_op.lhs, bin_op.rhs, .none });
@ -16735,7 +16735,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
defer if (src_ptr_lock) |lock| self.register_manager.unlockReg(lock);
const len: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
.Slice => len: {
.slice => len: {
const len_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
const len_lock = self.register_manager.lockRegAssumeUnused(len_reg);
defer self.register_manager.unlockReg(len_lock);
@ -16748,11 +16748,11 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
);
break :len .{ .register = len_reg };
},
.One => len: {
.one => len: {
const array_ty = dst_ptr_ty.childType(zcu);
break :len .{ .immediate = array_ty.arrayLen(zcu) * array_ty.childType(zcu).abiSize(zcu) };
},
.C, .Many => unreachable,
.c, .many => unreachable,
};
const len_lock: ?RegisterLock = switch (len) {
.register => |reg| self.register_manager.lockRegAssumeUnused(reg),

View file

@ -108,7 +108,7 @@ pub fn classifySystemV(ty: Type, zcu: *Zcu, target: std.Target, ctx: Context) [8
var result = [1]Class{.none} ** 8;
switch (ty.zigTypeTag(zcu)) {
.pointer => switch (ty.ptrSize(zcu)) {
.Slice => {
.slice => {
result[0] = .integer;
result[1] = .integer;
return result;

View file

@ -177,7 +177,7 @@ pub const ASTUnit = opaque {
extern fn ZigClangASTUnit_visitLocalTopLevelDecls(
*ASTUnit,
context: ?*anyopaque,
Fn: ?*const fn (?*anyopaque, *const Decl) callconv(.C) bool,
Fn: ?*const fn (?*anyopaque, *const Decl) callconv(.c) bool,
) bool;
pub const getLocalPreprocessingEntities_begin = ZigClangASTUnit_getLocalPreprocessingEntities_begin;

View file

@ -945,7 +945,7 @@ pub fn genTypedValue(
switch (ty.zigTypeTag(zcu)) {
.void => return .{ .mcv = .none },
.pointer => switch (ty.ptrSize(zcu)) {
.Slice => {},
.slice => {},
else => switch (val.toIntern()) {
.null_value => {
return .{ .mcv = .{ .immediate = 0 } };

View file

@ -1589,14 +1589,14 @@ pub const DeclGen = struct {
try dg.fmtIntLiteral(try pt.undefValue(ty), location),
}),
.ptr_type => |ptr_type| switch (ptr_type.flags.size) {
.One, .Many, .C => {
.one, .many, .c => {
try writer.writeAll("((");
try dg.renderCType(writer, ctype);
return writer.print("){x})", .{
try dg.fmtIntLiteral(try pt.undefValue(Type.usize), .Other),
});
},
.Slice => {
.slice => {
if (!location.isInitializer()) {
try writer.writeByte('(');
try dg.renderCType(writer, ctype);
@ -3570,7 +3570,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
try f.renderType(writer, inst_ty);
try writer.writeByte(')');
if (elem_has_bits) try writer.writeByte('&');
if (elem_has_bits and ptr_ty.ptrSize(zcu) == .One) {
if (elem_has_bits and ptr_ty.ptrSize(zcu) == .one) {
// It's a pointer to an array, so we need to de-reference.
try f.writeCValueDeref(writer, ptr);
} else try f.writeCValue(writer, ptr, .Other);
@ -5798,8 +5798,8 @@ fn fieldLocation(
}
},
.ptr_type => |ptr_info| switch (ptr_info.flags.size) {
.One, .Many, .C => unreachable,
.Slice => switch (field_index) {
.one, .many, .c => unreachable,
.slice => switch (field_index) {
0 => return .{ .field = .{ .identifier = "ptr" } },
1 => return .{ .field = .{ .identifier = "len" } },
else => unreachable,
@ -6902,7 +6902,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
try writer.writeAll("memset(");
switch (dest_ty.ptrSize(zcu)) {
.Slice => {
.slice => {
try f.writeCValueMember(writer, dest_slice, .{ .identifier = "ptr" });
try writer.writeAll(", 0xaa, ");
try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" });
@ -6912,14 +6912,14 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
try writer.writeAll(");\n");
}
},
.One => {
.one => {
const array_ty = dest_ty.childType(zcu);
const len = array_ty.arrayLen(zcu) * elem_abi_size;
try f.writeCValue(writer, dest_slice, .FunctionArgument);
try writer.print(", 0xaa, {d});\n", .{len});
},
.Many, .C => unreachable,
.many, .c => unreachable,
}
try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
return .none;
@ -6932,7 +6932,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
const elem_ptr_ty = try pt.ptrType(.{
.child = elem_ty.toIntern(),
.flags = .{
.size = .C,
.size = .c,
},
});
@ -6946,14 +6946,14 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
try f.writeCValue(writer, index, .Other);
try writer.writeAll(" != ");
switch (dest_ty.ptrSize(zcu)) {
.Slice => {
.slice => {
try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" });
},
.One => {
.one => {
const array_ty = dest_ty.childType(zcu);
try writer.print("{d}", .{array_ty.arrayLen(zcu)});
},
.Many, .C => unreachable,
.many, .c => unreachable,
}
try writer.writeAll("; ++");
try f.writeCValue(writer, index, .Other);
@ -6981,7 +6981,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
try writer.writeAll("memset(");
switch (dest_ty.ptrSize(zcu)) {
.Slice => {
.slice => {
try f.writeCValueMember(writer, dest_slice, .{ .identifier = "ptr" });
try writer.writeAll(", ");
try f.writeCValue(writer, bitcasted, .FunctionArgument);
@ -6989,7 +6989,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" });
try writer.writeAll(");\n");
},
.One => {
.one => {
const array_ty = dest_ty.childType(zcu);
const len = array_ty.arrayLen(zcu) * elem_abi_size;
@ -6998,7 +6998,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
try f.writeCValue(writer, bitcasted, .FunctionArgument);
try writer.print(", {d});\n", .{len});
},
.Many, .C => unreachable,
.many, .c => unreachable,
}
try f.freeCValue(inst, bitcasted);
try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
@ -7015,7 +7015,7 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
const src_ty = f.typeOf(bin_op.rhs);
const writer = f.object.writer();
if (dest_ty.ptrSize(zcu) != .One) {
if (dest_ty.ptrSize(zcu) != .one) {
try writer.writeAll("if (");
try writeArrayLen(f, writer, dest_ptr, dest_ty);
try writer.writeAll(" != 0) ");
@ -7038,11 +7038,11 @@ fn writeArrayLen(f: *Function, writer: ArrayListWriter, dest_ptr: CValue, dest_t
const pt = f.object.dg.pt;
const zcu = pt.zcu;
switch (dest_ty.ptrSize(zcu)) {
.One => try writer.print("{}", .{
.one => try writer.print("{}", .{
try f.fmtIntLiteral(try pt.intValue(Type.usize, dest_ty.childType(zcu).arrayLen(zcu))),
}),
.Many, .C => unreachable,
.Slice => try f.writeCValueMember(writer, dest_ptr, .{ .identifier = "len" }),
.many, .c => unreachable,
.slice => try f.writeCValueMember(writer, dest_ptr, .{ .identifier = "len" }),
}
}

View file

@ -1458,7 +1458,7 @@ pub const Pool = struct {
_ => |ip_index| switch (ip.indexToKey(ip_index)) {
.int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind),
.ptr_type => |ptr_info| switch (ptr_info.flags.size) {
.One, .Many, .C => {
.one, .many, .c => {
const elem_ctype = elem_ctype: {
if (ptr_info.packed_offset.host_size > 0 and
ptr_info.flags.vector_index == .none)
@ -1505,7 +1505,7 @@ pub const Pool = struct {
.@"volatile" = ptr_info.flags.is_volatile,
});
},
.Slice => {
.slice => {
const target = &mod.resolved_target.result;
var fields = [_]Info.Field{
.{
@ -1598,7 +1598,7 @@ pub const Pool = struct {
switch (payload_type) {
.anyerror_type => return payload_ctype,
else => switch (ip.indexToKey(payload_type)) {
.ptr_type => |payload_ptr_info| if (payload_ptr_info.flags.size != .C and
.ptr_type => |payload_ptr_info| if (payload_ptr_info.flags.size != .c and
!payload_ptr_info.flags.is_allowzero) return payload_ctype,
.error_set_type, .inferred_error_set_type => return payload_ctype,
else => {},

View file

@ -2109,7 +2109,7 @@ pub const Object = struct {
ptr_info.flags.is_allowzero or
ptr_info.flags.is_const or
ptr_info.flags.is_volatile or
ptr_info.flags.size == .Many or ptr_info.flags.size == .C or
ptr_info.flags.size == .many or ptr_info.flags.size == .c or
!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(zcu))
{
const bland_ptr_ty = try pt.ptrType(.{
@ -2120,8 +2120,8 @@ pub const Object = struct {
.flags = .{
.alignment = ptr_info.flags.alignment,
.size = switch (ptr_info.flags.size) {
.Many, .C, .One => .One,
.Slice => .Slice,
.many, .c, .one => .one,
.slice => .slice,
},
},
});
@ -3382,8 +3382,8 @@ pub const Object = struct {
toLlvmAddressSpace(ptr_type.flags.address_space, target),
);
break :type switch (ptr_type.flags.size) {
.One, .Many, .C => ptr_ty,
.Slice => try o.builder.structType(.normal, &.{
.one, .many, .c => ptr_ty,
.slice => try o.builder.structType(.normal, &.{
ptr_ty,
try o.lowerType(Type.usize),
}),
@ -6988,7 +6988,7 @@ pub const FuncGen = struct {
const zcu = pt.zcu;
const llvm_usize = try o.lowerType(Type.usize);
switch (ty.ptrSize(zcu)) {
.Slice => {
.slice => {
const len = try fg.wip.extractValue(ptr, &.{1}, "");
const elem_ty = ty.childType(zcu);
const abi_size = elem_ty.abiSize(zcu);
@ -6996,13 +6996,13 @@ pub const FuncGen = struct {
const abi_size_llvm_val = try o.builder.intValue(llvm_usize, abi_size);
return fg.wip.bin(.@"mul nuw", len, abi_size_llvm_val, "");
},
.One => {
.one => {
const array_ty = ty.childType(zcu);
const elem_ty = array_ty.childType(zcu);
const abi_size = elem_ty.abiSize(zcu);
return o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu) * abi_size);
},
.Many, .C => unreachable,
.many, .c => unreachable,
}
}
@ -8670,11 +8670,11 @@ pub const FuncGen = struct {
const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
switch (ptr_ty.ptrSize(zcu)) {
// It's a pointer to an array, so according to LLVM we need an extra GEP index.
.One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
.one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
try o.builder.intValue(try o.lowerType(Type.usize), 0), offset,
}, ""),
.C, .Many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""),
.Slice => {
.c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""),
.slice => {
const base = try self.wip.extractValue(ptr, &.{0}, "");
return self.wip.gep(.inbounds, llvm_elem_ty, base, &.{offset}, "");
},
@ -8693,11 +8693,11 @@ pub const FuncGen = struct {
const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
switch (ptr_ty.ptrSize(zcu)) {
// It's a pointer to an array, so according to LLVM we need an extra GEP index.
.One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
.one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset,
}, ""),
.C, .Many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""),
.Slice => {
.c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""),
.slice => {
const base = try self.wip.extractValue(ptr, &.{0}, "");
return self.wip.gep(.inbounds, llvm_elem_ty, base, &.{negative_offset}, "");
},
@ -10034,9 +10034,9 @@ pub const FuncGen = struct {
const llvm_usize_ty = try o.lowerType(Type.usize);
const len = switch (ptr_ty.ptrSize(zcu)) {
.Slice => try self.wip.extractValue(dest_slice, &.{1}, ""),
.One => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)),
.Many, .C => unreachable,
.slice => try self.wip.extractValue(dest_slice, &.{1}, ""),
.one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)),
.many, .c => unreachable,
};
const elem_llvm_ty = try o.lowerType(elem_ty);
const end_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, dest_ptr, &.{len}, "");

View file

@ -8463,7 +8463,7 @@ pub const Metadata = enum(u32) {
field.* = .{
.name = name,
.type = []const u8,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
};
@ -8474,7 +8474,7 @@ pub const Metadata = enum(u32) {
field.* = .{
.name = name,
.type = std.fmt.Formatter(format),
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
};

View file

@ -1705,13 +1705,13 @@ const NavGen = struct {
const storage_class = self.spvStorageClass(ptr_info.flags.address_space);
const ptr_ty_id = try self.ptrType(child_ty, storage_class);
if (target.os.tag == .vulkan and ptr_info.flags.size == .Many) {
if (target.os.tag == .vulkan and ptr_info.flags.size == .many) {
try self.spv.decorate(ptr_ty_id, .{ .ArrayStride = .{
.array_stride = @intCast(child_ty.abiSize(zcu)),
} });
}
if (ptr_info.flags.size != .Slice) {
if (ptr_info.flags.size != .slice) {
return ptr_ty_id;
}
@ -4399,15 +4399,15 @@ const NavGen = struct {
const result_ty_id = try self.resolveType(result_ty, .direct);
switch (ptr_ty.ptrSize(zcu)) {
.One => {
.one => {
// Pointer to array
// TODO: Is this correct?
return try self.accessChainId(result_ty_id, ptr_id, &.{offset_id});
},
.C, .Many => {
.c, .many => {
return try self.ptrAccessChain(result_ty_id, ptr_id, offset_id, &.{});
},
.Slice => {
.slice => {
// TODO: This is probably incorrect. A slice should be returned here, though this is what llvm does.
const slice_ptr_id = try self.extractField(result_ty, ptr_id, 0);
return try self.ptrAccessChain(result_ty_id, slice_ptr_id, offset_id, &.{});
@ -4989,15 +4989,15 @@ const NavGen = struct {
const pt = self.pt;
const zcu = pt.zcu;
switch (ty.ptrSize(zcu)) {
.Slice => return self.extractField(Type.usize, operand_id, 1),
.One => {
.slice => return self.extractField(Type.usize, operand_id, 1),
.one => {
const array_ty = ty.childType(zcu);
const elem_ty = array_ty.childType(zcu);
const abi_size = elem_ty.abiSize(zcu);
const size = array_ty.arrayLenIncludingSentinel(zcu) * abi_size;
return try self.constInt(Type.usize, size, .direct);
},
.Many, .C => unreachable,
.many, .c => unreachable,
}
}

View file

@ -159,7 +159,7 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand)
section.writeOperand(info.child, child);
},
.pointer => |info| {
std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec.
std.debug.assert(info.size == .slice); // Should be no other pointer types in the spec.
for (operand) |item| {
section.writeOperand(info.child, item);
}
@ -292,7 +292,7 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
.@"enum" => 1,
.optional => |info| if (operand) |child| operandSize(info.child, child) else 0,
.pointer => |info| blk: {
std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec.
std.debug.assert(info.size == .slice); // Should be no other pointer types in the spec.
var total: usize = 0;
for (operand) |item| {
total += operandSize(info.child, item);

View file

@ -190,7 +190,7 @@ pub fn attachSegfaultHandler() void {
debug.updateSegfaultHandler(&act);
}
fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) noreturn {
fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) noreturn {
// TODO: use alarm() here to prevent infinite loops
PanicSwitch.preDispatch();

View file

@ -3182,7 +3182,7 @@ fn updateLazyType(
try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
},
.ptr_type => |ptr_type| switch (ptr_type.flags.size) {
.One, .Many, .C => {
.one, .many, .c => {
const ptr_child_type: Type = .fromInterned(ptr_type.child);
try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type);
try wip_nav.strp(name);
@ -3210,7 +3210,7 @@ fn updateLazyType(
try wip_nav.refType(ptr_child_type);
}
},
.Slice => {
.slice => {
try wip_nav.abbrevCode(.generated_struct_type);
try wip_nav.strp(name);
try uleb128(diw, ty.abiSize(zcu));

View file

@ -248,7 +248,7 @@ pub const Value = union(enum) {
.array => return encode(arena, &input),
.pointer => |info| switch (info.size) {
.One => switch (@typeInfo(info.child)) {
.one => switch (@typeInfo(info.child)) {
.array => |child_info| {
const Slice = []const child_info.child;
return encode(arena, @as(Slice, input));
@ -257,7 +257,7 @@ pub const Value = union(enum) {
@compileError("Unhandled type: {s}" ++ @typeName(info.child));
},
},
.Slice => {
.slice => {
if (info.child == u8) {
return Value{ .string = try arena.dupe(u8, input) };
}
@ -357,7 +357,7 @@ pub const Yaml = struct {
},
.pointer => |info| {
switch (info.size) {
.Slice => {
.slice => {
var parsed = try self.arena.allocator().alloc(info.child, self.docs.items.len);
for (self.docs.items, 0..) |doc, i| {
parsed[i] = try self.parseValue(info.child, doc);
@ -446,7 +446,7 @@ pub const Yaml = struct {
const arena = self.arena.allocator();
switch (ptr_info.size) {
.Slice => {
.slice => {
if (ptr_info.child == u8) {
return value.asString();
}

View file

@ -256,7 +256,7 @@ pub const MutableValue = union(enum) {
},
.pointer => {
const ptr_ty = ip.indexToKey(ty_ip).ptr_type;
if (ptr_ty.flags.size != .Slice) return;
if (ptr_ty.flags.size != .slice) return;
const ptr = try arena.create(MutableValue);
const len = try arena.create(MutableValue);
ptr.* = .{ .interned = try pt.intern(.{ .undef = ip.slicePtrType(ty_ip) }) };

View file

@ -231,13 +231,13 @@ fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void {
}
}
fn declVisitorNamesOnlyC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.C) bool {
fn declVisitorNamesOnlyC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.c) bool {
const c: *Context = @ptrCast(@alignCast(context));
declVisitorNamesOnly(c, decl) catch return false;
return true;
}
fn declVisitorC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.C) bool {
fn declVisitorC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.c) bool {
const c: *Context = @ptrCast(@alignCast(context));
declVisitor(c, decl) catch return false;
return true;

View file

@ -13,3 +13,4 @@ pub const value_tracing = false;
pub const skip_non_native = false;
pub const force_gpa = false;
pub const dev = .core;
pub const value_interpret_mode = .direct;

View file

@ -1,33 +1,143 @@
#undef linux
#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
#define __STDC_WANT_IEC_60559_TYPES_EXT__
#endif
#include <float.h>
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#if _MSC_VER
#include <intrin.h>
#elif defined(__i386__) || defined(__x86_64__)
#include <cpuid.h>
#if defined(_MSC_VER)
#define zig_msvc
#elif defined(__clang__)
#define zig_clang
#define zig_gnuc
#elif defined(__GNUC__)
#define zig_gnuc
#elif defined(__IBMC__)
#define zig_xlc
#elif defined(__TINYC__)
#define zig_tinyc
#elif defined(__slimcc__)
#define zig_slimcc
#endif
#if !defined(__cplusplus) && __STDC_VERSION__ <= 201710L
#if __STDC_VERSION__ >= 199901L
#include <stdbool.h>
#if defined(__aarch64__) || (defined(zig_msvc) && defined(_M_ARM64))
#define zig_aarch64
#elif defined(__thumb__) || (defined(zig_msvc) && defined(_M_ARM))
#define zig_thumb
#define zig_arm
#elif defined(__arm__)
#define zig_arm
#elif defined(__hexagon__)
#define zig_hexagon
#elif defined(__loongarch32)
#define zig_loongarch32
#define zig_loongarch
#elif defined(__loongarch64)
#define zig_loongarch64
#define zig_loongarch
#elif defined(__mips64)
#define zig_mips64
#define zig_mips
#elif defined(__mips__)
#define zig_mips32
#define zig_mips
#elif defined(__powerpc64__)
#define zig_powerpc64
#define zig_powerpc
#elif defined(__powerpc__)
#define zig_powerpc32
#define zig_powerpc
#elif defined(__riscv) && __riscv_xlen == 32
#define zig_riscv32
#define zig_riscv
#elif defined(__riscv) && __riscv_xlen == 64
#define zig_riscv64
#define zig_riscv
#elif defined(__s390x__)
#define zig_s390x
#elif defined(__sparc__) && defined(__arch64__)
#define zig_sparc64
#define zig_sparc
#elif defined(__sparc__)
#define zig_sparc32
#define zig_sparc
#elif defined(__wasm32__)
#define zig_wasm32
#define zig_wasm
#elif defined(__wasm64__)
#define zig_wasm64
#define zig_wasm
#elif defined(__i386__) || (defined(zig_msvc) && defined(_M_IX86))
#define zig_x86_32
#define zig_x86
#elif defined (__x86_64__) || (defined(zig_msvc) && defined(_M_X64))
#define zig_x86_64
#define zig_x86
#endif
#if defined(zig_msvc) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define zig_little_endian 1
#define zig_big_endian 0
#else
typedef char bool;
#define false 0
#define true 1
#define zig_little_endian 0
#define zig_big_endian 1
#endif
#if defined(_AIX)
#define zig_aix
#elif defined(__MACH__)
#define zig_darwin
#elif defined(__DragonFly__)
#define zig_dragonfly
#define zig_bsd
#elif defined(__EMSCRIPTEN__)
#define zig_emscripten
#elif defined(__FreeBSD__)
#define zig_freebsd
#define zig_bsd
#elif defined(__Fuchsia__)
#define zig_fuchsia
#elif defined(__HAIKU__)
#define zig_haiku
#elif defined(__gnu_hurd__)
#define zig_hurd
#elif defined(__linux__)
#define zig_linux
#elif defined(__NetBSD__)
#define zig_netbsd
#define zig_bsd
#elif defined(__OpenBSD__)
#define zig_openbsd
#define zig_bsd
#elif defined(__SVR4)
#define zig_solaris
#elif defined(__wasi__)
#define zig_wasi
#elif defined(_WIN32)
#define zig_windows
#elif defined(__MVS__)
#define zig_zos
#endif
#if defined(zig_windows)
#define zig_coff
#elif defined(__ELF__)
#define zig_elf
#elif defined(zig_zos)
#define zig_goff
#elif defined(zig_darwin)
#define zig_macho
#elif defined(zig_aix)
#define zig_xcoff
#endif
#define zig_concat(lhs, rhs) lhs##rhs
#define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs)
#if defined(__has_include)
#define zig_has_include(include) __has_include(include)
#else
#define zig_has_include(include) 0
#endif
#if defined(__has_builtin)
#define zig_has_builtin(builtin) __has_builtin(__builtin_##builtin)
#else
@ -41,37 +151,19 @@ typedef char bool;
#define zig_has_attribute(attribute) 0
#endif
#if __LITTLE_ENDIAN__ || _MSC_VER
#define zig_little_endian 1
#define zig_big_endian 0
#else
#define zig_little_endian 0
#define zig_big_endian 1
#endif
#if __STDC_VERSION__ >= 201112L
#if __STDC_VERSION__ >= 202311L
#define zig_threadlocal thread_local
#elif __STDC_VERSION__ >= 201112L
#define zig_threadlocal _Thread_local
#elif defined(__GNUC__)
#elif defined(zig_gnuc) || defined(zig_slimcc)
#define zig_threadlocal __thread
#elif _MSC_VER
#elif defined(zig_msvc)
#define zig_threadlocal __declspec(thread)
#else
#define zig_threadlocal zig_threadlocal_unavailable
#endif
#if defined(__clang__)
#define zig_clang
#elif defined(__GNUC__)
#define zig_gnuc
#endif
#if defined(zig_gnuc) && (defined(__i386__) || defined(__x86_64__))
#define zig_f128_has_miscompilations 1
#else
#define zig_f128_has_miscompilations 0
#endif
#if _MSC_VER
#if defined(zig_msvc)
#define zig_const_arr
#define zig_callconv(c) __##c
#else
@ -82,7 +174,7 @@ typedef char bool;
#if zig_has_attribute(naked) || defined(zig_gnuc)
#define zig_naked_decl __attribute__((naked))
#define zig_naked __attribute__((naked))
#elif defined(_MSC_VER)
#elif defined(zig_msvc)
#define zig_naked_decl
#define zig_naked __declspec(naked)
#else
@ -104,7 +196,7 @@ typedef char bool;
#if zig_has_attribute(noinline)
#define zig_never_inline __attribute__((noinline)) zig_maybe_flatten
#elif defined(_MSC_VER)
#elif defined(zig_msvc)
#define zig_never_inline __declspec(noinline) zig_maybe_flatten
#else
#define zig_never_inline zig_never_inline_unavailable
@ -124,46 +216,48 @@ typedef char bool;
#if __STDC_VERSION__ >= 199901L
#define zig_restrict restrict
#elif defined(__GNUC__)
#elif defined(zig_gnuc) || defined(zig_tinyc)
#define zig_restrict __restrict
#else
#define zig_restrict
#endif
#if zig_has_attribute(aligned)
#if zig_has_attribute(aligned) || defined(zig_tinyc)
#define zig_under_align(alignment) __attribute__((aligned(alignment)))
#elif _MSC_VER
#elif defined(zig_msvc)
#define zig_under_align(alignment) __declspec(align(alignment))
#else
#define zig_under_align zig_align_unavailable
#endif
#if __STDC_VERSION__ >= 201112L
#if __STDC_VERSION__ >= 202311L
#define zig_align(alignment) alignas(alignment)
#elif __STDC_VERSION__ >= 201112L
#define zig_align(alignment) _Alignas(alignment)
#else
#define zig_align(alignment) zig_under_align(alignment)
#endif
#if zig_has_attribute(aligned)
#if zig_has_attribute(aligned) || defined(zig_tinyc)
#define zig_align_fn(alignment) __attribute__((aligned(alignment)))
#elif _MSC_VER
#elif defined(zig_msvc)
#define zig_align_fn(alignment)
#else
#define zig_align_fn zig_align_fn_unavailable
#endif
#if zig_has_attribute(packed)
#if zig_has_attribute(packed) || defined(zig_tinyc)
#define zig_packed(definition) __attribute__((packed)) definition
#elif _MSC_VER
#elif defined(zig_msvc)
#define zig_packed(definition) __pragma(pack(1)) definition __pragma(pack())
#else
#define zig_packed(definition) zig_packed_unavailable
#endif
#if zig_has_attribute(section)
#if zig_has_attribute(section) || defined(zig_tinyc)
#define zig_linksection(name) __attribute__((section(name)))
#define zig_linksection_fn zig_linksection
#elif _MSC_VER
#elif defined(zig_msvc)
#define zig_linksection(name) __pragma(section(name, read, write)) __declspec(allocate(name))
#define zig_linksection_fn(name) __pragma(section(name, read, execute)) __declspec(code_seg(name))
#else
@ -171,8 +265,10 @@ typedef char bool;
#define zig_linksection_fn zig_linksection
#endif
#if zig_has_builtin(unreachable) || defined(zig_gnuc)
#if zig_has_builtin(unreachable) || defined(zig_gnuc) || defined(zig_tinyc)
#define zig_unreachable() __builtin_unreachable()
#elif defined(zig_msvc)
#define zig_unreachable() __assume(0)
#else
#define zig_unreachable()
#endif
@ -183,23 +279,23 @@ typedef char bool;
#define zig_extern extern
#endif
#if _MSC_VER
#if _M_X64
#if defined(zig_msvc)
#if defined(zig_x86_64)
#define zig_mangle_c(symbol) symbol
#else /*_M_X64 */
#else /* zig_x86_64 */
#define zig_mangle_c(symbol) "_" symbol
#endif /*_M_X64 */
#else /* _MSC_VER */
#if __APPLE__
#endif /* zig_x86_64 */
#else /* zig_msvc */
#if defined(zig_macho)
#define zig_mangle_c(symbol) "_" symbol
#else /* __APPLE__ */
#else /* zig_macho */
#define zig_mangle_c(symbol) symbol
#endif /* __APPLE__ */
#endif /* _MSC_VER */
#endif /* zig_macho */
#endif /* zig_msvc */
#if zig_has_attribute(alias) && !__APPLE__
#if (zig_has_attribute(alias) || defined(zig_tinyc)) && !defined(zig_macho)
#define zig_export(symbol, name) __attribute__((alias(symbol)))
#elif _MSC_VER
#elif defined(zig_msvc)
#define zig_export(symbol, name) ; \
__pragma(comment(linker, "/alternatename:" zig_mangle_c(name) "=" zig_mangle_c(symbol)))
#else
@ -209,24 +305,24 @@ typedef char bool;
#define zig_mangled_tentative zig_mangled
#define zig_mangled_final zig_mangled
#if _MSC_VER
#if defined(zig_msvc)
#define zig_mangled(mangled, unmangled) ; \
zig_export(#mangled, unmangled)
#define zig_mangled_export(mangled, unmangled, symbol) \
zig_export(unmangled, #mangled) \
zig_export(symbol, unmangled)
#else /* _MSC_VER */
#else /* zig_msvc */
#define zig_mangled(mangled, unmangled) __asm(zig_mangle_c(unmangled))
#define zig_mangled_export(mangled, unmangled, symbol) \
zig_mangled_final(mangled, unmangled) \
zig_export(symbol, unmangled)
#endif /* _MSC_VER */
#endif /* zig_msvc */
#if _MSC_VER
#if defined(zig_msvc)
#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\
__pragma(comment(linker, "/alternatename:" zig_mangle_c(#fn_name) "=" zig_mangle_c(#libc_name)));
#define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, sig_args, call_args)
#else /* _MSC_VER */
#else /* zig_msvc */
#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm(zig_mangle_c(#libc_name));
#define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type libc_name sig_args; \
static inline Type fn_name sig_args { return libc_name call_args; }
@ -235,10 +331,10 @@ typedef char bool;
#define zig_expand_import_0(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args)
#define zig_expand_import_1(Type, fn_name, libc_name, sig_args, call_args) zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args)
#if zig_has_attribute(weak) || defined(zig_gnuc)
#if zig_has_attribute(weak) || defined(zig_gnuc) || defined(zig_tinyc)
#define zig_weak_linkage __attribute__((weak))
#define zig_weak_linkage_fn __attribute__((weak))
#elif _MSC_VER
#elif defined(zig_msvc)
#define zig_weak_linkage __declspec(selectany)
#define zig_weak_linkage_fn
#else
@ -246,68 +342,94 @@ typedef char bool;
#define zig_weak_linkage_fn zig_weak_linkage_unavailable
#endif
#if defined(zig_gnuc) || defined(zig_tinyc) || defined(zig_slimcc)
#define zig_gnuc_asm
#endif
#if zig_has_builtin(trap)
#define zig_trap() __builtin_trap()
#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
#elif defined(zig_msvc)
#if defined(zig_x86)
#define zig_trap() __ud2()
#elif defined(_MSC_VER)
#else
#define zig_trap() __fastfail(7)
#elif defined(__thumb__)
#endif
#elif defined(zig_gnuc_asm)
#if defined(zig_thumb)
#define zig_trap() __asm__ volatile("udf #0xfe")
#elif defined(__arm__) || defined(__aarch64__)
#elif defined(zig_arm) || defined(zig_aarch64)
#define zig_trap() __asm__ volatile("udf #0xfdee")
#elif defined(__loongarch__) || defined(__powerpc__)
#elif defined(zig_hexagon)
#define zig_trap() __asm__ volatile("r27:26 = memd(#0xbadc0fee)")
#elif defined(zig_loongarch) || defined(zig_powerpc)
#define zig_trap() __asm__ volatile(".word 0x0")
#elif defined(__mips__)
#elif defined(zig_mips)
#define zig_trap() __asm__ volatile(".word 0x3d")
#elif defined(__riscv)
#elif defined(zig_riscv)
#define zig_trap() __asm__ volatile("unimp")
#elif defined(__s390__)
#elif defined(zig_s390x)
#define zig_trap() __asm__ volatile("j 0x2")
#elif defined(__sparc__)
#elif defined(zig_sparc)
#define zig_trap() __asm__ volatile("illtrap")
#elif defined(__i386__) || defined(__x86_64__)
#elif defined(zig_x86)
#define zig_trap() __asm__ volatile("ud2")
#else
#define zig_trap() zig_trap_unavailable
#endif
#else
#define zig_trap() zig_trap_unavailable
#endif
#if zig_has_builtin(debugtrap)
#define zig_breakpoint() __builtin_debugtrap()
#elif defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
#elif defined(zig_msvc)
#define zig_breakpoint() __debugbreak()
#elif defined(__arm__)
#elif defined(zig_gnuc_asm)
#if defined(zig_arm)
#define zig_breakpoint() __asm__ volatile("bkpt #0x0")
#elif defined(__aarch64__)
#elif defined(zig_aarch64)
#define zig_breakpoint() __asm__ volatile("brk #0xf000")
#elif defined(__loongarch__)
#elif defined(zig_hexagon)
#define zig_breakpoint() __asm__ volatile("brkpt")
#elif defined(zig_loongarch)
#define zig_breakpoint() __asm__ volatile("break 0x0")
#elif defined(__mips__)
#elif defined(zig_mips)
#define zig_breakpoint() __asm__ volatile("break")
#elif defined(__powerpc__)
#elif defined(zig_powerpc)
#define zig_breakpoint() __asm__ volatile("trap")
#elif defined(__riscv)
#elif defined(zig_riscv)
#define zig_breakpoint() __asm__ volatile("ebreak")
#elif defined(__s390__)
#elif defined(zig_s390x)
#define zig_breakpoint() __asm__ volatile("j 0x6")
#elif defined(__sparc__)
#elif defined(zig_sparc)
#define zig_breakpoint() __asm__ volatile("ta 0x1")
#elif defined(__i386__) || defined(__x86_64__)
#elif defined(zig_x86)
#define zig_breakpoint() __asm__ volatile("int $0x3")
#else
#define zig_breakpoint() zig_breakpoint_unavailable
#endif
#if zig_has_builtin(return_address) || defined(zig_gnuc)
#else
#define zig_breakpoint() zig_breakpoint_unavailable
#endif
#if zig_has_builtin(return_address) || defined(zig_gnuc) || defined(zig_tinyc)
#define zig_return_address() __builtin_extract_return_addr(__builtin_return_address(0))
#elif defined(_MSC_VER)
#elif defined(zig_msvc)
#define zig_return_address() _ReturnAddress()
#else
#define zig_return_address() 0
#endif
#if zig_has_builtin(frame_address) || defined(zig_gnuc)
#if zig_has_builtin(frame_address) || defined(zig_gnuc) || defined(zig_tinyc)
#define zig_frame_address() __builtin_frame_address(0)
#elif defined(zig_msvc)
#define zig_frame_address() _AddressOfReturnAddress()
#else
#define zig_frame_address() 0
#endif
@ -326,18 +448,18 @@ typedef char bool;
#define zig_wasm_memory_grow(index, delta) zig_unimplemented()
#endif
#if __STDC_VERSION__ >= 201112L
#if __STDC_VERSION__ >= 202311L
#define zig_noreturn [[noreturn]]
#elif __STDC_VERSION__ >= 201112L
#define zig_noreturn _Noreturn
#elif zig_has_attribute(noreturn) || defined(zig_gnuc)
#elif zig_has_attribute(noreturn) || defined(zig_gnuc) || defined(zig_tinyc)
#define zig_noreturn __attribute__((noreturn))
#elif _MSC_VER
#elif defined(zig_msvc)
#define zig_noreturn __declspec(noreturn)
#else
#define zig_noreturn
#endif
#define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T))
#define zig_compiler_rt_abbrev_uint32_t si
#define zig_compiler_rt_abbrev_int32_t si
#define zig_compiler_rt_abbrev_uint64_t di
@ -353,12 +475,25 @@ typedef char bool;
zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t);
zig_extern void *memset (void *, int, size_t);
/* ===================== 8/16/32/64-bit Integer Support ===================== */
/* ================ Bool and 8/16/32/64-bit Integer Support ================= */
#if __STDC_VERSION__ >= 199901L || _MSC_VER
#include <limits.h>
#define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T))
#if __STDC_VERSION__ >= 202311L
/* bool, true, and false are provided by the language. */
#elif __STDC_VERSION__ >= 199901L || zig_has_include(<stdbool.h>)
#include <stdbool.h>
#else
typedef char bool;
#define false 0
#define true 1
#endif
#if __STDC_VERSION__ >= 199901L || defined(zig_msvc) || zig_has_include(<stdint.h>)
#include <stdint.h>
#else
#if SCHAR_MIN == ~0x7F && SCHAR_MAX == 0x7F && UCHAR_MAX == 0xFF
typedef unsigned char uint8_t;
typedef signed char int8_t;
@ -1132,7 +1267,7 @@ static inline int64_t zig_bit_reverse_i64(int64_t val, uint8_t bits) {
static inline uint8_t zig_popcount_i##w(int##w##_t val, uint8_t bits) { \
return zig_popcount_u##w((uint##w##_t)val, bits); \
}
#if zig_has_builtin(popcount) || defined(zig_gnuc)
#if zig_has_builtin(popcount) || defined(zig_gnuc) || defined(zig_tinyc)
#define zig_builtin_popcount(w) \
static inline uint8_t zig_popcount_u##w(uint##w##_t val, uint8_t bits) { \
(void)bits; \
@ -1161,7 +1296,7 @@ zig_builtin_popcount(64)
static inline uint8_t zig_ctz_i##w(int##w##_t val, uint8_t bits) { \
return zig_ctz_u##w((uint##w##_t)val, bits); \
}
#if zig_has_builtin(ctz) || defined(zig_gnuc)
#if zig_has_builtin(ctz) || defined(zig_gnuc) || defined(zig_tinyc)
#define zig_builtin_ctz(w) \
static inline uint8_t zig_ctz_u##w(uint##w##_t val, uint8_t bits) { \
if (val == 0) return bits; \
@ -1186,7 +1321,7 @@ zig_builtin_ctz(64)
static inline uint8_t zig_clz_i##w(int##w##_t val, uint8_t bits) { \
return zig_clz_u##w((uint##w##_t)val, bits); \
}
#if zig_has_builtin(clz) || defined(zig_gnuc)
#if zig_has_builtin(clz) || defined(zig_gnuc) || defined(zig_tinyc)
#define zig_builtin_clz(w) \
static inline uint8_t zig_clz_u##w(uint##w##_t val, uint8_t bits) { \
if (val == 0) return bits; \
@ -1254,7 +1389,7 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128;
#define zig_make_u128(hi, lo) ((zig_u128){ .h##i = (hi), .l##o = (lo) })
#define zig_make_i128(hi, lo) ((zig_i128){ .h##i = (hi), .l##o = (lo) })
#if _MSC_VER /* MSVC doesn't allow struct literals in constant expressions */
#if defined(zig_msvc) /* MSVC doesn't allow struct literals in constant expressions */
#define zig_init_u128(hi, lo) { .h##i = (hi), .l##o = (lo) }
#define zig_init_i128(hi, lo) { .h##i = (hi), .l##o = (lo) }
#else /* But non-MSVC doesn't like the unprotected commas */
@ -3016,7 +3151,13 @@ static inline uint16_t zig_popcount_big(const void *val, bool is_signed, uint16_
/* ========================= Floating Point Support ========================= */
#if _MSC_VER
#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
#define __STDC_WANT_IEC_60559_TYPES_EXT__
#endif
#include <float.h>
#if defined(zig_msvc)
float __cdecl nanf(char const* input);
double __cdecl nan(char const* input);
long double __cdecl nanl(char const* input);
@ -3078,7 +3219,7 @@ typedef uint16_t zig_f16;
#undef zig_init_special_f16
#define zig_init_special_f16(sign, name, arg, repr) repr
#endif
#if __APPLE__ && (defined(__i386__) || defined(__x86_64__))
#if defined(zig_darwin) && defined(zig_x86)
typedef uint16_t zig_compiler_rt_f16;
#else
typedef zig_f16 zig_compiler_rt_f16;
@ -3086,7 +3227,7 @@ typedef zig_f16 zig_compiler_rt_f16;
#define zig_has_f32 1
#define zig_libc_name_f32(name) name##f
#if _MSC_VER
#if defined(zig_msvc)
#define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, )
#else
#define zig_init_special_f32(sign, name, arg, repr) zig_make_special_f32(sign, name, arg, repr)
@ -3118,7 +3259,7 @@ typedef uint32_t zig_f32;
#define zig_has_f64 1
#define zig_libc_name_f64(name) name
#if _MSC_VER
#if defined(zig_msvc)
#define zig_init_special_f64(sign, name, arg, repr) sign zig_make_f64(zig_msvc_flt_##name, )
#else
#define zig_init_special_f64(sign, name, arg, repr) zig_make_special_f64(sign, name, arg, repr)
@ -3183,6 +3324,12 @@ typedef zig_u128 zig_f80;
#define zig_init_special_f80(sign, name, arg, repr) repr
#endif
#if !defined(zig_clang) && defined(zig_gnuc) && defined(zig_x86)
#define zig_f128_has_miscompilations 1
#else
#define zig_f128_has_miscompilations 0
#endif
#define zig_has_f128 1
#define zig_libc_name_f128(name) name##q
#define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr)
@ -3211,7 +3358,7 @@ typedef __float128 zig_f128;
#define zig_has_f128 0
#undef zig_make_special_f128
#undef zig_init_special_f128
#if __APPLE__ || defined(__aarch64__)
#if defined(zig_darwin) || defined(zig_aarch64)
typedef __attribute__((__vector_size__(2 * sizeof(uint64_t)))) uint64_t zig_v2u64;
zig_basic_operator(zig_v2u64, xor_v2u64, ^)
#define zig_repr_f128 v2u64
@ -3230,10 +3377,10 @@ typedef zig_u128 zig_f128;
#endif
#endif
#if !_MSC_VER && defined(ZIG_TARGET_ABI_MSVC)
#if !defined(zig_msvc) && defined(ZIG_TARGET_ABI_MSVC)
/* Emulate msvc abi on a gnu compiler */
typedef zig_f64 zig_c_longdouble;
#elif _MSC_VER && !defined(ZIG_TARGET_ABI_MSVC)
#elif defined(zig_msvc) && !defined(ZIG_TARGET_ABI_MSVC)
/* Emulate gnu abi on an msvc compiler */
typedef zig_f128 zig_c_longdouble;
#else
@ -3582,7 +3729,7 @@ zig_float_builtins(64)
res = zig_atomicrmw_expected; \
} while (0)
#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
#if (__STDC_VERSION__ >= 201112L || (zig_has_include(<stdatomic.h>) && !defined(zig_msvc))) && !defined(__STDC_NO_ATOMICS__)
#include <stdatomic.h>
typedef enum memory_order zig_memory_order;
#define zig_memory_order_relaxed memory_order_relaxed
@ -3610,7 +3757,7 @@ typedef enum memory_order zig_memory_order;
#define zig_atomicrmw_add_float zig_atomicrmw_add
#undef zig_atomicrmw_sub_float
#define zig_atomicrmw_sub_float zig_atomicrmw_sub
#elif defined(__GNUC__)
#elif defined(zig_gnuc)
typedef int zig_memory_order;
#define zig_memory_order_relaxed __ATOMIC_RELAXED
#define zig_memory_order_acquire __ATOMIC_ACQUIRE
@ -3633,7 +3780,7 @@ typedef int zig_memory_order;
#define zig_atomic_load(res, obj, order, Type, ReprType) __atomic_load (obj, &(res), order)
#undef zig_atomicrmw_xchg_float
#define zig_atomicrmw_xchg_float zig_atomicrmw_xchg
#elif _MSC_VER && (_M_IX86 || _M_X64)
#elif defined(zig_msvc) && defined(zig_x86)
#define zig_memory_order_relaxed 0
#define zig_memory_order_acquire 2
#define zig_memory_order_release 3
@ -3653,7 +3800,7 @@ typedef int zig_memory_order;
#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg)
#define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg)
#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##order##_##Type(obj)
/* TODO: _MSC_VER && (_M_ARM || _M_ARM64) */
/* TODO: zig_msvc && (zig_thumb || zig_aarch64) */
#else
#define zig_memory_order_relaxed 0
#define zig_memory_order_acquire 2
@ -3676,7 +3823,7 @@ typedef int zig_memory_order;
#define zig_atomic_load(res, obj, order, Type, ReprType) zig_atomics_unavailable
#endif
#if _MSC_VER && (_M_IX86 || _M_X64)
#if defined(zig_msvc) && defined(zig_x86)
/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */
@ -3773,7 +3920,7 @@ zig_msvc_atomics(i16, int16_t, short, 16, 16)
zig_msvc_atomics(u32, uint32_t, long, , 32)
zig_msvc_atomics(i32, int32_t, long, , 32)
#if _M_X64
#if defined(zig_x86_64)
zig_msvc_atomics(u64, uint64_t, __int64, 64, 64)
zig_msvc_atomics(i64, int64_t, __int64, 64, 64)
#endif
@ -3818,11 +3965,11 @@ zig_msvc_atomics(i64, int64_t, __int64, 64, 64)
}
zig_msvc_flt_atomics(f32, long, , 32)
#if _M_X64
#if defined(zig_x86_64)
zig_msvc_flt_atomics(f64, int64_t, 64, 64)
#endif
#if _M_IX86
#if defined(zig_x86_32)
static inline void zig_msvc_atomic_barrier() {
int32_t barrier;
__asm {
@ -3859,7 +4006,7 @@ static inline bool zig_msvc_cmpxchg_p32(void volatile* obj, void* expected, void
if (!success) *(void**)expected = initial;
return success;
}
#else /* _M_IX86 */
#else /* zig_x86_32 */
static inline void* zig_msvc_atomicrmw_xchg_p64(void volatile* obj, void* arg) {
return _InterlockedExchangePointer(obj, arg);
}
@ -3920,55 +4067,59 @@ static inline void zig_msvc_atomic_store_i128(zig_i128 volatile* obj, zig_i128 a
while (!zig_cmpxchg_weak(obj, expected, arg, zig_memory_order_seq_cst, zig_memory_order_seq_cst, i128, zig_i128));
}
#endif /* _M_IX86 */
#endif /* zig_x86_32 */
#endif /* _MSC_VER && (_M_IX86 || _M_X64) */
#endif /* zig_msvc && zig_x86 */
/* ======================== Special Case Intrinsics ========================= */
#if defined(_M_ARM) || defined(__thumb__)
#if defined(zig_msvc)
#include <intrin.h>
#endif
#if defined(zig_thumb)
static inline void* zig_thumb_windows_teb(void) {
void* teb = 0;
#if defined(_MSC_VER)
#if defined(zig_msvc)
teb = (void*)_MoveFromCoprocessor(15, 0, 13, 0, 2);
#elif defined(__GNUC__)
#elif defined(zig_gnuc_asm)
__asm__ ("mrc p15, 0, %[ptr], c13, c0, 2" : [ptr] "=r" (teb));
#endif
return teb;
}
#elif defined(_M_ARM64) || defined(__arch64__)
#elif defined(zig_aarch64)
static inline void* zig_aarch64_windows_teb(void) {
void* teb = 0;
#if defined(_MSC_VER)
#if defined(zig_msvc)
teb = (void*)__readx18qword(0x0);
#elif defined(__GNUC__)
#elif defined(zig_gnuc_asm)
__asm__ ("mov %[ptr], x18" : [ptr] "=r" (teb));
#endif
return teb;
}
#elif defined(_M_IX86) || defined(__i386__)
#elif defined(zig_x86_32)
static inline void* zig_x86_windows_teb(void) {
void* teb = 0;
#if defined(_MSC_VER)
#if defined(zig_msvc)
teb = (void*)__readfsdword(0x18);
#elif defined(__GNUC__)
#elif defined(zig_gnuc_asm)
__asm__ ("movl %%fs:0x18, %[ptr]" : [ptr] "=r" (teb));
#endif
return teb;
}
#elif defined(_M_X64) || defined(__x86_64__)
#elif defined(zig_x86_64)
static inline void* zig_x86_64_windows_teb(void) {
void* teb = 0;
#if defined(_MSC_VER)
#if defined(zig_msvc)
teb = (void*)__readgsqword(0x30);
#elif defined(__GNUC__)
#elif defined(zig_gnuc_asm)
__asm__ ("movq %%gs:0x30, %[ptr]" : [ptr] "=r" (teb));
#endif
return teb;
@ -3976,29 +4127,39 @@ static inline void* zig_x86_64_windows_teb(void) {
#endif
#if (_MSC_VER && (_M_IX86 || _M_X64)) || defined(__i386__) || defined(__x86_64__)
#if defined(zig_x86)
static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) {
#if _MSC_VER
#if defined(zig_msvc)
int cpu_info[4];
__cpuidex(cpu_info, leaf_id, subid);
*eax = (uint32_t)cpu_info[0];
*ebx = (uint32_t)cpu_info[1];
*ecx = (uint32_t)cpu_info[2];
*edx = (uint32_t)cpu_info[3];
#elif defined(zig_gnuc_asm)
__asm__("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf_id), "c"(subid));
#else
__cpuid_count(leaf_id, subid, *eax, *ebx, *ecx, *edx);
*eax = 0;
*ebx = 0;
*ecx = 0;
*edx = 0;
#endif
}
static inline uint32_t zig_x86_get_xcr0(void) {
#if _MSC_VER
#if defined(zig_msvc)
return (uint32_t)_xgetbv(0);
#else
#elif defined(zig_gnuc_asm)
uint32_t eax;
uint32_t edx;
__asm__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0));
return eax;
#else
*eax = 0;
*ebx = 0;
*ecx = 0;
*edx = 0;
#endif
}

Binary file not shown.

View file

@ -410,11 +410,11 @@ test "alignment of function with c calling convention" {
var runtime_nothing = &nothing;
_ = &runtime_nothing;
const casted1: *align(a) const u8 = @ptrCast(runtime_nothing);
const casted2: *const fn () callconv(.C) void = @ptrCast(casted1);
const casted2: *const fn () callconv(.c) void = @ptrCast(casted1);
casted2();
}
fn nothing() callconv(.C) void {}
fn nothing() callconv(.c) void {}
const DefaultAligned = struct {
nevermind: u32,

View file

@ -1118,7 +1118,7 @@ test "compile time int to ptr of function" {
// On some architectures function pointers must be aligned.
const hardcoded_fn_addr = maxInt(usize) & ~@as(usize, 0xf);
pub const FUNCTION_CONSTANT = @as(PFN_void, @ptrFromInt(hardcoded_fn_addr));
pub const PFN_void = *const fn (*anyopaque) callconv(.C) void;
pub const PFN_void = *const fn (*anyopaque) callconv(.c) void;
fn foobar(func: PFN_void) !void {
try std.testing.expect(@intFromPtr(func) == hardcoded_fn_addr);
@ -1281,11 +1281,11 @@ test "implicit cast *[0]T to E![]const u8" {
var global_array: [4]u8 = undefined;
test "cast from array reference to fn: comptime fn ptr" {
const f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array));
const f = @as(*align(1) const fn () callconv(.c) void, @ptrCast(&global_array));
try expect(@intFromPtr(f) == @intFromPtr(&global_array));
}
test "cast from array reference to fn: runtime fn ptr" {
var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array));
var f = @as(*align(1) const fn () callconv(.c) void, @ptrCast(&global_array));
_ = &f;
try expect(@intFromPtr(f) == @intFromPtr(&global_array));
}
@ -1309,12 +1309,12 @@ test "*const [N]null u8 to ?[]const u8" {
test "cast between [*c]T and ?[*:0]T on fn parameter" {
const S = struct {
const Handler = ?fn ([*c]const u8) callconv(.C) void;
const Handler = ?fn ([*c]const u8) callconv(.c) void;
fn addCallback(comptime handler: Handler) void {
_ = handler;
}
fn myCallback(cstr: ?[*:0]const u8) callconv(.C) void {
fn myCallback(cstr: ?[*:0]const u8) callconv(.c) void {
_ = cstr;
}

View file

@ -26,7 +26,7 @@ test "exporting with internal linkage" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
const S = struct {
fn foo() callconv(.C) void {}
fn foo() callconv(.c) void {}
comptime {
@export(&foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .internal });
}

View file

@ -44,7 +44,7 @@ test "export function alias" {
if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
_ = struct {
fn foo_internal() callconv(.C) u32 {
fn foo_internal() callconv(.c) u32 {
return 123;
}
export const foo_exported = foo_internal;

View file

@ -20,7 +20,7 @@ test "function extern symbol" {
if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
const a = @extern(*const fn () callconv(.C) i32, .{ .name = "a_mystery_function" });
const a = @extern(*const fn () callconv(.c) i32, .{ .name = "a_mystery_function" });
try expect(a() == 4567);
}
@ -35,7 +35,7 @@ test "function extern symbol matches extern decl" {
const S = struct {
extern fn another_mystery_function() u32;
const same_thing = @extern(*const fn () callconv(.C) u32, .{ .name = "another_mystery_function" });
const same_thing = @extern(*const fn () callconv(.c) u32, .{ .name = "another_mystery_function" });
};
try expect(S.another_mystery_function() == 12345);
try expect(S.same_thing() == 12345);
@ -55,5 +55,5 @@ test "coerce extern function types" {
};
_ = S;
_ = @as(fn () callconv(.C) ?*u32, c_extern_function);
_ = @as(fn () callconv(.c) ?*u32, c_extern_function);
}

View file

@ -153,9 +153,9 @@ test "extern struct with stdcallcc fn pointer" {
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
const S = extern struct {
ptr: *const fn () callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .C) i32,
ptr: *const fn () callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .c) i32,
fn foo() callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .C) i32 {
fn foo() callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .c) i32 {
return 1234;
}
};
@ -169,7 +169,7 @@ const nComplexCallconv = 100;
fn fComplexCallconvRet(x: u32) callconv(blk: {
const s: struct { n: u32 } = .{ .n = nComplexCallconv };
break :blk switch (s.n) {
0 => .C,
0 => .c,
1 => .Inline,
else => .Unspecified,
};
@ -435,13 +435,13 @@ test "implicit cast function to function ptr" {
return 123;
}
};
var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue;
var fnPtr1: *const fn () callconv(.c) c_int = S1.someFunctionThatReturnsAValue;
_ = &fnPtr1;
try expect(fnPtr1() == 123);
const S2 = struct {
extern fn someFunctionThatReturnsAValue() c_int;
};
var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue;
var fnPtr2: *const fn () callconv(.c) c_int = S2.someFunctionThatReturnsAValue;
_ = &fnPtr2;
try expect(fnPtr2() == 123);
}

View file

@ -324,7 +324,7 @@ test "generic function instantiation non-duplicates" {
for (source, 0..) |s, i| dest[i] = s;
}
fn foo() callconv(.C) void {}
fn foo() callconv(.c) void {}
};
var buffer: [100]u8 = undefined;
S.copy(u8, &buffer, "hello");
@ -471,13 +471,13 @@ test "coerced function body has inequal value with its uncoerced body" {
try expect(S.A.do() == 1234);
}
test "generic function returns value from callconv(.C) function" {
test "generic function returns value from callconv(.c) function" {
const S = struct {
fn getU8() callconv(.C) u8 {
fn getU8() callconv(.c) u8 {
return 123;
}
fn getGeneric(comptime T: type, supplier: fn () callconv(.C) T) T {
fn getGeneric(comptime T: type, supplier: fn () callconv(.c) T) T {
return supplier();
}
};
@ -521,11 +521,11 @@ test "function argument tuple used as struct field" {
try expect(c.t[0] == null);
}
test "comptime callconv(.C) function ptr uses comptime type argument" {
test "comptime callconv(.c) function ptr uses comptime type argument" {
const S = struct {
fn A(
comptime T: type,
comptime destroycb: ?*const fn (?*T) callconv(.C) void,
comptime destroycb: ?*const fn (?*T) callconv(.c) void,
) !void {
try expect(destroycb == null);
}

View file

@ -80,7 +80,7 @@ test "import c keywords" {
try std.testing.expect(ptr_id == &some_non_c_keyword_constant);
if (builtin.target.ofmt != .coff and builtin.target.os.tag != .windows) {
var ptr_fn: *const fn () callconv(.C) Id = &double;
var ptr_fn: *const fn () callconv(.c) Id = &double;
try std.testing.expect(ptr_fn == &float);
ptr_fn = &an_alias_of_float;
try std.testing.expect(ptr_fn == &float);

View file

@ -891,7 +891,7 @@ test "runtime init of unnamed packed struct type" {
}{ .x = z }).m();
}
test "packed struct passed to callconv(.C) function" {
test "packed struct passed to callconv(.c) function" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
@ -906,7 +906,7 @@ test "packed struct passed to callconv(.C) function" {
d: u46 = 0,
};
fn foo(p: Packed, a1: u64, a2: u64, a3: u64, a4: u64, a5: u64) callconv(.C) bool {
fn foo(p: Packed, a1: u64, a2: u64, a3: u64, a4: u64, a5: u64) callconv(.c) bool {
return p.a == 12345 and p.b == true and p.c == true and p.d == 0 and a1 == 5 and a2 == 4 and a3 == 3 and a4 == 2 and a5 == 1;
}
};
@ -1270,7 +1270,7 @@ test "2-byte packed struct argument in C calling convention" {
x: u15 = 0,
y: u1 = 0,
fn foo(s: @This()) callconv(.C) i32 {
fn foo(s: @This()) callconv(.c) i32 {
return s.x;
}
fn bar(s: @This()) !void {

View file

@ -803,7 +803,7 @@ test "fn with C calling convention returns struct by value" {
handle: i32,
};
fn makeBar(t: i32) callconv(.C) ExternBar {
fn makeBar(t: i32) callconv(.c) ExternBar {
return ExternBar{
.handle = t,
};

View file

@ -141,14 +141,14 @@ test "array-like initializer for tuple types" {
.{
.name = "0",
.type = i32,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(i32),
},
.{
.name = "1",
.type = u8,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(u8),
},
@ -330,7 +330,7 @@ test "zero sized struct in tuple handled correctly" {
.fields = &.{.{
.name = "0",
.type = struct {},
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
}},

View file

@ -20,13 +20,13 @@ test "tuple declaration type info" {
try expectEqualStrings(info.fields[0].name, "0");
try expect(info.fields[0].type == u32);
try expect(@as(*const u32, @ptrCast(@alignCast(info.fields[0].default_value))).* == 1);
try expect(info.fields[0].defaultValue() == 1);
try expect(info.fields[0].is_comptime);
try expect(info.fields[0].alignment == @alignOf(u32));
try expectEqualStrings(info.fields[1].name, "1");
try expect(info.fields[1].type == []const u8);
try expect(info.fields[1].default_value == null);
try expect(info.fields[1].defaultValue() == null);
try expect(!info.fields[1].is_comptime);
try expect(info.fields[1].alignment == @alignOf([]const u8));
}

View file

@ -118,21 +118,21 @@ test "Type.Array" {
.array = .{
.len = 123,
.child = u8,
.sentinel = null,
.sentinel_ptr = null,
},
}));
try testing.expect([2]u32 == @Type(.{
.array = .{
.len = 2,
.child = u32,
.sentinel = null,
.sentinel_ptr = null,
},
}));
try testing.expect([2:0]u32 == @Type(.{
.array = .{
.len = 2,
.child = u32,
.sentinel = &@as(u32, 0),
.sentinel_ptr = &@as(u32, 0),
},
}));
try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
@ -141,14 +141,14 @@ test "Type.Array" {
test "@Type create slice with null sentinel" {
const Slice = @Type(.{
.pointer = .{
.size = .Slice,
.size = .slice,
.is_const = true,
.is_volatile = false,
.is_allowzero = false,
.alignment = 8,
.address_space = .generic,
.child = *i32,
.sentinel = null,
.sentinel_ptr = null,
},
});
try testing.expect(Slice == []align(8) const *i32);
@ -266,10 +266,10 @@ test "Type.Struct" {
try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout);
try testing.expectEqualSlices(u8, "x", infoA.fields[0].name);
try testing.expectEqual(u8, infoA.fields[0].type);
try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value);
try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value_ptr);
try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
try testing.expectEqual(u32, infoA.fields[1].type);
try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value);
try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value_ptr);
try testing.expectEqualSlices(Type.Declaration, &.{}, infoA.decls);
try testing.expectEqual(@as(bool, false), infoA.is_tuple);
@ -284,10 +284,10 @@ test "Type.Struct" {
try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout);
try testing.expectEqualSlices(u8, "x", infoB.fields[0].name);
try testing.expectEqual(u8, infoB.fields[0].type);
try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value);
try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value_ptr);
try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
try testing.expectEqual(u32, infoB.fields[1].type);
try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoB.fields[1].default_value.?)).*);
try testing.expectEqual(@as(u32, 5), infoB.fields[1].defaultValue().?);
try testing.expectEqual(@as(usize, 0), infoB.decls.len);
try testing.expectEqual(@as(bool, false), infoB.is_tuple);
@ -296,10 +296,10 @@ test "Type.Struct" {
try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout);
try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
try testing.expectEqual(u8, infoC.fields[0].type);
try testing.expectEqual(@as(u8, 3), @as(*const u8, @ptrCast(infoC.fields[0].default_value.?)).*);
try testing.expectEqual(@as(u8, 3), infoC.fields[0].defaultValue().?);
try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
try testing.expectEqual(u32, infoC.fields[1].type);
try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoC.fields[1].default_value.?)).*);
try testing.expectEqual(@as(u32, 5), infoC.fields[1].defaultValue().?);
try testing.expectEqual(@as(usize, 0), infoC.decls.len);
try testing.expectEqual(@as(bool, false), infoC.is_tuple);
@ -309,10 +309,10 @@ test "Type.Struct" {
try testing.expectEqual(Type.ContainerLayout.auto, infoD.layout);
try testing.expectEqualSlices(u8, "x", infoD.fields[0].name);
try testing.expectEqual(comptime_int, infoD.fields[0].type);
try testing.expectEqual(@as(comptime_int, 3), @as(*const comptime_int, @ptrCast(infoD.fields[0].default_value.?)).*);
try testing.expectEqual(@as(comptime_int, 3), infoD.fields[0].defaultValue().?);
try testing.expectEqualSlices(u8, "y", infoD.fields[1].name);
try testing.expectEqual(comptime_int, infoD.fields[1].type);
try testing.expectEqual(@as(comptime_int, 5), @as(*const comptime_int, @ptrCast(infoD.fields[1].default_value.?)).*);
try testing.expectEqual(@as(comptime_int, 5), infoD.fields[1].defaultValue().?);
try testing.expectEqual(@as(usize, 0), infoD.decls.len);
try testing.expectEqual(@as(bool, false), infoD.is_tuple);
@ -322,10 +322,10 @@ test "Type.Struct" {
try testing.expectEqual(Type.ContainerLayout.auto, infoE.layout);
try testing.expectEqualSlices(u8, "0", infoE.fields[0].name);
try testing.expectEqual(comptime_int, infoE.fields[0].type);
try testing.expectEqual(@as(comptime_int, 1), @as(*const comptime_int, @ptrCast(infoE.fields[0].default_value.?)).*);
try testing.expectEqual(@as(comptime_int, 1), infoE.fields[0].defaultValue().?);
try testing.expectEqualSlices(u8, "1", infoE.fields[1].name);
try testing.expectEqual(comptime_int, infoE.fields[1].type);
try testing.expectEqual(@as(comptime_int, 2), @as(*const comptime_int, @ptrCast(infoE.fields[1].default_value.?)).*);
try testing.expectEqual(@as(comptime_int, 2), infoE.fields[1].defaultValue().?);
try testing.expectEqual(@as(usize, 0), infoE.decls.len);
try testing.expectEqual(@as(bool, true), infoE.is_tuple);
@ -548,11 +548,11 @@ test "Type.Fn" {
const some_opaque = opaque {};
const some_ptr = *some_opaque;
const T = fn (c_int, some_ptr) callconv(.C) void;
const T = fn (c_int, some_ptr) callconv(.c) void;
{
const fn_info = std.builtin.Type{ .@"fn" = .{
.calling_convention = .C,
.calling_convention = .c,
.is_generic = false,
.is_var_args = false,
.return_type = void,
@ -582,7 +582,7 @@ test "reified struct field name from optional payload" {
.fields = &.{.{
.name = name,
.type = u8,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 1,
}},
@ -628,7 +628,7 @@ test "reified struct uses @alignOf" {
.{
.name = "globals",
.type = modules.mach.globals,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(modules.mach.globals),
},
@ -688,7 +688,7 @@ test "empty struct assigned to reified struct field" {
.fields = &.{.{
.name = "components",
.type = @TypeOf(modules.components),
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(@TypeOf(modules.components)),
}},
@ -738,7 +738,7 @@ test "struct field names sliced at comptime from larger string" {
.alignment = 0,
.name = name ++ "",
.type = usize,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
}};
}

View file

@ -44,7 +44,7 @@ test "type info: C pointer type info" {
fn testCPtr() !void {
const ptr_info = @typeInfo([*c]align(4) const i8);
try expect(ptr_info == .pointer);
try expect(ptr_info.pointer.size == .C);
try expect(ptr_info.pointer.size == .c);
try expect(ptr_info.pointer.is_const);
try expect(!ptr_info.pointer.is_volatile);
try expect(ptr_info.pointer.alignment == 4);
@ -54,8 +54,8 @@ fn testCPtr() !void {
test "type info: value is correctly copied" {
comptime {
var ptrInfo = @typeInfo([]u32);
ptrInfo.pointer.size = .One;
try expect(@typeInfo([]u32).pointer.size == .Slice);
ptrInfo.pointer.size = .one;
try expect(@typeInfo([]u32).pointer.size == .slice);
}
}
@ -79,12 +79,12 @@ test "type info: pointer type info" {
fn testPointer() !void {
const u32_ptr_info = @typeInfo(*u32);
try expect(u32_ptr_info == .pointer);
try expect(u32_ptr_info.pointer.size == .One);
try expect(u32_ptr_info.pointer.size == .one);
try expect(u32_ptr_info.pointer.is_const == false);
try expect(u32_ptr_info.pointer.is_volatile == false);
try expect(u32_ptr_info.pointer.alignment == @alignOf(u32));
try expect(u32_ptr_info.pointer.child == u32);
try expect(u32_ptr_info.pointer.sentinel == null);
try expect(u32_ptr_info.pointer.sentinel() == null);
}
test "type info: unknown length pointer type info" {
@ -95,10 +95,10 @@ test "type info: unknown length pointer type info" {
fn testUnknownLenPtr() !void {
const u32_ptr_info = @typeInfo([*]const volatile f64);
try expect(u32_ptr_info == .pointer);
try expect(u32_ptr_info.pointer.size == .Many);
try expect(u32_ptr_info.pointer.size == .many);
try expect(u32_ptr_info.pointer.is_const == true);
try expect(u32_ptr_info.pointer.is_volatile == true);
try expect(u32_ptr_info.pointer.sentinel == null);
try expect(u32_ptr_info.pointer.sentinel() == null);
try expect(u32_ptr_info.pointer.alignment == @alignOf(f64));
try expect(u32_ptr_info.pointer.child == f64);
}
@ -111,12 +111,12 @@ test "type info: null terminated pointer type info" {
fn testNullTerminatedPtr() !void {
const ptr_info = @typeInfo([*:0]u8);
try expect(ptr_info == .pointer);
try expect(ptr_info.pointer.size == .Many);
try expect(ptr_info.pointer.size == .many);
try expect(ptr_info.pointer.is_const == false);
try expect(ptr_info.pointer.is_volatile == false);
try expect(@as(*const u8, @ptrCast(ptr_info.pointer.sentinel.?)).* == 0);
try expect(ptr_info.pointer.sentinel().? == 0);
try expect(@typeInfo([:0]u8).pointer.sentinel != null);
try expect(@typeInfo([:0]u8).pointer.sentinel() != null);
}
test "type info: slice type info" {
@ -127,7 +127,7 @@ test "type info: slice type info" {
fn testSlice() !void {
const u32_slice_info = @typeInfo([]u32);
try expect(u32_slice_info == .pointer);
try expect(u32_slice_info.pointer.size == .Slice);
try expect(u32_slice_info.pointer.size == .slice);
try expect(u32_slice_info.pointer.is_const == false);
try expect(u32_slice_info.pointer.is_volatile == false);
try expect(u32_slice_info.pointer.alignment == 4);
@ -145,14 +145,14 @@ fn testArray() !void {
try expect(info == .array);
try expect(info.array.len == 42);
try expect(info.array.child == u8);
try expect(info.array.sentinel == null);
try expect(info.array.sentinel() == null);
}
{
const info = @typeInfo([10:0]u8);
try expect(info.array.len == 10);
try expect(info.array.child == u8);
try expect(@as(*const u8, @ptrCast(info.array.sentinel.?)).* == @as(u8, 0));
try expect(info.array.sentinel().? == @as(u8, 0));
try expect(@sizeOf([10:0]u8) == info.array.len + 1);
}
}
@ -292,8 +292,8 @@ fn testStruct() !void {
try expect(unpacked_struct_info.@"struct".is_tuple == false);
try expect(unpacked_struct_info.@"struct".backing_integer == null);
try expect(unpacked_struct_info.@"struct".fields[0].alignment == @alignOf(u32));
try expect(@as(*align(1) const u32, @ptrCast(unpacked_struct_info.@"struct".fields[0].default_value.?)).* == 4);
try expect(mem.eql(u8, "foobar", @as(*align(1) const *const [6:0]u8, @ptrCast(unpacked_struct_info.@"struct".fields[1].default_value.?)).*));
try expect(unpacked_struct_info.@"struct".fields[0].defaultValue().? == 4);
try expect(mem.eql(u8, "foobar", unpacked_struct_info.@"struct".fields[1].defaultValue().?));
}
const TestStruct = struct {
@ -315,8 +315,8 @@ fn testPackedStruct() !void {
try expect(struct_info.@"struct".fields.len == 4);
try expect(struct_info.@"struct".fields[0].alignment == 0);
try expect(struct_info.@"struct".fields[2].type == f32);
try expect(struct_info.@"struct".fields[2].default_value == null);
try expect(@as(*align(1) const u32, @ptrCast(struct_info.@"struct".fields[3].default_value.?)).* == 4);
try expect(struct_info.@"struct".fields[2].defaultValue() == null);
try expect(struct_info.@"struct".fields[3].defaultValue().? == 4);
try expect(struct_info.@"struct".fields[3].alignment == 0);
try expect(struct_info.@"struct".decls.len == 1);
}
@ -374,13 +374,13 @@ fn testFunction() !void {
try expect(foo_fn_info.@"fn".is_var_args);
try expect(foo_fn_info.@"fn".return_type.? == usize);
const foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFoo));
try expect(foo_ptr_fn_info.pointer.size == .One);
try expect(foo_ptr_fn_info.pointer.size == .one);
try expect(foo_ptr_fn_info.pointer.is_const);
try expect(!foo_ptr_fn_info.pointer.is_volatile);
try expect(foo_ptr_fn_info.pointer.address_space == .generic);
try expect(foo_ptr_fn_info.pointer.child == foo_fn_type);
try expect(!foo_ptr_fn_info.pointer.is_allowzero);
try expect(foo_ptr_fn_info.pointer.sentinel == null);
try expect(foo_ptr_fn_info.pointer.sentinel() == null);
// Avoid looking at `typeInfoFooAligned` on targets which don't support function alignment.
switch (builtin.target.cpu.arch) {
@ -401,14 +401,14 @@ fn testFunction() !void {
try expect(aligned_foo_fn_info.@"fn".is_var_args);
try expect(aligned_foo_fn_info.@"fn".return_type.? == usize);
const aligned_foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFooAligned));
try expect(aligned_foo_ptr_fn_info.pointer.size == .One);
try expect(aligned_foo_ptr_fn_info.pointer.size == .one);
try expect(aligned_foo_ptr_fn_info.pointer.is_const);
try expect(!aligned_foo_ptr_fn_info.pointer.is_volatile);
try expect(aligned_foo_ptr_fn_info.pointer.alignment == 4);
try expect(aligned_foo_ptr_fn_info.pointer.address_space == .generic);
try expect(aligned_foo_ptr_fn_info.pointer.child == aligned_foo_fn_type);
try expect(!aligned_foo_ptr_fn_info.pointer.is_allowzero);
try expect(aligned_foo_ptr_fn_info.pointer.sentinel == null);
try expect(aligned_foo_ptr_fn_info.pointer.sentinel() == null);
}
extern fn typeInfoFoo(a: usize, b: bool, ...) callconv(.c) usize;
@ -517,7 +517,7 @@ test "type info: TypeId -> Type impl cast" {
test "sentinel of opaque pointer type" {
const c_void_info = @typeInfo(*anyopaque);
try expect(c_void_info.pointer.sentinel == null);
try expect(c_void_info.pointer.sentinel_ptr == null);
}
test "@typeInfo does not force declarations into existence" {
@ -601,9 +601,9 @@ test "typeInfo resolves usingnamespace declarations" {
try expectEqualStrings(decls[1].name, "f1");
}
test "value from struct @typeInfo default_value can be loaded at comptime" {
test "value from struct @typeInfo default_value_ptr can be loaded at comptime" {
comptime {
const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".fields[0].default_value;
const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".fields[0].default_value_ptr;
try expect(@as(*const u8, @ptrCast(a)).* == 1);
}
}
@ -646,7 +646,7 @@ test "@typeInfo decls ignore dependency loops" {
test "type info of tuple of string literal default value" {
const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0];
const value = @as(*align(1) const *const [2:0]u8, @ptrCast(struct_field.default_value.?)).*;
const value = struct_field.defaultValue().?;
comptime std.debug.assert(value[0] == 'h');
}

View file

@ -1229,7 +1229,7 @@ test "return an extern union from C calling convention" {
s: S,
};
fn bar(arg_u: U) callconv(.C) U {
fn bar(arg_u: U) callconv(.c) U {
var u = arg_u;
_ = &u;
return u;

View file

@ -108,19 +108,19 @@ test "simple variadic function" {
if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350
const S = struct {
fn simple(...) callconv(.C) c_int {
fn simple(...) callconv(.c) c_int {
var ap = @cVaStart();
defer @cVaEnd(&ap);
return @cVaArg(&ap, c_int);
}
fn compatible(_: c_int, ...) callconv(.C) c_int {
fn compatible(_: c_int, ...) callconv(.c) c_int {
var ap = @cVaStart();
defer @cVaEnd(&ap);
return @cVaArg(&ap, c_int);
}
fn add(count: c_int, ...) callconv(.C) c_int {
fn add(count: c_int, ...) callconv(.c) c_int {
var ap = @cVaStart();
defer @cVaEnd(&ap);
var i: usize = 0;
@ -169,7 +169,7 @@ test "coerce reference to var arg" {
if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350
const S = struct {
fn addPtr(count: c_int, ...) callconv(.C) c_int {
fn addPtr(count: c_int, ...) callconv(.c) c_int {
var ap = @cVaStart();
defer @cVaEnd(&ap);
var i: usize = 0;
@ -202,7 +202,7 @@ test "variadic functions" {
if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350
const S = struct {
fn printf(list_ptr: *std.ArrayList(u8), format: [*:0]const u8, ...) callconv(.C) void {
fn printf(list_ptr: *std.ArrayList(u8), format: [*:0]const u8, ...) callconv(.c) void {
var ap = @cVaStart();
defer @cVaEnd(&ap);
vprintf(list_ptr, format, &ap);
@ -212,7 +212,7 @@ test "variadic functions" {
list: *std.ArrayList(u8),
format: [*:0]const u8,
ap: *std.builtin.VaList,
) callconv(.C) void {
) callconv(.c) void {
for (std.mem.span(format)) |c| switch (c) {
's' => {
const arg = @cVaArg(ap, [*:0]const u8);
@ -247,7 +247,7 @@ test "copy VaList" {
if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350
const S = struct {
fn add(count: c_int, ...) callconv(.C) c_int {
fn add(count: c_int, ...) callconv(.c) c_int {
var ap = @cVaStart();
defer @cVaEnd(&ap);
var copy = @cVaCopy(&ap);
@ -284,7 +284,7 @@ test "unused VaList arg" {
if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350
const S = struct {
fn thirdArg(dummy: c_int, ...) callconv(.C) c_int {
fn thirdArg(dummy: c_int, ...) callconv(.c) c_int {
_ = dummy;
var ap = @cVaStart();

View file

@ -21,7 +21,7 @@ pub fn isPtrTo(comptime id: std.builtin.TypeId) TraitFn {
pub fn isSingleItemPtr(comptime T: type) bool {
if (comptime is(.pointer)(T)) {
return @typeInfo(T).pointer.size == .One;
return @typeInfo(T).pointer.size == .one;
}
return false;
}

View file

@ -1,18 +1,16 @@
export fn entry() void {
_ = @Type(.{ .pointer = .{
.size = .One,
.size = .one,
.is_const = false,
.is_volatile = false,
.alignment = 1,
.address_space = .generic,
.child = u8,
.is_allowzero = false,
.sentinel = &@as(u8, 0),
.sentinel_ptr = &@as(u8, 0),
} });
}
// error
// backend=stage2
// target=native
//
// :2:9: error: sentinels are only allowed on slices and unknown-length pointers

View file

@ -12,30 +12,30 @@ comptime {
}
comptime {
_ = @Type(.{ .array = .{ .child = S, .len = 0, .sentinel = &sentinel } });
_ = @Type(.{ .array = .{ .child = S, .len = 0, .sentinel_ptr = &sentinel } });
}
comptime {
_ = @Type(.{ .pointer = .{
.size = .Many,
.size = .slice,
.is_const = false,
.is_volatile = false,
.alignment = @alignOf(S),
.address_space = .generic,
.child = S,
.is_allowzero = false,
.sentinel = &sentinel,
.sentinel_ptr = &sentinel,
} });
}
comptime {
_ = @Type(.{ .pointer = .{
.size = .Many,
.size = .many,
.is_const = false,
.is_volatile = false,
.alignment = @alignOf(S),
.address_space = .generic,
.child = S,
.is_allowzero = false,
.sentinel = &sentinel,
.sentinel_ptr = &sentinel,
} });
}

View file

@ -1,11 +1,9 @@
export fn entry() void {
_ = @Type(.{ .@"struct" = .{ .layout = .@"packed", .fields = &.{
.{ .name = "one", .type = u4, .default_value = null, .is_comptime = false, .alignment = 2 },
.{ .name = "one", .type = u4, .default_value_ptr = null, .is_comptime = false, .alignment = 2 },
}, .decls = &.{}, .is_tuple = false } });
}
// error
// backend=stage2
// target=native
//
// :2:9: error: alignment in a packed struct field must be set to 0

View file

@ -4,7 +4,7 @@ comptime {
.fields = &.{.{
.name = "foo",
.type = u32,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 4,
}},
@ -18,7 +18,7 @@ comptime {
.fields = &.{.{
.name = "3",
.type = u32,
.default_value = null,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 4,
}},
@ -32,7 +32,7 @@ comptime {
.fields = &.{.{
.name = "0",
.type = u32,
.default_value = null,
.default_value_ptr = null,
.is_comptime = true,
.alignment = 4,
}},
@ -46,7 +46,7 @@ comptime {
.fields = &.{.{
.name = "0",
.type = u32,
.default_value = null,
.default_value_ptr = null,
.is_comptime = true,
.alignment = 4,
}},
@ -60,7 +60,7 @@ comptime {
.fields = &.{.{
.name = "0",
.type = u32,
.default_value = null,
.default_value_ptr = null,
.is_comptime = true,
.alignment = 4,
}},
@ -70,8 +70,6 @@ comptime {
}
// error
// backend=stage2
// target=native
//
// :2:5: error: tuple cannot have non-numeric field 'foo'
// :16:5: error: tuple field name '3' does not match field index 0

View file

@ -17,7 +17,7 @@ comptime {
.fields = &.{.{
.name = "0",
.type = u32,
.default_value = null,
.default_value_ptr = null,
.is_comptime = true,
.alignment = 5,
}},
@ -29,21 +29,19 @@ comptime {
comptime {
_ = @Type(.{
.pointer = .{
.size = .Many,
.size = .many,
.is_const = true,
.is_volatile = false,
.alignment = 7,
.address_space = .generic,
.child = u8,
.is_allowzero = false,
.sentinel = null,
.sentinel_ptr = null,
},
});
}
// error
// backend=stage2
// target=native
//
// :2:9: error: alignment value '3' is not a power of two or zero
// :14:9: error: alignment value '5' is not a power of two or zero

View file

@ -1,5 +1,5 @@
comptime {
_ = @Type(.{ .array = .{ .len = 0, .child = u8, .sentinel = undefined } });
_ = @Type(.{ .array = .{ .len = 0, .child = u8, .sentinel_ptr = undefined } });
}
comptime {
_ = @Type(.{