-
Notifications
You must be signed in to change notification settings - Fork 45
Refactor RegTraversalIter
#235
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
Conversation
This is a non-functional change to refactor `RegTraversalIter` to make it more amenable for future commits adding limits to which registers can be allocated. This change does change the API of `RegTraversalIter`, though. It boils down to several parts: - using `Cursor` internally: much of the cursor-advancing logic is duplicated between the preferred and non-preferred register list. This change adds a new, private struct--`Cursor`--to handle this. This refactoring also reduces the scope of the borrow we take down to only what is necessary (i.e., the actual register lists). - changing parameter order: this also passes through the arguments constructing a `RegTraversalIter` in the order they will be checked during iteration: first it emits the fixed register, then the hinted register, then the offset-based lookup. This is a clarity tweak. - only allow one hint register: `RegTraversalIter` allowed for two hint registers but the library never uses the second one. This change switches to only using a single register, with no other change in behavior. - minor simplifications: e.g., we can use `Option::take` to avoid a more verbose access (and removal) of the fixed register. Another possible change here would be to pass the hinted register as an `Option<PReg>` with `None` to indicate no hint. This seems more conventional and a quick audit of the code supports this but I avoided this out of an abundance of caution.
16f6604 to
10be861
Compare
cfallin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much cleaner -- thanks very much!
I'm not sure why the original implementation didn't use Option<PReg> for the hint field rather than the separate flag and I agree that'd be cleaner -- feel free to make that change as well.
|
(I'll merge this now but happy to take said additional cleanup as part of another PR.) |
As noted in a [comment] to bytecodealliance#235, passing an `Option<PReg>` _is_ a bit more clear API. To do this, this change adds `PReg::is_valid()` to do the conversion. This change (rather unnecessarily) also renames this variable to `hint` everywhere (previously: `hint`, `hint_reg`, `reg_hint`) and uses variables directly in several close-by `format!` strings. This is a non-functional change. [comment]: bytecodealliance#235 (review)
As noted in a [comment] to bytecodealliance#235, passing an `Option<PReg>` _is_ a bit more clear API. To do this, this change adds `PReg::is_valid()` to do the conversion. This change (rather unnecessarily) also renames this variable to `hint` everywhere (previously: `hint`, `hint_reg`, `reg_hint`) and uses variables directly in several close-by `format!` strings. This is a non-functional change. [comment]: bytecodealliance#235 (review)
As noted in a [comment] to #235, passing an `Option<PReg>` _is_ a bit more clear API. To do this, this change adds `PReg::is_valid()` to do the conversion. This change (rather unnecessarily) also renames this variable to `hint` everywhere (previously: `hint`, `hint_reg`, `reg_hint`) and uses variables directly in several close-by `format!` strings. This is a non-functional change. [comment]: #235 (review)
This is a non-functional change to refactor
RegTraversalIterto make it more amenable for future commits adding limits to which registers can be allocated. This change does change the API ofRegTraversalIter, though.It boils down to several parts:
Cursorinternally: much of the cursor-advancing logic is duplicated between the preferred and non-preferred register list. This change adds a new, private struct--Cursor--to handle this. This refactoring also reduces the scope of the borrow we take down to only what is necessary (i.e., the actual register lists).RegTraversalIterin the order they will be checked during iteration: first it emits the fixed register, then the hinted register, then the offset-based lookup. This is a clarity tweak.RegTraversalIterallowed for two hint registers but the library never uses the second one. This change switches to only using a single register, with no other change in behavior.Option::taketo avoid a more verbose access (and removal) of the fixed register.Another possible change here would be to pass the hinted register as an
Option<PReg>withNoneto indicate no hint. This seems more conventional and a quick audit of the code supports this but I avoided this out of an abundance of caution.