| ... | ... | @@ -15155,21 +15155,26 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15155 | 15155 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 15156 | 15156 | |
| 15157 | 15157 | if (ptr_addrspace) |ptr_as| { |
| 15158 | | const alloc_ty = try pt.ptrTypeSema(.{ |
| 15158 | const constant_alloc_ty = try pt.ptrTypeSema(.{ |
| 15159 | 15159 | .child = result_ty.toIntern(), |
| 15160 | 15160 | .flags = .{ |
| 15161 | 15161 | .address_space = ptr_as, |
| 15162 | 15162 | .is_const = true, |
| 15163 | 15163 | }, |
| 15164 | 15164 | }); |
| 15165 | | const alloc = try block.addTy(.alloc, alloc_ty); |
| 15165 | const alloc_ty = try pt.ptrTypeSema(.{ |
| 15166 | .child = result_ty.toIntern(), |
| 15167 | .flags = .{ .address_space = ptr_as }, |
| 15168 | }); |
| 15166 | 15169 | const elem_ptr_ty = try pt.ptrTypeSema(.{ |
| 15167 | 15170 | .child = resolved_elem_ty.toIntern(), |
| 15168 | 15171 | .flags = .{ .address_space = ptr_as }, |
| 15169 | 15172 | }); |
| 15170 | 15173 | |
| 15174 | const mutable_alloc = try block.addTy(.alloc, alloc_ty); |
| 15175 | |
| 15171 | 15176 | // if both the source and destination are arrays |
| 15172 | | // we can hot path via a memcpy. |
| 15177 | // we can hotpath via a memcpy. |
| 15173 | 15178 | if (lhs_ty.zigTypeTag(zcu) == .pointer and |
| 15174 | 15179 | rhs_ty.zigTypeTag(zcu) == .pointer) |
| 15175 | 15180 | { |
| ... | ... | @@ -15180,27 +15185,24 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15180 | 15185 | .address_space = ptr_as, |
| 15181 | 15186 | }, |
| 15182 | 15187 | }); |
| 15183 | | const many_ty = try pt.ptrTypeSema(.{ |
| 15184 | | .child = resolved_elem_ty.toIntern(), |
| 15185 | | .flags = .{ |
| 15186 | | .size = .Many, |
| 15187 | | .address_space = ptr_as, |
| 15188 | | }, |
| 15189 | | }); |
| 15190 | | const slice_ty_ref = Air.internedToRef(slice_ty.toIntern()); |
| 15188 | |
| 15189 | const many_ty = slice_ty.slicePtrFieldType(zcu); |
| 15190 | const many_alloc = try block.addTyOp(.bitcast, many_ty, mutable_alloc); |
| 15191 | 15191 | |
| 15192 | 15192 | // lhs_dest_slice = dest[0..lhs.len] |
| 15193 | const slice_ty_ref = Air.internedToRef(slice_ty.toIntern()); |
| 15193 | 15194 | const lhs_len_ref = try pt.intRef(Type.usize, lhs_len); |
| 15194 | 15195 | const lhs_dest_slice = try block.addInst(.{ |
| 15195 | 15196 | .tag = .slice, |
| 15196 | 15197 | .data = .{ .ty_pl = .{ |
| 15197 | 15198 | .ty = slice_ty_ref, |
| 15198 | 15199 | .payload = try sema.addExtra(Air.Bin{ |
| 15199 | | .lhs = alloc, |
| 15200 | .lhs = many_alloc, |
| 15200 | 15201 | .rhs = lhs_len_ref, |
| 15201 | 15202 | }), |
| 15202 | 15203 | } }, |
| 15203 | 15204 | }); |
| 15205 | |
| 15204 | 15206 | _ = try block.addBinOp(.memcpy, lhs_dest_slice, lhs); |
| 15205 | 15207 | |
| 15206 | 15208 | // rhs_dest_slice = dest[lhs.len..][0..rhs.len] |
| ... | ... | @@ -15210,7 +15212,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15210 | 15212 | .data = .{ .ty_pl = .{ |
| 15211 | 15213 | .ty = Air.internedToRef(many_ty.toIntern()), |
| 15212 | 15214 | .payload = try sema.addExtra(Air.Bin{ |
| 15213 | | .lhs = alloc, |
| 15215 | .lhs = many_alloc, |
| 15214 | 15216 | .rhs = lhs_len_ref, |
| 15215 | 15217 | }), |
| 15216 | 15218 | } }, |
| ... | ... | @@ -15230,18 +15232,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15230 | 15232 | |
| 15231 | 15233 | if (res_sent_val) |sent_val| { |
| 15232 | 15234 | const elem_index = try pt.intRef(Type.usize, result_len); |
| 15233 | | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 15235 | const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty); |
| 15234 | 15236 | const init = Air.internedToRef((try pt.getCoerced(sent_val, lhs_info.elem_type)).toIntern()); |
| 15235 | 15237 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); |
| 15236 | 15238 | } |
| 15237 | 15239 | |
| 15238 | | return alloc; |
| 15240 | return block.addTyOp(.bitcast, constant_alloc_ty, mutable_alloc); |
| 15239 | 15241 | } |
| 15240 | 15242 | |
| 15241 | 15243 | var elem_i: u32 = 0; |
| 15242 | 15244 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 15243 | 15245 | const elem_index = try pt.intRef(Type.usize, elem_i); |
| 15244 | | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 15246 | const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty); |
| 15245 | 15247 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 15246 | 15248 | .array_cat_offset = inst_data.src_node, |
| 15247 | 15249 | .elem_index = elem_i, |
| ... | ... | @@ -15253,7 +15255,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15253 | 15255 | const rhs_elem_i = elem_i - lhs_len; |
| 15254 | 15256 | const elem_index = try pt.intRef(Type.usize, elem_i); |
| 15255 | 15257 | const rhs_index = try pt.intRef(Type.usize, rhs_elem_i); |
| 15256 | | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 15258 | const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty); |
| 15257 | 15259 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 15258 | 15260 | .array_cat_offset = inst_data.src_node, |
| 15259 | 15261 | .elem_index = @intCast(rhs_elem_i), |
| ... | ... | @@ -15263,12 +15265,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15263 | 15265 | } |
| 15264 | 15266 | if (res_sent_val) |sent_val| { |
| 15265 | 15267 | const elem_index = try pt.intRef(Type.usize, result_len); |
| 15266 | | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 15268 | const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty); |
| 15267 | 15269 | const init = Air.internedToRef((try pt.getCoerced(sent_val, lhs_info.elem_type)).toIntern()); |
| 15268 | 15270 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); |
| 15269 | 15271 | } |
| 15270 | 15272 | |
| 15271 | | return alloc; |
| 15273 | return block.addTyOp(.bitcast, constant_alloc_ty, mutable_alloc); |
| 15272 | 15274 | } |
| 15273 | 15275 | |
| 15274 | 15276 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, result_len); |