Skip to content

Commit c19bb8e

Browse files
RuleApp interface for all external solvers (prep for #3514) (#3521)
2 parents f8622f6 + 3c41ebb commit c19bb8e

File tree

3 files changed

+127
-40
lines changed

3 files changed

+127
-40
lines changed

key.core/src/main/java/de/uka/ilkd/key/proof/Goal.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import de.uka.ilkd.key.rule.*;
2323
import de.uka.ilkd.key.rule.inst.SVInstantiations;
2424
import de.uka.ilkd.key.rule.merge.MergeRule;
25-
import de.uka.ilkd.key.smt.SMTRuleApp;
2625
import de.uka.ilkd.key.strategy.AutomatedRuleApplicationManager;
2726
import de.uka.ilkd.key.strategy.QueueRuleApplicationManager;
2827
import de.uka.ilkd.key.strategy.Strategy;
@@ -627,7 +626,7 @@ public ImmutableList<Goal> apply(final RuleApp ruleApp) {
627626
} else {
628627
proof.replace(this, goalList);
629628
if (ruleApp instanceof TacletApp tacletApp && tacletApp.taclet().closeGoal()
630-
|| ruleApp instanceof SMTRuleApp) {
629+
|| ruleApp instanceof AbstractExternalSolverRuleApp) {
631630
// the first new goal is the one to be closed
632631
proof.closeGoal(goalList.head());
633632
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* This file is part of KeY - https://key-project.org
2+
* KeY is licensed under the GNU General Public License Version 2
3+
* SPDX-License-Identifier: GPL-2.0-only */
4+
package de.uka.ilkd.key.rule;
5+
6+
import de.uka.ilkd.key.logic.*;
7+
import de.uka.ilkd.key.proof.Goal;
8+
9+
import org.key_project.util.collection.ImmutableList;
10+
11+
/**
12+
* The rule application that is used when a goal is closed by means of an external solver. So far it
13+
* stores the rule that that has been used and a title containing some information for the user.
14+
* <p>
15+
* {@link de.uka.ilkd.key.smt.SMTRuleApp}
16+
*/
17+
public abstract class AbstractExternalSolverRuleApp extends AbstractBuiltInRuleApp {
18+
protected final String title;
19+
protected final String successfulSolverName;
20+
21+
/**
22+
* Creates a new AbstractExternalSolverRuleApp,
23+
*
24+
* @param rule the ExternalSolverRule to apply
25+
* @param pio the position in the term to apply the rule to
26+
* @param unsatCore an unsat core consisting of the formulas that are needed to prove the goal
27+
* (optional null)
28+
* @param successfulSolverName the name of the solver used to find the proof
29+
* @param title the title of this rule app
30+
*/
31+
protected AbstractExternalSolverRuleApp(ExternalSolverRule rule, PosInOccurrence pio,
32+
ImmutableList<PosInOccurrence> unsatCore,
33+
String successfulSolverName, String title) {
34+
super(rule, pio, unsatCore);
35+
this.title = title;
36+
this.successfulSolverName = successfulSolverName;
37+
}
38+
39+
/**
40+
* Gets the title of this rule application
41+
*
42+
* @return title of this application
43+
*/
44+
public String getTitle() {
45+
return title;
46+
}
47+
48+
/**
49+
* Gets the name of the successful solver
50+
*
51+
* @return name of the successful solver
52+
*/
53+
public String getSuccessfulSolverName() {
54+
return successfulSolverName;
55+
}
56+
57+
@Override
58+
public String displayName() {
59+
return title;
60+
}
61+
62+
/**
63+
* Interface for the rules of external solvers
64+
*/
65+
public interface ExternalSolverRule extends BuiltInRule {
66+
AbstractExternalSolverRuleApp createApp(String successfulSolverName);
67+
68+
/**
69+
* Create a new rule application with the given solver name and unsat core.
70+
*
71+
* @param successfulSolverName solver that produced this result
72+
* @param unsatCore formulas required to prove the result
73+
* @return rule application instance
74+
*/
75+
AbstractExternalSolverRuleApp createApp(String successfulSolverName,
76+
ImmutableList<PosInOccurrence> unsatCore);
77+
78+
@Override
79+
AbstractExternalSolverRuleApp createApp(PosInOccurrence pos, TermServices services);
80+
81+
82+
@Override
83+
default boolean isApplicable(Goal goal, PosInOccurrence pio) {
84+
return false;
85+
}
86+
87+
@Override
88+
default boolean isApplicableOnSubTerms() {
89+
return false;
90+
}
91+
92+
@Override
93+
String displayName();
94+
95+
@Override
96+
String toString();
97+
}
98+
99+
/**
100+
* Sets the title (needs to create a new instance for this)
101+
*
102+
* @param title new title for rule app
103+
* @return copy of this with the new title
104+
*/
105+
public abstract AbstractExternalSolverRuleApp setTitle(String title);
106+
107+
@Override
108+
public AbstractExternalSolverRuleApp setIfInsts(ImmutableList<PosInOccurrence> ifInsts) {
109+
setMutable(ifInsts);
110+
return this;
111+
}
112+
}

key.core/src/main/java/de/uka/ilkd/key/smt/SMTRuleApp.java

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@
99
import de.uka.ilkd.key.java.Services;
1010
import de.uka.ilkd.key.logic.*;
1111
import de.uka.ilkd.key.proof.Goal;
12-
import de.uka.ilkd.key.rule.AbstractBuiltInRuleApp;
12+
import de.uka.ilkd.key.rule.AbstractExternalSolverRuleApp;
1313
import de.uka.ilkd.key.rule.BuiltInRule;
1414
import de.uka.ilkd.key.rule.RuleApp;
1515

1616
import org.key_project.logic.Name;
1717
import org.key_project.util.collection.ImmutableList;
1818

19+
import org.jspecify.annotations.NonNull;
20+
1921
/**
20-
* The rule application that is used when a goal is closed by means of an external solver. So far it
22+
* The rule application that is used when a goal is closed by means of an SMT solver. So far it
2123
* stores the rule that that has been used and a title containing some information for the user.
2224
*/
23-
public class SMTRuleApp extends AbstractBuiltInRuleApp {
24-
25+
public class SMTRuleApp extends AbstractExternalSolverRuleApp {
2526
public static final SMTRule RULE = new SMTRule();
26-
private final String title;
27-
private final String successfulSolverName;
2827

2928
/**
3029
* Create a new rule app without ifInsts (will be null).
@@ -37,39 +36,26 @@ public class SMTRuleApp extends AbstractBuiltInRuleApp {
3736
this(rule, pio, null, successfulSolverName);
3837
}
3938

40-
SMTRuleApp(SMTRule rule, PosInOccurrence pio, ImmutableList<PosInOccurrence> unsatCore,
39+
SMTRuleApp(ExternalSolverRule rule, PosInOccurrence pio,
40+
ImmutableList<PosInOccurrence> unsatCore,
4141
String successfulSolverName) {
42-
super(rule, pio, unsatCore);
43-
this.title = "SMT: " + successfulSolverName;
44-
this.successfulSolverName = successfulSolverName;
42+
super(rule, pio, unsatCore, successfulSolverName, "SMT: " + successfulSolverName);
4543
}
4644

4745
@Override
4846
public SMTRuleApp replacePos(PosInOccurrence newPos) {
4947
return new SMTRuleApp(RULE, newPos, ifInsts, successfulSolverName);
5048
}
5149

52-
public String getTitle() {
53-
return title;
54-
}
55-
56-
public String getSuccessfulSolverName() {
57-
return successfulSolverName;
58-
}
59-
6050
@Override
6151
public BuiltInRule rule() {
6252
return RULE;
6353
}
6454

65-
@Override
66-
public String displayName() {
67-
return title;
68-
}
69-
70-
public static class SMTRule implements BuiltInRule {
55+
public static class SMTRule implements ExternalSolverRule {
7156
public static final Name name = new Name("SMTRule");
7257

58+
@Override
7359
public SMTRuleApp createApp(String successfulSolverName) {
7460
return new SMTRuleApp(this, null, successfulSolverName);
7561
}
@@ -81,6 +67,7 @@ public SMTRuleApp createApp(String successfulSolverName) {
8167
* @param unsatCore formulas required to prove the result
8268
* @return rule application instance
8369
*/
70+
@Override
8471
public SMTRuleApp createApp(String successfulSolverName,
8572
ImmutableList<PosInOccurrence> unsatCore) {
8673
return new SMTRuleApp(this, null, unsatCore, successfulSolverName);
@@ -91,13 +78,6 @@ public SMTRuleApp createApp(PosInOccurrence pos, TermServices services) {
9178
return new SMTRuleApp(this, null, "");
9279
}
9380

94-
95-
@Override
96-
public boolean isApplicable(Goal goal, PosInOccurrence pio) {
97-
return false;
98-
}
99-
100-
10181
/**
10282
* Create a new goal (to be closed in {@link Goal#apply(RuleApp)} directly afterwards)
10383
* with the same sequent as the given one.
@@ -108,23 +88,20 @@ public boolean isApplicable(Goal goal, PosInOccurrence pio) {
10888
* @return a list with an identical goal as the given <tt>goal</tt>
10989
*/
11090
@Override
91+
@NonNull
11192
public ImmutableList<Goal> apply(Goal goal, Services services, RuleApp ruleApp) {
11293
if (goal.proof().getInitConfig().getJustifInfo().getJustification(RULE) == null) {
11394
goal.proof().getInitConfig().registerRule(RULE, () -> false);
11495
}
11596
return goal.split(1);
11697
}
11798

118-
@Override
119-
public boolean isApplicableOnSubTerms() {
120-
return false;
121-
}
122-
12399
@Override
124100
public String displayName() {
125101
return "SMT";
126102
}
127103

104+
@Override
128105
public String toString() {
129106
return displayName();
130107
}
@@ -133,9 +110,9 @@ public String toString() {
133110
public Name name() {
134111
return name;
135112
}
136-
137113
}
138114

115+
@Override
139116
public SMTRuleApp setTitle(String title) {
140117
return new SMTRuleApp(RULE, pio, ifInsts, title);
141118
}
@@ -168,5 +145,4 @@ public SMTRuleApp tryToInstantiate(Goal goal) {
168145
}
169146
return app.setIfInsts(ImmutableList.fromList(ifInsts));
170147
}
171-
172148
}

0 commit comments

Comments
 (0)