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

@@ -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);
}