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" {
30923092 {#header_open|Tagged union#}
30933093 <p>Unions can be declared with an enum tag type.
30943094 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#} to
3096 obtain the enum type from the union type.
3095 to use with {#link|switch#} expressions.
30973096 Tagged unions coerce to their tag type: {#link|Type Coercion: unions and enums#}.
30983097 </p>
30993098 {#code_begin|test#}
......@@ -3119,8 +3118,8 @@ test "switch on tagged union" {
31193118 }
31203119}
31213120
3122test "@TagType" {
3123 expect(@TagType(ComplexType) == ComplexTypeTag);
3121test "get tag type" {
3122 expect(std.meta.Tag(ComplexType) == ComplexTypeTag);
31243123}
31253124
31263125test "coerce to enum" {
......@@ -7740,7 +7739,7 @@ test "@hasDecl" {
77407739 {#header_close#}
77417740
77427741 {#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>
77447743 <p>
77457744 Converts an integer into an {#link|enum#} value.
77467745 </p>
......@@ -8435,16 +8434,6 @@ fn doTheTest() void {
84358434 </p>
84368435 {#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
84488437 {#header_open|@This#}
84498438 <pre>{#syntax#}@This() type{#endsyntax#}</pre>
84508439 <p>
src/astgen.zig-1
......@@ -3077,7 +3077,6 @@ fn nodeMayNeedMemoryLocation(start_node: *ast.Node, scope: *Scope) bool {
30773077 .{ "@round", false },
30783078 .{ "@subWithOverflow", false },
30793079 .{ "@tagName", false },
3080 .{ "@TagType", false },
30813080 .{ "@This", false },
30823081 .{ "@truncate", false },
30833082 .{ "@Type", false },
src/stage1/all_types.hpp-8
......@@ -1811,7 +1811,6 @@ enum BuiltinFnId {
18111811 BuiltinFnIdIntToPtr,
18121812 BuiltinFnIdPtrToInt,
18131813 BuiltinFnIdTagName,
1814 BuiltinFnIdTagType,
18151814 BuiltinFnIdFieldParentPtr,
18161815 BuiltinFnIdByteOffsetOf,
18171816 BuiltinFnIdBitOffsetOf,
......@@ -2623,7 +2622,6 @@ enum IrInstSrcId {
26232622 IrInstSrcIdDeclRef,
26242623 IrInstSrcIdPanic,
26252624 IrInstSrcIdTagName,
2626 IrInstSrcIdTagType,
26272625 IrInstSrcIdFieldParentPtr,
26282626 IrInstSrcIdByteOffsetOf,
26292627 IrInstSrcIdBitOffsetOf,
......@@ -4074,12 +4072,6 @@ struct IrInstGenTagName {
40744072 IrInstGen *target;
40754073};
40764074
4077struct IrInstSrcTagType {
4078 IrInstSrc base;
4079
4080 IrInstSrc *target;
4081};
4082
40834075struct IrInstSrcFieldParentPtr {
40844076 IrInstSrc base;
40854077
src/stage1/analyze.cpp+1-1
......@@ -3267,7 +3267,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
32673267
32683268 tag_type = new_type_table_entry(ZigTypeIdEnum);
32693269 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));
32713271 tag_type->llvm_type = tag_int_type->llvm_type;
32723272 tag_type->llvm_di_type = tag_int_type->llvm_di_type;
32733273 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) {
88428842 create_builtin_fn(g, BuiltinFnIdIntToPtr, "intToPtr", 2);
88438843 create_builtin_fn(g, BuiltinFnIdPtrToInt, "ptrToInt", 1);
88448844 create_builtin_fn(g, BuiltinFnIdTagName, "tagName", 1);
8845 create_builtin_fn(g, BuiltinFnIdTagType, "TagType", 1);
88468845 create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3);
88478846 create_builtin_fn(g, BuiltinFnIdByteOffsetOf, "byteOffsetOf", 2);
88488847 create_builtin_fn(g, BuiltinFnIdBitOffsetOf, "bitOffsetOf", 2);
src/stage1/ir.cpp-54
......@@ -516,8 +516,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
516516 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst));
517517 case IrInstSrcIdArgType:
518518 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArgType *>(inst));
519 case IrInstSrcIdTagType:
520 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagType *>(inst));
521519 case IrInstSrcIdExport:
522520 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcExport *>(inst));
523521 case IrInstSrcIdExtern:
......@@ -1496,10 +1494,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) {
14961494 return IrInstSrcIdTagName;
14971495}
14981496
1499static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) {
1500 return IrInstSrcIdTagType;
1501}
1502
15031497static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) {
15041498 return IrInstSrcIdFieldParentPtr;
15051499}
......@@ -4450,17 +4444,6 @@ static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir
44504444 return &instruction->base;
44514445}
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
44644447static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
44654448 IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr)
44664449{
......@@ -7202,16 +7185,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
72027185 IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value);
72037186 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);
72047187 }
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 }
72157188 case BuiltinFnIdFieldParentPtr:
72167189 {
72177190 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
3105131024 return ir_const_type(ira, &instruction->base.base, result_type);
3105231025}
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
3107831027static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
3107931028 ZigType *operand_type = ir_resolve_type(ira, op);
3108031029 if (type_is_invalid(operand_type))
......@@ -32435,8 +32384,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
3243532384 return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction);
3243632385 case IrInstSrcIdArgType:
3243732386 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction);
32438 case IrInstSrcIdTagType:
32439 return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction);
3244032387 case IrInstSrcIdExport:
3244132388 return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction);
3244232389 case IrInstSrcIdExtern:
......@@ -32879,7 +32826,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
3287932826 case IrInstSrcIdImplicitCast:
3288032827 case IrInstSrcIdResolveResult:
3288132828 case IrInstSrcIdArgType:
32882 case IrInstSrcIdTagType:
3288332829 case IrInstSrcIdErrorReturnTrace:
3288432830 case IrInstSrcIdErrorUnion:
3288532831 case IrInstSrcIdFloatOp:
src/stage1/ir_print.cpp-11
......@@ -282,8 +282,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
282282 return "SrcPanic";
283283 case IrInstSrcIdTagName:
284284 return "SrcTagName";
285 case IrInstSrcIdTagType:
286 return "SrcTagType";
287285 case IrInstSrcIdFieldParentPtr:
288286 return "SrcFieldParentPtr";
289287 case IrInstSrcIdByteOffsetOf:
......@@ -2354,12 +2352,6 @@ static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) {
23542352 fprintf(irp->f, ")");
23552353}
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
23632355static void ir_print_export(IrPrintSrc *irp, IrInstSrcExport *instruction) {
23642356 fprintf(irp->f, "@export(");
23652357 ir_print_other_inst_src(irp, instruction->target);
......@@ -2953,9 +2945,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
29532945 case IrInstSrcIdArgType:
29542946 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction);
29552947 break;
2956 case IrInstSrcIdTagType:
2957 ir_print_enum_tag_type(irp, (IrInstSrcTagType *)instruction);
2958 break;
29592948 case IrInstSrcIdExport:
29602949 ir_print_export(irp, (IrInstSrcExport *)instruction);
29612950 break;