authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-09-26 14:42:43-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-10-01 15:01:28-06:00
loga12203d2be2ff1021d8faa9b87c53af091f0bd01
tree8bb97c39c47b4bdad7fb7b34d8c3c684361dad46
parent70c507911a738538b8ef4df2b52184512e7d86a8
signature Commit is signed but in an unrecognized format.

Switch TypeInfo alignment fields from u29 to comptime_int


2 files changed, 20 insertions(+), 23 deletions(-)

lib/std/builtin.zig+3-3
......@@ -214,7 +214,7 @@ pub const TypeInfo = union(enum) {
214214 size: Size,
215215 is_const: bool,
216216 is_volatile: bool,
217 alignment: u29,
217 alignment: comptime_int,
218218 child: type,
219219 is_allowzero: bool,
220220
......@@ -262,7 +262,7 @@ pub const TypeInfo = union(enum) {
262262 field_type: type,
263263 default_value: anytype,
264264 is_comptime: bool,
265 alignment: u29,
265 alignment: comptime_int,
266266 };
267267
268268 /// This data structure is used by the Zig language code generation and
......@@ -319,7 +319,7 @@ pub const TypeInfo = union(enum) {
319319 pub const UnionField = struct {
320320 name: []const u8,
321321 field_type: type,
322 alignment: u29,
322 alignment: comptime_int,
323323 };
324324
325325 /// This data structure is used by the Zig language code generation and
src/stage1/ir.cpp+17-20
......@@ -25027,9 +25027,9 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, IrInst *source_instr,
2502725027 fields[2]->special = ConstValSpecialStatic;
2502825028 fields[2]->type = ira->codegen->builtin_types.entry_bool;
2502925029 fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile;
25030 // alignment: u32
25030 // alignment: comptime_int
2503125031 ensure_field_index(result->type, "alignment", 3);
25032 fields[3]->type = ira->codegen->builtin_types.entry_u29;
25032 fields[3]->type = ira->codegen->builtin_types.entry_num_lit_int;
2503325033 if (attrs_type->data.pointer.explicit_alignment != 0) {
2503425034 fields[3]->special = ConstValSpecialStatic;
2503525035 bigint_init_unsigned(&fields[3]->data.x_bigint, attrs_type->data.pointer.explicit_alignment);
......@@ -25432,12 +25432,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2543225432 union_field_val->type = type_info_union_field_type;
2543325433
2543425434 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
25435 // field_type: type
2543525436 inner_fields[1]->special = ConstValSpecialStatic;
2543625437 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;
2543725438 inner_fields[1]->data.x_type = union_field->type_entry;
2543825439
25440 // alignment: comptime_int
2543925441 inner_fields[2]->special = ConstValSpecialStatic;
25440 inner_fields[2]->type = ira->codegen->builtin_types.entry_u29;
25442 inner_fields[2]->type = ira->codegen->builtin_types.entry_num_lit_int;
2544125443 bigint_init_unsigned(&inner_fields[2]->data.x_bigint, union_field->align);
2544225444
2544325445 ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;
......@@ -25522,12 +25524,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2552225524 }
2552325525 set_optional_payload(inner_fields[2], struct_field->init_val);
2552425526
25527 // is_comptime: bool
2552525528 inner_fields[3]->special = ConstValSpecialStatic;
2552625529 inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;
2552725530 inner_fields[3]->data.x_bool = struct_field->is_comptime;
2552825531
25532 // alignment: comptime_int
2552925533 inner_fields[4]->special = ConstValSpecialStatic;
25530 inner_fields[4]->type = ira->codegen->builtin_types.entry_u29;
25534 inner_fields[4]->type = ira->codegen->builtin_types.entry_num_lit_int;
2553125535 bigint_init_unsigned(&inner_fields[4]->data.x_bigint, struct_field->align);
2553225536
2553325537 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
......@@ -25748,17 +25752,6 @@ static Error get_const_field_bool(IrAnalyze *ira, AstNode *source_node, ZigValue
2574825752 return ErrorNone;
2574925753}
2575025754
25751static Error get_const_field_u29(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value,
25752 const char *name, size_t field_index, uint32_t *out)
25753{
25754 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
25755 if (value == nullptr)
25756 return ErrorSemanticAnalyzeFail;
25757 assert(value->type == ira->codegen->builtin_types.entry_u29);
25758 *out = bigint_as_u32(&value->data.x_bigint);
25759 return ErrorNone;
25760}
25761
2576225755static BigInt *get_const_field_lit_int(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index)
2576325756{
2576425757 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
......@@ -25888,8 +25881,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
2588825881 return ira->codegen->invalid_inst_gen->value->type;
2588925882 }
2589025883
25891 uint32_t alignment;
25892 if ((err = get_const_field_u29(ira, source_instr->source_node, payload, "alignment", 3, &alignment)))
25884 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3);
25885 if (alignment == nullptr)
2589325886 return ira->codegen->invalid_inst_gen->value->type;
2589425887
2589525888 bool is_const;
......@@ -25916,7 +25909,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
2591625909 is_const,
2591725910 is_volatile,
2591825911 ptr_len,
25919 alignment,
25912 bigint_as_u32(alignment),
2592025913 0, // bit_offset_in_host
2592125914 0, // host_int_bytes
2592225915 is_allowzero,
......@@ -26153,8 +26146,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
2615326146 }
2615426147 if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))
2615526148 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)))
26149 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, field_value, "alignment", 4);
26150 if (alignment == nullptr)
2615726151 return ira->codegen->invalid_inst_gen->value->type;
26152 field->align = bigint_as_u32(alignment);
2615826153 }
2615926154
2616026155 return entry;
......@@ -26324,8 +26319,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
2632426319 return ira->codegen->invalid_inst_gen->value->type;
2632526320 field->type_val = type_value;
2632626321 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)))
26322 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, field_value, "alignment", 2);
26323 if (alignment == nullptr)
2632826324 return ira->codegen->invalid_inst_gen->value->type;
26325 field->align = bigint_as_u32(alignment);
2632926326 }
2633026327 return entry;
2633126328 }