-
Notifications
You must be signed in to change notification settings - Fork 273
[TG-2721] Use sparse arrays in string_refinementt::get #2009
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
romainbrenguier
merged 25 commits into
diffblue:develop
from
romainbrenguier:solvers/sparse-arrays-in-get
Apr 10, 2018
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a914153
Use map instead of vector for sparse array entries
romainbrenguier d483c81
Initialize sparse array from array_exprt
romainbrenguier ede2fa1
Clear string_dependencies in calls to dec_solve
romainbrenguier 5b4d618
Reduce number of constraints in format
romainbrenguier 5f07bf0
Initialization of sparse array from array-list
romainbrenguier 848dd95
Add an interval_sparse_array::of_expr function
romainbrenguier 0d03591
Add an `at` function for access in sparse arrays
romainbrenguier c52c813
Add a sum_overflows function
romainbrenguier c40b836
Truncate string concatenations in case of overflow
romainbrenguier 4779b25
Get rid of calls to plus_exprt_with_overflow
romainbrenguier ce4c008
Remove plus_exprt_with_overflow_check
romainbrenguier cb10550
Use sparse arrays in substitute_array_access
romainbrenguier dfc584a
Add concretize function for interval_sparse_array
romainbrenguier 037f631
Refactor string_refinementt::get
romainbrenguier 9b286d9
Use sparse arrays in string_refinement::get
romainbrenguier beff419
Use sparse arrays in get_array
romainbrenguier c58ac60
Avoid copy in ranged for loops over expressions
romainbrenguier 8ed138b
Remove unused header
romainbrenguier 052d503
Use get_array in get_char_array_and_concretize
romainbrenguier 6d87233
Use concretize instead of fill_in_array
romainbrenguier a6c4010
Stop using concretize_arrays_in_expression
romainbrenguier 1a08772
Tests where model involves long strings
romainbrenguier 8277e92
Stop using concretize_array_expr in unit tests
romainbrenguier 5392645
Reserve size of array in concretize
romainbrenguier 64b336a
Refactor interval_sparse_array::concretize
romainbrenguier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import org.cprover.CProverString; | ||
|
||
public class Test { | ||
public static void check(String s, String t) { | ||
// Filter | ||
if(s == null || t == null) | ||
return; | ||
|
||
// Act | ||
String u = s.concat(t); | ||
|
||
// Filter out | ||
if(u.length() < 3_000_000) | ||
return; | ||
if(CProverString.charAt(u, 500_000) != 'a') | ||
return; | ||
if(CProverString.charAt(u, 2_000_000) != 'b') | ||
return; | ||
|
||
// Assert | ||
assert(false); | ||
} | ||
|
||
public static void checkAbort(String s, String t) { | ||
// Filter | ||
if(s == null || t == null) | ||
return; | ||
|
||
// Act | ||
String u = s.concat(t); | ||
|
||
// Filter out | ||
if(u.length() < 67_108_864) | ||
return; | ||
if(CProverString.charAt(u, 2_000_000) != 'b') | ||
return; | ||
|
||
// Assert | ||
assert(false); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CORE | ||
Test.class | ||
--refine-strings --function Test.check --string-max-input-length 2000000 | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
assertion at file Test.java line 21 .* FAILURE | ||
-- | ||
-- | ||
This checks that the solver manage to violate assertions even when this requires | ||
some very long strings, as long as they don't exceed the arbitrary limit that | ||
is set by the solver (64M characters). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
Test.class | ||
--refine-strings --function Test.checkAbort | ||
^EXIT=6$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
This tests should abort, because concretizing a string of the required | ||
length may take to much memory. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,15 @@ Author: Romain Brenguier, [email protected] | |
/// at index `end_index'`. | ||
/// Where start_index' is max(0, start_index) and end_index' is | ||
/// max(min(end_index, s2.length), start_index') | ||
/// If s1.length + end_index' - start_index' is greater than the maximal integer | ||
/// of the type of res.length, then the result gets truncated to the size | ||
/// of this maximal integer. | ||
/// | ||
/// These axioms are: | ||
/// 1. \f$|res| = |s_1| + end\_index' - start\_index' \f$ | ||
/// 1. \f$|res| = overflow ? |s_1| + end\_index' - start\_index' | ||
/// : max_int \f$ | ||
/// 2. \f$\forall i<|s_1|. res[i]=s_1[i] \f$ | ||
/// 3. \f$\forall i< end\_index' - start\_index'.\ res[i+|s_1|] | ||
/// = s_2[start\_index'+i]\f$ | ||
/// 3. \f$\forall i< |res| - |s_1|.\ res[i+|s_1|] = s_2[start\_index'+i]\f$ | ||
/// | ||
/// \param res: an array of characters expression | ||
/// \param s1: an array of characters expression | ||
|
@@ -59,7 +62,8 @@ exprt string_constraint_generatort::add_axioms_for_concat_substr( | |
fresh_univ_index("QA_index_concat2", res.length().type()); | ||
const equal_exprt res_eq( | ||
res[plus_exprt(idx2, s1.length())], s2[plus_exprt(start1, idx2)]); | ||
return string_constraintt(idx2, minus_exprt(end1, start1), res_eq); | ||
const minus_exprt upper_bound(res.length(), s1.length()); | ||
return string_constraintt(idx2, upper_bound, res_eq); | ||
}()); | ||
|
||
return from_integer(0, get_return_code_type()); | ||
|
@@ -77,10 +81,13 @@ exprt length_constraint_for_concat_substr( | |
const exprt &start, | ||
const exprt &end) | ||
{ | ||
PRECONDITION(res.length().type().id() == ID_signedbv); | ||
const exprt start1 = maximum(start, from_integer(0, start.type())); | ||
const exprt end1 = maximum(minimum(end, s2.length()), start1); | ||
const plus_exprt res_length(s1.length(), minus_exprt(end1, start1)); | ||
return equal_exprt(res.length(), res_length); | ||
const exprt overflow = sum_overflows(res_length); | ||
const exprt max_int = to_signedbv_type(res.length().type()).largest_expr(); | ||
return equal_exprt(res.length(), if_exprt(overflow, max_int, res_length)); | ||
} | ||
|
||
/// Add axioms enforcing that the length of `res` is that of the concatenation | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How long do these tests take?
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.
On my computer 0.7s for the first one and 0.1s for the second.