Garbage values when using @bitCast() on components of meta.Vector?

When I repeatedly run the following program:

const std = @import("std");
pub const Vec4f = std.meta.Vector(4, f32);

pub fn garbage(a: Vec4f) void {
    const b = Vec4f{
        @bitCast(f32, @bitCast(i32, a[0])),
        @bitCast(f32, @bitCast(i32, a[1])),
        @bitCast(f32, @bitCast(i32, a[2])),
        @bitCast(f32, @bitCast(i32, a[3])),
    };

    std.debug.print("{} {}\n", .{ a, b });
}

pub fn main() !void {
    const p = Vec4f{ 100.0, 100.0, 100.0, 100.0 };
    garbage(p);
}

The printed results look unpredictable to me. Only the first component has the value I expect.
Example output:

{ 1.0e+02, 1.0e+02, 1.0e+02, 1.0e+02 } { 1.0e+02, 4.59149454e-41, 6.93492684e-03, 2.10054639e-41 }

Should this work?

I’m not an authority on vectors, like on most other matters, but it does seem to be miscompilation to me too. This works:

const std = @import("std");

pub const Vec4f = std.meta.Vector(4, f32);

pub fn garbage(a: Vec4f) Vec4f {
    std.debug.print("a[0]: {} a[1]: {} a[2]: {} a[3]: {}\n", .{
        @bitCast(f32, @bitCast(i32, a[0])),
        @bitCast(f32, @bitCast(i32, a[1])),
        @bitCast(f32, @bitCast(i32, a[2])),
        @bitCast(f32, @bitCast(i32, a[3])),
    });

    const b0 = @bitCast(f32, @bitCast(i32, a[0]));
    const b1 = @bitCast(f32, @bitCast(i32, a[1]));
    const b2 = @bitCast(f32, @bitCast(i32, a[2]));
    const b3 = @bitCast(f32, @bitCast(i32, a[3]));
    return .{ b0, b1, b2, b3 };
}

pub fn main() !void {
    const a: Vec4f = .{ 100.0, 100.0, 100.0, 100.0 };
    const b = garbage(a);

    std.debug.print("{any} {any}\n", .{ a, b });
}

Both printing the bit-casted values from inside garbage() outputs the right thing, and assigning the individual values to temporaries before grouping them inside a vector works fine.

Interesting. Thanks for pointing out the workaround!