@@ -362,84 +362,86 @@ module LowRewrite = struct
362362 raise (RewriteError LRW_CannotInfer )
363363 end
364364
365- | Some (prw , subl ) -> begin
366- let subcpos =
367- match subl with
368- | None -> None
369-
370- | Some (x , xty ) ->
371- let fx = f_local x xty in
372- let subcpos =
373- FPosition. select_form
374- ~xconv: `Eq ~keyed: true hyps None fx prw
375- in
376-
377- if FPosition. is_empty subcpos then
378- raise (RewriteError LRW_RPatternNoVariable );
365+ | Some (prw , None) -> begin
366+ let prw, _ =
367+ try
368+ PT. pf_find_occurence_lazy
369+ pt.PT. ptev_env ~full: false ~modes ~ptn: prw tgfp
370+ with PT. FindOccFailure `MatchFailure ->
371+ raise (RewriteError LRW_RPatternNoMatch ) in
379372
380- if FPosition. occurences subcpos <> 1 then
381- raise (RewriteError LRW_RPatternNotLinear );
373+ try
374+ let subf, occmode =
375+ PT. pf_find_occurence_lazy
376+ pt.PT. ptev_env ~rooted: true ~modes ~ptn: fp prw
377+ in
378+ (subf, occmode, None )
379+ with
380+ | PT. FindOccFailure `MatchFailure ->
381+ raise (RewriteError LRW_RPatternNoRuleMatch )
382+ | PT. FindOccFailure `IncompleteMatch ->
383+ raise (RewriteError LRW_CannotInfer )
384+ end
382385
383- let subcpos =
384- match o with
385- | None -> subcpos
386- | Some o ->
387- if not (FPosition. is_occurences_valid (snd o) subcpos) then
388- raise (RewriteError LRW_InvalidOccurence );
389- FPosition. filter o subcpos
390- in
386+ | Some (prw , Some (x , xty )) -> begin
387+ let strict_modes =
388+ [{ k_keyed = true ; k_conv = false ; k_delta = false }]
389+ in
391390
392- Some subcpos
391+ let fx = f_local x xty in
392+ let subcpos =
393+ FPosition. select_form
394+ ~xconv: `Eq ~keyed: true hyps None fx prw
393395 in
394396
395- let ctxt_modes =
396- match subl with
397- | None -> modes
398- | Some _ -> [{ k_keyed = true ; k_conv = false ; k_delta = false }]
397+ if FPosition. is_empty subcpos then
398+ raise (RewriteError LRW_RPatternNoVariable );
399+
400+ if FPosition. occurences subcpos <> 1 then
401+ raise (RewriteError LRW_RPatternNotLinear );
402+
403+ let subcpos =
404+ match o with
405+ | None -> subcpos
406+ | Some o ->
407+ if not (FPosition. is_occurences_valid (snd o) subcpos) then
408+ raise (RewriteError LRW_InvalidOccurence );
409+ FPosition. filter o subcpos
399410 in
400411
401412 let prw, prwmode =
402413 try
403414 PT. pf_find_occurence_lazy
404- pt.PT. ptev_env ~full: false ~modes: ctxt_modes ~ptn: prw tgfp
415+ pt.PT. ptev_env ~full: false ~modes: strict_modes ~ptn: prw tgfp
405416 with PT. FindOccFailure `MatchFailure ->
406417 raise (RewriteError LRW_RPatternNoMatch ) in
407418
408- let find_in_rpattern ~modes fp prw =
419+ let subf = FPosition. first_selected_subform subcpos prw in
420+
421+ begin
409422 try
410- PT. pf_find_occurence_lazy
411- pt.PT. ptev_env ~rooted: true ~modes ~ptn: fp prw
423+ ignore
424+ (PT. pf_find_occurence_lazy
425+ pt.PT. ptev_env ~rooted: true ~modes: strict_modes ~ptn: fp subf)
412426 with
413427 | PT. FindOccFailure `MatchFailure ->
414428 raise (RewriteError LRW_RPatternNoRuleMatch )
415429 | PT. FindOccFailure `IncompleteMatch ->
416430 raise (RewriteError LRW_CannotInfer )
417- in
418-
419- match subcpos with
420- | None ->
421- let subf, occmode =
422- find_in_rpattern ~modes: ctxt_modes fp prw
423- in
424- (subf, occmode, None )
425-
426- | Some subcpos ->
427- let subf = FPosition. first_selected_subform subcpos prw in
428-
429- ignore (find_in_rpattern ~modes: ctxt_modes fp subf);
431+ end ;
430432
431- let cpos =
432- let prwpos =
433- FPosition. select_form
434- ~xconv: `AlphaEq ~keyed: prwmode.k_keyed hyps
435- (Some (`Inclusive , EcMaps.Sint. singleton 1 ))
436- prw tgfp
437- in
438- let root = FPosition. path_of_singleton_occurence prwpos in
439- FPosition. reroot root subcpos
433+ let cpos =
434+ let prwpos =
435+ FPosition. select_form
436+ ~xconv: `AlphaEq ~keyed: prwmode.k_keyed hyps
437+ (Some (`Inclusive , EcMaps.Sint. singleton 1 ))
438+ prw tgfp
440439 in
440+ let root = FPosition. path_of_singleton_occurence prwpos in
441+ FPosition. reroot root subcpos
442+ in
441443
442- (subf, { k_keyed = true ; k_conv = false ; k_delta = false }, Some cpos)
444+ (subf, { k_keyed = true ; k_conv = false ; k_delta = false }, Some cpos)
443445 end
444446 in
445447
0 commit comments