-
Notifications
You must be signed in to change notification settings - Fork 274
Stop propt inheriting from messaget [blocks: #3800] #3249
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
Stop propt inheriting from messaget [blocks: #3800] #3249
Conversation
c372326
to
8d49b96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I think this is a very good idea.
- The reason for me requesting changes is the (seemingly?) unrelated change as noted below.
- More of a comment than a strict requirement: let's not do this
set_message_handler
game, but instead make thepropt
constructor take amessage_handlert&
and set things up in the constructor.
src/solvers/prop/prop_conv.h
Outdated
@@ -117,7 +117,6 @@ class prop_conv_solvert:public prop_convt | |||
typedef std::map<irep_idt, literalt> symbolst; | |||
typedef std::unordered_map<exprt, literalt, irep_hash> cachet; | |||
|
|||
const cachet &get_cache() const { return cache; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes sorry, this shouldn't be in this PR
This will introduce a lot of noise, if done consistently, and the benefit isn't obvious? |
To me, the benefit would be fixing a design flaw (the "is-a" relationship seems wrong), but maybe I'm missing something? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm generally in favour of doing that if we do it across the entire code base. It's a lot of churn, but not really much breaking changes as we are mostly passing around message_handlert.
We should then also add a rule to the coding standard that (ui_)message_handlert is passed through the constructor instead of a setter and decide on a consistent name for the messaget member, eg one of message
, msg
, log
or logger
.
8d49b96
to
b055e6b
Compare
+1 to all that @peterschrammel said, but also I'd like to hear more from @kroening as he seemed to be less happy with the route being taken. |
@peterschrammel I'm not sure why we have to do it across the whole code base at the same time? Is it just a naming issue? |
b055e6b
to
7af156d
Compare
Kind of agree with the discussion above. Let's be consistent; either inherit from or parameter to construction (do we ever swap the message output source? If not, let's just have it as part of the constructor), a slow migration seems painful. Is it worth doing ... unclear to me. |
For me it's clearly worth doing. If someone is trying to understand this code, the first thing they see is what the class inherits from, then they wonder "why is a decision procedure a message?", then they dig into messaget and realize it doesn't really represent messages but still has no link with what a solver should intuitively do, and they are left confused before having learned anything useful about solvers. |
From me to change my review to "approve" I'd ask for a proper constructor to be used, the member really shouldn't (need to) be public. As far as naming is concerned, let's try to set a precedent here: whatever is chosen here should make people happy and should over time be used elsewhere. (Personally I think something along the lines of |
7af156d
to
b7aeac9
Compare
@tautschnig I've added fixup commits to make the field protected, rename it to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As stated below, I'd propose an even stricter regime and only keep constructors that pass the message handler.
@@ -21,10 +21,11 @@ Author: Daniel Kroening, [email protected] | |||
|
|||
/*! \brief TO_BE_DOCUMENTED | |||
*/ | |||
class propt:public messaget | |||
class propt | |||
{ | |||
public: | |||
propt() { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, don't you need to consume a message_handlert
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't there before so adding one instead of constructing a new one could potentially change the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it makes things safer, so I'd happily take that change.
@@ -19,6 +19,11 @@ dimacs_cnft::dimacs_cnft():break_lines(false) | |||
{ | |||
} | |||
|
|||
dimacs_cnft::dimacs_cnft(message_handlert &message_handler) : dimacs_cnft() | |||
{ | |||
log.set_message_handler(message_handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to be a bit painful, but let's please try to use the constructor all the way, i.e., it would be dimacs_cnft(message_handler)
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea but this would go a bit beyond scope of a refactoring PR, and my initial statement "No functional changes." wouldn't be strictly true anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if we have no bugs (surely true) then it wouldn't entail any functional changes, because each time we construct a dimacs_cnft
we surely also initialized its message handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It we leave it initialized, doesn't it just means that some messages wouldn't get printed? This would be difficult to detect. It's also a bit difficult to manually check, as a lot of classes inherit from dimacs_cnft
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think any introduced functional change is a strict improvement here. Any class deriving should be forced to call a constructor that takes a message handler.
@@ -18,6 +18,7 @@ class dimacs_cnft:public cnf_clause_listt | |||
{ | |||
public: | |||
dimacs_cnft(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diffblue compatibility check is currently unavailable.
Please create manual bump.
(cbmc commit: b7aeac9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/90838766
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magnificent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving for now (but needs a rebase), the changes I had requested will happen as part of #3800.
863c4d6
to
de1a8f0
Compare
There was a problem hiding this 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: de1a8f0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/99395288
@@ -238,21 +238,21 @@ propt::resultt satcheck_minisat2_baset<T>::prop_solve() | |||
|
|||
if(solver_result==l_True) | |||
{ | |||
messaget::status() << | |||
"SAT checker: instance is SATISFIABLE" << eom; | |||
log.status() << "SAT checker: instance is SATISFIABLE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 230 also needs to be updated (Windows build).
@@ -580,7 +580,7 @@ void arrayst::add_array_constraints_update( | |||
|
|||
if(index_expr.type()!=value.type()) | |||
{ | |||
prop.error() << expr.pretty() << messaget::eom; | |||
prop.message.error() << expr.pretty() << messaget::eom; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change (inside a #if 0
block) looks suspicious: I believe this should be just error()
.
de1a8f0
to
2d9a3c1
Compare
No functional changes. A propt object should not be used as a messaget so the messaget should rather be a field.
2d9a3c1
to
756b003
Compare
There was a problem hiding this 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: 756b003).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/99448369
No functional changes.
A propt object should not be used as a messaget so the messaget should
rather be a field.