-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Sema: @memcpy
changes
#22631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sema: @memcpy
changes
#22631
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, yeah, I suspect that most (if not all) of the usages of
|
||
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), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var arr: [10]u64 = undefined; | ||
export fn foo() void { | ||
@memcpy(arr[0..6], arr[4..10]); | ||
} | ||
|
||
comptime { | ||
var types: [4]type = .{ u8, u16, u32, u64 }; | ||
@memcpy(types[2..4], types[1..3]); | ||
} | ||
|
||
// error | ||
// | ||
// :3:5: error: '@memcpy' arguments alias | ||
// :8:5: error: '@memcpy' arguments alias |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const src: [10]u8 = @splat(0); | ||
var dest: [10]u16 = undefined; | ||
|
||
export fn foo() void { | ||
@memcpy(&dest, &src); | ||
} | ||
|
||
// error | ||
// | ||
// :5:5: error: pointer element type 'u8' cannot coerce into element type 'u16' |
Uh oh!
There was an error while loading. Please reload this page.