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

Refactor Debuginfo.compare #3119

Merged
merged 1 commit into from
Oct 17, 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
19 changes: 12 additions & 7 deletions ocaml/lambda/debuginfo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,7 @@ let item_with_uid_and_function_symbol item ~dinfo_uid ~dinfo_function_symbol =
module Dbg = struct
type t = item list

(* CR-someday afrisch: FWIW, the current compare function does not seem very
good, since it reverses the two lists. I don't know how long the lists are,
nor if the specific currently implemented ordering is useful in other
contexts, but if one wants to use Map, a more efficient comparison should
be considered. *)
let compare dbg1 dbg2 =
let[@inline always] compare_aux dbg1 dbg2 =
let rec loop ds1 ds2 =
match ds1, ds2 with
| [], [] -> 0
Expand All @@ -240,7 +235,17 @@ module Dbg = struct
if c <> 0 then c else
loop ds1 ds2
in
loop (List.rev dbg1) (List.rev dbg2)
loop dbg1 dbg2

(* CR-someday afrisch: FWIW, the current compare function does not seem very
good, since it reverses the two lists. I don't know how long the lists are,
nor if the specific currently implemented ordering is useful in other
contexts, but if one wants to use Map, a more efficient comparison should
be considered. *)
let compare dbg1 dbg2 = compare_aux (List.rev dbg1) (List.rev dbg2)

(* Outermost inlined location first. *)
let compare_outer_first dbg1 dbg2 = compare_aux dbg1 dbg2

let is_none dbg =
match dbg with
Expand Down
7 changes: 7 additions & 0 deletions ocaml/lambda/debuginfo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ module Dbg : sig
(** [compare] and [hash] ignore [dinfo_scopes] field of item *)

val is_none : t -> bool

(** [compare] Inner-most inlined debug info is used first. Allocates. *)
val compare : t -> t -> int

(** [compare_outer_first] Outer-most inlined debug info is used first.
Does not allocate. *)
val compare_outer_first : t -> t -> int

val hash : t -> int
val to_list : t -> item list
val length : t -> int
Expand Down
Loading