Skip to content

Hide Compilation_unit.t's definition in a submodule #1134

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

Merged
merged 1 commit into from
Feb 21, 2023
Merged
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
119 changes: 67 additions & 52 deletions ocaml/utils/compilation_unit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -169,58 +169,73 @@ end = struct
let to_list t = t
end

(* As with [Name.t], changing [with_prefix] or [t] requires bumping magic
numbers. *)
type with_prefix =
{ name : Name.t;
for_pack_prefix : Prefix.t
}

(* type t = Without_prefix of Name.t [@@unboxed] | With_prefix of with_prefix *)
type t = Obj.t

(* Some manual inlining is done here to ensure good performance under
Closure. *)

let for_pack_prefix_and_name t =
let tag = Obj.tag t in
assert (tag = 0 || tag = Obj.string_tag);
if tag <> 0
then Prefix.empty, Sys.opaque_identity (Obj.obj t : Name.t)
else
let with_prefix = Sys.opaque_identity (Obj.obj t : with_prefix) in
with_prefix.for_pack_prefix, with_prefix.name

let name t =
let tag = Obj.tag t in
assert (tag = 0 || tag = Obj.string_tag);
if tag <> 0
then Sys.opaque_identity (Obj.obj t : Name.t)
else
let with_prefix = Sys.opaque_identity (Obj.obj t : with_prefix) in
with_prefix.name

let for_pack_prefix t =
let tag = Obj.tag t in
assert (tag = 0 || tag = Obj.string_tag);
if tag <> 0
then Prefix.empty
else
let with_prefix = Sys.opaque_identity (Obj.obj t : with_prefix) in
with_prefix.for_pack_prefix

let create for_pack_prefix name =
let empty_prefix = Prefix.is_empty for_pack_prefix in
let () =
if not empty_prefix
then (
Name.check_as_path_component name;
ListLabels.iter ~f:Name.check_as_path_component
(for_pack_prefix |> Prefix.to_list))
in
if empty_prefix
then Sys.opaque_identity (Obj.repr name)
else Sys.opaque_identity (Obj.repr { for_pack_prefix; name })
module T0 : sig
type t

val for_pack_prefix_and_name : t -> Prefix.t * Name.t

val name : t -> Name.t

val for_pack_prefix : t -> Prefix.t

val create : Prefix.t -> Name.t -> t
end = struct
(* As with [Name.t], changing [with_prefix] or [t] requires bumping magic
numbers. *)
type with_prefix =
{ name : Name.t;
for_pack_prefix : Prefix.t
}

(* type t = Without_prefix of Name.t [@@unboxed] | With_prefix of
with_prefix *)
type t = Obj.t

(* Some manual inlining is done here to ensure good performance under
Closure. *)

let for_pack_prefix_and_name t =
let tag = Obj.tag t in
assert (tag = 0 || tag = Obj.string_tag);
if tag <> 0
then Prefix.empty, Sys.opaque_identity (Obj.obj t : Name.t)
else
let with_prefix = Sys.opaque_identity (Obj.obj t : with_prefix) in
with_prefix.for_pack_prefix, with_prefix.name

let name t =
let tag = Obj.tag t in
assert (tag = 0 || tag = Obj.string_tag);
if tag <> 0
then Sys.opaque_identity (Obj.obj t : Name.t)
else
let with_prefix = Sys.opaque_identity (Obj.obj t : with_prefix) in
with_prefix.name

let for_pack_prefix t =
let tag = Obj.tag t in
assert (tag = 0 || tag = Obj.string_tag);
if tag <> 0
then Prefix.empty
else
let with_prefix = Sys.opaque_identity (Obj.obj t : with_prefix) in
with_prefix.for_pack_prefix

let create for_pack_prefix name =
let empty_prefix = Prefix.is_empty for_pack_prefix in
let () =
if not empty_prefix
then (
Name.check_as_path_component name;
ListLabels.iter ~f:Name.check_as_path_component
(for_pack_prefix |> Prefix.to_list))
in
if empty_prefix
then Sys.opaque_identity (Obj.repr name)
else Sys.opaque_identity (Obj.repr { for_pack_prefix; name })
end

include T0

let create_child parent name_ =
let prefix =
Expand Down