Skip to content

Changes to intervals needed to merge VSD #5203

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

Closed
wants to merge 35 commits into from

Conversation

martin-cs
Copy link
Collaborator

Similar to #5202 this is a series of commits pulled out of the variable-sensitivity-domain branch. As some of the patches have been squashed and cherry-picked multiple times I am not 100% sure of who wrote what but I think the full set of authors is correct. Again, squashing and editing of the commit messages are probably needed but let's look at the code first.

  • 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.

Daniel Neville and others added 30 commits December 8, 2019 20:49
(INT) Interval values
Also fix wrong placing of parentheses in output
As it stands in conflicted with the method from exprt
So they don't conflict with the exprt methods
Also, mark them as explicit where appropriate and
add some documentation
Also replace some asserts with INVARIANT, PRECONDITION or UNREACHABLE
Also left some comments for things that need to be cleaned up
in the future
Also, refactor minus and correct a typo in the comments
and add tests for them and eval.
Previously the typecast operator for interval_exprt simply set the type on the
bounds; This yielded incorrect results for widening or narrowing casts. This
delegates the typecast handling to simplify_expr instead.
@@ -0,0 +1,95 @@
/*******************************************************************\
Module: Unit tests for variable/sensitivity/abstract_object::merge
Author: DiffBlue Limited

Choose a reason for hiding this comment

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

So it turns out it’s spelled Diffblue actually, oops.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix.

@hannes-steffenhagen-diffblue
Copy link
Contributor

Worth pointing out that this has... limitations w.r.t. to floating point numbers.

@martin-cs
Copy link
Collaborator Author

@hannes-steffenhagen-diffblue Thanks for the note about floating-point. Yes, there are still things to do on this code but I would like to get VSD merged and then improve.

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

There are a number of ways the intervals code could be improved to help maintainability, but in the interest of getting something merged I suggest focusing on two priorities and address the other points in due course:

  • ensure that testing covers 100% of the file - there is so much code here it seems like there will be a few typos that a complete set of unit tests will surely catch.
  • minimize and tidy the public API as this will be hard to do after the fact (as code gets added, removing it later will be harder).

I will rebase this now so that we can see the codecov report, and add a commit eliminating parts of the interface that probably aren't required.

rhs_i=lhs_i;
if(rhs_i.is_bottom())
make_bottom();
if(id == ID_lt && !lhs_i.is_less_than(rhs_i))
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ I'd expect to see an equivalent for ID_gt and ID_ge?

{
}

explicit min_exprt(const exprt &_expr) : exprt(ID_min, _expr.type())
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ What is the reason for this constructor?

PRECONDITION(is_well_formed());
}

constant_interval_exprt(const constant_interval_exprt &x)
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Why the manual copy constructor? Seems like the default would work


bool is_well_formed() const
{
bool b = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ b-> well_formed;
💡 I'd probably just ditch the overall local variable and introduce a few locals:

const bool valid_type = is_numeric() || type.id() == ID_bool  ...
...
retur valid_type && matching_type && valid_bounds

return b;
}

bool is_valid_bound(const exprt &expr) const
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ This can be static if expr.type() is used

Comment on lines +25 to +34
WHEN("Something")
{
THEN("Something else")
{
REQUIRE(
constant_interval_exprt(CEV(4), CEV(8))
.left_shift(constant_interval_exprt(CEV(1))) ==
constant_interval_exprt(CEV(8), CEV(16)));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks incomplete and maybe tested elsewhere?

@@ -143,6 +143,47 @@ template<class T> class interval_templatet
}
}

void make_bottom()
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ I need to see why these changes are introduced - they seem unrelated to the rest of the PR>

/// or min_exprt for the lower bound
/// or max_exprt for the upper bound
/// Also, lower bound should always be <= upper bound
class constant_interval_exprt : public binary_exprt
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ from an "is-a" relation, I don't think an interval really is a binary expr? Not sure...

Comment on lines +436 to +439
if(equal(get_upper(), o.get_upper()) && equal(get_upper(), o.get_upper()))
{
return tvt(true);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong. For one, it appears to be if(A && A) and if the intention is whether upper == o.upper && lower ==o.lower, this is wrong. I think this should always be unknown unless the intersection is empty, then false, or one element, then true

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH the semantics of this are confusing, do you expect [a, b] == [a, b] to be true or unknown The docs appear to suggest unknown, this behaviour appears to suggest true. I think depending on context you will want one or the other, so probably much safer to not guess and implement two clearly different methods: range_equal which returns true or false if the ranges are exactly the same, and value_equal which returns a tvt - but this can be left for now and fixed in the follow up PR

@thk123 thk123 mentioned this pull request May 21, 2020
7 tasks
@thk123
Copy link
Contributor

thk123 commented May 22, 2020

However, given that the VSD is based on this interface - I think it actually makes more sense to merge this, and then tidy up the interface along with changes required to the VSD in subsequent PR. Instead i will dimiss comments to this effect - and will focus on the testing component

@thk123 thk123 mentioned this pull request May 27, 2020
6 tasks
@thk123
Copy link
Contributor

thk123 commented Jun 4, 2020

#5361, a rebased version of this, has been merged. #5362 still needs to be merged (a small fix from this PR), but I'm going to close this PR in any case.

@thk123 thk123 closed this Jun 4, 2020
@thk123
Copy link
Contributor

thk123 commented Jun 5, 2020

Just noting here #5362 has now also been merged.

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.

6 participants