Skip to content

introduce protected_exprt #3855

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
Jan 29, 2019
Merged

introduce protected_exprt #3855

merged 5 commits into from
Jan 29, 2019

Conversation

kroening
Copy link
Member

This will serve as the interface that we aspire exprt to offer; in
particular, access to opX is protected.

  • 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.
  • 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
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: cd7d05d).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/97934741
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

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

This presumably requires a TG bump before merging - will create to see how much additional work is required.

@@ -870,8 +870,8 @@ void value_set_fit::get_reference_set_sharing_rec(
insert(dest, exprt(ID_unknown, expr.type()));
else
{
index_exprt index_expr(
object, from_integer(0, index_type()), expr.type());
exprt index_expr =
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Why remove the type from lhs? Because we call make_typecast which makes this not an index_exprt 😱 -> ⛏️ don't change the type, instead create a typecast from the index_exprt

Copy link
Member Author

Choose a reason for hiding this comment

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

#3856 will fix this!

/// This API will eventually replace exprt.
class protected_exprt : public exprt
{
protected:
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Would it make more sense to use protected inheritance? I assume the answer is no as there remains calls to other methods, that have not been removed, but perhaps given this direction of travel it would making more sense to using them into the public section? (I think you can do this, but I have not actually tried).

Copy link
Contributor

Choose a reason for hiding this comment

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

This would circumvent the need for this class entirely and just update the classes that inherit from exprt to protected extend it and in fact allow for explicitly identifying the classes that use the wrong interface.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are a lot of classes inheriting from exprt; furthermore, the interface of exprt should change as well, once we are there.

src/util/expr.h Outdated
@@ -318,6 +318,40 @@ class exprt:public irept
const_unique_depth_iteratort unique_depth_cend() const;
};

/// Protected class for all expressions.
/// This API will eventually replace exprt.
class protected_exprt : public exprt
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ I slightly worry about the name, in general, X_exprt means an expression representing an AST node of type X. I guess protected is never a node of a C/C++/Java AST, but perhaps this should be called expr_protected or expr_api_protected to indicate that this is an internal fudge rather than an actual GOTO thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

@thk123
Copy link
Contributor

thk123 commented Jan 21, 2019

Ah this doesn't yet compile on CBMC - will hold off on the bump front for now.

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: 5d451cc).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98429525
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.

@thk123
Copy link
Contributor

thk123 commented Jan 24, 2019

@kroening This still isn't compiling on cbmc yet:

value_set_fi.cpp:858:48: error: within this context
           index_expr.make_typecast(array.type());

So will hold off on the bump for now.

@thk123 thk123 assigned kroening and unassigned thk123 Jan 24, 2019
src/util/expr.h Outdated
@@ -319,6 +319,40 @@ class exprt:public irept
const_unique_depth_iteratort unique_depth_cend() const;
};

/// Protected class for all expressions.
Copy link
Collaborator

@tautschnig tautschnig Jan 24, 2019

Choose a reason for hiding this comment

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

What is a "protected" class? Who is being protected? From what risks are they being shielded? When should anyone use it? I think this comment needs to be reworded.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused, an intermittent version had more elaborate documentation. Do a git reflog to look at those?

src/util/expr.h Outdated
DEPRECATED("use protected_exprt(id, type) instead")
explicit protected_exprt(const irep_idt &_id) : exprt(_id)
{
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems rather weird that newly introduced code would be deprecated? Can we just not have these?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, removed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Back again?

src/util/expr.h Outdated
using exprt::op3;
// using exprt::find;
// using exprt::get;
// using exprt::set;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding commented-out code without comments is just raising questions, but not providing answers.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, removed

const typet &type=
static_cast<const typet &>(expr.find(ID_C_c_sizeof_type));
// need to cast down to access 'find'
const auto &expr_as_irep = static_cast<const irept &>(expr);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that's an improvement?

@kroening kroening force-pushed the protected_exprt branch 2 times, most recently from 768c17e to f9368aa Compare January 24, 2019 15:00
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: 7b6444a).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98484788
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.

🚫
This PR failed Diffblue compatibility checks (cbmc commit: d9ae0f7).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98523776
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.

const auto &expr_as_irep = static_cast<const irept &>(expr);

const typet &type =
static_cast<const typet &>(expr_as_irep.find(ID_C_c_sizeof_type));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this still necessary, given .find is no longer protected?

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

using exprt::op0;
using exprt::op1;
using exprt::op2;
using exprt::op3;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this really be done? A multi_ary_exprt can, but need not have this many operands? For an unidentified multi_ary_exprt the caller should always use .operands() and just operate on that data structure.

Copy link
Member Author

Choose a reason for hiding this comment

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

replaced by ranged-checked opX().

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔

src/util/expr.h Outdated
@@ -319,6 +319,29 @@ class exprt:public irept
const_unique_depth_iteratort unique_depth_cend() const;
};

/// Class for expressions that offers a restriction of the API
/// offered by exprt. Notably, access to non-type-safe methods such
/// as opX() is protected.

Choose a reason for hiding this comment

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

Does that mean that exprt subclasses that so far only have these as their API will get updated (e.g. classes like typecast_exprt that only have op0 rather than a named accessor?).

Also, if we're already going to do an API do-over, why make the "new" expr inherit from irept at all, rather than have an irep as a protected field or something?

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.

It looks like some earlier version has been restored? Might be worth looking at the commits the GitHub lists or going for git reflog.

src/util/expr.h Outdated
@@ -319,6 +319,40 @@ class exprt:public irept
const_unique_depth_iteratort unique_depth_cend() const;
};

/// Protected class for all expressions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused, an intermittent version had more elaborate documentation. Do a git reflog to look at those?

src/util/expr.h Outdated
DEPRECATED("use protected_exprt(id, type) instead")
explicit protected_exprt(const irep_idt &_id) : exprt(_id)
{
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Back again?

Daniel Kroening added 2 commits January 26, 2019 11:53
This will enable protecting exprt::opX()
make_typecast isn't type safe; typecast_exprt::conditional_cast is.
Daniel Kroening added 3 commits January 26, 2019 12:09
exprt::make_typecast() isn't type safe
This prevents out-of-bound accesses to operands().
This will serve as the interface that we aspire exprt to offer; in
particular, access to opX is protected.
@kroening
Copy link
Member Author

Back again!

// make op0 and op1 public
using exprt::op0;
using exprt::op1;

const exprt &op2() const = delete;
exprt &op2() = delete;
const exprt &op3() const = delete;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there are still too many users -- but I'd say that it makes sense to work towards removing these two lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

(But at least it's not dangerous to use them).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand - these are being deleted, even though protected_exprt makes them unavailable anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, ok, the "this" was unclear.

The deletion of op2() and op3() is indeed no longer needed.

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: a48f855).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98702385
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.

@kroening kroening assigned peterschrammel and unassigned kroening Jan 27, 2019
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.

The changes to bits of code I am responsible for are fine. I will leave it to others to have opinions on the exact API. Being cleaner about the use of exprts / irepts is a good thing in general.

@@ -319,6 +319,28 @@ class exprt:public irept
const_unique_depth_iteratort unique_depth_cend() const;
};

/// Base class for all expressions. This protects low-level methods in
/// exprt that are not type safe. Depcrecated constructors are removed.
Copy link
Member

Choose a reason for hiding this comment

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

Typo in deprecated

@kroening kroening merged commit e4af3bf into develop Jan 29, 2019
@kroening kroening deleted the protected_exprt branch January 29, 2019 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants