std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
This commit is contained in:
@@ -64,33 +64,33 @@ pub inline fn expectEqual(expected: anytype, actual: anytype) !void {
|
||||
|
||||
fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
|
||||
switch (@typeInfo(@TypeOf(actual))) {
|
||||
.NoReturn,
|
||||
.Opaque,
|
||||
.Frame,
|
||||
.AnyFrame,
|
||||
.noreturn,
|
||||
.@"opaque",
|
||||
.frame,
|
||||
.@"anyframe",
|
||||
=> @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"),
|
||||
|
||||
.Undefined,
|
||||
.Null,
|
||||
.Void,
|
||||
.undefined,
|
||||
.null,
|
||||
.void,
|
||||
=> return,
|
||||
|
||||
.Type => {
|
||||
.type => {
|
||||
if (actual != expected) {
|
||||
print("expected type {s}, found type {s}\n", .{ @typeName(expected), @typeName(actual) });
|
||||
return error.TestExpectedEqual;
|
||||
}
|
||||
},
|
||||
|
||||
.Bool,
|
||||
.Int,
|
||||
.Float,
|
||||
.ComptimeFloat,
|
||||
.ComptimeInt,
|
||||
.EnumLiteral,
|
||||
.Enum,
|
||||
.Fn,
|
||||
.ErrorSet,
|
||||
.bool,
|
||||
.int,
|
||||
.float,
|
||||
.comptime_float,
|
||||
.comptime_int,
|
||||
.enum_literal,
|
||||
.@"enum",
|
||||
.@"fn",
|
||||
.error_set,
|
||||
=> {
|
||||
if (actual != expected) {
|
||||
print("expected {}, found {}\n", .{ expected, actual });
|
||||
@@ -98,7 +98,7 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
|
||||
}
|
||||
},
|
||||
|
||||
.Pointer => |pointer| {
|
||||
.pointer => |pointer| {
|
||||
switch (pointer.size) {
|
||||
.One, .Many, .C => {
|
||||
if (actual != expected) {
|
||||
@@ -119,9 +119,9 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
|
||||
}
|
||||
},
|
||||
|
||||
.Array => |array| try expectEqualSlices(array.child, &expected, &actual),
|
||||
.array => |array| try expectEqualSlices(array.child, &expected, &actual),
|
||||
|
||||
.Vector => |info| {
|
||||
.vector => |info| {
|
||||
var i: usize = 0;
|
||||
while (i < info.len) : (i += 1) {
|
||||
if (!std.meta.eql(expected[i], actual[i])) {
|
||||
@@ -133,13 +133,13 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
|
||||
}
|
||||
},
|
||||
|
||||
.Struct => |structType| {
|
||||
.@"struct" => |structType| {
|
||||
inline for (structType.fields) |field| {
|
||||
try expectEqual(@field(expected, field.name), @field(actual, field.name));
|
||||
}
|
||||
},
|
||||
|
||||
.Union => |union_info| {
|
||||
.@"union" => |union_info| {
|
||||
if (union_info.tag_type == null) {
|
||||
@compileError("Unable to compare untagged union values");
|
||||
}
|
||||
@@ -157,7 +157,7 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
|
||||
}
|
||||
},
|
||||
|
||||
.Optional => {
|
||||
.optional => {
|
||||
if (expected) |expected_payload| {
|
||||
if (actual) |actual_payload| {
|
||||
try expectEqual(expected_payload, actual_payload);
|
||||
@@ -173,7 +173,7 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
|
||||
}
|
||||
},
|
||||
|
||||
.ErrorUnion => {
|
||||
.error_union => {
|
||||
if (expected) |expected_payload| {
|
||||
if (actual) |actual_payload| {
|
||||
try expectEqual(expected_payload, actual_payload);
|
||||
@@ -237,12 +237,12 @@ pub inline fn expectApproxEqAbs(expected: anytype, actual: anytype, tolerance: a
|
||||
|
||||
fn expectApproxEqAbsInner(comptime T: type, expected: T, actual: T, tolerance: T) !void {
|
||||
switch (@typeInfo(T)) {
|
||||
.Float => if (!math.approxEqAbs(T, expected, actual, tolerance)) {
|
||||
.float => if (!math.approxEqAbs(T, expected, actual, tolerance)) {
|
||||
print("actual {}, not within absolute tolerance {} of expected {}\n", .{ actual, tolerance, expected });
|
||||
return error.TestExpectedApproxEqAbs;
|
||||
},
|
||||
|
||||
.ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),
|
||||
.comptime_float => @compileError("Cannot approximately compare two comptime_float values"),
|
||||
|
||||
else => @compileError("Unable to compare non floating point values"),
|
||||
}
|
||||
@@ -273,12 +273,12 @@ pub inline fn expectApproxEqRel(expected: anytype, actual: anytype, tolerance: a
|
||||
|
||||
fn expectApproxEqRelInner(comptime T: type, expected: T, actual: T, tolerance: T) !void {
|
||||
switch (@typeInfo(T)) {
|
||||
.Float => if (!math.approxEqRel(T, expected, actual, tolerance)) {
|
||||
.float => if (!math.approxEqRel(T, expected, actual, tolerance)) {
|
||||
print("actual {}, not within relative tolerance {} of expected {}\n", .{ actual, tolerance, expected });
|
||||
return error.TestExpectedApproxEqRel;
|
||||
},
|
||||
|
||||
.ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),
|
||||
.comptime_float => @compileError("Cannot approximately compare two comptime_float values"),
|
||||
|
||||
else => @compileError("Unable to compare non floating point values"),
|
||||
}
|
||||
@@ -415,7 +415,7 @@ fn SliceDiffer(comptime T: type) type {
|
||||
const full_index = self.start_index + i;
|
||||
const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true;
|
||||
if (diff) try self.ttyconf.setColor(writer, .red);
|
||||
if (@typeInfo(T) == .Pointer) {
|
||||
if (@typeInfo(T) == .pointer) {
|
||||
try writer.print("[{}]{*}: {any}\n", .{ full_index, value, value });
|
||||
} else {
|
||||
try writer.print("[{}]: {any}\n", .{ full_index, value });
|
||||
@@ -505,10 +505,10 @@ pub fn expectEqualSentinel(comptime T: type, comptime sentinel: T, expected: [:s
|
||||
|
||||
const expected_value_sentinel = blk: {
|
||||
switch (@typeInfo(@TypeOf(expected))) {
|
||||
.Pointer => {
|
||||
.pointer => {
|
||||
break :blk expected[expected.len];
|
||||
},
|
||||
.Array => |array_info| {
|
||||
.array => |array_info| {
|
||||
const indexable_outside_of_bounds = @as([]const array_info.child, &expected);
|
||||
break :blk indexable_outside_of_bounds[indexable_outside_of_bounds.len];
|
||||
},
|
||||
@@ -518,10 +518,10 @@ pub fn expectEqualSentinel(comptime T: type, comptime sentinel: T, expected: [:s
|
||||
|
||||
const actual_value_sentinel = blk: {
|
||||
switch (@typeInfo(@TypeOf(actual))) {
|
||||
.Pointer => {
|
||||
.pointer => {
|
||||
break :blk actual[actual.len];
|
||||
},
|
||||
.Array => |array_info| {
|
||||
.array => |array_info| {
|
||||
const indexable_outside_of_bounds = @as([]const array_info.child, &actual);
|
||||
break :blk indexable_outside_of_bounds[indexable_outside_of_bounds.len];
|
||||
},
|
||||
@@ -689,33 +689,33 @@ pub inline fn expectEqualDeep(expected: anytype, actual: anytype) error{TestExpe
|
||||
|
||||
fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpectedEqual}!void {
|
||||
switch (@typeInfo(@TypeOf(actual))) {
|
||||
.NoReturn,
|
||||
.Opaque,
|
||||
.Frame,
|
||||
.AnyFrame,
|
||||
.noreturn,
|
||||
.@"opaque",
|
||||
.frame,
|
||||
.@"anyframe",
|
||||
=> @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"),
|
||||
|
||||
.Undefined,
|
||||
.Null,
|
||||
.Void,
|
||||
.undefined,
|
||||
.null,
|
||||
.void,
|
||||
=> return,
|
||||
|
||||
.Type => {
|
||||
.type => {
|
||||
if (actual != expected) {
|
||||
print("expected type {s}, found type {s}\n", .{ @typeName(expected), @typeName(actual) });
|
||||
return error.TestExpectedEqual;
|
||||
}
|
||||
},
|
||||
|
||||
.Bool,
|
||||
.Int,
|
||||
.Float,
|
||||
.ComptimeFloat,
|
||||
.ComptimeInt,
|
||||
.EnumLiteral,
|
||||
.Enum,
|
||||
.Fn,
|
||||
.ErrorSet,
|
||||
.bool,
|
||||
.int,
|
||||
.float,
|
||||
.comptime_float,
|
||||
.comptime_int,
|
||||
.enum_literal,
|
||||
.@"enum",
|
||||
.@"fn",
|
||||
.error_set,
|
||||
=> {
|
||||
if (actual != expected) {
|
||||
print("expected {}, found {}\n", .{ expected, actual });
|
||||
@@ -723,7 +723,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
|
||||
}
|
||||
},
|
||||
|
||||
.Pointer => |pointer| {
|
||||
.pointer => |pointer| {
|
||||
switch (pointer.size) {
|
||||
// We have no idea what is behind those pointers, so the best we can do is `==` check.
|
||||
.C, .Many => {
|
||||
@@ -735,7 +735,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
|
||||
.One => {
|
||||
// Length of those pointers are runtime value, so the best we can do is `==` check.
|
||||
switch (@typeInfo(pointer.child)) {
|
||||
.Fn, .Opaque => {
|
||||
.@"fn", .@"opaque" => {
|
||||
if (actual != expected) {
|
||||
print("expected {*}, found {*}\n", .{ expected, actual });
|
||||
return error.TestExpectedEqual;
|
||||
@@ -762,7 +762,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
|
||||
}
|
||||
},
|
||||
|
||||
.Array => |_| {
|
||||
.array => |_| {
|
||||
if (expected.len != actual.len) {
|
||||
print("Array len not the same, expected {d}, found {d}\n", .{ expected.len, actual.len });
|
||||
return error.TestExpectedEqual;
|
||||
@@ -778,9 +778,9 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
|
||||
}
|
||||
},
|
||||
|
||||
.Vector => |info| {
|
||||
if (info.len != @typeInfo(@TypeOf(actual)).Vector.len) {
|
||||
print("Vector len not the same, expected {d}, found {d}\n", .{ info.len, @typeInfo(@TypeOf(actual)).Vector.len });
|
||||
.vector => |info| {
|
||||
if (info.len != @typeInfo(@TypeOf(actual)).vector.len) {
|
||||
print("Vector len not the same, expected {d}, found {d}\n", .{ info.len, @typeInfo(@TypeOf(actual)).vector.len });
|
||||
return error.TestExpectedEqual;
|
||||
}
|
||||
var i: usize = 0;
|
||||
@@ -794,7 +794,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
|
||||
}
|
||||
},
|
||||
|
||||
.Struct => |structType| {
|
||||
.@"struct" => |structType| {
|
||||
inline for (structType.fields) |field| {
|
||||
expectEqualDeep(@field(expected, field.name), @field(actual, field.name)) catch |e| {
|
||||
print("Field {s} incorrect. expected {any}, found {any}\n", .{ field.name, @field(expected, field.name), @field(actual, field.name) });
|
||||
@@ -803,7 +803,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
|
||||
}
|
||||
},
|
||||
|
||||
.Union => |union_info| {
|
||||
.@"union" => |union_info| {
|
||||
if (union_info.tag_type == null) {
|
||||
@compileError("Unable to compare untagged union values");
|
||||
}
|
||||
@@ -823,7 +823,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
|
||||
}
|
||||
},
|
||||
|
||||
.Optional => {
|
||||
.optional => {
|
||||
if (expected) |expected_payload| {
|
||||
if (actual) |actual_payload| {
|
||||
try expectEqualDeep(expected_payload, actual_payload);
|
||||
@@ -839,7 +839,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
|
||||
}
|
||||
},
|
||||
|
||||
.ErrorUnion => {
|
||||
.error_union => {
|
||||
if (expected) |expected_payload| {
|
||||
if (actual) |actual_payload| {
|
||||
try expectEqualDeep(expected_payload, actual_payload);
|
||||
@@ -1036,20 +1036,20 @@ test {
|
||||
/// }
|
||||
/// ```
|
||||
pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime test_fn: anytype, extra_args: anytype) !void {
|
||||
switch (@typeInfo(@typeInfo(@TypeOf(test_fn)).Fn.return_type.?)) {
|
||||
.ErrorUnion => |info| {
|
||||
switch (@typeInfo(@typeInfo(@TypeOf(test_fn)).@"fn".return_type.?)) {
|
||||
.error_union => |info| {
|
||||
if (info.payload != void) {
|
||||
@compileError("Return type must be !void");
|
||||
}
|
||||
},
|
||||
else => @compileError("Return type must be !void"),
|
||||
}
|
||||
if (@typeInfo(@TypeOf(extra_args)) != .Struct) {
|
||||
if (@typeInfo(@TypeOf(extra_args)) != .@"struct") {
|
||||
@compileError("Expected tuple or struct argument, found " ++ @typeName(@TypeOf(extra_args)));
|
||||
}
|
||||
|
||||
const ArgsTuple = std.meta.ArgsTuple(@TypeOf(test_fn));
|
||||
const fn_args_fields = @typeInfo(ArgsTuple).Struct.fields;
|
||||
const fn_args_fields = @typeInfo(ArgsTuple).@"struct".fields;
|
||||
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");
|
||||
}
|
||||
@@ -1061,7 +1061,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
|
||||
// Setup the tuple that will actually be used with @call (we'll need to insert
|
||||
// the failing allocator in field @"0" before each @call)
|
||||
var args: ArgsTuple = undefined;
|
||||
inline for (@typeInfo(@TypeOf(extra_args)).Struct.fields, 0..) |field, i| {
|
||||
inline for (@typeInfo(@TypeOf(extra_args)).@"struct".fields, 0..) |field, i| {
|
||||
const arg_i_str = comptime str: {
|
||||
var str_buf: [100]u8 = undefined;
|
||||
const args_i = i + 1;
|
||||
@@ -1129,7 +1129,7 @@ pub fn refAllDeclsRecursive(comptime T: type) void {
|
||||
inline for (comptime std.meta.declarations(T)) |decl| {
|
||||
if (@TypeOf(@field(T, decl.name)) == type) {
|
||||
switch (@typeInfo(@field(T, decl.name))) {
|
||||
.Struct, .Enum, .Union, .Opaque => refAllDeclsRecursive(@field(T, decl.name)),
|
||||
.@"struct", .@"enum", .@"union", .@"opaque" => refAllDeclsRecursive(@field(T, decl.name)),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user