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:
mlugg
2024-08-28 02:35:53 +01:00
parent 1a178d4995
commit 0fe3fd01dd
336 changed files with 4105 additions and 4112 deletions

View File

@@ -23,8 +23,8 @@ pub export fn entry4() void {
// backend=stage2
// target=x86_64-linux
//
// :4:25: error: expected error set or error union type, found 'ComptimeInt'
// :8:20: error: expected error set or error union type, found 'Int'
// :4:25: error: expected error set or error union type, found 'comptime_int'
// :8:20: error: expected error set or error union type, found 'int'
// :13:25: error: cannot cast an error union type to error set
// :18:29: error: payload types of error unions must match
// :18:29: note: destination payload is 'f32'

View File

@@ -1,6 +1,6 @@
const A = B;
test "Crash" {
_ = @typeInfo(@This()).Struct.decls[0];
_ = @typeInfo(@This()).@"struct".decls[0];
}
// error

View File

@@ -11,4 +11,4 @@ export fn entry() usize {
// backend=llvm
// target=native
//
// :4:29: error: invalid operands to binary expression: 'Struct' and 'Struct'
// :4:29: error: invalid operands to binary expression: 'struct' and 'struct'

View File

@@ -8,5 +8,5 @@ fn my_func(comptime T: type) !T {}
// error
//
// :2:9: error: expected type 'type', found 'fn (comptime type) @typeInfo(@typeInfo(@TypeOf(tmp.my_func)).Fn.return_type.?).ErrorUnion.error_set!anytype'
// :5:9: error: expected type 'type', found 'fn (comptime type) @typeInfo(@typeInfo(@TypeOf(tmp.my_func)).Fn.return_type.?).ErrorUnion.error_set!anytype'
// :2:9: error: expected type 'type', found 'fn (comptime type) @typeInfo(@typeInfo(@TypeOf(tmp.my_func)).@"fn".return_type.?).error_union.error_set!anytype'
// :5:9: error: expected type 'type', found 'fn (comptime type) @typeInfo(@typeInfo(@TypeOf(tmp.my_func)).@"fn".return_type.?).error_union.error_set!anytype'

View File

@@ -1,6 +1,6 @@
const builtin = @import("std").builtin;
comptime {
_ = @Type(.{ .Float = .{ .bits = 17 } });
_ = @Type(.{ .float = .{ .bits = 17 } });
}
// error

View File

@@ -9,4 +9,4 @@ export fn entry() void {
// backend=stage2
// target=native
//
// :2:18: error: invalid operands to binary bitwise expression: 'ErrorSet' and 'ErrorSet'
// :2:18: error: invalid operands to binary bitwise expression: 'error_set' and 'error_set'

View File

@@ -6,7 +6,7 @@ pub export fn entry() void {
const Widget = union(enum) { a: u0 };
comptime var a = 1;
const info = @typeInfo(Widget).Union;
const info = @typeInfo(Widget).@"union";
inline for (info.fields) |field| {
if (foo()) {
switch (field.type) {

View File

@@ -13,13 +13,13 @@ fn parse(comptime T: type, allocator: std.mem.Allocator) !void {
fn parseFree(comptime T: type, value: T, allocator: std.mem.Allocator) void {
switch (@typeInfo(T)) {
.Struct => |structInfo| {
.@"struct" => |structInfo| {
inline for (structInfo.fields) |field| {
if (!field.is_comptime)
parseFree(field.type, undefined, allocator);
}
},
.Pointer => |ptrInfo| {
.pointer => |ptrInfo| {
switch (ptrInfo.size) {
.One => {
parseFree(ptrInfo.child, value.*, allocator);

View File

@@ -27,5 +27,5 @@ pub fn main() Error!void {
// backend=llvm
// target=native
//
// :23:29: error: expected type 'error{InvalidCharacter}', found '@typeInfo(@typeInfo(@TypeOf(tmp.fooey)).Fn.return_type.?).ErrorUnion.error_set'
// :23:29: error: expected type 'error{InvalidCharacter}', found '@typeInfo(@typeInfo(@TypeOf(tmp.fooey)).@"fn".return_type.?).error_union.error_set'
// :23:29: note: 'error.InvalidDirection' not a member of destination error set

View File

@@ -10,6 +10,6 @@ export fn a() void {
// backend=stage2
// target=native
//
// :6:11: error: type '@typeInfo(@typeInfo(@TypeOf(tmp.b)).Fn.return_type.?).ErrorUnion.error_set!u32' is not indexable and not a range
// :6:11: error: type '@typeInfo(@typeInfo(@TypeOf(tmp.b)).@"fn".return_type.?).error_union.error_set!u32' is not indexable and not a range
// :6:11: note: for loop operand must be a range, array, slice, tuple, or vector
// :6:11: note: consider using 'try', 'catch', or 'if'

View File

@@ -5,7 +5,7 @@ pub export fn entry() void {
_ = sliceAsBytes(ohnoes);
_ = &ohnoes;
}
fn sliceAsBytes(slice: anytype) isPtrTo(.Array)(@TypeOf(slice)) {}
fn sliceAsBytes(slice: anytype) isPtrTo(.array)(@TypeOf(slice)) {}
pub const TraitFn = fn (type) bool;
@@ -20,8 +20,8 @@ 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;
if (comptime is(.pointer)(T)) {
return @typeInfo(T).pointer.size == .One;
}
return false;
}

View File

@@ -21,12 +21,12 @@ export fn quux() u32 {
//
// :2:18: error: expected type 'u32', found 'error{Ohno}'
// :1:17: note: function cannot return an error
// :8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(tmp.bar)).Fn.return_type.?).ErrorUnion.error_set'
// :8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(tmp.bar)).@"fn".return_type.?).error_union.error_set'
// :7:17: note: function cannot return an error
// :11:15: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(tmp.bar)).Fn.return_type.?).ErrorUnion.error_set!u32'
// :11:15: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(tmp.bar)).@"fn".return_type.?).error_union.error_set!u32'
// :11:15: note: cannot convert error union to payload type
// :11:15: note: consider using 'try', 'catch', or 'if'
// :10:17: note: function cannot return an error
// :15:14: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(tmp.bar)).Fn.return_type.?).ErrorUnion.error_set!u32'
// :15:14: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(tmp.bar)).@"fn".return_type.?).error_union.error_set!u32'
// :15:14: note: cannot convert error union to payload type
// :15:14: note: consider using 'try', 'catch', or 'if'

View File

@@ -45,7 +45,7 @@ comptime {
// :2:11: note: pointer-integer arithmetic only supports addition and subtraction
// :6:11: error: invalid pointer-pointer arithmetic operator
// :6:11: note: pointer-pointer arithmetic only supports subtraction
// :12:11: error: invalid operands to binary expression: 'Pointer' and 'Pointer'
// :12:11: error: invalid operands to binary expression: 'pointer' and 'pointer'
// :20:11: error: incompatible pointer arithmetic operands '[*]u8' and '[*]u16'
// :26:11: error: incompatible pointer arithmetic operands '*u8' and '*u16'
// :31:11: error: pointer arithmetic requires element type 'u0' to have runtime bits

View File

@@ -1,5 +1,5 @@
export fn entry() void {
_ = @Type(.{ .Pointer = .{
_ = @Type(.{ .pointer = .{
.size = .One,
.is_const = false,
.is_volatile = false,

View File

@@ -6,7 +6,7 @@ pub const DwarfSection = enum {
};
pub fn main() void {
const section = inline for (@typeInfo(DwarfSection).Enum.fields) |section| {
const section = inline for (@typeInfo(DwarfSection).@"enum".fields) |section| {
if (std.mem.eql(u8, section.name, "eh_frame")) break section;
};

View File

@@ -7,7 +7,7 @@ export fn foo() void {
wrong_type: []u8 = "foo",
};
comptime ignore(@typeInfo(MyStruct).Struct.fields[0]);
comptime ignore(@typeInfo(MyStruct).@"struct".fields[0]);
}
// error

View File

@@ -17,5 +17,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
// :13:6: error: no field or member function named 'a' in '@typeInfo(@typeInfo(@TypeOf(tmp.X.init)).Fn.return_type.?).ErrorUnion.error_set!tmp.X'
// :13:6: error: no field or member function named 'a' in '@typeInfo(@typeInfo(@TypeOf(tmp.X.init)).@"fn".return_type.?).error_union.error_set!tmp.X'
// :13:6: note: consider using 'try', 'catch', or 'if'

View File

@@ -1,6 +1,6 @@
export fn entry() void {
const V1 = @Vector(4, u8);
const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });
const V2 = @Type(.{ .vector = .{ .len = 4, .child = V1 } });
const v: V2 = undefined;
_ = v;
}

View File

@@ -2,7 +2,7 @@ const Foo = union(u32) {
A: i32,
};
export fn entry() void {
const x = @typeInfo(Foo).Union.tag_type.?;
const x = @typeInfo(Foo).@"union".tag_type.?;
_ = x;
}

View File

@@ -2,7 +2,7 @@ const Foo = union(enum(f32)) {
A: i32,
};
export fn entry() void {
const x = @typeInfo(Foo).Union.tag_type.?;
const x = @typeInfo(Foo).@"union".tag_type.?;
_ = x;
}

View File

@@ -16,5 +16,5 @@ const ExpectedVarDeclOrFn = struct {};
// backend=stage2
// target=native
//
// :4:9: error: expected type '@typeInfo(tmp.Error).Union.tag_type.?', found 'type'
// :4:9: error: expected type '@typeInfo(tmp.Error).@"union".tag_type.?', found 'type'
// :8:15: note: enum declared here

View File

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

View File

@@ -16,5 +16,5 @@ fn foo(x: i32) !void {
// backend=llvm
// target=native
//
// :2:34: error: ranges not allowed when switching on type '@typeInfo(@typeInfo(@TypeOf(tmp.foo)).Fn.return_type.?).ErrorUnion.error_set'
// :2:34: error: ranges not allowed when switching on type '@typeInfo(@typeInfo(@TypeOf(tmp.foo)).@"fn".return_type.?).error_union.error_set'
// :3:18: note: range here

View File

@@ -18,6 +18,6 @@ export fn entry() void {
// backend=stage2
// target=native
//
// :12:15: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(tmp.get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'
// :12:15: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(tmp.get_uval)).@"fn".return_type.?).error_union.error_set!u32'
// :12:15: note: cannot convert error union to payload type
// :12:15: note: consider using 'try', 'catch', or 'if'

View File

@@ -1,5 +1,5 @@
comptime {
const E = @Type(.{ .Enum = .{
const E = @Type(.{ .@"enum" = .{
.tag_type = u1,
.fields = &.{
.{ .name = "f0", .value = 0 },

View File

@@ -1,6 +1,6 @@
export fn entry() void {
_ = @Type(.{
.Enum = .{
.@"enum" = .{
.tag_type = u32,
.fields = &.{
.{ .name = "A", .value = 0 },

View File

@@ -1,6 +1,6 @@
export fn entry() void {
_ = @Type(.{
.Enum = .{
.@"enum" = .{
.tag_type = u32,
.fields = &.{
.{ .name = "A", .value = 10 },

View File

@@ -1,5 +1,5 @@
comptime {
@Type(.{ .Struct = .{
@Type(.{ .@"struct" = .{
.layout = .auto,
.fields = &.{.{
.name = "foo",
@@ -13,7 +13,7 @@ comptime {
} });
}
comptime {
@Type(.{ .Struct = .{
@Type(.{ .@"struct" = .{
.layout = .auto,
.fields = &.{.{
.name = "3",
@@ -27,7 +27,7 @@ comptime {
} });
}
comptime {
@Type(.{ .Struct = .{
@Type(.{ .@"struct" = .{
.layout = .auto,
.fields = &.{.{
.name = "0",
@@ -41,7 +41,7 @@ comptime {
} });
}
comptime {
@Type(.{ .Struct = .{
@Type(.{ .@"struct" = .{
.layout = .@"extern",
.fields = &.{.{
.name = "0",
@@ -55,7 +55,7 @@ comptime {
} });
}
comptime {
@Type(.{ .Struct = .{
@Type(.{ .@"struct" = .{
.layout = .@"packed",
.fields = &.{.{
.name = "0",

View File

@@ -1,5 +1,5 @@
const Foo = @Type(.{
.Fn = .{
.@"fn" = .{
.calling_convention = .Unspecified,
.is_generic = true,
.is_var_args = false,

View File

@@ -1,5 +1,5 @@
const Foo = @Type(.{
.Fn = .{
.@"fn" = .{
.calling_convention = .Unspecified,
.is_generic = false,
.is_var_args = true,

View File

@@ -1,5 +1,5 @@
const Foo = @Type(.{
.Fn = .{
.@"fn" = .{
.calling_convention = .Unspecified,
.is_generic = false,
.is_var_args = false,

View File

@@ -1,5 +1,5 @@
const Tag = @Type(.{
.Enum = .{
.@"enum" = .{
.tag_type = bool,
.fields = &.{},
.decls = &.{},

View File

@@ -1,5 +1,5 @@
const Tag = @Type(.{
.Enum = .{
.@"enum" = .{
.tag_type = undefined,
.fields = &.{},
.decls = &.{},

View File

@@ -1,5 +1,5 @@
const Tag = @Type(.{
.Enum = .{
.@"enum" = .{
.tag_type = u2,
.fields = &.{
.{ .name = "signed", .value = 0 },
@@ -11,7 +11,7 @@ const Tag = @Type(.{
},
});
const Tagged = @Type(.{
.Union = .{
.@"union" = .{
.layout = .auto,
.tag_type = Tag,
.fields = &.{

View File

@@ -1,5 +1,5 @@
const Tag = @Type(.{
.Enum = .{
.@"enum" = .{
.tag_type = u1,
.fields = &.{
.{ .name = "signed", .value = 0 },
@@ -10,7 +10,7 @@ const Tag = @Type(.{
},
});
const Tagged = @Type(.{
.Union = .{
.@"union" = .{
.layout = .auto,
.tag_type = Tag,
.fields = &.{

View File

@@ -1,5 +1,5 @@
const Tag = @Type(.{
.Enum = .{
.@"enum" = .{
.tag_type = u0,
.fields = &.{},
.decls = &.{},
@@ -7,7 +7,7 @@ const Tag = @Type(.{
},
});
const Tagged = @Type(.{
.Union = .{
.@"union" = .{
.layout = .auto,
.tag_type = Tag,
.fields = &.{

View File

@@ -1,5 +1,5 @@
const Tag = @Type(.{
.Enum = .{
.@"enum" = .{
.tag_type = u1,
.fields = &.{
.{ .name = "signed", .value = 0 },
@@ -10,7 +10,7 @@ const Tag = @Type(.{
},
});
const Tagged = @Type(.{
.Union = .{
.@"union" = .{
.layout = .auto,
.tag_type = Tag,
.fields = &.{},

View File

@@ -1,5 +1,5 @@
const Untagged = @Type(.{
.Union = .{
.@"union" = .{
.layout = .auto,
.tag_type = null,
.fields = &.{

View File

@@ -1,5 +1,5 @@
const Foo = @Type(.{
.Struct = undefined,
.@"struct" = undefined,
});
comptime {
_ = Foo;

View File

@@ -1,6 +1,6 @@
comptime {
_ = @Type(.{
.Union = .{
.@"union" = .{
.layout = .auto,
.tag_type = null,
.fields = &.{
@@ -12,7 +12,7 @@ comptime {
}
comptime {
_ = @Type(.{
.Struct = .{
.@"struct" = .{
.layout = .auto,
.fields = &.{.{
.name = "0",
@@ -28,7 +28,7 @@ comptime {
}
comptime {
_ = @Type(.{
.Pointer = .{
.pointer = .{
.size = .Many,
.is_const = true,
.is_volatile = false,

View File

@@ -1,9 +1,9 @@
comptime {
_ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } });
_ = @Type(.{ .array = .{ .len = 0, .child = u8, .sentinel = undefined } });
}
comptime {
_ = @Type(.{
.Struct = .{
.@"struct" = .{
.fields = undefined,
.decls = undefined,
.is_tuple = false,
@@ -15,7 +15,7 @@ comptime {
const std = @import("std");
const fields: [1]std.builtin.Type.StructField = undefined;
_ = @Type(.{
.Struct = .{
.@"struct" = .{
.layout = .auto,
.fields = &fields,
.decls = &.{},

View File

@@ -5,8 +5,8 @@ fn foo(a: anytype) !void {
const Error = error{ A, B };
export fn entry() void {
const info = @typeInfo(@TypeOf(foo));
const ret_type = info.Fn.return_type.?;
const error_set = @typeInfo(ret_type).ErrorUnion.error_set;
const ret_type = info.@"fn".return_type.?;
const error_set = @typeInfo(ret_type).error_union.error_set;
_ = Error || error_set;
}

View File

@@ -6,7 +6,7 @@ fn getIndex() usize {
}
export fn entry() void {
const index = getIndex();
const field = @typeInfo(Struct).Struct.fields[index];
const field = @typeInfo(Struct).@"struct".fields[index];
_ = field;
}
@@ -14,7 +14,7 @@ export fn entry() void {
// backend=stage2
// target=native
//
// :9:51: error: values of type '[]const builtin.Type.StructField' must be comptime-known, but index value is runtime-known
// :9:54: error: values of type '[]const builtin.Type.StructField' must be comptime-known, but index value is runtime-known
// : note: struct requires comptime because of this field
// : note: types are not available at runtime
// : struct requires comptime because of this field

View File

@@ -6,4 +6,4 @@ export fn a() void {
// backend=stage2
// target=native
//
// :2:23: error: invalid operands to binary expression: 'Float' and 'Float'
// :2:23: error: invalid operands to binary expression: 'float' and 'float'

View File

@@ -18,5 +18,5 @@ export fn entry2() void {
// backend=stage2
// target=native
//
// :4:42: error: invalid operands to binary expression: 'ErrorSet' and 'ComptimeInt'
// :12:35: error: invalid operands to binary expression: 'ErrorSet' and 'ComptimeInt'
// :4:42: error: invalid operands to binary expression: 'error_set' and 'comptime_int'
// :12:35: error: invalid operands to binary expression: 'error_set' and 'comptime_int'

View File

@@ -16,7 +16,7 @@ pub export fn entry2() void {
_ = b;
}
const Int = @typeInfo(bar).Struct.backing_integer.?;
const Int = @typeInfo(bar).@"struct".backing_integer.?;
const foo = enum(Int) {
c = @bitCast(bar{

View File

@@ -12,5 +12,5 @@ pub export fn entry() void {
// backend=stage2
// target=native
//
// :8:8: error: no field or member function named 'f' in '@typeInfo(tmp.T).Union.tag_type.?'
// :8:8: error: no field or member function named 'f' in '@typeInfo(tmp.T).@"union".tag_type.?'
// :1:11: note: enum declared here

View File

@@ -23,7 +23,7 @@ pub export fn entry3() void {
a: noreturn,
b: void,
};
var e = @typeInfo(U).Union.tag_type.?.a;
var e = @typeInfo(U).@"union".tag_type.?.a;
var u: U = undefined;
u = (&e).*;
}
@@ -38,6 +38,6 @@ pub export fn entry3() void {
// :19:10: error: cannot initialize 'noreturn' field of union
// :16:9: note: field 'a' declared here
// :15:15: note: union declared here
// :28:13: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field
// :28:13: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).@"union".tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field
// :23:9: note: 'noreturn' field here
// :22:15: note: union declared here