Skip to content

Factor out goto model processing and default options #2049

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 3 commits into from
Apr 18, 2018

Conversation

karkhaz
Copy link
Collaborator

@karkhaz karkhaz commented Apr 12, 2018

This PR introduces a static method for setting CBCM's default options, and makes two of cbmc_parse_optiont's methods static (for getting and processing a goto-model). This is so that clients that wish to emulate CBMC's functionality can do so by calling into these static methods, rather than duplicating code that is currently scattered through the file.

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.

This refactoring is great, and my requests-for-more-work are all only possible because you started this line of work. Sorry that it means there is even more work to do... @peterschrammel @kroening could you comment on whether some of that work is also useful to simplify/reduce redundancy with other *_parse_optionst instances?

@@ -111,6 +130,8 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
if(cmdline.isset("paths"))
options.set_option("paths", true);

cbmc_parse_optionst::set_default_options(options);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit pick: may I suggest to move this up by three lines to be the very first step before doing if(cmdline.isset...?

options.set_option("simplify-if", true);

// Default false
options.set_option("stop-on-fail", false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please add unwinding-assertions, partial-loops, slice-formula in here and refactor their current command-line/options code to use if(cmdline.isset...)?

const optionst &options)
goto_modelt &goto_model,
const optionst &options,
const cmdlinet &cmdline,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your change highlights one existing poor design: this function should not be using cmdline anymore, anything it cares about ought to have been placed in options. Could you please clean this up as well?

const cmdlinet &cmdline,
messaget &log,
ui_message_handlert &ui_message_handler,
message_handlert &mh)
Copy link
Collaborator

Choose a reason for hiding this comment

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

mh and ui_message_handler will actually be the same in the context of cbmc_parse_optionst, and both of which you'd get by doing log.get_message_handler(). What you wouldn't be able to get, though, is ui_message_handler.get_ui() so maybe pass that in addition to just a messaget?

const optionst &options,
const cmdlinet &cmdline,
messaget &log,
message_handlert &mh)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above: just pass log, and obtain mh via log.get_message_handler().

@karkhaz karkhaz force-pushed the kk-factor-goto-model-processing branch 2 times, most recently from 20594cf to 0859693 Compare April 12, 2018 15:18
@karkhaz
Copy link
Collaborator Author

karkhaz commented Apr 12, 2018

Just pushed some changes. Please could you confirm that the hunk at cbmc_parse_options.cpp:224 captures the right intention? I think this is a bit more explicit than before, even, since the code before would silently ignore --unwinding-assertions if --cover is passed...but perhaps that behaviour is intentional?

At the severe risk of creating more work for myself...there are queries to cmdline scattered everywhere, for example in process_goto_program. Many of the cmdline options that are being queried never even get an option set for them. Arguably, I could go on a crusade to get rid of all lookups to cmdline after the initial setting of options, so that the only object we ever pass around is options. On the other hand, since options is used fairly deep inside CBMC (at least inside symex, maybe even later) perhaps it makes sense to keep it as small as possible? Some of the cmdline options that are queried in the front-end only make sense in the front end, e.g. --version, --show-goto-functions etc and perhaps it's a waste of lookup time to drag them all over the rest of the program. I don't have strong opinions either way, let me know what your preference is.

I think eventually it might be desirable to avoid passing options around to deep code as well as cmdline. I've opened #2050 based on a discussion @tautschnig and I had about something unrelated.

@karkhaz karkhaz force-pushed the kk-factor-goto-model-processing branch from 0859693 to 85e8d63 Compare April 12, 2018 15:42
There was previously no public interface to check whether an option had
been set in an optionst object; this meant that clients were instead
using the isset() method of cmdlinet. This change allows us to set the
options from the cmdlinet near the beginning of the front-end, and not
refer to the cmdlinet afterward.
@karkhaz karkhaz force-pushed the kk-factor-goto-model-processing branch from 85e8d63 to 9af0a1c Compare April 12, 2018 16:44
CBMC parse options that have default values are all set in a single
place---a static method that may also be called from any client that
needs to emulate CBMC's default options (e.g. unit tests). Previous to
this commit, there were a lot of

    if(cmdline.isset("no-foo"))
      options.set_option("foo", false);
    else
      options.set_option("foo", true);

This commit removes all the else cases.
@karkhaz karkhaz force-pushed the kk-factor-goto-model-processing branch from 9af0a1c to b7b9ad9 Compare April 12, 2018 17:23
@karkhaz
Copy link
Collaborator Author

karkhaz commented Apr 12, 2018

All checks passed. I implemented your suggestion of changing cmdline lookups to options lookups, but there were several things passed on the command line that were not having an option set for them (property, reachability-slice{,-fb}, bounds-check, pointer-check, nondet-static) so I'm setting options for those now.

options.set_option("bounds-check", true);

