Skip to content

Commit 36f73cd

Browse files
authored
Modularity for Proof Strategies (#3650)
2 parents de6e44b + 6525913 commit 36f73cd

92 files changed

Lines changed: 3770 additions & 2149 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ key/key.ui/examples/**/**.proof
6767

6868
# generated by the antlr plugin of IntelliJ
6969
key.core/src/main/antlr4/gen/
70+
*.tokens
7071

7172
scripts/tools/checkstyle/key_checks_incremental.xml
7273
checkstyle-diff.txt

key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/macros/PrepareInfFlowContractPreBranchesMacro.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,9 @@ private String getAppRuleName(Node parent) {
138138
return parentRuleName;
139139
}
140140

141-
142-
@Override
143-
protected RuleAppCost instantiateApp(RuleApp app, PosInOccurrence pio, Goal goal,
144-
MutableState mState) {
145-
return computeCost(app, pio, goal, mState);
146-
}
147-
148141
@Override
149142
public boolean isStopAtFirstNonCloseableGoal() {
150143
return false;
151144
}
152145
}
153-
154146
}

key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/macros/SelfcompositionStateExpansionMacro.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
import de.uka.ilkd.key.proof.Goal;
1313
import de.uka.ilkd.key.proof.Proof;
1414
import de.uka.ilkd.key.proof.init.ProofOblInput;
15-
import de.uka.ilkd.key.strategy.JavaCardDLStrategyFactory;
16-
import de.uka.ilkd.key.strategy.RuleAppCostCollector;
17-
import de.uka.ilkd.key.strategy.Strategy;
18-
import de.uka.ilkd.key.strategy.StrategyProperties;
15+
import de.uka.ilkd.key.strategy.*;
1916

