11(* -------------------------------------------------------------------- *)
22open EcUtils
3+ open EcMaps
34open EcLocation
45open EcIdent
56open EcSymbols
@@ -99,17 +100,21 @@ module LowApply = struct
99100 in List. for_all h_eqs ld1.h_local
100101
101102 (* ------------------------------------------------------------------ *)
102- let rec check_pthead (pt : pt_head ) (tc : ckenv ) =
103+ let rec check_pthead (pt : pt_head ) (subgoals : _ ) ( tc : ckenv ) =
103104 let hyps = hyps_of_ckenv tc in
104105
105106 match pt with
106- | PTCut f -> begin
107+ | PTCut ( f , cutsolve ) -> begin
107108 match tc with
108- | `Hyps ( _ , _ ) -> (PTCut f, f )
109+ | `Hyps ( _ , _ ) -> (PTCut ( f, None ), f, subgoals) (* FIXME * )
109110 | `Tc (tc , _ ) ->
110111 (* cut - create a dedicated subgoal *)
111112 let handle = RApi. newgoal tc ~hyps f in
112- (PTHandle handle, f)
113+ let subgoals =
114+ ofold
115+ (fun cutsolve subgoals -> DMap. add handle cutsolve subgoals)
116+ subgoals cutsolve
117+ in (PTHandle handle, f, subgoals)
113118 end
114119
115120 | PTHandle hd -> begin
@@ -121,38 +126,38 @@ module LowApply = struct
121126 (* proof reuse - fetch corresponding subgoal*)
122127 if not (sub_hyps subgoal.g_hyps (hyps_of_ckenv tc)) then
123128 raise InvalidProofTerm ;
124- (pt, subgoal.g_concl)
129+ (pt, subgoal.g_concl, subgoals )
125130 end
126131
127132 | PTLocal x -> begin
128133 let hyps = hyps_of_ckenv tc in
129- try (pt, LDecl. hyp_by_id x hyps)
134+ try (pt, LDecl. hyp_by_id x hyps, subgoals )
130135 with LDecl. LdeclError _ -> raise InvalidProofTerm
131136 end
132137
133138 | PTGlobal (p , tys ) ->
134139 (* FIXME: poor API ==> poor error recovery *)
135140 let env = LDecl. toenv (hyps_of_ckenv tc) in
136- (pt, EcEnv.Ax. instanciate p tys env)
141+ (pt, EcEnv.Ax. instanciate p tys env, subgoals )
137142
138143 | PTTerm pt ->
139- let pt, ax = check `Elim pt tc in
140- (PTTerm pt, ax)
144+ let pt, ax, subgoals = check_ `Elim pt subgoals tc in
145+ (PTTerm pt, ax, subgoals )
141146
142147 (* ------------------------------------------------------------------ *)
143- and check (mode : [`Intro | `Elim] ) (pt : proofterm ) (tc : ckenv ) =
148+ and check_ (mode : [`Intro | `Elim] ) (pt : proofterm ) ( subgoals : _ ) (tc : ckenv ) =
144149 let hyps = hyps_of_ckenv tc in
145150 let env = LDecl. toenv hyps in
146151
147- let rec check_args (sbt , ax , nargs ) args =
152+ let rec check_args (sbt , ax , nargs ) subgoals args =
148153 match args with
149- | [] -> (Fsubst. f_subst sbt ax, List. rev nargs)
154+ | [] -> (Fsubst. f_subst sbt ax, List. rev nargs, subgoals )
150155
151156 | arg :: args ->
152- let ((sbt, ax), narg) = check_arg (sbt, ax) arg in
153- check_args (sbt, ax, narg :: nargs) args
157+ let ((sbt, ax), narg, subgoals ) = check_arg (sbt, ax) subgoals arg in
158+ check_args (sbt, ax, narg :: nargs) subgoals args
154159
155- and check_arg (sbt , ax ) arg =
160+ and check_arg (sbt , ax ) subgoals arg =
156161 let check_binder (x , xty ) f =
157162 let xty = Fsubst. gty_subst sbt xty in
158163
@@ -186,43 +191,53 @@ module LowApply = struct
186191 | None -> EcCoreGoal. ptcut f1
187192 | Some subpt -> subpt
188193 in
189- let subpt, subax = check mode subpt tc in
194+ let subpt, subax, subgoals = check_ mode subpt subgoals tc in
190195 if not (EcReduction. is_conv hyps f1 subax) then
191196 raise InvalidProofTerm ;
192- ((sbt, f2), PASub (Some subpt))
197+ ((sbt, f2), PASub (Some subpt), subgoals )
193198
194199 | Some (`Forall (x , xty , f )), _ ->
195- (check_binder (x, xty) f, arg)
200+ (check_binder (x, xty) f, arg, subgoals )
196201
197202 | _ , _ ->
198203 if Fsubst. is_subst_id sbt then
199204 raise InvalidProofTerm ;
200- check_arg (Fsubst. f_subst_id, Fsubst. f_subst sbt ax) arg
205+ check_arg (Fsubst. f_subst_id, Fsubst. f_subst sbt ax) subgoals arg
201206 end
202207
203208 | `Intro -> begin
204209 match TTC. destruct_exists hyps ax with
205- | Some (`Exists (x , xty , f )) -> (check_binder (x, xty) f, arg)
210+ | Some (`Exists (x , xty , f )) ->
211+ (check_binder (x, xty) f, arg, subgoals)
206212 | None ->
207213 if Fsubst. is_subst_id sbt then
208214 raise InvalidProofTerm ;
209- check_arg (Fsubst. f_subst_id, Fsubst. f_subst sbt ax) arg
215+ check_arg (Fsubst. f_subst_id, Fsubst. f_subst sbt ax) subgoals arg
210216 end
211217 in
212218
213219 match pt with
214220 | PTApply pt ->
215- let (nhd, ax) = check_pthead pt.pt_head tc in
216- let ax, nargs = check_args (Fsubst. f_subst_id, ax, [] ) pt.pt_args in
217- (PTApply { pt_head = nhd; pt_args = nargs }, ax)
221+ let (nhd, ax, subgoals) = check_pthead pt.pt_head subgoals tc in
222+ let ax, nargs, subgoals =
223+ check_args (Fsubst. f_subst_id, ax, [] ) subgoals pt.pt_args in
224+ (PTApply { pt_head = nhd; pt_args = nargs }, ax, subgoals)
218225
219226 | PTQuant (bd , pt ) -> begin
220227 match mode with
221228 | `Intro -> raise InvalidProofTerm
222229 | `Elim ->
223- let pt, ax = check `Elim pt tc in
224- (PTQuant (bd, pt), f_forall [bd] ax)
230+ let pt, ax, subgoals = check_ `Elim pt subgoals tc in
231+ (PTQuant (bd, pt), f_forall [bd] ax, subgoals )
225232 end
233+
234+ let check_with_cutsolve (mode : [`Intro | `Elim] ) (pt : proofterm ) (tc : ckenv ) =
235+ check_ mode pt DMap. empty tc
236+
237+ let check (mode : [`Intro | `Elim] ) (pt : proofterm ) (tc : ckenv ) =
238+ let pt, f, subgoals = check_ mode pt DMap. empty tc in
239+ assert (DMap. is_empty subgoals);
240+ (pt, f)
226241end
227242
228243(* -------------------------------------------------------------------- *)
@@ -619,10 +634,16 @@ let t_intro_sx_seq id tt tc =
619634 FApi. t_focus (tt id) tc
620635
621636(* -------------------------------------------------------------------- *)
622- let tt_apply (pt : proofterm ) (tc : tcenv ) =
637+ type cutsolver = {
638+ smt : FApi .backward ;
639+ done_ : FApi .backward ;
640+ }
641+
642+ (* -------------------------------------------------------------------- *)
643+ let tt_apply ?(cutsolver : cutsolver option ) (pt : proofterm ) (tc : tcenv ) =
623644 let (hyps, concl) = FApi. tc_flat tc in
624- let tc, (pt, ax) =
625- RApi. to_pure (fun tc -> LowApply. check `Elim pt (`Tc (tc, None ))) tc in
645+ let tc, (pt, ax, subgoals ) =
646+ RApi. to_pure (fun tc -> LowApply. check_with_cutsolve `Elim pt (`Tc (tc, None ))) tc in
626647
627648 if not (EcReduction. is_conv hyps ax concl) then begin
628649 (*
@@ -636,7 +657,25 @@ let tt_apply (pt : proofterm) (tc : tcenv) =
636657 raise InvalidGoalShape
637658 end ;
638659
639- FApi. close tc (VApply pt)
660+ let tc = FApi. close tc (VApply pt) in
661+
662+ match cutsolver with
663+ | None ->
664+ assert (DMap. is_empty subgoals);
665+ tc
666+
667+ | Some cutsolver -> begin
668+ Format. eprintf " %d@." (DMap. cardinal subgoals);
669+ FApi. t_onall (fun tc ->
670+ let tactic =
671+ match DMap. find_opt (FApi. tc1_handle tc) subgoals with
672+ | Some `Smt -> cutsolver.smt
673+ | Some `Done -> cutsolver.done_
674+ | Some `DoneSmt -> FApi. t_seq cutsolver.done_ cutsolver.smt
675+ | None -> t_id in
676+ tactic tc
677+ ) tc
678+ end
640679
641680(* -------------------------------------------------------------------- *)
642681let tt_apply_hyp (x : EcIdent.t ) ?(args = [] ) ?(sk = 0 ) tc =
@@ -663,8 +702,8 @@ let tt_apply_hd (hd : handle) ?(args = []) ?(sk = 0) tc =
663702 tt_apply pt tc
664703
665704(* -------------------------------------------------------------------- *)
666- let t_apply (pt : proofterm ) (tc : tcenv1 ) =
667- tt_apply pt (FApi. tcenv_of_tcenv1 tc)
705+ let t_apply ?( cutsolver : cutsolver option ) (pt : proofterm ) (tc : tcenv1 ) =
706+ tt_apply ?cutsolver pt (FApi. tcenv_of_tcenv1 tc)
668707
669708(* -------------------------------------------------------------------- *)
670709let t_apply_hyp (x : EcIdent.t ) ?args ?sk tc =
0 commit comments