-
Notifications
You must be signed in to change notification settings - Fork 0
/
namesAndTypes.v
406 lines (320 loc) · 12.4 KB
/
namesAndTypes.v
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
Require Import partial.
Require Import Coq.Structures.Equalities.
(* Module Type Nice (T: Typ) := *)
(* (MyDecidableType T) <+ (Infinite T). *)
Module Type AbstractNamesAndTypes.
Declare Module VarNameM : Typ.
Declare Module FieldNameM : Typ.
Declare Module MethodNameM : Typ.
Declare Module ClassNameM : Typ.
Declare Module RefM : Typ.
Declare Module vn : Nice VarNameM.
Declare Module fn : Nice FieldNameM.
Declare Module mn : Nice MethodNameM.
Declare Module cn : Nice ClassNameM.
Declare Module rn : Nice RefM.
End AbstractNamesAndTypes.
Module NamesAndTypesAndOtherNames (ant: AbstractNamesAndTypes) .
Import ant.
Definition VarName_type := ant.VarNameM.t.
Definition FieldName_type := ant.FieldNameM.t.
Definition MethodName_type := ant.MethodNameM.t.
Definition ClassName_type := ant.ClassNameM.t.
Definition Ref_type := ant.RefM.t.
Definition v_eq_dec := ant.vn.eq_dec.
Definition fn_eq_dec := ant.fn.eq_dec.
Definition mn_eq_dec := ant.mn.eq_dec.
Definition cn_eq_dec := ant.cn.eq_dec.
Definition rn_eq_dec := ant.rn.eq_dec.
Definition var_name_this :=
let fresh := vn.constructFresh nil in let (x, _) := fresh in x.
Inductive annotation_type :=
| ann_epsilon : annotation_type
| ann_var : VarName_type -> annotation_type.
Inductive class :=
| AnyRef : class
| extends : ClassName_type -> class -> class.
Inductive FM_Range_type :=
| FM_null : FM_Range_type
| FM_ref : Ref_type -> FM_Range_type.
Module FM_typeM <: Typ .
Definition t := FM_Range_type.
End FM_typeM.
Module p_FM := PartialFunctions ant.FieldNameM FM_typeM ant.fn.
Definition FM_type := p_FM.PartFunc.
(* run-time object *)
Inductive RTObject :=
| obj : class -> FM_type -> RTObject.
Module RTObject_typeM <: Typ .
Definition t := RTObject.
End RTObject_typeM.
Module p_heap := PartialFunctions ant.RefM RTObject_typeM ant.rn.
Definition Heap_type := p_heap.PartFunc.
Inductive env_Range_type :=
| envNull : env_Range_type
| envRef : Ref_type -> env_Range_type
| envBox : Ref_type -> env_Range_type.
Module env_Range_typeM <: Typ.
Definition t := env_Range_type.
End env_Range_typeM.
Module p_env := PartialFunctions VarNameM env_Range_typeM
ant.vn.
Definition Env_type := p_env.PartFunc.
Theorem class_eq_dec : forall x y : class, {x = y } + {x <> y}.
intro.
induction x.
intro.
destruct y.
left; reflexivity.
right; simplify_eq.
intro y'.
destruct y'.
right; simplify_eq.
set (ind_hyp := IHx y').
destruct ind_hyp.
rewrite e.
destruct (cn_eq_dec c c0).
rewrite e0.
left; reflexivity.
right.
intro H; inversion H.
firstorder.
right; intro H; inversion H.
firstorder.
Qed.
Inductive typecheck_type :=
| typt_class : class -> typecheck_type
| typt_box : class -> typecheck_type
| typt_all : typecheck_type.
Inductive effect :=
| eff_ocap : effect
| eff_epsilon : effect.
Module tyM <: Typ.
Definition t := typecheck_type.
End tyM.
Module p_Γ := PartialFunctions VarNameM tyM vn.
Notation Gamma_type := p_Γ.PartFunc.
End NamesAndTypesAndOtherNames.
Module ConcreteNamesAndTypes <: AbstractNamesAndTypes.
Module VarNameM.
Inductive _var_name_type :=
| _var_name_type_constr : nat -> _var_name_type.
Definition t := _var_name_type.
End VarNameM.
Module FieldNameM.
Inductive _field_name_type :=
| _field_name_type_constr : nat -> _field_name_type.
Definition t := _field_name_type.
End FieldNameM.
Module MethodNameM.
Inductive _method_name_type :=
| _method_name_type_constr : nat -> _method_name_type.
Definition t := _method_name_type.
End MethodNameM.
Module ClassNameM.
Inductive _class_name_type :=
| _class_name_type_constr : nat -> _class_name_type.
Definition t := _class_name_type.
End ClassNameM.
Module RefM.
Inductive _ref_type :=
| _ref_type_constr : nat -> _ref_type.
Definition t := _ref_type.
End RefM.
Module varNameNice <: Nice VarNameM.
Import VarNameM.
Lemma _var_name_eq_dec :
forall (x y : _var_name_type),
{x = y} + {x <> y}.
intros.
destruct x as [nx]; destruct y as [ny].
case_eq (nat_eq_dec nx ny); intros; clear H.
left; rewrite e; reflexivity.
right; simplify_eq; assumption.
Qed.
Definition eq_dec := _var_name_eq_dec.
Require Import Coq.Lists.List.
Lemma _var_name_type_constructFresh
: forall lT : list _var_name_type,
{fresh : _var_name_type | ~ In fresh lT}.
Definition unpack (x: _var_name_type) :=
match x with | _var_name_type_constr nx => nx end.
intros.
set (lTn := map unpack lT).
destruct (infiniteNat.constructFresh lTn) as [fresh_nat fresh_nat_is_fresh].
assert (forall x1 x2, unpack x1 = unpack x2 -> x1 = x2) as unpack_injective.
intros.
destruct x1 as [n1]; destruct x2 as [n2].
simplify_eq H; intro are_eq; rewrite are_eq; reflexivity.
set (lem := count_occ_map unpack _var_name_eq_dec nat_eq_dec unpack_injective
(_var_name_type_constr fresh_nat) lT
).
fold lTn in lem.
simpl in lem.
set (lemlem := proj1 (count_occ_not_In nat_eq_dec lTn fresh_nat) fresh_nat_is_fresh).
rewrite lemlem in lem.
set (lemlemlem := proj2 (count_occ_not_In _var_name_eq_dec lT (_var_name_type_constr fresh_nat))
lem).
exact (exist _ (_var_name_type_constr fresh_nat) lemlemlem).
Qed.
Definition constructFresh := _var_name_type_constructFresh.
End varNameNice.
Module fieldNameNice <: Nice FieldNameM.
Import FieldNameM.
Lemma _field_name_eq_dec :
forall (x y : _field_name_type),
{x = y} + {x <> y}.
intros.
destruct x as [nx]; destruct y as [ny].
case_eq (nat_eq_dec nx ny); intros; clear H.
left; rewrite e; reflexivity.
right; simplify_eq; assumption.
Qed.
Definition eq_dec := _field_name_eq_dec.
Require Import Coq.Lists.List.
Lemma _field_name_type_constructFresh
: forall lT : list _field_name_type,
{fresh : _field_name_type | ~ In fresh lT}.
Definition unpack (x: _field_name_type) :=
match x with | _field_name_type_constr nx => nx end.
intros.
set (lTn := map unpack lT).
destruct (infiniteNat.constructFresh lTn) as [fresh_nat fresh_nat_is_fresh].
assert (forall x1 x2, unpack x1 = unpack x2 -> x1 = x2) as unpack_injective.
intros.
destruct x1 as [n1]; destruct x2 as [n2].
simplify_eq H; intro are_eq; rewrite are_eq; reflexivity.
set (lem := count_occ_map unpack _field_name_eq_dec nat_eq_dec unpack_injective
(_field_name_type_constr fresh_nat) lT
).
fold lTn in lem.
simpl in lem.
set (lemlem := proj1 (count_occ_not_In nat_eq_dec lTn fresh_nat) fresh_nat_is_fresh).
rewrite lemlem in lem.
set (lemlemlem := proj2 (count_occ_not_In _field_name_eq_dec lT (_field_name_type_constr fresh_nat))
lem).
exact (exist _ (_field_name_type_constr fresh_nat) lemlemlem).
Qed.
Definition constructFresh := _field_name_type_constructFresh.
End fieldNameNice.
Module methodNameNice <: Nice MethodNameM.
Import MethodNameM.
Lemma _method_name_eq_dec :
forall (x y : _method_name_type),
{x = y} + {x <> y}.
intros.
destruct x as [nx]; destruct y as [ny].
case_eq (nat_eq_dec nx ny); intros; clear H.
left; rewrite e; reflexivity.
right; simplify_eq; assumption.
Qed.
Definition eq_dec := _method_name_eq_dec.
Require Import Coq.Lists.List.
Lemma _method_name_type_constructFresh
: forall lT : list _method_name_type,
{fresh : _method_name_type | ~ In fresh lT}.
Definition unpack (x: _method_name_type) :=
match x with | _method_name_type_constr nx => nx end.
intros.
set (lTn := map unpack lT).
destruct (infiniteNat.constructFresh lTn) as [fresh_nat fresh_nat_is_fresh].
assert (forall x1 x2, unpack x1 = unpack x2 -> x1 = x2) as unpack_injective.
intros.
destruct x1 as [n1]; destruct x2 as [n2].
simplify_eq H; intro are_eq; rewrite are_eq; reflexivity.
set (lem := count_occ_map unpack _method_name_eq_dec nat_eq_dec unpack_injective
(_method_name_type_constr fresh_nat) lT
).
fold lTn in lem.
simpl in lem.
set (lemlem := proj1 (count_occ_not_In nat_eq_dec lTn fresh_nat) fresh_nat_is_fresh).
rewrite lemlem in lem.
set (lemlemlem := proj2 (count_occ_not_In _method_name_eq_dec lT (_method_name_type_constr fresh_nat))
lem).
exact (exist _ (_method_name_type_constr fresh_nat) lemlemlem).
Qed.
Definition constructFresh := _method_name_type_constructFresh.
End methodNameNice.
Module classNameNice <: Nice ClassNameM.
Import ClassNameM.
Lemma _class_name_eq_dec :
forall (x y : _class_name_type),
{x = y} + {x <> y}.
intros.
destruct x as [nx]; destruct y as [ny].
case_eq (nat_eq_dec nx ny); intros; clear H.
left; rewrite e; reflexivity.
right; simplify_eq; assumption.
Qed.
Definition eq_dec := _class_name_eq_dec.
Require Import Coq.Lists.List.
Lemma _class_name_type_constructFresh
: forall lT : list _class_name_type,
{fresh : _class_name_type | ~ In fresh lT}.
Definition unpack (x: _class_name_type) :=
match x with | _class_name_type_constr nx => nx end.
intros.
set (lTn := map unpack lT).
destruct (infiniteNat.constructFresh lTn) as [fresh_nat fresh_nat_is_fresh].
assert (forall x1 x2, unpack x1 = unpack x2 -> x1 = x2) as unpack_injective.
intros.
destruct x1 as [n1]; destruct x2 as [n2].
simplify_eq H; intro are_eq; rewrite are_eq; reflexivity.
set (lem := count_occ_map unpack _class_name_eq_dec nat_eq_dec unpack_injective
(_class_name_type_constr fresh_nat) lT
).
fold lTn in lem.
simpl in lem.
set (lemlem := proj1 (count_occ_not_In nat_eq_dec lTn fresh_nat) fresh_nat_is_fresh).
rewrite lemlem in lem.
set (lemlemlem := proj2 (count_occ_not_In _class_name_eq_dec lT (_class_name_type_constr fresh_nat))
lem).
exact (exist _ (_class_name_type_constr fresh_nat) lemlemlem).
Qed.
Definition constructFresh := _class_name_type_constructFresh.
End classNameNice.
Module refNice <: Nice RefM.
Import RefM.
Lemma _ref_eq_dec :
forall (x y : _ref_type),
{x = y} + {x <> y}.
intros.
destruct x as [nx]; destruct y as [ny].
case_eq (nat_eq_dec nx ny); intros; clear H.
left; rewrite e; reflexivity.
right; simplify_eq; assumption.
Qed.
Definition eq_dec := _ref_eq_dec.
Require Import Coq.Lists.List.
Lemma _ref_type_constructFresh
: forall lT : list _ref_type,
{fresh : _ref_type | ~ In fresh lT}.
Definition unpack (x: _ref_type) :=
match x with | _ref_type_constr nx => nx end.
intros.
set (lTn := map unpack lT).
destruct (infiniteNat.constructFresh lTn) as [fresh_nat fresh_nat_is_fresh].
assert (forall x1 x2, unpack x1 = unpack x2 -> x1 = x2) as unpack_injective.
intros.
destruct x1 as [n1]; destruct x2 as [n2].
simplify_eq H; intro are_eq; rewrite are_eq; reflexivity.
set (lem := count_occ_map unpack _ref_eq_dec nat_eq_dec unpack_injective
(_ref_type_constr fresh_nat) lT
).
fold lTn in lem.
simpl in lem.
set (lemlem := proj1 (count_occ_not_In nat_eq_dec lTn fresh_nat) fresh_nat_is_fresh).
rewrite lemlem in lem.
set (lemlemlem := proj2 (count_occ_not_In _ref_eq_dec lT (_ref_type_constr fresh_nat))
lem).
exact (exist _ (_ref_type_constr fresh_nat) lemlemlem).
Qed.
Definition constructFresh := _ref_type_constructFresh.
End refNice.
Module vn := varNameNice.
Module fn := fieldNameNice.
Module mn := methodNameNice.
Module rn := refNice.
Module cn := classNameNice.
End ConcreteNamesAndTypes.
Module ConcreteEverything := NamesAndTypesAndOtherNames ConcreteNamesAndTypes.