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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Removal of Triple, and Quadruple #3529

wants to merge 9 commits into from

Conversation

wadoon
Copy link
Member

@wadoon wadoon commented Nov 23, 2024

Refactoring

This PR starts the removal of generic data classes in favor of Java records (aka. named tuples). In this PR, only Triple and Quadruple are removed.

In general, generic parametric data classes (Tuple, Union, ...) lead to unreadable, incomprehensible code, e.g., what does the entity Triple<StatementBlock, URI, Integer> express? Answer: It is the key in a map to find block contracts. Using the record BlockContractKey expresses this better than triple of something.

Therefore, records give you the chance of defining useful variable names, and documentation, and also avoid auto-boxing (hence NPE).

Intended Change

No use of Triple<…> and Quadruple<…>.

Type of pull request

  • X Refactoring (behaviour should not change or only minimally change)
  • X There are changes to the (Java) code

Ensuring quality

  • X by TEST CASES!!! and compiler

@wadoon wadoon changed the title Weigl/recordsftw Removal of Triple, and Quadruple Nov 27, 2024
Copy link

sonarcloud bot commented Nov 28, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
2 New Major Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Member

@WolframPfeifer WolframPfeifer left a comment

Choose a reason for hiding this comment

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

Thanks! In my opinion, it is a very good idea to remove these two classes, and use records with good names instead.

I only have some minor remarks:

  • In some comments, "first" and "second" have been replaced too aggressively ...
  • Some uses of var should be removed in my opinion.
  • Some record parameters could use better names instead of "first", "second", ...

Location location = new Location(url, Position.newOneBased(script.second, script.third));

return new Pair<>(script.first, location);
/**
Copy link
Member

Choose a reason for hiding this comment

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

Should we then maybe just delete this method?

@@ -134,4 +133,13 @@ protected static SequentFormula replace(PosInOccurrence pio, Term newTerm, Servi
public boolean isApplicableOnSubTerms() {
return false;
}

Copy link
Member

Choose a reason for hiding this comment

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

The documentation is only a placeholder. I also would rather have this record in a separate file, since it is used in multiple other files ...

@@ -112,9 +111,10 @@ public class IntermediateProofReplayer {
private final LinkedList<Pair<Node, NodeIntermediate>> queue =
new LinkedList<>();

private record PartnerNode(Node first, PosInOccurrence second, NodeIntermediate third) {}
Copy link
Member

Choose a reason for hiding this comment

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

Do you understand what these parameters are used for? Can you maybe give them better names?


final Triple<Term, Term, Term> ownSEState =
var ownSEState =
Copy link
Member

Choose a reason for hiding this comment

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

I think the type should be made explicit here. Also, SETriple is not really a triple any more, right? So maybe also the method should be renamed ...

}

private record Guard(JavaBlock first, Term second, Term third) {}
Copy link
Member

Choose a reason for hiding this comment

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

Same as earlier: Can you give the parameters/fields of the record useful names?

Comment on lines 456 to +460
* @param heapVar The heap variable for which the values should be merged.
* @param heap1 The first heap term.
* @param heap2 The second heap term.
* @param state1 SE state for the first heap term.
* @param state2 SE state for the second heap term
* @param heap1 The distinguishingFormula heap term.
* @param heap2 The ifTerm heap term.
* @param state1 SE state for the distinguishingFormula heap term.
* @param state2 SE state for the ifTerm heap term
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you wrongly replaced some words in the whole file (also earlier in the file) ...

@@ -132,22 +131,28 @@ public static Term createIfThenElseTerm(final SymbolicExecutionState state1,
* <code>{ v := \if (c1) \then (t1) \else (t2) }</code>, where c1 is the path condition of
* state1. However, the method also tries an optimization: The path condition c2 of state2 could
* be used if it is shorter than c1. Moreover, equal parts of c1 and c2 could be omitted, since
* the condition shall only distinguish between the states. The first element of the triple is
* the discriminating condition, the second and third elements are the respective parts for the
* the condition shall only distinguish between the states. The distinguishingFormula element of
Copy link
Member

Choose a reason for hiding this comment

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

Same as earlier: Too aggressive textual replacements.

Triple<IObserverFunction, Term, Term> dep =
new JmlIO(services).context(context).translateDependencyContract(originalDep);
return cf.dep(kjt, targetHeap, dep, dep.first.isStatic() ? null : context.selfVar());
var dep = new JmlIO(services).context(context).translateDependencyContract(originalDep);
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a bad use of var ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants