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

Failure in proving subtyping on recursive error implementations #702

Open
jcp19 opened this issue Nov 2, 2023 · 0 comments
Open

Failure in proving subtyping on recursive error implementations #702

jcp19 opened this issue Nov 2, 2023 · 0 comments

Comments

@jcp19
Copy link
Contributor

jcp19 commented Nov 2, 2023

TODO: elaborate

package p

type scmpError struct {
	TypeCode int
	Cause    error
}

preserves e.ErrorMem()
ensures   e.Size() == old(e.Size())
decreases e.Size()
func (e scmpError) Error() string /*{
	unfold e.ErrorMem()
	defer fold e.ErrorMem()
	res := newErr(e)
    assume res.Size() == 1 + e.Cause.Size()
	return res.Error()
}*/

preserves e != nil && e.ErrorMem()
ensures   res != nil && res.ErrorMem()
ensures   e.Size() == old(e.Size())
ensures   res.Size() == 1 + e.Size()
decreases _
func newErr(e error) (res error)

pred (err scmpError) ErrorMem() {
	err.Cause != nil ==> err.Cause.ErrorMem()
}

ghost
pure
requires  acc(err.ErrorMem(), _)
decreases err.Size()
func (err scmpError) IsDuplicableMem() bool {
	return unfolding acc(err.ErrorMem(), _) in
		err.Cause == nil || err.Cause.IsDuplicableMem()
}

ghost
preserves err.ErrorMem()
ensures   err.IsDuplicableMem() ==> err.ErrorMem()
ensures   err.Size() == old(err.Size())
decreases err.Size()
func (err scmpError) Duplicate() /*{
	if err.IsDuplicableMem() {
		unfold err.ErrorMem()
        if err.Cause != nil {
            assert err.Cause.ErrorMem()
            assert err.Cause.IsDuplicableMem()
		    err.Cause.Duplicate()
		    assert err.Cause.ErrorMem() && err.Cause.ErrorMem()
        }
		fold err.ErrorMem()
		fold err.ErrorMem()
	}
}*/

ghost
requires acc(e.ErrorMem(), _)
ensures  0 < res
pure func (e scmpError) Size() (res int) {
	return 2 + (unfolding acc(e.ErrorMem(), _) in
        e.Cause == nil ?
            0 : 
		    (let _ := Asserting(0 <= e.Cause.Size()) in e.Cause.Size()))
}

ghost
pure
requires b
decreases _
func Asserting(b bool) bool

scmpError implements error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant