authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-04-28 11:16:11-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-05-02 14:39:28-06:00
logca6db2d008cf3e0e3700e84400bd3d6e259e3c0f
treea5975ad5f4f6c655577152d087e3f31eb5d060ad
parent1696e943acd67119104f303467c0e26eecb94544
signature Commit is signed but in an unrecognized format.

Implement @Type() for EnumLiteral and FnFrame


3 files changed, 33 insertions(+), 3 deletions(-)

lib/std/builtin.zig+7-1
......@@ -157,7 +157,7 @@ pub const TypeInfo = union(enum) {
157157 Fn: Fn,
158158 BoundFn: Fn,
159159 Opaque: void,
160 Frame: void,
160 Frame: Frame,
161161 AnyFrame: AnyFrame,
162162 Vector: Vector,
163163 EnumLiteral: void,
......@@ -315,6 +315,12 @@ pub const TypeInfo = union(enum) {
315315 args: []FnArg,
316316 };
317317
318 /// This data structure is used by the Zig language code generation and
319 /// therefore must be kept in sync with the compiler implementation.
320 pub const Frame = struct {
321 function: var,
322 };
323
318324 /// This data structure is used by the Zig language code generation and
319325 /// therefore must be kept in sync with the compiler implementation.
320326 pub const AnyFrame = struct {
src/ir.cpp+10-2
......@@ -25446,10 +25446,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
2544625446 ZigType *child_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "child", 0);
2544725447 return get_any_frame_type(ira->codegen, child_type);
2544825448 }
25449 case ZigTypeIdEnumLiteral:
25450 return ira->codegen->builtin_types.entry_enum_literal;
25451 case ZigTypeIdFnFrame: {
25452 assert(payload->special == ConstValSpecialStatic);
25453 assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr));
25454 ZigValue *function = get_const_field(ira, source_instr->source_node, payload, "function", 0);
25455 assert(function->type->id == ZigTypeIdFn);
25456 ZigFn *fn = function->data.x_ptr.data.fn.fn_entry;
25457 return get_fn_frame_type(ira->codegen, fn);
25458 }
2544925459 case ZigTypeIdErrorSet:
2545025460 case ZigTypeIdEnum:
25451 case ZigTypeIdFnFrame:
25452 case ZigTypeIdEnumLiteral:
2545325461 ir_add_error(ira, source_instr, buf_sprintf(
2545425462 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
2545525463 return ira->codegen->invalid_inst_gen->value->type;
test/stage1/behavior/type.zig+16
......@@ -213,3 +213,19 @@ test "Type.AnyFrame" {
213213 anyframe->anyframe->u8,
214214 });
215215}
216
217test "Type.EnumLiteral" {
218 testTypes(&[_]type{
219 @TypeOf(.Dummy),
220 });
221}
222
223fn add(a: i32, b: i32) i32 {
224 return a + b;
225}
226
227test "Type.Frame" {
228 testTypes(&[_]type{
229 @Frame(add),
230 });
231}