authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-09-23 11:49:44-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-10-01 17:59:42-06:00
log97ab720d84ac6af5174ed93f371fedfa2331445d
tree45873c843a24f1709e3c5eb401fd6d711e593307
parent0228887b943dd7e70f7c5cc56e3993769342abf2
signature Commit is signed but in an unrecognized format.

stage1: Add alignment to TypeInfo.Fn


3 files changed, 26 insertions(+), 16 deletions(-)

lib/std/builtin.zig+1
......@@ -343,6 +343,7 @@ pub const TypeInfo = union(enum) {
343343 /// therefore must be kept in sync with the compiler implementation.
344344 pub const Fn = struct {
345345 calling_convention: CallingConvention,
346 alignment: u29,
346347 is_generic: bool,
347348 is_var_args: bool,
348349 return_type: ?type,
src/stage1/ir.cpp+20-15
......@@ -25564,7 +25564,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2556425564 result->special = ConstValSpecialStatic;
2556525565 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
2556625566
25567 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 5);
25567 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 6);
2556825568 result->data.x_struct.fields = fields;
2556925569
2557025570 // calling_convention: TypeInfo.CallingConvention
......@@ -25572,30 +25572,35 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2557225572 fields[0]->special = ConstValSpecialStatic;
2557325573 fields[0]->type = get_builtin_type(ira->codegen, "CallingConvention");
2557425574 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);
25575 // alignment: u29
25576 ensure_field_index(result->type, "alignment", 1);
25577 fields[1]->special = ConstValSpecialStatic;
25578 fields[1]->type = ira->codegen->builtin_types.entry_u29;
25579 bigint_init_unsigned(&fields[1]->data.x_bigint, type_entry->data.fn.fn_type_id.alignment);
2557525580 // is_generic: bool
25576 ensure_field_index(result->type, "is_generic", 1);
25581 ensure_field_index(result->type, "is_generic", 2);
2557725582 bool is_generic = type_entry->data.fn.is_generic;
25578 fields[1]->special = ConstValSpecialStatic;
25579 fields[1]->type = ira->codegen->builtin_types.entry_bool;
25580 fields[1]->data.x_bool = is_generic;
25581 // is_varargs: bool
25582 ensure_field_index(result->type, "is_var_args", 2);
25583 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;
2558425583 fields[2]->special = ConstValSpecialStatic;
2558525584 fields[2]->type = ira->codegen->builtin_types.entry_bool;
25586 fields[2]->data.x_bool = type_entry->data.fn.fn_type_id.is_var_args;
25587 // return_type: ?type
25588 ensure_field_index(result->type, "return_type", 3);
25585 fields[2]->data.x_bool = is_generic;
25586 // is_varargs: bool
25587 ensure_field_index(result->type, "is_var_args", 3);
25588 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;
2558925589 fields[3]->special = ConstValSpecialStatic;
25590 fields[3]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
25590 fields[3]->type = ira->codegen->builtin_types.entry_bool;
25591 fields[3]->data.x_bool = is_varargs;
25592 // return_type: ?type
25593 ensure_field_index(result->type, "return_type", 4);
25594 fields[4]->special = ConstValSpecialStatic;
25595 fields[4]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
2559125596 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
25592 fields[3]->data.x_optional = nullptr;
25597 fields[4]->data.x_optional = nullptr;
2559325598 else {
2559425599 ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>();
2559525600 return_type->special = ConstValSpecialStatic;
2559625601 return_type->type = ira->codegen->builtin_types.entry_type;
2559725602 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
25598 fields[3]->data.x_optional = return_type;
25603 fields[4]->data.x_optional = return_type;
2559925604 }
2560025605 // args: []TypeInfo.FnArg
2560125606 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
......@@ -25611,7 +25616,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2561125616 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
2561225617 fn_arg_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);
2561325618
25614 init_const_slice(ira->codegen, fields[4], fn_arg_array, 0, fn_arg_count, false);
25619 init_const_slice(ira->codegen, fields[5], fn_arg_array, 0, fn_arg_count, false);
2561525620
2561625621 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
2561725622 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];
test/stage1/behavior/type_info.zig+5-1
......@@ -273,11 +273,14 @@ test "type info: function type info" {
273273fn testFunction() void {
274274 const fn_info = @typeInfo(@TypeOf(foo));
275275 expect(fn_info == .Fn);
276 expect(fn_info.Fn.alignment == 0);
276277 expect(fn_info.Fn.calling_convention == .C);
277278 expect(!fn_info.Fn.is_generic);
278279 expect(fn_info.Fn.args.len == 2);
279280 expect(fn_info.Fn.is_var_args);
280281 expect(fn_info.Fn.return_type.? == usize);
282 const fn_aligned_info = @typeInfo(@TypeOf(fooAligned));
283 expect(fn_aligned_info.Fn.alignment == 4);
281284
282285 const test_instance: TestStruct = undefined;
283286 const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo));
......@@ -285,7 +288,8 @@ fn testFunction() void {
285288 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
286289}
287290
288extern fn foo(a: usize, b: bool, ...) usize;
291extern fn foo(a: usize, b: bool, ...) callconv(.C) usize;
292extern fn fooAligned(a: usize, b: bool, ...) align(4) callconv(.C) usize;
289293
290294test "typeInfo with comptime parameter in struct fn def" {
291295 const S = struct {