Skip to content

Commit 486609f

Browse files
committed
bug correction: get_instances of a hint rule has priority none
1 parent 0369d06 commit 486609f

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

apps/tc/elpi/create_tc_predicate.elpi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ coq-mode->elpi mode-input (pr in "term").
1515
coq-mode->elpi mode-output (pr out "term").
1616

1717
pred modes-of-class i:gref, o:list (pair argument_mode string).
18-
modes-of-class ClassGr Modes :-
19-
coq.hints.modes ClassGr "typeclass_instances" CoqModesList,
18+
modes-of-class ClassGR Modes :-
19+
not (is-option-active {oTC-modes}),
20+
coq.hints.modes ClassGR "typeclass_instances" CoqModesList,
2021
not (CoqModesList = []),
21-
std.assert! (CoqModesList = [HintModesFst]) "At the moment we only allow TC with one Hint Mode",
22+
std.assert! (CoqModesList = [HintModesFst]) {calc ("At the moment we only allow TC with one Hint Mode (cause by class" ^ {coq.gref->string ClassGR} ^ ")")},
2223
std.append {std.map HintModesFst coq-mode->elpi} [pr out "term"] Modes.
23-
modes-of-class ClassGr Modes :-
24-
coq.env.typeof ClassGr ClassTy,
24+
modes-of-class ClassGR Modes :-
25+
coq.env.typeof ClassGR ClassTy,
2526
N is {coq.count-prods ClassTy} + 1, % + 1 for the solution
2627
list-init N (x\r\ r = (pr out "term")) Modes.
2728

apps/tc/elpi/tc_aux.elpi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ gref->pred-name Gr S :-
7272
(coq.gref->path Gr [Hd | Tl],
7373
std.fold Tl Hd (x\acc\r\ r is acc ^ "." ^ x) Path',
7474
Path is Path' ^ ".tc-"),
75-
S is "tc-" ^ Path ^ {coq.gref->id Gr}.
75+
% CAVEAT : Non-ascii caractars can't be part of a pred
76+
% name, we replace ö with o
77+
rex.replace "ö" "o" {coq.gref->id Gr} GrStr,
78+
S is "tc-" ^ Path ^ GrStr.
7679

7780
pred no-backtrack i:list prop, o:list prop.
7881
no-backtrack [] [].

apps/tc/theories/db.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Elpi Db tc_options.db lp:{{
2626
pred oTC-use-pattern-fragment-compiler o:list string.
2727
oTC-use-pattern-fragment-compiler ["TC", "CompilerWithPatternFragment"].
2828

29+
pred oTC-modes o:list string.
30+
oTC-modes ["TC", "Disable", "Modes"].
31+
2932
pred is-option-active i:list string.
3033
is-option-active Opt :-
3134
coq.option.get Opt (coq.option.bool tt).

apps/tc/theories/tc.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Elpi Query lp:{{
4747
sigma Options\
4848
Options = [oTC-ignore-eta-reduction, oTC-resolution-time,
4949
oTC-clauseNameShortName, oTC-time-refine, oTC-debug,
50-
oTC-use-pattern-fragment-compiler],
50+
oTC-use-pattern-fragment-compiler, oTC-modes],
5151
std.forall Options (x\ sigma Args\ x Args,
5252
coq.option.add Args (coq.option.bool ff) ff).
5353
}}.

elpi-builtin.elpi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,10 @@ pred fold i:list B, i:A, i:(B -> A -> A -> prop), o:A.
537537
fold [] A _ A.
538538
fold [X|XS] A F R :- F X A A1, fold XS A1 F R.
539539

540+
pred fold-right i:list B, i:A, i:(B -> A -> A -> prop), o:A.
541+
fold-right [] A _ A.
542+
fold-right [X|XS] A F R :- fold-right XS A F A', F X A' R.
543+
540544
pred fold2 i:list C, i:list B, i:A, i:(C -> B -> A -> A -> prop), o:A.
541545
fold2 [] [_|_] _ _ _ :- fatal-error "fold2 on lists of different length".
542546
fold2 [_|_] [] _ _ _ :- fatal-error "fold2 on lists of different length".

src/coq_elpi_builtins.ml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ let tc_instance = let open Conv in let open API.AlgebraicData in declare {
485485
M (fun ~ok ~ko { implementation; priority } -> ok implementation priority));
486486
]} |> CConv.(!<)
487487

488-
let get_instance_prio gr env sigma (info : 'a Typeclasses.hint_info_gen) : tc_priority =
489-
match info.hint_priority with
488+
let get_instance_prio gr env sigma (hint_priority : int option) : tc_priority =
489+
match hint_priority with
490490
| Some p -> UserGiven p
491491
| None ->
492492
let rec nb_hyp sigma c = match EConstr.kind sigma c with
@@ -533,14 +533,20 @@ let get_instances (env: Environ.env) (emap: Evd.evar_map) tc : type_class_instan
533533
| Constr.Const (a, _) -> Some (Names.GlobRef.ConstRef a)
534534
| Constr.Construct (a, _) -> Some (Names.GlobRef.ConstructRef a)
535535
| _ -> None) constrs in
536-
let inst_of_tc =
536+
let inst_of_tc = (* contains all the instances of a type class *)
537537
Typeclasses.instances_exn env emap tc |>
538538
List.fold_left (fun m i -> GlobRef.Map.add i.Typeclasses.is_impl i m) GlobRef.Map.empty in
539-
let instances_grefs2istance x =
539+
let instances_grefs2istance inst_gr : type_class_instance =
540540
let open Typeclasses in
541-
let inst = GlobRef.Map.find x inst_of_tc in
542-
let priority = get_instance_prio x env sigma inst.is_info in
543-
{ implementation = x; priority } in
541+
let user_hint_prio =
542+
(* Note: in general we deal with an instance I of a type class. Here we look if
543+
the user has given a priority to I. However, external hints are
544+
not in the inst_of_tc (the Not_found exception)*)
545+
try (GlobRef.Map.find inst_gr inst_of_tc).is_info.hint_priority
546+
with Not_found -> None in
547+
let priority = get_instance_prio inst_gr env sigma user_hint_prio in
548+
{ implementation = inst_gr; priority }
549+
in
544550
List.map instances_grefs2istance instances_grefs
545551

546552
type scope = ExecutionSite | CurrentModule | Library

0 commit comments

Comments
 (0)