Skip to content

Commit 142fb08

Browse files
committed
smart elaboration of contexts
We elaborate the last item by purging id_phant so that the term can type check even if the requirements of the factory were not postulated
1 parent 664e1d8 commit 142fb08

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

hb.elpi

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,31 +1857,39 @@ declare-old-constant (some C) :-
18571857
std.forall {coq.locate-all Id} (declare-old-located Id).
18581858
declare-old-constant _ :- true.
18591859

1860-
pred context->factory i:context-decl, o:factoryname.
1861-
context->factory (context-item IDT _ TTySkel none t\ context-item _ _ (TF t) none _\ context-end) GRF :- !,
1862-
coq.id->name IDT NameT,
1863-
std.assert-ok! (coq.elaborate-ty-skeleton TTySkel _ TTy) "context entry illtyped",
1864-
@pi-decl NameT TTy t\
1865-
std.assert! (factory? (TF t) (triple GRF _Params t))
1866-
"the last argument must be a factory applied to the type variable".
1867-
context->factory (context-item ID _ TSkel none Factories) GRF :- !,
1868-
coq.id->name ID Name,
1869-
std.assert-ok! (coq.elaborate-ty-skeleton TSkel _ T) "context entry illtyped",
1870-
@pi-decl Name T x\ context->factory (Factories x) GRF.
1871-
context->factory (context-item ID _ _ (some _) _) _ :-
1860+
pred elaborate-context-skel->factory i:context-decl, o:context-decl, o:factoryname, o:diagnostic.
1861+
elaborate-context-skel->factory
1862+
(context-item IDT IT TTySkel none t\ context-item IDF IF (TFSkel t) none _\ context-end)
1863+
(context-item IDT IT TTy none t\ context-item IDF IF (TFSkel t) none _\ context-end) GRF Diag
1864+
:- !, std.do-ok! Diag [
1865+
coq.elaborate-ty-skeleton TTySkel _ TTy,
1866+
(d\ coq.id->name IDT NameT),
1867+
(d\ @pi-decl NameT TTy t\ purge-id (TFSkel t) (TFSkel1 t), coq.elaborate-ty-skeleton (TFSkel1 t) _ (TF1 t) d),
1868+
(d\ @pi-decl NameT TTy t\ std.assert! (factory? (TF1 t) (triple GRF _Params t)) "the last argument must be a factory applied to the type variable"),
1869+
].
1870+
elaborate-context-skel->factory (context-item ID I TSkel none C) (context-item ID I T none C1) GRF Diag :- !, std.do-ok! Diag [
1871+
coq.elaborate-ty-skeleton TSkel _ T,
1872+
(d\ coq.id->name ID Name),
1873+
(d\ @pi-decl Name T x\ elaborate-context-skel->factory (C x) (C1 x) GRF d),
1874+
].
1875+
elaborate-context-skel->factory (context-item ID _ _ (some _) _) _ _ _ :-
18721876
coq.error "context item cannot be given a body:" ID.
18731877

1878+
pred purge-id i:term, o:term.
1879+
purge-id T T1 :-
1880+
(pi fresh t v\ copy {{lib:@hb.id lp:t lp:v}} fresh :- !) => copy T T1.
1881+
18741882
pred main-begin-declare-builders i:context-decl.
18751883
main-begin-declare-builders CtxSkel :- std.do! [
18761884
Name is "Builders_" ^ {term_to_string {new_int}}, % TODO?
1877-
context->factory CtxSkel GRF,
1885+
std.assert-ok! (elaborate-context-skel->factory CtxSkel Ctx GRF) "Context illtyped",
18781886
coq.env.begin-module Name none,
18791887
if (GRF = indt FRecord) (std.do! [
18801888
coq.env.begin-module "Super" none,
18811889
std.forall {coq.CS.canonical-projections FRecord} declare-old-constant,
18821890
coq.env.end-module _]) (true),
18831891
coq.env.begin-section Name,
1884-
builders-postulate-factories CtxSkel,
1892+
builders-postulate-factories Ctx,
18851893
].
18861894

18871895
pred postulate-factory-abbrev i:term, i:list term, i:id, i:factoryname, o:term.
@@ -1940,7 +1948,7 @@ builders-postulate-factories (context-item IDT _ TySkel none t\ context-item IDF
19401948

19411949
builders-postulate-factories (context-item ID _ TSkel none Factories) :- std.do! [
19421950
if-verbose (coq.say "HB: postulating" ID),
1943-
std.assert-ok! (coq.elaborate-ty-skeleton TSkel _ T) "builders-postulate-factorie: illtyped context",
1951+
std.assert-ok! (coq.elaborate-ty-skeleton TSkel _ T) "builders-postulate-factories: illtyped context",
19441952
if (var T) (coq.fresh-type T) true,
19451953
@local! => hb-add-const ID _ T @opaque! P, % no body, local -> a variable
19461954
TheParam = global (const P),

0 commit comments

Comments
 (0)