aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-09-15 14:49:40 +0100
committerMatthew Lugg <mlugg@mlugg.co.uk>2023-09-23 13:51:18 +0100
commit644041b3a492558592e1306d2214c9e6b25de53b (patch)
treecfddcc1e038f94a877181140c93912342a7239ad /src/Compilation.zig
parentfc3ff262374c704a01a5f8a8b0cd721e3b61a9c8 (diff)
downloadzig-644041b3a492558592e1306d2214c9e6b25de53b.tar.gz
zig-644041b3a492558592e1306d2214c9e6b25de53b.zip
Sema: refactor detection of comptime-known consts
This was previously implemented by analyzing the AIR prior to the ZIR `make_ptr_const` instruction. This solution was highly delicate, and in particular broke down whenever there was a second `alloc` between the `store` and `alloc` instructions, which is especially common in destructure statements. Sema now uses a different strategy to detect whether a `const` is comptime-known. When the `alloc` is created, Sema begins tracking all pointers and stores which refer to that allocation in temporary local state. If any store is not comptime-known or has a higher runtime index than the allocation, the allocation is marked as being runtime-known. When we reach the `make_ptr_const` instruction, if the allocation is not marked as runtime-known, it must be comptime-known. Sema will use the set of `store` instructions to re-initialize the value in comptime memory. We optimize for the common case of a single `store` instruction by not creating a comptime alloc in this case, instead directly plucking the result value from the instruction. Resolves: #16083
Diffstat (limited to 'src/Compilation.zig')
0 files changed, 0 insertions, 0 deletions