authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2021-01-11 11:04:38-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-01-30 13:19:58+02:00
log1637d8ac80b46599e276eb767208f54f0a30ccf0
tree1990400fd1d63579cff6e552f91d7139513e6c49
parentb7767eb834084adc9db94b9ed961aaa2756fc018
signature Commit is signed but in an unrecognized format.

remove @TagType


7 files changed, 5 insertions(+), 91 deletions(-)

doc/langref.html.in+4-15
...@@ -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>
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/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).Enum.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;