zig icon indicating copy to clipboard operation
zig copied to clipboard

Rename `simd.suggestVectorSize` to clarify intent and fix related segfault

Open castholm opened this issue 1 year ago • 2 comments

Closes #18296.

The first commit fixes the segfault in mem.indexOfSentinel.

The second renames suggestVectorSize to suggestVectorLength and makes the former a compile error. The function returns the vector length (as in, the number of elements), not the size in bytes of the entire vector or the bit size of individual elements. This distinction is important and some usages of the function in the stdlib operated under these incorrect assumptions.

I combed through nearby local variables and updated the names of them where the distinction was relevant.

Let me know if you would rather have the bug fix and the updated function names be two separate change sets.

castholm avatar Dec 19 '23 21:12 castholm

Wouldn't suggestVectorLen fit better here to parallel .len on arrays and slices?

notcancername avatar Dec 23 '23 20:12 notcancername

Wouldn't suggestVectorLen fit better here to parallel .len on arrays and slices?

No opinion, but I should add I went with "length" because that file already had a function named vectorLength a few lines down.

https://github.com/ziglang/zig/blob/4ae4ded16488cd70ef4473889f343c27373045de/lib/std/simd.zig#L80-L86

castholm avatar Dec 23 '23 21:12 castholm

Another excellent @castholm patch.

andrewrk avatar Jan 10 '24 01:01 andrewrk