authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-01-31 12:37:12+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-01-31 12:37:12+02:00
logfdc875ed0080cd2542a854a8cd6c627b25e9b7a4
tree440a26f4a274b02dd67fc8b307e767b6faec24a9
parent78d2f2b819b4dc90bb112197d376d37e50540493
parent0b5f3c2ef96df02341cdf54f6eefb3cdb88781d8
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #7750 from tadeokondrak/6609-tagtype-tag

Remove @TagType; std.meta.TagType -> std.meta.Tag

31 files changed, 96 insertions(+), 187 deletions(-)

doc/langref.html.in+7-18
...@@ -2909,15 +2909,15 @@ test "enum variant switch" {...@@ -2909,15 +2909,15 @@ test "enum variant switch" {
2909 expect(mem.eql(u8, what_is_it, "this is a number"));2909 expect(mem.eql(u8, what_is_it, "this is a number"));
2910}2910}
29112911
2912// @TagType can be used to access the integer tag type of an enum.2912// @typeInfo can be used to access the integer tag type of an enum.
2913const Small = enum {2913const Small = enum {
2914 one,2914 one,
2915 two,2915 two,
2916 three,2916 three,
2917 four,2917 four,
2918};2918};
2919test "@TagType" {2919test "std.meta.Tag" {
2920 expect(@TagType(Small) == u2);2920 expect(@typeInfo(Small).Enum.tag_type == u2);
2921}2921}
29222922
2923// @typeInfo tells us the field count and the fields names:2923// @typeInfo tells us the field count and the fields names:
...@@ -3092,8 +3092,7 @@ test "simple union" {...@@ -3092,8 +3092,7 @@ test "simple union" {
3092 {#header_open|Tagged union#}3092 {#header_open|Tagged union#}
3093 <p>Unions can be declared with an enum tag type.3093 <p>Unions can be declared with an enum tag type.
3094 This turns the union into a <em>tagged</em> union, which makes it eligible3094 This turns the union into a <em>tagged</em> union, which makes it eligible
3095 to use with {#link|switch#} expressions. One can use {#link|@TagType#} to3095 to use with {#link|switch#} expressions.
3096 obtain the enum type from the union type.
3097 Tagged unions coerce to their tag type: {#link|Type Coercion: unions and enums#}.3096 Tagged unions coerce to their tag type: {#link|Type Coercion: unions and enums#}.
3098 </p>3097 </p>
3099 {#code_begin|test#}3098 {#code_begin|test#}
...@@ -3119,8 +3118,8 @@ test "switch on tagged union" {...@@ -3119,8 +3118,8 @@ test "switch on tagged union" {
3119 }3118 }
3120}3119}
31213120
3122test "@TagType" {3121test "get tag type" {
3123 expect(@TagType(ComplexType) == ComplexTypeTag);3122 expect(std.meta.Tag(ComplexType) == ComplexTypeTag);
3124}3123}
31253124
3126test "coerce to enum" {3125test "coerce to enum" {
...@@ -7740,7 +7739,7 @@ test "@hasDecl" {...@@ -7740,7 +7739,7 @@ test "@hasDecl" {
7740 {#header_close#}7739 {#header_close#}
77417740
7742 {#header_open|@intToEnum#}7741 {#header_open|@intToEnum#}
7743 <pre>{#syntax#}@intToEnum(comptime DestType: type, int_value: @TagType(DestType)) DestType{#endsyntax#}</pre>7742 <pre>{#syntax#}@intToEnum(comptime DestType: type, int_value: std.meta.Tag(DestType)) DestType{#endsyntax#}</pre>
7744 <p>7743 <p>
7745 Converts an integer into an {#link|enum#} value.7744 Converts an integer into an {#link|enum#} value.
7746 </p>7745 </p>
...@@ -8435,16 +8434,6 @@ fn doTheTest() void {...@@ -8435,16 +8434,6 @@ fn doTheTest() void {
8435 </p>8434 </p>
8436 {#header_close#}8435 {#header_close#}
84378436
8438 {#header_open|@TagType#}
8439 <pre>{#syntax#}@TagType(T: type) type{#endsyntax#}</pre>
8440 <p>
8441 For an enum, returns the integer type that is used to store the enumeration value.
8442 </p>
8443 <p>
8444 For a union, returns the enum type that is used to store the tag value.
8445 </p>
8446 {#header_close#}
8447
8448 {#header_open|@This#}8437 {#header_open|@This#}
8449 <pre>{#syntax#}@This() type{#endsyntax#}</pre>8438 <pre>{#syntax#}@This() type{#endsyntax#}</pre>
8450 <p>8439 <p>
lib/std/builtin.zig+1-1
...@@ -175,7 +175,7 @@ pub const SourceLocation = struct {...@@ -175,7 +175,7 @@ pub const SourceLocation = struct {
175 column: u32,175 column: u32,
176};176};
177177
178pub const TypeId = @TagType(TypeInfo);178pub const TypeId = std.meta.Tag(TypeInfo);
179179
180/// This data structure is used by the Zig language code generation and180/// This data structure is used by the Zig language code generation and
181/// therefore must be kept in sync with the compiler implementation.181/// therefore must be kept in sync with the compiler implementation.
lib/std/c/ast.zig+1-1
...@@ -110,7 +110,7 @@ pub const Error = union(enum) {...@@ -110,7 +110,7 @@ pub const Error = union(enum) {
110110
111 pub const ExpectedToken = struct {111 pub const ExpectedToken = struct {
112 token: TokenIndex,112 token: TokenIndex,
113 expected_id: @TagType(Token.Id),113 expected_id: std.meta.Tag(Token.Id),
114114
115 pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {115 pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {
116 const found_token = tree.tokens.at(self.token);116 const found_token = tree.tokens.at(self.token);
lib/std/c/parse.zig+3-3
...@@ -26,7 +26,7 @@ pub const Options = struct {...@@ -26,7 +26,7 @@ pub const Options = struct {
26 None,26 None,
2727
28 /// Some warnings are errors28 /// Some warnings are errors
29 Some: []@TagType(ast.Error),29 Some: []std.meta.Tag(ast.Error),
3030
31 /// All warnings are errors31 /// All warnings are errors
32 All,32 All,
...@@ -1363,7 +1363,7 @@ const Parser = struct {...@@ -1363,7 +1363,7 @@ const Parser = struct {
1363 return &node.base;1363 return &node.base;
1364 }1364 }
13651365
1366 fn eatToken(parser: *Parser, id: @TagType(Token.Id)) ?TokenIndex {1366 fn eatToken(parser: *Parser, id: std.meta.Tag(Token.Id)) ?TokenIndex {
1367 while (true) {1367 while (true) {
1368 switch ((parser.it.next() orelse return null).id) {1368 switch ((parser.it.next() orelse return null).id) {
1369 .LineComment, .MultiLineComment, .Nl => continue,1369 .LineComment, .MultiLineComment, .Nl => continue,
...@@ -1377,7 +1377,7 @@ const Parser = struct {...@@ -1377,7 +1377,7 @@ const Parser = struct {
1377 }1377 }
1378 }1378 }
13791379
1380 fn expectToken(parser: *Parser, id: @TagType(Token.Id)) Error!TokenIndex {1380 fn expectToken(parser: *Parser, id: std.meta.Tag(Token.Id)) Error!TokenIndex {
1381 while (true) {1381 while (true) {
1382 switch ((parser.it.next() orelse return error.ParseError).id) {1382 switch ((parser.it.next() orelse return error.ParseError).id) {
1383 .LineComment, .MultiLineComment, .Nl => continue,1383 .LineComment, .MultiLineComment, .Nl => continue,
lib/std/c/tokenizer.zig+2-2
...@@ -131,7 +131,7 @@ pub const Token = struct {...@@ -131,7 +131,7 @@ pub const Token = struct {
131 Keyword_error,131 Keyword_error,
132 Keyword_pragma,132 Keyword_pragma,
133133
134 pub fn symbol(id: @TagType(Id)) []const u8 {134 pub fn symbol(id: std.meta.TagType(Id)) []const u8 {
135 return switch (id) {135 return switch (id) {
136 .Invalid => "Invalid",136 .Invalid => "Invalid",
137 .Eof => "Eof",137 .Eof => "Eof",
...@@ -347,7 +347,7 @@ pub const Token = struct {...@@ -347,7 +347,7 @@ pub const Token = struct {
347pub const Tokenizer = struct {347pub const Tokenizer = struct {
348 buffer: []const u8,348 buffer: []const u8,
349 index: usize = 0,349 index: usize = 0,
350 prev_tok_id: @TagType(Token.Id) = .Invalid,350 prev_tok_id: std.meta.TagType(Token.Id) = .Invalid,
351 pp_directive: bool = false,351 pp_directive: bool = false,
352352
353 pub fn next(self: *Tokenizer) Token {353 pub fn next(self: *Tokenizer) Token {
lib/std/hash/auto_hash.zig+1-1
...@@ -239,7 +239,7 @@ fn testHashDeepRecursive(key: anytype) u64 {...@@ -239,7 +239,7 @@ fn testHashDeepRecursive(key: anytype) u64 {
239239
240test "typeContainsSlice" {240test "typeContainsSlice" {
241 comptime {241 comptime {
242 testing.expect(!typeContainsSlice(@TagType(std.builtin.TypeInfo)));242 testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));
243243
244 testing.expect(typeContainsSlice([]const u8));244 testing.expect(typeContainsSlice([]const u8));
245 testing.expect(!typeContainsSlice(u8));245 testing.expect(!typeContainsSlice(u8));
lib/std/json.zig+5-5
...@@ -246,7 +246,7 @@ pub const StreamingParser = struct {...@@ -246,7 +246,7 @@ pub const StreamingParser = struct {
246 // Only call this function to generate array/object final state.246 // Only call this function to generate array/object final state.
247 pub fn fromInt(x: anytype) State {247 pub fn fromInt(x: anytype) State {
248 debug.assert(x == 0 or x == 1);248 debug.assert(x == 0 or x == 1);
249 const T = @TagType(State);249 const T = std.meta.Tag(State);
250 return @intToEnum(State, @intCast(T, x));250 return @intToEnum(State, @intCast(T, x));
251 }251 }
252 };252 };
...@@ -1138,7 +1138,7 @@ pub const TokenStream = struct {...@@ -1138,7 +1138,7 @@ pub const TokenStream = struct {
1138 }1138 }
1139};1139};
11401140
1141fn checkNext(p: *TokenStream, id: std.meta.TagType(Token)) void {1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) void {
1142 const token = (p.next() catch unreachable).?;1142 const token = (p.next() catch unreachable).?;
1143 debug.assert(std.meta.activeTag(token) == id);1143 debug.assert(std.meta.activeTag(token) == id);
1144}1144}
...@@ -1782,7 +1782,7 @@ test "parseFree descends into tagged union" {...@@ -1782,7 +1782,7 @@ test "parseFree descends into tagged union" {
1782 };1782 };
1783 // use a string with unicode escape so we know result can't be a reference to global constant1783 // use a string with unicode escape so we know result can't be a reference to global constant
1784 const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);1784 const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);
1785 testing.expectEqual(@TagType(T).string, @as(@TagType(T), r));1785 testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
1786 testing.expectEqualSlices(u8, "withąunicode", r.string);1786 testing.expectEqualSlices(u8, "withąunicode", r.string);
1787 testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);1787 testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
1788 parseFree(T, r, options);1788 parseFree(T, r, options);
...@@ -2077,7 +2077,7 @@ pub const Parser = struct {...@@ -2077,7 +2077,7 @@ pub const Parser = struct {
2077 }2077 }
2078 }2078 }
20792079
2080 fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayloadType(Token, Token.String), input: []const u8, i: usize) !Value {2080 fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayload(Token, Token.String), input: []const u8, i: usize) !Value {
2081 const slice = s.slice(input, i);2081 const slice = s.slice(input, i);
2082 switch (s.escapes) {2082 switch (s.escapes) {
2083 .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice },2083 .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice },
...@@ -2090,7 +2090,7 @@ pub const Parser = struct {...@@ -2090,7 +2090,7 @@ pub const Parser = struct {
2090 }2090 }
2091 }2091 }
20922092
2093 fn parseNumber(p: *Parser, n: std.meta.TagPayloadType(Token, Token.Number), input: []const u8, i: usize) !Value {2093 fn parseNumber(p: *Parser, n: std.meta.TagPayload(Token, Token.Number), input: []const u8, i: usize) !Value {
2094 return if (n.is_integer)2094 return if (n.is_integer)
2095 Value{ .Integer = try std.fmt.parseInt(i64, n.slice(input, i), 10) }2095 Value{ .Integer = try std.fmt.parseInt(i64, n.slice(input, i), 10) }
2096 else2096 else
lib/std/meta.zig+21-16
...@@ -600,15 +600,18 @@ test "std.meta.FieldEnum" {...@@ -600,15 +600,18 @@ test "std.meta.FieldEnum" {
600 expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));600 expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
601}601}
602602
603pub fn TagType(comptime T: type) type {603// Deprecated: use Tag
604pub const TagType = Tag;
605
606pub fn Tag(comptime T: type) type {
604 return switch (@typeInfo(T)) {607 return switch (@typeInfo(T)) {
605 .Enum => |info| info.tag_type,608 .Enum => |info| info.tag_type,
606 .Union => |info| if (info.tag_type) |Tag| Tag else null,609 .Union => |info| info.tag_type orelse @compileError(@typeName(T) ++ " has no tag type"),
607 else => @compileError("expected enum or union type, found '" ++ @typeName(T) ++ "'"),610 else => @compileError("expected enum or union type, found '" ++ @typeName(T) ++ "'"),
608 };611 };
609}612}
610613
611test "std.meta.TagType" {614test "std.meta.Tag" {
612 const E = enum(u8) {615 const E = enum(u8) {
613 C = 33,616 C = 33,
614 D,617 D,
...@@ -618,14 +621,14 @@ test "std.meta.TagType" {...@@ -618,14 +621,14 @@ test "std.meta.TagType" {
618 D: u16,621 D: u16,
619 };622 };
620623
621 testing.expect(TagType(E) == u8);624 testing.expect(Tag(E) == u8);
622 testing.expect(TagType(U) == E);625 testing.expect(Tag(U) == E);
623}626}
624627
625///Returns the active tag of a tagged union628///Returns the active tag of a tagged union
626pub fn activeTag(u: anytype) @TagType(@TypeOf(u)) {629pub fn activeTag(u: anytype) Tag(@TypeOf(u)) {
627 const T = @TypeOf(u);630 const T = @TypeOf(u);
628 return @as(@TagType(T), u);631 return @as(Tag(T), u);
629}632}
630633
631test "std.meta.activeTag" {634test "std.meta.activeTag" {
...@@ -646,13 +649,15 @@ test "std.meta.activeTag" {...@@ -646,13 +649,15 @@ test "std.meta.activeTag" {
646 testing.expect(activeTag(u) == UE.Float);649 testing.expect(activeTag(u) == UE.Float);
647}650}
648651
652const TagPayloadType = TagPayload;
653
649///Given a tagged union type, and an enum, return the type of the union654///Given a tagged union type, and an enum, return the type of the union
650/// field corresponding to the enum tag.655/// field corresponding to the enum tag.
651pub fn TagPayloadType(comptime U: type, tag: @TagType(U)) type {656pub fn TagPayload(comptime U: type, tag: Tag(U)) type {
652 testing.expect(trait.is(.Union)(U));657 testing.expect(trait.is(.Union)(U));
653658
654 const info = @typeInfo(U).Union;659 const info = @typeInfo(U).Union;
655 const tag_info = @typeInfo(@TagType(U)).Enum;660 const tag_info = @typeInfo(Tag(U)).Enum;
656661
657 inline for (info.fields) |field_info| {662 inline for (info.fields) |field_info| {
658 if (comptime mem.eql(u8, field_info.name, @tagName(tag)))663 if (comptime mem.eql(u8, field_info.name, @tagName(tag)))
...@@ -662,14 +667,14 @@ pub fn TagPayloadType(comptime U: type, tag: @TagType(U)) type {...@@ -662,14 +667,14 @@ pub fn TagPayloadType(comptime U: type, tag: @TagType(U)) type {
662 unreachable;667 unreachable;
663}668}
664669
665test "std.meta.TagPayloadType" {670test "std.meta.TagPayload" {
666 const Event = union(enum) {671 const Event = union(enum) {
667 Moved: struct {672 Moved: struct {
668 from: i32,673 from: i32,
669 to: i32,674 to: i32,
670 },675 },
671 };676 };
672 const MovedEvent = TagPayloadType(Event, Event.Moved);677 const MovedEvent = TagPayload(Event, Event.Moved);
673 var e: Event = undefined;678 var e: Event = undefined;
674 testing.expect(MovedEvent == @TypeOf(e.Moved));679 testing.expect(MovedEvent == @TypeOf(e.Moved));
675}680}
...@@ -694,13 +699,13 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {...@@ -694,13 +699,13 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {
694 }699 }
695 },700 },
696 .Union => |info| {701 .Union => |info| {
697 if (info.tag_type) |Tag| {702 if (info.tag_type) |UnionTag| {
698 const tag_a = activeTag(a);703 const tag_a = activeTag(a);
699 const tag_b = activeTag(b);704 const tag_b = activeTag(b);
700 if (tag_a != tag_b) return false;705 if (tag_a != tag_b) return false;
701706
702 inline for (info.fields) |field_info| {707 inline for (info.fields) |field_info| {
703 if (@field(Tag, field_info.name) == tag_a) {708 if (@field(UnionTag, field_info.name) == tag_a) {
704 return eql(@field(a, field_info.name), @field(b, field_info.name));709 return eql(@field(a, field_info.name), @field(b, field_info.name));
705 }710 }
706 }711 }
...@@ -822,9 +827,9 @@ test "intToEnum with error return" {...@@ -822,9 +827,9 @@ test "intToEnum with error return" {
822827
823pub const IntToEnumError = error{InvalidEnumTag};828pub const IntToEnumError = error{InvalidEnumTag};
824829
825pub fn intToEnum(comptime Tag: type, tag_int: anytype) IntToEnumError!Tag {830pub fn intToEnum(comptime EnumTag: type, tag_int: anytype) IntToEnumError!EnumTag {
826 inline for (@typeInfo(Tag).Enum.fields) |f| {831 inline for (@typeInfo(EnumTag).Enum.fields) |f| {
827 const this_tag_value = @field(Tag, f.name);832 const this_tag_value = @field(EnumTag, f.name);
828 if (tag_int == @enumToInt(this_tag_value)) {833 if (tag_int == @enumToInt(this_tag_value)) {
829 return this_tag_value;834 return this_tag_value;
830 }835 }
lib/std/meta/trailer_flags.zig+1-1
...@@ -146,7 +146,7 @@ test "TrailerFlags" {...@@ -146,7 +146,7 @@ test "TrailerFlags" {
146 b: bool,146 b: bool,
147 c: u64,147 c: u64,
148 });148 });
149 testing.expectEqual(u2, @TagType(Flags.FieldEnum));149 testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
150150
151 var flags = Flags.init(.{151 var flags = Flags.init(.{
152 .b = true,152 .b = true,
lib/std/testing.zig+3-3
...@@ -119,10 +119,10 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {...@@ -119,10 +119,10 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
119 @compileError("Unable to compare untagged union values");119 @compileError("Unable to compare untagged union values");
120 }120 }
121121
122 const TagType = @TagType(@TypeOf(expected));122 const Tag = std.meta.Tag(@TypeOf(expected));
123123
124 const expectedTag = @as(TagType, expected);124 const expectedTag = @as(Tag, expected);
125 const actualTag = @as(TagType, actual);125 const actualTag = @as(Tag, actual);
126126
127 expectEqual(expectedTag, actualTag);127 expectEqual(expectedTag, actualTag);
128128
lib/std/zig/parser_test.zig+1-1
...@@ -3822,7 +3822,7 @@ fn testCanonical(source: []const u8) !void {...@@ -3822,7 +3822,7 @@ fn testCanonical(source: []const u8) !void {
3822 return testTransform(source, source);3822 return testTransform(source, source);
3823}3823}
38243824
3825const Error = @TagType(std.zig.ast.Error);3825const Error = std.meta.Tag(std.zig.ast.Error);
38263826
3827fn testError(source: []const u8, expected_errors: []const Error) !void {3827fn testError(source: []const u8, expected_errors: []const Error) !void {
3828 const tree = try std.zig.parse(std.testing.allocator, source);3828 const tree = try std.zig.parse(std.testing.allocator, source);
src/DepTokenizer.zig+2-2
...@@ -266,11 +266,11 @@ pub fn next(self: *Tokenizer) ?Token {...@@ -266,11 +266,11 @@ pub fn next(self: *Tokenizer) ?Token {
266 unreachable;266 unreachable;
267}267}
268268
269fn errorPosition(comptime id: @TagType(Token), index: usize, bytes: []const u8) Token {269fn errorPosition(comptime id: std.meta.Tag(Token), index: usize, bytes: []const u8) Token {
270 return @unionInit(Token, @tagName(id), .{ .index = index, .bytes = bytes });270 return @unionInit(Token, @tagName(id), .{ .index = index, .bytes = bytes });
271}271}
272272
273fn errorIllegalChar(comptime id: @TagType(Token), index: usize, char: u8) Token {273fn errorIllegalChar(comptime id: std.meta.Tag(Token), index: usize, char: u8) Token {
274 return @unionInit(Token, @tagName(id), .{ .index = index, .char = char });274 return @unionInit(Token, @tagName(id), .{ .index = index, .char = char });
275}275}
276276
src/astgen.zig-1
...@@ -3077,7 +3077,6 @@ fn nodeMayNeedMemoryLocation(start_node: *ast.Node, scope: *Scope) bool {...@@ -3077,7 +3077,6 @@ fn nodeMayNeedMemoryLocation(start_node: *ast.Node, scope: *Scope) bool {
3077 .{ "@round", false },3077 .{ "@round", false },
3078 .{ "@subWithOverflow", false },3078 .{ "@subWithOverflow", false },
3079 .{ "@tagName", false },3079 .{ "@tagName", false },
3080 .{ "@TagType", false },
3081 .{ "@This", false },3080 .{ "@This", false },
3082 .{ "@truncate", false },3081 .{ "@truncate", false },
3083 .{ "@Type", false },3082 .{ "@Type", false },
src/link/MachO/commands.zig+1-1
...@@ -140,7 +140,7 @@ pub const LoadCommand = union(enum) {...@@ -140,7 +140,7 @@ pub const LoadCommand = union(enum) {
140 }140 }
141141
142 fn eql(self: LoadCommand, other: LoadCommand) bool {142 fn eql(self: LoadCommand, other: LoadCommand) bool {
143 if (@as(@TagType(LoadCommand), self) != @as(@TagType(LoadCommand), other)) return false;143 if (@as(meta.Tag(LoadCommand), self) != @as(meta.Tag(LoadCommand), other)) return false;
144 return switch (self) {144 return switch (self) {
145 .DyldInfoOnly => |x| meta.eql(x, other.DyldInfoOnly),145 .DyldInfoOnly => |x| meta.eql(x, other.DyldInfoOnly),
146 .Symtab => |x| meta.eql(x, other.Symtab),146 .Symtab => |x| meta.eql(x, other.Symtab),
src/stage1/all_types.hpp-8
...@@ -1811,7 +1811,6 @@ enum BuiltinFnId {...@@ -1811,7 +1811,6 @@ enum BuiltinFnId {
1811 BuiltinFnIdIntToPtr,1811 BuiltinFnIdIntToPtr,
1812 BuiltinFnIdPtrToInt,1812 BuiltinFnIdPtrToInt,
1813 BuiltinFnIdTagName,1813 BuiltinFnIdTagName,
1814 BuiltinFnIdTagType,
1815 BuiltinFnIdFieldParentPtr,1814 BuiltinFnIdFieldParentPtr,
1816 BuiltinFnIdByteOffsetOf,1815 BuiltinFnIdByteOffsetOf,
1817 BuiltinFnIdBitOffsetOf,1816 BuiltinFnIdBitOffsetOf,
...@@ -2623,7 +2622,6 @@ enum IrInstSrcId {...@@ -2623,7 +2622,6 @@ enum IrInstSrcId {
2623 IrInstSrcIdDeclRef,2622 IrInstSrcIdDeclRef,
2624 IrInstSrcIdPanic,2623 IrInstSrcIdPanic,
2625 IrInstSrcIdTagName,2624 IrInstSrcIdTagName,
2626 IrInstSrcIdTagType,
2627 IrInstSrcIdFieldParentPtr,2625 IrInstSrcIdFieldParentPtr,
2628 IrInstSrcIdByteOffsetOf,2626 IrInstSrcIdByteOffsetOf,
2629 IrInstSrcIdBitOffsetOf,2627 IrInstSrcIdBitOffsetOf,
...@@ -4074,12 +4072,6 @@ struct IrInstGenTagName {...@@ -4074,12 +4072,6 @@ struct IrInstGenTagName {
4074 IrInstGen *target;4072 IrInstGen *target;
4075};4073};
40764074
4077struct IrInstSrcTagType {
4078 IrInstSrc base;
4079
4080 IrInstSrc *target;
4081};
4082
4083struct IrInstSrcFieldParentPtr {4075struct IrInstSrcFieldParentPtr {
4084 IrInstSrc base;4076 IrInstSrc base;
40854077
src/stage1/analyze.cpp+1-1
...@@ -3267,7 +3267,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3267,7 +3267,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
32673267
3268 tag_type = new_type_table_entry(ZigTypeIdEnum);3268 tag_type = new_type_table_entry(ZigTypeIdEnum);
3269 buf_resize(&tag_type->name, 0);3269 buf_resize(&tag_type->name, 0);
3270 buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name));3270 buf_appendf(&tag_type->name, "@typeInfo(%s).Union.tag_type.?", buf_ptr(&union_type->name));
3271 tag_type->llvm_type = tag_int_type->llvm_type;3271 tag_type->llvm_type = tag_int_type->llvm_type;
3272 tag_type->llvm_di_type = tag_int_type->llvm_di_type;3272 tag_type->llvm_di_type = tag_int_type->llvm_di_type;
3273 tag_type->abi_size = tag_int_type->abi_size;3273 tag_type->abi_size = tag_int_type->abi_size;
src/stage1/codegen.cpp-1
...@@ -8842,7 +8842,6 @@ static void define_builtin_fns(CodeGen *g) {...@@ -8842,7 +8842,6 @@ static void define_builtin_fns(CodeGen *g) {
8842 create_builtin_fn(g, BuiltinFnIdIntToPtr, "intToPtr", 2);8842 create_builtin_fn(g, BuiltinFnIdIntToPtr, "intToPtr", 2);
8843 create_builtin_fn(g, BuiltinFnIdPtrToInt, "ptrToInt", 1);8843 create_builtin_fn(g, BuiltinFnIdPtrToInt, "ptrToInt", 1);
8844 create_builtin_fn(g, BuiltinFnIdTagName, "tagName", 1);8844 create_builtin_fn(g, BuiltinFnIdTagName, "tagName", 1);
8845 create_builtin_fn(g, BuiltinFnIdTagType, "TagType", 1);
8846 create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3);8845 create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3);
8847 create_builtin_fn(g, BuiltinFnIdByteOffsetOf, "byteOffsetOf", 2);8846 create_builtin_fn(g, BuiltinFnIdByteOffsetOf, "byteOffsetOf", 2);
8848 create_builtin_fn(g, BuiltinFnIdBitOffsetOf, "bitOffsetOf", 2);8847 create_builtin_fn(g, BuiltinFnIdBitOffsetOf, "bitOffsetOf", 2);
src/stage1/ir.cpp-54
...@@ -516,8 +516,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {...@@ -516,8 +516,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
516 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst));516 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst));
517 case IrInstSrcIdArgType:517 case IrInstSrcIdArgType:
518 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArgType *>(inst));518 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArgType *>(inst));
519 case IrInstSrcIdTagType:
520 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagType *>(inst));
521 case IrInstSrcIdExport:519 case IrInstSrcIdExport:
522 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcExport *>(inst));520 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcExport *>(inst));
523 case IrInstSrcIdExtern:521 case IrInstSrcIdExtern:
...@@ -1496,10 +1494,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) {...@@ -1496,10 +1494,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) {
1496 return IrInstSrcIdTagName;1494 return IrInstSrcIdTagName;
1497}1495}
14981496
1499static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) {
1500 return IrInstSrcIdTagType;
1501}
1502
1503static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) {1497static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) {
1504 return IrInstSrcIdFieldParentPtr;1498 return IrInstSrcIdFieldParentPtr;
1505}1499}
...@@ -4450,17 +4444,6 @@ static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir...@@ -4450,17 +4444,6 @@ static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir
4450 return &instruction->base;4444 return &instruction->base;
4451}4445}
44524446
4453static IrInstSrc *ir_build_tag_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4454 IrInstSrc *target)
4455{
4456 IrInstSrcTagType *instruction = ir_build_instruction<IrInstSrcTagType>(irb, scope, source_node);
4457 instruction->target = target;
4458
4459 ir_ref_instruction(target, irb->current_basic_block);
4460
4461 return &instruction->base;
4462}
4463
4464static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,4447static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4465 IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr)4448 IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr)
4466{4449{
...@@ -7202,16 +7185,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod...@@ -7202,16 +7185,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
7202 IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value);7185 IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value);
7203 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);7186 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);
7204 }7187 }
7205 case BuiltinFnIdTagType:
7206 {
7207 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
7208 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7209 if (arg0_value == irb->codegen->invalid_inst_src)
7210 return arg0_value;
7211
7212 IrInstSrc *tag_type = ir_build_tag_type(irb, scope, node, arg0_value);
7213 return ir_lval_wrap(irb, scope, tag_type, lval, result_loc);
7214 }
7215 case BuiltinFnIdFieldParentPtr:7188 case BuiltinFnIdFieldParentPtr:
7216 {7189 {
7217 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7190 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
...@@ -31051,30 +31024,6 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy...@@ -31051,30 +31024,6 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
31051 return ir_const_type(ira, &instruction->base.base, result_type);31024 return ir_const_type(ira, &instruction->base.base, result_type);
31052}31025}
3105331026
31054static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagType *instruction) {
31055 Error err;
31056 IrInstGen *target_inst = instruction->target->child;
31057 ZigType *enum_type = ir_resolve_type(ira, target_inst);
31058 if (type_is_invalid(enum_type))
31059 return ira->codegen->invalid_inst_gen;
31060
31061 if (enum_type->id == ZigTypeIdEnum) {
31062 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))
31063 return ira->codegen->invalid_inst_gen;
31064
31065 return ir_const_type(ira, &instruction->base.base, enum_type->data.enumeration.tag_int_type);
31066 } else if (enum_type->id == ZigTypeIdUnion) {
31067 ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target->base.source_node, enum_type);
31068 if (type_is_invalid(tag_type))
31069 return ira->codegen->invalid_inst_gen;
31070 return ir_const_type(ira, &instruction->base.base, tag_type);
31071 } else {
31072 ir_add_error(ira, &target_inst->base, buf_sprintf("expected enum or union, found '%s'",
31073 buf_ptr(&enum_type->name)));
31074 return ira->codegen->invalid_inst_gen;
31075 }
31076}
31077
31078static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {31027static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
31079 ZigType *operand_type = ir_resolve_type(ira, op);31028 ZigType *operand_type = ir_resolve_type(ira, op);
31080 if (type_is_invalid(operand_type))31029 if (type_is_invalid(operand_type))
...@@ -32435,8 +32384,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc...@@ -32435,8 +32384,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
32435 return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction);32384 return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction);
32436 case IrInstSrcIdArgType:32385 case IrInstSrcIdArgType:
32437 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction);32386 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction);
32438 case IrInstSrcIdTagType:
32439 return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction);
32440 case IrInstSrcIdExport:32387 case IrInstSrcIdExport:
32441 return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction);32388 return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction);
32442 case IrInstSrcIdExtern:32389 case IrInstSrcIdExtern:
...@@ -32879,7 +32826,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {...@@ -32879,7 +32826,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
32879 case IrInstSrcIdImplicitCast:32826 case IrInstSrcIdImplicitCast:
32880 case IrInstSrcIdResolveResult:32827 case IrInstSrcIdResolveResult:
32881 case IrInstSrcIdArgType:32828 case IrInstSrcIdArgType:
32882 case IrInstSrcIdTagType:
32883 case IrInstSrcIdErrorReturnTrace:32829 case IrInstSrcIdErrorReturnTrace:
32884 case IrInstSrcIdErrorUnion:32830 case IrInstSrcIdErrorUnion:
32885 case IrInstSrcIdFloatOp:32831 case IrInstSrcIdFloatOp:
src/stage1/ir_print.cpp-11
...@@ -282,8 +282,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {...@@ -282,8 +282,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
282 return "SrcPanic";282 return "SrcPanic";
283 case IrInstSrcIdTagName:283 case IrInstSrcIdTagName:
284 return "SrcTagName";284 return "SrcTagName";
285 case IrInstSrcIdTagType:
286 return "SrcTagType";
287 case IrInstSrcIdFieldParentPtr:285 case IrInstSrcIdFieldParentPtr:
288 return "SrcFieldParentPtr";286 return "SrcFieldParentPtr";
289 case IrInstSrcIdByteOffsetOf:287 case IrInstSrcIdByteOffsetOf:
...@@ -2354,12 +2352,6 @@ static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) {...@@ -2354,12 +2352,6 @@ static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) {
2354 fprintf(irp->f, ")");2352 fprintf(irp->f, ")");
2355}2353}
23562354
2357static void ir_print_enum_tag_type(IrPrintSrc *irp, IrInstSrcTagType *instruction) {
2358 fprintf(irp->f, "@TagType(");
2359 ir_print_other_inst_src(irp, instruction->target);
2360 fprintf(irp->f, ")");
2361}
2362
2363static void ir_print_export(IrPrintSrc *irp, IrInstSrcExport *instruction) {2355static void ir_print_export(IrPrintSrc *irp, IrInstSrcExport *instruction) {
2364 fprintf(irp->f, "@export(");2356 fprintf(irp->f, "@export(");
2365 ir_print_other_inst_src(irp, instruction->target);2357 ir_print_other_inst_src(irp, instruction->target);
...@@ -2953,9 +2945,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai...@@ -2953,9 +2945,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
2953 case IrInstSrcIdArgType:2945 case IrInstSrcIdArgType:
2954 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction);2946 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction);
2955 break;2947 break;
2956 case IrInstSrcIdTagType:
2957 ir_print_enum_tag_type(irp, (IrInstSrcTagType *)instruction);
2958 break;
2959 case IrInstSrcIdExport:2948 case IrInstSrcIdExport:
2960 ir_print_export(irp, (IrInstSrcExport *)instruction);2949 ir_print_export(irp, (IrInstSrcExport *)instruction);
2961 break;2950 break;
src/test.zig+2-2
...@@ -750,7 +750,7 @@ pub const TestContext = struct {...@@ -750,7 +750,7 @@ pub const TestContext = struct {
750750
751 for (actual_errors.list) |actual_error| {751 for (actual_errors.list) |actual_error| {
752 for (case_error_list) |case_msg, i| {752 for (case_error_list) |case_msg, i| {
753 const ex_tag: @TagType(@TypeOf(case_msg)) = case_msg;753 const ex_tag: std.meta.Tag(@TypeOf(case_msg)) = case_msg;
754 switch (actual_error) {754 switch (actual_error) {
755 .src => |actual_msg| {755 .src => |actual_msg| {
756 for (actual_msg.notes) |*note| {756 for (actual_msg.notes) |*note| {
...@@ -789,7 +789,7 @@ pub const TestContext = struct {...@@ -789,7 +789,7 @@ pub const TestContext = struct {
789 }789 }
790 while (notes_to_check.popOrNull()) |note| {790 while (notes_to_check.popOrNull()) |note| {
791 for (case_error_list) |case_msg, i| {791 for (case_error_list) |case_msg, i| {
792 const ex_tag: @TagType(@TypeOf(case_msg)) = case_msg;792 const ex_tag: std.meta.Tag(@TypeOf(case_msg)) = case_msg;
793 switch (note.*) {793 switch (note.*) {
794 .src => |actual_msg| {794 .src => |actual_msg| {
795 for (actual_msg.notes) |*sub_note| {795 for (actual_msg.notes) |*sub_note| {
src/translate_c.zig+1-1
...@@ -3288,7 +3288,7 @@ const ClangFunctionType = union(enum) {...@@ -3288,7 +3288,7 @@ const ClangFunctionType = union(enum) {
3288 NoProto: *const clang.FunctionType,3288 NoProto: *const clang.FunctionType,
32893289
3290 fn getReturnType(self: @This()) clang.QualType {3290 fn getReturnType(self: @This()) clang.QualType {
3291 switch (@as(@TagType(@This()), self)) {3291 switch (@as(std.meta.Tag(@This()), self)) {
3292 .Proto => return self.Proto.getReturnType(),3292 .Proto => return self.Proto.getReturnType(),
3293 .NoProto => return self.NoProto.getReturnType(),3293 .NoProto => return self.NoProto.getReturnType(),
3294 }3294 }
src/type.zig+1-1
...@@ -110,7 +110,7 @@ pub const Type = extern union {...@@ -110,7 +110,7 @@ pub const Type = extern union {
110110
111 pub fn tag(self: Type) Tag {111 pub fn tag(self: Type) Tag {
112 if (self.tag_if_small_enough < Tag.no_payload_count) {112 if (self.tag_if_small_enough < Tag.no_payload_count) {
113 return @intToEnum(Tag, @intCast(@TagType(Tag), self.tag_if_small_enough));113 return @intToEnum(Tag, @intCast(std.meta.Tag(Tag), self.tag_if_small_enough));
114 } else {114 } else {
115 return self.ptr_otherwise.tag;115 return self.ptr_otherwise.tag;
116 }116 }
src/value.zig+1-1
...@@ -223,7 +223,7 @@ pub const Value = extern union {...@@ -223,7 +223,7 @@ pub const Value = extern union {
223223
224 pub fn tag(self: Value) Tag {224 pub fn tag(self: Value) Tag {
225 if (self.tag_if_small_enough < Tag.no_payload_count) {225 if (self.tag_if_small_enough < Tag.no_payload_count) {
226 return @intToEnum(Tag, @intCast(@TagType(Tag), self.tag_if_small_enough));226 return @intToEnum(Tag, @intCast(std.meta.Tag(Tag), self.tag_if_small_enough));
227 } else {227 } else {
228 return self.ptr_otherwise.tag;228 return self.ptr_otherwise.tag;
229 }229 }
test/compile_errors.zig+4-16
...@@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
323 \\ e: E,323 \\ e: E,
324 \\};324 \\};
325 \\export fn entry() void {325 \\export fn entry() void {
326 \\ if (@TagType(E) != u8) @compileError("did not infer u8 tag type");326 \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type");
327 \\ const s: S = undefined;327 \\ const s: S = undefined;
328 \\}328 \\}
329 , &[_][]const u8{329 , &[_][]const u8{
...@@ -2728,7 +2728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2728,7 +2728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2728 \\const InvalidToken = struct {};2728 \\const InvalidToken = struct {};
2729 \\const ExpectedVarDeclOrFn = struct {};2729 \\const ExpectedVarDeclOrFn = struct {};
2730 , &[_][]const u8{2730 , &[_][]const u8{
2731 "tmp.zig:4:9: error: expected type '@TagType(Error)', found 'type'",2731 "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'",
2732 });2732 });
27332733
2734 cases.addTest("binary OR operator on error sets",2734 cases.addTest("binary OR operator on error sets",
...@@ -7462,24 +7462,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -7462,24 +7462,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7462 "tmp.zig:4:5: note: declared here",7462 "tmp.zig:4:5: note: declared here",
7463 });7463 });
74647464
7465 cases.add("@TagType when union has no attached enum",
7466 \\const Foo = union {
7467 \\ A: i32,
7468 \\};
7469 \\export fn entry() void {
7470 \\ const x = @TagType(Foo);
7471 \\}
7472 , &[_][]const u8{
7473 "tmp.zig:5:24: error: union 'Foo' has no tag",
7474 "tmp.zig:1:13: note: consider 'union(enum)' here",
7475 });
7476
7477 cases.add("non-integer tag type to automatic union enum",7465 cases.add("non-integer tag type to automatic union enum",
7478 \\const Foo = union(enum(f32)) {7466 \\const Foo = union(enum(f32)) {
7479 \\ A: i32,7467 \\ A: i32,
7480 \\};7468 \\};
7481 \\export fn entry() void {7469 \\export fn entry() void {
7482 \\ const x = @TagType(Foo);7470 \\ const x = @typeInfo(Foo).Union.tag_type.?;
7483 \\}7471 \\}
7484 , &[_][]const u8{7472 , &[_][]const u8{
7485 "tmp.zig:1:24: error: expected integer tag type, found 'f32'",7473 "tmp.zig:1:24: error: expected integer tag type, found 'f32'",
...@@ -7490,7 +7478,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -7490,7 +7478,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7490 \\ A: i32,7478 \\ A: i32,
7491 \\};7479 \\};
7492 \\export fn entry() void {7480 \\export fn entry() void {
7493 \\ const x = @TagType(Foo);7481 \\ const x = @typeInfo(Foo).Union.tag_type.?;
7494 \\}7482 \\}
7495 , &[_][]const u8{7483 , &[_][]const u8{
7496 "tmp.zig:1:19: error: expected enum tag type, found 'u32'",7484 "tmp.zig:1:19: error: expected enum tag type, found 'u32'",
test/runtime_safety.zig+1-1
...@@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
74 \\pub fn main() void {74 \\pub fn main() void {
75 \\ var u: U = undefined;75 \\ var u: U = undefined;
76 \\ @memset(@ptrCast([*]u8, &u), 0x55, @sizeOf(U));76 \\ @memset(@ptrCast([*]u8, &u), 0x55, @sizeOf(U));
77 \\ var t: @TagType(U) = u;77 \\ var t: @typeInfo(U).Union.tag_type.? = u;
78 \\ var n = @tagName(t);78 \\ var n = @tagName(t);
79 \\}79 \\}
80 );80 );
test/stage1/behavior/bugs/1322.zig+2-2
...@@ -13,7 +13,7 @@ const C = struct {};...@@ -13,7 +13,7 @@ const C = struct {};
1313
14test "tagged union with all void fields but a meaningful tag" {14test "tagged union with all void fields but a meaningful tag" {
15 var a: A = A{ .b = B{ .c = C{} } };15 var a: A = A{ .b = B{ .c = C{} } };
16 std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).c);16 std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).c);
17 a = A{ .b = B.None };17 a = A{ .b = B.None };
18 std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).None);18 std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).None);
19}19}
test/stage1/behavior/enum.zig+8-7
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;2const mem = @import("std").mem;
3const Tag = @import("std").meta.Tag;
34
4test "extern enum" {5test "extern enum" {
5 const S = struct {6 const S = struct {
...@@ -827,12 +828,12 @@ test "set enum tag type" {...@@ -827,12 +828,12 @@ test "set enum tag type" {
827 {828 {
828 var x = Small.One;829 var x = Small.One;
829 x = Small.Two;830 x = Small.Two;
830 comptime expect(@TagType(Small) == u2);831 comptime expect(Tag(Small) == u2);
831 }832 }
832 {833 {
833 var x = Small2.One;834 var x = Small2.One;
834 x = Small2.Two;835 x = Small2.Two;
835 comptime expect(@TagType(Small2) == u2);836 comptime expect(Tag(Small2) == u2);
836 }837 }
837}838}
838839
...@@ -905,11 +906,11 @@ fn getC(data: *const BitFieldOfEnums) C {...@@ -905,11 +906,11 @@ fn getC(data: *const BitFieldOfEnums) C {
905}906}
906907
907test "casting enum to its tag type" {908test "casting enum to its tag type" {
908 testCastEnumToTagType(Small2.Two);909 testCastEnumTag(Small2.Two);
909 comptime testCastEnumToTagType(Small2.Two);910 comptime testCastEnumTag(Small2.Two);
910}911}
911912
912fn testCastEnumToTagType(value: Small2) void {913fn testCastEnumTag(value: Small2) void {
913 expect(@enumToInt(value) == 1);914 expect(@enumToInt(value) == 1);
914}915}
915916
...@@ -1163,14 +1164,14 @@ test "enum with comptime_int tag type" {...@@ -1163,14 +1164,14 @@ test "enum with comptime_int tag type" {
1163 Two = 2,1164 Two = 2,
1164 Three = 1,1165 Three = 1,
1165 };1166 };
1166 comptime expect(@TagType(Enum) == comptime_int);1167 comptime expect(Tag(Enum) == comptime_int);
1167}1168}
11681169
1169test "enum with one member default to u0 tag type" {1170test "enum with one member default to u0 tag type" {
1170 const E0 = enum {1171 const E0 = enum {
1171 X,1172 X,
1172 };1173 };
1173 comptime expect(@TagType(E0) == u0);1174 comptime expect(Tag(E0) == u0);
1174}1175}
11751176
1176test "tagName on enum literals" {1177test "tagName on enum literals" {
test/stage1/behavior/type_info.zig+1-1
...@@ -14,7 +14,7 @@ test "type info: tag type, void info" {...@@ -14,7 +14,7 @@ test "type info: tag type, void info" {
14}14}
1515
16fn testBasic() void {16fn testBasic() void {
17 expect(@TagType(TypeInfo) == TypeId);17 expect(@typeInfo(TypeInfo).Union.tag_type == TypeId);
18 const void_info = @typeInfo(void);18 const void_info = @typeInfo(void);
19 expect(void_info == TypeId.Void);19 expect(void_info == TypeId.Void);
20 expect(void_info.Void == {});20 expect(void_info.Void == {});
test/stage1/behavior/union.zig+23-22
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;3const expectEqual = std.testing.expectEqual;
4const Tag = std.meta.Tag;
45
5const Value = union(enum) {6const Value = union(enum) {
6 Int: u64,7 Int: u64,
...@@ -128,7 +129,7 @@ const MultipleChoice = union(enum(u32)) {...@@ -128,7 +129,7 @@ const MultipleChoice = union(enum(u32)) {
128test "simple union(enum(u32))" {129test "simple union(enum(u32))" {
129 var x = MultipleChoice.C;130 var x = MultipleChoice.C;
130 expect(x == MultipleChoice.C);131 expect(x == MultipleChoice.C);
131 expect(@enumToInt(@as(@TagType(MultipleChoice), x)) == 60);132 expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60);
132}133}
133134
134const MultipleChoice2 = union(enum(u32)) {135const MultipleChoice2 = union(enum(u32)) {
...@@ -144,13 +145,13 @@ const MultipleChoice2 = union(enum(u32)) {...@@ -144,13 +145,13 @@ const MultipleChoice2 = union(enum(u32)) {
144};145};
145146
146test "union(enum(u32)) with specified and unspecified tag values" {147test "union(enum(u32)) with specified and unspecified tag values" {
147 comptime expect(@TagType(@TagType(MultipleChoice2)) == u32);148 comptime expect(Tag(Tag(MultipleChoice2)) == u32);
148 testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });149 testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
149 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });150 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
150}151}
151152
152fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {153fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
153 expect(@enumToInt(@as(@TagType(MultipleChoice2), x)) == 60);154 expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60);
154 expect(1123 == switch (x) {155 expect(1123 == switch (x) {
155 MultipleChoice2.A => 1,156 MultipleChoice2.A => 1,
156 MultipleChoice2.B => 2,157 MultipleChoice2.B => 2,
...@@ -204,11 +205,11 @@ test "union field access gives the enum values" {...@@ -204,11 +205,11 @@ test "union field access gives the enum values" {
204}205}
205206
206test "cast union to tag type of union" {207test "cast union to tag type of union" {
207 testCastUnionToTagType(TheUnion{ .B = 1234 });208 testCastUnionToTag(TheUnion{ .B = 1234 });
208 comptime testCastUnionToTagType(TheUnion{ .B = 1234 });209 comptime testCastUnionToTag(TheUnion{ .B = 1234 });
209}210}
210211
211fn testCastUnionToTagType(x: TheUnion) void {212fn testCastUnionToTag(x: TheUnion) void {
212 expect(@as(TheTag, x) == TheTag.B);213 expect(@as(TheTag, x) == TheTag.B);
213}214}
214215
...@@ -298,7 +299,7 @@ const TaggedUnionWithAVoid = union(enum) {...@@ -298,7 +299,7 @@ const TaggedUnionWithAVoid = union(enum) {
298299
299fn testTaggedUnionInit(x: anytype) bool {300fn testTaggedUnionInit(x: anytype) bool {
300 const y = TaggedUnionWithAVoid{ .A = x };301 const y = TaggedUnionWithAVoid{ .A = x };
301 return @as(@TagType(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A;302 return @as(Tag(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A;
302}303}
303304
304pub const UnionEnumNoPayloads = union(enum) {305pub const UnionEnumNoPayloads = union(enum) {
...@@ -309,8 +310,8 @@ pub const UnionEnumNoPayloads = union(enum) {...@@ -309,8 +310,8 @@ pub const UnionEnumNoPayloads = union(enum) {
309test "tagged union with no payloads" {310test "tagged union with no payloads" {
310 const a = UnionEnumNoPayloads{ .B = {} };311 const a = UnionEnumNoPayloads{ .B = {} };
311 switch (a) {312 switch (a) {
312 @TagType(UnionEnumNoPayloads).A => @panic("wrong"),313 Tag(UnionEnumNoPayloads).A => @panic("wrong"),
313 @TagType(UnionEnumNoPayloads).B => {},314 Tag(UnionEnumNoPayloads).B => {},
314 }315 }
315}316}
316317
...@@ -325,9 +326,9 @@ test "union with only 1 field casted to its enum type" {...@@ -325,9 +326,9 @@ test "union with only 1 field casted to its enum type" {
325 };326 };
326327
327 var e = Expr{ .Literal = Literal{ .Bool = true } };328 var e = Expr{ .Literal = Literal{ .Bool = true } };
328 const Tag = @TagType(Expr);329 const ExprTag = Tag(Expr);
329 comptime expect(@TagType(Tag) == u0);330 comptime expect(Tag(ExprTag) == u0);
330 var t = @as(Tag, e);331 var t = @as(ExprTag, e);
331 expect(t == Expr.Literal);332 expect(t == Expr.Literal);
332}333}
333334
...@@ -337,17 +338,17 @@ test "union with only 1 field casted to its enum type which has enum value speci...@@ -337,17 +338,17 @@ test "union with only 1 field casted to its enum type which has enum value speci
337 Bool: bool,338 Bool: bool,
338 };339 };
339340
340 const Tag = enum(comptime_int) {341 const ExprTag = enum(comptime_int) {
341 Literal = 33,342 Literal = 33,
342 };343 };
343344
344 const Expr = union(Tag) {345 const Expr = union(ExprTag) {
345 Literal: Literal,346 Literal: Literal,
346 };347 };
347348
348 var e = Expr{ .Literal = Literal{ .Bool = true } };349 var e = Expr{ .Literal = Literal{ .Bool = true } };
349 comptime expect(@TagType(Tag) == comptime_int);350 comptime expect(Tag(ExprTag) == comptime_int);
350 var t = @as(Tag, e);351 var t = @as(ExprTag, e);
351 expect(t == Expr.Literal);352 expect(t == Expr.Literal);
352 expect(@enumToInt(t) == 33);353 expect(@enumToInt(t) == 33);
353 comptime expect(@enumToInt(t) == 33);354 comptime expect(@enumToInt(t) == 33);
...@@ -501,7 +502,7 @@ test "union with one member defaults to u0 tag type" {...@@ -501,7 +502,7 @@ test "union with one member defaults to u0 tag type" {
501 const U0 = union(enum) {502 const U0 = union(enum) {
502 X: u32,503 X: u32,
503 };504 };
504 comptime expect(@TagType(@TagType(U0)) == u0);505 comptime expect(Tag(Tag(U0)) == u0);
505}506}
506507
507test "union with comptime_int tag" {508test "union with comptime_int tag" {
...@@ -510,7 +511,7 @@ test "union with comptime_int tag" {...@@ -510,7 +511,7 @@ test "union with comptime_int tag" {
510 Y: u16,511 Y: u16,
511 Z: u8,512 Z: u8,
512 };513 };
513 comptime expect(@TagType(@TagType(Union)) == comptime_int);514 comptime expect(Tag(Tag(Union)) == comptime_int);
514}515}
515516
516test "extern union doesn't trigger field check at comptime" {517test "extern union doesn't trigger field check at comptime" {
...@@ -591,7 +592,7 @@ test "function call result coerces from tagged union to the tag" {...@@ -591,7 +592,7 @@ test "function call result coerces from tagged union to the tag" {
591 Two: usize,592 Two: usize,
592 };593 };
593594
594 const ArchTag = @TagType(Arch);595 const ArchTag = Tag(Arch);
595596
596 fn doTheTest() void {597 fn doTheTest() void {
597 var x: ArchTag = getArch1();598 var x: ArchTag = getArch1();
...@@ -696,8 +697,8 @@ test "cast from pointer to anonymous struct to pointer to union" {...@@ -696,8 +697,8 @@ test "cast from pointer to anonymous struct to pointer to union" {
696697
697test "method call on an empty union" {698test "method call on an empty union" {
698 const S = struct {699 const S = struct {
699 const MyUnion = union(Tag) {700 const MyUnion = union(MyUnionTag) {
700 pub const Tag = enum { X1, X2 };701 pub const MyUnionTag = enum { X1, X2 };
701 X1: [0]u8,702 X1: [0]u8,
702 X2: [0]u8,703 X2: [0]u8,
703704
...@@ -797,7 +798,7 @@ test "union enum type gets a separate scope" {...@@ -797,7 +798,7 @@ test "union enum type gets a separate scope" {
797 };798 };
798799
799 fn doTheTest() void {800 fn doTheTest() void {
800 expect(!@hasDecl(@TagType(U), "foo"));801 expect(!@hasDecl(Tag(U), "foo"));
801 }802 }
802 };803 };
803804
test/tests.zig+1-1
...@@ -499,7 +499,7 @@ pub fn addPkgTests(...@@ -499,7 +499,7 @@ pub fn addPkgTests(
499 if (skip_single_threaded and test_target.single_threaded)499 if (skip_single_threaded and test_target.single_threaded)
500 continue;500 continue;
501501
502 const ArchTag = @TagType(builtin.Arch);502 const ArchTag = std.meta.Tag(builtin.Arch);
503 if (test_target.disable_native and503 if (test_target.disable_native and
504 test_target.target.getOsTag() == std.Target.current.os.tag and504 test_target.target.getOsTag() == std.Target.current.os.tag and
505 test_target.target.getCpuArch() == std.Target.current.cpu.arch)505 test_target.target.getCpuArch() == std.Target.current.cpu.arch)
tools/process_headers.zig+1-1
...@@ -47,7 +47,7 @@ const MultiAbi = union(enum) {...@@ -47,7 +47,7 @@ const MultiAbi = union(enum) {
47 fn eql(a: MultiAbi, b: MultiAbi) bool {47 fn eql(a: MultiAbi, b: MultiAbi) bool {
48 if (@enumToInt(a) != @enumToInt(b))48 if (@enumToInt(a) != @enumToInt(b))
49 return false;49 return false;
50 if (@TagType(MultiAbi)(a) != .specific)50 if (std.meta.Tag(MultiAbi)(a) != .specific)
51 return true;51 return true;
52 return a.specific == b.specific;52 return a.specific == b.specific;
53 }53 }