Skip to content
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

Removal of Triple, and Quadruple #3529

Merged
merged 10 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import de.uka.ilkd.key.rule.BuiltInRule;
import de.uka.ilkd.key.strategy.StrategyProperties;
import de.uka.ilkd.key.symbolic_execution.util.SymbolicExecutionSideProofUtil;
import de.uka.ilkd.key.util.Triple;

import org.key_project.logic.Name;
import org.key_project.logic.sort.Sort;
Expand Down Expand Up @@ -87,7 +86,7 @@ protected JFunction createResultFunction(Services services, Sort sort) {
* @return The found result {@link Term} and the conditions.
* @throws ProofInputException Occurred Exception.
*/
protected List<Triple<Term, Set<Term>, Node>> computeResultsAndConditions(Services services,
protected List<ResultsAndCondition> computeResultsAndConditions(Services services,
Goal goal, ProofEnvironment sideProofEnvironment, Sequent sequentToProve,
JFunction newPredicate) throws ProofInputException {
return SymbolicExecutionSideProofUtil.computeResultsAndConditions(services, goal.proof(),
Expand Down Expand Up @@ -134,4 +133,13 @@ protected static SequentFormula replace(PosInOccurrence pio, Term newTerm, Servi
public boolean isApplicableOnSubTerms() {
return false;
}

WolframPfeifer marked this conversation as resolved.
Show resolved Hide resolved
/**
*
* @param result
* @param conditions
* @param node
*/
public record ResultsAndCondition(Term result, Set<Term> conditions, Node node) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,13 @@
import java.util.Set;

import de.uka.ilkd.key.java.Services;
import de.uka.ilkd.key.logic.PosInOccurrence;
import de.uka.ilkd.key.logic.Sequent;
import de.uka.ilkd.key.logic.SequentFormula;
import de.uka.ilkd.key.logic.Term;
import de.uka.ilkd.key.logic.TermBuilder;
import de.uka.ilkd.key.logic.TermServices;
import de.uka.ilkd.key.logic.*;
import de.uka.ilkd.key.logic.op.*;
import de.uka.ilkd.key.proof.Goal;
import de.uka.ilkd.key.proof.Node;
import de.uka.ilkd.key.proof.mgt.ProofEnvironment;
import de.uka.ilkd.key.rule.BuiltInRule;
import de.uka.ilkd.key.rule.DefaultBuiltInRuleApp;
import de.uka.ilkd.key.rule.IBuiltInRuleApp;
import de.uka.ilkd.key.rule.RuleAbortException;
import de.uka.ilkd.key.rule.RuleApp;
import de.uka.ilkd.key.rule.*;
import de.uka.ilkd.key.symbolic_execution.util.SymbolicExecutionSideProofUtil;
import de.uka.ilkd.key.symbolic_execution.util.SymbolicExecutionUtil;
import de.uka.ilkd.key.util.Triple;

import org.key_project.logic.Name;
import org.key_project.util.collection.ImmutableArray;
Expand Down Expand Up @@ -181,7 +170,7 @@ public IBuiltInRuleApp createApp(PosInOccurrence pos, TermServices services) {
.addFormula(new SequentFormula(newModalityWithUpdatesTerm), false, false)
.sequent();
// Compute results and their conditions
List<Triple<Term, Set<Term>, Node>> conditionsAndResultsMap =
List<ResultsAndCondition> conditionsAndResultsMap =
computeResultsAndConditions(services, goal, sideProofEnv, sequentToProve,
newPredicate);
// Create new single goal in which the query is replaced by the possible results
Expand All @@ -190,10 +179,11 @@ public IBuiltInRuleApp createApp(PosInOccurrence pos, TermServices services) {
resultGoal.removeFormula(pio);
// Create results
Set<Term> resultTerms = new LinkedHashSet<>();
for (Triple<Term, Set<Term>, Node> conditionsAndResult : conditionsAndResultsMap) {
Term conditionTerm = tb.and(conditionsAndResult.second);
Term resultEqualityTerm = varFirst ? tb.equals(conditionsAndResult.first, otherTerm)
: tb.equals(otherTerm, conditionsAndResult.first);
for (ResultsAndCondition conditionsAndResult : conditionsAndResultsMap) {
Term conditionTerm = tb.and(conditionsAndResult.conditions());
Term resultEqualityTerm =
varFirst ? tb.equals(conditionsAndResult.result(), otherTerm)
: tb.equals(otherTerm, conditionsAndResult.result());
Term resultTerm = pio.isInAntec() ? tb.imp(conditionTerm, resultEqualityTerm)
: tb.and(conditionTerm, resultEqualityTerm);
resultTerms.add(resultTerm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package de.uka.ilkd.key.symbolic_execution.rule;

import java.util.List;
import java.util.Set;

import de.uka.ilkd.key.java.Services;
import de.uka.ilkd.key.logic.PIOPathIterator;
Expand All @@ -16,7 +15,6 @@
import de.uka.ilkd.key.logic.TermServices;
import de.uka.ilkd.key.logic.op.*;
import de.uka.ilkd.key.proof.Goal;
import de.uka.ilkd.key.proof.Node;
import de.uka.ilkd.key.proof.mgt.ProofEnvironment;
import de.uka.ilkd.key.rule.BuiltInRule;
import de.uka.ilkd.key.rule.DefaultBuiltInRuleApp;
Expand All @@ -25,7 +23,6 @@
import de.uka.ilkd.key.rule.RuleAbortException;
import de.uka.ilkd.key.rule.RuleApp;
import de.uka.ilkd.key.symbolic_execution.util.SymbolicExecutionSideProofUtil;
import de.uka.ilkd.key.util.Triple;

import org.key_project.logic.Name;
import org.key_project.logic.sort.Sort;
Expand Down Expand Up @@ -228,7 +225,7 @@ public IBuiltInRuleApp createApp(PosInOccurrence pos, TermServices services) {
sequentToProve =
sequentToProve.addFormula(new SequentFormula(newTerm), false, false).sequent();
// Compute results and their conditions
List<Triple<Term, Set<Term>, Node>> conditionsAndResultsMap =
List<ResultsAndCondition> conditionsAndResultsMap =
computeResultsAndConditions(services, goal, sideProofEnv, sequentToProve,
newPredicate);
// Create new single goal in which the query is replaced by the possible results
Expand All @@ -237,10 +234,11 @@ public IBuiltInRuleApp createApp(PosInOccurrence pos, TermServices services) {
final TermBuilder tb = services.getTermBuilder();
resultGoal.removeFormula(pio);
if (pio.isTopLevel() || queryConditionTerm != null) {
for (Triple<Term, Set<Term>, Node> conditionsAndResult : conditionsAndResultsMap) {
Term conditionTerm = tb.and(conditionsAndResult.second);
Term newEqualityTerm = varFirst ? tb.equals(varTerm, conditionsAndResult.first)
: tb.equals(conditionsAndResult.first, varTerm);
for (ResultsAndCondition conditionsAndResult : conditionsAndResultsMap) {
Term conditionTerm = tb.and(conditionsAndResult.conditions());
Term newEqualityTerm =
varFirst ? tb.equals(varTerm, conditionsAndResult.result())
: tb.equals(conditionsAndResult.result(), varTerm);
Term resultTerm = pio.isInAntec() ? tb.imp(conditionTerm, newEqualityTerm)
: tb.and(conditionTerm, newEqualityTerm);
if (queryConditionTerm != null) {
Expand All @@ -256,11 +254,11 @@ public IBuiltInRuleApp createApp(PosInOccurrence pos, TermServices services) {
tb.equals(resultFunctionTerm, varTerm),
services),
pio.isInAntec(), false);
for (Triple<Term, Set<Term>, Node> conditionsAndResult : conditionsAndResultsMap) {
Term conditionTerm = tb.and(conditionsAndResult.second);
for (ResultsAndCondition conditionsAndResult : conditionsAndResultsMap) {
Term conditionTerm = tb.and(conditionsAndResult.conditions());
Term resultTerm = tb.imp(conditionTerm,
varFirst ? tb.equals(resultFunctionTerm, conditionsAndResult.first)
: tb.equals(conditionsAndResult.first, resultFunctionTerm));
varFirst ? tb.equals(resultFunctionTerm, conditionsAndResult.result())
: tb.equals(conditionsAndResult.result(), resultFunctionTerm));
resultGoal.addFormula(new SequentFormula(resultTerm), true, false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import de.uka.ilkd.key.strategy.StrategyProperties;
import de.uka.ilkd.key.symbolic_execution.profile.SimplifyTermProfile;
import de.uka.ilkd.key.symbolic_execution.profile.SymbolicExecutionJavaProfile;
import de.uka.ilkd.key.symbolic_execution.rule.AbstractSideProofRule.ResultsAndCondition;
import de.uka.ilkd.key.util.ProofStarter;
import de.uka.ilkd.key.util.SideProofUtil;
import de.uka.ilkd.key.util.Triple;

import org.key_project.logic.Name;
import org.key_project.util.collection.ImmutableArray;
Expand Down Expand Up @@ -169,7 +169,8 @@ public static List<Pair<Term, Node>> computeResults(Services services, Proof pro
* @return The found result {@link Term} and the conditions.
* @throws ProofInputException Occurred Exception.
*/
public static List<Triple<Term, Set<Term>, Node>> computeResultsAndConditions(Services services,
public static List<ResultsAndCondition> computeResultsAndConditions(
Services services,
Proof proof, ProofEnvironment sideProofEnvironment, Sequent sequentToProve,
Operator operator, String description, String methodTreatment, String loopTreatment,
String queryTreatment, String splittingOption, boolean addNamesToServices)
Expand All @@ -182,8 +183,7 @@ public static List<Triple<Term, Set<Term>, Node>> computeResultsAndConditions(Se
Set<Operator> relevantThingsInSequentToProve =
extractRelevantThings(info.getProof().getServices(), sequentToProve);
// Extract results and conditions from side proof
List<Triple<Term, Set<Term>, Node>> conditionsAndResultsMap =
new LinkedList<>();
List<ResultsAndCondition> conditionsAndResultsMap = new LinkedList<>();
for (Goal resultGoal : info.getProof().openGoals()) {
if (SymbolicExecutionUtil.hasApplicableRules(resultGoal)) {
throw new IllegalStateException("Not all applicable rules are applied.");
Expand Down Expand Up @@ -245,8 +245,8 @@ public static List<Triple<Term, Set<Term>, Node>> computeResultsAndConditions(Se
if (result == null) {
result = services.getTermBuilder().ff();
}
conditionsAndResultsMap.add(
new Triple<>(result, resultConditions, resultGoal.node()));
conditionsAndResultsMap
.add(new ResultsAndCondition(result, resultConditions, resultGoal.node()));
}
return conditionsAndResultsMap;
} finally {
Expand Down Expand Up @@ -303,14 +303,11 @@ public static void addNewNamesToNamespace(Services services, Term term) {
final Namespace<JFunction> functions = services.getNamespaces().functions();
final Namespace<IProgramVariable> progVars = services.getNamespaces().programVariables();
// LogicVariables are always local bound
term.execPreOrder(new DefaultVisitor() {
@Override
public void visit(Term visited) {
if (visited.op() instanceof JFunction) {
functions.add((JFunction) visited.op());
} else if (visited.op() instanceof IProgramVariable) {
progVars.add((IProgramVariable) visited.op());
}
term.execPreOrder((DefaultVisitor) visited -> {
if (visited.op() instanceof JFunction) {
functions.add((JFunction) visited.op());
} else if (visited.op() instanceof IProgramVariable) {
progVars.add((IProgramVariable) visited.op());
}
});
}
Expand Down Expand Up @@ -385,12 +382,9 @@ public static Set<Operator> extractRelevantThings(final Services services,
Sequent sequentToProve) {
final Set<Operator> result = new HashSet<>();
for (SequentFormula sf : sequentToProve) {
sf.formula().execPreOrder(new DefaultVisitor() {
@Override
public void visit(Term visited) {
if (isRelevantThing(services, visited)) {
result.add(visited.op());
}
sf.formula().execPreOrder((DefaultVisitor) visited -> {
if (isRelevantThing(services, visited)) {
result.add(visited.op());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import de.uka.ilkd.key.java.JavaInfo;
import de.uka.ilkd.key.java.Services;
import de.uka.ilkd.key.parser.Location;
import de.uka.ilkd.key.nparser.ProofScriptEntry;
import de.uka.ilkd.key.proof.Proof;
import de.uka.ilkd.key.proof.init.InitConfig;
import de.uka.ilkd.key.proof.init.Profile;
Expand All @@ -21,7 +21,7 @@
import de.uka.ilkd.key.proof.io.ProblemLoaderException;
import de.uka.ilkd.key.proof.mgt.SpecificationRepository;

import org.key_project.util.collection.Pair;
import org.jspecify.annotations.Nullable;

/**
* Instances of this class are used to collect and access all relevant information for verification
Expand All @@ -48,7 +48,7 @@ public class KeYEnvironment<U extends UserInterfaceControl> {
/**
* An optional field denoting a script contained in the proof file.
*/
private final Pair<String, Location> proofScript;
private final @Nullable ProofScriptEntry proofScript;

/**
* Indicates that this {@link KeYEnvironment} is disposed.
Expand Down Expand Up @@ -77,7 +77,7 @@ public KeYEnvironment(U ui, InitConfig initConfig) {
* @param initConfig The loaded project.
*/
public KeYEnvironment(U ui, InitConfig initConfig, Proof loadedProof,
Pair<String, Location> proofScript, ReplayResult replayResult) {
@Nullable ProofScriptEntry proofScript, ReplayResult replayResult) {
this.ui = ui;
this.initConfig = initConfig;
this.loadedProof = loadedProof;
Expand Down Expand Up @@ -317,7 +317,7 @@ public boolean isDisposed() {
return disposed;
}

public Pair<String, Location> getProofScript() {
public @Nullable ProofScriptEntry getProofScript() {
return proofScript;
}
}
21 changes: 17 additions & 4 deletions key.core/src/main/java/de/uka/ilkd/key/nparser/KeyAst.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* SPDX-License-Identifier: GPL-2.0-only */
package de.uka.ilkd.key.nparser;

import java.net.URI;
import java.net.URL;
import java.util.List;

import de.uka.ilkd.key.java.Position;
import de.uka.ilkd.key.nparser.builder.BuilderHelpers;
import de.uka.ilkd.key.nparser.builder.ChoiceFinder;
import de.uka.ilkd.key.nparser.builder.FindProblemInformation;
Expand All @@ -15,7 +17,6 @@
import de.uka.ilkd.key.settings.Configuration;
import de.uka.ilkd.key.settings.ProofSettings;
import de.uka.ilkd.key.speclang.njml.JmlParser;
import de.uka.ilkd.key.util.Triple;

import org.key_project.util.java.StringUtil;

Expand Down Expand Up @@ -84,12 +85,24 @@ public static class File extends KeyAst<KeYParser.FileContext> {
return settings;
}

public @Nullable Triple<String, Integer, Integer> findProofScript() {
/**
* Returns the a {@link ProofScriptEntry} from the underlying AST if an {@code \proofscript}
* entry is present.
* The {@code url} is used as the source of input and might be later used for error message,
* or including
* other files.
*
* @param url location pointing to the source of the AST
* @return a {@link ProofScriptEntry} if {@code \proofscript} is present
*/
public @Nullable ProofScriptEntry findProofScript(URI url) {
if (ctx.problem() != null && ctx.problem().proofScript() != null) {
KeYParser.ProofScriptContext pctx = ctx.problem().proofScript();
Location location = new Location(url,
Position.newOneBased(pctx.ps.getLine(), pctx.ps.getCharPositionInLine()));

String text = pctx.ps.getText();
return new Triple<>(StringUtil.trim(text, '"'), pctx.ps.getLine(),
pctx.ps.getCharPositionInLine());
return new ProofScriptEntry(StringUtil.trim(text, '"'), location);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* This file is part of KeY - https://key-project.org
* KeY is licensed under the GNU General Public License Version 2
* SPDX-License-Identifier: GPL-2.0-only */
package de.uka.ilkd.key.nparser;

import de.uka.ilkd.key.parser.Location;

import org.jspecify.annotations.NonNull;

/**
* This struct encapsulate the information of a proofscript found in key files.
*
* @param script the content of the script
* @param location location of the content
* @author Alexander Weigl
* @version 1 (23.04.24)
*/
public record ProofScriptEntry(@NonNull String script, @NonNull Location location) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import de.uka.ilkd.key.java.abstraction.KeYJavaType;
import de.uka.ilkd.key.logic.Sequent;
import de.uka.ilkd.key.nparser.ChoiceInformation;
import de.uka.ilkd.key.nparser.KeyAst;
import de.uka.ilkd.key.nparser.ProblemInformation;
import de.uka.ilkd.key.nparser.ProofReplayer;
import de.uka.ilkd.key.nparser.*;
import de.uka.ilkd.key.proof.Proof;
import de.uka.ilkd.key.proof.ProofAggregate;
import de.uka.ilkd.key.proof.io.IProofFileParser;
Expand All @@ -23,14 +21,14 @@
import de.uka.ilkd.key.speclang.PositionedString;
import de.uka.ilkd.key.speclang.SLEnvInput;
import de.uka.ilkd.key.util.ProgressMonitor;
import de.uka.ilkd.key.util.Triple;

import org.key_project.util.collection.DefaultImmutableSet;
import org.key_project.util.collection.ImmutableSet;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;


/**
Expand Down Expand Up @@ -174,12 +172,24 @@ public boolean implies(ProofOblInput po) {
}


/**
* True iff a {@link ProofScriptEntry} is present
*
* @see #readProofScript()
*/
public boolean hasProofScript() {
return getParseContext().findProofScript() != null;
return readProofScript() != null;
}

public Triple<String, Integer, Integer> readProofScript() {
return getParseContext().findProofScript();
/**
* Returns the {@link ProofScriptEntry} in this resource
*
* @return {@link ProofScriptEntry} if present otherwise null
* @see KeyAst.File#findProofScript(URI)
*/
public @Nullable ProofScriptEntry readProofScript() {
URI url = getInitialFile().toURI();
return getParseContext().findProofScript(url);
}

/**
Expand Down
Loading
Loading