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

Compiler fails without explanation or trace #6909

Open
marler8997 opened this issue Nov 1, 2020 · 4 comments
Open

Compiler fails without explanation or trace #6909

marler8997 opened this issue Nov 1, 2020 · 4 comments
Labels
os-windows standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@marler8997
Copy link
Contributor

There is a bug that's a few months old now where the Zig compiler will fail if any pathnames contain ".." on Windows (see #6044).

However, there are really 2 problems here, the first being that the Zig compiler can't handle .. in pathnames, and the second being that the compiler fails without a helpful explanation as to what happened. I've created this issue to track and second problem. I'm not sure if the lack of an error message or error trace is unique to this ".." problem, or if there are other codepaths in the compiler that would also cause this.

The following will reproduce this issue on Windows:

> mkdir src
> echo "" > src\bug.zig
> zig build-obj src\..\src\bug.zig
error: Unexpected

A better experience would look something like this:

> zig build-obj src\..\src\bug.zig
NTCreateFile "src\..\src\bug.zig" failed with error.Unexpected

Printing an error trace would also be better.

Issue also seen on Reddit: https://www.reddit.com/r/Zig/comments/jlprjh/trying_to_diagnose_compiler_error_unexpected/

@andrewrk
Copy link
Member

andrewrk commented Nov 1, 2020

error: Unexpected

If you ever see this, there is one clear action path to take, which is to get a debug build of the compiler and cause the issue again, because it means we need to add another NTSTATUS code to the switch case, and a debug build will tell you the source line and the NTSTATUS number.

Right now it is annoying to get a debug build of zig on windows if you are building with MSVC because MSVC does not let you mix release LLVM + debug zig. However I have a plan to use zig-bootstrap to distribute a "zig source toolkit" which is a .zip file which contains release LLVM+LLD+Clang+Zig and then you can use zig as a C/C++ compiler for building zig from source, in any mode. This will make it easy to work on zig without even having MSVC installed.

@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Nov 1, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Nov 1, 2020
@jarlostensen
Copy link

I do a lot of Windows development and I probably stress the pipeline in slightly unusual ways as I build freestanding kernels in that environment so I'm happy to take this further with a debug build as soon as possible. Let me know what I can do to help. I've also seen problems with the build pipeline (build.zig) on Windows which appear to be related to the use of NtCreateFile but I've not had an opportunity to try and diagnose it further.

@marler8997
Copy link
Contributor Author

marler8997 commented Nov 2, 2020

@andrewrk it sounds like in a release build, we don't really have a feasible way to solve this? If so, maybe the solution here is to have Zig handle unexpected errors with a message like this?

> zig build-obj src\..\src\bug.zig
An unexpected error occurred, unable to gather more information since this is a release build of the compiler.

At least with this people who run into unexpected errors will have an idea of what action to take next (i.e. try to get a debug build of the compiler to root cause the underlying issue).

@andrewrk
Copy link
Member

andrewrk commented Nov 2, 2020

@marler8997 that looks reasonable. It would be pretty straightforward to translate errors that end up bubbling out of main into more friendly errors explaining what steps could be taken next.

@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os-windows standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

3 participants