Skip to content

Commit 0803997

Browse files
committed
Managing Exports
1 parent 6230b10 commit 0803997

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

_CoqProject

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ tests/duplicate_structure.v
5252
tests/instance_params_no_type.v
5353
tests/test_CS_db_filtering.v
5454
tests/subtype.v
55+
tests/exports.v
5556

5657
-R . HB

hb.elpi

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,13 +1241,20 @@ main-declare-builder (builder _ SrcFactory TgtMixin B) FromClauses MoreFromClaus
12411241
].
12421242

12431243
% [export Module] exports a Module now adds it to the collection of
1244-
% modules to export in the end
1244+
% modules to export in the end of the current enclosing module,
1245+
% by the command HB.Exports
1246+
12451247
pred to-export o:modpath.
12461248
pred export i:modpath.
12471249
export Module :- !,
12481250
coq.env.export-module Module,
12491251
acc current (clause _ _ (to-export Module)).
12501252

1253+
pred main-reexport.
1254+
main-reexport :- !,
1255+
std.findall (to-export Module_) Mods,
1256+
std.forall Mods (x\ sigma y\ to-export y = x, coq.env.export-module y).
1257+
12511258
pred mk-mixin-fun i:list-w-params mixinname, i:term, o:term.
12521259
mk-mixin-fun ML X MLX :- mk-mixin-fun.then ML (p\ t\ body\ body = X) MLX.
12531260

@@ -1673,11 +1680,6 @@ main-declare-structure Module GRFSwP ClosureCheck :- std.do! [
16731680

16741681
coq.env.begin-module "Exports" none,
16751682
declare-sort-coercion Structure SortProjection,
1676-
if-verbose (coq.say "HB: exporting operations"),
1677-
ClassAlias => ClassRequires => Factories =>
1678-
export-operations Structure SortProjection ClassProjection MLwP [] EX MLToExport,
1679-
% TODO: issue an Arguments op T : rename, where T is the name written by
1680-
% the user in Definition foo := { T of ... }
16811683

16821684
if-verbose (coq.say "HB: exporting unification hints"),
16831685
ClassAlias => ClassRequires => Factories =>
@@ -1693,10 +1695,8 @@ main-declare-structure Module GRFSwP ClosureCheck :- std.do! [
16931695
(coq.say "declare-structure:" ClassName "should be an inductive", fail),
16941696

16951697
if-verbose (coq.say "HB: accumulating various props"),
1696-
std.map MLToExport (m\r\ r = mixin-first-class m ClassName) MixinFirstClass,
16971698
std.flatten [
1698-
MixinFirstClass, EX, Factories,
1699-
[ClassRequires], [ClassAlias], [is-structure Structure],
1699+
Factories, [ClassRequires], [ClassAlias], [is-structure Structure],
17001700
NewJoins, [class-def CurrentClass]
17011701
]
17021702
NewClauses,
@@ -1711,6 +1711,20 @@ main-declare-structure Module GRFSwP ClosureCheck :- std.do! [
17111711

17121712
export Exports,
17131713

1714+
if-verbose (coq.say "HB: exporting operations"),
1715+
ClassAlias => ClassRequires => Factories =>
1716+
export-operations Structure SortProjection ClassProjection MLwP [] EX MLToExport,
1717+
% TODO: issue an Arguments op T : rename, where T is the name written by
1718+
% the user in Definition foo := { T of ... }
1719+
1720+
if-verbose (coq.say "HB: start operations meta-data module ElpiOperations"),
1721+
ElpiOperationModName is "ElpiOperations" ^ {std.any->string {new_int}},
1722+
coq.env.begin-module ElpiOperationModName none,
1723+
std.map MLToExport (m\r\ r = mixin-first-class m ClassName) MixinFirstClass,
1724+
std.forall {std.append EX MixinFirstClass} (c\ acc current (clause _ _ c)),
1725+
coq.env.end-module ElpiOperations,
1726+
export ElpiOperations,
1727+
17141728
declare-factory-abbrev Module (factory-by-classname ClassName),
17151729

17161730
NewClauses => if-MC-compat (mc-compat-structure Module ModulePath MLToExport {w-params.nparams MLwP} ClassName ClassProjection),

structures.v

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,40 @@ main _ :- coq.error "Usage: HB.end.".
454454
Elpi Typecheck.
455455
Elpi Export HB.end.
456456

457+
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
458+
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
459+
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
460+
461+
(** [HB.exports] rexports Exports modules that have been accumulated by
462+
[HB.structure] (it contains canonical, coercions and ELPI metadata) *)
463+
464+
Elpi Command HB.export.
465+
Elpi Accumulate File "hb.elpi".
466+
Elpi Accumulate Db hb.db.
467+
Elpi Accumulate lp:{{
468+
main [str M] :- !, with-attributes (export {coq.locate-module M}).
469+
main _ :- coq.error "Usage: HB.export M.".
470+
}}.
471+
Elpi Typecheck.
472+
Elpi Export HB.export.
473+
474+
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
475+
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
476+
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
477+
478+
(** [HB.exports] rexports Exports modules that have been accumulated by
479+
[HB.structure] (it contains canonical, coercions and ELPI metadata) *)
480+
481+
Elpi Command HB.reexport.
482+
Elpi Accumulate File "hb.elpi".
483+
Elpi Accumulate Db hb.db.
484+
Elpi Accumulate lp:{{
485+
main [] :- !, with-attributes (main-reexport).
486+
main _ :- coq.error "Usage: HB.reexport.".
487+
}}.
488+
Elpi Typecheck.
489+
Elpi Export HB.reexport.
490+
457491
(*
458492
459493
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)

0 commit comments

Comments
 (0)