Is it possible to trigger TC resolution on a goal in a way that integrates multiple possible TC successes with ltac backtracking?
See https://gitlab.mpi-sws.org/iris/iris/-/issues/422#note_69507 for context.
AFAIK this is not possible yet, but it will be when the continuation of tc search is exposed to the user with Hint Cuts
ah, bummer
and I didnt understand the 2nd part^^ what does this have to do with Hint Cut?
You'll have full access to the tc state so you can implement multi-success backtrack any way you want.
what I think we'd like to do is something like
(* imagine goal is an evar of TC type *)
backtracking_tc_resolution;
match goal with |- ?x => unify x other_term end
now assuming the TC has two instances, resolving to one_term
and other_term
, then it should first use one_term
, go on in the ltac, then the match fails so it backtracks, now it tries the other_term
instance, and then it succeeds.
we can already do (refine one_term + refine other_term)
; this would be the TC-powered version of that
Yes, I believe that with the hint cut feature you could do that internally to the TC engine with the match goal as an Extern Hint
right but that doesnt sound like what we want
in such a simple case just having the multisuccess tc eauto should suffice, shouldn't it ?
we need this integrated in some larger ltac context
so, it's ltac driving TC search, not the other way around (like your proposal sounds)
ok I see
Pierre-Marie Pédrot said:
in such a simple case just having the multisuccess tc eauto should suffice, shouldn't it ?
yeah I think that's what I was trying to ask for :D
this is trivial to expose then, I wonder whether we don't have it somewhere in some intricate fashion
though @Robbert Krebbers notes that this would be incredibly fragile since TCs tend to backtrack like crazy as there's very little BT control for TC instances
yeah expect superexponential behaviours all over the place
this would just increase our demand for better control of TC backtracking :D
(like "nobacktrack" instances and things like that)
actually I don't see in the code where we cut the result of the tc search from the toplevel tactic
I would love to have a multi-sucess entry point to typeclass search! I wanted to have this in both Mtac2 and Ltac2 more times than I can count.
typeclasses eauto
is multisuccess. assert (Class A); [typeclasses eauto|kont]
works
And once (typeclasses eauto)
when you don't want to backtrack, ofc
Unless you're in a particular case where TC foo
is considered not to need backtracking (independent subgoal, in Prop, without existentials)
Does that mean @Ralf Jung 's original example already works?
Hm, no it doesn't
Class R := r : nat.
Hint Extern 0 R => exact 0 : typeclass_instances.
Hint Extern 10 R => exact 1 : typeclass_instances.
Lemma test : R.
typeclasses eauto;
match goal with |- ?x => unify x 1 end.
Defined.
Print test.
(* Prints 0. *)
but possibly for a silly reason: the match
is never even executed, since typeclasses eauto
already solves the goal...
Class R := r : nat.
Hint Extern 0 R => exact 0 : typeclass_instances.
Hint Extern 10 R => exact 1 : typeclass_instances.
Lemma test : True.
Proof.
unshelve (let x := open_constr:(_:R) in pose (k:=x)).
all:try typeclasses eauto;
let c := eval cbv in k in idtac c;unify c 1.
(* idtac says "0" then "1" *)
exact I.
Defined.
Print test.
(* let k := 1 in I *)
@Gaëtan Gilbert interesting. Why is that try
needed?
also, why does this still pick 0
?
Lemma test : R.
Proof.
all: try typeclasses eauto;
let c := eval cbv in k in idtac c;unify c 1.
Defined.
that seems very odd. somehow the presence of the other goal matters? but just having another goal via assert
doesn't suffice...
oh, that script makes no sense as k
is not bound. and I guess I cannot do match goal
in a all:
tactic...
the try is because tc eauto fails on the 2nd goal
the unify is run in the 2n goal
this still picks 0
:
Lemma test : True.
Proof.
unshelve (let x := open_constr:(_:R) in pose (k:=x)).
2: exact I.
all:try typeclasses eauto;
let c := eval cbv in k in idtac c;unify c 1.
Defined.
so the other goal needs to exist but it is also constantly in the way... that all seems rather hacky I have to say^^
that all seems rather hacky I have to say^^
I was just proving that tc eauto is multisuccess, not trying to make it useful
fair :D
Last updated: Feb 01 2023 at 11:04 UTC