Skip to content

[TG-9450] Allocate reference arrays with constant size in assignments from json #5112

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

This is to ensure static reference arrays retrieved from a json file are assigned with a constant size (when not marked as @nondetLength). This is so that array-cell-sensitivity can apply to such arrays.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • 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.
  • [na] White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@romainbrenguier romainbrenguier changed the title Allocate reference arrays with constant size in assignments from json [TG-9450] Allocate reference arrays with constant size in assignments from json Sep 17, 2019
@romainbrenguier romainbrenguier force-pushed the feature/assign-from-json-ref branch 7 times, most recently from 473a686 to d114b94 Compare September 20, 2019 09:13
@romainbrenguier romainbrenguier marked this pull request as ready for review September 20, 2019 09:33
@codecov-io
Copy link

codecov-io commented Sep 20, 2019

Codecov Report

Merging #5112 into develop will increase coverage by <.01%.
The diff coverage is 94.28%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5112      +/-   ##
===========================================
+ Coverage    66.95%   66.96%   +<.01%     
===========================================
  Files         1145     1146       +1     
  Lines        93653    93702      +49     
===========================================
+ Hits         62702    62743      +41     
- Misses       30951    30959       +8
Flag Coverage Δ
#cproversmt2 42.68% <ø> (ø) ⬆️
#regression 63.45% <82.85%> (ø) ⬆️
#unit 31.91% <74.28%> (+0.08%) ⬆️
Impacted Files Coverage Δ
jbmc/src/java_bytecode/java_bytecode_language.h 76.92% <ø> (ø) ⬆️
...bmc/src/java_bytecode/java_static_initializers.cpp 99.11% <100%> (+0.02%) ⬆️
jbmc/src/java_bytecode/code_with_references.h 100% <100%> (ø)
jbmc/src/java_bytecode/code_with_references.cpp 80% <80%> (ø)
jbmc/src/java_bytecode/assignments_from_json.cpp 98% <96.96%> (-0.28%) ⬇️
src/util/std_code.h 91.95% <0%> (-0.49%) ⬇️
...src/java_bytecode/java_bytecode_convert_method.cpp 97.53% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f097054...69348e0. Read the comment docs.

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.

✔️
Passed Diffblue compatibility checks (cbmc commit: d114b94).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128489226

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

I don't fully grasp why the references are necessary (perhaps add some high-level docs about what they're doing?), but I don't see anything troubling.

@@ -28,9 +28,6 @@ Author: Diffblue Ltd.
/// ones that are not marked `const` may be mutated.
struct object_creation_infot
Copy link
Contributor

Choose a reason for hiding this comment

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

Commit message: "We make is to make it so" -> "We make it so"

public:
std::list<std::shared_ptr<code_with_referencest>> list;

void add(code_without_referencest code);
Copy link
Contributor

Choose a reason for hiding this comment

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

You seem to use add(code_without_referencest{...}) a lot, so perhaps just create an add(codet) overload?

*reference.array_length, ID_ge, from_integer(0, java_int_type())}}});
code.add(code_without_referencest{
allocate_array(reference.expr, *reference.array_length, info.loc)});
code.add(reference_allocationt{id, info.loc});
Copy link
Contributor

Choose a reason for hiding this comment

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

Commit "Add reference allocation code for references" doesn't seem to do what it says (it only deletes code from get_or_create_reference)

@@ -63,3 +63,9 @@ void code_with_references_listt::append(code_with_references_listt &&other)
{
list.splice(list.end(), other.list);
}

void code_with_references_listt::add_to_front(code_without_referencest code)
Copy link
Contributor

Choose a reason for hiding this comment

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

Commit message: typo "begginning"

@romainbrenguier romainbrenguier force-pushed the feature/assign-from-json-ref branch from d114b94 to 69348e0 Compare September 23, 2019 07:09
@romainbrenguier
Copy link
Contributor Author

@smowton

I don't fully grasp why the references are necessary (perhaps add some high-level docs about what they're doing?), but I don't see anything troubling.

This is already explained in the documentation of assign_from_json, we need them for objects that are reference-equal. For instance Object a = new Object(); Object b = new Object(); Object c = a;" We have c == abut notb == aand the way to distinguish the two cases in the json is to makeca reference toa`.

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.

✔️
Passed Diffblue compatibility checks (cbmc commit: 69348e0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128702645

Not that the json file has been modified on purpose so that this checks
that it is actually loaded and not retrieved by execution of the Util function.
This test does not work with symex-driven-lazy-loading because this option is
not compatible with --property.

Choose a reason for hiding this comment

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

⛏️ Missing new line

@@ -902,11 +902,10 @@ code_with_references_listt assign_from_json_rec(
return result;
}

void assign_from_json(
code_with_references_listt assign_from_json(

Choose a reason for hiding this comment

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

⛏️ Typo in the commit message: the all the value pairs -> all the value pairs

This better reflects what this function does and make it easier to
refactor.
This is in preparation for adding a new class in this file, we add there
the function and class which will be needed by this class.
This will be use in assign_from_json for json files in which the "@ref"
and "@id" entries are used, so that we can easily substitute code marked
by "@ref" by the code corresponding to the object marked by "@id".

This also move object_creation_referencet to the new header file since
it will be used there, and the allocate_array is now declared in the new
header and defined in the corresponding cpp file.
This should be an output of the functions rather than an "info".
We make it so that assign_*_from_json functions have a return
type which reflects what the function does. That way we separate
the json to assignment conversion from the writting of code blocks,
which will ultimately allow us to rewrite references in the assignments.
We know the number of elements of the reference array only when it is
assigned so we replace the reference.array_length field at that point.
This will make it easier to add declarations at the begginning of a list of
codet after the rest of the code has been generated.
This will allow references to be replaced after the all value pairs
have been replaced.
For instance in the regression test
regression/jbmc/deterministic_assignments_json/test_char_array_pass.desc
the reference 2 wouldn't have been assigned before the end of the
assign_from_json call in which it is referenced for the first time so
its allocation size would be non-deterministic but this is fixed by this
commit.
This is a case for the json conversion which requires particular
attention.
This checks that array cell sensitivity works fine for static arrays,
whether we use the --static-values option or not.
@romainbrenguier romainbrenguier force-pushed the feature/assign-from-json-ref branch from 69348e0 to bc47e49 Compare September 23, 2019 11:10
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.

✔️
Passed Diffblue compatibility checks (cbmc commit: bc47e49).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128757153

@romainbrenguier romainbrenguier merged commit bec782e into diffblue:develop Sep 23, 2019
@romainbrenguier romainbrenguier deleted the feature/assign-from-json-ref branch September 23, 2019 14:39
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.

5 participants