diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-04-25 03:46:10 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-09-01 18:30:31 +0100 |
| commit | 5fb4a7df38deb705f77088d7788f0acc09da613d (patch) | |
| tree | 5616328dadfb98993775ae1758ce631a3a216334 /test/behavior/switch_loop.zig | |
| parent | 1b000b90c9a7abde3aeacf29cef73a877da237e1 (diff) | |
| download | zig-5fb4a7df38deb705f77088d7788f0acc09da613d.tar.gz zig-5fb4a7df38deb705f77088d7788f0acc09da613d.zip | |
Air: add explicit `repeat` instruction to repeat loops
This commit introduces a new AIR instruction, `repeat`, which causes
control flow to move back to the start of a given AIR loop. `loop`
instructions will no longer automatically perform this operation after
control flow reaches the end of the body.
The motivation for making this change now was really just consistency
with the upcoming implementation of #8220: it wouldn't make sense to
have this feature work significantly differently. However, there were
already some TODOs kicking around which wanted this feature. It's useful
for two key reasons:
* It allows loops over AIR instruction bodies to loop precisely until
they reach a `noreturn` instruction. This allows for tail calling a
few things, and avoiding a range check on each iteration of a hot
path, plus gives a nice assertion that validates AIR structure a
little. This is a very minor benefit, which this commit does apply to
the LLVM and C backends.
* It should allow for more compact ZIR and AIR to be emitted by having
AstGen emit `repeat` instructions more often rather than having
`continue` statements `break` to a `block` which is *followed* by a
`repeat`. This is done in status quo because `repeat` instructions
only ever cause the direct parent block to repeat. Now that AIR is
more flexible, this flexibility can be pretty trivially extended to
ZIR, and we can then emit better ZIR. This commit does not implement
this.
Support for this feature is currently regressed on all self-hosted
native backends, including x86_64. This support will be added where
necessary before this branch is merged.
Diffstat (limited to 'test/behavior/switch_loop.zig')
0 files changed, 0 insertions, 0 deletions
