Skip to content

CVC5: Add parser support #474

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

CVC5: Add parser support #474

wants to merge 9 commits into from

Conversation

daniel-raffler
Copy link
Contributor

Hello,
this PR will add support for parsing to CVC5. The approach taken is very similar to what we're doing in the Bitwuzla code as we again have to carefully synchronize symbol definitions from the parser with those from our variable/uf cache. Note that we also included some changes to the way that CVC5 array values from the model are translate into ValueAssignments for JavaSMT. This was needed to fix tests that became possible with the new parser support.

@Override
public Term makeVariable(Sort sort, String name) {
Term existingVar = variablesCache.get(name, sort.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as i remember i chose the string representation as it was possible to get equal sorts that were not equal, thus it was not possible to find already existing variables. Have you checked for this?

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 can look into that, but so far I've not had any issues with it. Do you still remember if it used to fail for any specific sorts?

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 went thought the git log and it seems like we switched to using the String representation here. I wasn't able to reproduce the problem with Bitvector sorts even when using the old version of the commit.

Could it be that this was linked to the parallel issues that CVC5 has? Sorts are "per thread" in CVC5 and this may have caused issues with finding existing variables in the cache.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be that this was linked to the parallel issues that CVC5 has? Sorts are "per thread" in CVC5 and this may have caused issues with finding existing variables in the cache.

No i am pretty sure that that was not the case.

This is actually a funny problem; using the String should be fine in theory, but so should be using the term itself. In the former, we might have a clash of 2 sorts whose terms are not equal, but their string representation. In the later we might have the reverse. I would prefer to trust the sort terms, as they are what the solver itself uses.

@@ -426,21 +424,14 @@ public <R> R visit(FormulaVisitor<R> visitor, Formula formula, final Term f) {
getFormulaType(f),
f.getKind()));

} else if (f.getKind() == Kind.VARIABLE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What changed that there are no more bound variables? We still support quantifiers, so there should be bound variables.
Is the kind deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bound variables are substituted when the quantifier is matched here. I think this makes this code unreachable as there should be no way to create a bound variable by itself? Then again it probably wouldn't hurt to leave the code in.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. We should be careful to take another look if #491 is merged before this PR!

@baierd
Copy link
Contributor

baierd commented Jul 21, 2025

@daniel-raffler whats the current state of this PR?

# Conflicts:
#	src/org/sosy_lab/java_smt/solvers/cvc5/CVC5FormulaCreator.java
@daniel-raffler
Copy link
Contributor Author

@daniel-raffler whats the current state of this PR?

I think we need to decide whether we want such a workaround for CVC5 or not. We're already doing something similar in Bitwuzla to support parsing, and it seems to be working well so far. Then again it does introduce 100+ lines of extra code that are rather complex and may be hard to maintain.

Other than that this PR should be complete and I did test it with CPAchecker to fix any remaining issues

@baierd
Copy link
Contributor

baierd commented Jul 21, 2025

At some point we can simply use the independent SMTLib2 parser.

Up until then its a hard choice, as CVC5 can not be fully used in some applications, but also it would add more maintenance effort.

Since this has been untouched for a while, could you merge main to it and run it again with CPAchecker such that we use the parser? (e.g. CVC5 als main solver with another as interpolation solver)

@daniel-raffler
Copy link
Contributor Author

Since this has been untouched for a while, could you merge main to it and run it again with CPAchecker such that we use the parser? (e.g. CVC5 als main solver with another as interpolation solver)

I ran the svcomp test set today. Since the cluster is still busy I could only do SV-COMP25_unreach-call. Here are the results for the current version:
Screenshot From 2025-07-23 22-07-14
The turquoise line is for CVC5, light brown is CVC5 with MathSAT for the interpolants, dark brown is MathSAT with CVC5 for the interpolants, and orange is just MathSAT

And here are the results for this branch:
Screenshot From 2025-07-23 22-07-04
Colors are the same as before. Most of the gains are from the changes in CVC5Model that fix array values. There are 95 segmentation faults left when MathSat is used with CVC5 as interpolator, but I'm not sure which of the two is causing the issue

Overall I think this helps quite a bit to improve the performance of CVC5 and we can still fix any remaining bugs later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants