Skip to content

"multibuilds" - a plan to harmonize conditional compilation with compile errors, documentation, and IDEs #3028

@andrewrk

Description

@andrewrk

Here are some problems to solve:

  • Functions which are only called with one particular set of build flags, such as windows-only functions, would be omitted from documentation and IDE features when targeting non-windows
  • Compile errors for unused things (compile errors for unused things #335). This is currently not possible because, if a function is unused, maybe it is used when a different set of build flags are provided.
  • In order for documentation to have resolved error sets, the error inference must be evaluated. The error sets might be different depending on build flags
    • this is even true for docs of generic functions
  • whether or not code is unreachable can depend on comptime stuff such as build flags
  • Functions which take comptime parameters, what parameters are even valid? Only actual usage can fully describe what code paths are valid.

And so here is my plan: multibuilds - The idea of building not just the native target, not just a cross compiled target - but telling the compiler about the complete set of targets / build flags that are supported by the project. This gives the compiler the ability to assume that any branches not taken, are actually dead even across all the desired set of builds.

Zig is in a unique position to explore this concept, with its strong emphasis on cross compilation support.

What this looks like from an implementation perspective is roughly:

  • Add to the interface of the compiler ability to specify a set of targets/build options, rather than a single one.
  • For each target/build options, the user can choose whether this is just for analysis purposes or whether it should actually produce output.
  • Semantic analysis must build all the targets at once, and when there is a comptime branch which decides between targets/build options, the analysis must take both branches, keeping track of the builds separately. However it has to be able to connect them together at the end, for diagnostics purposes and for some advanced analysis that considers the full set of targets.

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