authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-08-19 13:49:20-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-08-19 14:55:40-06:00
log0f677810ea9d5c8ba549f6c9948979a768a1eda6
tree460060b1bb3b07f91465ea47ffbeb84bbc67ddba
parent083c0f1cebc763e4e43529b50f6df9839c32c1c7
signature Commit is signed but in an unrecognized format.

Remove offset field from TypeInfo.StructField

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

3 files changed, 7 insertions(+), 36 deletions(-)

lib/std/builtin.zig-1
...@@ -254,7 +254,6 @@ pub const TypeInfo = union(enum) {...@@ -254,7 +254,6 @@ pub const TypeInfo = union(enum) {
254 /// therefore must be kept in sync with the compiler implementation.254 /// therefore must be kept in sync with the compiler implementation.
255 pub const StructField = struct {255 pub const StructField = struct {
256 name: []const u8,256 name: []const u8,
257 offset: ?comptime_int,
258 field_type: type,257 field_type: type,
259 default_value: anytype,258 default_value: anytype,
260 };259 };
src/ir.cpp+7-24
...@@ -25678,37 +25678,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -25678,37 +25678,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
25678 struct_field_val->type = type_info_struct_field_type;25678 struct_field_val->type = type_info_struct_field_type;
2567925679
25680 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 4);25680 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 4);
25681 inner_fields[1]->special = ConstValSpecialStatic;
25682 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
25683
25684 ZigType *field_type = resolve_struct_field_type(ira->codegen, struct_field);
25685 if (field_type == nullptr)
25686 return ErrorSemanticAnalyzeFail;
25687 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))
25688 return err;
25689 if (!type_has_bits(ira->codegen, struct_field->type_entry)) {
25690 inner_fields[1]->data.x_optional = nullptr;
25691 } else {
25692 size_t byte_offset = struct_field->offset;
25693 inner_fields[1]->data.x_optional = ira->codegen->pass1_arena->create<ZigValue>();
25694 inner_fields[1]->data.x_optional->special = ConstValSpecialStatic;
25695 inner_fields[1]->data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int;
25696 bigint_init_unsigned(&inner_fields[1]->data.x_optional->data.x_bigint, byte_offset);
25697 }
2569825681
25699 inner_fields[2]->special = ConstValSpecialStatic;25682 inner_fields[1]->special = ConstValSpecialStatic;
25700 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;25683 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;
25701 inner_fields[2]->data.x_type = struct_field->type_entry;25684 inner_fields[1]->data.x_type = struct_field->type_entry;
2570225685
25703 // default_value: anytype25686 // default_value: anytype
25704 inner_fields[3]->special = ConstValSpecialStatic;25687 inner_fields[2]->special = ConstValSpecialStatic;
25705 inner_fields[3]->type = get_optional_type2(ira->codegen, struct_field->type_entry);25688 inner_fields[2]->type = get_optional_type2(ira->codegen, struct_field->type_entry);
25706 if (inner_fields[3]->type == nullptr) return ErrorSemanticAnalyzeFail;25689 if (inner_fields[2]->type == nullptr) return ErrorSemanticAnalyzeFail;
25707 memoize_field_init_val(ira->codegen, type_entry, struct_field);25690 memoize_field_init_val(ira->codegen, type_entry, struct_field);
25708 if(struct_field->init_val != nullptr && type_is_invalid(struct_field->init_val->type)){25691 if(struct_field->init_val != nullptr && type_is_invalid(struct_field->init_val->type)){
25709 return ErrorSemanticAnalyzeFail;25692 return ErrorSemanticAnalyzeFail;
25710 }25693 }
25711 set_optional_payload(inner_fields[3], struct_field->init_val);25694 set_optional_payload(inner_fields[2], struct_field->init_val);
2571225695
25713 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;25696 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
25714 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);25697 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
test/stage1/behavior/type_info.zig-11
...@@ -238,7 +238,6 @@ fn testStruct() void {...@@ -238,7 +238,6 @@ fn testStruct() void {
238 expect(struct_info == .Struct);238 expect(struct_info == .Struct);
239 expect(struct_info.Struct.layout == .Packed);239 expect(struct_info.Struct.layout == .Packed);
240 expect(struct_info.Struct.fields.len == 4);240 expect(struct_info.Struct.fields.len == 4);
241 expect(struct_info.Struct.fields[1].offset == null);
242 expect(struct_info.Struct.fields[2].field_type == *TestStruct);241 expect(struct_info.Struct.fields[2].field_type == *TestStruct);
243 expect(struct_info.Struct.fields[2].default_value == null);242 expect(struct_info.Struct.fields[2].default_value == null);
244 expect(struct_info.Struct.fields[3].default_value.? == 4);243 expect(struct_info.Struct.fields[3].default_value.? == 4);
...@@ -320,16 +319,6 @@ fn testAnyFrame() void {...@@ -320,16 +319,6 @@ fn testAnyFrame() void {
320 }319 }
321}320}
322321
323test "type info: optional field unwrapping" {
324 const Struct = struct {
325 cdOffset: u32,
326 };
327
328 const field = @typeInfo(Struct).Struct.fields[0];
329
330 _ = field.offset orelse 0;
331}
332
333test "type info: pass to function" {322test "type info: pass to function" {
334 _ = passTypeInfo(@typeInfo(void));323 _ = passTypeInfo(@typeInfo(void));
335 _ = comptime passTypeInfo(@typeInfo(void));324 _ = comptime passTypeInfo(@typeInfo(void));