Debian Codegraph @

apps/locker/theories/locker.v

raw
1 (* Locking mechanisms.
2
3 license: GNU Lesser General Public License Version 2.1 or later
4 ------------------------------------------------------------------------- *)
5 From elpi.apps.locker.elpi Extra Dependency "locker.elpi" as locker.
6
7 From Corelib Require Import ssreflect.
8 From elpi Require Import elpi.
9
10 (** [lock] locks a definition on an opaque key
11
12 + can be used everywhere
13 - conversion may cross the lock (by congruence), while reduction will not
14
15 Example:
16
17 [[
18 lock Definition foo : T := bo.
19 ]]
20
21 Synthesizes:
22 - [foo_key_subproof] an opaque term of type unit
23 - [foo] unfolds to [locked_with foo_key_subproof bo]
24 - [Canonical foo_unlock_subterm := Unlockable ...] so that [rewrite unlock]
25 exposes the real body
26
27 Supported attributes:
28 - [#[key]] lets one override the name of the key
29
30 *)
31
32 Elpi Command lock.
33 Elpi Accumulate File locker.
34 Elpi Accumulate lp:{{
35 main [const-decl ID (some Bo) Ty] :- !,
36 attributes A,
37 coq.parse-attributes A [
38 att "key" string,
39 ] Opts, !,
40 Opts => locker.key-lock ID Bo Ty none.
41 main [upoly-const-decl ID (some Bo) Ty UnivDecl] :- !,
42 attributes A,
43 coq.parse-attributes A [
44 att "key" string,
45 ] Opts, !,
46 Opts => locker.key-lock ID Bo Ty (some UnivDecl).
47 main _ :- coq.error "Usage: lock Definition ...".
48 }}.
49
50 Elpi Export lock.
51
52 (** [mlock] locks a definition behind a module type
53
54 + hard locking (the body is really sealed)
55 - cannot be used inside sections
56
57 Example:
58
59 [[
60 mlock Definition foo : T := bo.
61 ]]
62
63 Synthesizes:
64 - [Module Type foo_Locked] with fields [body] and [unlock] where
65 [body : T] and [unlock : body = bo]
66 - [Module foo : foo_Locked]
67 - [foo] a notation for [foo.body]
68 - [Canonical foo_unlock_subterm := Unlockable ...] so that [rewrite unlock]
69 exposes the real body
70
71 *)
72
73 Elpi Command mlock.
74 Elpi Accumulate File locker.
75 #[synterp] Elpi Accumulate lp:{{
76 pred synterp-action i:id.
77 synterp-action ID :-
78 Module is ID ^ "_Locked",
79 coq.env.begin-module-type Module,
80 coq.env.end-module-type TY,
81 coq.env.begin-module ID (some TY),
82 coq.env.end-module _.
83 main [const-decl ID _ _] :- synterp-action ID.
84 main [upoly-const-decl ID _ _ _] :- synterp-action ID.
85 }}.
86 Elpi Accumulate lp:{{
87 main [const-decl ID (some Bo) Ty] :- !, locker.module-lock ID Bo Ty none.
88 main [upoly-const-decl ID (some Bo) Ty UD] :- !, locker.module-lock ID Bo Ty (some UD).
89 main _ :- coq.error "Usage: mlock Definition ...".
90 }}.
91
92 Elpi Export mlock.