From 1637d8ac80b46599e276eb767208f54f0a30ccf0 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Mon, 11 Jan 2021 11:04:38 -0700 Subject: [PATCH] remove @TagType --- doc/langref.html.in | 19 +++----------- src/astgen.zig | 1 - src/stage1/all_types.hpp | 8 ------ src/stage1/analyze.cpp | 2 +- src/stage1/codegen.cpp | 1 - src/stage1/ir.cpp | 54 ---------------------------------------- src/stage1/ir_print.cpp | 11 -------- 7 files changed, 5 insertions(+), 91 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 85917680d3..3af4d7d2b1 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -3092,8 +3092,7 @@ test "simple union" { {#header_open|Tagged union#}

Unions can be declared with an enum tag type. This turns the union into a tagged union, which makes it eligible - to use with {#link|switch#} expressions. One can use {#link|@TagType#} to - obtain the enum type from the union type. + to use with {#link|switch#} expressions. Tagged unions coerce to their tag type: {#link|Type Coercion: unions and enums#}.

{#code_begin|test#} @@ -3119,8 +3118,8 @@ test "switch on tagged union" { } } -test "@TagType" { - expect(@TagType(ComplexType) == ComplexTypeTag); +test "get tag type" { + expect(std.meta.Tag(ComplexType) == ComplexTypeTag); } test "coerce to enum" { @@ -7740,7 +7739,7 @@ test "@hasDecl" { {#header_close#} {#header_open|@intToEnum#} -
{#syntax#}@intToEnum(comptime DestType: type, int_value: @TagType(DestType)) DestType{#endsyntax#}
+
{#syntax#}@intToEnum(comptime DestType: type, int_value: std.meta.Tag(DestType)) DestType{#endsyntax#}

Converts an integer into an {#link|enum#} value.

@@ -8435,16 +8434,6 @@ fn doTheTest() void {

{#header_close#} - {#header_open|@TagType#} -
{#syntax#}@TagType(T: type) type{#endsyntax#}
-

- For an enum, returns the integer type that is used to store the enumeration value. -

-

- For a union, returns the enum type that is used to store the tag value. -

- {#header_close#} - {#header_open|@This#}
{#syntax#}@This() type{#endsyntax#}

diff --git a/src/astgen.zig b/src/astgen.zig index 8b4f1cc93c..a74b83de44 100644 --- a/src/astgen.zig +++ b/src/astgen.zig @@ -3077,7 +3077,6 @@ fn nodeMayNeedMemoryLocation(start_node: *ast.Node, scope: *Scope) bool { .{ "@round", false }, .{ "@subWithOverflow", false }, .{ "@tagName", false }, - .{ "@TagType", false }, .{ "@This", false }, .{ "@truncate", false }, .{ "@Type", false }, diff --git a/src/stage1/all_types.hpp b/src/stage1/all_types.hpp index 196010ebca..d2741320d7 100644 --- a/src/stage1/all_types.hpp +++ b/src/stage1/all_types.hpp @@ -1811,7 +1811,6 @@ enum BuiltinFnId { BuiltinFnIdIntToPtr, BuiltinFnIdPtrToInt, BuiltinFnIdTagName, - BuiltinFnIdTagType, BuiltinFnIdFieldParentPtr, BuiltinFnIdByteOffsetOf, BuiltinFnIdBitOffsetOf, @@ -2623,7 +2622,6 @@ enum IrInstSrcId { IrInstSrcIdDeclRef, IrInstSrcIdPanic, IrInstSrcIdTagName, - IrInstSrcIdTagType, IrInstSrcIdFieldParentPtr, IrInstSrcIdByteOffsetOf, IrInstSrcIdBitOffsetOf, @@ -4074,12 +4072,6 @@ struct IrInstGenTagName { IrInstGen *target; }; -struct IrInstSrcTagType { - IrInstSrc base; - - IrInstSrc *target; -}; - struct IrInstSrcFieldParentPtr { IrInstSrc base; diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index faf66f59f3..6bc97d323a 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -3267,7 +3267,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { tag_type = new_type_table_entry(ZigTypeIdEnum); buf_resize(&tag_type->name, 0); - buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name)); + buf_appendf(&tag_type->name, "@typeInfo(%s).Enum.tag_type", buf_ptr(&union_type->name)); tag_type->llvm_type = tag_int_type->llvm_type; tag_type->llvm_di_type = tag_int_type->llvm_di_type; tag_type->abi_size = tag_int_type->abi_size; diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index d850b3ee31..6aa134c3b0 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -8842,7 +8842,6 @@ static void define_builtin_fns(CodeGen *g) { create_builtin_fn(g, BuiltinFnIdIntToPtr, "intToPtr", 2); create_builtin_fn(g, BuiltinFnIdPtrToInt, "ptrToInt", 1); create_builtin_fn(g, BuiltinFnIdTagName, "tagName", 1); - create_builtin_fn(g, BuiltinFnIdTagType, "TagType", 1); create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3); create_builtin_fn(g, BuiltinFnIdByteOffsetOf, "byteOffsetOf", 2); create_builtin_fn(g, BuiltinFnIdBitOffsetOf, "bitOffsetOf", 2); diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index 9fd6f15873..e876873022 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -516,8 +516,6 @@ static void destroy_instruction_src(IrInstSrc *inst) { return heap::c_allocator.destroy(reinterpret_cast(inst)); case IrInstSrcIdArgType: return heap::c_allocator.destroy(reinterpret_cast(inst)); - case IrInstSrcIdTagType: - return heap::c_allocator.destroy(reinterpret_cast(inst)); case IrInstSrcIdExport: return heap::c_allocator.destroy(reinterpret_cast(inst)); case IrInstSrcIdExtern: @@ -1496,10 +1494,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) { return IrInstSrcIdTagName; } -static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) { - return IrInstSrcIdTagType; -} - static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) { return IrInstSrcIdFieldParentPtr; } @@ -4450,17 +4444,6 @@ static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir return &instruction->base; } -static IrInstSrc *ir_build_tag_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, - IrInstSrc *target) -{ - IrInstSrcTagType *instruction = ir_build_instruction(irb, scope, source_node); - instruction->target = target; - - ir_ref_instruction(target, irb->current_basic_block); - - return &instruction->base; -} - static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr) { @@ -7202,16 +7185,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value); return ir_lval_wrap(irb, scope, tag_name, lval, result_loc); } - case BuiltinFnIdTagType: - { - AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); - if (arg0_value == irb->codegen->invalid_inst_src) - return arg0_value; - - IrInstSrc *tag_type = ir_build_tag_type(irb, scope, node, arg0_value); - return ir_lval_wrap(irb, scope, tag_type, lval, result_loc); - } case BuiltinFnIdFieldParentPtr: { 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 return ir_const_type(ira, &instruction->base.base, result_type); } -static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagType *instruction) { - Error err; - IrInstGen *target_inst = instruction->target->child; - ZigType *enum_type = ir_resolve_type(ira, target_inst); - if (type_is_invalid(enum_type)) - return ira->codegen->invalid_inst_gen; - - if (enum_type->id == ZigTypeIdEnum) { - if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown))) - return ira->codegen->invalid_inst_gen; - - return ir_const_type(ira, &instruction->base.base, enum_type->data.enumeration.tag_int_type); - } else if (enum_type->id == ZigTypeIdUnion) { - ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target->base.source_node, enum_type); - if (type_is_invalid(tag_type)) - return ira->codegen->invalid_inst_gen; - return ir_const_type(ira, &instruction->base.base, tag_type); - } else { - ir_add_error(ira, &target_inst->base, buf_sprintf("expected enum or union, found '%s'", - buf_ptr(&enum_type->name))); - return ira->codegen->invalid_inst_gen; - } -} - static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { ZigType *operand_type = ir_resolve_type(ira, op); if (type_is_invalid(operand_type)) @@ -32435,8 +32384,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction); case IrInstSrcIdArgType: return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction); - case IrInstSrcIdTagType: - return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction); case IrInstSrcIdExport: return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction); case IrInstSrcIdExtern: @@ -32879,7 +32826,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) { case IrInstSrcIdImplicitCast: case IrInstSrcIdResolveResult: case IrInstSrcIdArgType: - case IrInstSrcIdTagType: case IrInstSrcIdErrorReturnTrace: case IrInstSrcIdErrorUnion: case IrInstSrcIdFloatOp: diff --git a/src/stage1/ir_print.cpp b/src/stage1/ir_print.cpp index 572551e615..98d349012e 100644 --- a/src/stage1/ir_print.cpp +++ b/src/stage1/ir_print.cpp @@ -282,8 +282,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) { return "SrcPanic"; case IrInstSrcIdTagName: return "SrcTagName"; - case IrInstSrcIdTagType: - return "SrcTagType"; case IrInstSrcIdFieldParentPtr: return "SrcFieldParentPtr"; case IrInstSrcIdByteOffsetOf: @@ -2354,12 +2352,6 @@ static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) { fprintf(irp->f, ")"); } -static void ir_print_enum_tag_type(IrPrintSrc *irp, IrInstSrcTagType *instruction) { - fprintf(irp->f, "@TagType("); - ir_print_other_inst_src(irp, instruction->target); - fprintf(irp->f, ")"); -} - static void ir_print_export(IrPrintSrc *irp, IrInstSrcExport *instruction) { fprintf(irp->f, "@export("); ir_print_other_inst_src(irp, instruction->target); @@ -2953,9 +2945,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai case IrInstSrcIdArgType: ir_print_arg_type(irp, (IrInstSrcArgType *)instruction); break; - case IrInstSrcIdTagType: - ir_print_enum_tag_type(irp, (IrInstSrcTagType *)instruction); - break; case IrInstSrcIdExport: ir_print_export(irp, (IrInstSrcExport *)instruction); break;