-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improved treatment of final fields #3495
base: main
Are you sure you want to change the base?
Conversation
Is #3189 now obsolete? Interestingly, |
This is the commits from back then merged onto the modern main.
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.
thanks to Richard for hinting at the needed infrastructure
9fb4182
to
9bae13f
Compare
The last commits add sound special treatment for constructors. |
# Conflicts: # key.core/src/test/resources/de/uka/ilkd/key/nparser/taclets.old.txt
a final field reference in a created object points to null or to a created object.
08b0083
to
da84fda
Compare
it was not wrong before but not confluent. Failed the case vstte10_05_Queue/AmortizedQueue_AmortizedQueue.key
2ccdb0f
to
27f1584
Compare
8db48a8
to
022ce5a
Compare
022ce5a
to
e921c72
Compare
Regarding the effectiveness: Julian has shown that the IPSO case study heavily relied on the feature. Regarding the efficiency: The mean time per rule application is .74 ms compared to .76 ms on the current master. No regression observed. |
There was a problem hiding this 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!
@@ -232,6 +232,24 @@ | |||
noRestriction | |||
}; | |||
|
|||
/*! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that this documentation is not shown when looking at the taclet settings in the option dialog. Apparently there is an xml file, where basically the same documentation is present. We really should unify this. But I don't want to block this, and prefer a new PR instead ...
\heuristics(simplify_enlarging) | ||
}; | ||
|
||
referencedObjectIsCreatedRighFinalEQ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small typo:
referencedObjectIsCreatedRighFinalEQ { | |
referencedObjectIsCreatedRightFinalEQ { |
// We know this holds because of isPOSupported: | ||
FunctionalOperationContractPO fpo = (FunctionalOperationContractPO) abstractPO; | ||
IProgramMethod iconstructor = fpo.getProgramMethod(); | ||
assert iconstructor instanceof ProgramMethod : "Contracts cannot have schema "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the message of the assertion here.
protected static boolean isJavaFieldConstant(Term fieldTerm, HeapLDT heapLDT, | ||
Services services) { | ||
try { | ||
getJavaFieldConstant(fieldTerm, heapLDT, services); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code here is correct, but really looks a bit weird (calling a getter, ignoring the result, and then returning true).
* Constructor calls must not leak 'this' to the called constructor. | ||
*/ | ||
private void validateConstructorReference(ConstructorReference methodReference) { | ||
// TODO We have to make sure that on non-static subclass is instantiated here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open TODO? Honestly I don't understand it ...
@@ -1566,6 +1567,26 @@ public void translateSetStatement(final SetStatement statement, final IProgramMe | |||
new SpecificationRepository.JmlStatementSpec(pv, ImmutableList.of(assignee, value))); | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I correct that this means that the feature works for ghost fields in exactly the same way as for Java fields (that is another edge case I did not think of so far)?
@@ -22,6 +22,9 @@ | |||
// default value for a field | |||
alpha alpha::defaultValue; | |||
|
|||
// reading from final attributes (corr. to select for non-final fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean by that comment. What do you mean by "correct" here? What happens if you have a non-final field f
and a for example the term int::final(o, f)
? I would suppose that you can not resolve it further, but it is clearly a term that could occur in the sequent ...
|
||
// Without that created-check, it is not consistent. | ||
\assumes(wellFormed(h), | ||
boolean::select(h, o, java.lang.Object::<created>) = TRUE ==>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just thought about whether we could model java.lang.Object::<created>
itself as a final field ...
@@ -3632,10 +3805,11 @@ | |||
\displayname "active_attribute_access" | |||
}; | |||
|
|||
// TODO 2 variants with different taclet options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open TODO?
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
The major challenges include
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
The following new items showed up:
static final
fields are a challenge since they need double special treatment in parsing and prettyprintingType of pull request
The plan is to have a taclet otion to fall back to old behaviour.
Ensuring quality
To do:
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.