mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
Add alignment field to TypeInfo.UnionField and TypeInfo.StructField
Closes https://github.com/ziglang/zig/issues/6122
This commit is contained in:
parent
77df5dae7f
commit
d81648ce8c
@ -262,6 +262,7 @@ pub const TypeInfo = union(enum) {
|
|||||||
field_type: type,
|
field_type: type,
|
||||||
default_value: anytype,
|
default_value: anytype,
|
||||||
is_comptime: bool,
|
is_comptime: bool,
|
||||||
|
alignment: u29,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This data structure is used by the Zig language code generation and
|
/// This data structure is used by the Zig language code generation and
|
||||||
@ -318,6 +319,7 @@ pub const TypeInfo = union(enum) {
|
|||||||
pub const UnionField = struct {
|
pub const UnionField = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
field_type: type,
|
field_type: type,
|
||||||
|
alignment: u29,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This data structure is used by the Zig language code generation and
|
/// This data structure is used by the Zig language code generation and
|
||||||
|
|||||||
@ -47,6 +47,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
|
|||||||
@as(?struct_field.field_type, null),
|
@as(?struct_field.field_type, null),
|
||||||
),
|
),
|
||||||
.is_comptime = false,
|
.is_comptime = false,
|
||||||
|
.alignment = @alignOf(?struct_field.field_type),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
break :blk @Type(.{
|
break :blk @Type(.{
|
||||||
|
|||||||
@ -25431,11 +25431,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
|
|||||||
union_field_val->special = ConstValSpecialStatic;
|
union_field_val->special = ConstValSpecialStatic;
|
||||||
union_field_val->type = type_info_union_field_type;
|
union_field_val->type = type_info_union_field_type;
|
||||||
|
|
||||||
ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 2);
|
ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
|
||||||
inner_fields[1]->special = ConstValSpecialStatic;
|
inner_fields[1]->special = ConstValSpecialStatic;
|
||||||
inner_fields[1]->type = ira->codegen->builtin_types.entry_type;
|
inner_fields[1]->type = ira->codegen->builtin_types.entry_type;
|
||||||
inner_fields[1]->data.x_type = union_field->type_entry;
|
inner_fields[1]->data.x_type = union_field->type_entry;
|
||||||
|
|
||||||
|
inner_fields[2]->special = ConstValSpecialStatic;
|
||||||
|
inner_fields[2]->type = ira->codegen->builtin_types.entry_u29;
|
||||||
|
bigint_init_unsigned(&inner_fields[2]->data.x_bigint, union_field->align);
|
||||||
|
|
||||||
ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;
|
ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;
|
||||||
init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
|
init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
|
||||||
|
|
||||||
@ -25502,7 +25506,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
|
|||||||
struct_field_val->special = ConstValSpecialStatic;
|
struct_field_val->special = ConstValSpecialStatic;
|
||||||
struct_field_val->type = type_info_struct_field_type;
|
struct_field_val->type = type_info_struct_field_type;
|
||||||
|
|
||||||
ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 4);
|
ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 5);
|
||||||
|
|
||||||
inner_fields[1]->special = ConstValSpecialStatic;
|
inner_fields[1]->special = ConstValSpecialStatic;
|
||||||
inner_fields[1]->type = ira->codegen->builtin_types.entry_type;
|
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
|
|||||||
inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;
|
inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;
|
||||||
inner_fields[3]->data.x_bool = struct_field->is_comptime;
|
inner_fields[3]->data.x_bool = struct_field->is_comptime;
|
||||||
|
|
||||||
|
inner_fields[4]->special = ConstValSpecialStatic;
|
||||||
|
inner_fields[4]->type = ira->codegen->builtin_types.entry_u29;
|
||||||
|
bigint_init_unsigned(&inner_fields[4]->data.x_bigint, struct_field->align);
|
||||||
|
|
||||||
ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
|
ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
|
||||||
init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
|
init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
|
||||||
|
|
||||||
@ -26145,6 +26153,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
|
|||||||
}
|
}
|
||||||
if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))
|
if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))
|
||||||
return ira->codegen->invalid_inst_gen->value->type;
|
return ira->codegen->invalid_inst_gen->value->type;
|
||||||
|
if ((err = get_const_field_u29(ira, source_instr->source_node, field_value, "alignment", 4, &field->align)))
|
||||||
|
return ira->codegen->invalid_inst_gen->value->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
@ -26314,6 +26324,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
|
|||||||
return ira->codegen->invalid_inst_gen->value->type;
|
return ira->codegen->invalid_inst_gen->value->type;
|
||||||
field->type_val = type_value;
|
field->type_val = type_value;
|
||||||
field->type_entry = type_value->data.x_type;
|
field->type_entry = type_value->data.x_type;
|
||||||
|
if ((err = get_const_field_u29(ira, source_instr->source_node, field_value, "alignment", 2, &field->align)))
|
||||||
|
return ira->codegen->invalid_inst_gen->value->type;
|
||||||
}
|
}
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user