Skip to content

Commit

Permalink
Merge pull request #1205 from hacspec/bundle-naming-fixes
Browse files Browse the repository at this point in the history
Bundle naming fixes
  • Loading branch information
maximebuyse authored Dec 24, 2024
2 parents 1e7bbd1 + 254990d commit 08057f7
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 138 deletions.
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 @@ -414,8 +414,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 @@ -432,10 +436,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

0 comments on commit 08057f7

Please sign in to comment.