zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 0f677810ea9d5c8ba549f6c9948979a768a1eda6 (tree)
parent 083c0f1cebc763e4e43529b50f6df9839c32c1c7
Author: Tadeo Kondrak <me@tadeo.ca>
Date:   Wed, 19 Aug 2020 13:49:20 -0600

Remove offset field from TypeInfo.StructField

This isn't needed with @bitOffsetOf/@byteoffsetOf and complicates
@Type handling.

Diffstat:
Mlib/std/builtin.zig | 1-
Msrc/ir.cpp | 31+++++++------------------------
Mtest/stage1/behavior/type_info.zig | 11-----------
3 files changed, 7 insertions(+), 36 deletions(-)

diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig @@ -254,7 +254,6 @@ pub const TypeInfo = union(enum) { /// therefore must be kept in sync with the compiler implementation. pub const StructField = struct { name: []const u8, - offset: ?comptime_int, field_type: type, default_value: anytype, }; diff --git a/src/ir.cpp b/src/ir.cpp @@ -25678,37 +25678,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy struct_field_val->type = type_info_struct_field_type; ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 4); - inner_fields[1]->special = ConstValSpecialStatic; - inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int); - - ZigType *field_type = resolve_struct_field_type(ira->codegen, struct_field); - if (field_type == nullptr) - return ErrorSemanticAnalyzeFail; - if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown))) - return err; - if (!type_has_bits(ira->codegen, struct_field->type_entry)) { - inner_fields[1]->data.x_optional = nullptr; - } else { - size_t byte_offset = struct_field->offset; - inner_fields[1]->data.x_optional = ira->codegen->pass1_arena->create<ZigValue>(); - inner_fields[1]->data.x_optional->special = ConstValSpecialStatic; - inner_fields[1]->data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int; - bigint_init_unsigned(&inner_fields[1]->data.x_optional->data.x_bigint, byte_offset); - } - inner_fields[2]->special = ConstValSpecialStatic; - inner_fields[2]->type = ira->codegen->builtin_types.entry_type; - inner_fields[2]->data.x_type = struct_field->type_entry; + inner_fields[1]->special = ConstValSpecialStatic; + inner_fields[1]->type = ira->codegen->builtin_types.entry_type; + inner_fields[1]->data.x_type = struct_field->type_entry; // default_value: anytype - inner_fields[3]->special = ConstValSpecialStatic; - inner_fields[3]->type = get_optional_type2(ira->codegen, struct_field->type_entry); - if (inner_fields[3]->type == nullptr) return ErrorSemanticAnalyzeFail; + inner_fields[2]->special = ConstValSpecialStatic; + inner_fields[2]->type = get_optional_type2(ira->codegen, struct_field->type_entry); + if (inner_fields[2]->type == nullptr) return ErrorSemanticAnalyzeFail; memoize_field_init_val(ira->codegen, type_entry, struct_field); if(struct_field->init_val != nullptr && type_is_invalid(struct_field->init_val->type)){ return ErrorSemanticAnalyzeFail; } - set_optional_payload(inner_fields[3], struct_field->init_val); + set_optional_payload(inner_fields[2], struct_field->init_val); ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee; init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true); diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig @@ -238,7 +238,6 @@ fn testStruct() void { expect(struct_info == .Struct); expect(struct_info.Struct.layout == .Packed); expect(struct_info.Struct.fields.len == 4); - expect(struct_info.Struct.fields[1].offset == null); expect(struct_info.Struct.fields[2].field_type == *TestStruct); expect(struct_info.Struct.fields[2].default_value == null); expect(struct_info.Struct.fields[3].default_value.? == 4); @@ -320,16 +319,6 @@ fn testAnyFrame() void { } } -test "type info: optional field unwrapping" { - const Struct = struct { - cdOffset: u32, - }; - - const field = @typeInfo(Struct).Struct.fields[0]; - - _ = field.offset orelse 0; -} - test "type info: pass to function" { _ = passTypeInfo(@typeInfo(void)); _ = comptime passTypeInfo(@typeInfo(void));