@@ -719,8 +719,14 @@ and module_data =
719
719
mda_address : address_lazy ;
720
720
mda_shape : Shape .t ; }
721
721
722
+ and module_alias_locks = lock list
723
+ (* * If the module is an alias for another module, this is the list of locks
724
+ from the original module to this module. This is accumulative: write
725
+ [module B = A;; module C = B;;], then [C] will record all locks from [A]
726
+ to [C]. Empty if not an alias. *)
727
+
722
728
and module_entry =
723
- | Mod_local of module_data
729
+ | Mod_local of module_data * module_alias_locks
724
730
| Mod_persistent
725
731
| Mod_unbound of module_unbound_reason
726
732
@@ -936,7 +942,7 @@ let diff env1 env2 =
936
942
(* Functions for use in "wrap" parameters in IdTbl *)
937
943
let wrap_identity x = x
938
944
let wrap_value vda = Val_bound vda
939
- let wrap_module mda = Mod_local mda
945
+ let wrap_module mda = Mod_local ( mda, [] )
940
946
941
947
(* Forward declarations *)
942
948
@@ -1239,7 +1245,7 @@ let check_functor_appl
1239
1245
1240
1246
let find_ident_module id env =
1241
1247
match find_same_module id env.modules with
1242
- | Mod_local data -> data
1248
+ | Mod_local ( data , _ ) -> data
1243
1249
| Mod_unbound _ -> raise Not_found
1244
1250
| Mod_persistent ->
1245
1251
match Ident. to_global id with
@@ -1529,7 +1535,7 @@ let find_shape env (ns : Shape.Sig_component_kind.t) id =
1529
1535
end
1530
1536
| Module ->
1531
1537
begin match IdTbl. find_same_without_locks id env.modules with
1532
- | Mod_local { mda_shape; _ } -> mda_shape
1538
+ | Mod_local ( { mda_shape; _ } , _ ) -> mda_shape
1533
1539
| Mod_persistent -> Shape. for_persistent_unit (Ident. name id)
1534
1540
| Mod_unbound _ ->
1535
1541
(* Only present temporarily while approximating the environment for
@@ -1765,7 +1771,7 @@ let iter_env wrap proj1 proj2 f env () =
1765
1771
(fun id (path , entry ) ->
1766
1772
match entry with
1767
1773
| Mod_unbound _ -> ()
1768
- | Mod_local data ->
1774
+ | Mod_local ( data , _ ) ->
1769
1775
iter_components (Pident id) path data.mda_components
1770
1776
| Mod_persistent -> () )
1771
1777
env.modules;
@@ -1811,7 +1817,7 @@ let rec find_shadowed_comps path env =
1811
1817
List. filter_map
1812
1818
(fun (p , data ) ->
1813
1819
match data with
1814
- | Mod_local x -> Some (p, x)
1820
+ | Mod_local ( x , _ ) -> Some (p, x)
1815
1821
| Mod_unbound _ | Mod_persistent -> None )
1816
1822
(IdTbl. find_all wrap_module (Ident. name id) env.modules)
1817
1823
| Pdot (p , s ) ->
@@ -2077,7 +2083,7 @@ let rec components_of_module_maker
2077
2083
NameMap. add (Ident. name id) mda c.comp_modules;
2078
2084
env :=
2079
2085
store_module ~update_summary: false ~check: None
2080
- id addr pres md shape ! env
2086
+ id addr pres md shape [] ! env
2081
2087
| Sig_modtype (id , decl , _ ) ->
2082
2088
let final_decl =
2083
2089
(* The prefixed items get the same scope as [cm_path], which is
@@ -2352,7 +2358,7 @@ and store_extension ~check ~rebind id addr ext shape env =
2352
2358
summary = Env_extension (env.summary, id, ext) }
2353
2359
2354
2360
and store_module ?(update_summary =true ) ~check
2355
- id addr presence md shape env =
2361
+ id addr presence md shape alias_locks env =
2356
2362
let open Subst.Lazy in
2357
2363
let loc = md.md_loc in
2358
2364
Option. iter
@@ -2373,7 +2379,7 @@ and store_module ?(update_summary=true) ~check
2373
2379
if not update_summary then env.summary
2374
2380
else Env_module (env.summary, id, presence, force_module_decl md) in
2375
2381
{ env with
2376
- modules = IdTbl. add id (Mod_local mda) env.modules;
2382
+ modules = IdTbl. add id (Mod_local ( mda, alias_locks) ) env.modules;
2377
2383
summary }
2378
2384
2379
2385
and store_modtype ?(update_summary =true ) id info shape env =
@@ -2466,7 +2472,7 @@ and add_extension ~check ?shape ~rebind id ext env =
2466
2472
store_extension ~check ~rebind id addr ext shape env
2467
2473
2468
2474
and add_module_declaration_lazy
2469
- ~update_summary ?(arg =false ) ?shape ~check id presence md env =
2475
+ ~update_summary ?(arg =false ) ?shape ~check id presence md ?( locks = [] ) env =
2470
2476
let check =
2471
2477
if not check then
2472
2478
None
@@ -2478,13 +2484,13 @@ and add_module_declaration_lazy
2478
2484
let addr = module_declaration_address env id presence md in
2479
2485
let shape = shape_or_leaf md.Subst.Lazy. md_uid shape in
2480
2486
let env =
2481
- store_module ~update_summary ~check id addr presence md shape env
2487
+ store_module ~update_summary ~check id addr presence md shape locks env
2482
2488
in
2483
2489
if arg then add_functor_arg id env else env
2484
2490
2485
- let add_module_declaration ?(arg =false ) ?shape ~check id presence md env =
2491
+ let add_module_declaration ?(arg =false ) ?shape ~check id presence md ? locks env =
2486
2492
add_module_declaration_lazy ~update_summary: true ~arg ?shape ~check id
2487
- presence (Subst.Lazy. of_module_decl md) env
2493
+ presence (Subst.Lazy. of_module_decl md) ?locks env
2488
2494
2489
2495
and add_modtype_lazy ~update_summary ?shape id info env =
2490
2496
let shape = shape_or_leaf info.Subst.Lazy. mtd_uid shape in
@@ -2543,9 +2549,9 @@ let enter_extension ~scope ~rebind name ext env =
2543
2549
let env = store_extension ~check: true ~rebind id addr ext shape env in
2544
2550
(id, env)
2545
2551
2546
- let enter_module_declaration ~scope ?arg ?shape s presence md env =
2552
+ let enter_module_declaration ~scope ?arg ?shape s presence md ? locks env =
2547
2553
let id = Ident. create_scoped ~scope s in
2548
- (id, add_module_declaration ?arg ?shape ~check: true id presence md env)
2554
+ (id, add_module_declaration ?arg ?shape ~check: true id presence md ?locks env)
2549
2555
2550
2556
let enter_modtype ~scope name mtd env =
2551
2557
let id = Ident. create_scoped ~scope name in
@@ -2608,7 +2614,8 @@ module Add_signature(T : Types.Wrapped)(M : sig
2608
2614
val add_value : ?shape : Shape .t -> mode :(Mode .allowed * 'r0 ) Mode.Value .t -> Ident .t ->
2609
2615
T .value_description -> t -> t
2610
2616
val add_module_declaration : ?arg : bool -> ?shape : Shape .t -> check :bool
2611
- -> Ident .t -> module_presence -> T .module_declaration -> t -> t
2617
+ -> Ident .t -> module_presence -> T .module_declaration -> ?locks : lock list ->
2618
+ t -> t
2612
2619
val add_modtype : ?shape : Shape .t -> Ident .t -> T .modtype_declaration -> t -> t
2613
2620
end ) = struct
2614
2621
open T
@@ -2688,7 +2695,7 @@ let add_cltype = add_cltype ?shape:None
2688
2695
let add_modtype_lazy = add_modtype_lazy ?shape:None
2689
2696
let add_modtype = add_modtype ?shape:None
2690
2697
let add_module_declaration_lazy ?(arg =false ) =
2691
- add_module_declaration_lazy ~arg ?shape:None ~check: false
2698
+ add_module_declaration_lazy ~arg ?shape:None ~check: false ?locks: None
2692
2699
let add_signature sg env =
2693
2700
let _, env = add_signature Shape.Map. empty None sg env in
2694
2701
env
@@ -3001,8 +3008,9 @@ let lookup_ident_module (type a) (load : a load) ~errors ~use ~loc s env =
3001
3008
may_lookup_error errors loc env (Unbound_module (Lident s))
3002
3009
in
3003
3010
match data with
3004
- | Mod_local mda -> begin
3011
+ | Mod_local ( mda , alias_locks ) -> begin
3005
3012
use_module ~use ~loc path mda;
3013
+ let locks = alias_locks @ locks in
3006
3014
match load with
3007
3015
| Load -> path, locks, (mda : a )
3008
3016
| Don't_load -> path, locks, (() : a)
@@ -3572,7 +3580,7 @@ let lookup_module_path ~errors ~use ~loc ~load lid env =
3572
3580
match lid with
3573
3581
| Lident s ->
3574
3582
if ! Clflags. transparent_modules && not load then
3575
- let path, locks, _ =
3583
+ let path, locks, () =
3576
3584
lookup_ident_module Don't_load ~errors ~use ~loc s env
3577
3585
in
3578
3586
path, locks
@@ -3968,7 +3976,7 @@ let fold_modules f lid env acc =
3968
3976
(fun name (p , entry ) acc ->
3969
3977
match entry with
3970
3978
| Mod_unbound _ -> acc
3971
- | Mod_local mda ->
3979
+ | Mod_local ( mda , _ ) ->
3972
3980
let md =
3973
3981
Subst.Lazy. force_module_decl mda.mda_declaration
3974
3982
in
0 commit comments