| author | |
| committer | |
| log | a1e78d0b0631885b95dfa80ab617818d1fd61277 |
| tree | a73ef9c8e04c3a16dc690277ac21581999c2f669 |
| parent | cc3bceea3de67f24e6c17d4c04a34a2301e097f8 |
| signature |
part of #43354 files changed, 16 insertions(+), 5 deletions(-)
lib/std/builtin.zig+1| ... | ... | @@ -246,6 +246,7 @@ pub const TypeInfo = union(enum) { |
| 246 | 246 | layout: ContainerLayout, |
| 247 | 247 | fields: []const StructField, |
| 248 | 248 | decls: []const Declaration, |
| 249 | is_tuple: bool, | |
| 249 | 250 | }; |
| 250 | 251 | |
| 251 | 252 | /// This data structure is used by the Zig language code generation and |
lib/std/mem.zig+2-3| ... | ... | @@ -709,8 +709,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T { |
| 709 | 709 | .Struct => |init_info| { |
| 710 | 710 | var value = std.mem.zeroes(T); |
| 711 | 711 | |
| 712 | // typeInfo won't tell us if this is a tuple | |
| 713 | if (comptime eql(u8, init_info.fields[0].name, "0")) { | |
| 712 | if (init_info.is_tuple) { | |
| 714 | 713 | inline for (init_info.fields) |field, i| { |
| 715 | 714 | @field(value, struct_info.fields[i].name) = @field(init, field.name); |
| 716 | 715 | } |
| ... | ... | @@ -785,7 +784,7 @@ test "zeroInit" { |
| 785 | 784 | a: u8, |
| 786 | 785 | }; |
| 787 | 786 | |
| 788 | const c = zeroInit(Color, .{255, 255}); | |
| 787 | const c = zeroInit(Color, .{ 255, 255 }); | |
| 789 | 788 | testing.expectEqual(Color{ |
| 790 | 789 | .r = 255, |
| 791 | 790 | .g = 255, |
src/ir.cpp+7-1| ... | ... | @@ -25546,7 +25546,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 25546 | 25546 | result->special = ConstValSpecialStatic; |
| 25547 | 25547 | result->type = ir_type_info_get_type(ira, "Struct", nullptr); |
| 25548 | 25548 | |
| 25549 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 3); | |
| 25549 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 4); | |
| 25550 | 25550 | result->data.x_struct.fields = fields; |
| 25551 | 25551 | |
| 25552 | 25552 | // layout: ContainerLayout |
| ... | ... | @@ -25627,6 +25627,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 25627 | 25627 | return err; |
| 25628 | 25628 | } |
| 25629 | 25629 | |
| 25630 | // is_tuple: bool | |
| 25631 | ensure_field_index(result->type, "is_tuple", 3); | |
| 25632 | fields[3]->special = ConstValSpecialStatic; | |
| 25633 | fields[3]->type = ira->codegen->builtin_types.entry_bool; | |
| 25634 | fields[3]->data.x_bool = is_tuple(type_entry); | |
| 25635 | ||
| 25630 | 25636 | break; |
| 25631 | 25637 | } |
| 25632 | 25638 | case ZigTypeIdFn: |
test/stage1/behavior/type_info.zig+6-1| ... | ... | @@ -280,7 +280,7 @@ fn testFunction() void { |
| 280 | 280 | expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | extern fn foo(a: usize, b: bool, args: ...) usize; | |
| 283 | extern fn foo(a: usize, b: bool, ...) usize; | |
| 284 | 284 | |
| 285 | 285 | test "typeInfo with comptime parameter in struct fn def" { |
| 286 | 286 | const S = struct { |
| ... | ... | @@ -425,3 +425,8 @@ test "Declarations are returned in declaration order" { |
| 425 | 425 | expect(std.mem.eql(u8, d[3].name, "d")); |
| 426 | 426 | expect(std.mem.eql(u8, d[4].name, "e")); |
| 427 | 427 | } |
| 428 | ||
| 429 | test "Struct.is_tuple" { | |
| 430 | expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple); | |
| 431 | expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple); | |
| 432 | } |