Odin
Odin copied to clipboard
SOA slice accessors turn into pointers instead of slices/multipointers
Context
Odin: dev-2024-03-nightly:4c35633e0
OS: Windows 10 Professional (version: 22H2), build 19045.4291
CPU: Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
RAM: 32681 MiB
Backend: LLVM 17.0.1
Expected Behavior
If I have an SOA slice, I would assume my_soa_slice.some_member
would return a multipointer, or even better a slice to the raw data. This bug is fairly annoying, since I'm forced to do a lot of casting/transmuting/pointer math, or use soa_unzip
. But unzipping is not a good solution when dealing with complex data with many members in a large changing codebase. Some other people on the Odin discord ran into this as well, and IIRC Bill said the current behavior should change.
This should probably also work with dynamic arrays, or let the user know they should use [:]
instead.
Note: fixed arrays work fine.
Current Behavior
Currently it returns a regular pointer to the data.
Steps to Reproduce
Foo :: struct {
a: f32,
b: f32,
}
foos := #soa[]Foo{}
// Error: Cannot iterate over 'foos.a' of type '^f32'
for a in foos.a {
fmt.println(a)
}
foos2 := #soa[2]Foo{}
as: [2]f32 = foos2.a // this works fine
It's hard to get both the foos.a[i]
syntax and also make foos.a
be something iterable. Since it's a pointer and not a slice, it's not exactly the trivial way of doing things.
Right, if this doesn't work with the acessor syntax that's fine, I'm mainly looking for some way to get to get the slice easily. I understand the SOA fields aren't internally stored as slices.
But maybe there could be an intrinsic, something like intrinsics.soa_unzip_field(foo.a)
. Or even just soa_unzip(foo, a)
?
Or is there a way to implement a helper proc like that in userspace?