Skip to content

Make sharing map iteration independent of tree depth #4582

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

Merged
merged 5 commits into from
Apr 29, 2019

Conversation

danpoe
Copy link
Contributor

@danpoe danpoe commented Apr 28, 2019

This makes the various methods that iterate over a sharing map independent of the depth of the nodes in the tree. This is in preparation to support variable height trees.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a 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).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me, but given my judgement wasn't exactly spot-on on an earlier PR it would be great if @smowton could please review and approve.

@@ -894,6 +894,8 @@ SHARING_MAPT2(, innert *)::get_container_node(const key_type &k)
key >>= chunk;
}

SM_ASSERT(ip->is_container());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not is_defined_container here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-const version of get_container_node() adds empty nodes if the key doesn't exist yet in the map. In this case, !empty() will not hold.

@@ -378,6 +378,9 @@ TEST_CASE("Sharing map views and iteration", "[core][util]")
SECTION("Iterate")
{
sharing_map_standardt sm;

sm.iterate([](const irep_idt &key, const std::string &value) {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ... what does this test other than that it compiles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just checks that calling iterate() on an empty map doesn't violate an internal assertion of the map.

std::function<void(const key_type &k, const mapped_type &m)> f) const;

void gather_all(const baset &n, const unsigned depth, delta_viewt &delta_view)
void gather_all(const innert &n, delta_viewt &delta_view)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format would like the const; on this line as well.


for(const auto &l1 : ip1->get_container())
{
const key_type &k1=l1.get_key();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space around =

SM_ASSERT(!ip1->empty());
SM_ASSERT(!ip2->empty());

if(ip1->is_internal() && ip2->is_container())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only this way around? Also, if a node is internal in tree 1 and a leaf in tree 2, why is it guaranteed to have a single child?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other cases are handled further down in the method.

A container node can only contain more than one element if it is at the very bottom of the tree (which happens when the hash codes of two different keys are the same). Since the corresponding node of the first map is an internal node, the node can't be at the bottom, since the bottom nodes always have to be container nodes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, got you. Suggest putting that in a comment!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, added a comment to explain this.

@danpoe danpoe force-pushed the refactor/sharing-map-iteration branch 2 times, most recently from d69b9bb to 0283845 Compare April 29, 2019 10:29
@danpoe danpoe force-pushed the refactor/sharing-map-iteration branch from 0283845 to 16dae89 Compare April 29, 2019 10:41
@danpoe danpoe merged commit d14ffbc into diffblue:develop Apr 29, 2019
@danpoe danpoe deleted the refactor/sharing-map-iteration branch June 2, 2020 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants