Skip to content

Simpler sort syntax - #3957

Open
mattulbrich wants to merge 10 commits into
mainfrom
simplerSortSyntax
Open

Simpler sort syntax#3957
mattulbrich wants to merge 10 commits into
mainfrom
simplerSortSyntax

Conversation

@mattulbrich

@mattulbrich mattulbrich commented Aug 7, 2026

Copy link
Copy Markdown
Member

Intended Change

This PR suggests changing the type parameter syntax from T<[X]> to T<X> for readability reasons.

(The original syntax was suggested to avoid parser problems wrt implicit identifiers like <init>.)

Plan

  • Changed the lexer and parser
  • Repaired >= and >>
  • Adapting the toString methods
  • Adapting many, many references in examples and test cases

Type of pull request

  • Refactoring (behaviour should not change or only minimally change)

Ensuring quality

  • yes: I made sure that introduced/changed code is well documented (javadoc and inline comments).
  • n/a: I made sure that new/changed end-user features are well documented (https://github.com/KeYProject/key-docs).
  • yes: I added new test case(s) for new functionality.
  • no: I have checked that runtime performance has not deteriorated.

Additional information and contact(s)

The contributions within this pull request are licensed under GPLv2 (only) for inclusion in KeY.

@mattulbrich mattulbrich self-assigned this Aug 7, 2026
@mattulbrich mattulbrich added KeY Parser Feature New feature or request 🛠 Maintenance Code quality and related things w/o functional changes labels Aug 7, 2026
@WolframPfeifer

WolframPfeifer commented Aug 7, 2026

Copy link
Copy Markdown
Member

I really like this feature. However, we should consider the following (motivated by experience with VeriFast, compare also to verifast/verifast#271):

Assuming we want to lift this syntax into JML (for instance for ghost fields and model methods), it might be unexpected for the user that the List<T> in Java is quite different from \seq<S> in JML. The upper bound of T is Object, while the upper bound of S would be any.

A problematic example would be (not real JML for the sequence singleton, access and concat):

class List<T> {
  //@ ghost \seq<T> absVal;

  //@ ensures absVal == \old(absVal) ++ (t);  // <-- This is ok.
  void add(T t) {
   ..
  }

  //@ ensures \result == absVal[i];      // <-- Probably still ok here ...
  //@ assignable \nothing;
  T get(int i) {
   ..
  }
}

@WolframPfeifer

Copy link
Copy Markdown
Member

Actually, in the example above it might not be a problem, because T in the ghost field is inside the scope of the class, so it is actually the same T here.

@Drodt

Drodt commented Aug 7, 2026

Copy link
Copy Markdown
Member

The consensus is that this PR should be merged once ready.

@wadoon

wadoon commented Aug 7, 2026

Copy link
Copy Markdown
Member

Wolfram's point was already discussed some time ago, where we discovered that the implicit upper bound between Java (java.lang.Object) and JML (in KeY any) is different.

Let us assume the following:

class Box<T extends ?>{ 
   //@ \dl_seq<T> s;

   //@ ...
   //@ <Q extends ?> model \dl_seq<T> t();
}

The following is valid T <: Object but not Q <: Object.

We discussed the introduction of additional type parameter parentheses. But maybe playing around with JML/Java syntax could avoid the confusion:

  1. Java/JML Syntax: Box<T extends ?> is always Object-bound
  2. A logical bound type must be stated explicitly: Box<T extends \dl_any> or also using the typeof operator: Box<T <: \dl_any>.

@unp1
unp1 force-pushed the simplerSortSyntax branch from 2cb8d1c to a17280b Compare August 8, 2026 17:28
@mattulbrich
mattulbrich marked this pull request as ready for review August 9, 2026 00:32
@mattulbrich mattulbrich added the Review Request Waiting for review label Aug 9, 2026
@mattulbrich

Copy link
Copy Markdown
Member Author

Thanks Richard for repairing the term hash scheme such that all examples run through.

I have tried to adapt the proof, but the automation happens to do things in a slightly different order and then rewriting can no longer establish the needed statements. I can close the proof manually with a few rule applications that contradict the then natural order of the rules, but this is quite difficult to capture in a proof script or lemma.

This case shows that (as discussed only yesterday), our equality treatment is very brittle.

Thanks again, Richard!

The PR is ready now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature or request KeY Parser 🛠 Maintenance Code quality and related things w/o functional changes Review Request Waiting for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants