Skip to content

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

Merged

Conversation

romainbrenguier
Copy link
Contributor

@romainbrenguier romainbrenguier commented Apr 12, 2019

Based on #4520

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

  • Each commit message has a non-empty body, explaining why the change was made.
  • [na] Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • [na] 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).
  • [na] 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: 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.

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

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

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.

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.

@@ -35,6 +37,7 @@ class parse_options_baset
virtual ~parse_options_baset() { }

protected:
std::unique_ptr<ui_message_handlert> message_handler;
Copy link
Collaborator

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?

{
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};
Copy link
Collaborator

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)

Copy link
Contributor Author

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.

@romainbrenguier romainbrenguier force-pushed the clean-up/parse-options-messages branch 2 times, most recently from edfa668 to 14a57e6 Compare April 15, 2019 09:56
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.

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();
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 method (janalyzer_parse_optionst::get_ui) actually used?

Copy link
Contributor Author

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

Copy link
Collaborator

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?

@@ -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());
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@@ -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(),
Copy link
Collaborator

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.

@@ -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(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

🍌

ui_message_handler,
ui_message_handler.get_ui(),
message_handler,
message_handler.get_ui(),
Copy link
Collaborator

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();
Copy link
Collaborator

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(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

🍌

Copy link
Member

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();
Copy link
Collaborator

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?

@@ -10,10 +10,12 @@ Author: Daniel Kroening, [email protected]
#ifndef CPROVER_UTIL_PARSE_OPTIONS_H
#define CPROVER_UTIL_PARSE_OPTIONS_H

#include <memory>
Copy link
Collaborator

Choose a reason for hiding this comment

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

No longer needed

protected:
ui_message_handlert message_handler;
Copy link
Collaborator

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.

Copy link
Member

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.

@romainbrenguier romainbrenguier force-pushed the clean-up/parse-options-messages branch from 14a57e6 to 3245e75 Compare April 16, 2019 08:09
@@ -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(),
Copy link
Member

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

@romainbrenguier romainbrenguier force-pushed the clean-up/parse-options-messages branch 2 times, most recently from 79b4117 to 5845d01 Compare April 17, 2019 08:15
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: 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.

@romainbrenguier romainbrenguier force-pushed the clean-up/parse-options-messages branch from f075f24 to 46ec583 Compare April 17, 2019 09:55
@romainbrenguier
Copy link
Contributor Author

@peterschrammel I removed the unnecessary arguments

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: 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.
@romainbrenguier romainbrenguier force-pushed the clean-up/parse-options-messages branch from 46ec583 to 262cc35 Compare April 17, 2019 13:38
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: 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.

@tautschnig tautschnig merged commit d535b09 into diffblue:develop Apr 18, 2019
@romainbrenguier romainbrenguier deleted the clean-up/parse-options-messages branch April 18, 2019 07:54
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.

4 participants