authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-09-26 08:48:26-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-10-01 15:01:25-06:00
logd81648ce8ce93780c7eb8c93f05b6f99f160474c
tree603e96d9b31f985c553bf5ac0ba7699117b8b7b0
parent77df5dae7f69f0d46c8e229df12f43f33487073f
signature Commit is signed but in an unrecognized format.

Add alignment field to TypeInfo.UnionField and TypeInfo.StructField

Closes https://github.com/ziglang/zig/issues/6122

3 files changed, 17 insertions(+), 2 deletions(-)

lib/std/builtin.zig+2
...@@ -262,6 +262,7 @@ pub const TypeInfo = union(enum) {...@@ -262,6 +262,7 @@ pub const TypeInfo = union(enum) {
262 field_type: type,262 field_type: type,
263 default_value: anytype,263 default_value: anytype,
264 is_comptime: bool,264 is_comptime: bool,
265 alignment: u29,
265 };266 };
266267
267 /// This data structure is used by the Zig language code generation and268 /// This data structure is used by the Zig language code generation and
...@@ -318,6 +319,7 @@ pub const TypeInfo = union(enum) {...@@ -318,6 +319,7 @@ pub const TypeInfo = union(enum) {
318 pub const UnionField = struct {319 pub const UnionField = struct {
319 name: []const u8,320 name: []const u8,
320 field_type: type,321 field_type: type,
322 alignment: u29,
321 };323 };
322324
323 /// This data structure is used by the Zig language code generation and325 /// This data structure is used by the Zig language code generation and
lib/std/meta/trailer_flags.zig+1
...@@ -47,6 +47,7 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -47,6 +47,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
47 @as(?struct_field.field_type, null),47 @as(?struct_field.field_type, null),
48 ),48 ),
49 .is_comptime = false,49 .is_comptime = false,
50 .alignment = @alignOf(?struct_field.field_type),
50 };51 };
51 }52 }
52 break :blk @Type(.{53 break :blk @Type(.{
src/stage1/ir.cpp+14-2
...@@ -25431,11 +25431,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -25431,11 +25431,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
25431 union_field_val->special = ConstValSpecialStatic;25431 union_field_val->special = ConstValSpecialStatic;
25432 union_field_val->type = type_info_union_field_type;25432 union_field_val->type = type_info_union_field_type;
2543325433
25434 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 2);25434 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
25435 inner_fields[1]->special = ConstValSpecialStatic;25435 inner_fields[1]->special = ConstValSpecialStatic;
25436 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;25436 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;
25437 inner_fields[1]->data.x_type = union_field->type_entry;25437 inner_fields[1]->data.x_type = union_field->type_entry;
2543825438
25439 inner_fields[2]->special = ConstValSpecialStatic;
25440 inner_fields[2]->type = ira->codegen->builtin_types.entry_u29;
25441 bigint_init_unsigned(&inner_fields[2]->data.x_bigint, union_field->align);
25442
25439 ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;25443 ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;
25440 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);25444 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
2544125445
...@@ -25502,7 +25506,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -25502,7 +25506,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
25502 struct_field_val->special = ConstValSpecialStatic;25506 struct_field_val->special = ConstValSpecialStatic;
25503 struct_field_val->type = type_info_struct_field_type;25507 struct_field_val->type = type_info_struct_field_type;
2550425508
25505 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 4);25509 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 5);
2550625510
25507 inner_fields[1]->special = ConstValSpecialStatic;25511 inner_fields[1]->special = ConstValSpecialStatic;
25508 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;25512 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;
...@@ -25522,6 +25526,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -25522,6 +25526,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
25522 inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;25526 inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;
25523 inner_fields[3]->data.x_bool = struct_field->is_comptime;25527 inner_fields[3]->data.x_bool = struct_field->is_comptime;
2552425528
25529 inner_fields[4]->special = ConstValSpecialStatic;
25530 inner_fields[4]->type = ira->codegen->builtin_types.entry_u29;
25531 bigint_init_unsigned(&inner_fields[4]->data.x_bigint, struct_field->align);
25532
25525 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;25533 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
25526 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);25534 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
2552725535
...@@ -26145,6 +26153,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -26145,6 +26153,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
26145 }26153 }
26146 if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))26154 if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))
26147 return ira->codegen->invalid_inst_gen->value->type;26155 return ira->codegen->invalid_inst_gen->value->type;
26156 if ((err = get_const_field_u29(ira, source_instr->source_node, field_value, "alignment", 4, &field->align)))
26157 return ira->codegen->invalid_inst_gen->value->type;
26148 }26158 }
2614926159
26150 return entry;26160 return entry;
...@@ -26314,6 +26324,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -26314,6 +26324,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
26314 return ira->codegen->invalid_inst_gen->value->type;26324 return ira->codegen->invalid_inst_gen->value->type;
26315 field->type_val = type_value;26325 field->type_val = type_value;
26316 field->type_entry = type_value->data.x_type;26326 field->type_entry = type_value->data.x_type;
26327 if ((err = get_const_field_u29(ira, source_instr->source_node, field_value, "alignment", 2, &field->align)))
26328 return ira->codegen->invalid_inst_gen->value->type;
26317 }26329 }
26318 return entry;26330 return entry;
26319 }26331 }