elliottt opened PR #5756 from trevor/default-in-jump-table
to main
:
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
bjorn3 submitted PR review.
bjorn3 created PR review comment:
Maybe keep it as first element instead?
elliottt edited PR #5756 from trevor/default-in-jump-table
to main
:
While working through #5731, adapting
branch_destination
to return an iterator over multiple slices ofBlockCall
values was a little awkward, and yielded more complicated indexing for heavily used operations likeinst_values
. As the root of the problem is the jump table default target and data not living in contiguous memory, there was a somewhat obvious solution: inline the default block into theJumpTableData
, and remove it from theBranchTable
instruction data.The resulting refactoring is implemented in this PR: jump tables require a default block when they are created, and maintain an invariant that the last element of their internal vector is always the default label. Additionally, they now export slices for both the vector and just the jump table, to make it easy to adapt existing uses of
as_slice
.For a little bit of additional motivation, consider this godbolt link. There are three indexing functions implemented: one that indexes into two slices using
nth
on a chained iterator; one that checks which slice the index falls on; and one that indexes into a single slice. By far the best option is indexing into a single slice, followed by choosing the slice to index, followed by usingnth
. Without this refactoring, we would need to pick the approach in eitherindex1
orindex2
to finish transitioningbr_table
to usingBlockCall
arguments, and both feel like bad options.<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
bjorn3 submitted PR review.
bjorn3 created PR review comment:
*excluding
here and below?
elliottt submitted PR review.
elliottt created PR review comment:
Thanks for catching that!
elliottt submitted PR review.
elliottt created PR review comment:
The only downside there is that we would break the invariant that the table data is 0-indexed. However, as we can always return a slice to the table data, maybe that's fine?
elliottt updated PR #5756 from trevor/default-in-jump-table
to main
.
elliottt has marked PR #5756 as ready for review.
bjorn3 submitted PR review.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
This sounds like define or definition to me. Default is a keyword, and default_ isn't the nicest either. Unless someone has a better suggestion I guess leaving it the way it is right now is fine.
bjorn3 created PR review comment:
This is still needed, right?
bjorn3 created PR review comment:
Iter skips the default block, right?
bjorn3 created PR review comment:
Maybe cleanup for a followup PR, but is a separate targets argument still necessary?
bjorn3 created PR review comment:
I think so.
elliottt submitted PR review.
elliottt created PR review comment:
As it's using
iter_mut
, the default label is included.
elliottt submitted PR review.
elliottt created PR review comment:
Right now it is, but I'd like to change that as well. It would be great to have a function for translating the blocks in the branch instructions instead of passing the labels as an extra argument.
elliottt submitted PR review.
elliottt created PR review comment:
iter
includes the default block. I decided thatas_slice
,as_slice_mut
,iter
, anditer_mut
would iterate the whole vector, and that access to just the table or default block would be throughtable_slice
anddefault_block
.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
I see
elliottt submitted PR review.
elliottt created PR review comment:
Perhaps it would be better to go the other way, and introduce a special function for accessing a slice for the whole vector, keeping the existing functions as excluding the default?
bjorn3 submitted PR review.
bjorn3 created PR review comment:
Another option would be to not use the regular names for conversion to a slice or iterator at all, but instead explicitly call out which part is returned for each function, both those returning everything and those returning only a part.
elliottt submitted PR review.
elliottt created PR review comment:
I think I'm going to rework this to keep the existing behavior consistent, and introduce new functions to iterate the whole range. Thanks for pointing this out :)
elliottt updated PR #5756 from trevor/default-in-jump-table
to main
.
elliottt submitted PR review.
elliottt created PR review comment:
I switched it to iterate over
all_branches_mut
instead, which reads a bit better and doesn't change the meaning of the old function.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
7.0.0
elliottt updated PR #5756 from trevor/default-in-jump-table
to main
.
elliottt submitted PR review.
elliottt created PR review comment:
Whoops :sweat_smile:
elliottt updated PR #5756 from trevor/default-in-jump-table
to main
.
elliottt updated PR #5756 from trevor/default-in-jump-table
to main
.
elliottt updated PR #5756 from trevor/default-in-jump-table
to main
.
elliottt updated PR #5756 from trevor/default-in-jump-table
to main
.
jameysharp submitted PR review.
jameysharp submitted PR review.
jameysharp created PR review comment:
This comment should be updated to refer to
all_branches
instead ofiter
.
jameysharp created PR review comment:
I was going to say that this should just use
table.all_branches()
but then I remembered that would change the visit order. Instead, would you update the comment above to note that some callers depend on the default block being visited first?
elliottt updated PR #5756 from trevor/default-in-jump-table
to main
.
elliottt merged PR #5756.
elliottt submitted PR review.
elliottt created PR review comment:
I implemented this change in #5770.
Last updated: Dec 23 2024 at 12:05 UTC