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) {
262262 field_type: type,
263263 default_value: anytype,
264264 is_comptime: bool,
265 alignment: u29,
265266 };
266267
267268 /// This data structure is used by the Zig language code generation and
......@@ -318,6 +319,7 @@ pub const TypeInfo = union(enum) {
318319 pub const UnionField = struct {
319320 name: []const u8,
320321 field_type: type,
322 alignment: u29,
321323 };
322324
323325 /// 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 {
4747 @as(?struct_field.field_type, null),
4848 ),
4949 .is_comptime = false,
50 .alignment = @alignOf(?struct_field.field_type),
5051 };
5152 }
5253 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
2543125431 union_field_val->special = ConstValSpecialStatic;
2543225432 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);
2543525435 inner_fields[1]->special = ConstValSpecialStatic;
2543625436 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;
2543725437 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
2543925443 ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;
2544025444 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
2550225506 struct_field_val->special = ConstValSpecialStatic;
2550325507 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
2550725511 inner_fields[1]->special = ConstValSpecialStatic;
2550825512 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
2552225526 inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;
2552325527 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
2552525533 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
2552625534 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
2614526153 }
2614626154 if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))
2614726155 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;
2614826158 }
2614926159
2615026160 return entry;
......@@ -26314,6 +26324,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
2631426324 return ira->codegen->invalid_inst_gen->value->type;
2631526325 field->type_val = type_value;
2631626326 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;
2631726329 }
2631826330 return entry;
2631926331 }