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

Hackeython: ADTs in JML #3427

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Hackeython: ADTs in JML #3427

wants to merge 4 commits into from

Conversation

Drodt
Copy link
Member

@Drodt Drodt commented Feb 22, 2024

Intended Change

Based on #3420. Changes the JML pareser to accept definitions of ADTs. Datatypes have a list of constructors separated by |, and a body of functions.

class Test {
	/*@ datatype List {
	  @ 	Nil()
	  @	| Cons(\any head, List tail);
	  @
	  @ 	int size() {
	  @		return 0;
	  @ 	}
	  @ }
	  @*/
}

Currently, ADTs can only be defined on class-level, not inside methods or outside of classes.

There also is no semantics for these ADTs. KeY simply ignores them. Ideally, we want to use the defined types and functions in specification and translate them to KeY ADTs.

We also want to use the new Java switch expressions to allow pattern matching on ADTs, i.e,:

switch (list) {
  case Nil -> 0;
  case Cons(_, xs) -> 1 + xs.size();
}

Open questions are:

  • How are JML ADTs translated to KeY?
  • How are switch expressions with pattern matching translated?
  • Can we define a shorthand infix notation for ADT function, e.g., l1 + l2 for l1.append(l2)?
  • How do we resolve ADT function calls in specification?
  • What happens if we already have a List class/interface?

OpenJML has a similar concept of ADTs and pattern matching. For demonstration, there is a list example.

Type of pull request

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (behaviour should not change or only minimally change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • There are changes to the (Java) code
  • There are changes to the taclet rule base
  • There are changes to the deployment/CI infrastructure (gradle, github, ...)
  • Other: Changes to ANLTR grammars

Ensuring quality

  • I made sure that introduced/changed code is well documented (javadoc and inline comments).
  • I made sure that new/changed end-user features are well documented (https://github.com/KeYProject/key-docs).
  • I added new test case(s) for new functionality.
  • I have tested the feature as follows: ...
  • 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.

@Drodt Drodt added JML Parser Feature New feature or request RFC "Request for comments" is the appeal for making and expressing your opinion on a topic. HacKeYthon Candidate Issue for HacKeYthon '24 labels Feb 22, 2024
Copy link

codecov bot commented Feb 22, 2024

Codecov Report

Attention: 71 lines in your changes are missing coverage. Please review.

Comparison is base (1fb0c10) 37.77% compared to head (c6bc033) 37.75%.

Files Patch % Lines
...e/uka/ilkd/key/nparser/builder/TacletPBuilder.java 0.00% 56 Missing ⚠️
.../key/nparser/builder/FunctionPredicateBuilder.java 0.00% 14 Missing ⚠️
...a/ilkd/key/nparser/builder/DeclarationBuilder.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3427      +/-   ##
============================================
- Coverage     37.77%   37.75%   -0.03%     
+ Complexity    17031    17030       -1     
============================================
  Files          2076     2076              
  Lines        126950   127017      +67     
  Branches      21381    21388       +7     
============================================
- Hits          47952    47951       -1     
- Misses        73092    73159      +67     
- Partials       5906     5907       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wadoon
Copy link
Member

wadoon commented Feb 22, 2024

One of the primary todos might be to prepare a proposal for JMLref.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request HacKeYthon Candidate Issue for HacKeYthon '24 JML Parser 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.

2 participants