My interpretation of:
TODO talk about C ABI interop
In the documentation, is that Vectors are intended to ‘just work’ with C, doing what one would expect… when possible.
There’s a lot of handwaving involved in saying that, though. I find the following comparison informative.
This is legal, and does what you’d expect:
export fn vSum(v: @Vector(4, u8)) u32 {
return @reduce(.Add, v);
}
test "export vecFn" {
const v: @Vector(4, u8) = .{ 1, 2, 3, 4 };
try expectEqual(10, vSum(v));
}
This, however, is a compile error:
export fn vSum(v: @Vector(4, u9)) u32 {
return @reduce(.Add, v);
}
error: parameter of type ‘@Vector(4, u9)’ not allowed in function with calling convention ‘etc’
My takeaway: if it’s a ‘natural’ machine-typed vector, it has a well-defined C ABI representation, and it’s fine. Interestingly this works with e.g. @Vector(1024, u16), so it isn’t limited to natural SIMD types. Presumably you can pass that a * uint16_t, and pinky-swear it has 1024 elements? Pure guesswork on my part.
Another data point: a @Vector(8, 256) passes std.meta.hasUniqueRepresentation, but is a compile error in export context: probably extern struct also, although I didn’t try that.
So the way to find out is: put the type where you want it and see what the compiler says. ¯\_(ツ)_/¯
It does seem worth documenting what’s going on here. The less lore, the better.