Skip to content

Commit ba7b6fd

Browse files
committed
separate synterp phase
1 parent f62e5cb commit ba7b6fd

File tree

11 files changed

+271
-172
lines changed

11 files changed

+271
-172
lines changed

HB/builders.elpi

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ namespace builders {
55

66
pred begin i:context-decl.
77
begin CtxSkel :- std.do! [
8-
Name is "Builders_" ^ {std.any->string {new_int}}, % TODO?
8+
std.assert!(coq.next-synterp-action (begin-module Name)) "synterp code did not open module",
99
if-verbose (coq.say {header} "begin module for builders"),
1010
log.coq.env.begin-module Name none,
1111

1212
builders.private.factory CtxSkel IDF GRF,
1313

1414
% the Super module to access operations/axioms shadowed by the ones in the factory
15+
if-verbose (coq.say {header} "begin module Super"),
16+
log.coq.env.begin-module "Super" none,
1517
if (GRF = indt FRecord) (std.do! [
16-
if-verbose (coq.say {header} "begin module Super"),
17-
log.coq.env.begin-module "Super" none,
1818
std.forall {coq.env.projections FRecord}
1919
builders.private.declare-shadowed-constant,
20-
log.coq.env.end-module-name "Super" _,
21-
if-verbose (coq.say {header} "ended module Super")
22-
]) (true),
20+
]) true,
21+
if-verbose (coq.say {header} "ended module Super"),
22+
log.coq.env.end-module-name "Super" _,
2323

