-
Notifications
You must be signed in to change notification settings - Fork 277
De-duplicate "generate a nondet int in a given range" logic #4416
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
De-duplicate "generate a nondet int in a given range" logic #4416
Conversation
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: 1433c1c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/105338866
Status will be re-evaluated on next push.
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 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.
Looks great
src/util/nondet.cpp
Outdated
@@ -93,15 +82,16 @@ code_blockt generate_nondet_switch( | |||
|
|||
code_blockt result_block; | |||
|
|||
allocate_objectst allocate_objects( | |||
mode, source_location, name_prefix, symbol_table); |
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.
⛏️ prefer braces
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.
Done. I keep forgetting about this new convention...
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's not really new, just that it wasn't really applied, then someone pointed out this guideline to me on one of my PR, so I have been annoying everyone with this since then. 😈
from_integer(0, java_int_type()), | ||
max_length_expr, | ||
location); | ||
"nondet_array_length", | ||
loc, |
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 is location
replaced with loc
?
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.
Didn't even notice that as CLion suggested loc
here. loc
is a field of the object factory and location
is the parameter to the function. From what I can see these two values are always the same so one of them is unnecessary. For now I changed it back to location
, and I'll tidy up the loc
/location
duplication in a follow-up PR. 🍊
@@ -13,6 +13,25 @@ Author: Diffblue Ltd. | |||
#include <util/std_expr.h> | |||
#include <util/symbol_table.h> | |||
|
|||
/// Same as \ref generate_nondet_int( | |||
/// const mp_integer &min_value, |
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.
Does this multi-line \ref
actually render correctly in Doxygen?
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 tried it locally and it links to the right function, though only the generate_nondet_init
part turns into a link. Some of the parameter types (like source_locationt
) also appear as links to the Doxygen for those types.
If there is a better / more standard way of linking between overloaded functions, please let me know.
src/util/nondet.cpp
Outdated
@@ -7,6 +7,7 @@ Author: Diffblue Ltd. | |||
\*******************************************************************/ | |||
|
|||
#include "nondet.h" | |||
#include "allocate_objects.h" |
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.
Nit pick:
#include "nondet.h"
#include "allocate_objects.h"
#include "arith_tools.h"
#include "c_types.h"
#include "fresh_symbol.h"
#include "symbol.h"
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.
Fixed the linebreaks in the same commit and removed the "util" parts in a new commit (same as the one for the forward declarations below).
src/util/nondet.h
Outdated
@@ -9,6 +9,7 @@ Author: Diffblue Ltd. | |||
#ifndef CPROVER_JAVA_BYTECODE_NONDET_H | |||
#define CPROVER_JAVA_BYTECODE_NONDET_H | |||
|
|||
#include <util/allocate_objects.h> | |||
#include <util/std_code.h> | |||
#include <util/std_expr.h> | |||
#include <util/symbol_table.h> |
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 guess it's the first time I'm properly looking at this: the only includes we really need here are #include "std_code.h"
and #include "std_expr.h"
. Everything else can (and IMHO: should be) done via forward declarations.
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.
Done in a new commit.
from_integer(0, java_int_type()), | ||
minus_exprt(length_expr, from_integer(1, java_int_type())), | ||
location); | ||
"enum_index_init", | ||
loc, |
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.
Just like @romainbrenguier I'm surprised this even compiles? As it does, is the location
parameter for this method unnecessary?
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.
See my comment marked 🍊 above.
The way the object factory passes variables around is currently quite messy in general, it uses a mix of
- class fields (even though there isn't a publicly visible class here; from what I can see the class is only used to store fields)
- many parameters to most functions
- a poorly named
java_object_factory_parameterst
which groups further arguments into a struct.
The three common ways of moving lots of variables around are all combined in one place here... I would like to generally tidy this up a bit, probably moving away from lots of function parameters and fields to bundling more things in (a) struct(s). Let me know what you think.
fcb2ec6
to
f2c6f83
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: fcb2ec6).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/105427335
Status will be re-evaluated on next push.
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 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: f2c6f83).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/105427499
Status will be re-evaluated on next push.
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 compatibility was already broken by an earlier merge.
src/util/nondet.cpp
Outdated
allocate_objectst &allocate_objects, | ||
code_blockt &instructions) | ||
{ | ||
PRECONDITION(min_value < max_value); |
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 fine
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.
Done (in a new commit, as the previous version used <
too).
Following the new coding standard
We will be able to use the exprt version in other parts of the code.
There is no reason why this function shouldn't work to "choose" between just one value.
This will make the functions more re-usable in parts of the code that use different prefixes.
This simplifies the code in generate_nondet_init and reduces code duplication.
Specifying "util" is not necessary as nondet.cpp is itself in the util folder. Forward declarations can be used in nondet.h.
Calls to java_object_factoryt::gen_nondet_int_init can be replaced with equivalent calls to generate_nondet_int from nondet.h.
f2c6f83
to
63d9f50
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: 63d9f50).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/105439082
Status will be re-evaluated on next push.
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 compatibility was already broken by an earlier merge.
This PR addresses code duplication between
nondet.cpp
andjava_object_factory.cpp
. The latter had a utility functiongen_nondet_int_init
which can be replaced withgenerate_nondet_int
fromnondet.h
after a few small changes.No functional change is made in this PR, only refactoring.