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) {...@@ -214,7 +214,7 @@ pub const TypeInfo = union(enum) {
214 size: Size,214 size: Size,
215 is_const: bool,215 is_const: bool,
216 is_volatile: bool,216 is_volatile: bool,
217 alignment: u29,217 alignment: comptime_int,
218 child: type,218 child: type,
219 is_allowzero: bool,219 is_allowzero: bool,
220220
...@@ -262,7 +262,7 @@ pub const TypeInfo = union(enum) {...@@ -262,7 +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 alignment: comptime_int,
266 };266 };
267267
268 /// This data structure is used by the Zig language code generation and268 /// This data structure is used by the Zig language code generation and
...@@ -319,7 +319,7 @@ pub const TypeInfo = union(enum) {...@@ -319,7 +319,7 @@ pub const TypeInfo = union(enum) {
319 pub const UnionField = struct {319 pub const UnionField = struct {
320 name: []const u8,320 name: []const u8,
321 field_type: type,321 field_type: type,
322 alignment: u29,322 alignment: comptime_int,
323 };323 };
324324
325 /// This data structure is used by the Zig language code generation and325 /// 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,...@@ -25027,9 +25027,9 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, IrInst *source_instr,
25027 fields[2]->special = ConstValSpecialStatic;25027 fields[2]->special = ConstValSpecialStatic;
25028 fields[2]->type = ira->codegen->builtin_types.entry_bool;25028 fields[2]->type = ira->codegen->builtin_types.entry_bool;
25029 fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile;25029 fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile;
25030 // alignment: u3225030 // alignment: comptime_int
25031 ensure_field_index(result->type, "alignment", 3);25031 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;
25033 if (attrs_type->data.pointer.explicit_alignment != 0) {25033 if (attrs_type->data.pointer.explicit_alignment != 0) {
25034 fields[3]->special = ConstValSpecialStatic;25034 fields[3]->special = ConstValSpecialStatic;
25035 bigint_init_unsigned(&fields[3]->data.x_bigint, attrs_type->data.pointer.explicit_alignment);25035 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...@@ -25432,12 +25432,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
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, 3);25434 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
25435 // field_type: type
25435 inner_fields[1]->special = ConstValSpecialStatic;25436 inner_fields[1]->special = ConstValSpecialStatic;
25436 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;25437 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;
25437 inner_fields[1]->data.x_type = union_field->type_entry;25438 inner_fields[1]->data.x_type = union_field->type_entry;
2543825439
25440 // alignment: comptime_int
25439 inner_fields[2]->special = ConstValSpecialStatic;25441 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;
25441 bigint_init_unsigned(&inner_fields[2]->data.x_bigint, union_field->align);25443 bigint_init_unsigned(&inner_fields[2]->data.x_bigint, union_field->align);
2544225444
25443 ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;25445 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...@@ -25522,12 +25524,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
25522 }25524 }
25523 set_optional_payload(inner_fields[2], struct_field->init_val);25525 set_optional_payload(inner_fields[2], struct_field->init_val);
2552425526
25527 // is_comptime: bool
25525 inner_fields[3]->special = ConstValSpecialStatic;25528 inner_fields[3]->special = ConstValSpecialStatic;
25526 inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;25529 inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;
25527 inner_fields[3]->data.x_bool = struct_field->is_comptime;25530 inner_fields[3]->data.x_bool = struct_field->is_comptime;
2552825531
25532 // alignment: comptime_int
25529 inner_fields[4]->special = ConstValSpecialStatic;25533 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;
25531 bigint_init_unsigned(&inner_fields[4]->data.x_bigint, struct_field->align);25535 bigint_init_unsigned(&inner_fields[4]->data.x_bigint, struct_field->align);
2553225536
25533 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;25537 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...@@ -25748,17 +25752,6 @@ static Error get_const_field_bool(IrAnalyze *ira, AstNode *source_node, ZigValue
25748 return ErrorNone;25752 return ErrorNone;
25749}25753}
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
25762static BigInt *get_const_field_lit_int(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index)25755static BigInt *get_const_field_lit_int(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index)
25763{25756{
25764 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);25757 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...@@ -25888,8 +25881,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
25888 return ira->codegen->invalid_inst_gen->value->type;25881 return ira->codegen->invalid_inst_gen->value->type;
25889 }25882 }
2589025883
25891 uint32_t alignment;25884 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3);
25892 if ((err = get_const_field_u29(ira, source_instr->source_node, payload, "alignment", 3, &alignment)))25885 if (alignment == nullptr)
25893 return ira->codegen->invalid_inst_gen->value->type;25886 return ira->codegen->invalid_inst_gen->value->type;
2589425887
25895 bool is_const;25888 bool is_const;
...@@ -25916,7 +25909,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -25916,7 +25909,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
25916 is_const,25909 is_const,
25917 is_volatile,25910 is_volatile,
25918 ptr_len,25911 ptr_len,
25919 alignment,25912 bigint_as_u32(alignment),
25920 0, // bit_offset_in_host25913 0, // bit_offset_in_host
25921 0, // host_int_bytes25914 0, // host_int_bytes
25922 is_allowzero,25915 is_allowzero,
...@@ -26153,8 +26146,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -26153,8 +26146,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
26153 }26146 }
26154 if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))26147 if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))
26155 return ira->codegen->invalid_inst_gen->value->type;26148 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)
26157 return ira->codegen->invalid_inst_gen->value->type;26151 return ira->codegen->invalid_inst_gen->value->type;
26152 field->align = bigint_as_u32(alignment);
26158 }26153 }
2615926154
26160 return entry;26155 return entry;
...@@ -26324,8 +26319,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -26324,8 +26319,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
26324 return ira->codegen->invalid_inst_gen->value->type;26319 return ira->codegen->invalid_inst_gen->value->type;
26325 field->type_val = type_value;26320 field->type_val = type_value;
26326 field->type_entry = type_value->data.x_type;26321 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)
26328 return ira->codegen->invalid_inst_gen->value->type;26324 return ira->codegen->invalid_inst_gen->value->type;
26325 field->align = bigint_as_u32(alignment);
26329 }26326 }
26330 return entry;26327 return entry;
26331 }26328 }