| author | |
| committer | |
| log | 1637d8ac80b46599e276eb767208f54f0a30ccf0 |
| tree | 1990400fd1d63579cff6e552f91d7139513e6c49 |
| parent | b7767eb834084adc9db94b9ed961aaa2756fc018 |
| signature | Commit is signed but in an unrecognized format. |
7 files changed, 5 insertions(+), 91 deletions(-)
doc/langref.html.in+4-15| ... | ... | @@ -3092,8 +3092,7 @@ test "simple union" { |
| 3092 | 3092 | {#header_open|Tagged union#} |
| 3093 | 3093 | <p>Unions can be declared with an enum tag type. |
| 3094 | 3094 | 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. | |
| 3097 | 3096 | Tagged unions coerce to their tag type: {#link|Type Coercion: unions and enums#}. |
| 3098 | 3097 | </p> |
| 3099 | 3098 | {#code_begin|test#} |
| ... | ... | @@ -3119,8 +3118,8 @@ test "switch on tagged union" { |
| 3119 | 3118 | } |
| 3120 | 3119 | } |
| 3121 | 3120 | |
| 3122 | test "@TagType" { | |
| 3123 | expect(@TagType(ComplexType) == ComplexTypeTag); | |
| 3121 | test "get tag type" { | |
| 3122 | expect(std.meta.Tag(ComplexType) == ComplexTypeTag); | |
| 3124 | 3123 | } |
| 3125 | 3124 | |
| 3126 | 3125 | test "coerce to enum" { |
| ... | ... | @@ -7740,7 +7739,7 @@ test "@hasDecl" { |
| 7740 | 7739 | {#header_close#} |
| 7741 | 7740 | |
| 7742 | 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 | 7743 | <p> |
| 7745 | 7744 | Converts an integer into an {#link|enum#} value. |
| 7746 | 7745 | </p> |
| ... | ... | @@ -8435,16 +8434,6 @@ fn doTheTest() void { |
| 8435 | 8434 | </p> |
| 8436 | 8435 | {#header_close#} |
| 8437 | 8436 | |
| 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 | 8437 | {#header_open|@This#} |
| 8449 | 8438 | <pre>{#syntax#}@This() type{#endsyntax#}</pre> |
| 8450 | 8439 | <p> |
src/astgen.zig-1| ... | ... | @@ -3077,7 +3077,6 @@ fn nodeMayNeedMemoryLocation(start_node: *ast.Node, scope: *Scope) bool { |
| 3077 | 3077 | .{ "@round", false }, |
| 3078 | 3078 | .{ "@subWithOverflow", false }, |
| 3079 | 3079 | .{ "@tagName", false }, |
| 3080 | .{ "@TagType", false }, | |
| 3081 | 3080 | .{ "@This", false }, |
| 3082 | 3081 | .{ "@truncate", false }, |
| 3083 | 3082 | .{ "@Type", false }, |
src/stage1/all_types.hpp-8| ... | ... | @@ -1811,7 +1811,6 @@ enum BuiltinFnId { |
| 1811 | 1811 | BuiltinFnIdIntToPtr, |
| 1812 | 1812 | BuiltinFnIdPtrToInt, |
| 1813 | 1813 | BuiltinFnIdTagName, |
| 1814 | BuiltinFnIdTagType, | |
| 1815 | 1814 | BuiltinFnIdFieldParentPtr, |
| 1816 | 1815 | BuiltinFnIdByteOffsetOf, |
| 1817 | 1816 | BuiltinFnIdBitOffsetOf, |
| ... | ... | @@ -2623,7 +2622,6 @@ enum IrInstSrcId { |
| 2623 | 2622 | IrInstSrcIdDeclRef, |
| 2624 | 2623 | IrInstSrcIdPanic, |
| 2625 | 2624 | IrInstSrcIdTagName, |
| 2626 | IrInstSrcIdTagType, | |
| 2627 | 2625 | IrInstSrcIdFieldParentPtr, |
| 2628 | 2626 | IrInstSrcIdByteOffsetOf, |
| 2629 | 2627 | IrInstSrcIdBitOffsetOf, |
| ... | ... | @@ -4074,12 +4072,6 @@ struct IrInstGenTagName { |
| 4074 | 4072 | IrInstGen *target; |
| 4075 | 4073 | }; |
| 4076 | 4074 | |
| 4077 | struct IrInstSrcTagType { | |
| 4078 | IrInstSrc base; | |
| 4079 | ||
| 4080 | IrInstSrc *target; | |
| 4081 | }; | |
| 4082 | ||
| 4083 | 4075 | struct IrInstSrcFieldParentPtr { |
| 4084 | 4076 | IrInstSrc base; |
| 4085 | 4077 |
src/stage1/analyze.cpp+1-1| ... | ... | @@ -3267,7 +3267,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3267 | 3267 | |
| 3268 | 3268 | tag_type = new_type_table_entry(ZigTypeIdEnum); |
| 3269 | 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 | 3271 | tag_type->llvm_type = tag_int_type->llvm_type; |
| 3272 | 3272 | tag_type->llvm_di_type = tag_int_type->llvm_di_type; |
| 3273 | 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 | 8842 | create_builtin_fn(g, BuiltinFnIdIntToPtr, "intToPtr", 2); |
| 8843 | 8843 | create_builtin_fn(g, BuiltinFnIdPtrToInt, "ptrToInt", 1); |
| 8844 | 8844 | create_builtin_fn(g, BuiltinFnIdTagName, "tagName", 1); |
| 8845 | create_builtin_fn(g, BuiltinFnIdTagType, "TagType", 1); | |
| 8846 | 8845 | create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3); |
| 8847 | 8846 | create_builtin_fn(g, BuiltinFnIdByteOffsetOf, "byteOffsetOf", 2); |
| 8848 | 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 | 516 | return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst)); |
| 517 | 517 | case IrInstSrcIdArgType: |
| 518 | 518 | return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArgType *>(inst)); |
| 519 | case IrInstSrcIdTagType: | |
| 520 | return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagType *>(inst)); | |
| 521 | 519 | case IrInstSrcIdExport: |
| 522 | 520 | return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcExport *>(inst)); |
| 523 | 521 | case IrInstSrcIdExtern: |
| ... | ... | @@ -1496,10 +1494,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) { |
| 1496 | 1494 | return IrInstSrcIdTagName; |
| 1497 | 1495 | } |
| 1498 | 1496 | |
| 1499 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) { | |
| 1500 | return IrInstSrcIdTagType; | |
| 1501 | } | |
| 1502 | ||
| 1503 | 1497 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) { |
| 1504 | 1498 | return IrInstSrcIdFieldParentPtr; |
| 1505 | 1499 | } |
| ... | ... | @@ -4450,17 +4444,6 @@ static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir |
| 4450 | 4444 | return &instruction->base; |
| 4451 | 4445 | } |
| 4452 | 4446 | |
| 4453 | static 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 | ||
| 4464 | 4447 | static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4465 | 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 | 7185 | IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value); |
| 7203 | 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 | 7188 | case BuiltinFnIdFieldParentPtr: |
| 7216 | 7189 | { |
| 7217 | 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 | 31024 | return ir_const_type(ira, &instruction->base.base, result_type); |
| 31052 | 31025 | } |
| 31053 | 31026 | |
| 31054 | static 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 | ||
| 31078 | 31027 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 31079 | 31028 | ZigType *operand_type = ir_resolve_type(ira, op); |
| 31080 | 31029 | if (type_is_invalid(operand_type)) |
| ... | ... | @@ -32435,8 +32384,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc |
| 32435 | 32384 | return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction); |
| 32436 | 32385 | case IrInstSrcIdArgType: |
| 32437 | 32386 | return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction); |
| 32438 | case IrInstSrcIdTagType: | |
| 32439 | return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction); | |
| 32440 | 32387 | case IrInstSrcIdExport: |
| 32441 | 32388 | return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction); |
| 32442 | 32389 | case IrInstSrcIdExtern: |
| ... | ... | @@ -32879,7 +32826,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) { |
| 32879 | 32826 | case IrInstSrcIdImplicitCast: |
| 32880 | 32827 | case IrInstSrcIdResolveResult: |
| 32881 | 32828 | case IrInstSrcIdArgType: |
| 32882 | case IrInstSrcIdTagType: | |
| 32883 | 32829 | case IrInstSrcIdErrorReturnTrace: |
| 32884 | 32830 | case IrInstSrcIdErrorUnion: |
| 32885 | 32831 | case IrInstSrcIdFloatOp: |
src/stage1/ir_print.cpp-11| ... | ... | @@ -282,8 +282,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) { |
| 282 | 282 | return "SrcPanic"; |
| 283 | 283 | case IrInstSrcIdTagName: |
| 284 | 284 | return "SrcTagName"; |
| 285 | case IrInstSrcIdTagType: | |
| 286 | return "SrcTagType"; | |
| 287 | 285 | case IrInstSrcIdFieldParentPtr: |
| 288 | 286 | return "SrcFieldParentPtr"; |
| 289 | 287 | case IrInstSrcIdByteOffsetOf: |
| ... | ... | @@ -2354,12 +2352,6 @@ static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) { |
| 2354 | 2352 | fprintf(irp->f, ")"); |
| 2355 | 2353 | } |
| 2356 | 2354 | |
| 2357 | static 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 | ||
| 2363 | 2355 | static void ir_print_export(IrPrintSrc *irp, IrInstSrcExport *instruction) { |
| 2364 | 2356 | fprintf(irp->f, "@export("); |
| 2365 | 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 | 2945 | case IrInstSrcIdArgType: |
| 2954 | 2946 | ir_print_arg_type(irp, (IrInstSrcArgType *)instruction); |
| 2955 | 2947 | break; |
| 2956 | case IrInstSrcIdTagType: | |
| 2957 | ir_print_enum_tag_type(irp, (IrInstSrcTagType *)instruction); | |
| 2958 | break; | |
| 2959 | 2948 | case IrInstSrcIdExport: |
| 2960 | 2949 | ir_print_export(irp, (IrInstSrcExport *)instruction); |
| 2961 | 2950 | break; |