| ... | ... | @@ -13570,13 +13570,23 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13570 | 13570 | |
| 13571 | 13571 | const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len); |
| 13572 | 13572 | const rhs_len = try sema.usizeCast(block, rhs_src, rhs_info.len); |
| 13573 | | const result_len = std.math.add(usize, lhs_len, rhs_len) catch |err| switch (err) { |
| 13574 | | error.Overflow => return sema.fail( |
| 13573 | const result_len, const result_len_with_sent = blk: { |
| 13574 | if (std.math.add(usize, lhs_len, rhs_len)) |result_len| { |
| 13575 | const sent_len = @intFromBool(res_sent_val != null); |
| 13576 | if (std.math.add(usize, result_len, sent_len)) |with_sent| { |
| 13577 | break :blk .{ result_len, with_sent }; |
| 13578 | } else |err| switch (err) { |
| 13579 | error.Overflow => {}, |
| 13580 | } |
| 13581 | } else |err| switch (err) { |
| 13582 | error.Overflow => {}, |
| 13583 | } |
| 13584 | return sema.fail( |
| 13575 | 13585 | block, |
| 13576 | 13586 | src, |
| 13577 | 13587 | "concatenating arrays of length {d} and {d} produces an array too large for this compiler implementation to handle", |
| 13578 | 13588 | .{ lhs_len, rhs_len }, |
| 13579 | | ), |
| 13589 | ); |
| 13580 | 13590 | }; |
| 13581 | 13591 | |
| 13582 | 13592 | const result_ty = try pt.arrayType(.{ |
| ... | ... | @@ -13614,7 +13624,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13614 | 13624 | else |
| 13615 | 13625 | rhs_val; |
| 13616 | 13626 | |
| 13617 | | const element_vals = try sema.arena.alloc(InternPool.Index, result_len); |
| 13627 | const element_vals = try sema.arena.alloc(InternPool.Index, result_len_with_sent); |
| 13618 | 13628 | var elem_i: u32 = 0; |
| 13619 | 13629 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 13620 | 13630 | const lhs_elem_i = elem_i; |
| ... | ... | @@ -13642,6 +13652,9 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13642 | 13652 | const coerced_elem_val = sema.resolveValue(coerced_elem_val_inst).?; |
| 13643 | 13653 | element_vals[elem_i] = coerced_elem_val.toIntern(); |
| 13644 | 13654 | } |
| 13655 | if (res_sent_val) |v| { |
| 13656 | element_vals[result_len] = v.toIntern(); |
| 13657 | } |
| 13645 | 13658 | return sema.addConstantMaybeRef( |
| 13646 | 13659 | try pt.aggregateValue(result_ty, element_vals), |
| 13647 | 13660 | ptr_addrspace != null, |
| ... | ... | @@ -30644,11 +30657,18 @@ fn coerceArrayLike( |
| 30644 | 30657 | return block.addTyOp(.array_to_vector, dest_ty, inst); |
| 30645 | 30658 | } |
| 30646 | 30659 | |
| 30647 | | const element_vals = try sema.arena.alloc(InternPool.Index, dest_len); |
| 30648 | | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len); |
| 30660 | const dest_len_including_sent = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel(zcu)); |
| 30661 | const element_vals = try sema.arena.alloc(InternPool.Index, dest_len_including_sent); |
| 30662 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len_including_sent); |
| 30649 | 30663 | var runtime_src: ?LazySrcLoc = null; |
| 30650 | 30664 | |
| 30651 | 30665 | for (element_vals, element_refs, 0..) |*val, *ref, i| { |
| 30666 | if (i == dest_len) { |
| 30667 | const sentinel_val = dest_ty.sentinel(zcu).?; |
| 30668 | val.* = sentinel_val.toIntern(); |
| 30669 | ref.* = Air.internedToRef(sentinel_val.toIntern()); |
| 30670 | break; |
| 30671 | } |
| 30652 | 30672 | const index_ref = Air.internedToRef((try pt.intValue(.usize, i)).toIntern()); |
| 30653 | 30673 | const src = inst_src; // TODO better source location |
| 30654 | 30674 | const elem_src = inst_src; // TODO better source location |
| ... | ... | @@ -30686,6 +30706,7 @@ fn coerceTupleToArray( |
| 30686 | 30706 | const inst_ty = sema.typeOf(inst); |
| 30687 | 30707 | const inst_len = inst_ty.arrayLen(zcu); |
| 30688 | 30708 | const dest_len = dest_ty.arrayLen(zcu); |
| 30709 | const dest_len_including_sent = dest_ty.arrayLenIncludingSentinel(zcu); |
| 30689 | 30710 | |
| 30690 | 30711 | if (dest_len != inst_len) { |
| 30691 | 30712 | const msg = msg: { |
| ... | ... | @@ -30698,7 +30719,7 @@ fn coerceTupleToArray( |
| 30698 | 30719 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30699 | 30720 | } |
| 30700 | 30721 | |
| 30701 | | const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len); |
| 30722 | const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len_including_sent); |
| 30702 | 30723 | const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems); |
| 30703 | 30724 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems); |
| 30704 | 30725 | const dest_elem_ty = dest_ty.childType(zcu); |