OpenZFS Bug Ported to Zig

40 points by mtlynch


invlpg

I’m a self-proclaimed Zig fan, but this seems a little disingenuous to me. @andrewrk uses const prolifically where the original code mutated variables in place.

If he had written

    var cols = vdrz.vd_original_width;
    // ...
    cols = vdrz.get_logical_width(txg);

and

    var psize = (asize >> ashift);
    psize -= nparity * (divCeil(asize_shifted, cols) catch unreachable);
    psize <<= ashift;

which is a more direct translation of the original code, then the Zig compiler wouldn’t have caught either mistake. Surely a fairer way to put it is that @andrewrk’s preferred style, and perhaps the style of idiomatic Zig caught the error, not the language itself.

If the original code had been written in the same way, using const everywhere, then clang/gcc would’ve caught the same error with -Wunused-variable.