|
|
|
@ -112,7 +112,7 @@ type 'a t =
|
|
|
|
|
]} *)
|
|
|
|
|
| Functor : 'a t Arg.t option * 'a t -> 'a t
|
|
|
|
|
| Link : Nsd.t -> extended t
|
|
|
|
|
| Pack : dictionary -> extended t
|
|
|
|
|
| Namespace : dictionary -> extended t
|
|
|
|
|
|
|
|
|
|
and extended = |
|
|
|
|
|
and simple = |
|
|
|
|
@ -156,7 +156,7 @@ and pp ppf = function
|
|
|
|
|
Fmt.pf ppf "%a:%a" Origin.pp origin pp_signature signature
|
|
|
|
|
| Functor (arg, x) ->
|
|
|
|
|
Fmt.pf ppf "%a -> %a" Fmt.(option ~none:(any "()") pp_arg) arg pp x
|
|
|
|
|
| Pack ms ->
|
|
|
|
|
| Namespace ms ->
|
|
|
|
|
Fmt.pf ppf "@[[%a]@]"
|
|
|
|
|
Fmt.(Dump.iter_bindings Mod.Map.iter (any "pack") Mod.pp pp)
|
|
|
|
|
ms
|
|
|
|
@ -177,7 +177,8 @@ module Dictionary = struct
|
|
|
|
|
| Sig { origin = Unit (_, name); _ }, Link link when Nsd.equal name link
|
|
|
|
|
->
|
|
|
|
|
Some x
|
|
|
|
|
| Pack p0, Pack p1 -> Some (Pack (Mod.Map.union merge p0 p1))
|
|
|
|
|
| Namespace p0, Namespace p1 ->
|
|
|
|
|
Some (Namespace (Mod.Map.union merge p0 p1))
|
|
|
|
|
| _, v -> Some v in
|
|
|
|
|
Mod.Map.union merge
|
|
|
|
|
end
|
|
|
|
@ -204,19 +205,32 @@ let rec with_namespace namespaced m =
|
|
|
|
|
match tl with
|
|
|
|
|
| [] ->
|
|
|
|
|
let v = with_namespace (Nsd.v name) m in
|
|
|
|
|
(hd, Pack (Dictionary.of_list [ v ]))
|
|
|
|
|
(hd, Namespace (Dictionary.of_list [ v ]))
|
|
|
|
|
| _ ->
|
|
|
|
|
let[@warning "-8"] (Ok namespace) = Mod.Path.of_list_of_names tl in
|
|
|
|
|
let namespaced = Nsd.v ~namespace name in
|
|
|
|
|
let v = with_namespace namespaced m in
|
|
|
|
|
(hd, Pack (Dictionary.of_list [ v ])))
|
|
|
|
|
(hd, Namespace (Dictionary.of_list [ v ])))
|
|
|
|
|
|
|
|
|
|
let namespace path =
|
|
|
|
|
let rec go global path =
|
|
|
|
|
match Mod.Path.to_list path with
|
|
|
|
|
| [] -> assert false (* XXX(dinosaure): a [Mod.Path.t] can not be empty. *)
|
|
|
|
|
| [ name ] ->
|
|
|
|
|
(name, Namespace (Dictionary.of_list [ (Nsd.name global, Link global) ]))
|
|
|
|
|
| name :: rest ->
|
|
|
|
|
let[@warning "-8"] (Ok rest) = Mod.Path.of_list_of_names rest in
|
|
|
|
|
(name, Namespace (Dictionary.of_list [ go global rest ])) in
|
|
|
|
|
match Nsd.namespace path with
|
|
|
|
|
| None -> invalid_arg "Module.namespace: empty namespace"
|
|
|
|
|
| Some namespace -> go path namespace
|
|
|
|
|
|
|
|
|
|
let rec spirit_away p root = function
|
|
|
|
|
| Alias a as alias ->
|
|
|
|
|
if not root then Alias { a with phantom = Some p } else alias
|
|
|
|
|
| (Abstract _ | Functor _) as v -> v
|
|
|
|
|
| Link _ as link -> link (* TODO *)
|
|
|
|
|
| Pack v -> Pack (Mod.Map.map (spirit_away p false) v)
|
|
|
|
|
| Namespace v -> Namespace (Mod.Map.map (spirit_away p false) v)
|
|
|
|
|
| Sig { origin; signature } ->
|
|
|
|
|
let origin' = Origin.Phantom (root, p) in
|
|
|
|
|
let origin =
|
|
|
|
@ -303,5 +317,5 @@ module Partial = struct
|
|
|
|
|
{ Arg.name; signature = of_extended signature })
|
|
|
|
|
a in
|
|
|
|
|
Functor (a, of_extended x)
|
|
|
|
|
| _ -> invalid_arg "Impossible to simplify Alias, Link or Pack"
|
|
|
|
|
| _ -> invalid_arg "Impossible to simplify Alias, Link or Namespace"
|
|
|
|
|
end
|
|
|
|
|