Skip to content

Commit fb96158

Browse files
authored
Fix for a performance regression (#3607)
2 parents 888bee0 + 10f6e27 commit fb96158

File tree

9 files changed

+71
-19
lines changed

9 files changed

+71
-19
lines changed

key.core/src/main/java/de/uka/ilkd/key/control/instantiation_model/TacletInstantiationModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ private void initIfChoiceModels() {
126126

127127
if (size > 0) {
128128
ImmutableArray<AssumesFormulaInstantiation> antecCand =
129-
AssumesFormulaInstSeq.createList(seq, true);
129+
AssumesFormulaInstSeq.createList(seq, true, services);
130130
ImmutableArray<AssumesFormulaInstantiation> succCand =
131-
AssumesFormulaInstSeq.createList(seq, false);
131+
AssumesFormulaInstSeq.createList(seq, false, services);
132132

133133
Iterator<SequentFormula> it = ifseq.iterator();
134134
Term ifFma;

key.core/src/main/java/de/uka/ilkd/key/java/ServiceCaches.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import de.uka.ilkd.key.proof.Proof;
1313
import de.uka.ilkd.key.proof.TermTacletAppIndex;
1414
import de.uka.ilkd.key.proof.TermTacletAppIndexCacheSet;
15-
import de.uka.ilkd.key.rule.AssumesFormulaInstantiationCache;
1615
import de.uka.ilkd.key.rule.metaconstruct.arith.Monomial;
1716
import de.uka.ilkd.key.rule.metaconstruct.arith.Polynomial;
1817
import de.uka.ilkd.key.strategy.IfInstantiationCachePool;
@@ -24,6 +23,8 @@
2423

2524
import org.key_project.logic.op.Operator;
2625
import org.key_project.logic.sort.Sort;
26+
import org.key_project.prover.proof.SessionCaches;
27+
import org.key_project.prover.rules.instantiation.caches.AssumesFormulaInstantiationCache;
2728
import org.key_project.prover.sequent.PosInOccurrence;
2829
import org.key_project.prover.strategy.costbased.RuleAppCost;
2930
import org.key_project.util.LRUCache;
@@ -69,7 +70,7 @@
6970
*
7071
* @author Martin Hentschel
7172
*/
72-
public class ServiceCaches {
73+
public class ServiceCaches implements SessionCaches {
7374
/**
7475
* The maximal number of index entries in {@link #getTermTacletAppIndexCache()}.
7576
*/
@@ -221,7 +222,7 @@ public final IfInstantiationCachePool getIfInstantiationCache() {
221222
return ifInstantiationCache;
222223
}
223224

224-
public final AssumesFormulaInstantiationCache getIfFormulaInstantiationCache() {
225+
public final AssumesFormulaInstantiationCache getAssumesFormulaInstantiationCache() {
225226
return assumesFormulaInstantiationCache;
226227
}
227228

key.core/src/main/java/de/uka/ilkd/key/java/Services.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121

2222
import org.key_project.logic.LogicServices;
2323
import org.key_project.logic.Name;
24+
import org.key_project.prover.proof.ProofServices;
2425
import org.key_project.util.lookup.Lookup;
2526

2627
/**
2728
* This is a collection of common services to the KeY prover. Services include information on the
2829
* underlying Java model and a converter to transform Java program elements to logic (where
2930
* possible) and back.
3031
*/
31-
public class Services implements TermServices, LogicServices {
32+
public class Services implements TermServices, LogicServices, ProofServices {
3233
/**
3334
* the proof
3435
*/

key.core/src/main/java/de/uka/ilkd/key/rule/TacletApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,8 @@ public ImmutableList<TacletApp> findIfFormulaInstantiations(Sequent seq, Service
859859
return findIfFormulaInstantiationsHelp(
860860
createSemisequentList(taclet().assumesSequent().succedent()),
861861
createSemisequentList(taclet().assumesSequent().antecedent()),
862-
AssumesFormulaInstSeq.createList(seq, false),
863-
AssumesFormulaInstSeq.createList(seq, true),
862+
AssumesFormulaInstSeq.createList(seq, false, services),
863+
AssumesFormulaInstSeq.createList(seq, true, services),
864864
ImmutableSLList.nil(), matchConditions(), services);
865865
}
866866

key.core/src/main/java/de/uka/ilkd/key/strategy/AssumesInstantiator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public void findAssumesFormulaInstantiations() {
7373
addResult(tacletAppContainer.getTacletApp());
7474
} else {
7575
final Services services = getServices();
76-
allAntecFormulas = AssumesFormulaInstSeq.createList(p_seq, true);
77-
allSuccFormulas = AssumesFormulaInstSeq.createList(p_seq, false);
76+
allAntecFormulas = AssumesFormulaInstSeq.createList(p_seq, true, services);
77+
allSuccFormulas = AssumesFormulaInstSeq.createList(p_seq, false, services);
7878
findIfFormulaInstantiationsHelp(ifSequent.succedent().asList().reverse(), //// Matching
7979
//// with the
8080
//// last
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 org.key_project.prover.proof;
5+
6+
/**
7+
* provides access to services related to proof search
8+
*/
9+
public interface ProofServices {
10+
/**
11+
* provides access to the caching infrastructure of a proof session
12+
*
13+
* @return the caches used during proof search
14+
*/
15+
SessionCaches getCaches();
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 org.key_project.prover.proof;
5+
6+
import org.key_project.prover.rules.instantiation.caches.AssumesFormulaInstantiationCache;
7+
8+
/**
9+
* Provides access to caches used during proof search
10+
*/
11+
public interface SessionCaches {
12+
/**
13+
* returns the cache relevant for matching assumes formulas
14+
*
15+
* @return the cache relevant for matching assumes formulas
16+
*/
17+
AssumesFormulaInstantiationCache getAssumesFormulaInstantiationCache();
18+
}

key.ncore.calculus/src/main/java/org/key_project/prover/rules/instantiation/AssumesFormulaInstSeq.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import org.key_project.logic.LogicServices;
77
import org.key_project.logic.PosInTerm;
8+
import org.key_project.prover.proof.ProofServices;
9+
import org.key_project.prover.rules.instantiation.caches.AssumesFormulaInstantiationCache;
810
import org.key_project.prover.sequent.PosInOccurrence;
911
import org.key_project.prover.sequent.Semisequent;
1012
import org.key_project.prover.sequent.Sequent;
@@ -58,15 +60,9 @@ public String toString(LogicServices services) {
5860
/**
5961
* Create a list with all formulas of a given semi-sequent
6062
*/
61-
public static ImmutableArray<AssumesFormulaInstantiation> createList(Sequent p_s,
63+
private static ImmutableArray<AssumesFormulaInstantiation> createListHelp(Sequent p_s,
64+
Semisequent semi,
6265
boolean inAntecedent) {
63-
Semisequent semi;
64-
if (inAntecedent) {
65-
semi = p_s.antecedent();
66-
} else {
67-
semi = p_s.succedent();
68-
}
69-
7066
final AssumesFormulaInstSeq[] assumesInstFromSeq =
7167
new AssumesFormulaInstSeq[semi.size()];
7268
int i = assumesInstFromSeq.length - 1;
@@ -79,6 +75,26 @@ public static ImmutableArray<AssumesFormulaInstantiation> createList(Sequent p_s
7975
return new ImmutableArray<>(assumesInstFromSeq);
8076
}
8177

78+
/**
79+
* Retrieves a list with all formulas of a given semi-sequent
80+
*/
81+
public static ImmutableArray<AssumesFormulaInstantiation> createList(Sequent p_s,
82+
boolean inAntecedent,
83+
ProofServices services) {
84+
final AssumesFormulaInstantiationCache cache =
85+
services.getCaches().getAssumesFormulaInstantiationCache();
86+
final Semisequent semi = inAntecedent ? p_s.antecedent() : p_s.succedent();
87+
88+
ImmutableArray<AssumesFormulaInstantiation> val = cache.get(inAntecedent, semi);
89+
90+
if (val == null) {
91+
val = createListHelp(p_s, semi, inAntecedent);
92+
cache.put(inAntecedent, semi, val);
93+
}
94+
95+
return val;
96+
}
97+
8298
@Override
8399
public String toString() {
84100
return toString(null);

key.core/src/main/java/de/uka/ilkd/key/rule/AssumesFormulaInstantiationCache.java renamed to key.ncore.calculus/src/main/java/org/key_project/prover/rules/instantiation/caches/AssumesFormulaInstantiationCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This file is part of KeY - https://key-project.org
22
* KeY is licensed under the GNU General Public License Version 2
33
* SPDX-License-Identifier: GPL-2.0-only */
4-
package de.uka.ilkd.key.rule;
4+
package org.key_project.prover.rules.instantiation.caches;
55

66
import java.util.concurrent.locks.ReentrantReadWriteLock;
77
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;

0 commit comments

Comments
 (0)