Skip to content

Improved treatment of final fields#3495

Merged
WolframPfeifer merged 36 commits intoKeYProject:mainfrom
mattulbrich:newFinalHeaps
Mar 7, 2025
Merged

Improved treatment of final fields#3495
WolframPfeifer merged 36 commits intoKeYProject:mainfrom
mattulbrich:newFinalHeaps

Conversation

@mattulbrich
Copy link
Copy Markdown
Member

@mattulbrich mattulbrich commented Jul 6, 2024

Intended Change

Final fields cannot change their value after a single assignment in the constructor. In the current KeY logic, final fields are treated like normal fields stored on the heap. This is highly inefficient since heap assignments cannot have an impact on final fields at all.

The plan is hence to access final fields using a function of their own that does not depend on the heap, unlike other fields

T::select(Heap, Object, Field)   // for non-final fields
T::final(Object, Field)  // for final fields

The major challenges include

  • adapting reading of final fields in modalities
  • adapting accessing final fields in JML
  • handling constructors: they are allowed to write.

Writing must somehow be restricted since any modality could write to final fields and thus compromise proofs if thus different inconsistent values for final fields are around on a sequent.

Plan

  • Add functions for finals, add a taclet option
  • Implement rules that act upon those taclet options
  • Implement special treatment for constructors
  • Test effectiveness
  • Code cleanup
  • Document the changes

The following new items showed up:

  • Deal with prettyprinting of final fields using select. Currently o.f is the prettyprinting for both accesses.
  • Deal with parsing of final fields in JavaDL. o.f means something different now ...
  • static final fields are a challenge since they need double special treatment in parsing and prettyprinting

Type of pull request

  • Breaking change (feature that cause existing functionality to change)

The plan is to have a taclet otion to fall back to old behaviour.

Ensuring quality

To do:

  • 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 checked that runtime performance has not deteriorated.

Additional information and contact(s)

It is the modernised version of #3189.

@WolframPfeifer @wadoon

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

@mattulbrich mattulbrich self-assigned this Jul 6, 2024
@wadoon
Copy link
Copy Markdown
Member

wadoon commented Jul 6, 2024

Is #3189 now obsolete?

Interestingly, final is not so final on bytecode level.

@mattulbrich
Copy link
Copy Markdown
Member Author

Is #3189 now obsolete?

This is the commits from back then merged onto the modern main.

Interestingly, final is not so final on bytecode level.

There are a few source code level things that get lost on byte code. Also generics. Sometimes private fields are not so private in byte code. We operate on source code level and assume that all code is compiler-conformant.

... revert to heap updates in such cases.
@mattulbrich mattulbrich marked this pull request as draft July 6, 2024 21:33
@mattulbrich
Copy link
Copy Markdown
Member Author

The last commits add sound special treatment for constructors.

@mattulbrich mattulbrich marked this pull request as ready for review February 23, 2025 22:26
@mattulbrich mattulbrich added the Review Request Waiting for review label Feb 23, 2025
Copy link
Copy Markdown
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.

Nice feature, while reviewing it everything worked as expected. I have a few minor questions/remarks that should be resolved, but overall I think it is very well written and also nicely documented in code. Thanks!

@mattulbrich mattulbrich added Reviewer Feedback Feedback from the review needs to be addressed and removed Review Request Waiting for review labels Feb 27, 2025
@mattulbrich mattulbrich added Review Request Waiting for review and removed Reviewer Feedback Feedback from the review needs to be addressed labels Mar 5, 2025
Copy link
Copy Markdown
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 for resolving all of my points!

Regarding documentation: I compiled a list of questions/possible points that would make sense to describe in our manual (KeYProject/key-docs#44). Let's try not to forget about it ...

@WolframPfeifer WolframPfeifer enabled auto-merge March 7, 2025 11:19
@WolframPfeifer WolframPfeifer added Feature New feature or request Calculus Java Pull requests that update Java code and removed Review Request Waiting for review labels Mar 7, 2025
@WolframPfeifer WolframPfeifer added this pull request to the merge queue Mar 7, 2025
Merged via the queue into KeYProject:main with commit c2d9f78 Mar 7, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Calculus Feature New feature or request Java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants