Skip to content

add slice cast support #580

Open
39ali wants to merge 1 commit intoRust-GPU:mainfrom
39ali:slice-cast
Open

add slice cast support #580
39ali wants to merge 1 commit intoRust-GPU:mainfrom
39ali:slice-cast

Conversation

@39ali
Copy link
Copy Markdown
Contributor

@39ali 39ali commented Apr 15, 2026

fixes casting array as a slice , or array to ptr :

*[T; N] -> *[T]

*[T; N] -> *T

fixes #465

Copy link
Copy Markdown
Member

@Firestar99 Firestar99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased it on main, squashed the fmt fixes and added disassembly and arrays from consts to the compiletest.

Overall, I'm super impressed how simple this has turned out to be. I haven't looked at our existing pointer emulation too deeply before, but this seems quite logical.

@LegNeato But this also shows that I've been wrong about RuntimeArray only being used via spirv_std::RuntimeArray, it is also used to represent slices. Just that those slices get removed in the post-link legalization, since they contain a pointer, so you don't actually see them in the disassembly of the compiletest.
See:

FieldsShape::Array { stride, count } => {
let element_type = ty.field(cx, 0).spirv_type(span, cx);
if ty.is_unsized() {
// There's a potential for this array to be sized, but the element to be unsized, e.g. `[[u8]; 5]`.
// However, I think rust disallows all these cases, so assert this here.
assert_eq!(count, 0);
SpirvType::RuntimeArray {
element: element_type,
}
.def(span, cx)

@39ali
Copy link
Copy Markdown
Contributor Author

39ali commented Apr 16, 2026

@Firestar99 we should probably use LogicalPtrCast in the future and resolve it in qptr, but the issue it'll get zombied since i think qptr is not on by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using an array as a slice causes a compiler error

2 participants