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

Exploiting JML Names in the Proof Tree #3022

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

Conversation

wadoon
Copy link
Member

@wadoon wadoon commented Feb 5, 2023

This PR adds the newly introduced JML names for entities to KeY. Such labels are exploited inside the KeY's proof tree as branching labels. And may later become accessible in proof scripts.

This MR brings following changes:

  • JML entities have names:

    //@ invariant NAME: true;
    //@ ensures<h1> NAME: true;
    //@ behavior NAME: requires NAME1: true; 
  • lbl function is supported, e.g., \lbl(NAME, x != y)

  • A new term label name(XXX) is added, where "XXX" holds the name given in the JML specification.

  • Terms that are created by the JMLParser/Translator receive a this term label if the entity has a name or a \lbl was given.

  • Change to the KeY parser: Goal templates can have computed labels.

    Currently, the label of a goal can be a schema variable or static string. With this MR you are allowed to define labels which are computed by a Java interface BranchNamingFunction.
    A taclet exploits this in the following way:

    andRight {
        \find (==> b & c)
        "\nameLabelOf(b)":\replacewith(==> b);
        "\nameLabelOf(c)":\replacewith(==> c)
        \heuristics(beta)
    };
    

    New branching naming functions can be added by an interface. The \nameLabelOf tries to find a f«name(X)» term label, and returns X. It fallbacks to the origin term label and then to the toString representation.

TODO

  • Better branch names for origin label
  • Test function for the introduction of abbreviations on sequent based on name label.
  • Discuss impact on proof scripts. Extend proofs scripts with abbreviation variable? @post_abc?
  • andRightX and orLeftX per Built-In rule?

KeY example (working)

\sorts { s; }
\predicates {	p; 	q; }
\problem {
  (p<<name("A")>> -> q<<name("B")>>) -> !q<<name("C")>> -> !p<<name("D")>>
}

image

New rules andRightX (for $x \in 3..6$) allows a more comprehensible proof split.

image

JML

Consider following examples:

class Test {
    //@ public invariant MY_SUPER_INVARIANT: CONST == 42;

    public final int CONST = 42;
    /*@
    requires Z: this != null;
    ensures A: \result == 42;
    ensures B: \result >= 0;
    ensures C: \result != 0;
    */
    public int foo() {return CONST;}
}

This results into the following proof tree. At places where no name label is available we ask the origin label for a string representation. The origin label needs further improvement e.g., line numbers ❗

image

Sum And Max

class SumAndMax {

    int sum;
    int max;

    /*@ normal_behaviour
      @   requires R1: (\forall int i; 0 <= i && i < a.length; 0 <= a[i]);
      @   assignable sum, max;
      @   ensures E1: (\forall int i; 0 <= i && i < a.length; a[i] <= max);
      @   ensures E2: (a.length > 0
      @           ==> (\exists int i; 0 <= i && i < a.length; max == a[i]));
      @   ensures E3: sum == (\sum int i; 0 <= i && i < a.length; a[i]);
      @   ensures E4: sum <= a.length * max;
      @*/
    void sumAndMax(int[] a) {
        sum = 0;
        max = 0;
        int k = 0;

        /*@ loop_invariant I1: 0 <= k && k <= a.length;
          @ loop_invariant I2: (\forall int i; 0 <= i && i < k; a[i] <= max);
          @ loop_invariant I3: (k == 0 ==> max == 0);
          @ loop_invariant I4: (k > 0 ==> (\exists int i; 0 <= i && i < k; max == a[i]));
          @ loop_invariant I5: sum == (\sum int i; 0 <= i && i< k; a[i]);
          @ loop_invariant I6: sum <= k * max;
          @
          @  assignable sum, max;
          @  decreases a.length - k;
          @*/
        while(k < a.length) {
            if(max < a[k]) {
                max = a[k];
            }
            sum += a[k];
            k++;
        }
    }
}

Introduction of Abbreviations for Named Terms

Menu: Proof-> Introduce abbreviation for named formulas

Before:

image

After actions is applied:

image

