Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: zig check [source] #5208

Closed
The-Jon opened this issue Apr 28, 2020 · 4 comments
Closed

add: zig check [source] #5208

The-Jon opened this issue Apr 28, 2020 · 4 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@The-Jon
Copy link

The-Jon commented Apr 28, 2020

The issue is that the compiler won't give any error messages if the code/function isn't called.

This check mode should deactivate the lazy compilation so that the whole code will be analyzed/checked for errors.

Similar to Rust "cargo check"

@pfgithub
Copy link
Contributor

pfgithub commented Apr 29, 2020

Currently, this can be done using zig test by adding this line to a file that imports everything:

test "" {
    meta.refAllDecls(@This());
}

Example: https://github.com/ziglang/zig/blob/master/lib/std/std.zig

@daurnimator
Copy link
Contributor

This check mode should deactivate the lazy compilation so that the whole code will be analyzed/checked for errors.

What sort of errors?

Many code paths are intentionally errors on various combinations of architecture/OS.

The long term plan here is #3028

@daurnimator daurnimator added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Apr 29, 2020
@Vexu Vexu added this to the 0.7.0 milestone May 9, 2020
@SpexGuy
Copy link
Contributor

SpexGuy commented Sep 21, 2020

Here's a more concrete proposal for how this could be done:

  • First, mark all publicly reachable decls from a certain file that are considered to be in the same module as that file as "reachable".
  • For each decl, run a check compile. When running a check compile, certain identifiers are marked as "unknown". This includes any generic parameters to the function. Providing something like a -notarget parameter could mark many of the std.builtin values as unknown for a less strict test. This could also work with multibuilds (How to destroy the memory of the string field in JSON #3208).
  • Any code involving a comptime identifier whose value is unknown is not checked and evaluates to unknown.
  • Any code with comptime identifiers that are known are checked with that set of parameters.
  • Functions called with a set of parameters that are partially known are checked with the pieces that are known, even if they are in a different package.
  • An extra argument (-whynot), possibly with a regex filter, could output information about things that are not checked and why they were not checked.

This sort of check would catch problems like this, which are not caught by refAllDecls because the function is generic:

pub fn foo(x: anytype) u32 {
    x.bar();
    return "foo";
}

@andrewrk
Copy link
Member

Closing as Too Complicated.

I also want to note that since this proposal was filed, zig has gained the zig ast-check sub-command and many checks have moved over to AstGen, resulting in quite a few compile errors no longer being lazy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

6 participants