zigtools / zls

A Zig language server supporting Zig developers with features like autocomplete and goto definition
MIT License
2.99k stars 297 forks source link

Provide a configuration option to use incremental compilation for build-on-save #2001

Open mlugg opened 2 months ago

mlugg commented 2 months ago

After ziglang/zig#21063 is merged, the Zig compiler is able to perform certain incremental updates correctly. There's still a ways to go before it's generally usable, but -fno-emit-bin builds will be the first thing to work correctly, and some do under that PR. For instance, simple incremental updates to the compiler itself typically do the right thing now.

In the future, incremental compilation will be able to help the Zig compiler expose detailed semantic information to ZLS or a similar project (ziglang/zig#615). However, ZLS can still make good use of incremental compilation before upstream progress is made there.

If ZLS' build runner introduces support for std.Build.Watch like the standard build runner does, which should be a relatively straightforward enhancement, it can begin using incremental compilation for build-on-save. (Incremental compilation currently only works if the compiler process stays running via the compiler server protocol: serialization and deserialization of compiler state to disk is a WIP feature.)

This functionality should be behind a config option which can be disabled by default. It's definitely possible to crash the compiler right now, or even to get false positive compile errors; incremental compilation is not stable, even when not emitting a binary. When we are emitting a binary, it'll basically crash immediately, so this will currently only work if the user is providing via build_on_save_step the name of a step which will pass -fno-emit-bin to the compiler. Nevertheless, it might be valuable to expose this as an option for people to try out.

andrewrk commented 2 months ago

What component are you talking about enhancing? The build system already has -fincremental and --watch which can be combined together.

andrewrk commented 2 months ago

Oh, man I was really confused for a moment there. I thought I was commenting on the zig issue tracker. Sorry!

Techatrix commented 2 months ago

@andrewrk Welcome to ZLS, happy to have you back! 🎉 We have missed you here since your last visit in 2020