Skip to content

Commit 46099ed

Browse files
committed
Revert subtype theory + syntactic sugar for cloning it
The previous Subtype theory forces the definition of the type sT for the subtype carrier, having multiple `sT` types when one has multiple subtype instances. This commits reverts this (i.e. the subtype carrier can be substituted by a user type) but add a command to carefully clone it.
1 parent a06eccc commit 46099ed

File tree

20 files changed

+1142
-991
lines changed

20 files changed

+1142
-991
lines changed

examples/ChaChaPoly/chacha_poly.ec

Lines changed: 200 additions & 177 deletions
Large diffs are not rendered by default.

examples/MEE-CBC/FunctionalSpec.ec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ proof.
492492
(size (pad _p (hmac_sha256 _mk _p)))
493493
(nth witness (iv :: mee_enc AES hmac_sha256 _ek _mk iv _p)
494494
(size (pad _p (hmac_sha256 _mk _p)))).
495-
smt().
496495
split=> //=.
497496
split; 1:by rewrite /mee_enc /= size_cbc_enc addzC.
498497
by rewrite take_size.

examples/ehoare/adversary.ec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ proof.
7474
rewrite (eq_Ep _ _
7575
((fun r => (inv p)%xr * (! test r)%xr) + (fun r => (1 + size log)%xr))).
7676
+ move => x xx /=. rewrite of_realM; 1,2:smt(of_realM invr_ge0 ge0_mu). smt().
77-
rewrite EpD EpC EpZ /=; 1: smt(invr_gt0 dr_mu_test of_realK).
77+
rewrite EpD EpC EpZ /=; 1: smt(invr_gt0 dr_mu_test of_realdK).
7878
rewrite Ep_mu mu_not dr_ll /= -/p.
7979
rewrite !to_pos_pos; 1,2,3,4:smt(mu_bounded dr_mu_test size_ge0).
8080
by auto.

src/ecCommands.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@ let rec process_type (scope : EcScope.scope) (tyd : ptydecl located) =
411411
and process_types (scope : EcScope.scope) tyds =
412412
List.fold_left process_type scope tyds
413413

414+
(* -------------------------------------------------------------------- *)
415+
and process_subtype (scope : EcScope.scope) (subtype : psubtype located) =
416+
EcScope.check_state `InTop "subtype" scope;
417+
let scope = EcScope.Ty.add_subtype scope subtype in
418+
EcScope.notify scope `Info "added subtype: `%s'" (unloc subtype.pl_desc.pst_name);
419+
scope
420+
414421
(* -------------------------------------------------------------------- *)
415422
and process_typeclass (scope : EcScope.scope) (tcd : ptypeclass located) =
416423
EcScope.check_state `InTop "type class" scope;
@@ -743,6 +750,7 @@ and process (ld : Loader.loader) (scope : EcScope.scope) g =
743750
match
744751
match g.pl_desc with
745752
| Gtype t -> `Fct (fun scope -> process_types scope (List.map (mk_loc loc) t))
753+
| Gsubtype t -> `Fct (fun scope -> process_subtype scope (mk_loc loc t))
746754
| Gtypeclass t -> `Fct (fun scope -> process_typeclass scope (mk_loc loc t))
747755
| Gtycinstance t -> `Fct (fun scope -> process_tycinst scope (mk_loc loc t))
748756
| Gmodule m -> `Fct (fun scope -> process_module scope m)

src/ecCoreLib.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ module CI_Xreal = struct
116116
let mk_Rpbar = fun x -> EcPath.pqname p_Rpbar x
117117

118118
let p_realp = mk_Rp "realp"
119-
let p_of_real = mk_Rp "of_real"
119+
let p_of_real = mk_Rp "of_reald"
120120

121121
let p_xreal = mk_Rpbar "xreal"
122122
let p_rp = mk_Rpbar "rp"

src/ecLexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
"theory" , THEORY ; (* KW: global *)
196196
"abstract" , ABSTRACT ; (* KW: global *)
197197
"section" , SECTION ; (* KW: global *)
198+
"subtype" , SUBTYPE ; (* KW: global *)
198199
"type" , TYPE ; (* KW: global *)
199200
"class" , CLASS ; (* KW: global *)
200201
"instance" , INSTANCE ; (* KW: global *)

src/ecParser.mly

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@
558558
%token SPLITWHILE
559559
%token STAR
560560
%token SUBST
561+
%token SUBTYPE
561562
%token SUFF
562563
%token SWAP
563564
%token SYMMETRY
@@ -1644,6 +1645,21 @@ typedecl:
16441645
| locality=locality TYPE td=tyd_name EQ te=datatype_def
16451646
{ [mk_tydecl ~locality td (PTYD_Datatype te)] }
16461647

1648+
(* -------------------------------------------------------------------- *)
1649+
(* Subtypes *)
1650+
subtype:
1651+
| SUBTYPE name=lident cname=prefix(AS, uident)? EQ LBRACE
1652+
x=lident COLON carrier=loc(type_exp) PIPE pred=form
1653+
RBRACE rename=subtype_rename?
1654+
{ { pst_name = name;
1655+
pst_cname = cname;
1656+
pst_carrier = carrier;
1657+
pst_pred = (x, pred);
1658+
pst_rename = rename; } }
1659+
1660+
subtype_rename:
1661+
| RENAME x=STRING COMMA y=STRING { (x, y) }
1662+
16471663
(* -------------------------------------------------------------------- *)
16481664
(* Type classes *)
16491665
typeclass:
@@ -3764,6 +3780,7 @@ global_action:
37643780
| mod_def_or_decl { Gmodule $1 }
37653781
| sig_def { Ginterface $1 }
37663782
| typedecl { Gtype $1 }
3783+
| subtype { Gsubtype $1 }
37673784
| typeclass { Gtypeclass $1 }
37683785
| tycinstance { Gtycinstance $1 }
37693786
| operator { Goperator $1 }

src/ecParsetree.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,15 @@ let rec pf_ident ?(raw = false) f =
385385
| PFtuple [f] when not raw -> pf_ident ~raw f
386386
| _ -> None
387387

388+
(* -------------------------------------------------------------------- *)
389+
type psubtype = {
390+
pst_name : psymbol;
391+
pst_cname : psymbol option;
392+
pst_carrier : pty;
393+
pst_pred : (psymbol * pformula);
394+
pst_rename : (string * string) option;
395+
}
396+
388397
(* -------------------------------------------------------------------- *)
389398
type ptyvardecls =
390399
(psymbol * pqsymbol list) list
@@ -1262,6 +1271,7 @@ type global_action =
12621271
| Gabbrev of pabbrev
12631272
| Gaxiom of paxiom
12641273
| Gtype of ptydecl list
1274+
| Gsubtype of psubtype
12651275
| Gtypeclass of ptypeclass
12661276
| Gtycinstance of ptycinstance
12671277
| Gaddrw of (is_local * pqsymbol * pqsymbol list)

0 commit comments

Comments
 (0)