authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-02-24 23:21:11+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-02-24 23:21:11+02:00
log3458fb891d8c7072a9bff6a32db9f3105ab72aa4
treee942a2f76b1d2a9f4fb7ee5373161f893db511ba
parent45da72c5b64069b7d5238465130a50f96678a148
signaturelock-open Commit is signed but in an unrecognized format.

remove `@typeId`, `@memberCount`, `@memberName` and `@memberType` from the compiler


5 files changed, 8 insertions(+), 444 deletions(-)

doc/langref.html.in+8-76
......@@ -2810,14 +2810,10 @@ test "@TagType" {
28102810 assert(@TagType(Small) == u2);
28112811}
28122812
2813// @memberCount tells how many fields an enum has:
2814test "@memberCount" {
2815 assert(@memberCount(Small) == 4);
2816}
2817
2818// @memberName tells the name of a field in an enum:
2819test "@memberName" {
2820 assert(mem.eql(u8, @memberName(Small, 1), "Two"));
2813// @typeInfo tells us the field count and the fields name:
2814test "@typeInfo" {
2815 assert(@typeInfo(Small).Enum.fields.len == 4);
2816 assert(mem.eql(u8, @typeInfo(Small).Enum.fields[0].name, "Two"));
28212817}
28222818
28232819// @tagName gives a []const u8 representation of an enum value:
......@@ -2825,7 +2821,7 @@ test "@tagName" {
28252821 assert(mem.eql(u8, @tagName(Small.Three), "Three"));
28262822}
28272823 {#code_end#}
2828 {#see_also|@memberName|@memberCount|@tagName|@sizeOf#}
2824 {#see_also|@typeInfo|@tagName|@sizeOf#}
28292825
28302826 {#header_open|extern enum#}
28312827 <p>
......@@ -6816,7 +6812,7 @@ async fn func(y: *i32) void {
68166812 Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
68176813 </p>
68186814 <p>
6819 Asserts that {#syntax#}@typeId(DestType) != @import("builtin").TypeId.Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@intToPtr{#endsyntax#} if you need this.
6815 Asserts that {#syntax#}@typeInfo(DestType) != .Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@intToPtr{#endsyntax#} if you need this.
68206816 </p>
68216817 <p>
68226818 Can be used for these things for example:
......@@ -7269,7 +7265,7 @@ test "main" {
72697265 <p>
72707266 Floored division. Rounds toward negative infinity. For unsigned integers it is
72717267 the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
7272 {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
7268 {#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
72737269 </p>
72747270 <ul>
72757271 <li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li>
......@@ -7283,7 +7279,7 @@ test "main" {
72837279 <p>
72847280 Truncated division. Rounds toward zero. For unsigned integers it is
72857281 the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
7286 {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
7282 {#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
72877283 </p>
72887284 <ul>
72897285 <li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li>
......@@ -7679,33 +7675,6 @@ test "@hasDecl" {
76797675 </p>
76807676 {#header_close#}
76817677
7682 {#header_open|@memberCount#}
7683 <pre>{#syntax#}@memberCount(comptime T: type) comptime_int{#endsyntax#}</pre>
7684 <p>
7685 This function returns the number of members in a struct, enum, or union type.
7686 </p>
7687 <p>
7688 The result is a compile time constant.
7689 </p>
7690 <p>
7691 It does not include functions, variables, or constants.
7692 </p>
7693 {#header_close#}
7694 {#header_open|@memberName#}
7695 <pre>{#syntax#}@memberName(comptime T: type, comptime index: usize) [N]u8{#endsyntax#}</pre>
7696 <p>Returns the field name of a struct, union, or enum.</p>
7697 <p>
7698 The result is a compile time constant.
7699 </p>
7700 <p>
7701 It does not include functions, variables, or constants.
7702 </p>
7703 {#header_close#}
7704 {#header_open|@memberType#}
7705 <pre>{#syntax#}@memberType(comptime T: type, comptime index: usize) type{#endsyntax#}</pre>
7706 <p>Returns the field type of a struct or union.</p>
7707 {#header_close#}
7708
77097678 {#header_open|@memcpy#}
77107679 <pre>{#syntax#}@memcpy(noalias dest: [*]u8, noalias source: [*]const u8, byte_count: usize){#endsyntax#}</pre>
77117680 <p>
......@@ -8401,43 +8370,6 @@ test "integer truncation" {
84018370 <li>{#link|struct#}</li>
84028371 </ul>
84038372 {#header_close#}
8404
8405 {#header_open|@typeId#}
8406 <pre>{#syntax#}@typeId(comptime T: type) @import("builtin").TypeId{#endsyntax#}</pre>
8407 <p>
8408 Returns which kind of type something is. Possible values:
8409 </p>
8410 {#code_begin|syntax#}
8411pub const TypeId = enum {
8412 Type,
8413 Void,
8414 Bool,
8415 NoReturn,
8416 Int,
8417 Float,
8418 Pointer,
8419 Array,
8420 Struct,
8421 ComptimeFloat,
8422 ComptimeInt,
8423 Undefined,
8424 Null,
8425 Optional,
8426 ErrorUnion,
8427 ErrorSet,
8428 Enum,
8429 Union,
8430 Fn,
8431 BoundFn,
8432 Opaque,
8433 Frame,
8434 AnyFrame,
8435 Vector,
8436 EnumLiteral,
8437};
8438 {#code_end#}
8439 {#header_close#}
8440
84418373 {#header_open|@typeInfo#}
84428374 <pre>{#syntax#}@typeInfo(comptime T: type) @import("std").builtin.TypeInfo{#endsyntax#}</pre>
84438375 <p>
src/all_types.hpp-34
......@@ -1695,9 +1695,6 @@ enum BuiltinFnId {
16951695 BuiltinFnIdMemset,
16961696 BuiltinFnIdSizeof,
16971697 BuiltinFnIdAlignOf,
1698 BuiltinFnIdMemberCount,
1699 BuiltinFnIdMemberType,
1700 BuiltinFnIdMemberName,
17011698 BuiltinFnIdField,
17021699 BuiltinFnIdTypeInfo,
17031700 BuiltinFnIdType,
......@@ -1777,7 +1774,6 @@ enum BuiltinFnId {
17771774 BuiltinFnIdBitOffsetOf,
17781775 BuiltinFnIdNewStackCall,
17791776 BuiltinFnIdAsyncCall,
1780 BuiltinFnIdTypeId,
17811777 BuiltinFnIdShlExact,
17821778 BuiltinFnIdShrExact,
17831779 BuiltinFnIdSetEvalBranchQuota,
......@@ -2638,9 +2634,6 @@ enum IrInstSrcId {
26382634 IrInstSrcIdMemset,
26392635 IrInstSrcIdMemcpy,
26402636 IrInstSrcIdSlice,
2641 IrInstSrcIdMemberCount,
2642 IrInstSrcIdMemberType,
2643 IrInstSrcIdMemberName,
26442637 IrInstSrcIdBreakpoint,
26452638 IrInstSrcIdReturnAddress,
26462639 IrInstSrcIdFrameAddress,
......@@ -2677,7 +2670,6 @@ enum IrInstSrcId {
26772670 IrInstSrcIdTypeInfo,
26782671 IrInstSrcIdType,
26792672 IrInstSrcIdHasField,
2680 IrInstSrcIdTypeId,
26812673 IrInstSrcIdSetEvalBranchQuota,
26822674 IrInstSrcIdPtrType,
26832675 IrInstSrcIdAlignCast,
......@@ -3715,26 +3707,6 @@ struct IrInstGenSlice {
37153707 bool safety_check_on;
37163708};
37173709
3718struct IrInstSrcMemberCount {
3719 IrInstSrc base;
3720
3721 IrInstSrc *container;
3722};
3723
3724struct IrInstSrcMemberType {
3725 IrInstSrc base;
3726
3727 IrInstSrc *container_type;
3728 IrInstSrc *member_index;
3729};
3730
3731struct IrInstSrcMemberName {
3732 IrInstSrc base;
3733
3734 IrInstSrc *container_type;
3735 IrInstSrc *member_index;
3736};
3737
37383710struct IrInstSrcBreakpoint {
37393711 IrInstSrc base;
37403712};
......@@ -4142,12 +4114,6 @@ struct IrInstSrcHasField {
41424114 IrInstSrc *field_name;
41434115};
41444116
4145struct IrInstSrcTypeId {
4146 IrInstSrc base;
4147
4148 IrInstSrc *type_value;
4149};
4150
41514117struct IrInstSrcSetEvalBranchQuota {
41524118 IrInstSrc base;
41534119
src/codegen.cpp-4
......@@ -8152,9 +8152,6 @@ static void define_builtin_fns(CodeGen *g) {
81528152 create_builtin_fn(g, BuiltinFnIdMemset, "memset", 3);
81538153 create_builtin_fn(g, BuiltinFnIdSizeof, "sizeOf", 1);
81548154 create_builtin_fn(g, BuiltinFnIdAlignOf, "alignOf", 1);
8155 create_builtin_fn(g, BuiltinFnIdMemberCount, "memberCount", 1);
8156 create_builtin_fn(g, BuiltinFnIdMemberType, "memberType", 2);
8157 create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2);
81588155 create_builtin_fn(g, BuiltinFnIdField, "field", 2);
81598156 create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1);
81608157 create_builtin_fn(g, BuiltinFnIdType, "Type", 1);
......@@ -8231,7 +8228,6 @@ static void define_builtin_fns(CodeGen *g) {
82318228 create_builtin_fn(g, BuiltinFnIdMulAdd, "mulAdd", 4);
82328229 create_builtin_fn(g, BuiltinFnIdNewStackCall, "newStackCall", SIZE_MAX);
82338230 create_builtin_fn(g, BuiltinFnIdAsyncCall, "asyncCall", SIZE_MAX);
8234 create_builtin_fn(g, BuiltinFnIdTypeId, "typeId", 1);
82358231 create_builtin_fn(g, BuiltinFnIdShlExact, "shlExact", 2);
82368232 create_builtin_fn(g, BuiltinFnIdShrExact, "shrExact", 2);
82378233 create_builtin_fn(g, BuiltinFnIdSetEvalBranchQuota, "setEvalBranchQuota", 1);
src/ir.cpp-282
......@@ -405,12 +405,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
405405 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst));
406406 case IrInstSrcIdSlice:
407407 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSlice *>(inst));
408 case IrInstSrcIdMemberCount:
409 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst));
410 case IrInstSrcIdMemberType:
411 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberType *>(inst));
412 case IrInstSrcIdMemberName:
413 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberName *>(inst));
414408 case IrInstSrcIdBreakpoint:
415409 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst));
416410 case IrInstSrcIdReturnAddress:
......@@ -477,8 +471,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
477471 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcType *>(inst));
478472 case IrInstSrcIdHasField:
479473 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasField *>(inst));
480 case IrInstSrcIdTypeId:
481 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeId *>(inst));
482474 case IrInstSrcIdSetEvalBranchQuota:
483475 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst));
484476 case IrInstSrcIdAlignCast:
......@@ -1325,18 +1317,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {
13251317 return IrInstSrcIdSlice;
13261318}
13271319
1328static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) {
1329 return IrInstSrcIdMemberCount;
1330}
1331
1332static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) {
1333 return IrInstSrcIdMemberType;
1334}
1335
1336static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) {
1337 return IrInstSrcIdMemberName;
1338}
1339
13401320static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {
13411321 return IrInstSrcIdBreakpoint;
13421322}
......@@ -1481,10 +1461,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {
14811461 return IrInstSrcIdHasField;
14821462}
14831463
1484static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) {
1485 return IrInstSrcIdTypeId;
1486}
1487
14881464static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {
14891465 return IrInstSrcIdSetEvalBranchQuota;
14901466}
......@@ -3749,41 +3725,6 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction,
37493725 return &instruction->base;
37503726}
37513727
3752static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) {
3753 IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node);
3754 instruction->container = container;
3755
3756 ir_ref_instruction(container, irb->current_basic_block);
3757
3758 return &instruction->base;
3759}
3760
3761static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3762 IrInstSrc *container_type, IrInstSrc *member_index)
3763{
3764 IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node);
3765 instruction->container_type = container_type;
3766 instruction->member_index = member_index;
3767
3768 ir_ref_instruction(container_type, irb->current_basic_block);
3769 ir_ref_instruction(member_index, irb->current_basic_block);
3770
3771 return &instruction->base;
3772}
3773
3774static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3775 IrInstSrc *container_type, IrInstSrc *member_index)
3776{
3777 IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node);
3778 instruction->container_type = container_type;
3779 instruction->member_index = member_index;
3780
3781 ir_ref_instruction(container_type, irb->current_basic_block);
3782 ir_ref_instruction(member_index, irb->current_basic_block);
3783
3784 return &instruction->base;
3785}
3786
37873728static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
37883729 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
37893730 return &instruction->base;
......@@ -4458,15 +4399,6 @@ static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source
44584399 return &instruction->base;
44594400}
44604401
4461static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
4462 IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node);
4463 instruction->type_value = type_value;
4464
4465 ir_ref_instruction(type_value, irb->current_basic_block);
4466
4467 return &instruction->base;
4468}
4469
44704402static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
44714403 IrInstSrc *new_quota)
44724404{
......@@ -6710,48 +6642,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
67106642 IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
67116643 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
67126644 }
6713 case BuiltinFnIdMemberCount:
6714 {
6715 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6716 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6717 if (arg0_value == irb->codegen->invalid_inst_src)
6718 return arg0_value;
6719
6720 IrInstSrc *member_count = ir_build_member_count(irb, scope, node, arg0_value);
6721 return ir_lval_wrap(irb, scope, member_count, lval, result_loc);
6722 }
6723 case BuiltinFnIdMemberType:
6724 {
6725 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6726 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6727 if (arg0_value == irb->codegen->invalid_inst_src)
6728 return arg0_value;
6729
6730 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6731 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6732 if (arg1_value == irb->codegen->invalid_inst_src)
6733 return arg1_value;
6734
6735
6736 IrInstSrc *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);
6737 return ir_lval_wrap(irb, scope, member_type, lval, result_loc);
6738 }
6739 case BuiltinFnIdMemberName:
6740 {
6741 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6742 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6743 if (arg0_value == irb->codegen->invalid_inst_src)
6744 return arg0_value;
6745
6746 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6747 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6748 if (arg1_value == irb->codegen->invalid_inst_src)
6749 return arg1_value;
6750
6751
6752 IrInstSrc *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);
6753 return ir_lval_wrap(irb, scope, member_name, lval, result_loc);
6754 }
67556645 case BuiltinFnIdField:
67566646 {
67576647 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
......@@ -7109,16 +6999,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
71096999 }
71107000 case BuiltinFnIdAsyncCall:
71117001 return ir_gen_async_call(irb, scope, nullptr, node, lval, result_loc);
7112 case BuiltinFnIdTypeId:
7113 {
7114 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
7115 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7116 if (arg0_value == irb->codegen->invalid_inst_src)
7117 return arg0_value;
7118
7119 IrInstSrc *type_id = ir_build_type_id(irb, scope, node, arg0_value);
7120 return ir_lval_wrap(irb, scope, type_id, lval, result_loc);
7121 }
71227002 case BuiltinFnIdShlExact:
71237003 {
71247004 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
......@@ -24795,19 +24675,6 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins
2479524675 return ir_const_type(ira, &instruction->base.base, type);
2479624676}
2479724677
24798static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) {
24799 IrInstGen *type_value = instruction->type_value->child;
24800 ZigType *type_entry = ir_resolve_type(ira, type_value);
24801 if (type_is_invalid(type_entry))
24802 return ira->codegen->invalid_inst_gen;
24803
24804 ZigType *result_type = get_builtin_type(ira->codegen, "TypeId");
24805
24806 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
24807 bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));
24808 return result;
24809}
24810
2481124678static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
2481224679 IrInstSrcSetEvalBranchQuota *instruction)
2481324680{
......@@ -26445,143 +26312,6 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
2644526312 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
2644626313}
2644726314
26448static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) {
26449 Error err;
26450 IrInstGen *container = instruction->container->child;
26451 if (type_is_invalid(container->value->type))
26452 return ira->codegen->invalid_inst_gen;
26453 ZigType *container_type = ir_resolve_type(ira, container);
26454
26455 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
26456 return ira->codegen->invalid_inst_gen;
26457
26458 uint64_t result;
26459 if (type_is_invalid(container_type)) {
26460 return ira->codegen->invalid_inst_gen;
26461 } else if (container_type->id == ZigTypeIdEnum) {
26462 result = container_type->data.enumeration.src_field_count;
26463 } else if (container_type->id == ZigTypeIdStruct) {
26464 result = container_type->data.structure.src_field_count;
26465 } else if (container_type->id == ZigTypeIdUnion) {
26466 result = container_type->data.unionation.src_field_count;
26467 } else if (container_type->id == ZigTypeIdErrorSet) {
26468 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) {
26469 return ira->codegen->invalid_inst_gen;
26470 }
26471 if (type_is_global_error_set(container_type)) {
26472 ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime"));
26473 return ira->codegen->invalid_inst_gen;
26474 }
26475 result = container_type->data.error_set.err_count;
26476 } else {
26477 ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
26478 return ira->codegen->invalid_inst_gen;
26479 }
26480
26481 return ir_const_unsigned(ira, &instruction->base.base, result);
26482}
26483
26484static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) {
26485 Error err;
26486 IrInstGen *container_type_value = instruction->container_type->child;
26487 ZigType *container_type = ir_resolve_type(ira, container_type_value);
26488 if (type_is_invalid(container_type))
26489 return ira->codegen->invalid_inst_gen;
26490
26491 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
26492 return ira->codegen->invalid_inst_gen;
26493
26494
26495 uint64_t member_index;
26496 IrInstGen *index_value = instruction->member_index->child;
26497 if (!ir_resolve_usize(ira, index_value, &member_index))
26498 return ira->codegen->invalid_inst_gen;
26499
26500 if (container_type->id == ZigTypeIdStruct) {
26501 if (member_index >= container_type->data.structure.src_field_count) {
26502 ir_add_error(ira, &index_value->base,
26503 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26504 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
26505 return ira->codegen->invalid_inst_gen;
26506 }
26507 TypeStructField *field = container_type->data.structure.fields[member_index];
26508
26509 return ir_const_type(ira, &instruction->base.base, field->type_entry);
26510 } else if (container_type->id == ZigTypeIdUnion) {
26511 if (member_index >= container_type->data.unionation.src_field_count) {
26512 ir_add_error(ira, &index_value->base,
26513 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26514 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
26515 return ira->codegen->invalid_inst_gen;
26516 }
26517 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
26518
26519 return ir_const_type(ira, &instruction->base.base, field->type_entry);
26520 } else {
26521 ir_add_error(ira, &container_type_value->base,
26522 buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name)));
26523 return ira->codegen->invalid_inst_gen;
26524 }
26525}
26526
26527static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) {
26528 Error err;
26529 IrInstGen *container_type_value = instruction->container_type->child;
26530 ZigType *container_type = ir_resolve_type(ira, container_type_value);
26531 if (type_is_invalid(container_type))
26532 return ira->codegen->invalid_inst_gen;
26533
26534 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
26535 return ira->codegen->invalid_inst_gen;
26536
26537 uint64_t member_index;
26538 IrInstGen *index_value = instruction->member_index->child;
26539 if (!ir_resolve_usize(ira, index_value, &member_index))
26540 return ira->codegen->invalid_inst_gen;
26541
26542 if (container_type->id == ZigTypeIdStruct) {
26543 if (member_index >= container_type->data.structure.src_field_count) {
26544 ir_add_error(ira, &index_value->base,
26545 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26546 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
26547 return ira->codegen->invalid_inst_gen;
26548 }
26549 TypeStructField *field = container_type->data.structure.fields[member_index];
26550
26551 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
26552 init_const_str_lit(ira->codegen, result->value, field->name);
26553 return result;
26554 } else if (container_type->id == ZigTypeIdEnum) {
26555 if (member_index >= container_type->data.enumeration.src_field_count) {
26556 ir_add_error(ira, &index_value->base,
26557 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26558 member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count));
26559 return ira->codegen->invalid_inst_gen;
26560 }
26561 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];
26562
26563 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
26564 init_const_str_lit(ira->codegen, result->value, field->name);
26565 return result;
26566 } else if (container_type->id == ZigTypeIdUnion) {
26567 if (member_index >= container_type->data.unionation.src_field_count) {
26568 ir_add_error(ira, &index_value->base,
26569 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26570 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
26571 return ira->codegen->invalid_inst_gen;
26572 }
26573 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
26574
26575 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
26576 init_const_str_lit(ira->codegen, result->value, field->name);
26577 return result;
26578 } else {
26579 ir_add_error(ira, &container_type_value->base,
26580 buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name)));
26581 return ira->codegen->invalid_inst_gen;
26582 }
26583}
26584
2658526315static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {
2658626316 Error err;
2658726317 ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);
......@@ -29556,12 +29286,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
2955629286 return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);
2955729287 case IrInstSrcIdSlice:
2955829288 return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction);
29559 case IrInstSrcIdMemberCount:
29560 return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction);
29561 case IrInstSrcIdMemberType:
29562 return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction);
29563 case IrInstSrcIdMemberName:
29564 return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction);
2956529289 case IrInstSrcIdBreakpoint:
2956629290 return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);
2956729291 case IrInstSrcIdReturnAddress:
......@@ -29616,8 +29340,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
2961629340 return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);
2961729341 case IrInstSrcIdHasField:
2961829342 return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);
29619 case IrInstSrcIdTypeId:
29620 return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction);
2962129343 case IrInstSrcIdSetEvalBranchQuota:
2962229344 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);
2962329345 case IrInstSrcIdPtrType:
......@@ -30038,9 +29760,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
3003829760 case IrInstSrcIdSplat:
3003929761 case IrInstSrcIdBoolNot:
3004029762 case IrInstSrcIdSlice:
30041 case IrInstSrcIdMemberCount:
30042 case IrInstSrcIdMemberType:
30043 case IrInstSrcIdMemberName:
3004429763 case IrInstSrcIdAlignOf:
3004529764 case IrInstSrcIdReturnAddress:
3004629765 case IrInstSrcIdFrameAddress:
......@@ -30067,7 +29786,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
3006729786 case IrInstSrcIdTypeInfo:
3006829787 case IrInstSrcIdType:
3006929788 case IrInstSrcIdHasField:
30070 case IrInstSrcIdTypeId:
3007129789 case IrInstSrcIdAlignCast:
3007229790 case IrInstSrcIdImplicitCast:
3007329791 case IrInstSrcIdResolveResult:
src/ir_print.cpp-48
......@@ -191,12 +191,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
191191 return "SrcMemcpy";
192192 case IrInstSrcIdSlice:
193193 return "SrcSlice";
194 case IrInstSrcIdMemberCount:
195 return "SrcMemberCount";
196 case IrInstSrcIdMemberType:
197 return "SrcMemberType";
198 case IrInstSrcIdMemberName:
199 return "SrcMemberName";
200194 case IrInstSrcIdBreakpoint:
201195 return "SrcBreakpoint";
202196 case IrInstSrcIdReturnAddress:
......@@ -269,8 +263,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
269263 return "SrcType";
270264 case IrInstSrcIdHasField:
271265 return "SrcHasField";
272 case IrInstSrcIdTypeId:
273 return "SrcTypeId";
274266 case IrInstSrcIdSetEvalBranchQuota:
275267 return "SrcSetEvalBranchQuota";
276268 case IrInstSrcIdPtrType:
......@@ -1784,28 +1776,6 @@ static void ir_print_slice_gen(IrPrintGen *irp, IrInstGenSlice *instruction) {
17841776 ir_print_other_inst_gen(irp, instruction->result_loc);
17851777}
17861778
1787static void ir_print_member_count(IrPrintSrc *irp, IrInstSrcMemberCount *instruction) {
1788 fprintf(irp->f, "@memberCount(");
1789 ir_print_other_inst_src(irp, instruction->container);
1790 fprintf(irp->f, ")");
1791}
1792
1793static void ir_print_member_type(IrPrintSrc *irp, IrInstSrcMemberType *instruction) {
1794 fprintf(irp->f, "@memberType(");
1795 ir_print_other_inst_src(irp, instruction->container_type);
1796 fprintf(irp->f, ", ");
1797 ir_print_other_inst_src(irp, instruction->member_index);
1798 fprintf(irp->f, ")");
1799}
1800
1801static void ir_print_member_name(IrPrintSrc *irp, IrInstSrcMemberName *instruction) {
1802 fprintf(irp->f, "@memberName(");
1803 ir_print_other_inst_src(irp, instruction->container_type);
1804 fprintf(irp->f, ", ");
1805 ir_print_other_inst_src(irp, instruction->member_index);
1806 fprintf(irp->f, ")");
1807}
1808
18091779static void ir_print_breakpoint(IrPrintSrc *irp, IrInstSrcBreakpoint *instruction) {
18101780 fprintf(irp->f, "@breakpoint()");
18111781}
......@@ -2279,12 +2249,6 @@ static void ir_print_has_field(IrPrintSrc *irp, IrInstSrcHasField *instruction)
22792249 fprintf(irp->f, ")");
22802250}
22812251
2282static void ir_print_type_id(IrPrintSrc *irp, IrInstSrcTypeId *instruction) {
2283 fprintf(irp->f, "@typeId(");
2284 ir_print_other_inst_src(irp, instruction->type_value);
2285 fprintf(irp->f, ")");
2286}
2287
22882252static void ir_print_set_eval_branch_quota(IrPrintSrc *irp, IrInstSrcSetEvalBranchQuota *instruction) {
22892253 fprintf(irp->f, "@setEvalBranchQuota(");
22902254 ir_print_other_inst_src(irp, instruction->new_quota);
......@@ -2799,15 +2763,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
27992763 case IrInstSrcIdSlice:
28002764 ir_print_slice_src(irp, (IrInstSrcSlice *)instruction);
28012765 break;
2802 case IrInstSrcIdMemberCount:
2803 ir_print_member_count(irp, (IrInstSrcMemberCount *)instruction);
2804 break;
2805 case IrInstSrcIdMemberType:
2806 ir_print_member_type(irp, (IrInstSrcMemberType *)instruction);
2807 break;
2808 case IrInstSrcIdMemberName:
2809 ir_print_member_name(irp, (IrInstSrcMemberName *)instruction);
2810 break;
28112766 case IrInstSrcIdBreakpoint:
28122767 ir_print_breakpoint(irp, (IrInstSrcBreakpoint *)instruction);
28132768 break;
......@@ -2907,9 +2862,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
29072862 case IrInstSrcIdHasField:
29082863 ir_print_has_field(irp, (IrInstSrcHasField *)instruction);
29092864 break;
2910 case IrInstSrcIdTypeId:
2911 ir_print_type_id(irp, (IrInstSrcTypeId *)instruction);
2912 break;
29132865 case IrInstSrcIdSetEvalBranchQuota:
29142866 ir_print_set_eval_branch_quota(irp, (IrInstSrcSetEvalBranchQuota *)instruction);
29152867 break;