Skip to content

Commit 3a78e83

Browse files
authored
flambda-backend: Revert "Instance compilation units" (#1175)
Revert "Instance compilation units (#1113)" This reverts commit 3bdccca.
1 parent 9a683c9 commit 3a78e83

File tree

2 files changed

+32
-129
lines changed

2 files changed

+32
-129
lines changed

utils/compilation_unit.ml

Lines changed: 32 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ module String = Misc.Stdlib.String
2323
type error =
2424
| Invalid_character of char * string
2525
| Bad_compilation_unit_name of string
26-
| Child_of_instance of { child_name : string }
27-
| Packed_instance of { name : string }
2826

2927
exception Error of error
3028

@@ -172,56 +170,46 @@ end = struct
172170
end
173171

174172
module T0 : sig
175-
type descr = private
176-
{ name : Name.t;
177-
for_pack_prefix : Prefix.t;
178-
arguments : (Name.t * t) list
179-
}
180-
181-
and t
173+
type t
182174

183-
val descr : t -> descr
175+
val for_pack_prefix_and_name : t -> Prefix.t * Name.t
184176

185177
val name : t -> Name.t
186178

187179
val for_pack_prefix : t -> Prefix.t
188180

189-
val arguments : t -> (Name.t * t) list
190-
191-
val create_full : Prefix.t -> Name.t -> (Name.t * t) list -> t
181+
val create : Prefix.t -> Name.t -> t
192182
end = struct
193-
(* As with [Name.t], changing [descr] or [t] requires bumping magic
183+
(* As with [Name.t], changing [with_prefix] or [t] requires bumping magic
194184
numbers. *)
195-
type descr =
185+
type with_prefix =
196186
{ name : Name.t;
197-
for_pack_prefix : Prefix.t;
198-
arguments : (Name.t * t) list
187+
for_pack_prefix : Prefix.t
199188
}
200189

201-
(* type t = Simple of Name.t [@@unboxed] | Full of descr *)
202-
and t = Obj.t
190+
(* type t = Without_prefix of Name.t [@@unboxed] | With_prefix of
191+
with_prefix *)
192+
type t = Obj.t
203193

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

207-
let descr t =
197+
let for_pack_prefix_and_name t =
208198
let tag = Obj.tag t in
209199
assert (tag = 0 || tag = Obj.string_tag);
210200
if tag <> 0
211-
then
212-
{ name = Sys.opaque_identity (Obj.obj t : Name.t);
213-
for_pack_prefix = Prefix.empty;
214-
arguments = []
215-
}
216-
else Sys.opaque_identity (Obj.obj t : descr)
201+
then Prefix.empty, Sys.opaque_identity (Obj.obj t : Name.t)
202+
else
203+
let with_prefix = Sys.opaque_identity (Obj.obj t : with_prefix) in
204+
with_prefix.for_pack_prefix, with_prefix.name
217205

218206
let name t =
219207
let tag = Obj.tag t in
220208
assert (tag = 0 || tag = Obj.string_tag);
221209
if tag <> 0
222210
then Sys.opaque_identity (Obj.obj t : Name.t)
223211
else
224-
let with_prefix = Sys.opaque_identity (Obj.obj t : descr) in
212+
let with_prefix = Sys.opaque_identity (Obj.obj t : with_prefix) in
225213
with_prefix.name
226214

227215
let for_pack_prefix t =
@@ -230,55 +218,26 @@ end = struct
230218
if tag <> 0
231219
then Prefix.empty
232220
else
233-
let descr = Sys.opaque_identity (Obj.obj t : descr) in
234-
descr.for_pack_prefix
235-
236-
let arguments t =
237-
let tag = Obj.tag t in
238-
assert (tag = 0 || tag = Obj.string_tag);
239-
if tag <> 0
240-
then []
241-
else
242-
let descr = Sys.opaque_identity (Obj.obj t : descr) in
243-
descr.arguments
221+
let with_prefix = Sys.opaque_identity (Obj.obj t : with_prefix) in
222+
with_prefix.for_pack_prefix
244223

245-
let create_full for_pack_prefix name arguments =
224+
let create for_pack_prefix name =
246225
let empty_prefix = Prefix.is_empty for_pack_prefix in
247-
let empty_arguments = match arguments with [] -> true | _ -> false in
248226
let () =
249227
if not empty_prefix
250228
then (
251-
let () =
252-
if not empty_arguments
253-
then
254-
(* CR-someday lmaurer: [for_pack_prefix] and [arguments] would make
255-
for better output but it doesn't seem worth moving both [error]
256-
and [print] to before this point *)
257-
raise (Error (Packed_instance { name = name |> Name.to_string }))
258-
in
259229
Name.check_as_path_component name;
260230
ListLabels.iter ~f:Name.check_as_path_component
261231
(for_pack_prefix |> Prefix.to_list))
262232
in
263-
let arguments =
264-
ListLabels.sort
265-
~cmp:(fun (p1, _v1) (p2, _v2) -> Name.compare p1 p2)
266-
arguments
267-
in
268-
if empty_prefix && empty_arguments
233+
if empty_prefix
269234
then Sys.opaque_identity (Obj.repr name)
270-
else Sys.opaque_identity (Obj.repr { for_pack_prefix; name; arguments })
235+
else Sys.opaque_identity (Obj.repr { for_pack_prefix; name })
271236
end
272237

273238
include T0
274239

275-
let create prefix name = create_full prefix name []
276-
277240
let create_child parent name_ =
278-
if not (Prefix.is_empty (for_pack_prefix parent))
279-
then
280-
(* CR-someday lmaurer: Same as for [create_full] *)
281-
raise (Error (Child_of_instance { child_name = name_ |> Name.to_string }));
282241
let prefix =
283242
(for_pack_prefix parent |> Prefix.to_list) @ [name parent] |> Prefix.of_list
284243
in
@@ -294,10 +253,6 @@ let of_string str =
294253
Prefix.empty, Name.of_string str
295254
| Some _ -> Misc.fatal_errorf "[of_string] does not parse qualified names"
296255
in
297-
let () =
298-
if String.contains str '['
299-
then Misc.fatal_error "[of_string] does not parse instances"
300-
in
301256
create for_pack_prefix name
302257

303258
let dummy = create Prefix.empty (Name.of_string "*none*")
@@ -313,67 +268,30 @@ let is_packed t = not (Prefix.is_empty (for_pack_prefix t))
313268
include Identifiable.Make (struct
314269
type nonrec t = t
315270

316-
let rec compare t1 t2 =
271+
let compare t1 t2 =
317272
if t1 == t2
318273
then 0
319274
else
320-
let { for_pack_prefix = for_pack_prefix1;
321-
name = name1;
322-
arguments = args1
323-
} =
324-
descr t1
325-
in
326-
let { for_pack_prefix = for_pack_prefix2;
327-
name = name2;
328-
arguments = args2
329-
} =
330-
descr t2
331-
in
275+
let for_pack_prefix1, name1 = for_pack_prefix_and_name t1 in
276+
let for_pack_prefix2, name2 = for_pack_prefix_and_name t2 in
332277
let c = Name.compare name1 name2 in
333-
if c <> 0
334-
then c
335-
else
336-
let c = Prefix.compare for_pack_prefix1 for_pack_prefix2 in
337-
if c <> 0 then c else List.compare compare_args args1 args2
338-
339-
and compare_args (param1, value1) (param2, value2) =
340-
let c = Name.compare param1 param2 in
341-
if c <> 0 then c else compare value1 value2
278+
if c <> 0 then c else Prefix.compare for_pack_prefix1 for_pack_prefix2
342279

343280
let equal x y = if x == y then true else compare x y = 0
344281

345-
let rec print fmt t =
346-
let { for_pack_prefix; name; arguments } = descr t in
347-
let () =
348-
if Prefix.is_empty for_pack_prefix
349-
then Format.fprintf fmt "%a" Name.print name
350-
else
351-
Format.fprintf fmt "%a.%a" Prefix.print for_pack_prefix Name.print name
352-
in
353-
ListLabels.iter ~f:(print_arg fmt) arguments
354-
355-
and print_arg fmt (param, value) =
356-
Format.fprintf fmt "[%a:%a]" Name.print param print value
282+
let print fmt t =
283+
let for_pack_prefix, name = for_pack_prefix_and_name t in
284+
if Prefix.is_empty for_pack_prefix
285+
then Format.fprintf fmt "%a" Name.print name
286+
else Format.fprintf fmt "%a.%a" Prefix.print for_pack_prefix Name.print name
357287

358288
let output = output_of_print print
359289

360-
let rec hash t =
361-
let { for_pack_prefix; name; arguments } = descr t in
362-
Hashtbl.hash
363-
( Name.hash name,
364-
Prefix.hash for_pack_prefix,
365-
ListLabels.map ~f:hash_arg arguments )
366-
367-
and hash_arg (param, value) = Hashtbl.hash (param, hash value)
290+
let hash t =
291+
let for_pack_prefix, name = for_pack_prefix_and_name t in
292+
Hashtbl.hash (Name.hash name, Prefix.hash for_pack_prefix)
368293
end)
369294

370-
let is_instance t = match arguments t with [] -> false | _ :: _ -> true
371-
372-
let create_instance t args =
373-
if is_instance t
374-
then Misc.fatal_errorf "@[<hov 1>Already an instance:@ %a@]" print t;
375-
create_full (for_pack_prefix t) (name t) args
376-
377295
let full_path t = Prefix.to_list (for_pack_prefix t) @ [name t]
378296

379297
let is_parent t ~child =

utils/compilation_unit.mli

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ val create : Prefix.t -> Name.t -> t
9595
parent compilation unit as the prefix. *)
9696
val create_child : t -> Name.t -> t
9797

98-
(** Create a compilation unit that's an instantiation of another unit with
99-
given arguments. The arguments will be sorted alphabetically by
100-
parameter name. *)
101-
val create_instance : t -> (Name.t * t) list -> t
102-
10398
(** Create a compilation unit from the given [name]. No prefix is allowed;
10499
throws a fatal error if there is a "." in the name. (As a special case,
105100
a "." is allowed as the first character, to handle compilation units
@@ -195,19 +190,9 @@ val full_path : t -> Name.t list
195190
usual conventions. *)
196191
val full_path_as_string : t -> string
197192

198-
(** Returns the arguments in the compilation unit, if it is an instance, or
199-
the empty list otherwise. *)
200-
val arguments : t -> (Name.t * t) list
201-
202-
(** Returns [true] iff the given compilation unit is an instance (equivalent
203-
to [arguments t <> []]). *)
204-
val is_instance : t -> bool
205-
206193
type error = private
207194
| Invalid_character of char * string
208195
| Bad_compilation_unit_name of string
209-
| Child_of_instance of { child_name : string }
210-
| Packed_instance of { name : string }
211196

212197
(** The exception raised by conversion functions in this module. *)
213198
exception Error of error

0 commit comments

Comments
 (0)