| ... | @@ -13570,13 +13570,23 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13570,13 +13570,23 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13570 | | 13570 | |
| 13571 | const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len); | 13571 | const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len); |
| 13572 | const rhs_len = try sema.usizeCast(block, rhs_src, rhs_info.len); | 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) { | 13573 | const result_len, const result_len_with_sent = blk: { |
| 13574 | error.Overflow => return sema.fail( | 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 | block, | 13585 | block, |
| 13576 | src, | 13586 | src, |
| 13577 | "concatenating arrays of length {d} and {d} produces an array too large for this compiler implementation to handle", | 13587 | "concatenating arrays of length {d} and {d} produces an array too large for this compiler implementation to handle", |
| 13578 | .{ lhs_len, rhs_len }, | 13588 | .{ lhs_len, rhs_len }, |
| 13579 | ), | 13589 | ); |
| 13580 | }; | 13590 | }; |
| 13581 | | 13591 | |
| 13582 | const result_ty = try pt.arrayType(.{ | 13592 | const result_ty = try pt.arrayType(.{ |
| ... | @@ -13614,7 +13624,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13614,7 +13624,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13614 | else | 13624 | else |
| 13615 | rhs_val; | 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 | var elem_i: u32 = 0; | 13628 | var elem_i: u32 = 0; |
| 13619 | while (elem_i < lhs_len) : (elem_i += 1) { | 13629 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 13620 | const lhs_elem_i = elem_i; | 13630 | const lhs_elem_i = elem_i; |
| ... | @@ -13642,6 +13652,9 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13642,6 +13652,9 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13642 | const coerced_elem_val = sema.resolveValue(coerced_elem_val_inst).?; | 13652 | const coerced_elem_val = sema.resolveValue(coerced_elem_val_inst).?; |
| 13643 | element_vals[elem_i] = coerced_elem_val.toIntern(); | 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 | return sema.addConstantMaybeRef( | 13658 | return sema.addConstantMaybeRef( |
| 13646 | try pt.aggregateValue(result_ty, element_vals), | 13659 | try pt.aggregateValue(result_ty, element_vals), |
| 13647 | ptr_addrspace != null, | 13660 | ptr_addrspace != null, |
| ... | @@ -30644,11 +30657,18 @@ fn coerceArrayLike( | ... | @@ -30644,11 +30657,18 @@ fn coerceArrayLike( |
| 30644 | return block.addTyOp(.array_to_vector, dest_ty, inst); | 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); | 30660 | const dest_len_including_sent = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel(zcu)); |
| 30648 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len); | 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 | var runtime_src: ?LazySrcLoc = null; | 30663 | var runtime_src: ?LazySrcLoc = null; |
| 30650 | | 30664 | |
| 30651 | for (element_vals, element_refs, 0..) |*val, *ref, i| { | 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 | const index_ref = Air.internedToRef((try pt.intValue(.usize, i)).toIntern()); | 30672 | const index_ref = Air.internedToRef((try pt.intValue(.usize, i)).toIntern()); |
| 30653 | const src = inst_src; // TODO better source location | 30673 | const src = inst_src; // TODO better source location |
| 30654 | const elem_src = inst_src; // TODO better source location | 30674 | const elem_src = inst_src; // TODO better source location |
| ... | @@ -30686,6 +30706,7 @@ fn coerceTupleToArray( | ... | @@ -30686,6 +30706,7 @@ fn coerceTupleToArray( |
| 30686 | const inst_ty = sema.typeOf(inst); | 30706 | const inst_ty = sema.typeOf(inst); |
| 30687 | const inst_len = inst_ty.arrayLen(zcu); | 30707 | const inst_len = inst_ty.arrayLen(zcu); |
| 30688 | const dest_len = dest_ty.arrayLen(zcu); | 30708 | const dest_len = dest_ty.arrayLen(zcu); |
| | 30709 | const dest_len_including_sent = dest_ty.arrayLenIncludingSentinel(zcu); |
| 30689 | | 30710 | |
| 30690 | if (dest_len != inst_len) { | 30711 | if (dest_len != inst_len) { |
| 30691 | const msg = msg: { | 30712 | const msg = msg: { |
| ... | @@ -30698,7 +30719,7 @@ fn coerceTupleToArray( | ... | @@ -30698,7 +30719,7 @@ fn coerceTupleToArray( |
| 30698 | return sema.failWithOwnedErrorMsg(block, msg); | 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 | const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems); | 30723 | const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems); |
| 30703 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems); | 30724 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems); |
| 30704 | const dest_elem_ty = dest_ty.childType(zcu); | 30725 | const dest_elem_ty = dest_ty.childType(zcu); |