-
Notifications
You must be signed in to change notification settings - Fork 273
Lazy methods: allow driver program to provide stubs #2124
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
Lazy methods: allow driver program to provide stubs #2124
Conversation
Please check with #1272. Apparently there are N ways of marking something as do-not-display. Let's please not add approach N+1. The concept of "fallback functions" muddles the semantics of goto programs for the benefit of the user interface. At least that's my understanding of this matter... |
This isn't about hiding symbols or GOTO functions, it's about providing bodies for functions that we don't have source code for. Example: class A {
public int afield;
static void f() {
A a = Opaque.getA();
}
} If we don't have
DeepTest on the other hand retains the call, but uses a custom derivative of
That's more useful than JBMC's approach (I think JBMC should switch to using this method), as it (a) clarifies where the nondet init sequence came from (a call to stub In order to do this, |
Thanks a lot for the elaboration, but can we please have a comprehensive and agreed solution to address #1948, #1949, #2070, #1317, #1585, #1566 (and there might be more)? And of course right now, thanks to @hannes-steffenhagen-diffblue's work, we already have Maybe this PR is part of a bigger plan, but if so it would really help to sketch this out to make sure there isn't further fragmentation. |
Hmmm, okay, to cooperate better with these goto-instrument-oriented function generators / replacers we could instead ask the driver program what to do in this circumstance -- i.e., none of the language frontends could furnish a body for this front-end, so does the driver program want to have a go at providing a GOTO program somehow? Then it would use one of @hannes-steffenhagen-diffblue's passes, or for Java we'd do the nondet-object-graph thing. I can have a go at this solution next week. |
e25524e
to
ed58067
Compare
@tautschnig pushed an alternative implementation. I think this should satisfy everyone's needs (when using the lazy loading framework): it gives the driver program a chance to provide a body before I'm checking with @peterschrammel whether we can open-source DeepTest's stub generation code; if so I plan to submit a followup PR to get jbmc using this mechanism to provide stubs. |
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 proposal is good, because it keeps the lazy behaviour contained rather than spreading it across multiple classes and APIs.
Yet I struggle to fully evaluate it (thus sticking with "Comment" rather than "Approve") as there are no regression tests (there may be tests exercising the new code paths already present in the test suite, but no test has observably different behaviour).
src/goto-programs/lazy_goto_model.h
Outdated
@@ -110,6 +129,7 @@ class lazy_goto_modelt : public abstract_goto_modelt | |||
const goto_functionst::goto_functiont &get_goto_function(const irep_idt &id) | |||
override | |||
{ | |||
|
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.
Unintended change?
ed58067
to
5dc0093
Compare
If I get an ok to open a file of deeptest's code I will make jbmc a user of this code, then hopefully its existing tests will suffice to show this is working as intended. |
5dc0093
to
26355b1
Compare
I, for one, am ok for the moment if you tell me that there are tests elsewhere that show this makes a difference and works as intended. Not great, but if you put that note in the commit message then you're committing to it ;-) Elsewhere it was said that there are current issues in tests elsewhere, so you might, however, have to hold off on this anyway. |
26355b1
to
944c4bc
Compare
This should be tested with Deeptest once it can build with mainline cbmc again. |
@tautschnig @thk123 I've obtained permission from @peterschrammel to open a simple version of Deeptest's stub generator and added a commit to use it in jbmc. The new stub generator, If this works this will serve as a template for how Deeptest can integrate its own stub generator with lazy_goto_modelt. |
6d1bce1
to
0ce1064
Compare
Test-gen bump: https://github.com/diffblue/test-gen/pull/1794 @tautschnig @peterschrammel @thk123 @mgudemann this is ready for review. |
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.
Various, mostly stylistic notes.
#define CPROVER_JAVA_BYTECODE_SIMPLE_METHOD_STUBBING_H | ||
|
||
#include <util/symbol_table_base.h> | ||
#include <java_bytecode/java_bytecode_language.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.
Forward declarations would suffice.
{ | ||
code_blockt new_instructions; | ||
const code_typet &required_type = to_code_type(symbol.type); | ||
namespacet ns(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.
Is that actually used in this method?
#include <util/namespace.h> | ||
#include <util/prefix.h> | ||
#include <util/fresh_symbol.h> | ||
#include <util/invariant_utils.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: lexicographic sorting.
|
||
#include <util/std_expr.h> | ||
#include <util/std_code.h> | ||
#include <util/pointer_offset_size.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.
Is this needed/used?
#include <util/std_code.h> | ||
#include <util/pointer_offset_size.h> | ||
#include <util/namespace.h> | ||
#include <util/prefix.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.
Seems unused.
synthesized_source_location, | ||
ID_java, | ||
symbol_table); | ||
init_symbol.type = this_type; |
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.
Seems unnecessary?!
synthesized_source_location, | ||
ID_java, | ||
symbol_table); | ||
to_return_symbol.type = required_return_type; |
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.
Seems unnecessary?!
if(sym.value.id()!=ID_nil) | ||
return; | ||
if(sym.type.id()!=ID_code) | ||
return; |
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: the use of &&
would make this code more concise and would express what is the condition instead of saying when not to do this. Like this:
if(!sym.is_type && sym.value.id() == ID_nil && sym.type.id() == ID_code) create_method_stub(...);
(while moving the two sym.name
to the top to clearly mark the exceptional case.
void java_simple_method_stubst::check_method_stub( | ||
const irep_idt &symname) | ||
{ | ||
const symbolt &sym=*symbol_table.lookup(symname); |
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 a newly added file, so should be made clang-format correct.
This provides a hook for the driver program to either replace a method outright, or to provide a stub implementation when a function body cannot be provided by the language frontend (language_filest).
0ce1064
to
7c7c64d
Compare
@tautschnig all changes applied. |
#include <util/irep.h> | ||
|
||
class message_handlert; | ||
class object_factory_parameterst; |
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.
Some compilers insist that this should be a struct
and thus make the Travis build fail.
|
This generates simple stub bodies using the same method as convert_nondet, but creates the stubs out-of-line rather than inline. That adds support for nondet constructors, which jbmc previously ignored.
This uses lazy_goto_modelt's support for driver programs supplying method replacements to provide stub implementations of methods whose code is unavailable.
7c7c64d
to
cd04e70
Compare
Fixed the compile bug. My local clang-format (LLVM 6.0) appears to disagree with the version running on Travis (LLVM 3.7), so I'm inclined to ignore them both. |
31ef182 Merge pull request diffblue#2208 from diffblue/cleanout-goto-programs 0e84d3e Merge pull request diffblue#2195 from smowton/smowton/feature/smarter-reachability-slicer c801126 Merge pull request diffblue#2209 from diffblue/travis-no-osx-g++ 3487bf7 Reachability slicer: mark reachable code more precisely 85e8451 Merge pull request diffblue#2066 from tautschnig/bv-endianness 5e5eafb Merge pull request diffblue#2191 from smowton/smowton/feature/java-fatal-assertions 8a68ab8 remove g++ build on OS X; this is identical to the clang++ build 48e5b25 Amend faulty long-string test 3f718ba Java: make null-pointer and similar checks fatal 821eb1d remove basic_blocks and goto_program_irep d87c2db Merge pull request diffblue#2203 from diffblue/typed-lookup d77dea3 strongly type the lookup() methods in namespacet 2382f27 Merge pull request diffblue#2193 from martin-cs/feature/correct-instruction-documentation c314272 Merge pull request diffblue#2181 from diffblue/format-expr-constants 514a0a5 Merge pull request diffblue#2167 from diffblue/parse_unwindset_options 0102452 move escape(s) to string_utils f1b6174 use unwindsett in goto-instrument dcc907a introduce unwindsett for unwinding limits 10aeae8 format_expr now does index, c_bool constants, string constants 92b92d6 Correct the documentation of ASSERT : it does not alter control flow. a11add8 Expand the documentation of the goto-program instructions. a06503b Merge pull request diffblue#2197 from tautschnig/fix-help 05e4bc3 Remove stray whitespace previously demanded by clang-format 3261f4d Fix help output of --generate-function-body-options 7c67b23 Merge pull request diffblue#2110 from tautschnig/type-mismatch-exception 18fb262 Merge pull request diffblue#2025 from tautschnig/stack-depth-fix 9191b6a Merge pull request diffblue#2199 from tautschnig/simplifier-typing f99e631 Merge pull request diffblue#2198 from tautschnig/fix-test-desc 1a79a11 stack depth instrumentation: __CPROVER_initialize may be empty a7690ba Merge pull request diffblue#2185 from smowton/smowton/fix/tolerate-ts18661-types fc02e8f Restore returns before writing the simplified binary 49333eb Make restore_returns handle simplified programs 46f7987 Fix perl regular expressioons in regression test descriptions 9fe432b Merge pull request diffblue#1899 from danpoe/sharing-map-catch-unit-tests 9cc6aae Merge pull request diffblue#2081 from hannes-steffenhagen-diffblue/floating_point_simplificiation da19abe Tolerate TS 18661 (_Float32 et al) types a055454 Try all rounding modes when domain is unknown 5f7bc15 Add float support to constant propagator domain 3dc2244 Move adjust_float_expressions to goto-programs 06d8bea Merge pull request diffblue#2187 from diffblue/move-convert-nondet 6d8c3fa Merge pull request diffblue#2189 from thk123/bugfix/json-parser-restart 2ad157f Merge pull request diffblue#2186 from smowton/smowton/fix/call-graph-uninit-field cd54ad7 Corrected state persistence in the json parser 4447be0 Fix uninitialised collect_callsites field in call_grapht ead0aa3 Merge pull request diffblue#2188 from smowton/smowton/fix/init-string-types-without-refine-strings 57988fc Fix String type initialisation when --refine-strings is not active 6a76aff Move convert_nondet to java_bytecode ac6eb21 Merge pull request diffblue#1858 from danpoe/dependence-graph-fix 10b8b09 Merge pull request diffblue#2011 from thomasspriggs/final_classes a154593 Merge pull request diffblue#2087 from danpoe/feature/small-map 7002909 More dependence graph tests 66263ea Make dependence graph merge() return true when abstract state changes 3aa6dca Control dependency computation fix a408423 Simplified state merging in the dependence graph 0315816 Merge pull request diffblue#2180 from thomasspriggs/json_id2string 8941567 Merge pull request diffblue#2124 from smowton/smowton/feature/fallback-function-provider cd04e70 JBMC: use simple method stubbing pass a6b2cda Add Java simple method stubbing pass ec1127c Lazy goto model: hook for driver program to replace or stub functions b6a4382 Remove `id2string` from inside calls to the `json_stringt` constructor. b673ebb Add storage of final modifier status of java classes in `java_class_typet`. a2ad909 Small map 808dade Provide suitable diagnostics for equality-without-matching-types 89cf6fe Throw appropriate exceptions when converting constraints 2ae66c2 Produce a proper error message when catching a std::runtime_error at top level e7b3ade Workaround for Visual Studio loss of CV qualifier bug 1f661f5 Move sharing map and sharing node unit tests to util 47463a3 Use std::size_t instead of unsigned in the sharing map 3e22217 Sharing map documentation e54f740 Fix sharing map compiler warnings bcc489c Move sharing map unit tests to catch 34114b8 Use a specialised endianness map for flattening git-subtree-dir: cbmc git-subtree-split: 31ef182
This adds a mechanism for asking languaget instances to produce functions they have not advertised.
DeepTest currently uses it to supply stub function bodies (jbmc replaces the calls, but this results
in a less-useful trace, as it lacks FUNCTION_CALL steps for stubbed functions).