Skip to content

[TG-9450] Allocate array with right length when "@nondetLength" not used in Json #5106

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 Sep 13, 2019

These are refactoring commits apart from the last one, which does the actual change.
This makes array given by --static-values be directly allocated to the right size when they are not marked as @nondetLength or references (marked with @ref or @id).

To fully implement TG-9450 the case of references still needs to be solved and it will be done in a separate PR.

  • 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.
  • [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.
  • [na] White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@romainbrenguier romainbrenguier force-pushed the refactor/assign-from-json branch 3 times, most recently from 28b633c to a9433c6 Compare September 13, 2019 15:50
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: a9433c6).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/127412071

@codecov-io
Copy link

codecov-io commented Sep 13, 2019

Codecov Report

Merging #5106 into develop will decrease coverage by 1.6%.
The diff coverage is 97.22%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5106      +/-   ##
===========================================
- Coverage    66.94%   65.33%   -1.61%     
===========================================
  Files         1145     1145              
  Lines        93630    93647      +17     
===========================================
- Hits         62677    61187    -1490     
- Misses       30953    32460    +1507
Flag Coverage Δ
#cproversmt2 ?
#regression 63.44% <50%> (-0.02%) ⬇️
#unit 31.69% <72.22%> (+0.19%) ⬆️
Impacted Files Coverage Δ
jbmc/src/java_bytecode/assignments_from_json.cpp 98.27% <97.22%> (+0.82%) ⬆️
src/solvers/smt2/smt2_dec.h 0% <0%> (-100%) ⬇️
src/solvers/smt2/letify.cpp 0% <0%> (-100%) ⬇️
src/solvers/floatbv/float_bv.h 0% <0%> (-100%) ⬇️
src/solvers/smt2/smt2irep.cpp 0% <0%> (-88%) ⬇️
src/solvers/floatbv/float_bv.cpp 0% <0%> (-74.37%) ⬇️
src/solvers/smt2/smt2_dec.cpp 0% <0%> (-67.7%) ⬇️
src/solvers/smt2/letify.h 33.33% <0%> (-66.67%) ⬇️
src/solvers/smt2/smt2_conv.h 36.36% <0%> (-63.64%) ⬇️
src/solvers/smt2/smt2_conv.cpp 19.78% <0%> (-37.56%) ⬇️
... and 23 more

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 2082719...5829c8a. Read the comment docs.

@romainbrenguier romainbrenguier force-pushed the refactor/assign-from-json branch 2 times, most recently from 6422e28 to d10671e Compare September 16, 2019 07:20
@romainbrenguier romainbrenguier marked this pull request as ready for review September 16, 2019 07:22
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: d10671e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/127759742

@romainbrenguier romainbrenguier changed the title [TG-9450] Allocate array with right length when if "@nondetLength" not used in Json [TG-9450] Allocate array with right length when "@nondetLength" not used in Json Sep 17, 2019
@antlechner antlechner self-assigned this Sep 17, 2019
Copy link
Contributor

@antlechner antlechner left a comment

Choose a reason for hiding this comment

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

Reviewed everything except unit test commit. Looks good, only some small blocking comments.

@romainbrenguier romainbrenguier force-pushed the refactor/assign-from-json branch 3 times, most recently from b01ea24 to b420f26 Compare September 18, 2019 15:54
@romainbrenguier
Copy link
Contributor Author

@antlechner comments addressed, ready for re-review

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: e0aeb22).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128210163
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: b01ea24).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128210873
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.

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

@@ -457,18 +457,16 @@ static symbol_exprt nondet_length(
}

/// One of the cases in the recursive algorithm: the case where \p expr
/// represents an array.
/// represents an array which is not flagged with @nondetLength.
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Does the @ compile correctly with Doxygen?
💡 Could mention here in/after the "Allocate array with right size when possible" commit that we only need this function for arrays that are reference-equal to some other array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

 Does the @ compile correctly with Doxygen?

No @nondetLength didn't appear, I've added back quotes "`" and now it works.

💡 Could mention here in/after the "Allocate array with right size when possible" commit that we only need this function for arrays that are reference-equal to some other array.

Actually this function is also used in the non-reference case.

/// We add constraints on the length: if "nondetLength" is specified in \p json,
/// then the number of elements specified in \p json should be less than or
/// equal to the length of the array. Otherwise the number of elements should be
/// We add an assume statement constraining the number of elements to be
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Might be clearer to write it the other way round (we constrain the length of the array, the number of elements is known and constant).

java_class_typet type;
// TODO java_class_typet constructors should ensure there is always a
// @class_identifier field, and that name is always set
type.set_name("java::" + class_name);
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ type.set_name(test_class_symbol.name)

entry["field_name"] = [] {
json_objectt int_json;
int_json["value"] = json_numbert{"42"};
int_json["@type"] = json_stringt{"int"};
Copy link
Contributor

@antlechner antlechner Sep 19, 2019

Choose a reason for hiding this comment

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

⛏️ Note that json-io, the library that the inputs to assign_from_json are based on, never uses primitives so would use java.lang.Integer instead of int here, even if the field is of type int.

field_symbol.is_static_lifetime = true;
return field_symbol;
}());
add_clinit(symbol_table, "TestClass");
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ Could save the return value to a variable here and use it as an argument to assign_from_json below.

.get()
.get_identifier() == "symbol_to_assign");
}
THEN("The instruction zero-initializes the struct")
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ The code here checks for "initializes the struct" but doesn't check for "zero".

.get()
.type() == java_reference_type(java_int_type()));
}
THEN("The instruction allocates the struct")
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Which struct? All this is checking for is an assignment to allocation_symbol.

{
REQUIRE(
make_query(block)[7].as<code_assumet>()[0].get().type() ==
bool_typet{});
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Can we check what the assumptions for this are, rather than just check that they have boolean type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's difficult to do in a robust manner because you can have different assumptions which are logically equivalent...

No functional changes
By keeping the iterator to the found entry.
This makes the assign_array_from_json a bit simpler.
This is an intermediary commit towards removing the optional argument
from assign_array_from_json.
This simplifies the logic in assign_array_from_json and makes its
specification simpler.
This makes it so that we only have one block.add(code_assumet(...))
instruction, it is thus easier to figure out what the assumption is
depending on the parameters.
Depending on whether the array has deterministic length or not.
This will make it easier to allocate the array directly to the right
size in the deterministic case.
When the array is not marked as nondet and is not a reference it can
directly be allocated with the right size, which will allow constant
propagation through arrays.
@romainbrenguier romainbrenguier force-pushed the refactor/assign-from-json branch 2 times, most recently from d42b140 to 14e1424 Compare September 20, 2019 07:04
This in particular check that an array field (which is not marked nondet
and not a reference) is allocated with a constant size.
@romainbrenguier romainbrenguier force-pushed the refactor/assign-from-json branch from 14e1424 to 5829c8a Compare September 20, 2019 07:06
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: 8d09d98).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128467148
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: d42b140).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128467475
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: 14e1424).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128472197
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 merged commit 20164f5 into diffblue:develop Sep 20, 2019
@romainbrenguier romainbrenguier deleted the refactor/assign-from-json branch September 20, 2019 08:19
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: 5829c8a).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128475220

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