Skip to content

Commit c64752a

Browse files
eponiergares
authored andcommitted
more fresh names
1 parent b41a14c commit c64752a

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

apps/derive/elpi/param1.elpi

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ reali-store N X XR :- !,
108108
Args = [_, _, X, XR],
109109
T1 = app [{{ lib:@param1.store_reali }}|Args],
110110
std.assert-ok! (coq.typecheck T1 T2) "reali-store: T1 illtyped",
111-
coq.env.add-const Nreali T1 T2 _ GR,
111+
coq.ensure-fresh-global-id Nreali FNreali,
112+
coq.env.add-const FNreali T1 T2 _ GR,
112113
@global! => coq.TC.declare-instance (const GR) 0.
113114

114115
pred reali-store-indc i:string, i:constructor, i:constructor.
@@ -134,7 +135,8 @@ dispatch (const GR) Prefix Clauses :- !, do! [
134135
std.assert-ok! (coq.typecheck VR VRTy) "param1: illtyped constant",
135136
std.assert-ok! (coq.unify-leq VRTy TyRV) "param1: constant does not have the right type",
136137

137-
coq.env.add-const Name VR TyRV _ TermR,
138+
coq.ensure-fresh-global-id Name FName,
139+
coq.env.add-const FName VR TyRV _ TermR,
138140

139141
reali-store Name Term (global (const TermR)),
140142

@@ -166,8 +168,9 @@ dispatch (indt GR) Prefix Clauses :- !, do! [
166168

167169
NewName is Prefix ^ {coq.gref->id (indt GR)},
168170

171+
coq.ensure-fresh-global-id NewName FNewName,
169172
coq.build-indt-decl
170-
(pr new_name NewName) tt LnoR LnoR {coq.subst-fun [Ind] TyR} KnamesR KtypesR DeclR
173+
(pr new_name FNewName) tt LnoR LnoR {coq.subst-fun [Ind] TyR} KnamesR KtypesR DeclR
171174
),
172175

173176
std.assert-ok! (coq.typecheck-indt-decl DeclR) "derive.param1 generates illtyped inductive",
@@ -176,7 +179,8 @@ dispatch (indt GR) Prefix Clauses :- !, do! [
176179

177180
reali-store NewName Ind (global (indt GRR)),
178181
coq.env.indt GRR _ _ _ _ RealNamesR _,
179-
forall2 Knames RealNamesR (reali-store-indc NewName),
182+
Prefix1 is NewName ^ "_",
183+
forall2 Knames RealNamesR (reali-store-indc Prefix1),
180184
C1 = (reali Ind (global (indt GRR)) :- !),
181185
coq.elpi.accumulate _ "derive.param1.db" (clause _ (before "reali:fail") C1),
182186
C2 = (realiR Ind (global (indt GRR)) :- !),
@@ -192,7 +196,8 @@ dispatch (indc _) _ _ :-
192196
coq.error "derive.param1: cannot translate a constructor".
193197

194198
pred main i:gref, i:string, o:list prop.
195-
main T Out Clauses :- dispatch T Out Clauses.
199+
main T _ Clauses :-
200+
dispatch T "is_" Clauses.
196201

197202
}
198203

apps/derive/elpi/param2.elpi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ store-param N X X1 XR :- !,
133133
Args = [_, _, _, X, X1, XR],
134134
T1 = app [{{ lib:@param2.store_param }}|Args],
135135
std.assert-ok! (coq.typecheck T1 T2) "store-param: T1 illtyped",
136-
coq.env.add-const Nparam T1 T2 _ C,
136+
coq.ensure-fresh-global-id Nparam FNparam,
137+
coq.env.add-const FNparam T1 T2 _ C,
137138
@global! => coq.TC.declare-instance (const C) 0.
138139

139140
pred store-param-indc i:string, i:constructor, i:constructor.
@@ -159,7 +160,8 @@ dispatch (const GR as C) Suffix Clauses :- do! [
159160
std.assert-ok! (coq.typecheck XR XRTy) "param2: illtyped constant",
160161
std.assert-ok! (coq.unify-leq XRTy TyRTermTerm) "param2: constant does not have the right type",
161162

162-
coq.env.add-const NameR XR TyRTermTerm _ TermR,
163+
coq.ensure-fresh-global-id NameR FNameR,
164+
coq.env.add-const FNameR XR TyRTermTerm _ TermR,
163165

164166
store-param NameR Term Term (global (const TermR)),
165167

@@ -175,14 +177,15 @@ dispatch (indt I as GR) Suffix Clauses :- do! [
175177
Ind = global GR,
176178
coq.env.indt I IsInd Lno Luno Ty Knames Ktypes,
177179
NameR is {coq.gref->id GR} ^ Suffix,
180+
coq.ensure-fresh-global-id NameR FNameR,
178181
map Knames (rename-indc Suffix) KnamesR,
179182

180183
std.map Knames (k\r\ r = global (indc k)) Ks,
181184
pi new_name\ sigma KtypesR TyR\ (
182185
(param-indt I IsInd Lno Luno Ty Ks Ktypes
183186
new_name IsIndR LnoR LunoR TyR KtypesR),
184187
coq.build-indt-decl
185-
(pr new_name NameR) IsIndR LnoR LunoR {coq.subst-fun [Ind, Ind] TyR} KnamesR KtypesR DeclR
188+
(pr new_name FNameR) IsIndR LnoR LunoR {coq.subst-fun [Ind, Ind] TyR} KnamesR KtypesR DeclR
186189
),
187190

188191
std.assert-ok! (coq.typecheck-indt-decl DeclR) "derive.param2 generates illtyped term",
@@ -210,7 +213,8 @@ dispatch (indc _) _ _ :-
210213
coq.error "derive.param2: cannot translate a constructor".
211214

212215
pred main i:gref, i:string, o:list prop.
213-
main T Out Clauses :- dispatch T Out Clauses.
216+
main T _ Clauses :-
217+
dispatch T "_R" Clauses.
214218

215219
}
216220

apps/derive/theories/derive/param1.v

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@ Elpi Accumulate File paramX.
8383
Elpi Accumulate File param1.
8484
Elpi Accumulate Db derive.param1.db.
8585
Elpi Accumulate lp:{{
86-
main [str I, str O] :- !, coq.locate I GR, derive.param1.main GR O _.
87-
main [str I] :- !, coq.locate I GR, derive.param1.main GR "is_" _.
86+
main [str I] :- !, coq.locate I GR, derive.param1.main GR "" _.
8887
main _ :- usage.
8988

90-
usage :- coq.error "Usage: derive.param1 <object name> [<output prefix>]".
89+
usage :- coq.error "Usage: derive.param1 <object name>".
9190
}}.
9291
Elpi Typecheck.
9392

@@ -106,6 +105,6 @@ Elpi Accumulate derive lp:{{
106105
pred derive.on_param1 i:inductive, i:(inductive -> string -> list prop -> prop), i:string, o:list prop.
107106
derive.on_param1 T F N C :- reali (global (indt T)) (global (indt P)), !, F P N C.
108107

109-
derivation T Prefix (derive "param1" (derive.param1.main T N ) (reali-done T)) :- N is Prefix ^ "is_".
108+
derivation T N (derive "param1" (derive.param1.main T N ) (reali-done T)).
110109

111110
}}.

apps/derive/theories/derive/param2.v

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ Elpi Accumulate File paramX.
4646
Elpi Accumulate File param2.
4747
Elpi Accumulate Db derive.param2.db.
4848
Elpi Accumulate lp:{{
49-
main [str I, str O] :- !, coq.locate I GR, derive.param2.main GR O _.
50-
main [str I] :- !, coq.locate I GR, derive.param2.main GR "_R" _.
49+
main [str I] :- !, coq.locate I GR, derive.param2.main GR "" _.
5150
main _ :- usage.
5251

53-
usage :- coq.error "Usage: derive.param2 <object name> [<output suffix>]".
52+
usage :- coq.error "Usage: derive.param2 <object name>".
5453
}}.
5554
Elpi Typecheck.
5655

@@ -59,7 +58,7 @@ Elpi Accumulate derive Db derive.param2.db.
5958
Elpi Accumulate derive File param2.
6059
Elpi Accumulate derive lp:{{
6160

62-
derivation T Prefix (derive "param2" (derive.param2.main T N) (param-done T)) :- N is Prefix ^ "_R".
61+
derivation T N (derive "param2" (derive.param2.main T N) (param-done T)).
6362

6463
}}.
6564

0 commit comments

Comments
 (0)