Skip to content

Commit 39a63e0

Browse files
committed
Automatically increase search depth when nothing found
Except if a search depth was explicitly provided, in which case we just enforce it.
1 parent bc6c25d commit 39a63e0

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

HB/howto.elpi

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
namespace howto {
55

6-
pred main-trm i:term, i:string, i:int.
6+
pred main-trm i:term, i:string, i:option int.
77
main-trm T STgt Depth :- coq.term->gref T GR, main-gref GR STgt Depth.
88

9-
pred main-str i:string, i:string, i:int.
9+
pred main-str i:string, i:string, i:option int.
1010
main-str S STgt Depth :- coq.locate S GR, main-gref GR STgt Depth.
1111

12-
pred main-gref i:gref, i:string, i:int.
12+
pred main-gref i:gref, i:string, i:option int.
1313
main-gref GR STgt Depth :- class-def (class _ GR _), !,
1414
private.mixins-in-structures [GR] MLSrc,
1515
main-from MLSrc STgt Depth.
@@ -18,15 +18,23 @@ main-gref GR STgt Depth :-
1818
private.mixins-in-structures SL MLSrc,
1919
main-from MLSrc STgt Depth.
2020

21-
pred main-from i:list mixinname, i:string, i:int.
21+
pred main-from i:list mixinname, i:string, i:option int.
2222
main-from MLSrc STgt Depth :-
2323
private.mixins-in-structures [{coq.locate STgt}] MLTgt,
2424
private.list-diff MLTgt MLSrc ML,
25-
if (ML = []) (coq.say "HB: nothing to do.")
26-
(private.paths-from-for-step MLSrc ML Depth R,
27-
if (R = [])
28-
(coq.error "HB: no solution found, try to increase search depth.")
29-
(private.pp-solutions R)).
25+
if (ML = []) (coq.say "HB: nothing to do.") (main-from.aux MLSrc ML Depth).
26+
main-from.aux MLSrc ML (some Depth) :- main-increase-depth MLSrc ML Depth false.
27+
main-from.aux MLSrc ML none :- main-increase-depth MLSrc ML 3 true.
28+
29+
pred main-increase-depth i:list mixinname, i:list mixinname, i:int, i:prop.
30+
main-increase-depth MLSrc ML Depth AutoIncrease :-
31+
private.paths-from-for-step MLSrc ML Depth R,
32+
if (not (R = [])) (private.pp-solutions R)
33+
(if AutoIncrease
34+
(Depth' is Depth + 1,
35+
coq.say "HB: no solution found at depth" Depth "looking at depth" Depth',
36+
main-increase-depth MLSrc ML Depth' true)
37+
(coq.error "HB: no solution found, try to increase search depth.")).
3038

3139

3240
/* ------------------------------------------------------------------------- */

structures.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,17 @@ Elpi Accumulate Db hb.db.
322322
Elpi Accumulate lp:{{
323323

324324
main [trm T, str STgt] :- !,
325-
with-attributes (with-logging (howto.main-trm T STgt 3)).
325+
with-attributes (with-logging (howto.main-trm T STgt none)).
326326
main [trm T, str STgt, int Depth] :- !,
327-
with-attributes (with-logging (howto.main-trm T STgt Depth)).
327+
with-attributes (with-logging (howto.main-trm T STgt (some Depth))).
328328
main [str T, str STgt] :- !,
329-
with-attributes (with-logging (howto.main-str T STgt 3)).
329+
with-attributes (with-logging (howto.main-str T STgt none)).
330330
main [str T, str STgt, int Depth] :- !,
331-
with-attributes (with-logging (howto.main-str T STgt Depth)).
331+
with-attributes (with-logging (howto.main-str T STgt (some Depth))).
332332
main [str STgt] :- !,
333-
with-attributes (with-logging (howto.main-from [] STgt 3)).
333+
with-attributes (with-logging (howto.main-from [] STgt none)).
334334
main [str STgt, int Depth] :- !,
335-
with-attributes (with-logging (howto.main-from [] STgt Depth)).
335+
with-attributes (with-logging (howto.main-from [] STgt (some Depth))).
336336

337337
main _ :-
338338
coq.error

0 commit comments

Comments
 (0)