@@ -446,6 +446,33 @@ module Sign_diff = struct
446
446
}
447
447
end
448
448
449
+ (* Quickly compare module types without expanding them *)
450
+ let rec shallow_modtypes env subst mty1 mty2 =
451
+ let open Subst.Lazy in
452
+ match mty1, mty2 with
453
+ | Mty_alias p1 , Mty_alias p2 ->
454
+ not (Env. is_functor_arg p2 env) && equal_module_paths env p1 subst p2
455
+ | Mty_ident p1 , Mty_ident p2 ->
456
+ equal_modtype_paths env p1 subst p2
457
+ | Mty_strengthen (mty1,p1,_), Mty_strengthen (mty2,p2,_)
458
+ when shallow_modtypes env subst mty1 mty2
459
+ && shallow_module_paths env subst p1 mty2 p2 ->
460
+ true
461
+ | Mty_strengthen (mty1 ,_ ,_ ), mty2 ->
462
+ (* S with M <= S *)
463
+ shallow_modtypes env subst mty1 mty2
464
+ | _ -> false
465
+
466
+ and shallow_module_paths env subst p1 mty2 p2 =
467
+ equal_module_paths env p1 subst p2 ||
468
+ (* This shortcut is a significant win in some cases. Note we don't apply it
469
+ recursively as doing seems to be a net loss. *)
470
+ match (Env. find_module_lazy p1 env).md_type with
471
+ | Mty_strengthen (mty1 ,p1 ,_ ) ->
472
+ shallow_modtypes env subst mty1 mty2
473
+ && equal_module_paths env p1 subst p2
474
+ | _ | exception Not_found -> false
475
+
449
476
(* *
450
477
In the group of mutual functions below, the [~in_eq] argument is [true] when
451
478
we are in fact checking equality of module types.
462
489
described above.
463
490
*)
464
491
465
- (* Quickly compare module types without expanding them *)
466
- let shallow_modtypes env subst mty1 mty2 =
467
- let open Subst.Lazy in
468
- let rec cmp_modtypes mty1 mty2 =
469
- match mty1, mty2 with
470
- | Mty_alias p1 , Mty_alias p2 ->
471
- not (Env. is_functor_arg p2 env) && equal_module_paths env p1 subst p2
472
- | Mty_ident p1 , Mty_ident p2 ->
473
- equal_modtype_paths env p1 subst p2
474
- | Mty_strengthen (mty1,p1,_), Mty_strengthen (mty2,p2,_)
475
- when cmp_modtypes mty1 mty2 && cmp_strengthen_paths p1 mty2 p2 ->
476
- true
477
- | Mty_strengthen (mty1 ,_ ,_ ), mty2 ->
478
- (* S/M <= S *)
479
- cmp_modtypes mty1 mty2
480
- | _ -> false
481
- and cmp_strengthen_paths p1 mty2 p2 =
482
- equal_module_paths env p1 subst p2 ||
483
- match (Env. find_module_lazy p1 env).md_type with
484
- | Mty_strengthen (mty1 ,p1 ,_ ) ->
485
- (* M : S/N ==> S/M < S/N *)
486
- cmp_modtypes mty1 mty2 && equal_module_paths env p1 subst p2
487
- | _ | exception Not_found -> false
488
- in
489
- cmp_modtypes mty1 mty2
490
-
491
492
let rec modtypes ~in_eq ~loc env ~mark subst mty1 mty2 shape =
492
493
match try_modtypes ~in_eq ~loc env ~mark subst mty1 mty2 shape with
493
494
| Ok _ as ok -> ok
0 commit comments