3807
|
1 |
(*
|
|
2 |
File: MemoryImplementation.thy
|
|
3 |
Author: Stephan Merz
|
|
4 |
Copyright: 1997 University of Munich
|
|
5 |
|
|
6 |
Theory Name: MemoryImplementation
|
|
7 |
Logic Image: TLA
|
|
8 |
|
|
9 |
RPC-Memory example: Memory implementation
|
|
10 |
*)
|
|
11 |
|
|
12 |
MemoryImplementation = Memory + RPC + MemClerk + MIParameters +
|
|
13 |
|
|
14 |
types
|
|
15 |
histType = "(PrIds => histState) stfun" (* the type of the history variable *)
|
|
16 |
|
|
17 |
consts
|
|
18 |
(* the specification *)
|
|
19 |
(* channel (external) *)
|
|
20 |
memCh :: "memChType"
|
|
21 |
(* internal variables *)
|
|
22 |
mem :: "memType"
|
|
23 |
resbar :: "histType => resType" (* defined by refinement mapping *)
|
|
24 |
|
|
25 |
(* the state variables of the implementation *)
|
|
26 |
(* channels *)
|
|
27 |
(* same interface channel memCh *)
|
|
28 |
crCh :: "rpcSndChType"
|
|
29 |
rmCh :: "rpcRcvChType"
|
|
30 |
(* internal variables *)
|
|
31 |
(* identity refinement mapping for mem -- simply reused *)
|
|
32 |
rst :: "rpcStType"
|
|
33 |
cst :: "mClkStType"
|
|
34 |
ires :: "resType"
|
|
35 |
(* the history variable : not defined as a constant
|
|
36 |
rmhist :: "histType"
|
|
37 |
*)
|
|
38 |
|
|
39 |
(* the environment action *)
|
|
40 |
ENext :: "PrIds => action"
|
|
41 |
|
|
42 |
(* specification of the history variable *)
|
|
43 |
HInit :: "histType => PrIds => stpred"
|
|
44 |
HNext :: "histType => PrIds => action"
|
|
45 |
HistP :: "histType => PrIds => temporal"
|
|
46 |
Hist :: "histType => temporal"
|
|
47 |
|
|
48 |
(* the implementation *)
|
|
49 |
ImpInit :: "PrIds => stpred"
|
|
50 |
ImpNext :: "PrIds => action"
|
|
51 |
ImpLive :: "PrIds => temporal"
|
|
52 |
IPImp :: "PrIds => temporal"
|
|
53 |
Implementation :: "temporal"
|
|
54 |
ImpInv :: "histType => PrIds => stpred"
|
|
55 |
|
|
56 |
(* tuples of state functions changed by the various components *)
|
|
57 |
e :: "PrIds => (bit * memArgType) stfun"
|
|
58 |
c :: "PrIds => (mClkState * (bit * Vals) * (bit * rpcArgType)) stfun"
|
|
59 |
r :: "PrIds => (rpcState * (bit * Vals) * (bit * memArgType)) stfun"
|
|
60 |
m :: "PrIds => ((bit * Vals) * Vals) stfun"
|
|
61 |
|
|
62 |
(* the predicate S describes the states of the implementation.
|
|
63 |
slight simplification: two "histState" parameters instead of a (one- or
|
|
64 |
two-element) set. *)
|
|
65 |
S :: "histType => bool => bool => bool => mClkState => rpcState => histState => histState => PrIds => stpred"
|
|
66 |
|
|
67 |
(* predicates S1 -- S6 define special instances of S *)
|
|
68 |
S1 :: "histType => PrIds => stpred"
|
|
69 |
S2 :: "histType => PrIds => stpred"
|
|
70 |
S3 :: "histType => PrIds => stpred"
|
|
71 |
S4 :: "histType => PrIds => stpred"
|
|
72 |
S5 :: "histType => PrIds => stpred"
|
|
73 |
S6 :: "histType => PrIds => stpred"
|
|
74 |
|
|
75 |
(* auxiliary predicates *)
|
|
76 |
MVOKBARF :: "Vals => bool"
|
|
77 |
MVOKBA :: "Vals => bool"
|
|
78 |
MVNROKBA :: "Vals => bool"
|
|
79 |
|
|
80 |
rules
|
|
81 |
MVOKBARF_def "MVOKBARF v == (MemVal v) | (v = OK) | (v = BadArg) | (v = RPCFailure)"
|
|
82 |
MVOKBA_def "MVOKBA v == (MemVal v) | (v = OK) | (v = BadArg)"
|
|
83 |
MVNROKBA_def "MVNROKBA v == (MemVal v) | (v = NotAResult) | (v = OK) | (v = BadArg)"
|
|
84 |
|
|
85 |
(* the "base" variables: everything except resbar and hist (for any index) *)
|
|
86 |
MI_base "base_var <caller memCh @ p, rtrner memCh @ p,
|
|
87 |
caller crCh @ p, rtrner crCh @ p,
|
|
88 |
caller rmCh @ p, rtrner rmCh @ p,
|
|
89 |
rst@p, cst@p, mem@l, ires@p>"
|
|
90 |
|
|
91 |
(* Environment's next-state relation *)
|
|
92 |
ENext_def "ENext p == REX l. #(MemLoc l) .& Call memCh p (#(Inl (read,l)))"
|
|
93 |
|
|
94 |
(* Specification of the history variable used in the proof *)
|
|
95 |
HInit_def "$(HInit rmhist p) .= ($(rmhist@p) .= #histA)"
|
|
96 |
HNext_def "HNext rmhist p ==
|
|
97 |
(rmhist@p)$ .=
|
|
98 |
(.if (MemReturn rmCh ires p .| RPCFail crCh rmCh rst p)
|
|
99 |
.then #histB
|
|
100 |
.else .if (MClkReply memCh crCh cst p)
|
|
101 |
.then #histA
|
|
102 |
.else $(rmhist@p))"
|
|
103 |
HistP_def "HistP rmhist p ==
|
|
104 |
Init($(HInit rmhist p))
|
|
105 |
.& [][HNext rmhist p]_<c p,r p,m p, rmhist@p>"
|
|
106 |
Hist_def "Hist rmhist == RALL p. HistP rmhist p"
|
|
107 |
|
|
108 |
(* definitions of e,c,r,m *)
|
|
109 |
e_def "e p == caller memCh @ p"
|
|
110 |
c_def "c p == <cst@p, rtrner memCh @ p, caller crCh @ p>"
|
|
111 |
r_def "r p == <rst@p, rtrner crCh @ p, caller rmCh @ p>"
|
|
112 |
m_def "m p == <rtrner rmCh @ p, ires@p>"
|
|
113 |
|
|
114 |
(* definition of the implementation (without the history variable) *)
|
|
115 |
IPImp_def "IPImp p == Init(.~ $(Calling memCh p)) .& [][ENext p]_(e p)
|
|
116 |
.& MClkIPSpec memCh crCh cst p
|
|
117 |
.& RPCIPSpec crCh rmCh rst p
|
|
118 |
.& RPSpec rmCh mem ires p
|
|
119 |
.& (RALL l. #(MemLoc l) .-> MSpec rmCh mem ires l)"
|
|
120 |
|
|
121 |
ImpInit_def "$(ImpInit p) .= ( .~ $(Calling memCh p) \
|
|
122 |
\ .& $(MClkInit crCh cst p) \
|
|
123 |
\ .& $(RPCInit rmCh rst p) \
|
|
124 |
\ .& $(PInit ires p))"
|
|
125 |
|
|
126 |
ImpNext_def "ImpNext p == [ENext p]_(e p)
|
|
127 |
.& [MClkNext memCh crCh cst p]_(c p)
|
|
128 |
.& [RPCNext crCh rmCh rst p]_(r p)
|
|
129 |
.& [RNext rmCh mem ires p]_(m p)"
|
|
130 |
|
|
131 |
ImpLive_def "ImpLive p == WF(MClkFwd memCh crCh cst p)_(c p)
|
|
132 |
.& SF(MClkReply memCh crCh cst p)_(c p)
|
|
133 |
.& WF(RPCNext crCh rmCh rst p)_(r p)
|
|
134 |
.& WF(RNext rmCh mem ires p)_(m p)
|
|
135 |
.& WF(MemReturn rmCh ires p)_(m p)"
|
|
136 |
|
|
137 |
Impl_def "Implementation == (RALL p. Init(.~ $(Calling memCh p)) .& [][ENext p]_(e p))
|
|
138 |
.& MClkISpec memCh crCh cst
|
|
139 |
.& RPCISpec crCh rmCh rst
|
|
140 |
.& IRSpec rmCh mem ires"
|
|
141 |
|
|
142 |
ImpInv_def "$(ImpInv rmhist p) .= ($(S1 rmhist p) .| $(S2 rmhist p) .| $(S3 rmhist p) .|
|
|
143 |
$(S4 rmhist p) .| $(S5 rmhist p) .| $(S6 rmhist p))"
|
|
144 |
|
|
145 |
(* Definition of predicate S.
|
|
146 |
NB: The second conjunct of the definition in the paper is taken care of by
|
|
147 |
the type definitions. The last conjunct is asserted separately as the memory
|
|
148 |
invariant MemInv, proved in Memory.ML. *)
|
|
149 |
S_def "$(S rmhist ecalling ccalling rcalling cs rs hs1 hs2 p) .=
|
|
150 |
( ($(Calling memCh p) .= # ecalling)
|
|
151 |
.& ($(Calling crCh p) .= # ccalling)
|
|
152 |
.& (# ccalling .-> (arg[ $(crCh@p)] .= MClkRelayArg[ arg[$(memCh@p)] ]))
|
|
153 |
.& ((.~ # ccalling .& ($(cst@p) .= # clkB)) .-> MVOKBARF[ res[$(crCh@p)] ])
|
|
154 |
.& ($(Calling rmCh p) .= # rcalling)
|
|
155 |
.& (# rcalling .-> (arg[ $(rmCh@p)] .= RPCRelayArg[ arg[$(crCh@p)] ]))
|
|
156 |
.& (.~ # rcalling .-> ($(ires@p) .= # NotAResult))
|
|
157 |
.& ((.~ # rcalling .& ($(rst@p) .= # rpcB)) .-> MVOKBA[ res[$(rmCh@p)] ])
|
|
158 |
.& ($(cst@p) .= # cs)
|
|
159 |
.& ($(rst@p) .= # rs)
|
|
160 |
.& (($(rmhist@p) .= #hs1) .| ($(rmhist@p) .= #hs2))
|
|
161 |
.& (MVNROKBA[ $(ires@p)]))"
|
|
162 |
|
|
163 |
S1_def "$(S1 rmhist p) .= $(S rmhist False False False clkA rpcA histA histA p)"
|
|
164 |
S2_def "$(S2 rmhist p) .= $(S rmhist True False False clkA rpcA histA histA p)"
|
|
165 |
S3_def "$(S3 rmhist p) .= $(S rmhist True True False clkB rpcA histA histB p)"
|
|
166 |
S4_def "$(S4 rmhist p) .= $(S rmhist True True True clkB rpcB histA histB p)"
|
|
167 |
S5_def "$(S5 rmhist p) .= $(S rmhist True True False clkB rpcB histB histB p)"
|
|
168 |
S6_def "$(S6 rmhist p) .= $(S rmhist True False False clkB rpcA histB histB p)"
|
|
169 |
|
|
170 |
(* Definition of the refinement mapping resbar for result *)
|
|
171 |
resbar_def "$((resbar rmhist) @ p) .=
|
|
172 |
(.if ($(S1 rmhist p) .| $(S2 rmhist p))
|
|
173 |
.then $(ires@p)
|
|
174 |
.else .if $(S3 rmhist p)
|
|
175 |
.then .if $(rmhist@p) .= #histA
|
|
176 |
.then $(ires@p) .else # MemFailure
|
|
177 |
.else .if $(S4 rmhist p)
|
|
178 |
.then .if ($(rmhist@p) .= #histB) .& ($(ires@p) .= # NotAResult)
|
|
179 |
.then #MemFailure .else $(ires@p)
|
|
180 |
.else .if $(S5 rmhist p)
|
|
181 |
.then res[$(rmCh@p)]
|
|
182 |
.else .if $(S6 rmhist p)
|
|
183 |
.then .if res[$(crCh@p)] .= #RPCFailure
|
|
184 |
.then #MemFailure .else res[$(crCh@p)]
|
|
185 |
.else #NotAResult)" (* dummy value *)
|
|
186 |
|
|
187 |
end
|
|
188 |
|