-
Notifications
You must be signed in to change notification settings - Fork 274
Clean-up message_handler of parse_options_baset #4521
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
Clean-up message_handler of parse_options_baset #4521
Conversation
2db3a82
to
a76ee1f
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.
This PR failed Diffblue compatibility checks (cbmc commit: 2db3a82).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108107188
Status will be re-evaluated on next push.
Common spurious failures include: 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); compatibility was already broken by an earlier merge.
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 PR failed Diffblue compatibility checks (cbmc commit: a76ee1f).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108108467
Status will be re-evaluated on next push.
Common spurious failures include: 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); compatibility was already broken by an earlier merge.
a76ee1f
to
0e56317
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.
This PR failed Diffblue compatibility checks (cbmc commit: 0e56317).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108123437
Status will be re-evaluated on next push.
Common spurious failures include: 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); compatibility was already broken by an earlier merge.
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.
The second commit alone is worth merging this as soon as possible, but I really think we should not need to use std::unique_ptr
here.
src/util/parse_options.h
Outdated
@@ -35,6 +37,7 @@ class parse_options_baset | |||
virtual ~parse_options_baset() { } | |||
|
|||
protected: | |||
std::unique_ptr<ui_message_handlert> 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.
Why can't this just be a stack-allocated member?
src/util/parse_options.cpp
Outdated
{ | ||
std::string optstring=std::string("?h(help)")+_optstring; | ||
parse_result=cmdline.parse(argc, argv, optstring.c_str()); | ||
message_handler = util_make_unique<ui_message_handlert>(cmdline, program); | ||
log = messaget{*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.
I really think that message_handler
should be a full member (see also comment below) and the constructor should do : message_handler(cmdline, program), log(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.
I've done the change now. The reason I didn't do it originally was that it required a bit of reordering because the command line needs to be parsed before the object is constructed, but the change is actually not too bad.
0e56317
to
aac8b2a
Compare
edfa668
to
14a57e6
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.
I think this is a nice bit of cleanup, but I suppose you didn't quite expect to be opening a can of worms. See various notes below.
@@ -174,7 +173,7 @@ class janalyzer_parse_optionst : public parse_options_baset | |||
|
|||
ui_message_handlert::uit get_ui() | |||
{ | |||
return ui_message_handler.get_ui(); | |||
return message_handler.get_ui(); |
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.
Is this method (janalyzer_parse_optionst::get_ui
) actually used?
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 it's not useful anyway...
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.
Maybe just add a commit that removes those?
jbmc/src/jbmc/jbmc_parse_options.cpp
Outdated
@@ -564,7 +566,7 @@ int jbmc_parse_optionst::doit() | |||
if(cmdline.isset("show-properties")) | |||
{ | |||
show_properties( | |||
goto_model, log.get_message_handler(), ui_message_handler.get_ui()); | |||
goto_model, log.get_message_handler(), message_handler.get_ui()); |
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.
🍌 Are log.get_message_handler()
and message_handler
actually different?
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 hope not. But I will check.
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.
Message_handler and ui shouldn't be passed separately.
jbmc/src/jbmc/jbmc_parse_options.cpp
Outdated
@@ -800,7 +802,7 @@ int jbmc_parse_optionst::get_goto_program( | |||
show_goto_functions( | |||
*goto_model, | |||
log.get_message_handler(), | |||
ui_message_handler.get_ui(), | |||
message_handler.get_ui(), |
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.
🍌 Again, are log.get_message_handler()
and message_handler
different? It looks quite confusing.
jbmc/src/jbmc/jbmc_parse_options.cpp
Outdated
@@ -943,7 +944,7 @@ bool jbmc_parse_optionst::show_loaded_functions( | |||
show_properties( | |||
ns, | |||
log.get_message_handler(), | |||
ui_message_handler.get_ui(), | |||
message_handler.get_ui(), |
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.
🍌
jbmc/src/jbmc/jbmc_parse_options.cpp
Outdated
ui_message_handler, | ||
ui_message_handler.get_ui(), | ||
message_handler, | ||
message_handler.get_ui(), |
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.
Relates to 🍌
@@ -10,6 +10,6 @@ Author: Diffblue Ltd. | |||
|
|||
int main(int argc, const char *argv[]) | |||
{ | |||
auto parse_options = goto_harness_parse_optionst(argc, argv); | |||
goto_harness_parse_optionst parse_options{argc, argv}; | |||
return parse_options.main(); |
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.
While at it, go one step further and do return goto_harness_parse_optionst{argc, argv}.main();
?
@@ -617,7 +617,7 @@ int goto_instrument_parse_optionst::doit() | |||
show_goto_functions( | |||
goto_model, | |||
log.get_message_handler(), | |||
ui_message_handler.get_ui(), | |||
message_handler.get_ui(), |
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.
🍌
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.
No need to pass message_handler and ui separately.
@@ -150,7 +148,7 @@ class goto_instrument_parse_optionst : public parse_options_baset | |||
|
|||
ui_message_handlert::uit get_ui() | |||
{ | |||
return ui_message_handler.get_ui(); | |||
return message_handler.get_ui(); |
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.
Is goto_instrument_parse_optionst::get_ui
actually used?
src/util/parse_options.h
Outdated
@@ -10,10 +10,12 @@ Author: Daniel Kroening, [email protected] | |||
#ifndef CPROVER_UTIL_PARSE_OPTIONS_H | |||
#define CPROVER_UTIL_PARSE_OPTIONS_H | |||
|
|||
#include <memory> |
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.
No longer needed
src/util/parse_options.h
Outdated
protected: | ||
ui_message_handlert 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.
I think you could reduce the size of the diff quite a bit by just naming this ui_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.
I also have a slight preference for ui_message_handler
in order to distinguish it from a plain message_handler.
14a57e6
to
3245e75
Compare
@@ -616,7 +617,7 @@ int goto_instrument_parse_optionst::doit() | |||
{ | |||
show_goto_functions( | |||
goto_model, | |||
log.get_message_handler(), | |||
ui_message_handler, | |||
ui_message_handler.get_ui(), |
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.
No need to pass the ui separately (several occurrences).
79b4117
to
5845d01
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.
This PR failed Diffblue compatibility checks (cbmc commit: 79b4117).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108645501
Status will be re-evaluated on next push.
Common spurious failures include: 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); compatibility was already broken by an earlier merge.
f075f24
to
46ec583
Compare
@peterschrammel I removed the unnecessary arguments |
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 PR failed Diffblue compatibility checks (cbmc commit: 46ec583).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108672915
Status will be re-evaluated on next push.
Common spurious failures include: 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); compatibility was already broken by an earlier merge.
ui_message_handler.get_ui() already does the same thing, and is more explicit.
The message handler field was owned by the classes inheriting from parse_options_baset which lead to strange patterns where the handler reference was initialized using a reference to a field which was not constructed yet. This is cleaner and avoid some reference duplications.
Now the log field gets initialized before parse_options_baset is constructed so there is no danger as described in the comment.
The calls will always return a reference to the field ui_message_handler which can be accessed directly instead.
The messaget can be constructed from the message_handler.
This is more precise on the type of message handler we are expecting and makes the ui argument redundant.
This removes the need for passing a seperate ui argument.
46ec583
to
262cc35
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.
This PR failed Diffblue compatibility checks (cbmc commit: 262cc35).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108712914
Status will be re-evaluated on next push.
Common spurious failures include: 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); compatibility was already broken by an earlier merge.
Based on #4520The message handler field was owned by the classes inheriting from
parse_options_baset which lead to strange patterns where the handler
reference was initialized using a reference to a field which was not
constructed yet.
This is cleaner and avoid some reference duplication.