2017
import org.key_project.logic.Name;
2118
import org.key_project.prover.proof.ProofGoal;
@@ -136,10 +133,10 @@ public Name name() {
136133
String name = ruleApp.rule().name().toString();
137134
if ((admittedRuleNames.contains(name) || name.startsWith(INF_FLOW_UNFOLD_PREFIX))
138135
&& ruleApplicationInContextAllowed(ruleApp, pio, goal)) {
139-
JavaCardDLStrategyFactory strategyFactory = new JavaCardDLStrategyFactory();
140-
Strategy<@NonNull Goal> javaDlStrategy =
136+
ModularJavaDLStrategyFactory strategyFactory = new ModularJavaDLStrategyFactory();
137+
Strategy<@NonNull Goal> dlStrategy =
141138
strategyFactory.create(goal.proof(), new StrategyProperties());
142-
RuleAppCost costs = javaDlStrategy.computeCost(ruleApp, pio, goal, mState);
139+
RuleAppCost costs = dlStrategy.computeCost(ruleApp, pio, goal, mState);
143140
if ("orLeft".equals(name)) {
144141
costs = costs.add(NumberRuleAppCost.create(100));
145142
}

key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/strategy/SymbolicExecutionStrategy.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.util.ArrayList;
77

8-
import de.uka.ilkd.key.logic.JTerm;
98
import de.uka.ilkd.key.proof.Goal;
109
import de.uka.ilkd.key.proof.Proof;
1110
import de.uka.ilkd.key.strategy.JavaCardDLStrategy;
@@ -85,7 +84,7 @@ private SymbolicExecutionStrategy(Proof proof, StrategyProperties sp) {
8584
.equals(sp.get(StrategyProperties.SYMBOLIC_EXECUTION_ALIAS_CHECK_OPTIONS_KEY))) {
8685
// Make sure that an immediately alias check is performed by doing cuts of objects to
8786
// find out if they can be the same or not
88-
RuleSetDispatchFeature instRsd = getInstantiationDispatcher();
87+
RuleSetDispatchFeature instRsd = getDispatcher(StrategyAspect.Instantiation);
8988
enableInstantiate();
9089
final TermBuffer<Goal> buffer = new TermBuffer<>();
9190
Feature originalCut = instRsd.get(getHeuristic("cut"));
@@ -106,7 +105,7 @@ private SymbolicExecutionStrategy(Proof proof, StrategyProperties sp) {
106105
* {@inheritDoc}
107106
*/
108107
@Override
109-
protected Feature setupApprovalF() {
108+
protected @NonNull Feature setupApprovalF() {
110109
Feature result = super.setupApprovalF();
111110
// Make sure that cuts are only applied if the cut term is not already part of the sequent.
112111
// This check is performed exactly before the rule is applied because the sequent might has
@@ -122,17 +121,17 @@ protected Feature setupApprovalF() {
122121
* {@inheritDoc}
123122
*/
124123
@Override
125-
protected Feature setupGlobalF(Feature dispatcher) {
124+
protected @NonNull Feature setupGlobalF(@NonNull Feature dispatcher) {
126125
Feature globalF = super.setupGlobalF(dispatcher);
127126
// Make sure that modalities without symbolic execution label are executed first because
128127
// they might forbid rule application on modalities with symbolic execution label (see loop
129128
// body branches)
130129
globalF = add(globalF, ifZero(not(new BinaryFeature() {
131130
@Override
132-
protected <Goal extends ProofGoal<@NonNull Goal>> boolean filter(RuleApp app,
133-
PosInOccurrence pos, Goal goal, MutableState mState) {
131+
protected <GOAL extends ProofGoal<@NonNull GOAL>> boolean filter(RuleApp app,
132+
PosInOccurrence pos, GOAL goal, MutableState mState) {
134133
return pos != null
135-
&& SymbolicExecutionUtil.hasSymbolicExecutionLabel((JTerm) pos.subTerm());
134+
&& SymbolicExecutionUtil.hasSymbolicExecutionLabel(pos.subTerm());
136135
}
137136
}), longConst(-3000)));
138137
// Make sure that the modality which executes a loop body is preferred against the
@@ -141,9 +140,9 @@ protected Feature setupGlobalF(Feature dispatcher) {
141140
add(globalF,
142141
ifZero(add(new Feature() {
143142
@Override
144-
public <Goal extends ProofGoal<@NonNull Goal>> RuleAppCost computeCost(
143+
public <GOAL extends ProofGoal<@NonNull GOAL>> RuleAppCost computeCost(
145144
RuleApp app, PosInOccurrence pos,
146-
Goal goal, MutableState mState) {
145+
GOAL goal, MutableState mState) {
147146
return pos != null ? cost(0) : TopRuleAppCost.INSTANCE;
148147
}
149148
},
@@ -302,7 +301,7 @@ public static class Factory implements StrategyFactory {
302301
* {@inheritDoc}
303302
*/
304303
@Override
305-
public StrategySettingsDefinition getSettingsDefinition() {
304+
public @NonNull StrategySettingsDefinition getSettingsDefinition() {
306305
// Properties
307306
OneOfStrategyPropertyDefinition methodTreatment = new OneOfStrategyPropertyDefinition(
308307
StrategyProperties.METHOD_OPTIONS_KEY, "Method Treatment",

key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/util/SymbolicExecutionUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import de.uka.ilkd.key.settings.StrategySettings;
4747
import de.uka.ilkd.key.speclang.Contract;
4848
import de.uka.ilkd.key.speclang.OperationContract;
49-
import de.uka.ilkd.key.strategy.JavaCardDLStrategyFactory;
49+
import de.uka.ilkd.key.strategy.ModularJavaDLStrategyFactory;
5050
import de.uka.ilkd.key.strategy.Strategy;
5151
import de.uka.ilkd.key.strategy.StrategyProperties;
5252
import de.uka.ilkd.key.symbolic_execution.ExecutionVariableExtractor;
@@ -4325,7 +4325,7 @@ public static void initializeStrategy(SymbolicExecutionTreeBuilder builder) {
43254325
new SymbolicExecutionStrategy.Factory().create(proof, strategyProperties));
43264326
} else {
43274327
proof.setActiveStrategy(
4328-
new JavaCardDLStrategyFactory().create(proof, strategyProperties));
4328+
new ModularJavaDLStrategyFactory().create(proof, strategyProperties));
43294329
}
43304330
}
43314331

key.core/src/main/java/de/uka/ilkd/key/macros/AbstractPropositionalExpansionMacro.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ protected boolean ruleApplicationInContextAllowed(RuleApp ruleApp,
8686
* rejects everything else.
8787
*/
8888
private static class PropExpansionStrategy implements Strategy<Goal> {
89-
9089
private final Name NAME = new Name(PropExpansionStrategy.class.getSimpleName());
9190

9291
private final Set<String> admittedRuleNames;
@@ -142,6 +141,5 @@ public void instantiateApp(RuleApp app, PosInOccurrence pio, Goal goal,
142141
public boolean isStopAtFirstNonCloseableGoal() {
143142
return false;
144143
}
145-
146144
}
147145
}

key.core/src/main/java/de/uka/ilkd/key/nparser/KeyAst.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import java.net.URI;
77
import java.net.URISyntaxException;
8-
import java.net.URL;
8+
import java.nio.file.Path;
99
import java.util.ArrayList;
1010
import java.util.HashMap;
1111
import java.util.List;
@@ -129,7 +129,7 @@ public static class File extends KeyAst<KeYParser.FileContext> {
129129

130130
/// Returns the includes (possible empty but not null) computed from the underlying parse
131131
/// tree.
132-
public Includes getIncludes(URL base) {
132+
public Includes getIncludes(Path base) {
133133
IncludeFinder finder = new IncludeFinder(base);
134134
accept(finder);
135135
return finder.getIncludes();

key.core/src/main/java/de/uka/ilkd/key/nparser/ParsingFacade.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.BufferedInputStream;
77
import java.io.File;
88
import java.io.IOException;
9+
import java.net.URISyntaxException;
910
import java.net.URL;
1011
import java.nio.channels.Channels;
1112
import java.nio.channels.ReadableByteChannel;
@@ -70,7 +71,14 @@ public static List<KeyAst.File> parseFiles(URL url) throws IOException {
7071
reached.add(url);
7172
KeyAst.File ctx = parseFile(url);
7273
ctxs.add(ctx);
73-
Collection<RuleSource> includes = ctx.getIncludes(url).getRuleSets();
74+
Path path = null;
75+
try {
76+
path = Path.of(url.toURI());
77+
} catch (URISyntaxException e) {
78+
throw new IOException(e);
79+
}
80+
path = path.getParent();
81+
Collection<RuleSource> includes = ctx.getIncludes(path).getRuleSets();
7482
for (RuleSource u : includes) {
7583
if (!reached.contains(u.url())) {
7684
queue.push(u.url());

key.core/src/main/java/de/uka/ilkd/key/nparser/builder/IncludeFinder.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import java.io.File;
77
import java.net.MalformedURLException;
8-
import java.net.URL;
8+
import java.net.URI;
9+
import java.nio.file.Path;
910

1011
import de.uka.ilkd.key.nparser.KeYParser;
1112
import de.uka.ilkd.key.proof.init.Includes;
@@ -22,15 +23,12 @@
2223
* @see #getIncludes()
2324
*/
2425
public class IncludeFinder extends AbstractBuilder<Void> {
25-
private final URL base;
26+
private final Path base;
2627
private final Includes includes = new Includes();
27-
private final String basePath;
2828
private boolean ldt = false;
2929

30-
public IncludeFinder(URL base) {
30+
public IncludeFinder(Path base) {
3131
this.base = base;
32-
String a = base.getPath();
33-
basePath = a.substring(0, a.lastIndexOf('/'));
3432
}
3533

3634
@Override
@@ -44,29 +42,30 @@ public Void visitOne_include_statement(KeYParser.One_include_statementContext ct
4442
public Void visitOne_include(KeYParser.One_includeContext ctx) {
4543
String value = StringUtil.trim(ctx.getText(), "\"'");
4644
try {
47-
addInclude(value, ctx.relfile != null);
45+
addInclude(value);
4846
} catch (MalformedURLException e) {
4947
throw new BuildingException(ctx, e);
5048
}
5149
return null;
5250
}
5351

54-
private void addInclude(String filename, boolean relativePath) throws MalformedURLException {
52+
private void addInclude(String filename) throws MalformedURLException {
5553
RuleSource source;
5654
if (!filename.endsWith(".key")) {
5755
filename += ".key";
5856
}
5957

60-
if (relativePath) {
61-
filename = filename.replace('/', File.separatorChar); // Not required for Windows, but
62-
// whatsoever
63-
filename = filename.replace('\\', File.separatorChar); // Special handling for Linux
64-
URL path = new URL(base.getProtocol(), base.getHost(), base.getPort(),
65-
basePath + "/" + filename);
66-
source = RuleSourceFactory.initRuleFile(path);
67-
} else {
68-
source = RuleSourceFactory.fromDefaultLocation(filename);
58+
filename = filename.replace('/', File.separatorChar); // Not required for Windows, but
59+
// whatsoever
60+
filename = filename.replace('\\', File.separatorChar); // Special handling for Linux
61+
var path = base.resolve(filename).normalize();
62+
String pathString = path.toString().replace(File.separatorChar, '/'); // URIs on Windows
63+
64+
if (!(pathString.startsWith("file:") || pathString.startsWith("jar:"))) {
65+
pathString = "file:///" + pathString;
6966
}
67+
var url = URI.create(pathString).toURL();
68+
source = RuleSourceFactory.initRuleFile(url);
7069
if (ldt) {
7170
includes.putLDT(filename, source);
7271
} else {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,10 @@ public ImmutableList<Goal> apply(final RuleApp ruleApp) {
650650
removeLastAppliedRuleApp();
651651
node().setAppliedRuleApp(null);
652652
return null;
653+
} catch (IndexOutOfBoundsException e) {
654+
removeLastAppliedRuleApp();
655+
node().setAppliedRuleApp(null);
656+
return null;
653657
} finally {
654658
PERF_APP_EXECUTE.getAndAdd(System.nanoTime() - time);
655659
}

0 commit comments

Comments
 (0)