authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-09-01 18:55:36-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-02 00:17:59-04:00
log1b2154dfe2f9b5030f487e7c4be8c706ce6e59b5
treea6ac792b2e778fde3c89c1986b0debfd33a564a1
parent3f7cb14b267bbd823597ba24fd2e3f6f66abcbaa

builtin: Add TypeInfo.StructField.is_comptime


4 files changed, 14 insertions(+), 0 deletions(-)

lib/std/builtin.zig+1
......@@ -261,6 +261,7 @@ pub const TypeInfo = union(enum) {
261261 name: []const u8,
262262 field_type: type,
263263 default_value: anytype,
264 is_comptime: bool,
264265 };
265266
266267 /// This data structure is used by the Zig language code generation and
lib/std/meta/trailer_flags.zig+1
......@@ -46,6 +46,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
4646 ??struct_field.field_type,
4747 @as(?struct_field.field_type, null),
4848 ),
49 .is_comptime = false,
4950 };
5051 }
5152 break :blk @Type(.{
src/ir.cpp+6
......@@ -25683,6 +25683,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2568325683 }
2568425684 set_optional_payload(inner_fields[2], struct_field->init_val);
2568525685
25686 inner_fields[3]->special = ConstValSpecialStatic;
25687 inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;
25688 inner_fields[3]->data.x_bool = struct_field->is_comptime;
25689
2568625690 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
2568725691 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
2568825692
......@@ -26291,6 +26295,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
2629126295 buf_ptr(&field->type_entry->name), buf_ptr(&field->type_entry->name)));
2629226296 return ira->codegen->invalid_inst_gen->value->type;
2629326297 }
26298 if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))
26299 return ira->codegen->invalid_inst_gen->value->type;
2629426300 }
2629526301
2629626302 return entry;
test/stage1/behavior/type_info.zig+6
......@@ -418,3 +418,9 @@ test "Struct.is_tuple" {
418418 expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple);
419419 expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple);
420420}
421
422test "StructField.is_comptime" {
423 const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).Struct;
424 expect(!info.fields[0].is_comptime);
425 expect(info.fields[1].is_comptime);
426}