Skip to content

Commit f86869f

Browse files
authored
Merge pull request #311 from proux01/grefclass
Support grefclass
2 parents 9d0903c + f152810 commit f86869f

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

HB/common/phant-abbreviation.elpi

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ fun-infer-type funclass N Ty (t\private.phant-term AL (Bo t)) Out :-
9292
coq.name-suffix N "ph" PhN,
9393
fun-implicit N Ty (t\private.phant-term [private.infer-type N funclass|AL]
9494
(fun PhN {{ lib:@hb.phantom (_ -> _) lp:t }} _\ Bo t)) Out.
95-
fun-infer-type C _ _ _ _ :- coq.error "HB: inference of parameters of call" C "not implemented yet".
95+
fun-infer-type (grefclass Class) N Ty (t\private.phant-term AL (Bo t)) Out :-
96+
coq.name-suffix N "ph" PhN, private.build-type-pattern Class Pat,
97+
fun-implicit N Ty (t\private.phant-term [private.infer-type N (grefclass Class)|AL]
98+
(fun PhN {{ lib:@hb.phantom lp:Pat lp:t }} _\ Bo t)) Out.
9699

97100
% TODO: this looks like a hack to remove
98101
pred append-fun-unify i:phant-term, o:phant-term.
@@ -180,12 +183,25 @@ build-abbreviation K F [infer-type N sortclass|AL] K'' (fun N _ AbbrevFx) :- !,
180183
build-abbreviation K F [infer-type N funclass|AL] K'' (fun N _ AbbrevFx) :- !,
181184
pi x\ build-abbreviation K {mk-app F [{{ lib:hb.Phantom (_ -> _) lp:x }}]} AL K' (AbbrevFx x),
182185
K'' is K' + 1.
183-
build-abbreviation _ _ [infer-type _ (grefclass _)|_] _ _ :- coq.error "TODO".
186+
build-abbreviation K F [infer-type N (grefclass Class)|AL] K'' (fun N _ AbbrevFx) :- !,
187+
build-type-pattern Class Pat,
188+
pi x\ build-abbreviation K {mk-app F [{{ lib:hb.Phantom lp:Pat lp:x }}]} AL K' (AbbrevFx x),
189+
K'' is K' + 1.
184190
build-abbreviation K F [implicit|AL] K' FAbbrev :- !,
185191
build-abbreviation K {mk-app F [_]} AL K' FAbbrev.
186192
build-abbreviation K F [unify|AL] K' FAbbrev :- !,
187193
build-abbreviation K {mk-app F [{{lib:@hb.id _ _}}]} AL K' FAbbrev.
188194

195+
% [build-type-pattern GR Pat] cheks that GR : forall x_1 ... x_n, Type
196+
% and returns Pat = GR _ ... _ (that is GR applied to n holes).
197+
% Note that n can be 0 when GR : Type.
198+
pred build-type-pattern i:gref, o:term.
199+
build-type-pattern GR Pat :- build-type-pattern.aux GR {coq.env.typeof GR} Pat.
200+
build-type-pattern.aux GR T {{ lp:Pat _ }} :- coq.unify-eq T (prod N S T') ok, !,
201+
@pi-decl N S x\ build-type-pattern.aux GR (T' x) Pat.
202+
build-type-pattern.aux GR T (global GR) :- coq.unify-eq T {{ Type }} ok, !.
203+
build-type-pattern.aux _ _ _ :- coq.error "HB: wrong carrier type".
204+
189205

190206
% [mk-phant-term F PF] states that
191207
% if F = fun p1 .. p_k T m_0 .. m_n => _

HB/common/synthesis.elpi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ infer-coercion-tgt (w-params.cons ID Ty F) CoeClass :-
154154
@pi-parameter ID Ty x\ infer-coercion-tgt (F x) CoeClass.
155155
infer-coercion-tgt (w-params.nil _ {{ Type }} _) sortclass.
156156
infer-coercion-tgt (w-params.nil _ {{ _ -> _ }} _) funclass.
157-
infer-coercion-tgt (w-params.nil _ _ _) _ :-
158-
coq.error "HB: coercion not to Sortclass or Funclass not supported yet.".
157+
infer-coercion-tgt (w-params.nil _ T _) (grefclass GR) :- coq.term->gref T GR.
159158

160159
pred w-args.check-key i:list term, i:term, i:list (w-args A), o:prop.
161160
w-args.check-key _PS _T [] true :- !.

_CoqProject.test-suite

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ tests/exports2.v
6363
tests/log_impargs_record.v
6464
tests/compress_coe.v
6565
tests/funclass.v
66+
tests/grefclass.v
6667
tests/local_instance.v
6768
tests/lock.v
6869
tests/interleave_context.v

tests/grefclass.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
From HB Require Import structures.
2+
3+
Definition pred T := T -> bool.
4+
5+
HB.mixin Record isPredNat (f : pred nat) := {}.
6+
7+
HB.structure Definition PredNat := {f of isPredNat f}.
8+
9+
Section TestSort.
10+
Variable p : PredNat.type.
11+
Check p : pred nat.
12+
End TestSort.

0 commit comments

Comments
 (0)