| author | |
| committer | |
| log | b5ac2b4330b84799060609ce0f22eda266ad171b |
| tree | 8a6e8401eefd602691e2b6d3686757a051513fb3 |
| parent | 27ee4141592c7a9d77a2d73f5fa6a3c6262ac7fc |
5 files changed, 25 insertions(+), 16 deletions(-)
src/AstGen.zig+12-3| ... | ... | @@ -1320,7 +1320,10 @@ fn arrayInitExpr( |
| 1320 | 1320 | const len_inst = try gz.addInt(array_init.ast.elements.len); |
| 1321 | 1321 | const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type); |
| 1322 | 1322 | if (array_type.ast.sentinel == 0) { |
| 1323 | const array_type_inst = try gz.addBin(.array_type, len_inst, elem_type); | |
| 1323 | const array_type_inst = try gz.addPlNode(.array_type, array_init.ast.type_expr, Zir.Inst.Bin{ | |
| 1324 | .lhs = len_inst, | |
| 1325 | .rhs = elem_type, | |
| 1326 | }); | |
| 1324 | 1327 | break :inst .{ |
| 1325 | 1328 | .array = array_type_inst, |
| 1326 | 1329 | .elem = elem_type, |
| ... | ... | @@ -1553,7 +1556,10 @@ fn structInitExpr( |
| 1553 | 1556 | if (is_inferred_array_len) { |
| 1554 | 1557 | const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type); |
| 1555 | 1558 | const array_type_inst = if (array_type.ast.sentinel == 0) blk: { |
| 1556 | break :blk try gz.addBin(.array_type, .zero_usize, elem_type); | |
| 1559 | break :blk try gz.addPlNode(.array_type, struct_init.ast.type_expr, Zir.Inst.Bin{ | |
| 1560 | .lhs = .zero_usize, | |
| 1561 | .rhs = elem_type, | |
| 1562 | }); | |
| 1557 | 1563 | } else blk: { |
| 1558 | 1564 | const sentinel = try comptimeExpr(gz, scope, .{ .ty = elem_type }, array_type.ast.sentinel); |
| 1559 | 1565 | break :blk try gz.addPlNode( |
| ... | ... | @@ -3203,7 +3209,10 @@ fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) !Z |
| 3203 | 3209 | const len = try expr(gz, scope, .{ .coerced_ty = .usize_type }, len_node); |
| 3204 | 3210 | const elem_type = try typeExpr(gz, scope, node_datas[node].rhs); |
| 3205 | 3211 | |
| 3206 | const result = try gz.addBin(.array_type, len, elem_type); | |
| 3212 | const result = try gz.addPlNode(.array_type, node, Zir.Inst.Bin{ | |
| 3213 | .lhs = len, | |
| 3214 | .rhs = elem_type, | |
| 3215 | }); | |
| 3207 | 3216 | return rvalue(gz, rl, result, node); |
| 3208 | 3217 | } |
| 3209 | 3218 |
src/Sema.zig+9-9| ... | ... | @@ -2815,7 +2815,7 @@ fn zirAllocExtended( |
| 2815 | 2815 | ) CompileError!Air.Inst.Ref { |
| 2816 | 2816 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| 2817 | 2817 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); |
| 2818 | const ty_src = src; // TODO better source location | |
| 2818 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node }; | |
| 2819 | 2819 | const align_src = src; // TODO better source location |
| 2820 | 2820 | const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small); |
| 2821 | 2821 | |
| ... | ... | @@ -6194,11 +6194,12 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 6194 | 6194 | const tracy = trace(@src()); |
| 6195 | 6195 | defer tracy.end(); |
| 6196 | 6196 | |
| 6197 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; | |
| 6198 | const len_src = sema.src; // TODO better source location | |
| 6199 | const elem_src = sema.src; // TODO better source location | |
| 6200 | const len = try sema.resolveInt(block, len_src, bin_inst.lhs, Type.usize); | |
| 6201 | const elem_type = try sema.resolveType(block, elem_src, bin_inst.rhs); | |
| 6197 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 6198 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | |
| 6199 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | |
| 6200 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | |
| 6201 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize); | |
| 6202 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); | |
| 6202 | 6203 | const array_ty = try Type.array(sema.arena, len, null, elem_type, sema.mod); |
| 6203 | 6204 | |
| 6204 | 6205 | return sema.addType(array_ty); |
| ... | ... | @@ -10570,18 +10571,17 @@ fn analyzeArithmetic( |
| 10570 | 10571 | if (lhs_zig_ty_tag == .Pointer) switch (lhs_ty.ptrSize()) { |
| 10571 | 10572 | .One, .Slice => {}, |
| 10572 | 10573 | .Many, .C => { |
| 10573 | const op_src = src; // TODO better source location | |
| 10574 | 10574 | const air_tag: Air.Inst.Tag = switch (zir_tag) { |
| 10575 | 10575 | .add => .ptr_add, |
| 10576 | 10576 | .sub => .ptr_sub, |
| 10577 | 10577 | else => return sema.fail( |
| 10578 | 10578 | block, |
| 10579 | op_src, | |
| 10579 | src, | |
| 10580 | 10580 | "invalid pointer arithmetic operand: '{s}''", |
| 10581 | 10581 | .{@tagName(zir_tag)}, |
| 10582 | 10582 | ), |
| 10583 | 10583 | }; |
| 10584 | return analyzePtrArithmetic(sema, block, op_src, lhs, rhs, air_tag, lhs_src, rhs_src); | |
| 10584 | return analyzePtrArithmetic(sema, block, src, lhs, rhs, air_tag, lhs_src, rhs_src); | |
| 10585 | 10585 | }, |
| 10586 | 10586 | }; |
| 10587 | 10587 |
src/Zir.zig+2-2| ... | ... | @@ -212,7 +212,7 @@ pub const Inst = struct { |
| 212 | 212 | /// Uses the `pl_node` union field. Payload is `Bin`. |
| 213 | 213 | array_mul, |
| 214 | 214 | /// `[N]T` syntax. No source location provided. |
| 215 | /// Uses the `bin` union field. lhs is length, rhs is element type. | |
| 215 | /// Uses the `pl_node` union field. Payload is `Bin`. lhs is length, rhs is element type. | |
| 216 | 216 | array_type, |
| 217 | 217 | /// `[N:S]T` syntax. Source location is the array type expression node. |
| 218 | 218 | /// Uses the `pl_node` union field. Payload is `ArrayTypeSentinel`. |
| ... | ... | @@ -1571,7 +1571,7 @@ pub const Inst = struct { |
| 1571 | 1571 | .param_anytype_comptime = .str_tok, |
| 1572 | 1572 | .array_cat = .pl_node, |
| 1573 | 1573 | .array_mul = .pl_node, |
| 1574 | .array_type = .bin, | |
| 1574 | .array_type = .pl_node, | |
| 1575 | 1575 | .array_type_sentinel = .pl_node, |
| 1576 | 1576 | .vector_type = .pl_node, |
| 1577 | 1577 | .elem_type_index = .bin, |
src/print_zir.zig+1-1| ... | ... | @@ -142,7 +142,6 @@ const Writer = struct { |
| 142 | 142 | const tag = tags[inst]; |
| 143 | 143 | try stream.print("= {s}(", .{@tagName(tags[inst])}); |
| 144 | 144 | switch (tag) { |
| 145 | .array_type, | |
| 146 | 145 | .as, |
| 147 | 146 | .store, |
| 148 | 147 | .store_to_block_ptr, |
| ... | ... | @@ -354,6 +353,7 @@ const Writer = struct { |
| 354 | 353 | .elem_ptr, |
| 355 | 354 | .elem_val, |
| 356 | 355 | .coerce_result_ptr, |
| 356 | .array_type, | |
| 357 | 357 | => try self.writePlNodeBin(stream, inst), |
| 358 | 358 | |
| 359 | 359 | .elem_ptr_imm => try self.writeElemPtrImm(stream, inst), |
test/cases/compile_errors/invalid_array_elem_ty.zig+1-1| ... | ... | @@ -9,4 +9,4 @@ pub export fn entry() void { |
| 9 | 9 | // target=native |
| 10 | 10 | // backend=stage2 |
| 11 | 11 | // |
| 12 | // :4:1: error: expected type 'type', found 'fn() type' | |
| 12 | // :5:12: error: expected type 'type', found 'fn() type' |