if(cmdline.isset("pointer-check"))
options.set_option("pointer-check", true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

"pointer-check" and "bounds-check" are actually covered by PARSE_OPTIONS_GOTO_CHECK below so those two can be skipped here.

cmdline.isset("unwinding-assertions"));
error() << "--cover and --unwinding-assertions "
<< "must not be given together" << eom;
exit(CPROVER_EXIT_USAGE_ERROR);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's probably a good idea to communicate this to users explicitly.

nondet_static(goto_model);
}

if(cmdline.isset("string-abstraction"))
if(options.get_bool_option("string-abstraction"))
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 this option is getting set above?

@@ -777,21 +806,21 @@ bool cbmc_parse_optionst::process_goto_program(
// add loop ids
goto_model.goto_functions.compute_loop_numbers();

if(cmdline.isset("drop-unused-functions"))
if(options.get_bool_option("drop-unused-functions"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be checked as well above, I think.

{
error() << "--reachability-slice and --reachability-slice-fb "
<< "must not be given together" << eom;
log.error() << "--reachability-slice and --reachability-slice-fb "
Copy link
Collaborator

Choose a reason for hiding this comment

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

May I suggest moving this options-collision checking up with the cmdline parsing? Errors should be flagged as early as possible.

@karkhaz
Copy link
Collaborator Author

karkhaz commented Apr 12, 2018

sigh thanks for pointing these out. My strategy was to set the option for each command-line that was causing a test somewhere to fail. So all of the ones you pointed out don't have sufficient test coverage that it made a difference that I missed setting their option 😞 I now feel that this is fragile and prone to drift apart in the future---in both directions: where somebody misses setting an option, or where an option is accidentally set twice like in PARSE_OPTIONS_GOTO_CHECK. I don't really feel qualified to write tests to check for this.

I'll sort these out tomorrow, need to sleep now, but maybe I'll think of a more robust way of doing this (or I'd appreciate any suggestions). I've often fantasied about writing a new parse_optionst base class where everything would be specified in one single uniform place (flag, help text, action if the flag was passed)---similar to the path_choosert initializer in #1915, and shared between the cprover tools as needed. But not sure if that would be welcome, or a good use of time...

@tautschnig
Copy link
Collaborator

[...] I've often fantasied about writing a new parse_optionst base class where everything would be specified in one single uniform place [...]

Is #1521 of some help in this regard? Not that it specifies one single solution, but at least there is discussion - please do chime in!

Other than that: yes, better test coverage is needed, or really just a record of current test coverage. There has been some work on that, but AFAIK that got put on the backlog.

@karkhaz karkhaz force-pushed the kk-factor-goto-model-processing branch 2 times, most recently from 8aa1ea1 to 3e4a77e Compare April 15, 2018 21:50
@karkhaz
Copy link
Collaborator Author

karkhaz commented Apr 16, 2018

Comments are addressed, all checks are passing. I'll wait until I at least have a skeleton implementation before chiming in, I want to see if my ideas are practical.

(One other thing that I wanted to have is a command line interface that could dump itself as {ba,z}sh completion files, man pages, etc...there's already a script that does this, but it would be nice to do it programatically rather than parsing cmdline text, since then we could also pass type information to zsh completion and so on)

@smowton
Copy link
Contributor

smowton commented Apr 17, 2018

This looks great -- one question, to what degree can this be factored with JBMC?

@karkhaz
Copy link
Collaborator Author

karkhaz commented Apr 17, 2018

@smowton my feeling is that it might end up becoming a mess of front-end specific checks if we used the same static method? E.g. JBMC needs a lazy_goto_modelt, the options are slightly different and may become more or less different over time, etc.

I haven't actually tried it, but it looks like there would have to be e.g. a static cbmc_doit and static jbmc_doit, which would each call into static bmc_doit that contains common code, but there are things that need to happen in the middle of those functions...I'm not sure that it's worth factoring front-end stuff into a single method is worth it just yet. Having a common BMC is fine IMO, but there seems to be too many small differences in front-end stuff to justify it...

@smowton
Copy link
Contributor

smowton commented Apr 17, 2018

Fair enough, leave it then

options.set_option("simplify", true);
options.set_option("simplify-if", true);

// Default false
Copy link
Collaborator

@tautschnig tautschnig Apr 17, 2018

Choose a reason for hiding this comment

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

I am wondering: should this part actually be omitted completely? It does make a difference if the (new) is_set is used, but for get_bool_option setting them to false is as good as not setting them.

Edit: many other options also default to false, but are not being set here. I'm always after consistency...

CBMC's methods for getting a goto-model from a source file, and
processing that goto-model to be ready for bounded model checking, are
now static so that they can be called from clients that wish to set up a
goto-model the same way that CBMC does.
@karkhaz karkhaz force-pushed the kk-factor-goto-model-processing branch from 3e4a77e to 014d151 Compare April 17, 2018 22:23
@karkhaz
Copy link
Collaborator Author

karkhaz commented Apr 18, 2018

@tautschnig I removed the default-false options.

@tautschnig tautschnig merged commit 0bff19b into diffblue:develop Apr 18, 2018
@karkhaz karkhaz deleted the kk-factor-goto-model-processing branch April 18, 2018 21:10
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.

3 participants