Skip to content

Fix quantifiers for arrays only works with Z3 and CVC4 #6270

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

Closed
wants to merge 3 commits into from

Conversation

TGWDB
Copy link
Contributor

@TGWDB TGWDB commented Aug 4, 2021

This commit fixes an error introduced in #5974 where quantifiers
were produced for all SMT2 solvers despite only being supported by
Z3 and CVC4. The fix here reverts to the older behaviour for other
solvers.

Fixes #6263

  • 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.

@kroening
Copy link
Member

kroening commented Aug 4, 2021

MathSAT does not support forall either.

@TGWDB
Copy link
Contributor Author

TGWDB commented Aug 4, 2021

MathSAT does not support forall either.

Now we only produce the forall in the array code block for Z3 and CVC4, all other solvers will have the old code.

// The code below only works in Z3 and CVC4, it was added (and
// approved/merged) despite breaking other solvers.
// This conditional removes this for other solvers
if(solver == solvert::CVC4 || solver == solvert::Z3)
Copy link
Contributor

@SaswatPadhi SaswatPadhi Aug 4, 2021

Choose a reason for hiding this comment

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

Thanks for fixing this. In my original commit, I didn't realize that we also support solvers that do not have quantifier support.

Instead of checking for specific solvers, should we introduce use_quantified_array_init? This can be set to true for Z3 and CVC4in the case split we have in the constructor, and we wouldn't need the solver-specific checks or the comments above and below. We use the same pattern for other solver-specific features, e.g. array of Bools support, as const support etc.

Actually, may be we should have a use_quantifier flag instead to track solvers that support quantifiers. The issue here is with the use of quantifiers, not really specific to array initialization. May be we should also go over other uses of quantifiers in this file and guard them with use_quantifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree that a flag for quantifiers is probably the better approach, the PR above is a bit limited and incomplete (also we should have a flag and not solver specific code in random places).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've gone with a very lightweight (minimum) fix and rebase for now. Is this still blocking?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! No this isn't a blocker currently.

This commit fixes an error introduced in diffblue#5974 where quantifiers
were produced for all SMT2 solvers despite only being supported by
Z3 and CVC4. The fix here reverts to the older behaviour for other
solvers.

Fixes diffblue#6263
@TGWDB TGWDB force-pushed the array_quantifier_safety_z3_cvc4 branch from 4a1fab6 to 650d458 Compare May 12, 2022 14:51
@TGWDB TGWDB marked this pull request as draft May 12, 2022 14:52
@TGWDB TGWDB marked this pull request as ready for review May 18, 2022 15:03
@codecov
Copy link

codecov bot commented May 18, 2022

Codecov Report

Merging #6270 (52829ee) into develop (6baffa3) will decrease coverage by 0.02%.
The diff coverage is 18.75%.

@@             Coverage Diff             @@
##           develop    #6270      +/-   ##
===========================================
- Coverage    77.79%   77.76%   -0.03%     
===========================================
  Files         1567     1567              
  Lines       179707   179780      +73     
===========================================
+ Hits        139797   139807      +10     
- Misses       39910    39973      +63     
Impacted Files Coverage Δ
src/solvers/smt2/smt2_conv.cpp 65.92% <18.75%> (-1.57%) ⬇️
src/util/find_symbols.cpp 65.71% <0.00%> (-18.45%) ⬇️
src/ansi-c/cprover_library.cpp 87.50% <0.00%> (-10.12%) ⬇️
src/goto-checker/solver_factory.cpp 69.31% <0.00%> (-7.25%) ⬇️
src/goto-instrument/accelerate/scratch_program.cpp 50.51% <0.00%> (-1.00%) ⬇️
src/pointer-analysis/goto_program_dereference.cpp 56.80% <0.00%> (-0.69%) ⬇️
src/analyses/goto_rw.h 74.50% <0.00%> (-0.50%) ⬇️
src/util/std_expr.h 92.94% <0.00%> (-0.43%) ⬇️
src/cpp/cpp_convert_type.cpp 73.41% <0.00%> (-0.16%) ⬇️
... and 53 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 5c974cc...52829ee. Read the comment docs.

Comment on lines 4745 to 4749
// else
// {
// // This is where an alternate for other solvers that does not use
// // quantifiers should go.
// }
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not silently do this. It's ok to fail an invariant, but let's please not generate incomplete formulae without telling the user.

@tautschnig
Copy link
Collaborator

@TGWDB Thank you for adding the invariant. This is now, not unexpectedly, failing in some tests. I'd suggest to reinstate the regex pattern in the test, and mark the test as known-broken.

@tautschnig tautschnig removed their assignment May 23, 2022
TGWDB added 2 commits May 23, 2022 14:00
This adds an invariant failure when correct SMT output would not
be produced.
This marks two tests as KNOWNBUG due to them failing here.
@TGWDB TGWDB force-pushed the array_quantifier_safety_z3_cvc4 branch from b342ddc to 52829ee Compare May 23, 2022 13:12
Copy link
Member

@kroening kroening left a comment

Choose a reason for hiding this comment

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

This needs more work -- the array_of expression is an array constructor for an array that maps all indices to one value. Various solvers do support SMT2-LIB array constructor expressions, which should be used here.

@kroening
Copy link
Member

Perhaps a bit more controversial, we could consider dropping support for solvers that support neither as const nor the alternative that uses quantifiers. You won't get anything through CBMC without at least one of these.

@TGWDB
Copy link
Contributor Author

TGWDB commented Jun 6, 2022

@kroening I agree that this PR does not correctly solve all the issues with various solvers. This was intended to be a sport fix for an issue introduced in a prior PR that allowed us to crash some solvers. Instead now this produces an error from CBMC (where we should be building something better). With that in mind, would you be willing to accept this spot fix since in practice this is a fix to the output/failure behaviour? (Also in the context where a new SMT backend is being developer, which may deprecate this code path or enable a better solution in future.)

@TGWDB TGWDB closed this Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MathSAT SMT2 not working
8 participants