Skip to content

Commit

Permalink
Revert incomplete fix before 2ad7e70
Browse files Browse the repository at this point in the history
aka Resolve aliases indepedent of order in functors
  • Loading branch information
tjammer committed Aug 23, 2024
1 parent ea7e149 commit 76f1273
Showing 1 changed file with 3 additions and 37 deletions.
40 changes: 3 additions & 37 deletions lib/module.ml
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,6 @@ let validate_module_type env ~mname find mtype =
(* Go through signature and check that the implemented types match.
Implementation is appended to a list, so the most current bindings are the ones we pick.
That's exactly what we want. Also, set correct unique name to signature binding. *)
let sgn_decls = ref [] in
let prev_sgn_decl = ref None in
let mn = mname in
let com = "Signatures don't match" in
let f (name, loc, kind) (sub, acc) =
Expand All @@ -725,7 +723,6 @@ let validate_module_type env ~mname find mtype =
let msg = Error.format_type_err (com ^ ":") mn s i in
raise (Error (loc, msg))
in
prev_sgn_decl := Some name;
(sub, (name, loc, kind) :: acc)
| Some (Mvalue (ityp, callname)), Mvalue (styp, _) ->
let typ, _, b = Inference.types_match ~abstracts_map:sub styp ityp in
Expand Down Expand Up @@ -756,7 +753,6 @@ let validate_module_type env ~mname find mtype =
in the impl might refer to this signature type. Thus, the
signature types need to be manually placed into the decl map
which keeps track of in-module type declarations. *)
sgn_decls := (name, loc, decl, !prev_sgn_decl) :: !sgn_decls;
(sub, (name, loc, kind) :: acc))
| (None | Some (Mtypedef _)), Mvalue (typ, _) ->
let msg =
Expand All @@ -767,46 +763,16 @@ let validate_module_type env ~mname find mtype =
in
raise (Error (loc, msg))
in
let _, mtype = List.fold_right f mtype (Pmap.empty, []) in
(mtype, !sgn_decls |> List.rev)

let insert_into_impl sgn_decls impl =
(* The decls to insert are ordered because we go through the signature in
order. *)
let rec add_after acc ((name, loc, decl) as sgn) ~typename impl =
match impl with
| (Mtype (_, implname, _) as item) :: tl when String.equal typename implname
->
(Mtype (loc, name, decl) :: item :: acc, tl)
| item :: tl -> add_after (item :: acc) sgn ~typename tl
| [] -> failwith "Internal Error: Could not find typename to add after"
in

let rec aux acc sgn_decls impl =
match sgn_decls with
| (name, loc, decl, None) :: stl ->
aux (Mtype (loc, name, decl) :: acc) stl impl
| (name, loc, decl, Some typename) :: stl ->
let acc, impl = add_after acc (name, loc, decl) ~typename impl in
aux acc stl impl
| [] -> (
(* Add the remaining impl *)
match impl with item :: tl -> aux (item :: acc) [] tl | [] -> acc)
in
aux [] sgn_decls (List.rev impl)
List.fold_right f mtype (Pmap.empty, []) |> snd

let validate_signature env m =
match m.s with
| [] -> m
| s ->
let find name kind = List.find_map (find_item name kind) m.i in
let mname = Env.modpath env in
let s, sgn_decls = validate_module_type ~mname env find s in
let i = insert_into_impl sgn_decls m.i in
(* Add sgn decls to the impl. The difficulty lies in adding them to
the correct place. Each sgn decl remembers the previous type decl. We
use this information to insert the decl. *)
{ m with s; i }
let s = validate_module_type ~mname env find s in
{ m with s }

let validate_intf env ~mname intf m =
match m.s with
Expand Down

0 comments on commit 76f1273

Please sign in to comment.