Skip to content

ability to do conditional compilation on zig version including when builtin functions change #21957

@andrewrk

Description

@andrewrk

Currently, if a builtin function is added to the language, it is not possible to conditionally use it depending on the Zig version number:

const builtin = @import("builtin");
const introduced_new_thing = std.SemanticVersion.parse("0.12.0-dev.1377+3fc6fc681") catch unreachable;
const have_new_thing = builtin.zig_version.order(introduced_new_thing).compare(.gte));

fn example() void {
    if (have_new_thing) {
        @theNewBuiltin();
    }
}

Without this proposal, this code would cause older versions of the compiler to produce a compile error if a call to @theNewBuiltin was found anywhere in the file.

Not all such language changes can be accounted for by checking the version number, however, many of them can, and I think adding builtins should be one of them.

However, the downside here is that bad builtin calls in dead code would no longer be reportable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions