Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle naming fixes #1205

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions engine/lib/concrete_ident/concrete_ident.ml
Original file line number Diff line number Diff line change
Expand Up @@ -596,17 +596,16 @@ module Create = struct
let len x = List.length x.def_id.path in
let compare x y = len x - len y in
let id = List.min_elt ~compare from |> Option.value_exn in
let parent = parent id in
{
kind = Kind.Value;
def_id =
{
parent.def_id with
id.def_id with
path =
parent.def_id.path
id.def_id.path
@ [
{
data = TypeNs "rec_bundle";
data = TypeNs "cyclic_bundle";
disambiguator = [%hash: t list] from;
};
];
Expand Down Expand Up @@ -635,6 +634,17 @@ module Create = struct
let constructor name =
let path = name.def_id.path @ [ { data = Ctor; disambiguator = 0 } ] in
{ name with def_id = { name.def_id with path } }

let add_disambiguator name disambiguator =
let path = name.def_id.path in
if List.is_empty path then name
else
(* The following two `exn` function calls cannot fail as the path is not empty. *)
let last = List.last_exn path in
let path =
List.drop_last_exn path @ [ { data = last.data; disambiguator } ]
in
{ name with def_id = { name.def_id with path } }
end

let lookup_raw_impl_info (impl : t) : Types.impl_infos option =
Expand Down
5 changes: 5 additions & 0 deletions engine/lib/concrete_ident/concrete_ident.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ val eq_name : name -> t -> bool
val to_debug_string : t -> string

module Create : sig
val parent : t -> t
val fresh_module : from:t list -> t
val move_under : new_parent:t -> t -> t

Expand All @@ -37,6 +38,10 @@ module Create : sig
val map_last : f:(string -> string) -> t -> t
(** [map_last f ident] applies [f] on the last chunk of [ident]'s
path if it holds a string *)

val add_disambiguator : t -> int -> t
(** [add_disambiguator ident d] changes the disambiguator on
the last chunk of [ident]'s path to [d] *)
end

type view = { crate : string; path : string list; definition : string }
Expand Down
11 changes: 6 additions & 5 deletions engine/lib/dependencies.ml
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,12 @@ module Make (F : Features.T) = struct
in

let transform (bundle : item list) =
let module_names =
List.map ~f:(ident_of >> Concrete_ident.Create.parent) bundle
|> List.dedup_and_sort ~compare:Concrete_ident.compare
in
let ns : Concrete_ident.t =
Concrete_ident.Create.fresh_module ~from:(List.map ~f:ident_of bundle)
Concrete_ident.Create.fresh_module ~from:module_names
in
let new_name_under_ns : Concrete_ident.t -> Concrete_ident.t =
Concrete_ident.Create.move_under ~new_parent:ns
Expand All @@ -431,10 +435,7 @@ module Make (F : Features.T) = struct
(List.mem duplicates (new_name_under_ns id)
~equal:Concrete_ident.equal)
then id
else
Concrete_ident.Create.map_last
~f:(fun name -> name ^ (Concrete_ident.hash id |> Int.to_string))
id
else Concrete_ident.Create.add_disambiguator id (Concrete_ident.hash id)
in
let renamings =
List.map
Expand Down
Loading
Loading