2424
log.coq.env.begin-section Name,
2525
if-verbose (coq.say {header} "postulating factories"),
@@ -31,7 +31,7 @@ begin CtxSkel :- std.do! [
3131
% "end" is a keyword, be put it in the namespace by hand
3232
pred builders.end.
3333
builders.end :- std.do! [
34-
current-mode (builder-from _ _ GR ModName),
34+
current-mode (builder-from _ _ _ ModName),
3535

3636
log.coq.env.end-section-name ModName,
3737

@@ -48,8 +48,7 @@ builders.end :- std.do! [
4848
std.filter ExportClauses (export.private.abbrev-in-module CurModPath) ExportClausesFiltered,
4949

5050
% TODO: Do we need this module?
51-
gref->modname GR 1 "" M,
52-
Name is M ^ "_Exports",
51+
std.assert!(coq.next-synterp-action (begin-module Name)) "synterp code did not open module",
5352
log.coq.env.begin-module Name none,
5453

5554
acc-clauses current Clauses,

HB/common/stdpp.elpi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ constraint print-ctx mixin-src {
118118

119119
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120120

121-
% approximation, it should be logical path, not the file name
122-
pred coq.env.current-library o:string.
123-
coq.env.current-library L :- loc.fields {get-option "elpi.loc"} L _ _ _ _.
124-
coq.env.current-library "dummy.v".
125-
126121
pred coq.term-is-gref? i:term, o:gref.
127122
coq.term-is-gref? (global GR) GR :- !.
128123
coq.term-is-gref? (pglobal GR _) GR :- !.

HB/common/utils-synterp.elpi

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* Hierarchy Builder: algebraic hierarchies made easy
2+
This software is released under the terms of the MIT license */
3+
4+
% runs P in a context where Coq #[attributes] are parsed
5+
pred with-attributes i:prop.
6+
with-attributes P :-
7+
attributes A,
8+
coq.parse-attributes A [
9+
att "verbose" bool,
10+
att "mathcomp" bool,
11+
att "mathcomp.axiom" string,
12+
att "short.type" string,
13+
att "short.pack" string,
14+
att "key" string,
15+
att "arg_sort" bool,
16+
att "log" bool,
17+
att "log.raw" bool,
18+
att "compress_coercions" bool,
19+
att "export" bool,
20+
att "skip" string,
21+
att "local" bool,
22+
att "fail" bool,
23+
att "doc" string,
24+
att "primitive" bool,
25+
att "non_forgetful_inheritance" bool,
26+
att "hnf" bool,
27+
] Opts, !,
28+
Opts => (save-docstring, P).
29+
30+
pred if-verbose i:prop.
31+
if-verbose P :- get-option "verbose" tt, !, P.
32+
if-verbose _.
33+
34+
% header of if-verbose messages
35+
pred header o:string.
36+
header Msg :- Msg is "[" ^ {std.any->string {gettimeofday}} ^ "] HB: ".
37+
38+
% approximation, it should be logical path, not the file name
39+
pred coq.env.current-library o:string.
40+
coq.env.current-library L :- loc.fields {get-option "elpi.loc"} L _ _ _ _.
41+
coq.env.current-library "dummy.v".
42+
43+
% this is only declared in hb.db, this declaration is only to avoid a warning
44+
pred docstring o:loc, o:string.
45+
46+
pred save-docstring.
47+
save-docstring :-
48+
if (get-option "elpi.loc" Loc, get-option "elpi.phase" "interp", get-option "doc" Txt)
49+
(coq.elpi.accumulate _ "hb.db" (clause _ _ (docstring Loc Txt)))
50+
true.
51+
52+
pred compute-filter i:option string, o:list string.
53+
compute-filter none [].
54+
compute-filter (some S) MFilter :- % S is a component of the current modpath
55+
coq.env.current-path P,
56+
rex_split "\\." S L,
57+
compute-filter.aux P L MFilter, !.
58+
compute-filter (some S) MFilter :-
59+
coq.locate-module S M,
60+
coq.modpath->path M MFilter.
61+
compute-filter.aux [S|_] [S] [S] :- !.
62+
compute-filter.aux [S|XS] [S|SS] [S|YS] :- compute-filter.aux XS SS YS.
63+
compute-filter.aux [X|XS] L [X|YS] :- compute-filter.aux XS L YS.
64+
65+
pred list-uniq i:list A, o:list A.
66+
pred list-uniq.seen i:A.
67+
list-uniq [] [].
68+
list-uniq [X|XS] YS :- list-uniq.seen X, !, list-uniq XS YS.
69+
list-uniq [X|XS] [X|YS] :- list-uniq.seen X => list-uniq XS YS.
70+
71+
pred record-decl->id i:indt-decl, o:id.
72+
record-decl->id (parameter _ _ _ D) N :- pi p\ record-decl->id (D p) N.
73+
record-decl->id (record N _ _ _) N.

HB/common/utils.elpi

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,10 @@
33

44

55
% This file contains some HB specific utilities
6+
accumulate HB/common/utils-synterp.
67

78
shorten coq.{ term->gref, subst-fun, safe-dest-app, mk-app, mk-eta, subst-prod }.
89

9-
% HACK: move to coq-elpi proper, remove when coq-elpi > 1.9.2
10-
type attmap attribute-type.
11-
12-
% runs P in a context where Coq #[attributes] are parsed
13-
pred with-attributes i:prop.
14-
with-attributes P :-
15-
attributes A,
16-
17-
% HACK: move to coq-elpi proper, remove when coq-elpi > 1.9.2
18-
(pi S L AS Prefix R R1 Map PS\
19-
parse-attributes.aux [attribute S (node L)|AS] Prefix R :-
20-
if (Prefix = "") (PS = S) (PS is Prefix ^ "." ^ S), supported-attribute (att PS attmap), !,
21-
parse-attributes.aux AS Prefix R1,
22-
(pi x\ supported-attribute (att x string) :- !) => parse-attributes.aux L "" Map,
23-
std.append R1 [get-option PS Map] R
24-
) =>
25-
26-
coq.parse-attributes A [
27-
att "verbose" bool,
28-
att "mathcomp" bool,
29-
att "mathcomp.axiom" string,
30-
att "short.type" string,
31-
att "short.pack" string,
32-
att "key" string,
33-
att "arg_sort" bool,
34-
att "log" bool,
35-
att "log.raw" bool,
36-
att "compress_coercions" bool,
37-
att "export" bool,
38-
att "skip" string,
39-
att "local" bool,
40-
att "fail" bool,
41-
att "doc" string,
42-
att "primitive" bool,
43-
att "non_forgetful_inheritance" bool,
44-
att "hnf" bool,
45-
] Opts, !,
46-
Opts => (save-docstring, P).
47-
48-
pred if-verbose i:prop.
49-
if-verbose P :- get-option "verbose" tt, !, P.
50-
if-verbose _.
51-
52-
% header of if-verbose messages
53-
pred header o:string.
54-
header Msg :- Msg is "[" ^ {std.any->string {gettimeofday}} ^ "] HB: ".
55-
5610
pred if-arg-sort i:prop.
5711
if-arg-sort P :- get-option "arg_sort" tt, !, P.
5812
if-arg-sort _.
@@ -78,12 +32,6 @@ pred acc-clauses i:scope, i:list prop.
7832
acc-clauses Scope CL :- coq.elpi.accumulate-clauses Scope "hb.db" {std.map CL (c\r\ r = clause _ _ c)}.
7933
*/
8034

81-
pred save-docstring.
82-
save-docstring :-
83-
if (get-option "elpi.loc" Loc, get-option "doc" Txt)
84-
(acc-clause _ (docstring Loc Txt))
85-
true.
86-
8735
% TODO: Should this only be used for gref that are factories? (and check in the first/second branch so?)
8836
% Should we make this an HO predicate, eg "located->gref S L is-factory? GR"
8937
% TODO: rename since this is HB specific and is expected to return a factory

HB/instance.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [
3535
if-verbose (coq.say "HB: skipping section opening"),
3636
SectionBody = Body
3737
) (
38-
SectionName is "hb_instance_" ^ {std.any->string {new_int}},
38+
std.assert! (coq.next-synterp-action (begin-section SectionName)) "synterp code did not open section",
3939
log.coq.env.begin-section SectionName,
4040
private.postulate-arity TyWP [] Body SectionBody SectionTy
4141
),

HB/lock.elpi

Lines changed: 0 additions & 44 deletions
This file was deleted.

HB/structure.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ declare Module BSkel Sort :- std.do! [
170170

171171
if-verbose (coq.say {header} "operations meta-data module: ElpiOperations"),
172172

173-
ElpiOperationModName is "ElpiOperations" ^ {std.any->string {new_int}},
173+
ElpiOperationModName is {calc (Module ^ "ElpiOperations")},
174174
log.coq.env.begin-module ElpiOperationModName none,
175175
acc-clauses current {std.append EX MixinFirstClass},
176176
log.coq.env.end-module-name ElpiOperationModName ElpiOperations,

examples/hulk.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ rewrite new_concept.unlock.
269269
Time Fail reflexivity. (* takes 7s, the original body is restored *)
270270
Abort.
271271

272-
Print Module Type new_conceptLocked.
272+
Print Module Type new_concept_Locked.
273273
Print Module new_concept.
274274
(*
275275
Module Type new_conceptLocked = Sig

0 commit comments

Comments
 (0)