Implement @Type() for EnumLiteral and FnFrame

This commit is contained in:
Tadeo Kondrak 2020-04-28 11:16:11 -06:00
parent 1696e943ac
commit ca6db2d008
No known key found for this signature in database
GPG Key ID: D41E092CA43F1D8B
3 changed files with 33 additions and 3 deletions

View File

@ -157,7 +157,7 @@ pub const TypeInfo = union(enum) {
Fn: Fn,
BoundFn: Fn,
Opaque: void,
Frame: void,
Frame: Frame,
AnyFrame: AnyFrame,
Vector: Vector,
EnumLiteral: void,
@ -315,6 +315,12 @@ pub const TypeInfo = union(enum) {
args: []FnArg,
};
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Frame = struct {
function: var,
};
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const AnyFrame = struct {

View File

@ -25446,10 +25446,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
ZigType *child_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "child", 0);
return get_any_frame_type(ira->codegen, child_type);
}
case ZigTypeIdEnumLiteral:
return ira->codegen->builtin_types.entry_enum_literal;
case ZigTypeIdFnFrame: {
assert(payload->special == ConstValSpecialStatic);
assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr));
ZigValue *function = get_const_field(ira, source_instr->source_node, payload, "function", 0);
assert(function->type->id == ZigTypeIdFn);
ZigFn *fn = function->data.x_ptr.data.fn.fn_entry;
return get_fn_frame_type(ira->codegen, fn);
}
case ZigTypeIdErrorSet:
case ZigTypeIdEnum:
case ZigTypeIdFnFrame:
case ZigTypeIdEnumLiteral:
ir_add_error(ira, source_instr, buf_sprintf(
"TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
return ira->codegen->invalid_inst_gen->value->type;

View File

@ -213,3 +213,19 @@ test "Type.AnyFrame" {
anyframe->anyframe->u8,
});
}
test "Type.EnumLiteral" {
testTypes(&[_]type{
@TypeOf(.Dummy),
});
}
fn add(a: i32, b: i32) i32 {
return a + b;
}
test "Type.Frame" {
testTypes(&[_]type{
@Frame(add),
});
}