Skip to content

Move existing type validation checks to new framework #3147

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

danpoe
Copy link
Contributor

@danpoe danpoe commented Oct 11, 2018

This removes the validate_type() functions and moves the checks into a new static method
check() of the corresponding type.

  • Each commit message has a non-empty body, explaining why the change was made.
  • My contribution is formatted in line with CODING_STANDARD.md.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • 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.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

This PR failed Diffblue compatibility checks (cbmc commit: d297f66).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/87671157
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

Passed Diffblue compatibility checks (cbmc commit: d86260c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/87673212

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

As discussed elsewhere I don't think command-line options are needed for any tool apart from goto-instrument and that only needs one. We should validate on loading (with invariants) and then give the user a way of checking them explicitly via goto-instrument.

@kroening
Copy link
Member

  1. I still think you should not cast before the check -- you can fix that by making the check methods static
  2. The code in validate.h is only used in one place -- when you validate. However, it's included basically everywhere, incurring compile-time cost very globally. The include should be only included where actually used.

@danpoe
Copy link
Contributor Author

danpoe commented Nov 2, 2018

  1. Yes, we can potentially make the methods static. The thing I wanted to avoid initially is having to use the generic accessors op0(), op1(), etc. when implementing the checks. When we're just checking the number of operands it doesn't matter but for more comprehensive checks it could make for hard to read code. In any case, could you briefly explain what the issue with first doing the cast is?

  2. Yes, that should be fixed.

@kroening
Copy link
Member

kroening commented Nov 3, 2018

On 1: yes, using .op0() etc. bugs me as well. The plan is to make these protected on exprt, and only allow them on binary_exprt etc., and those that inherit from these classes.

I would recommend the following idiom:
a) The first step is to check the number of operands, say like this:

  DATA_INVARIANT(
    expr.operands().size()==3,
    "Transition systems must have three operands");

b) Then check any subsequent conditions of these operands, using a static cast to unary_exprt, binary_exprt, ternary_exprt, etc., say like this:

  DATA_INVARIANT(static_cast<const ternary_exprt &>(expr).op0().type().id()==ID_bool, "blah...");

After these are done, the type invariants are checked, it's safe to cast to the type!

@danpoe
Copy link
Contributor Author

danpoe commented Nov 5, 2018

Ok, I'll then turn the methods like check() into static member functions that take exprt.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

🚫
This PR failed Diffblue compatibility checks (cbmc commit: 35691f5).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/90557096
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

tautschnig added a commit that referenced this pull request Nov 9, 2018
Skeleton for well-formedness checking of goto models [blocks: #3118, #3147, #3188, #3191, #3187, #3193]
@danpoe danpoe force-pushed the refactor/use-validation-methods-in-std-types branch from 35691f5 to fef7925 Compare November 12, 2018 15:46
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: fef7925).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/91092694

return static_cast<const code_typet &>(type);
}

/// \copydoc to_code_type(const typet &)
inline code_typet &to_code_type(typet &type)
{
PRECONDITION(can_cast_type<code_typet>(type));
validate_type(type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this get a corresponding check call?

@danpoe danpoe force-pushed the refactor/use-validation-methods-in-std-types branch from fef7925 to 4033502 Compare November 19, 2018 17:15
This removes the validate_type() methods and moves the checks into a new method
check() of the corresponding type.
@danpoe danpoe force-pushed the refactor/use-validation-methods-in-std-types branch from 4033502 to f2dfd2e Compare November 23, 2018 11:38
@danpoe danpoe removed their assignment Nov 23, 2018
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: f2dfd2e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/92381958

@tautschnig tautschnig merged commit 075d97a into diffblue:develop Mar 4, 2019
@danpoe danpoe deleted the refactor/use-validation-methods-in-std-types branch June 2, 2020 17:13
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.

5 participants