Skip to content

Override default methods in BasicProverEnvironment for all delegates#685

Open
daniel-raffler wants to merge 16 commits into
masterfrom
672-methods-with-default-implementations-missing-from-delegates
Open

Override default methods in BasicProverEnvironment for all delegates#685
daniel-raffler wants to merge 16 commits into
masterfrom
672-methods-with-default-implementations-missing-from-delegates

Conversation

@daniel-raffler

Copy link
Copy Markdown
Contributor

Hello,

this PR adds overrides for all default methods in BasicProverEnvironment for all of our delegates. This makes sure that the solver implementation is used when available, and that we don't fall back to the default implementation when using a delegate

@baierd baierd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good besides the open points! Nice work!

Please open multiple smaller PRs next time instead of one giant one ;D

Did you test whether we handle push(BooleanFormula) correctly in all cases? (I saw that you added it to the trace test. Good!) The used delegate calls addConstraint(BooleanFormula) due to the default implementation, but is that addConstraint() call then tracked by the delegate layers?
Do we even need to add push(BooleanFormula) to the delegates? The default impl. uses two methods that are already part of the layers, and it is never overridden.

We should test most of our additional layers (logging/debugging etc.) from time to time! Would you be so kind and open issues (per delegate) to do this? Running CPAchecker with distinct analyses for each should be fine for now to get a sense of whether they work or collect problems.

@Override
public @Nullable T push(BooleanFormula f) throws InterruptedException {
stats.push.getAndIncrement();
stats.pop.getAndIncrement();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this line should not be here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! I've replaced it with

@Override
  public @Nullable T push(BooleanFormula f) throws InterruptedException {
    stats.push.getAndIncrement();
    stats.constraint.getAndIncrement();
    return delegate.push(f);
  }

which is what the default method would have produced

Should I get rid of the stats.constraint.getAndIncrement() entirely?


@Override
public ImmutableMap<String, String> getStatistics() {
return ImmutableMap.of();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing delegate call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm.. I wasn't quite sure what to put there. In StatisticsSolverContext the getStatistics method includes the data that we're collecting. However, this won't work for StatisticsBasicProverEnvironment as we're not tracking statistics for each prover individually

I've now simply added a call to the delegate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can always just return the solvers statistics if it provides some.

But i agree that this is actually a interesting question. I'll take a closer look.

Comment thread src/org/sosy_lab/java_smt/delegate/synchronize/SynchronizedEvaluator.java Outdated

@Override
public <T extends Formula> @Nullable T eval(T pFormula) {
throw new UnsupportedOperationException(UNSUPPORTED_OPERATION);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why can't we synchronize evaluators with contexts?

I know that the old code also did not allow this, but why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it's just because FormulaManager.translate expects a boolean formula. We could allow eval for boolean formulas, but throwing an UnsupportedOperationException only for some inputs may be a bit confusing to the user

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the current message is confusing, as it actually says that only boolean formulas are allowed.

Would you be so kind and test boolean formulas only + add a small test for this? Essentially just try to eval a boolean and a non-boolean formula.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've implemented it for booleans now, see here

Comment thread src/org/sosy_lab/java_smt/delegate/synchronize/SynchronizedModelWithContext.java Outdated
logger.logDefDiscard(
logger.toVariable(this), "getModelAssignments()", delegate::getModelAssignments);
return FluentIterable.from(result)
// TODO Fix this in the Z3 model

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would you be so kind and open a issue for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the issue has already been fixed by 48b66d4 and 3e665e5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good point.
If that's the case, we should remove the TODO. Could you double check with the commit that added the TODO whether we can be sure that it is related to the 2 fixes and remove the TODO if they are?

@daniel-raffler

daniel-raffler commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Looks good besides the open points! Nice work!

Thanks!

Please open multiple smaller PRs next time instead of one giant one ;D

Sure, I'll try to keep the PRs smaller 😅. Most of the large changes are just copy and paste, but I can see how it's hard to review

Did you test whether we handle push(BooleanFormula) correctly in all cases? (I saw that you added it to the trace test. Good!) The used delegate calls addConstraint(BooleanFormula) due to the default implementation, but is that addConstraint() call then tracked by the delegate layers?

The tracing delegate will just write prover.push(f) to the log. The formula for f has already been unrolled and is just a variable name. When translating to SMTLIB the call then needs to be split up and we generate (push 1) (assert f)

There is an example of how the trace changed in one of the tests. Before adding the override we had:

var var1 = mgr.getBooleanFormulaManager().makeTrue();
var0.push();
var var2 = var0.addConstraint(var1);

Now it's just:

var var1 = mgr.getBooleanFormulaManager().makeTrue();
var var2 = var0.push(var1);

We should test most of our additional layers (logging/debugging etc.) from time to time! Would you be so kind and open issues (per delegate) to do this? Running CPAchecker with distinct analyses for each should be fine for now to get a sense of whether they work or collect problems.

I've open some issues here

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

Development

Successfully merging this pull request may close these issues.

Methods with default implementations missing from delegates

2 participants