* master: (168 commits)
  missing NPE check in MasterHandlerTest
  Fix KeYProject#1696 (wrong hash for heapAtPre)
  a two-state method needs the invariant also at pre-state (try to fix KeYProject#1689)
  Fix KeYProject#1690
  Fix failing test case
  Fixed rule "wellFormedStoreObjectEQ"
  [floats] repairing JML interpretation of equality on floats and doubles.
  [floats] optimising float termination rules
  [floats] reconducting a proof
  Move functionality for relevant Java files from NodeInfo to new class ProofJavaSourceCollection
  fix error in logging formatting strings
  fix the collection of JUnit tests on jenkins
  [floats] missing rules for double assignments
  [floats] re-implementing a Z3FP solver.
  also show message of the chained cause of the exception in IssueDialog
  [floats] added missing unary minus
  repairing cast to integer in JML translation.
  [floats] repairing float-cast rules
  [floats] repairing cast to float
  [floats] nasty method call missing
  ...

# Conflicts:
#	key/key.core/src/main/antlr4/JmlParser.g4
#	key/key.core/src/main/java/de/uka/ilkd/key/nparser/builder/TacletPBuilder.java
#	key/key.core/src/main/java/de/uka/ilkd/key/speclang/jml/pretranslation/TextualJMLSpecCase.java
#	key/key.ui/src/main/java/de/uka/ilkd/key/gui/MainWindow.java
#	key/test/Test.java
* origin/master: (43 commits)
  fix jml-assert/model-methods-*.key Wrong classnames and forgoten parameter type.
  fix jml-assert/ModelMethods.java for real (wrong classname)
  fix jml-assert/ModelMethods.java (missing semicolon)
  please checkstyle
  make jml-assert/ModelMethod::test4 static as it was meant to be
  keep the ProgramVariableCollection when translating JML asserts While here only selfVar is used to fix usages of `this` in JML asserts the rest is probably needed to fix `\old()`.
  ensure that the condition of a JML assert statement is always a formula The condition is always some boolean expression, so it gets translated to either a formula or boolean Term, so normalize that to formula as that is what the rule needs in the end. Do it directly when translating the Term, to reject programs where the expression isn't boolean early.
  add tests for issue KeYProject#1698
  remove pointless extension of CreatingASTVisitor by MergeRuleUtils.CollectLocationVariablesVisitor As the name say it only collects stuff in the AST and doesn't change anything so the work CreatingASTVisitor does is unnessesary. So extend JavaASTVisitor directly instead.
  Adapt test cases after fixing class invariant soundness bug KeYProject#1598
  Fix KeYProject#1598 soundness bug of class invariants by adding '\assumes ( ==> self = null )'
  cleaned after talking to Richard
  fix after merge
  remove forgotten unused imports and last old TODO of jml assert branch
  remove the remaining TODOs of this branch - JMLAssert: should be fine - getOr: not needed anymore after better understanding CreatingASTVisitor     and implementing it better (maybe use children as parameter name in     CreatingASTVisitor too) - ProgVarReplaceVisitor: should be fine - SLEnvInput: the AST can't be changed at that point so that idea isn't     possible
  add tests for using quantors in jml assert/assume
  copy back test to hopefully fix mergeconflict
  fixed file name in example
  fixed wrong verbose output of testRunAllProofs
  added notloadable proofcollection TestProperty
  ...

# Conflicts:
#	key/key.core/src/main/java/de/uka/ilkd/key/proof/init/JavaProfile.java
* Fixing test cases
* Refactor (own package)
* origin/master: (119 commits)
  Use generic method correctly
  avoid creating proof obligations in ProofManagementDialog It is unnecessary to create proof obligations in most cases there and creating some proof obligations changes state shared with a large part of KeY (see KeYProject#1715).
  JavaDoc for changed methods + Doubles for timeout
  Checkstyle/SonarQube
  Avoid reopening popup menu when selection button is pressed
  Bug fixes from the IdentityHashMap case study
  Solve missing plugin in shadowJar by adding `mergeServiceFiles()`
  SonarQube
  Checkstyle
  mark JSpinner backgrounds correctly when an error occurs
  Deactivate SMT button when no proof is loaded
  Check formatting  with Spotless
  Add JavaDoc
  Modify problems using solver sockets
  Minor changes
  checkstyle
  Write comments
  Delete solvers.txt (automatically created during build)
  Load solvers.txt from everywhere on classpath
  Fix failing legacy solver test cases by setting different SMT logic
  ...
@wadoon wadoon self-assigned this Feb 5, 2023
# By Julian Wiesler (146) and others
# Via Wolfram Pfeifer (25) and others
* origin/main: (331 commits)
  Report location on error in constant evaluation
  Fix javadoc formatting
  Correctly handle unloading proofs
  Formatting and documentation
  ignore class output, add test case
  Javac issues extension: handle non-Java proofs
  Fix construction of Javac issue dialog
  fix typo
  Update tests.yml
  Fix branch name in Checkstyle script
  Update feature_request.md
  copy bug-report from gitlab to github
  Update dlsmt.sh
  Taclet equality oracle
  Move files
  Spotless
  Add open goals to error message of reload proof test
  Allow empty constructor blocks and others
  Deactivate ListOperationsNonNull_remove test
  Fix specification and proof script for setValueAt
  ...

# Conflicts:
#	key.core/src/main/antlr4/JmlParser.g4
#	key.core/src/main/java/de/uka/ilkd/key/logic/label/SpecNameLabel.java
#	key.core/src/main/java/de/uka/ilkd/key/nparser/builder/TacletPBuilder.java
#	key.core/src/main/java/de/uka/ilkd/key/proof/init/JavaProfile.java
#	key.core/src/main/java/de/uka/ilkd/key/speclang/jml/pretranslation/TextualJMLClassInv.java
#	key.core/src/main/java/de/uka/ilkd/key/speclang/jml/pretranslation/TextualJMLInitially.java
#	key.core/src/main/java/de/uka/ilkd/key/speclang/jml/pretranslation/TextualJMLSpecCase.java
#	key.core/src/main/java/de/uka/ilkd/key/speclang/njml/LabeledParserRuleContext.java
#	key.core/src/main/java/de/uka/ilkd/key/speclang/njml/TextualTranslator.java
#	key.core/src/test/java/de/uka/ilkd/key/rule/tacletbuilder/BranchNamingFunctionsTest.java
#	key.ui/src/main/java/de/uka/ilkd/key/gui/MainWindow.java
#	key.ui/src/main/java/de/uka/ilkd/key/gui/actions/MakeNamedFormulaToAbbrevAction.java
#	key/key.core/src/main/java/de/uka/ilkd/key/logic/label/FormulaTermLabel.java
#	key/key.core/src/main/java/de/uka/ilkd/key/rule/executor/javadl/NoFindTacletExecutor.java
#	key/key.core/src/main/java/de/uka/ilkd/key/rule/tacletbuilder/TacletGoalTemplate.java
#	key/key.core/src/main/resources/de/uka/ilkd/key/proof/rules/propRule.key
#	key/test/Test.java
wadoon and others added 6 commits March 3, 2023 15:09
* origin/main: (25 commits)
  Test for correct pretty printer behaviour
  Fix program element printing in proof saver
  Fix another proof file
  Fix taclet proof that uses this construct
  Fix inInt typo
  Fix ProofTreeView NPE
  Bump org.junit.vintage:junit-vintage-engine from 5.8.2 to 5.9.2
  Bump org.antlr:antlr4 from 4.9.3 to 4.12.0
  Bump org.antlr:antlr from 3.5.2 to 3.5.3
  disable test case for java 17
  Enabling Java 17 for unit-tests
  Formatting
  Indicate state in UI
  Handle proof modifications that prevent undos
  Refactor undo button to KeyAction
  Set popup size automatically
  Change UI to button + dropdown menu
  Fix misc. issues + Javadocs
  Support undo for auto mode and close by SMT
  Checkstyle, Javadocs
  ...
@wadoon wadoon marked this pull request as ready for review March 22, 2023 15:55
@wadoon

This comment was marked as resolved.

@wadoon

This comment was marked as resolved.

@wadoon
Copy link
Member Author

wadoon commented Mar 31, 2023

Still struggling about the differences in the proofs.

image

Added a GUI for finding differences in proof trees and sequents.

wadoon and others added 10 commits December 16, 2023 15:22
* origin/main:
  Bump com.miglayout:miglayout-swing from 11.2 to 11.3
* main: (25 commits)
  Bump com.diffplug.spotless from 6.24.0 to 6.25.0
  Bump com.diffplug.spotless from 6.23.3 to 6.24.0
  Bump org.slf4j:slf4j-api from 2.0.10 to 2.0.11
  Bump org.slf4j:slf4j-api from 2.0.9 to 2.0.10
  spotless reformat
  automatical translate package.html to package-info.java
  spotless
  after discussion: all datatypes are free
  ignore files in */antlr4/gen/*
  Treat duplicate predicate declarations as error.
  adding example file for natural numbers as ADTs
  Fix TestTermParser to avoid multiple parsing of declarations
  implement the discussion of KaKeY
  spotless
  fix merge errors
  fix passing of warnings
  no spaces in displaynames of taclets
  fix spaces in origin label manually + spotless
  add an example for case distinction
  add list example with two proofs
  ...
# By Drodt (57) and others
# Via GitHub (17) and others
* origin/main: (147 commits)
  Merge main into extraxt-new-core
  fixes KeYProject#1533
  added checkbox to disable example loader directly in dialog
  address reviewer comments:
  set border + spotless + typo
  JML enabled keys indicator for the status line
  add test case for adt taclets
  Fix position info for equality expr errors
  Revert debugging code
  Spotless
  Add ADT Deconstructors
  Moved TestSMTMod to newsmt2
  spotless applied to TestSMTMod
  Added test for Modulo Translation
  Added translation from KeY mod to SMT mod. Soundness derived from translation of KeY div to SMT div
  preventing NPEs in overloaded operators
  added test cases for operator overloading
  activate the OverloadedOperatorHandler.java for LocSet datatype and repair translation
  Bump ch.qos.logback:logback-classic from 1.4.14 to 1.5.0
  Update README.md (license date and Java version)
  ...

# Conflicts:
#	key.core/src/main/java/de/uka/ilkd/key/nparser/builder/TacletPBuilder.java
#	key.core/src/main/java/de/uka/ilkd/key/settings/GeneralSettings.java
#	key.core/src/main/java/de/uka/ilkd/key/speclang/jml/pretranslation/TextualJMLConstruct.java
#	key.ui/build.gradle
#	keyext.caching/src/test/java/de/uka/ilkd/key/proof/reference/TestReferenceSearcher.java
* main:
  ColorSettings: drop old configuration file format
  Bump ch.qos.logback:logback-classic from 1.5.0 to 1.5.3
@mattulbrich mattulbrich marked this pull request as draft March 26, 2024 12:43
auto-merge was automatically disabled March 26, 2024 12:43

Pull request was converted to draft

@wadoon wadoon marked this pull request as ready for review March 28, 2024 20:39
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.

For me, the generation of name labels seems to work only partially:

class Labels {
    int f = 7; 
    //@ invariant inv1: f == 7;
    /*@ requires pre1: x == 5;
      @ ensures post1: \result == 42;
      @ ensures post2: \result == \lbl(prod, 6 * 7);
      @*/
    int m(int x) {
        return 42;
    }
}

image
Only the formula with lbl got a label as expected. Am I doing something wrong here?

wadoon and others added 4 commits June 21, 2024 14:26
* also fix some encoding in recorder/src files
* main:
  change gradle github action to new syntax
  adding comments to jml spec factory default contracts
  EQ version of seqSwapPreservesSeqPerm + proof
  added rule for sequences: swap preserves perm
  Fix test case that failed with new default-contract behavior
  Fix code format
  Add test
  Add documentation
  Add proof setting for sound or unsound default contracts
  Don't add default contracts for Object or <init> methods
  Default contract for contractless methods
  Fix compiler check when using classpath
  Add printf to JavaRedux
* weigl/codequality:
  reenable sonarqube, disable the crappy things
wadoon added 2 commits June 26, 2024 16:13
* refs/heads/main:
  Update key.core/src/main/java/de/uka/ilkd/key/nparser/builder/TacletPBuilder.java
  spotless
  update oracle for taclet equality test
  repair soundness of assignment2UpdateRules with checked overflows
  spotless
  Changed types in replacement map for WD taclets, since PR KeYProject#3436 made casting TermSV to ProgramVariable not applicable
  Fix and test goToNext()
  Fix goToNextSibling() (thx Tobias)
  Format
  Add comments and next() method
  Remove SVSubstitute
  Clean up inheritance
  Implement missing methods
  Start implementation of traversal
  Implement cursor
  Increase Java version
  API design
  throw an error if choices used in a taclet are not declared
  correct inRange(..) predicates for overflow check semantics
  fix creating of branches for overflow checking
@mattulbrich
Copy link
Member

I mark this "Work in progress" since a number of checks fail. Please undo if/when ready to review.

@mattulbrich mattulbrich marked this pull request as draft February 20, 2025 13:37
@wadoon
Copy link
Member Author

wadoon commented Feb 23, 2025

This is a typical example that KeY development is dysfunctional.

It was green, and nobody reviewed it, after repeatedly merging the main branch into it, it became red.

I do not see any reason to invest further time into it, only to see the branch rot away until the next review.

@wadoon wadoon marked this pull request as ready for review February 23, 2025 13:24
@WolframPfeifer
Copy link
Member

This is a typical example that KeY development is dysfunctional.

It was green, and nobody reviewed it, after repeatedly merging the main branch into it, it became red.

I do not see any reason to invest further time into it, only to see the branch rot away until the next review.

I reviewed it a long time ago, had some fundamental questions, remarks, and pointed out some bugs (#3022 (review)). In my opinion, this is my job as a reviewer. Until now, I did not get any answer to those (see #3022 (review) and #3022 (comment)), so I do not consider it my job to do another review until my points are answered/resolved.

I think that the job of the developer is to provide a working, tested and high quality PR (at least with a clear concept, a description with a list of the changes it contains, good documentation, passing CI tests). Only having "green tests" is not sufficient ...

And if my questions have been resolved in the meantime, I would expect at least a comment answering them, not just a re-request of a review ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JML Parser JML (Semantics) RFC "Request for comments" is the appeal for making and expressing your opinion on a topic.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants