-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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: implement labeled switch/continue #19812
Open
mlugg
wants to merge
9
commits into
ziglang:master
Choose a base branch
from
mlugg:computed-goto-2
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+2,374
−784
Commits on May 3, 2024
-
Configuration menu - View commit details
-
Copy full SHA for d27e73c - Browse repository at this point
Copy the full SHA d27e73cView commit details -
Air: direct representation of ranges in switch cases
This commit modifies the representation of the AIR `switch_br` instruction to represent ranges in cases. Previously, Sema emitted different AIR in the case of a range, where the `else` branch of the `switch_br` contained a simple `cond_br` for each such case which did a simple range check (`x > a and x < b`). Not only does this add complexity to Sema, which -- as our secondary bottleneck -- we would like to keep as small as possible, but it also gets in the way of the implementation of ziglang#8220. This proposal turns certain `switch` statements into a looping construct, and for optimization purposes, we want to lower this to AIR fairly directly (i.e. without involving a `loop` instruction). That means we would ideally like a single instruction to represent the entire `switch` statement, so that we can dispatch back to it with a different operand as in ziglang#8220. This is not really possible to do correctly under the status quo system. For now, the actual lowering of `switch` is identical for the LLVM and C backends. This commit contains a TODO which temporarily regresseses all remaining self-hosted backends in the presence of switch case ranges. This functionality will be restored for at least the x86_64 backend before merge of this branch.
Configuration menu - View commit details
-
Copy full SHA for 0d99a13 - Browse repository at this point
Copy the full SHA 0d99a13View commit details -
Air: add explicit
repeat
instruction to repeat loopsThis 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 ziglang#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.
Configuration menu - View commit details
-
Copy full SHA for 3fd3bda - Browse repository at this point
Copy the full SHA 3fd3bdaView commit details -
Configuration menu - View commit details
-
Copy full SHA for db6c216 - Browse repository at this point
Copy the full SHA db6c216View commit details -
std.zig: resolve syntactic ambiguity
The parse of `fn foo(a: switch (...) { ... })` was previously handled incorrectly; `a` was treated as both the parameter name and a label. The same issue exists for `for` and `while` expressions -- they should be fixed too, and the grammar amended appropriately. This commit does not do this: it only aims to avoid introducing regressions from labeled switch syntax.
Configuration menu - View commit details
-
Copy full SHA for aaa83b3 - Browse repository at this point
Copy the full SHA aaa83b3View commit details -
x86_64: un-regress
loop
andswitch_br
This commit fixes codegen for the `loop` and `switch_br` instructions in the self-hosted x86_64 backend, which was previously regressed by this branch. It does *not* yet implement the new `loop_switch_br` instruction.
Configuration menu - View commit details
-
Copy full SHA for 750b804 - Browse repository at this point
Copy the full SHA 750b804View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2ed552d - Browse repository at this point
Copy the full SHA 2ed552dView commit details -
wasm: un-regress
switch_br
and fixloop
`.loop` is also a block, so the block_depth being stored for the loop was incorrect. By storing the value *after* block creation, we ensure a correct block_depth to jump back to when receiving `.repeat`. This also un-regresses `switch_br` which now correctly handles ranges within cases. It supports it for both jump tables as well as regular conditional branches.
Configuration menu - View commit details
-
Copy full SHA for e962ba9 - Browse repository at this point
Copy the full SHA e962ba9View commit details -
Configuration menu - View commit details
-
Copy full SHA for ac6e2e7 - Browse repository at this point
Copy the full SHA ac6e2e7View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.