| author | |
| committer | |
| log | 1696e943acd67119104f303467c0e26eecb94544 |
| tree | 0a152f64456fa75fff0776e54732f6beec34d6ee |
| parent | b7914d901c8c5761457a4774858f1004febc2d3a |
| signature |
Closes https://github.com/ziglang/zig/issues/30664 files changed, 42 insertions(+), 4 deletions(-)
src/analyze.cpp+13| ... | ... | @@ -6021,6 +6021,19 @@ ZigValue *create_const_null(CodeGen *g, ZigType *type) { |
| 6021 | 6021 | return const_val; |
| 6022 | 6022 | } |
| 6023 | 6023 | |
| 6024 | void init_const_fn(ZigValue *const_val, ZigFn *fn) { | |
| 6025 | const_val->special = ConstValSpecialStatic; | |
| 6026 | const_val->type = fn->type_entry; | |
| 6027 | const_val->data.x_ptr.special = ConstPtrSpecialFunction; | |
| 6028 | const_val->data.x_ptr.data.fn.fn_entry = fn; | |
| 6029 | } | |
| 6030 | ||
| 6031 | ZigValue *create_const_fn(CodeGen *g, ZigFn *fn) { | |
| 6032 | ZigValue *const_val = g->pass1_arena->create<ZigValue>(); | |
| 6033 | init_const_fn(const_val, fn); | |
| 6034 | return const_val; | |
| 6035 | } | |
| 6036 | ||
| 6024 | 6037 | void init_const_float(ZigValue *const_val, ZigType *type, double value) { |
| 6025 | 6038 | const_val->special = ConstValSpecialStatic; |
| 6026 | 6039 | const_val->type = type; |
src/analyze.hpp+3| ... | ... | @@ -180,6 +180,9 @@ ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size |
| 180 | 180 | void init_const_null(ZigValue *const_val, ZigType *type); |
| 181 | 181 | ZigValue *create_const_null(CodeGen *g, ZigType *type); |
| 182 | 182 | |
| 183 | void init_const_fn(ZigValue *const_val, ZigFn *fn); | |
| 184 | ZigValue *create_const_fn(CodeGen *g, ZigFn *fn); | |
| 185 | ||
| 183 | 186 | ZigValue **alloc_const_vals_ptrs(CodeGen *g, size_t count); |
| 184 | 187 | ZigValue **realloc_const_vals_ptrs(CodeGen *g, ZigValue **ptr, size_t old_count, size_t new_count); |
| 185 | 188 |
src/ir.cpp+12-3| ... | ... | @@ -25166,9 +25166,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 25166 | 25166 | break; |
| 25167 | 25167 | } |
| 25168 | 25168 | case ZigTypeIdFnFrame: |
| 25169 | ir_add_error(ira, source_instr, | |
| 25170 | buf_sprintf("compiler bug: TODO @typeInfo for async function frames. https://github.com/ziglang/zig/issues/3066")); | |
| 25171 | return ErrorSemanticAnalyzeFail; | |
| 25169 | { | |
| 25170 | result = ira->codegen->pass1_arena->create<ZigValue>(); | |
| 25171 | result->special = ConstValSpecialStatic; | |
| 25172 | result->type = ir_type_info_get_type(ira, "Frame", nullptr); | |
| 25173 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1); | |
| 25174 | result->data.x_struct.fields = fields; | |
| 25175 | ZigFn *fn = type_entry->data.frame.fn; | |
| 25176 | // function: var | |
| 25177 | ensure_field_index(result->type, "function", 0); | |
| 25178 | fields[0] = create_const_fn(ira->codegen, fn); | |
| 25179 | break; | |
| 25180 | } | |
| 25172 | 25181 | } |
| 25173 | 25182 | |
| 25174 | 25183 | assert(result != nullptr); |
test/stage1/behavior/type_info.zig+14-1| ... | ... | @@ -202,7 +202,7 @@ fn testUnion() void { |
| 202 | 202 | expect(typeinfo_info.Union.fields[4].enum_field != null); |
| 203 | 203 | expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4); |
| 204 | 204 | expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); |
| 205 | expect(typeinfo_info.Union.decls.len == 20); | |
| 205 | expect(typeinfo_info.Union.decls.len == 21); | |
| 206 | 206 | |
| 207 | 207 | const TestNoTagUnion = union { |
| 208 | 208 | Foo: void, |
| ... | ... | @@ -389,3 +389,16 @@ test "defaut value for a var-typed field" { |
| 389 | 389 | const S = struct { x: var }; |
| 390 | 390 | expect(@typeInfo(S).Struct.fields[0].default_value == null); |
| 391 | 391 | } |
| 392 | ||
| 393 | fn add(a: i32, b: i32) i32 { | |
| 394 | return a + b; | |
| 395 | } | |
| 396 | ||
| 397 | test "type info for async frames" { | |
| 398 | switch (@typeInfo(@Frame(add))) { | |
| 399 | .Frame => |frame| { | |
| 400 | expect(frame.function == add); | |
| 401 | }, | |
| 402 | else => unreachable, | |
| 403 | } | |
| 404 | } |