Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Slicing SOA array passed by value doesn't result in error

Open jakubtomsu opened this issue 1 year ago • 0 comments

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

Normal slice and SOA slice semantics should be consistent. Either slicing static arrays passed by value should be allowed, or slicing SOA arrays disallowed. I would prefer the first option because I use static arrays a lot, but I understand that might not work with Odin's procedure parameter semantics :P

Current Behavior

Regular static arrays cannot be sliced when passed by value, however SOA arrays can for some reason. This might have something to do with Addressing_SoaVariable is handled by the compiler but I'm not sure.

Foo :: struct {
    a: i32,
    b: f32,
}

get_first :: proc(foos: [10]Foo) -> []Foo {
    return foos[:] // Error: Cannot slice array 'foos[:]', value is not addressable
}

foo_soa :: proc(foos: #soa[10]Foo) -> #soa[]Foo {
    return foos[:] // No error!
}

jakubtomsu avatar Apr 29 '24 17:04 jakubtomsu