Skip to content

Loop-less initialization of primitive arrays #3649

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 5 commits into from
Jan 2, 2019

Conversation

allredj
Copy link
Contributor

@allredj allredj commented Dec 31, 2018

Nondeterministic primitive arrays are now initialized using a single NONDET instruction, instead of being initialized element-wise in a loop over the length of the array.

This removes the coupling between the length of nondeterministic primitive arrays and the maximum unwind value.

Advantages when dealing with arrays of primitive type:

  • --max-nondet-array-length can now be set to a value larger than --unwind
  • jbmc can now deal with large primitive arrays while keeping --unwind low

For multi-dimensional arrays, only the innermost dimension benefits from loop-less initialization. Higher dimensions are still initialized via a loop, and so are bound by --unwind.

  • 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).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@allredj allredj self-assigned this Dec 31, 2018
@allredj allredj changed the title Loop-less primitive array initialization Loop-less initialization of primitive arrays Dec 31, 2018
Will also be used in java_object_factory
@allredj allredj force-pushed the loop-less-array-init branch from e30da83 to 997d692 Compare December 31, 2018 11:39
Copy link
Contributor Author

@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: 997d692).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/95984671

Copy link
Contributor Author

@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: 65af890).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/95985244

/// loop.
/// The code produced is of the form (supposing an array of type OBJ):
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// struct java.lang.Integer **array_data_init;
Copy link
Member

Choose a reason for hiding this comment

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

🚫 OBJ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -0,0 +1,16 @@
class NondetArrayPrimitive
{
void intArray(int[] array)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a test for non-primitive arrays too?

Copy link
Member

Choose a reason for hiding this comment

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

And byte, char, short, long, double...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests for all primitive types.
Not for non-primitive types as this PR doesn't change behaviour for those.

Copy link
Member

@peterschrammel peterschrammel Jan 2, 2019

Choose a reason for hiding this comment

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

this PR doesn't change behaviour for those.

Is there a test that checks that?

/// Create code to nondeterministically initialize arrays of primitive type.
/// The code produced is of the form:
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// int (*array_data_init)[max_length_expr];
Copy link
Member

Choose a reason for hiding this comment

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

Why int? Shouldn't it be the primitive type? Or otherwise say 'example'.

Copy link
Contributor Author

@allredj allredj Dec 31, 2018

Choose a reason for hiding this comment

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

fixed

{
array_typet array_type(element_type, max_length_expr);

// int (*array_data_init)[max_length_expr];
Copy link
Member

Choose a reason for hiding this comment

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

Why int? What about byte, long, ...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Joel Allred added 4 commits December 31, 2018 15:44
Makes gen_nondet_array_init smaller and clarifies process.
Get rid of the initilization loop for nondet arrays, so the size of
nondeterministic arrays of primitive types no longer depend on the
max unwind value.
Array variable name is now of type "dynamic_object" for primitive arrays.
"dynamic_N_array" is a name generated by symex_cpp_new when
loop-initializing arrays (in remove_java_newt::lower_java_new_array).
We no longer loop-initialize primitive arrays.
@allredj allredj force-pushed the loop-less-array-init branch from 65af890 to 2d24bbd Compare December 31, 2018 16:04
Copy link
Contributor Author

@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: 2d24bbd).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/95995687

@kroening kroening merged commit 8e145fa into diffblue:develop Jan 2, 2019
@allredj allredj deleted the loop-less-array-init branch January 2, 2019 18:45
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