run clean compilation when link inputs change on incremental update #32081

Open
opened 2026-04-26 11:01:56 +02:00 by mlugg · 0 comments
Owner

The Zig compiler has the concept of the "prelink" phase, which handles all non-incremental inputs (i.e. objects, archives, and shared libraries) are processed before incremental handling of Zig code begins. However, as originally reported in #22501, this has implications for handling incremental updates when link inputs are changed: if a C source file input is modified on an incremental update, the self-hosted linkers will currently fail to handle the change correctly because they have already finish their prelink work.

#22501 suggested solving this by forcing linker implementations to support re-running prelink when link inputs change, but I recall us later agreeing that, at least for now, it would be fine for modification of non-Zig link inputs to force a clean build.

Therefore, the Zig compiler frontend should handle non-incremental link inputs being updated, by including them in the cache manifest when CacheMode.incremental is used (and recreating the compilation if the cache check misses). This means no work is required from linker implementations: they can simply assume that all link inputs are non-incremental.

Of course, we can (and I suspect ultimately will) consider another enhancement down the line to allow linkers to handle modifications of link inputs while keeping the existing incremental ZCU state. But for now, let's simplify our lives a bit and reduce the risk of exposing users to untested/buggy edge cases.

The Zig compiler has the concept of the "prelink" phase, which handles all non-incremental inputs (i.e. objects, archives, and shared libraries) are processed *before* incremental handling of Zig code begins. However, as originally reported in [#22501](https://github.com/ziglang/zig/issues/22501), this has implications for handling incremental updates when link inputs are changed: if a C source file input is modified on an incremental update, the self-hosted linkers will currently fail to handle the change correctly because they have already finish their prelink work. [#22501](https://github.com/ziglang/zig/issues/22501) suggested solving this by forcing linker implementations to support re-running prelink when link inputs change, but I recall us later agreeing that, at least for now, it would be fine for modification of non-Zig link inputs to force a clean build. Therefore, the Zig compiler *frontend* should handle non-incremental link inputs being updated, by including them in the cache manifest when `CacheMode.incremental` is used (and recreating the compilation if the cache check misses). This means no work is required from linker implementations: they can simply assume that all link inputs are non-incremental. Of course, we can (and I suspect ultimately will) consider another enhancement down the line to allow linkers to handle modifications of link inputs while keeping the existing incremental ZCU state. But for now, let's simplify our lives a bit and reduce the risk of exposing users to untested/buggy edge cases.
mlugg added this to the Urgent milestone 2026-09-01 21:24:21 +02:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ziglang/zig#32081
No description provided.