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

Example of abstraction using methods with ???. Needs some systematic checks for missing implementations #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package modularity

import stainless.collection._
import stainless.lang._
import stainless.annotation._

object MutableSetImplObj:

@mutable
final case class MutableSetImpl[V](private var list: List[V]) extends MutableSetObj.MutableSet[V]:
require(ListSpecs.noDuplicate(list))

override def toSet = list.content

override def contains(v: V): Boolean = list.contains(v)

override def add(v: V): Unit =
if !list.contains(v) then
list = v :: list
else
()

override def remove(v: V): Unit =
list = removeElement(list, v)

private def removeElement(l: List[V], v: V): List[V] = {
require(ListSpecs.noDuplicate(l))
l match
case Nil() => Nil[V]()
case Cons(h, t) if h == v => t
case Cons(h, t) => Cons(h, removeElement(t, v))
}.ensuring(res =>
!res.contains(v)
&& ListSpecs.noDuplicate(res)
&& res.content == l.content -- Set(v)
&& (if l.contains(v) then res.size == l.size - 1 else res.size == l.size)
)

override def size: BigInt =
list.size

end MutableSetImplObj
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package modularity


import stainless.collection._
import stainless.lang._
import stainless.annotation._


object MutableSetObj:
@mutable
trait MutableSet[V]:
@pure
def toSet: Set[V] = {
??? : Set[V]
}

@pure
def contains(v: V): Boolean = {
??? : Boolean
} ensuring(_ == toSet.contains(v))

def add(v: V): Unit = {
??? : Unit
} ensuring(() =>
toSet == old(this).toSet + v &&
(if old(this).contains(v) then
size == old(this).size
else
size == old(this).size + 1))

def remove(v: V): Unit = {
??? : Unit
} ensuring(() =>
toSet == old(this).toSet - v &&
(if old(this).contains(v) then
size == old(this).size - 1
else
size == old(this).size))

@pure
def size: BigInt = {
??? : BigInt
} ensuring(_ >= 0)

end MutableSet

def test =
val ms = new MutableSet[Int] {}
true

end MutableSetObj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# The settings below correspond to the various
# options listed by `stainless --help`

vc-cache = true
# debug = ["verification", "smt"]
timeout = 15
check-models = false
print-ids = false
print-types = false
batched = true
strict-arithmetic = false
solvers = "smt-cvc5,smt-z3,smt-cvc4"
check-measures = yes
infer-measures = true
simplifier = "ol"