| author | |
| committer | |
| log | 1696e943acd67119104f303467c0e26eecb94544 |
| tree | 0a152f64456fa75fff0776e54732f6beec34d6ee |
| parent | b7914d901c8c5761457a4774858f1004febc2d3a |
| signature | Commit is signed but in an unrecognized format. |
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,6 +6021,19 @@ ZigValue *create_const_null(CodeGen *g, ZigType *type) { |
| 6021 | return const_val; | 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 | void init_const_float(ZigValue *const_val, ZigType *type, double value) { | 6037 | void init_const_float(ZigValue *const_val, ZigType *type, double value) { |
| 6025 | const_val->special = ConstValSpecialStatic; | 6038 | const_val->special = ConstValSpecialStatic; |
| 6026 | const_val->type = type; | 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,6 +180,9 @@ ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size |
| 180 | void init_const_null(ZigValue *const_val, ZigType *type); | 180 | void init_const_null(ZigValue *const_val, ZigType *type); |
| 181 | ZigValue *create_const_null(CodeGen *g, ZigType *type); | 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 | ZigValue **alloc_const_vals_ptrs(CodeGen *g, size_t count); | 186 | ZigValue **alloc_const_vals_ptrs(CodeGen *g, size_t count); |
| 184 | ZigValue **realloc_const_vals_ptrs(CodeGen *g, ZigValue **ptr, size_t old_count, size_t new_count); | 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,9 +25166,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 25166 | break; | 25166 | break; |
| 25167 | } | 25167 | } |
| 25168 | case ZigTypeIdFnFrame: | 25168 | case ZigTypeIdFnFrame: |
| 25169 | ir_add_error(ira, source_instr, | 25169 | { |
| 25170 | buf_sprintf("compiler bug: TODO @typeInfo for async function frames. https://github.com/ziglang/zig/issues/3066")); | 25170 | result = ira->codegen->pass1_arena->create<ZigValue>(); |
| 25171 | return ErrorSemanticAnalyzeFail; | 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 | assert(result != nullptr); | 25183 | assert(result != nullptr); |
test/stage1/behavior/type_info.zig+14-1| ... | @@ -202,7 +202,7 @@ fn testUnion() void { | ... | @@ -202,7 +202,7 @@ fn testUnion() void { |
| 202 | expect(typeinfo_info.Union.fields[4].enum_field != null); | 202 | expect(typeinfo_info.Union.fields[4].enum_field != null); |
| 203 | expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4); | 203 | expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4); |
| 204 | expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); | 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 | const TestNoTagUnion = union { | 207 | const TestNoTagUnion = union { |
| 208 | Foo: void, | 208 | Foo: void, |
| ... | @@ -389,3 +389,16 @@ test "defaut value for a var-typed field" { | ... | @@ -389,3 +389,16 @@ test "defaut value for a var-typed field" { |
| 389 | const S = struct { x: var }; | 389 | const S = struct { x: var }; |
| 390 | expect(@typeInfo(S).Struct.fields[0].default_value == null); | 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 | } |