Sema: @memcpy changes

* The langspec definition of `@memcpy` has been changed so that the
  source and destination element types must be in-memory coercible,
  allowing all such calls to be raw copying operations, not actually
  applying any coercions.
* Implement aliasing check for comptime `@memcpy`; a compile error will
  now be emitted if the arguments alias.
* Implement more efficient comptime `@memcpy` by loading and storing a
  whole array at once, similar to how `@memset` is implemented.
This commit is contained in:
mlugg
2025-01-28 02:49:58 +00:00
committed by Matthew Lugg
parent 97ccf3504f
commit 71d16106ad
5 changed files with 173 additions and 52 deletions

View File

@@ -2057,6 +2057,22 @@ pub fn elemType2(ty: Type, zcu: *const Zcu) Type {
};
}
/// Given that `ty` is an indexable pointer, returns its element type. Specifically:
/// * for `*[n]T`, returns `T`
/// * for `[]T`, returns `T`
/// * for `[*]T`, returns `T`
/// * for `[*c]T`, returns `T`
pub fn indexablePtrElem(ty: Type, zcu: *const Zcu) Type {
const ip = &zcu.intern_pool;
const ptr_type = ip.indexToKey(ty.toIntern()).ptr_type;
switch (ptr_type.flags.size) {
.many, .slice, .c => return .fromInterned(ptr_type.child),
.one => {},
}
const array_type = ip.indexToKey(ptr_type.child).array_type;
return .fromInterned(array_type.child);
}
fn shallowElemType(child_ty: Type, zcu: *const Zcu) Type {
return switch (child_ty.zigTypeTag(zcu)) {
.array, .vector => child_ty.childType(zcu),