Skip to content

Commit 07dce2b

Browse files
authored
Merge pull request #742 from viperproject/meilers_axiom_instantiation
Fixing Silicon issue #753
2 parents 65ec341 + 34f6372 commit 07dce2b

4 files changed

Lines changed: 111 additions & 4 deletions

File tree

src/main/scala/viper/silver/ast/utility/DomainInstances.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,13 @@ object DomainInstances {
168168
case Some(ps) =>
169169
ps.flatMap(f = pair => {
170170
// assert(dfa.funcname==pair._1.funcname)
171-
val d2 = p.findDomain(pair._2.domainName)
171+
val d2 = p.findDomain(dfa.domainName)
172172
val tvs = d2.typVars
173-
tryUnifyWithDefault(tvs, tvs.map(pair._1.typVarMap.getOrElse(_, Program.defaultType)), tvs.map(dfa.typVarMap.getOrElse(_, Program.defaultType))) match {
174-
case Some(ts) => Set[Type](DomainType(pair._2.domainName, ts)(tvs))
173+
val axDom = p.findDomain(pair._2.domainName)
174+
val axTvs = axDom.typVars
175+
tryUnifyWithDefault(axTvs, tvs.map(pair._1.typVarMap.get(_).get), tvs.map(dfa.typVarMap.get(_).get)) match {
176+
case Some(ts) =>
177+
Set[Type](DomainType(pair._2.domainName, ts)(axTvs))
175178
case None => Set[Type]()
176179
}
177180
}).toSet
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
5+
domain $domain$to_int {
6+
7+
function to_int(to_int1: Perm): Int interpretation "to_int"
8+
}
9+
10+
function round(x: Perm): Perm
11+
decreases
12+
ensures x == 3/1 ==> result == 3/2
13+
//:: ExpectedOutput(postcondition.violated:assertion.false)
14+
ensures result == to_int(x) / 1
15+
{
16+
to_int(x) / 2
17+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
5+
domain Val {}
6+
7+
domain WellFoundedOrder[T] {
8+
9+
function decreasing(arg1: T, arg2: T): Bool
10+
11+
function bounded(arg1: T): Bool
12+
}
13+
14+
domain List[V] {
15+
16+
function Nil(): List[V]
17+
18+
function Cons(value: V, tail: List[V]): List[V]
19+
20+
function get_List_value(t: List[V]): V
21+
22+
function get_List_tail(t: List[V]): List[V]
23+
24+
function List_tag(t: List[V]): Int
25+
26+
axiom {
27+
(forall value: V, tail: List[V] ::
28+
{ (Cons(value, tail): List[V]) }
29+
value == (get_List_value((Cons(value, tail): List[V])): V))
30+
}
31+
32+
axiom {
33+
(forall value: V, tail: List[V] ::
34+
{ (Cons(value, tail): List[V]) }
35+
tail == (get_List_tail((Cons(value, tail): List[V])): List[V]))
36+
}
37+
38+
axiom {
39+
(List_tag((Nil(): List[V])): Int) == 1
40+
}
41+
42+
axiom {
43+
(forall value: V, tail: List[V] ::
44+
{ (Cons(value, tail): List[V]) }
45+
(List_tag((Cons(value, tail): List[V])): Int) == 0)
46+
}
47+
48+
axiom {
49+
(forall t: List[V] ::
50+
{ (List_tag(t): Int) }
51+
{ (get_List_value(t): V) }
52+
{ (get_List_tail(t): List[V]) }
53+
(List_tag(t) == 1 && t == (Nil(): List[V])) ||
54+
(List_tag(t) == 0 && exists v: V, l: List[V] :: t == Cons(v, l))
55+
//(t == (Cons((get_List_value(t): V), (get_List_tail(t): List[V])): List[V]))
56+
)
57+
}
58+
}
59+
60+
domain ListWellFoundedOrder[V] {
61+
62+
axiom {
63+
(bounded((Nil(): List[V])): Bool)
64+
}
65+
66+
axiom {
67+
(forall value: V, tail: List[V] ::
68+
{ (Cons(value, tail): List[V]) }
69+
(bounded((Cons(value, tail): List[V])): Bool) &&
70+
(decreasing(tail, (Cons(value, tail): List[V])): Bool))
71+
}
72+
}
73+
74+
// decreases l
75+
function len(l: List[Val]): Int
76+
ensures result >= 0
77+
{
78+
((List_tag(l): Int) == 1 ? 0 : 1 + len((get_List_tail(l): List[Val])))
79+
}
80+
81+
// decreases l
82+
method len_termination_proof(l: List[Val])
83+
{
84+
if ((List_tag(l): Int) == 1) {
85+
} else {
86+
assert (decreasing((get_List_tail(l): List[Val]), old(l)): Bool) &&
87+
(bounded(old(l)): Bool)}
88+
}

src/test/resources/termination/functions/basic/allTypes.vpr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ function numberOfUsers(seq:Seq[Bool]): Int
8585
decreases seq
8686
{
8787
|seq| == 0 ? 0 :
88-
//:: UnexpectedOutput(termination.failed:tuple.false, /silicon/issue/300/)
8988
seq[0] ? 1 + numberOfUsers(seq[1..]) : numberOfUsers(seq[1..])
9089
}
9190

0 commit comments

Comments
 (0)