-
Notifications
You must be signed in to change notification settings - Fork 261
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
fix: Correct null-related checking of type bounds, and add axioms #5738
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` // type axiom for trait parent: E extends RefTrait axiom (forall $o: ref :: { $Is($o, Tclass._module.E?()) } $o != null && $Is($o, Tclass._module.E?()) // CHANGE: remove o != null ==> $Is($o, Tclass._module.RefTrait())); // CHANGE: RefTrait --> RefTrait? // allocation axiom for trait parent: E extends RefTrait axiom (forall $o: ref, $heap: Heap :: { $IsAlloc($o, Tclass._module.E?(), $heap) } $o != null && $IsAlloc($o, Tclass._module.E?(), $heap) // CHANGE: like above ==> $IsAlloc($o, Tclass._module.RefTrait(), $heap)); // CHANGE: like above // type axiom for trait parent: E extends GeneralTrait axiom (forall $o: ref :: { $Is($o, Tclass._module.E?()) } // CHANGE: replace E? with E $o != null && $Is($o, Tclass._module.E?()) // CHANGE: remove o != null, and replace E? with E ==> $IsBox($Box($o), Tclass._module.GeneralTrait())); // allocation axiom for trait parent: E extends GeneralTrait axiom (forall $o: ref, $heap: Heap :: { $IsAlloc($o, Tclass._module.E?(), $heap) } // CHANGE: like above $o != null && $IsAlloc($o, Tclass._module.E?(), $heap) // CHANGE: like above ==> $IsAllocBox($Box($o), Tclass._module.GeneralTrait(), $heap)); ```
… type-bounds check
# Conflicts: # Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/SubsetTypes.dfy.expect # Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny1/SchorrWaite.dfy.expect # Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny1/SchorrWaite.dfy.refresh.expect
# Conflicts: # Source/DafnyPipeline.Test/expectedProverLog.smt2 # Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny1/SchorrWaite.dfy.expect # Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny1/SchorrWaite.dfy.refresh.expect
atomb
approved these changes
Sep 5, 2024
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.
This all looks reasonable. And it's thoroughly tested!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5719
Fixes #5726
Description
This PR solves both soundness and incompleteness problems related to when a nullable type extends a trait.
To fix the soundness issue (#5726), the resolver was changed to check type bounds after type inference. For example, the resolver now generates an error if a nullable reference type
E?
is used as a type argument with a boundB
that is not a nullable reference type. Note that this check cannot be done completely during pre-type inference, because pre-types don't distinguish betweenE?
andE
; therefore, the definitive check for this is done in the same place where type arguments are checked to have the specified type characteristics ((==)
,(0)
, ...).To fix the incompleteness issues (#5719), changes were made in the generated axioms. To describe them, consider the following types:
Previously, this generated the following type axioms (and analogous allocation axioms for
$IsAlloc
):The new axioms say:
To make the first of these axioms still be able to connect
E?
withRefTrait
, the axiom that connects a nullable typeX?
with its non-null reference typeX
was extended with an additional matching pattern:The property that a type parameter
T
with a boundB
has is (elsewhere) given as a quantification over boxes. To make this property known of a type that extends a trait, the following axioms were added:These are essentially box versions of the type axioms above.
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.