Skip to content

Commit 63f0e0d

Browse files
bgregoirlyonel2017
authored andcommitted
cloning + substitution of exception
1 parent ad61404 commit 63f0e0d

8 files changed

Lines changed: 34 additions & 15 deletions

File tree

examples/exception.ec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ op p2: int -> bool.
88

99
module M' ={
1010
proc truc (x:int) : int = {
11+
if (! p1 x \/ ! p2 x) else raise assume;
1112
ensure (! p1 x \/ ! p2 x) -> assume;
1213
if (!p1 x \/ !p2 x) { raise assert;}
1314
return x;
@@ -172,9 +173,11 @@ qed.
172173

173174
exception arg1 of int.
174175

176+
op toto i = arg1 i.
177+
175178
module M3 = {
176179
proc f () = {
177-
raise (arg1 3);
180+
raise (toto 3);
178181
}
179182

180183
}.
@@ -193,6 +196,8 @@ proof.
193196
proc. wp. skip => //.
194197
qed.
195198

199+
exception return ['a]
196200

197201

198202

203+
exception arg ['a] of 'a.

src/ecParsetree.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ type theory_cloning = {
11851185
}
11861186

11871187
and theory_renaming_kind =
1188-
[ `Lemma | `Op | `Pred | `Type | `Module | `ModType | `Theory]
1188+
[ `Lemma | `Op | `Pred | `Type | `Module | `ModType | `Theory | `Exn]
11891189

11901190
and theory_renaming =
11911191
(theory_renaming_kind list * string located pair)

src/ecSubst.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,12 @@ let subst_tc (s : subst) tc =
10131013
let tc_axs = List.map (snd_map (subst_form s)) tc.tc_axs in
10141014
{ tc_prt; tc_ops; tc_axs; tc_loca = tc.tc_loca }
10151015

1016+
1017+
(* -------------------------------------------------------------------- *)
1018+
let subst_excep (s : subst) (ex : excep) =
1019+
{ e_loca = ex.e_loca;
1020+
e_dom = subst_tys s ex.e_dom }
1021+
10161022
(* -------------------------------------------------------------------- *)
10171023
(* SUBSTITUTION OVER THEORIES *)
10181024
let rec subst_theory_item_r (s : subst) (item : theory_item_r) =
@@ -1023,8 +1029,8 @@ let rec subst_theory_item_r (s : subst) (item : theory_item_r) =
10231029
| Th_operator (x, op) ->
10241030
Th_operator (x, subst_op s op)
10251031

1026-
| Th_exception (x, es) ->
1027-
Th_exception (x, es)
1032+
| Th_exception (x, ex) ->
1033+
Th_exception (x, subst_excep s ex)
10281034

10291035
| Th_axiom (x, ax) ->
10301036
Th_axiom (x, subst_ax s ax)

src/ecSubst.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ val subst_tydecl : subst -> tydecl -> tydecl
4747
val subst_tc : subst -> typeclass -> typeclass
4848
val subst_theory : subst -> theory -> theory
4949
val subst_branches : subst -> opbranches -> opbranches
50+
val subst_excep : subst -> excep -> excep
5051

5152
(* -------------------------------------------------------------------- *)
5253
val subst_path : subst -> path -> path

src/ecThCloning.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ and rk_categories = {
217217
rkc_module : bool;
218218
rkc_modtype : bool;
219219
rkc_theory : bool;
220+
rkc_exn : bool;
220221
}
221222

222223
(* -------------------------------------------------------------------- *)
@@ -231,6 +232,7 @@ let rename ((rk, (rex, itempl)) : renaming) (k, x) =
231232
| `Selected { rkc_module = true }, `Module -> true
232233
| `Selected { rkc_modtype = true }, `ModType -> true
233234
| `Selected { rkc_theory = true }, `Theory -> true
235+
| `Selected { rkc_exn = true }, `Exn -> true
234236
| _, _ -> false in
235237

236238
let newx =
@@ -385,10 +387,12 @@ end = struct
385387
| Some ({cth_mode = `Concrete} as th) -> th
386388
in
387389

390+
(* FIXME improve error message *)
388391
let rec contains_module cth =
389392
let doit it =
390393
match it.ti_item with
391394
| Th_module _ -> true
395+
| Th_exception _ -> true
392396
| Th_theory (_, cth) -> contains_module cth
393397
| _ -> false
394398
in
@@ -435,7 +439,7 @@ end = struct
435439
let ovrd = (ovrd, mode) in
436440
nt_ovrd oc (proofs, evc) (loced (xdth @ prefix, x)) ovrd
437441

438-
| Th_exception _ -> (proofs, evc)
442+
| Th_exception _ -> (proofs, evc)
439443

440444
| Th_axiom (x, _) ->
441445
let axd = loced (thd @ prefix, x) in
@@ -524,12 +528,13 @@ end = struct
524528
| `Pred -> { rk with rkc_preds = true; }
525529
| `Module -> { rk with rkc_module = true; }
526530
| `ModType -> { rk with rkc_modtype = true; }
527-
| `Theory -> { rk with rkc_theory = true; } in
531+
| `Theory -> { rk with rkc_theory = true; }
532+
| `Exn -> { rk with rkc_exn = true; } in
528533

529534
let init = {
530535
rkc_lemmas = false; rkc_types = false; rkc_ops = false;
531536
rkc_preds = false; rkc_module = false; rkc_modtype = false;
532-
rkc_theory = false; } in
537+
rkc_theory = false; rkc_exn = false } in
533538

534539
`Selected (List.fold_left update init k)
535540

src/ecThCloning.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ and rk_categories = {
105105
rkc_module : bool;
106106
rkc_modtype : bool;
107107
rkc_theory : bool;
108+
rkc_exn : bool;
108109
}
109110

110111
(* -------------------------------------------------------------------- *)

src/ecTheoryReplay.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ let string_of_renaming_kind = function
364364
| `Module -> "module"
365365
| `ModType -> "module type"
366366
| `Theory -> "theory"
367+
| `Exn -> "exception"
367368

368369
(* -------------------------------------------------------------------- *)
369370
let rename ?(fold = true) ove subst (kind, name) =
@@ -386,7 +387,7 @@ let rename ?(fold = true) ove subst (kind, name) =
386387

387388
let nameok =
388389
match kind with
389-
| `Lemma | `Type ->
390+
| `Lemma | `Type | `Exn ->
390391
EcIo.is_sym_ident newname
391392
| `Op | `Pred ->
392393
EcIo.is_op_ident newname
@@ -787,11 +788,11 @@ and replay_ntd (ove : _ ovrenv) (subst, ops, proofs, scope) (import, x, oont) =
787788

788789

789790
(* -------------------------------------------------------------------- *)
790-
and replay_excep
791-
(ove : _ ovrenv) (subst, ops, proofs, scope) (import, name, excep)
792-
=
793-
let scope = ove.ovre_hooks.hadd_item scope ~import (Th_exception (name, excep)) in
794-
(subst, ops, proofs, scope)
791+
and replay_exception (ove : _ ovrenv) (subst, ops, proofs, scope) (import, name, excep) =
792+
let subst, name = rename ove subst (`Exn, name) in
793+
let excep = EcSubst.subst_excep subst excep in
794+
let item = Th_exception (name, excep) in
795+
(subst, ops, proofs, ove.ovre_hooks.hadd_item scope ~import item)
795796

796797
(* -------------------------------------------------------------------- *)
797798
and replay_axd (ove : _ ovrenv) (subst, ops, proofs, scope) (import, x, ax) =
@@ -1067,7 +1068,7 @@ and replay1 (ove : _ ovrenv) (subst, ops, proofs, scope) (hidden, item) =
10671068
replay_ntd ove (subst, ops, proofs, scope) (import, x, oont)
10681069

10691070
| Th_exception (x, e) ->
1070-
replay_excep ove (subst, ops, proofs, scope) (import, x, e)
1071+
replay_exception ove (subst, ops, proofs, scope) (import, x, e)
10711072

10721073
| Th_axiom (x, ax) ->
10731074
replay_axd ove (subst, ops, proofs, scope) (import, x, ax)

src/ecUserMessages.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ end = struct
716716
(string_of_ovkind kd) (string_of_qsymbol x)
717717

718718
| CE_ThyOverride x ->
719-
msg "Cannot override theory `%s`: contains module"
719+
msg "Cannot override theory `%s`: contains module or exception"
720720
(string_of_qsymbol x)
721721

722722
| CE_UnkAbbrev x ->

0 commit comments

Comments
 (0)