summaryrefslogtreecommitdiff
path: root/Test/irondafny0/xrefine3.dfy
blob: 86dbd957682ab13125f3240758c7c472a2ec688f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// RUN: %dafny /ironDafny /compile:3 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

abstract module AlphaSpec {
    type Alpha

    predicate IsValid(a:Alpha)

    method Init() returns (a:Alpha)
        ensures IsValid(a);
}

abstract module BetaSpec {
    type Beta
    import A : AlphaSpec

    predicate IsValid(b:Beta)

    method Init(ays:seq<A.Alpha>) returns (b:Beta)
        requires forall i :: 0 <= i < |ays| ==> A.IsValid(ays[i]);
        ensures IsValid(b);
}

module AlphaImpl exclusively refines AlphaSpec {
    type Alpha = bool    

    predicate IsValid(a:Alpha) { 
        a 
    }

    method Init() returns (a:Alpha)
        ensures IsValid(a);
    {
        a := true;
    }
}

module BetaImpl exclusively refines BetaSpec {
    import A = AlphaImpl
    type Beta = seq<A.Alpha>

    predicate IsValid(b:Beta) {
        forall i :: 0 <= i < |b| ==> A.IsValid(b[i])
    }

    method Init(ays:seq<A.Alpha>) returns (b:Beta) {
        b := ays;
    }
}

abstract module MainSpec {
    import A : AlphaSpec
    import B : BetaSpec

    method Main()
    {
        var a := A.Init();
        var ays := [a, a];
        assert forall i :: 0 <= i < |ays| ==> A.IsValid(ays[i]);
        var b := B.Init(ays);
        print "o hai!\n";
    }
}

module MainImpl exclusively refines MainSpec {
    import B = BetaImpl
    import A = AlphaImpl
}