mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
remove @TagType
This commit is contained in:
parent
b7767eb834
commit
1637d8ac80
@ -3092,8 +3092,7 @@ test "simple union" {
|
||||
{#header_open|Tagged union#}
|
||||
<p>Unions can be declared with an enum tag type.
|
||||
This turns the union into a <em>tagged</em> 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#}.
|
||||
</p>
|
||||
{#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#}
|
||||
<pre>{#syntax#}@intToEnum(comptime DestType: type, int_value: @TagType(DestType)) DestType{#endsyntax#}</pre>
|
||||
<pre>{#syntax#}@intToEnum(comptime DestType: type, int_value: std.meta.Tag(DestType)) DestType{#endsyntax#}</pre>
|
||||
<p>
|
||||
Converts an integer into an {#link|enum#} value.
|
||||
</p>
|
||||
@ -8435,16 +8434,6 @@ fn doTheTest() void {
|
||||
</p>
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@TagType#}
|
||||
<pre>{#syntax#}@TagType(T: type) type{#endsyntax#}</pre>
|
||||
<p>
|
||||
For an enum, returns the integer type that is used to store the enumeration value.
|
||||
</p>
|
||||
<p>
|
||||
For a union, returns the enum type that is used to store the tag value.
|
||||
</p>
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@This#}
|
||||
<pre>{#syntax#}@This() type{#endsyntax#}</pre>
|
||||
<p>
|
||||
|
||||
@ -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 },
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -516,8 +516,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst));
|
||||
case IrInstSrcIdArgType:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArgType *>(inst));
|
||||
case IrInstSrcIdTagType:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagType *>(inst));
|
||||
case IrInstSrcIdExport:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcExport *>(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<IrInstSrcTagType>(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:
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user