@@ -519,11 +519,12 @@ let reapply_coercions_body sigma trace body =
519
519
start_app_body sigma body
520
520
521
521
(* Try to coerce to a funclass; raise NoCoercion if not possible *)
522
- let inh_app_fun_core ~program_mode env sigma body typ =
522
+ let inh_app_fun_core ~program_mode ?( use_coercions = true ) env sigma body typ =
523
523
match unify_product env sigma typ with
524
524
| Inl sigma -> sigma, body, typ, IdCoe
525
525
| Inr t ->
526
526
try
527
+ if not use_coercions then raise NoCoercion ;
527
528
let p = lookup_path_to_fun_from env sigma typ in
528
529
let body = force_app_body body in
529
530
let sigma, body, typ, trace = apply_coercion env sigma p body typ in
@@ -541,13 +542,13 @@ let inh_app_fun_core ~program_mode env sigma body typ =
541
542
else Exninfo. iraise (NoCoercion ,info)
542
543
543
544
(* Try to coerce to a funclass; returns [j] if no coercion is applicable *)
544
- let inh_app_fun ~program_mode ~resolve_tc env sigma body typ =
545
- try inh_app_fun_core ~program_mode env sigma body typ
545
+ let inh_app_fun ~program_mode ~resolve_tc ? use_coercions env sigma body typ =
546
+ try inh_app_fun_core ~program_mode ?use_coercions env sigma body typ
546
547
with
547
548
| NoCoercion when not resolve_tc
548
549
|| not (get_use_typeclasses_for_conversion () ) -> (sigma, body, typ, IdCoe )
549
550
| NoCoercion ->
550
- try inh_app_fun_core ~program_mode env (saturate_evd env sigma) body typ
551
+ try inh_app_fun_core ~program_mode ?use_coercions env (saturate_evd env sigma) body typ
551
552
with NoCoercion -> (sigma, body, typ, IdCoe )
552
553
553
554
let type_judgment env sigma j =
@@ -564,15 +565,16 @@ let inh_tosort_force ?loc env sigma ({ uj_val; uj_type } as j) =
564
565
with Not_found | NoCoercion ->
565
566
error_not_a_type ?loc env sigma j
566
567
567
- let inh_coerce_to_sort ?loc env sigma j =
568
+ let inh_coerce_to_sort ?loc ?( use_coercions = true ) env sigma j =
568
569
let typ = whd_all env sigma j.uj_type in
569
570
match EConstr. kind sigma typ with
570
571
| Sort s -> (sigma,{ utj_val = j.uj_val; utj_type = ESorts. kind sigma s })
571
572
| Evar ev ->
572
573
let (sigma,s) = Evardefine. define_evar_as_sort env sigma ev in
573
574
(sigma,{ utj_val = j.uj_val; utj_type = s })
574
575
| _ ->
575
- inh_tosort_force ?loc env sigma j
576
+ if use_coercions then inh_tosort_force ?loc env sigma j
577
+ else error_not_a_type ?loc env sigma j
576
578
577
579
let inh_coerce_to_base ?loc ~program_mode env sigma j =
578
580
if program_mode then
@@ -582,8 +584,8 @@ let inh_coerce_to_base ?loc ~program_mode env sigma j =
582
584
sigma, res
583
585
else (sigma, j)
584
586
585
- let inh_coerce_to_fail flags env sigma rigidonly v v_ty target_type =
586
- if rigidonly && not (Heads. is_rigid env (EConstr.Unsafe. to_constr target_type) && Heads. is_rigid env (EConstr.Unsafe. to_constr v_ty))
587
+ let inh_coerce_to_fail ?( use_coercions = true ) flags env sigma rigidonly v v_ty target_type =
588
+ if not use_coercions || ( rigidonly && not (Heads. is_rigid env (EConstr.Unsafe. to_constr target_type) && Heads. is_rigid env (EConstr.Unsafe. to_constr v_ty) ))
587
589
then
588
590
raise NoCoercion
589
591
else
@@ -601,10 +603,10 @@ let inh_coerce_to_fail flags env sigma rigidonly v v_ty target_type =
601
603
let default_flags_of env =
602
604
default_flags_of TransparentState. full
603
605
604
- let rec inh_conv_coerce_to_fail ?loc env sigma ?(flags =default_flags_of env) rigidonly v t c1 =
606
+ let rec inh_conv_coerce_to_fail ?loc ? use_coercions env sigma ?(flags =default_flags_of env) rigidonly v t c1 =
605
607
try (unify_leq_delay ~flags env sigma t c1, v, IdCoe )
606
608
with UnableToUnify (best_failed_sigma ,e ) ->
607
- try inh_coerce_to_fail flags env sigma rigidonly v t c1
609
+ try inh_coerce_to_fail ?use_coercions flags env sigma rigidonly v t c1
608
610
with NoCoercion as exn ->
609
611
let _, info = Exninfo. capture exn in
610
612
match
@@ -624,21 +626,21 @@ let rec inh_conv_coerce_to_fail ?loc env sigma ?(flags=default_flags_of env) rig
624
626
let open Context.Rel.Declaration in
625
627
let env1 = push_rel (LocalAssum (name,u1)) env in
626
628
let (sigma, v1, trace1) =
627
- inh_conv_coerce_to_fail ?loc env1 sigma rigidonly
629
+ inh_conv_coerce_to_fail ?loc ?use_coercions env1 sigma rigidonly
628
630
(mkRel 1 ) (lift 1 u1) (lift 1 t1) in
629
631
let v2 = beta_applist sigma (lift 1 v,[v1]) in
630
632
let t2 = Retyping. get_type_of env1 sigma v2 in
631
- let (sigma,v2',trace2) = inh_conv_coerce_to_fail ?loc env1 sigma rigidonly v2 t2 u2 in
633
+ let (sigma,v2',trace2) = inh_conv_coerce_to_fail ?loc ?use_coercions env1 sigma rigidonly v2 t2 u2 in
632
634
let trace = ProdCoe { na= name; ty= u1; dom= trace1; body= trace2 } in
633
635
(sigma, mkLambda (name, u1, v2'), trace)
634
636
| _ ->
635
637
Exninfo. iraise (NoCoercionNoUnifier (best_failed_sigma,e), info)
636
638
637
639
(* Look for cj' obtained from cj by inserting coercions, s.t. cj'.typ = t *)
638
- let inh_conv_coerce_to_gen ?loc ~program_mode ~resolve_tc rigidonly flags env sigma cj t =
640
+ let inh_conv_coerce_to_gen ?loc ~program_mode ~resolve_tc ? use_coercions rigidonly flags env sigma cj t =
639
641
let (sigma, val', otrace) =
640
642
try
641
- let (sigma, val', trace) = inh_conv_coerce_to_fail ?loc env sigma ~flags rigidonly cj.uj_val cj.uj_type t in
643
+ let (sigma, val', trace) = inh_conv_coerce_to_fail ?loc ?use_coercions env sigma ~flags rigidonly cj.uj_val cj.uj_type t in
642
644
(sigma, val', Some trace)
643
645
with NoCoercionNoUnifier (best_failed_sigma ,e ) as exn ->
644
646
let _, info = Exninfo. capture exn in
@@ -659,15 +661,15 @@ let inh_conv_coerce_to_gen ?loc ~program_mode ~resolve_tc rigidonly flags env si
659
661
error_actual_type ?loc ~info env best_failed_sigma cj t e
660
662
else
661
663
let sigma = sigma' in
662
- let (sigma, val', trace) = inh_conv_coerce_to_fail ?loc env sigma rigidonly cj.uj_val cj.uj_type t in
664
+ let (sigma, val', trace) = inh_conv_coerce_to_fail ?loc ?use_coercions env sigma rigidonly cj.uj_val cj.uj_type t in
663
665
(sigma, val', Some trace)
664
666
with NoCoercionNoUnifier (_sigma ,_error ) as exn ->
665
667
let _, info = Exninfo. capture exn in
666
668
error_actual_type ?loc ~info env best_failed_sigma cj t e
667
669
in
668
670
(sigma,{ uj_val = val'; uj_type = t },otrace)
669
671
670
- let inh_conv_coerce_to ?loc ~program_mode ~resolve_tc env sigma ?(flags =default_flags_of env) =
671
- inh_conv_coerce_to_gen ?loc ~program_mode ~resolve_tc false flags env sigma
672
- let inh_conv_coerce_rigid_to ?loc ~program_mode ~resolve_tc env sigma ?(flags =default_flags_of env) =
673
- inh_conv_coerce_to_gen ?loc ~program_mode ~resolve_tc true flags env sigma
672
+ let inh_conv_coerce_to ?loc ~program_mode ~resolve_tc ? use_coercions env sigma ?(flags =default_flags_of env) =
673
+ inh_conv_coerce_to_gen ?loc ~program_mode ~resolve_tc ?use_coercions false flags env sigma
674
+ let inh_conv_coerce_rigid_to ?loc ~program_mode ~resolve_tc ? use_coercions env sigma ?(flags =default_flags_of env) =
675
+ inh_conv_coerce_to_gen ?loc ~program_mode ~resolve_tc ?use_coercions true flags env sigma
0 commit comments