Skip to content

Refactor rename using iterators instead of recursion #4254

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

romainbrenguier
Copy link
Contributor

@romainbrenguier romainbrenguier commented Feb 22, 2019

According to my experiments this is less efficient than the recursive function (I think because of the use of mutate). @tautschnig still wanted this to be in a pull request to be able to discuss it.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

No functional changes
This is an intermediary commit to make the diff of the next commit nicer.
No functional changes.
This is done automatically using clang-format.
This is so that we can have a nice diff in the next commit, for which
clang-format would not complain.
This use iterators to make the rename function not use recursion.
@kroening
Copy link
Member

I am thinking we want a function that takes a functor that can modify expressions, and does so using an explicit stack.

@tautschnig
Copy link
Collaborator

The problem with this implementation is that it calls mutate every time, even when this isn't necessary, because no renaming is to be done. This applies in particular to each of the calls to type renaming, which will hardly ever do anything (but still requires a writable reference). I've got an implementation (tautschnig@ee0b4a5) that does not require writable references, but it doesn't have the beauty of the depth iterator. If we could combine those, i.e., use the depth iterator, call the const-version of rename, and then mutate only if renaming was necessary, then we might have a nice result.

@romainbrenguier
Copy link
Contributor Author

The problem with this implementation is that it calls mutate every time, even when this isn't necessary, because no renaming is to be done. This applies in particular to each of the calls to type renaming, which will hardly ever do anything (but still requires a writable reference). I've got an implementation (tautschnig@ee0b4a5) that does not require writable references, but it doesn't have the beauty of the depth iterator. If we could combine those, i.e., use the depth iterator, call the const-version of rename, and then mutate only if renaming was necessary, then we might have a nice result.

Making rename_address/type return optional to avoid exprt write will be good to have. Can you make a pull request with this change? Whether the version with depth iterator would be nicer than the recursive version is a matter of taste I guess. If there is no clear advantage in using iterators, I would leave rename as it is.

@tautschnig
Copy link
Collaborator

Making rename_address/type return optional to avoid exprt write will be good to have. Can you make a pull request with this change?

Done: #4286

@TGWDB
Copy link
Contributor

TGWDB commented May 3, 2023

Closing due to age (no further comment on PR content), please reopen with rebase on develop if you intent to continue this work.

@TGWDB TGWDB closed this May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants