| ... | ... | @@ -13560,13 +13560,23 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13560 | 13560 | |
| 13561 | 13561 | const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len); |
| 13562 | 13562 | const rhs_len = try sema.usizeCast(block, rhs_src, rhs_info.len); |
| 13563 | | const result_len = std.math.add(usize, lhs_len, rhs_len) catch |err| switch (err) { |
| 13564 | | error.Overflow => return sema.fail( |
| 13563 | const result_len, const result_len_with_sent = blk: { |
| 13564 | if (std.math.add(usize, lhs_len, rhs_len)) |result_len| { |
| 13565 | const sent_len = @intFromBool(res_sent_val != null); |
| 13566 | if (std.math.add(usize, result_len, sent_len)) |with_sent| { |
| 13567 | break :blk .{ result_len, with_sent }; |
| 13568 | } else |err| switch (err) { |
| 13569 | error.Overflow => {}, |
| 13570 | } |
| 13571 | } else |err| switch (err) { |
| 13572 | error.Overflow => {}, |
| 13573 | } |
| 13574 | return sema.fail( |
| 13565 | 13575 | block, |
| 13566 | 13576 | src, |
| 13567 | 13577 | "concatenating arrays of length {d} and {d} produces an array too large for this compiler implementation to handle", |
| 13568 | 13578 | .{ lhs_len, rhs_len }, |
| 13569 | | ), |
| 13579 | ); |
| 13570 | 13580 | }; |
| 13571 | 13581 | |
| 13572 | 13582 | const result_ty = try pt.arrayType(.{ |
| ... | ... | @@ -13604,7 +13614,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13604 | 13614 | else |
| 13605 | 13615 | rhs_val; |
| 13606 | 13616 | |
| 13607 | | const element_vals = try sema.arena.alloc(InternPool.Index, result_len); |
| 13617 | const element_vals = try sema.arena.alloc(InternPool.Index, result_len_with_sent); |
| 13608 | 13618 | var elem_i: u32 = 0; |
| 13609 | 13619 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 13610 | 13620 | const lhs_elem_i = elem_i; |
| ... | ... | @@ -13632,6 +13642,9 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13632 | 13642 | const coerced_elem_val = sema.resolveValue(coerced_elem_val_inst).?; |
| 13633 | 13643 | element_vals[elem_i] = coerced_elem_val.toIntern(); |
| 13634 | 13644 | } |
| 13645 | if (res_sent_val) |v| { |
| 13646 | element_vals[result_len] = v.toIntern(); |
| 13647 | } |
| 13635 | 13648 | return sema.addConstantMaybeRef( |
| 13636 | 13649 | try pt.aggregateValue(result_ty, element_vals), |
| 13637 | 13650 | ptr_addrspace != null, |
| ... | ... | @@ -30616,11 +30629,18 @@ fn coerceArrayLike( |
| 30616 | 30629 | return block.addTyOp(.array_to_vector, dest_ty, inst); |
| 30617 | 30630 | } |
| 30618 | 30631 | |
| 30619 | | const element_vals = try sema.arena.alloc(InternPool.Index, dest_len); |
| 30620 | | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len); |
| 30632 | const dest_len_including_sent = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel(zcu)); |
| 30633 | const element_vals = try sema.arena.alloc(InternPool.Index, dest_len_including_sent); |
| 30634 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len_including_sent); |
| 30621 | 30635 | var runtime_src: ?LazySrcLoc = null; |
| 30622 | 30636 | |
| 30623 | 30637 | for (element_vals, element_refs, 0..) |*val, *ref, i| { |
| 30638 | if (i == dest_len) { |
| 30639 | const sentinel_val = dest_ty.sentinel(zcu).?; |
| 30640 | val.* = sentinel_val.toIntern(); |
| 30641 | ref.* = Air.internedToRef(sentinel_val.toIntern()); |
| 30642 | break; |
| 30643 | } |
| 30624 | 30644 | const index_ref = Air.internedToRef((try pt.intValue(.usize, i)).toIntern()); |
| 30625 | 30645 | const src = inst_src; // TODO better source location |
| 30626 | 30646 | const elem_src = inst_src; // TODO better source location |
| ... | ... | @@ -30658,6 +30678,7 @@ fn coerceTupleToArray( |
| 30658 | 30678 | const inst_ty = sema.typeOf(inst); |
| 30659 | 30679 | const inst_len = inst_ty.arrayLen(zcu); |
| 30660 | 30680 | const dest_len = dest_ty.arrayLen(zcu); |
| 30681 | const dest_len_including_sent = dest_ty.arrayLenIncludingSentinel(zcu); |
| 30661 | 30682 | |
| 30662 | 30683 | if (dest_len != inst_len) { |
| 30663 | 30684 | const msg = msg: { |
| ... | ... | @@ -30670,7 +30691,7 @@ fn coerceTupleToArray( |
| 30670 | 30691 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30671 | 30692 | } |
| 30672 | 30693 | |
| 30673 | | const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len); |
| 30694 | const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len_including_sent); |
| 30674 | 30695 | const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems); |
| 30675 | 30696 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems); |
| 30676 | 30697 | const dest_elem_ty = dest_ty.childType(zcu); |