3807
|
1 |
(*
|
|
2 |
File: Memory.thy
|
|
3 |
Author: Stephan Merz
|
|
4 |
Copyright: 1997 University of Munich
|
|
5 |
|
|
6 |
Theory Name: Memory
|
|
7 |
Logic Image: TLA
|
|
8 |
|
|
9 |
RPC-Memory example: Memory specification
|
|
10 |
*)
|
|
11 |
|
|
12 |
Memory = MemoryParameters + ProcedureInterface +
|
|
13 |
|
|
14 |
types
|
|
15 |
memChType = "(memArgType,Vals) channel"
|
|
16 |
memType = "(Locs => Vals) stfun" (* intention: MemLocs => MemVals *)
|
|
17 |
resType = "(PrIds => Vals) stfun"
|
|
18 |
|
|
19 |
consts
|
|
20 |
(* state predicates *)
|
|
21 |
MInit :: "memType => Locs => stpred"
|
|
22 |
PInit :: "resType => PrIds => stpred"
|
|
23 |
(* auxiliary predicates: is there a pending read/write request for
|
|
24 |
some process id and location/value? *)
|
|
25 |
RdRequest :: "memChType => PrIds => Locs => stpred"
|
|
26 |
WrRequest :: "memChType => PrIds => Locs => Vals => stpred"
|
|
27 |
|
|
28 |
(* actions *)
|
|
29 |
GoodRead :: "memType => resType => PrIds => Locs => action"
|
|
30 |
BadRead :: "memType => resType => PrIds => Locs => action"
|
|
31 |
ReadInner :: "memChType => memType => resType => PrIds => Locs => action"
|
|
32 |
Read :: "memChType => memType => resType => PrIds => action"
|
|
33 |
GoodWrite :: "memType => resType => PrIds => Locs => Vals => action"
|
|
34 |
BadWrite :: "memType => resType => PrIds => Locs => Vals => action"
|
|
35 |
WriteInner :: "memChType => memType => resType => PrIds => Locs => Vals => action"
|
|
36 |
Write :: "memChType => memType => resType => PrIds => Locs => action"
|
|
37 |
MemReturn :: "memChType => resType => PrIds => action"
|
|
38 |
MemFail :: "memChType => resType => PrIds => action"
|
|
39 |
RNext :: "memChType => memType => resType => PrIds => action"
|
|
40 |
UNext :: "memChType => memType => resType => PrIds => action"
|
|
41 |
|
|
42 |
(* temporal formulas *)
|
|
43 |
RPSpec :: "memChType => memType => resType => PrIds => temporal"
|
|
44 |
UPSpec :: "memChType => memType => resType => PrIds => temporal"
|
|
45 |
MSpec :: "memChType => memType => resType => Locs => temporal"
|
|
46 |
IRSpec :: "memChType => memType => resType => temporal"
|
|
47 |
IUSpec :: "memChType => memType => resType => temporal"
|
|
48 |
|
|
49 |
RSpec :: "memChType => resType => temporal"
|
|
50 |
USpec :: "memChType => temporal"
|
|
51 |
|
|
52 |
(* memory invariant: in the paper, the invariant is hidden in the definition of
|
|
53 |
the predicate S used in the implementation proof, but it is easier to verify
|
|
54 |
at this level. *)
|
|
55 |
MemInv :: "memType => Locs => stpred"
|
|
56 |
|
|
57 |
rules
|
|
58 |
MInit_def "$(MInit mm l) .= ($(mm@l) .= # InitVal)"
|
|
59 |
PInit_def "$(PInit rs p) .= ($(rs@p) .= # NotAResult)"
|
|
60 |
|
|
61 |
RdRequest_def "$(RdRequest ch p l) .=
|
|
62 |
($(Calling ch p) .& (arg[$(ch@p)] .= #(Inl (read,l))))"
|
|
63 |
WrRequest_def "$(WrRequest ch p l v) .=
|
|
64 |
($(Calling ch p) .& (arg[$(ch@p)] .= #(Inr (write,l,v))))"
|
|
65 |
(* a read that doesn't raise BadArg *)
|
|
66 |
GoodRead_def "GoodRead mm rs p l ==
|
|
67 |
#(MemLoc l) .& (rs@p)$ .= $(mm@l)"
|
|
68 |
(* a read that raises BadArg *)
|
|
69 |
BadRead_def "BadRead mm rs p l ==
|
|
70 |
.~ #(MemLoc l) .& (rs@p)$ .= #BadArg"
|
|
71 |
(* the read action with l visible *)
|
|
72 |
ReadInner_def "ReadInner ch mm rs p l ==
|
|
73 |
$(RdRequest ch p l)
|
|
74 |
.& (GoodRead mm rs p l .| BadRead mm rs p l)
|
|
75 |
.& unchanged (rtrner ch @ p)"
|
|
76 |
(* the read action with l quantified *)
|
|
77 |
Read_def "Read ch mm rs p == REX l. ReadInner ch mm rs p l"
|
|
78 |
|
|
79 |
(* similar definitions for the write action *)
|
|
80 |
GoodWrite_def "GoodWrite mm rs p l v ==
|
|
81 |
#(MemLoc l) .& #(MemVal v)
|
|
82 |
.& (mm@l)$ .= #v .& (rs@p)$ .= #OK"
|
|
83 |
BadWrite_def "BadWrite mm rs p l v ==
|
|
84 |
.~ (#(MemLoc l) .& #(MemVal v))
|
|
85 |
.& (rs@p)$ .= #BadArg .& unchanged (mm@l)"
|
|
86 |
WriteInner_def "WriteInner ch mm rs p l v ==
|
|
87 |
$(WrRequest ch p l v)
|
|
88 |
.& (GoodWrite mm rs p l v .| BadWrite mm rs p l v)
|
|
89 |
.& unchanged (rtrner ch @ p)"
|
|
90 |
Write_def "Write ch mm rs p l == REX v. WriteInner ch mm rs p l v"
|
|
91 |
|
|
92 |
(* the return action *)
|
|
93 |
MemReturn_def "MemReturn ch rs p ==
|
|
94 |
$(rs@p) .~= #NotAResult
|
|
95 |
.& (rs@p)$ .= #NotAResult
|
|
96 |
.& Return ch p ($(rs@p))"
|
|
97 |
(* the failure action of the unreliable memory *)
|
|
98 |
MemFail_def "MemFail ch rs p ==
|
|
99 |
$(Calling ch p)
|
|
100 |
.& (rs@p)$ .= #MemFailure
|
|
101 |
.& unchanged (rtrner ch @ p)"
|
|
102 |
RNext_def "RNext ch mm rs p ==
|
|
103 |
Read ch mm rs p
|
|
104 |
.| (REX l. Write ch mm rs p l)
|
|
105 |
.| MemReturn ch rs p"
|
|
106 |
UNext_def "UNext ch mm rs p ==
|
|
107 |
RNext ch mm rs p .| MemFail ch rs p"
|
|
108 |
|
|
109 |
RPSpec_def "RPSpec ch mm rs p ==
|
|
110 |
Init($(PInit rs p))
|
|
111 |
.& [][ RNext ch mm rs p ]_<rtrner ch @ p, rs@p>
|
|
112 |
.& WF(RNext ch mm rs p)_<rtrner ch @ p, rs@p>
|
|
113 |
.& WF(MemReturn ch rs p)_<rtrner ch @ p, rs@p>"
|
|
114 |
UPSpec_def "UPSpec ch mm rs p ==
|
|
115 |
Init($(PInit rs p))
|
|
116 |
.& [][ UNext ch mm rs p ]_<rtrner ch @ p, rs@p>
|
|
117 |
.& WF(RNext ch mm rs p)_<rtrner ch @ p, rs@p>
|
|
118 |
.& WF(MemReturn ch rs p)_<rtrner ch @ p, rs@p>"
|
|
119 |
MSpec_def "MSpec ch mm rs l ==
|
|
120 |
Init($(MInit mm l))
|
|
121 |
.& [][ REX p. Write ch mm rs p l ]_(mm@l)"
|
|
122 |
IRSpec_def "IRSpec ch mm rs ==
|
|
123 |
(RALL p. RPSpec ch mm rs p)
|
|
124 |
.& (RALL l. #(MemLoc l) .-> MSpec ch mm rs l)"
|
|
125 |
IUSpec_def "IUSpec ch mm rs ==
|
|
126 |
(RALL p. UPSpec ch mm rs p)
|
|
127 |
.& (RALL l. #(MemLoc l) .-> MSpec ch mm rs l)"
|
|
128 |
|
|
129 |
RSpec_def "RSpec ch rs == EEX mm. IRSpec ch mm rs"
|
|
130 |
USpec_def "USpec ch == EEX mm rs. IUSpec ch mm rs"
|
|
131 |
|
|
132 |
MemInv_def "$(MemInv mm l) .=
|
|
133 |
(#(MemLoc l) .-> MemVal[ $(mm@l)])"
|
|
134 |
end
|
|
135 |
|
|
136 |
|
|
137 |
|