std.builtin: rename Type.UnionField and Type.StructField's field_type to type

This commit is contained in:
r00ster91 2022-12-13 22:30:06 +01:00
parent 7350ea3e2d
commit aac2d6b56f
60 changed files with 177 additions and 178 deletions

View File

@ -4253,7 +4253,7 @@ fn isFieldOptional(comptime T: type, field_index: usize) !bool {
return switch (field_index) {
// This prong is analyzed `fields.len - 1` times with `idx` being an
// unique comptime-known value each time.
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].field_type) == .Optional,
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
else => return error.IndexOutOfBounds,
};
}

View File

@ -2270,13 +2270,13 @@ test "reIndex" {
test "auto store_hash" {
const HasCheapEql = AutoArrayHashMap(i32, i32);
const HasExpensiveEql = AutoArrayHashMap([32]i32, i32);
try testing.expect(meta.fieldInfo(HasCheapEql.Data, .hash).field_type == void);
try testing.expect(meta.fieldInfo(HasExpensiveEql.Data, .hash).field_type != void);
try testing.expect(meta.fieldInfo(HasCheapEql.Data, .hash).type == void);
try testing.expect(meta.fieldInfo(HasExpensiveEql.Data, .hash).type != void);
const HasCheapEqlUn = AutoArrayHashMapUnmanaged(i32, i32);
const HasExpensiveEqlUn = AutoArrayHashMapUnmanaged([32]i32, i32);
try testing.expect(meta.fieldInfo(HasCheapEqlUn.Data, .hash).field_type == void);
try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Data, .hash).field_type != void);
try testing.expect(meta.fieldInfo(HasCheapEqlUn.Data, .hash).type == void);
try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Data, .hash).type != void);
}
test "sort" {

View File

@ -280,8 +280,7 @@ pub const Type = union(enum) {
/// therefore must be kept in sync with the compiler implementation.
pub const StructField = struct {
name: []const u8,
/// TODO rename to `type`
field_type: type,
type: type,
default_value: ?*const anyopaque,
is_comptime: bool,
alignment: comptime_int,
@ -343,7 +342,7 @@ pub const Type = union(enum) {
/// therefore must be kept in sync with the compiler implementation.
pub const UnionField = struct {
name: []const u8,
field_type: type,
type: type,
alignment: comptime_int,
};

View File

@ -110,9 +110,9 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
var found = false;
inline for (comptime meta.fields(HashResult)) |p| {
if (mem.eql(u8, p.name, param.key)) {
switch (@typeInfo(p.field_type)) {
switch (@typeInfo(p.type)) {
.Int => @field(out, p.name) = fmt.parseUnsigned(
p.field_type,
p.type,
param.value,
10,
) catch return Error.InvalidEncoding,
@ -161,7 +161,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.field_type) != .Optional and p.default_value == null) {
if (@typeInfo(p.type) != .Optional and p.default_value == null) {
expected_fields += 1;
}
}
@ -223,7 +223,7 @@ fn serializeTo(params: anytype, out: anytype) !void {
{
const value = @field(params, p.name);
try out.writeAll(if (has_params) params_delimiter else fields_delimiter);
if (@typeInfo(p.field_type) == .Struct) {
if (@typeInfo(p.type) == .Struct) {
var buf: [@TypeOf(value).max_encoded_length]u8 = undefined;
try out.print("{s}{s}{s}", .{ p.name, kv_delimiter, try value.toB64(&buf) });
} else {

View File

@ -15,7 +15,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def
for (std.meta.fields(E)) |field| {
fields = fields ++ &[_]StructField{.{
.name = field.name,
.field_type = Data,
.type = Data,
.default_value = if (field_default) |d| @ptrCast(?*const anyopaque, &d) else null,
.is_comptime = false,
.alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,

View File

@ -134,7 +134,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
hash(hasher, tag, strat);
inline for (info.fields) |field| {
if (@field(tag_type, field.name) == tag) {
if (field.field_type != void) {
if (field.type != void) {
hash(hasher, @field(key, field.name), strat);
}
// TODO use a labelled break when it does not crash the compiler. cf #2908
@ -163,14 +163,14 @@ fn typeContainsSlice(comptime K: type) bool {
}
if (meta.trait.is(.Struct)(K)) {
inline for (@typeInfo(K).Struct.fields) |field| {
if (typeContainsSlice(field.field_type)) {
if (typeContainsSlice(field.type)) {
return true;
}
}
}
if (meta.trait.is(.Union)(K)) {
inline for (@typeInfo(K).Union.fields) |field| {
if (typeContainsSlice(field.field_type)) {
if (typeContainsSlice(field.type)) {
return true;
}
}

View File

@ -6,7 +6,7 @@ const testing = std.testing;
pub fn MultiWriter(comptime Writers: type) type {
comptime var ErrSet = error{};
inline for (@typeInfo(Writers).Struct.fields) |field| {
const StreamType = field.field_type;
const StreamType = field.type;
ErrSet = ErrSet || StreamType.Error;
}

View File

@ -1362,7 +1362,7 @@ fn ParseInternalErrorImpl(comptime T: type, comptime inferred_types: []const typ
if (unionInfo.tag_type) |_| {
var errors = error{NoUnionMembersMatched};
for (unionInfo.fields) |u_field| {
errors = errors || ParseInternalErrorImpl(u_field.field_type, inferred_types ++ [_]type{T});
errors = errors || ParseInternalErrorImpl(u_field.type, inferred_types ++ [_]type{T});
}
return errors;
} else {
@ -1379,7 +1379,7 @@ fn ParseInternalErrorImpl(comptime T: type, comptime inferred_types: []const typ
MissingField,
} || SkipValueError || TokenStream.Error;
for (structInfo.fields) |field| {
errors = errors || ParseInternalErrorImpl(field.field_type, inferred_types ++ [_]type{T});
errors = errors || ParseInternalErrorImpl(field.type, inferred_types ++ [_]type{T});
}
return errors;
},
@ -1491,7 +1491,7 @@ fn parseInternal(
inline for (unionInfo.fields) |u_field| {
// take a copy of tokens so we can withhold mutations until success
var tokens_copy = tokens.*;
if (parseInternal(u_field.field_type, token, &tokens_copy, options)) |value| {
if (parseInternal(u_field.type, token, &tokens_copy, options)) |value| {
tokens.* = tokens_copy;
return @unionInit(T, u_field.name, value);
} else |err| {
@ -1519,7 +1519,7 @@ fn parseInternal(
errdefer {
inline for (structInfo.fields) |field, i| {
if (fields_seen[i] and !field.is_comptime) {
parseFree(field.field_type, @field(r, field.name), options);
parseFree(field.type, @field(r, field.name), options);
}
}
}
@ -1547,24 +1547,24 @@ fn parseInternal(
// }
if (options.duplicate_field_behavior == .UseFirst) {
// unconditonally ignore value. for comptime fields, this skips check against default_value
parseFree(field.field_type, try parse(field.field_type, tokens, child_options), child_options);
parseFree(field.type, try parse(field.type, tokens, child_options), child_options);
found = true;
break;
} else if (options.duplicate_field_behavior == .Error) {
return error.DuplicateJSONField;
} else if (options.duplicate_field_behavior == .UseLast) {
if (!field.is_comptime) {
parseFree(field.field_type, @field(r, field.name), child_options);
parseFree(field.type, @field(r, field.name), child_options);
}
fields_seen[i] = false;
}
}
if (field.is_comptime) {
if (!try parsesTo(field.field_type, @ptrCast(*align(1) const field.field_type, field.default_value.?).*, tokens, child_options)) {
if (!try parsesTo(field.type, @ptrCast(*align(1) const field.type, field.default_value.?).*, tokens, child_options)) {
return error.UnexpectedValue;
}
} else {
@field(r, field.name) = try parse(field.field_type, tokens, child_options);
@field(r, field.name) = try parse(field.type, tokens, child_options);
}
fields_seen[i] = true;
found = true;
@ -1587,7 +1587,7 @@ fn parseInternal(
if (!fields_seen[i]) {
if (field.default_value) |default_ptr| {
if (!field.is_comptime) {
const default = @ptrCast(*align(1) const field.field_type, default_ptr).*;
const default = @ptrCast(*align(1) const field.type, default_ptr).*;
@field(r, field.name) = default;
}
} else {
@ -1732,7 +1732,7 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
if (unionInfo.tag_type) |UnionTagType| {
inline for (unionInfo.fields) |u_field| {
if (value == @field(UnionTagType, u_field.name)) {
parseFree(u_field.field_type, @field(value, u_field.name), options);
parseFree(u_field.type, @field(value, u_field.name), options);
break;
}
}
@ -1743,7 +1743,7 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
.Struct => |structInfo| {
inline for (structInfo.fields) |field| {
if (!field.is_comptime) {
parseFree(field.field_type, @field(value, field.name), options);
parseFree(field.type, @field(value, field.name), options);
}
}
},
@ -2270,12 +2270,12 @@ pub fn stringify(
}
inline for (S.fields) |Field| {
// don't include void fields
if (Field.field_type == void) continue;
if (Field.type == void) continue;
var emit_field = true;
// don't include optional fields that are null when emit_null_optional_fields is set to false
if (@typeInfo(Field.field_type) == .Optional) {
if (@typeInfo(Field.type) == .Optional) {
if (options.emit_null_optional_fields == false) {
if (@field(value, Field.name) == null) {
emit_field = false;

View File

@ -300,7 +300,7 @@ pub fn zeroes(comptime T: type) T {
if (comptime meta.containerLayout(T) == .Extern) {
// The C language specification states that (global) unions
// should be zero initialized to the first named member.
return @unionInit(T, info.fields[0].name, zeroes(info.fields[0].field_type));
return @unionInit(T, info.fields[0].name, zeroes(info.fields[0].type));
}
@compileError("Can't set a " ++ @typeName(T) ++ " to zero.");
@ -435,7 +435,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
inline for (struct_info.fields) |field| {
if (field.default_value) |default_value_ptr| {
const default_value = @ptrCast(*align(1) const field.field_type, default_value_ptr).*;
const default_value = @ptrCast(*align(1) const field.type, default_value_ptr).*;
@field(value, field.name) = default_value;
}
}
@ -452,9 +452,9 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
@compileError("Encountered an initializer for `" ++ field.name ++ "`, but it is not a field of " ++ @typeName(T));
}
switch (@typeInfo(field.field_type)) {
switch (@typeInfo(field.type)) {
.Struct => {
@field(value, field.name) = zeroInit(field.field_type, @field(init, field.name));
@field(value, field.name) = zeroInit(field.type, @field(init, field.name));
},
else => {
@field(value, field.name) = @field(init, field.name);

View File

@ -522,8 +522,8 @@ test "std.meta.fields" {
try testing.expect(mem.eql(u8, e2f[0].name, "A"));
try testing.expect(mem.eql(u8, sf[0].name, "a"));
try testing.expect(mem.eql(u8, uf[0].name, "a"));
try testing.expect(comptime sf[0].field_type == u8);
try testing.expect(comptime uf[0].field_type == u8);
try testing.expect(comptime sf[0].type == u8);
try testing.expect(comptime uf[0].type == u8);
}
pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
@ -557,8 +557,8 @@ test "std.meta.fieldInfo" {
try testing.expect(mem.eql(u8, e2f.name, "A"));
try testing.expect(mem.eql(u8, sf.name, "a"));
try testing.expect(mem.eql(u8, uf.name, "a"));
try testing.expect(comptime sf.field_type == u8);
try testing.expect(comptime uf.field_type == u8);
try testing.expect(comptime sf.type == u8);
try testing.expect(comptime uf.type == u8);
}
pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {
@ -831,7 +831,7 @@ pub fn TagPayload(comptime U: type, comptime tag: Tag(U)) type {
inline for (info.fields) |field_info| {
if (comptime mem.eql(u8, field_info.name, @tagName(tag)))
return field_info.field_type;
return field_info.type;
}
unreachable;
@ -1111,7 +1111,7 @@ fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type {
var num_buf: [128]u8 = undefined;
tuple_fields[i] = .{
.name = std.fmt.bufPrint(&num_buf, "{d}", .{i}) catch unreachable,
.field_type = T,
.type = T,
.default_value = null,
.is_comptime = false,
.alignment = if (@sizeOf(T) > 0) @alignOf(T) else 0,
@ -1146,8 +1146,8 @@ const TupleTester = struct {
@compileError("Argument count mismatch");
inline for (fields_list) |fld, i| {
if (expected[i] != fld.field_type) {
@compileError("Field " ++ fld.name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld.field_type));
if (expected[i] != fld.type) {
@compileError("Field " ++ fld.name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld.type));
}
}
}

View File

@ -24,10 +24,10 @@ pub fn TrailerFlags(comptime Fields: type) type {
inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| {
fields[i] = Type.StructField{
.name = struct_field.name,
.field_type = ?struct_field.field_type,
.default_value = &@as(?struct_field.field_type, null),
.type = ?struct_field.type,
.default_value = &@as(?struct_field.type, null),
.is_comptime = false,
.alignment = @alignOf(?struct_field.field_type),
.alignment = @alignOf(?struct_field.type),
};
}
break :blk @Type(.{
@ -105,26 +105,26 @@ pub fn TrailerFlags(comptime Fields: type) type {
const active = (self.bits & (1 << i)) != 0;
if (i == @enumToInt(field)) {
assert(active);
return mem.alignForwardGeneric(usize, off, @alignOf(field_info.field_type));
return mem.alignForwardGeneric(usize, off, @alignOf(field_info.type));
} else if (active) {
off = mem.alignForwardGeneric(usize, off, @alignOf(field_info.field_type));
off += @sizeOf(field_info.field_type);
off = mem.alignForwardGeneric(usize, off, @alignOf(field_info.type));
off += @sizeOf(field_info.type);
}
}
}
pub fn Field(comptime field: FieldEnum) type {
return @typeInfo(Fields).Struct.fields[@enumToInt(field)].field_type;
return @typeInfo(Fields).Struct.fields[@enumToInt(field)].type;
}
pub fn sizeInBytes(self: Self) usize {
var off: usize = 0;
inline for (@typeInfo(Fields).Struct.fields) |field, i| {
if (@sizeOf(field.field_type) == 0)
if (@sizeOf(field.type) == 0)
continue;
if ((self.bits & (1 << i)) != 0) {
off = mem.alignForwardGeneric(usize, off, @alignOf(field.field_type));
off += @sizeOf(field.field_type);
off = mem.alignForwardGeneric(usize, off, @alignOf(field.type));
off += @sizeOf(field.type);
}
}
return off;

View File

@ -566,7 +566,7 @@ pub fn hasUniqueRepresentation(comptime T: type) bool {
var sum_size = @as(usize, 0);
inline for (info.fields) |field| {
const FieldType = field.field_type;
const FieldType = field.type;
if (comptime !hasUniqueRepresentation(FieldType)) return false;
sum_size += @sizeOf(FieldType);
}

View File

@ -84,9 +84,9 @@ pub fn MultiArrayList(comptime S: type) type {
var data: [fields.len]Data = undefined;
for (fields) |field_info, i| {
data[i] = .{
.size = @sizeOf(field_info.field_type),
.size = @sizeOf(field_info.type),
.size_index = i,
.alignment = if (@sizeOf(field_info.field_type) == 0) 1 else field_info.alignment,
.alignment = if (@sizeOf(field_info.type) == 0) 1 else field_info.alignment,
};
}
const Sort = struct {
@ -294,10 +294,10 @@ pub fn MultiArrayList(comptime S: type) type {
) catch {
const self_slice = self.slice();
inline for (fields) |field_info, i| {
if (@sizeOf(field_info.field_type) != 0) {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
const dest_slice = self_slice.items(field)[new_len..];
const byte_count = dest_slice.len * @sizeOf(field_info.field_type);
const byte_count = dest_slice.len * @sizeOf(field_info.type);
// We use memset here for more efficient codegen in safety-checked,
// valgrind-enabled builds. Otherwise the valgrind client request
// will be repeated for every element.
@ -316,9 +316,9 @@ pub fn MultiArrayList(comptime S: type) type {
const self_slice = self.slice();
const other_slice = other.slice();
inline for (fields) |field_info, i| {
if (@sizeOf(field_info.field_type) != 0) {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
mem.copy(field_info.field_type, other_slice.items(field), self_slice.items(field));
mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));
}
}
gpa.free(self.allocatedBytes());
@ -377,9 +377,9 @@ pub fn MultiArrayList(comptime S: type) type {
const self_slice = self.slice();
const other_slice = other.slice();
inline for (fields) |field_info, i| {
if (@sizeOf(field_info.field_type) != 0) {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
mem.copy(field_info.field_type, other_slice.items(field), self_slice.items(field));
mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));
}
}
gpa.free(self.allocatedBytes());
@ -396,9 +396,9 @@ pub fn MultiArrayList(comptime S: type) type {
const self_slice = self.slice();
const result_slice = result.slice();
inline for (fields) |field_info, i| {
if (@sizeOf(field_info.field_type) != 0) {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
mem.copy(field_info.field_type, result_slice.items(field), self_slice.items(field));
mem.copy(field_info.type, result_slice.items(field), self_slice.items(field));
}
}
return result;
@ -413,10 +413,10 @@ pub fn MultiArrayList(comptime S: type) type {
pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
inline for (fields) |field_info, i| {
if (@sizeOf(field_info.field_type) != 0) {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
const ptr = sc.slice.items(field);
mem.swap(field_info.field_type, &ptr[a_index], &ptr[b_index]);
mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);
}
}
}
@ -449,7 +449,7 @@ pub fn MultiArrayList(comptime S: type) type {
}
fn FieldType(comptime field: Field) type {
return meta.fieldInfo(S, field).field_type;
return meta.fieldInfo(S, field).type;
}
/// This function is used in tools/zig-gdb.py to fetch the child type to facilitate

View File

@ -81,7 +81,7 @@ pub const DevicePathProtocol = extern struct {
// Got the associated union type for self.type, now
// we need to initialize it and its subtype
if (self.type == enum_value) {
var subtype = self.initSubtype(ufield.field_type);
var subtype = self.initSubtype(ufield.type);
if (subtype) |sb| {
// e.g. return .{ .Hardware = .{ .Pci = @ptrCast(...) } }
@ -103,7 +103,7 @@ pub const DevicePathProtocol = extern struct {
if (self.subtype == tag_val) {
// e.g. expr = .{ .Pci = @ptrCast(...) }
return @unionInit(TUnion, subtype.name, @ptrCast(subtype.field_type, self));
return @unionInit(TUnion, subtype.name, @ptrCast(subtype.type, self));
}
}

View File

@ -802,7 +802,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
const ArgsTuple = std.meta.ArgsTuple(@TypeOf(test_fn));
const fn_args_fields = @typeInfo(ArgsTuple).Struct.fields;
if (fn_args_fields.len == 0 or fn_args_fields[0].field_type != std.mem.Allocator) {
if (fn_args_fields.len == 0 or fn_args_fields[0].type != std.mem.Allocator) {
@compileError("The provided function must have an " ++ @typeName(std.mem.Allocator) ++ " as its first argument");
}
const expected_args_tuple_len = fn_args_fields.len - 1;

View File

@ -230,12 +230,12 @@ pub const Socket = struct {
pub fn setName(self: *Self, name: []const u8) void {
self.name = @ptrToInt(name.ptr);
self.name_len = @intCast(meta.fieldInfo(Self, .name_len).field_type, name.len);
self.name_len = @intCast(meta.fieldInfo(Self, .name_len).type, name.len);
}
pub fn setBuffers(self: *Self, buffers: []const Buffer) void {
self.buffers = @ptrToInt(buffers.ptr);
self.buffers_len = @intCast(meta.fieldInfo(Self, .buffers_len).field_type, buffers.len);
self.buffers_len = @intCast(meta.fieldInfo(Self, .buffers_len).type, buffers.len);
}
pub fn setControl(self: *Self, control: []const u8) void {
@ -243,12 +243,12 @@ pub const Socket = struct {
self.control = Buffer.from(control);
} else {
self.control = @ptrToInt(control.ptr);
self.control_len = @intCast(meta.fieldInfo(Self, .control_len).field_type, control.len);
self.control_len = @intCast(meta.fieldInfo(Self, .control_len).type, control.len);
}
}
pub fn setFlags(self: *Self, flags: u32) void {
self.flags = @intCast(meta.fieldInfo(Self, .flags).field_type, flags);
self.flags = @intCast(meta.fieldInfo(Self, .flags).type, flags);
}
pub fn getName(self: Self) []const u8 {

View File

@ -125,7 +125,7 @@ pub fn extraData(tree: Ast, index: usize, comptime T: type) T {
const fields = std.meta.fields(T);
var result: T = undefined;
inline for (fields) |field, i| {
comptime assert(field.field_type == Node.Index);
comptime assert(field.type == Node.Index);
@field(result, field.name) = tree.extra_data[index + i];
}
return result;

View File

@ -50,7 +50,7 @@ pub fn cast(comptime DestType: type, target: anytype) DestType {
},
.Union => |info| {
inline for (info.fields) |field| {
if (field.field_type == SourceType) return @unionInit(DestType, field.name, target);
if (field.type == SourceType) return @unionInit(DestType, field.name, target);
}
@compileError("cast to union type '" ++ @typeName(DestType) ++ "' from type '" ++ @typeName(SourceType) ++ "' which is not present in union");
},

View File

@ -153,7 +153,7 @@ const Parser = struct {
try p.extra_data.ensureUnusedCapacity(p.gpa, fields.len);
const result = @intCast(u32, p.extra_data.items.len);
inline for (fields) |field| {
comptime assert(field.field_type == Node.Index);
comptime assert(field.type == Node.Index);
p.extra_data.appendAssumeCapacity(@field(extra, field.name));
}
return result;

View File

@ -1260,7 +1260,7 @@ pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end
var i: usize = index;
var result: T = undefined;
inline for (fields) |field| {
@field(result, field.name) = switch (field.field_type) {
@field(result, field.name) = switch (field.type) {
u32 => air.extra[i],
Inst.Ref => @intToEnum(Inst.Ref, air.extra[i]),
i32 => @bitCast(i32, air.extra[i]),

View File

@ -79,7 +79,7 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
const fields = std.meta.fields(@TypeOf(extra));
var i = index;
inline for (fields) |field| {
astgen.extra.items[i] = switch (field.field_type) {
astgen.extra.items[i] = switch (field.type) {
u32 => @field(extra, field.name),
Zir.Inst.Ref => @enumToInt(@field(extra, field.name)),
i32 => @bitCast(u32, @field(extra, field.name)),

View File

@ -637,9 +637,9 @@ const DocData = struct {
inline for (comptime std.meta.fields(Type)) |case| {
if (@field(Type, case.name) == active_tag) {
const current_value = @field(self, case.name);
inline for (comptime std.meta.fields(case.field_type)) |f| {
inline for (comptime std.meta.fields(case.type)) |f| {
try jsw.arrayElem();
if (f.field_type == std.builtin.Type.Pointer.Size) {
if (f.type == std.builtin.Type.Pointer.Size) {
try jsw.emitNumber(@enumToInt(@field(current_value, f.name)));
} else {
try std.json.stringify(@field(current_value, f.name), opts, w);

View File

@ -259,7 +259,7 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
const fields = std.meta.fields(@TypeOf(extra));
const result = @intCast(u32, ip.extra.items.len);
inline for (fields) |field| {
ip.extra.appendAssumeCapacity(switch (field.field_type) {
ip.extra.appendAssumeCapacity(switch (field.type) {
u32 => @field(extra, field.name),
Index => @enumToInt(@field(extra, field.name)),
i32 => @bitCast(u32, @field(extra, field.name)),
@ -274,7 +274,7 @@ fn extraData(ip: InternPool, comptime T: type, index: usize) T {
var i: usize = index;
var result: T = undefined;
inline for (fields) |field| {
@field(result, field.name) = switch (field.field_type) {
@field(result, field.name) = switch (field.type) {
u32 => ip.extra.items[i],
Index => @intToEnum(Index, ip.extra.items[i]),
i32 => @bitCast(i32, ip.extra.items[i]),

View File

@ -718,7 +718,7 @@ const Analysis = struct {
const fields = std.meta.fields(@TypeOf(extra));
const result = @intCast(u32, a.extra.items.len);
inline for (fields) |field| {
a.extra.appendAssumeCapacity(switch (field.field_type) {
a.extra.appendAssumeCapacity(switch (field.type) {
u32 => @field(extra, field.name),
else => @compileError("bad field type"),
});

View File

@ -15767,7 +15767,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
union_field_fields.* = .{
// name: []const u8,
name_val,
// field_type: type,
// type: type,
try Value.Tag.ty.create(fields_anon_decl.arena(), field.ty),
// alignment: comptime_int,
try Value.Tag.int_u64.create(fields_anon_decl.arena(), alignment),
@ -15880,7 +15880,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
struct_field_fields.* = .{
// name: []const u8,
name_val,
// field_type: type,
// type: type,
try Value.Tag.ty.create(fields_anon_decl.arena(), field_ty),
// default_value: ?*const anyopaque,
try default_val_ptr.copy(fields_anon_decl.arena()),
@ -15925,7 +15925,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
struct_field_fields.* = .{
// name: []const u8,
name_val,
// field_type: type,
// type: type,
try Value.Tag.ty.create(fields_anon_decl.arena(), field.ty),
// default_value: ?*const anyopaque,
try default_val_ptr.copy(fields_anon_decl.arena()),
@ -18574,8 +18574,8 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
// TODO use reflection instead of magic numbers here
// name: []const u8
const name_val = field_struct_val[0];
// field_type: type,
const field_type_val = field_struct_val[1];
// type: type,
const type_val = field_struct_val[1];
// alignment: comptime_int,
const alignment_val = field_struct_val[2];
@ -18609,7 +18609,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
}
var buffer: Value.ToTypeBuffer = undefined;
const field_ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator);
const field_ty = try type_val.toType(&buffer).copy(new_decl_arena_allocator);
gop.value_ptr.* = .{
.ty = field_ty,
.abi_align = @intCast(u32, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?),
@ -18828,9 +18828,9 @@ fn reifyStruct(
// TODO use reflection instead of magic numbers here
// name: []const u8
const name_val = field_struct_val[0];
// field_type: type,
const field_type_val = field_struct_val[1];
//default_value: ?*const anyopaque,
// type: type,
const type_val = field_struct_val[1];
// default_value: ?*const anyopaque,
const default_value_val = field_struct_val[2];
// is_comptime: bool,
const is_comptime_val = field_struct_val[3];
@ -18893,7 +18893,7 @@ fn reifyStruct(
}
var buffer: Value.ToTypeBuffer = undefined;
const field_ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator);
const field_ty = try type_val.toType(&buffer).copy(new_decl_arena_allocator);
gop.value_ptr.* = .{
.ty = field_ty,
.abi_align = abi_align,
@ -31439,7 +31439,7 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
const fields = std.meta.fields(@TypeOf(extra));
const result = @intCast(u32, sema.air_extra.items.len);
inline for (fields) |field| {
sema.air_extra.appendAssumeCapacity(switch (field.field_type) {
sema.air_extra.appendAssumeCapacity(switch (field.type) {
u32 => @field(extra, field.name),
Air.Inst.Ref => @enumToInt(@field(extra, field.name)),
i32 => @bitCast(u32, @field(extra, field.name)),

View File

@ -71,7 +71,7 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) struct { data: T, en
var i: usize = index;
var result: T = undefined;
inline for (fields) |field| {
@field(result, field.name) = switch (field.field_type) {
@field(result, field.name) = switch (field.type) {
u32 => code.extra[i],
Inst.Ref => @intToEnum(Inst.Ref, code.extra[i]),
i32 => @bitCast(i32, code.extra[i]),

View File

@ -477,7 +477,7 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
const fields = std.meta.fields(@TypeOf(extra));
const result = @intCast(u32, self.mir_extra.items.len);
inline for (fields) |field| {
self.mir_extra.appendAssumeCapacity(switch (field.field_type) {
self.mir_extra.appendAssumeCapacity(switch (field.type) {
u32 => @field(extra, field.name),
i32 => @bitCast(u32, @field(extra, field.name)),
else => @compileError("bad field type"),

View File

@ -505,7 +505,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
var i: usize = index;
var result: T = undefined;
inline for (fields) |field| {
@field(result, field.name) = switch (field.field_type) {
@field(result, field.name) = switch (field.type) {
u32 => mir.extra[i],
i32 => @bitCast(i32, mir.extra[i]),
else => @compileError("bad field type"),

View File

@ -386,7 +386,7 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
const fields = std.meta.fields(@TypeOf(extra));
const result = @intCast(u32, self.mir_extra.items.len);
inline for (fields) |field| {
self.mir_extra.appendAssumeCapacity(switch (field.field_type) {
self.mir_extra.appendAssumeCapacity(switch (field.type) {
u32 => @field(extra, field.name),
i32 => @bitCast(u32, @field(extra, field.name)),
else => @compileError("bad field type"),

View File

@ -283,7 +283,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
var i: usize = index;
var result: T = undefined;
inline for (fields) |field| {
@field(result, field.name) = switch (field.field_type) {
@field(result, field.name) = switch (field.type) {
u32 => mir.extra[i],
i32 => @bitCast(i32, mir.extra[i]),
else => @compileError("bad field type"),

View File

@ -340,7 +340,7 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
const fields = std.meta.fields(@TypeOf(extra));
const result = @intCast(u32, self.mir_extra.items.len);
inline for (fields) |field| {
self.mir_extra.appendAssumeCapacity(switch (field.field_type) {
self.mir_extra.appendAssumeCapacity(switch (field.type) {
u32 => @field(extra, field.name),
i32 => @bitCast(u32, @field(extra, field.name)),
else => @compileError("bad field type"),

View File

@ -132,7 +132,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
var i: usize = index;
var result: T = undefined;
inline for (fields) |field| {
@field(result, field.name) = switch (field.field_type) {
@field(result, field.name) = switch (field.type) {
u32 => mir.extra[i],
i32 => @bitCast(i32, mir.extra[i]),
else => @compileError("bad field type"),

View File

@ -347,7 +347,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
var i: usize = index;
var result: T = undefined;
inline for (fields) |field| {
@field(result, field.name) = switch (field.field_type) {
@field(result, field.name) = switch (field.type) {
u32 => mir.extra[i],
i32 => @bitCast(i32, mir.extra[i]),
else => @compileError("bad field type"),

View File

@ -960,7 +960,7 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32
const fields = std.meta.fields(@TypeOf(extra));
const result = @intCast(u32, func.mir_extra.items.len);
inline for (fields) |field| {
func.mir_extra.appendAssumeCapacity(switch (field.field_type) {
func.mir_extra.appendAssumeCapacity(switch (field.type) {
u32 => @field(extra, field.name),
else => |field_type| @compileError("Unsupported field type " ++ @typeName(field_type)),
});

View File

@ -589,7 +589,7 @@ pub fn extraData(self: *const Mir, comptime T: type, index: usize) struct { data
var i: usize = index;
var result: T = undefined;
inline for (fields) |field| {
@field(result, field.name) = switch (field.field_type) {
@field(result, field.name) = switch (field.type) {
u32 => self.extra[i],
else => |field_type| @compileError("Unsupported field type " ++ @typeName(field_type)),
};

View File

@ -374,7 +374,7 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
const fields = std.meta.fields(@TypeOf(extra));
const result = @intCast(u32, self.mir_extra.items.len);
inline for (fields) |field| {
self.mir_extra.appendAssumeCapacity(switch (field.field_type) {
self.mir_extra.appendAssumeCapacity(switch (field.type) {
u32 => @field(extra, field.name),
i32 => @bitCast(u32, @field(extra, field.name)),
else => @compileError("bad field type"),

View File

@ -612,7 +612,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
var i: usize = index;
var result: T = undefined;
inline for (fields) |field| {
@field(result, field.name) = switch (field.field_type) {
@field(result, field.name) = switch (field.type) {
u32 => mir.extra[i],
i32 => @bitCast(i32, mir.extra[i]),
else => @compileError("bad field type"),

View File

@ -116,7 +116,7 @@ fn writeOperands(section: *Section, comptime Operands: type, operands: Operands)
};
inline for (fields) |field| {
section.writeOperand(field.field_type, @field(operands, field.name));
section.writeOperand(field.type, @field(operands, field.name));
}
}
@ -196,7 +196,7 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe
fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void {
var mask: Word = 0;
inline for (@typeInfo(Operand).Struct.fields) |field, bit| {
switch (@typeInfo(field.field_type)) {
switch (@typeInfo(field.type)) {
.Optional => if (@field(operand, field.name) != null) {
mask |= 1 << @intCast(u5, bit);
},
@ -214,7 +214,7 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
section.writeWord(mask);
inline for (@typeInfo(Operand).Struct.fields) |field| {
switch (@typeInfo(field.field_type)) {
switch (@typeInfo(field.type)) {
.Optional => |info| if (@field(operand, field.name)) |child| {
section.writeOperands(info.child, child);
},
@ -230,7 +230,7 @@ fn writeExtendedUnion(section: *Section, comptime Operand: type, operand: Operan
inline for (@typeInfo(Operand).Union.fields) |field| {
if (@field(Operand, field.name) == tag) {
section.writeOperands(field.field_type, @field(operand, field.name));
section.writeOperands(field.type, @field(operand, field.name));
return;
}
}
@ -250,7 +250,7 @@ fn operandsSize(comptime Operands: type, operands: Operands) usize {
var total: usize = 0;
inline for (fields) |field| {
total += operandSize(field.field_type, @field(operands, field.name));
total += operandSize(field.type, @field(operands, field.name));
}
return total;
@ -304,7 +304,7 @@ fn extendedMaskSize(comptime Operand: type, operand: Operand) usize {
var total: usize = 0;
var any_set = false;
inline for (@typeInfo(Operand).Struct.fields) |field| {
switch (@typeInfo(field.field_type)) {
switch (@typeInfo(field.type)) {
.Optional => |info| if (@field(operand, field.name)) |child| {
total += operandsSize(info.child, child);
any_set = true;
@ -326,7 +326,7 @@ fn extendedUnionSize(comptime Operand: type, operand: Operand) usize {
inline for (@typeInfo(Operand).Union.fields) |field| {
if (@field(Operand, field.name) == tag) {
// Add one for the tag itself.
return 1 + operandsSize(field.field_type, @field(operand, field.name));
return 1 + operandsSize(field.type, @field(operand, field.name));
}
}
unreachable;

View File

@ -339,7 +339,7 @@ pub const Yaml = struct {
if (union_info.tag_type) |_| {
inline for (union_info.fields) |field| {
if (self.parseValue(field.field_type, value)) |u_value| {
if (self.parseValue(field.type, value)) |u_value| {
return @unionInit(T, field.name, u_value);
} else |err| {
if (@as(@TypeOf(err) || error{TypeMismatch}, err) != error.TypeMismatch) return err;
@ -366,16 +366,16 @@ pub const Yaml = struct {
break :blk map.get(field_name);
};
if (@typeInfo(field.field_type) == .Optional) {
@field(parsed, field.name) = try self.parseOptional(field.field_type, value);
if (@typeInfo(field.type) == .Optional) {
@field(parsed, field.name) = try self.parseOptional(field.type, value);
continue;
}
const unwrapped = value orelse {
log.debug("missing struct field: {s}: {s}", .{ field.name, @typeName(field.field_type) });
log.debug("missing struct field: {s}: {s}", .{ field.name, @typeName(field.type) });
return error.StructFieldMissing;
};
@field(parsed, field.name) = try self.parseValue(field.field_type, unwrapped);
@field(parsed, field.name) = try self.parseValue(field.type, unwrapped);
}
return parsed;

View File

@ -1312,7 +1312,7 @@ const Writer = struct {
type_len: u32 = 0,
align_len: u32 = 0,
init_len: u32 = 0,
field_type: Zir.Inst.Ref = .none,
type: Zir.Inst.Ref = .none,
name: u32,
is_comptime: bool,
};
@ -1353,7 +1353,7 @@ const Writer = struct {
if (has_type_body) {
fields[field_i].type_len = self.code.extra[extra_index];
} else {
fields[field_i].field_type = @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index]);
fields[field_i].type = @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index]);
}
extra_index += 1;
@ -1384,8 +1384,8 @@ const Writer = struct {
} else {
try stream.print("@\"{d}\": ", .{i});
}
if (field.field_type != .none) {
try self.writeInstRef(stream, field.field_type);
if (field.type != .none) {
try self.writeInstRef(stream, field.type);
}
if (field.type_len > 0) {

View File

@ -392,7 +392,7 @@ pub const Node = extern union {
}
pub fn Data(comptime t: Tag) type {
return std.meta.fieldInfo(t.Type(), .data).field_type;
return std.meta.fieldInfo(t.Type(), .data).type;
}
};
@ -845,7 +845,7 @@ const Context = struct {
try c.extra_data.ensureUnusedCapacity(c.gpa, fields.len);
const result = @intCast(u32, c.extra_data.items.len);
inline for (fields) |field| {
comptime std.debug.assert(field.field_type == NodeIndex);
comptime std.debug.assert(field.type == NodeIndex);
c.extra_data.appendAssumeCapacity(@field(extra, field.name));
}
return result;

View File

@ -6216,7 +6216,7 @@ pub const Type = extern union {
}
pub fn Data(comptime t: Tag) type {
return std.meta.fieldInfo(t.Type(), .data).field_type;
return std.meta.fieldInfo(t.Type(), .data).type;
}
};

View File

@ -338,7 +338,7 @@ pub const Value = extern union {
}
pub fn Data(comptime t: Tag) type {
return std.meta.fieldInfo(t.Type(), .data).field_type;
return std.meta.fieldInfo(t.Type(), .data).type;
}
};

View File

@ -358,7 +358,7 @@ test "comptime @bitCast packed struct to int and back" {
const rt_cast = @bitCast(S, i);
const ct_cast = comptime @bitCast(S, @as(Int, 0));
inline for (@typeInfo(S).Struct.fields) |field| {
if (@typeInfo(field.field_type) == .Vector)
if (@typeInfo(field.type) == .Vector)
continue; //TODO: https://github.com/ziglang/zig/issues/13201
try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));

View File

@ -8,7 +8,7 @@ fn NamespacedGlobals(comptime modules: anytype) type {
.fields = &.{
.{
.name = "globals",
.field_type = modules.mach.globals,
.type = modules.mach.globals,
.default_value = null,
.is_comptime = false,
.alignment = @alignOf(modules.mach.globals),

View File

@ -7,7 +7,7 @@ fn NamespacedComponents(comptime modules: anytype) type {
.is_tuple = false,
.fields = &.{.{
.name = "components",
.field_type = @TypeOf(modules.components),
.type = @TypeOf(modules.components),
.default_value = null,
.is_comptime = false,
.alignment = @alignOf(@TypeOf(modules.components)),

View File

@ -8,7 +8,7 @@ fn CreateUnion(comptime T: type) type {
.fields = &[_]std.builtin.Type.UnionField{
.{
.name = "field",
.field_type = T,
.type = T,
.alignment = @alignOf(T),
},
},

View File

@ -23,7 +23,7 @@ test "issue 6456" {
fields = fields ++ &[_]StructField{StructField{
.alignment = 0,
.name = name,
.field_type = usize,
.type = usize,
.default_value = &@as(?usize, null),
.is_comptime = false,
}};

View File

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

View File

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

View File

@ -268,10 +268,10 @@ test "Type.Struct" {
const infoA = @typeInfo(A).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].field_type);
try testing.expectEqual(u8, infoA.fields[0].type);
try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value);
try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
try testing.expectEqual(u32, infoA.fields[1].field_type);
try testing.expectEqual(u32, infoA.fields[1].type);
try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value);
try testing.expectEqualSlices(Type.Declaration, &.{}, infoA.decls);
try testing.expectEqual(@as(bool, false), infoA.is_tuple);
@ -286,10 +286,10 @@ test "Type.Struct" {
const infoB = @typeInfo(B).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].field_type);
try testing.expectEqual(u8, infoB.fields[0].type);
try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value);
try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
try testing.expectEqual(u32, infoB.fields[1].field_type);
try testing.expectEqual(u32, infoB.fields[1].type);
try testing.expectEqual(@as(u32, 5), @ptrCast(*align(1) const u32, infoB.fields[1].default_value.?).*);
try testing.expectEqual(@as(usize, 0), infoB.decls.len);
try testing.expectEqual(@as(bool, false), infoB.is_tuple);
@ -298,10 +298,10 @@ test "Type.Struct" {
const infoC = @typeInfo(C).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].field_type);
try testing.expectEqual(u8, infoC.fields[0].type);
try testing.expectEqual(@as(u8, 3), @ptrCast(*const u8, infoC.fields[0].default_value.?).*);
try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
try testing.expectEqual(u32, infoC.fields[1].field_type);
try testing.expectEqual(u32, infoC.fields[1].type);
try testing.expectEqual(@as(u32, 5), @ptrCast(*align(1) const u32, infoC.fields[1].default_value.?).*);
try testing.expectEqual(@as(usize, 0), infoC.decls.len);
try testing.expectEqual(@as(bool, false), infoC.is_tuple);
@ -311,10 +311,10 @@ test "Type.Struct" {
const infoD = @typeInfo(D).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].field_type);
try testing.expectEqual(comptime_int, infoD.fields[0].type);
try testing.expectEqual(@as(comptime_int, 3), @ptrCast(*const comptime_int, infoD.fields[0].default_value.?).*);
try testing.expectEqualSlices(u8, "y", infoD.fields[1].name);
try testing.expectEqual(comptime_int, infoD.fields[1].field_type);
try testing.expectEqual(comptime_int, infoD.fields[1].type);
try testing.expectEqual(@as(comptime_int, 5), @ptrCast(*const comptime_int, infoD.fields[1].default_value.?).*);
try testing.expectEqual(@as(usize, 0), infoD.decls.len);
try testing.expectEqual(@as(bool, false), infoD.is_tuple);
@ -324,10 +324,10 @@ test "Type.Struct" {
const infoE = @typeInfo(E).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].field_type);
try testing.expectEqual(comptime_int, infoE.fields[0].type);
try testing.expectEqual(@as(comptime_int, 1), @ptrCast(*const comptime_int, infoE.fields[0].default_value.?).*);
try testing.expectEqualSlices(u8, "1", infoE.fields[1].name);
try testing.expectEqual(comptime_int, infoE.fields[1].field_type);
try testing.expectEqual(comptime_int, infoE.fields[1].type);
try testing.expectEqual(@as(comptime_int, 2), @ptrCast(*const comptime_int, infoE.fields[1].default_value.?).*);
try testing.expectEqual(@as(usize, 0), infoE.decls.len);
try testing.expectEqual(@as(bool, true), infoE.is_tuple);
@ -396,8 +396,8 @@ test "Type.Union" {
.layout = .Extern,
.tag_type = null,
.fields = &.{
.{ .name = "int", .field_type = i32, .alignment = @alignOf(f32) },
.{ .name = "float", .field_type = f32, .alignment = @alignOf(f32) },
.{ .name = "int", .type = i32, .alignment = @alignOf(f32) },
.{ .name = "float", .type = f32, .alignment = @alignOf(f32) },
},
.decls = &.{},
},
@ -412,8 +412,8 @@ test "Type.Union" {
.layout = .Packed,
.tag_type = null,
.fields = &.{
.{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
.{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
.{ .name = "signed", .type = i32, .alignment = @alignOf(i32) },
.{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) },
},
.decls = &.{},
},
@ -439,8 +439,8 @@ test "Type.Union" {
.layout = .Auto,
.tag_type = Tag,
.fields = &.{
.{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
.{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
.{ .name = "signed", .type = i32, .alignment = @alignOf(i32) },
.{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) },
},
.decls = &.{},
},
@ -470,7 +470,7 @@ test "Type.Union from Type.Enum" {
.layout = .Auto,
.tag_type = Tag,
.fields = &.{
.{ .name = "working_as_expected", .field_type = u32, .alignment = @alignOf(u32) },
.{ .name = "working_as_expected", .type = u32, .alignment = @alignOf(u32) },
},
.decls = &.{},
},
@ -487,7 +487,7 @@ test "Type.Union from regular enum" {
.layout = .Auto,
.tag_type = E,
.fields = &.{
.{ .name = "working_as_expected", .field_type = u32, .alignment = @alignOf(u32) },
.{ .name = "working_as_expected", .type = u32, .alignment = @alignOf(u32) },
},
.decls = &.{},
},
@ -537,7 +537,7 @@ test "reified struct field name from optional payload" {
.layout = .Auto,
.fields = &.{.{
.name = name,
.field_type = u8,
.type = u8,
.default_value = null,
.is_comptime = false,
.alignment = 1,

View File

@ -257,7 +257,7 @@ fn testUnion() !void {
try expect(typeinfo_info.Union.layout == .Auto);
try expect(typeinfo_info.Union.tag_type.? == TypeId);
try expect(typeinfo_info.Union.fields.len == 24);
try expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));
try expect(typeinfo_info.Union.fields[4].type == @TypeOf(@typeInfo(u8).Int));
try expect(typeinfo_info.Union.decls.len == 22);
const TestNoTagUnion = union {
@ -271,7 +271,7 @@ fn testUnion() !void {
try expect(notag_union_info.Union.layout == .Auto);
try expect(notag_union_info.Union.fields.len == 2);
try expect(notag_union_info.Union.fields[0].alignment == @alignOf(void));
try expect(notag_union_info.Union.fields[1].field_type == u32);
try expect(notag_union_info.Union.fields[1].type == u32);
try expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32));
const TestExternUnion = extern union {
@ -281,7 +281,7 @@ fn testUnion() !void {
const extern_union_info = @typeInfo(TestExternUnion);
try expect(extern_union_info.Union.layout == .Extern);
try expect(extern_union_info.Union.tag_type == null);
try expect(extern_union_info.Union.fields[0].field_type == *anyopaque);
try expect(extern_union_info.Union.fields[0].type == *anyopaque);
}
test "type info: struct info" {
@ -319,7 +319,7 @@ fn testPackedStruct() !void {
try expect(struct_info.Struct.backing_integer == u128);
try expect(struct_info.Struct.fields.len == 4);
try expect(struct_info.Struct.fields[0].alignment == 0);
try expect(struct_info.Struct.fields[2].field_type == f32);
try expect(struct_info.Struct.fields[2].type == f32);
try expect(struct_info.Struct.fields[2].default_value == null);
try expect(@ptrCast(*align(1) const u32, struct_info.Struct.fields[3].default_value.?).* == 4);
try expect(struct_info.Struct.fields[3].alignment == 0);

View File

@ -454,7 +454,7 @@ test "global union with single field is correctly initialized" {
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
glbl = Foo1{
.f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 },
.f = @typeInfo(Foo1).Union.fields[0].type{ .x = 123 },
};
try expect(glbl.f.x == 123);
}

View File

@ -9,7 +9,7 @@ pub export fn entry() void {
const info = @typeInfo(Widget).Union;
inline for (info.fields) |field| {
if (foo()) {
switch (field.field_type) {
switch (field.type) {
u0 => a = 2,
else => unreachable,
}

View File

@ -16,7 +16,7 @@ fn parseFree(comptime T: type, value: T, allocator: std.mem.Allocator) void {
.Struct => |structInfo| {
inline for (structInfo.fields) |field| {
if (!field.is_comptime)
parseFree(field.field_type, undefined, allocator);
parseFree(field.type, undefined, allocator);
}
},
.Pointer => |ptrInfo| {

View File

@ -1,6 +1,6 @@
export fn entry() void {
_ = @Type(.{ .Struct = .{ .layout = .Packed, .fields = &.{
.{ .name = "one", .field_type = u4, .default_value = null, .is_comptime = false, .alignment = 2 },
.{ .name = "one", .type = u4, .default_value = null, .is_comptime = false, .alignment = 2 },
}, .decls = &.{}, .is_tuple = false } });
}

View File

@ -3,7 +3,7 @@ comptime {
.layout = .Auto,
.fields = &.{.{
.name = "foo",
.field_type = u32,
.type = u32,
.default_value = null,
.is_comptime = false,
.alignment = 4,
@ -17,7 +17,7 @@ comptime {
.layout = .Auto,
.fields = &.{.{
.name = "3",
.field_type = u32,
.type = u32,
.default_value = null,
.is_comptime = false,
.alignment = 4,
@ -31,7 +31,7 @@ comptime {
.layout = .Auto,
.fields = &.{.{
.name = "0",
.field_type = u32,
.type = u32,
.default_value = null,
.is_comptime = true,
.alignment = 4,
@ -45,7 +45,7 @@ comptime {
.layout = .Extern,
.fields = &.{.{
.name = "0",
.field_type = u32,
.type = u32,
.default_value = null,
.is_comptime = true,
.alignment = 4,
@ -59,7 +59,7 @@ comptime {
.layout = .Packed,
.fields = &.{.{
.name = "0",
.field_type = u32,
.type = u32,
.default_value = null,
.is_comptime = true,
.alignment = 4,

View File

@ -16,8 +16,8 @@ const Tagged = @Type(.{
.layout = .Auto,
.tag_type = Tag,
.fields = &.{
.{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
.{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
.{ .name = "signed", .type = i32, .alignment = @alignOf(i32) },
.{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) },
},
.decls = &.{},
},

View File

@ -15,9 +15,9 @@ const Tagged = @Type(.{
.layout = .Auto,
.tag_type = Tag,
.fields = &.{
.{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
.{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
.{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) },
.{ .name = "signed", .type = i32, .alignment = @alignOf(i32) },
.{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) },
.{ .name = "arst", .type = f32, .alignment = @alignOf(f32) },
},
.decls = &.{},
},

View File

@ -3,7 +3,7 @@ const Untagged = @Type(.{
.layout = .Auto,
.tag_type = null,
.fields = &.{
.{ .name = "foo", .field_type = opaque {}, .alignment = 1 },
.{ .name = "foo", .type = opaque {}, .alignment = 1 },
},
.decls = &.{},
},
@ -17,4 +17,4 @@ export fn entry() usize {
// target=native
//
// :1:18: error: opaque types have unknown size and therefore cannot be directly embedded in unions
// :6:45: note: opaque declared here
// :6:39: note: opaque declared here