Skip to content

Commit

Permalink
Add debugging printers for uniqueness
Browse files Browse the repository at this point in the history
Sadly this doesn't actually work in the debugger.
  • Loading branch information
goldfirere committed Oct 25, 2024
1 parent 33b3634 commit fd050dc
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 3 deletions.
10 changes: 10 additions & 0 deletions ocaml/tools/debug_printers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ let sort = Jkind.Sort.Debug_printers.t
let sort_var = Jkind.Sort.Debug_printers.var
let jkind = Jkind.Debug_printers.t
let zero_alloc_var = Zero_alloc.debug_printer
let maybe_unique = Uniqueness_analysis.Maybe_unique.print
let maybe_aliased = Uniqueness_analysis.Maybe_aliased.print
let aliased = Uniqueness_analysis.Aliased.print
let tag = Uniqueness_analysis.Tag.print
let projection = Uniqueness_analysis.Projection.print
let usage_tree = Uniqueness_analysis.Usage_tree.print
let usage_forest = Uniqueness_analysis.Usage_forest.print
let paths = Uniqueness_analysis.Paths.print
let value = Uniqueness_analysis.Value.print
let ienv = Uniqueness_analysis.Ienv.print
1 change: 1 addition & 0 deletions ocaml/typing/ident.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include Identifiable.S with type t := t
- [compare] compares identifiers by binding location
*)

val print : Format.formatter -> t -> unit
val print_with_scope : Format.formatter -> t -> unit
(** Same as {!print} except that it will also add a "[n]" suffix
if the scope of the argument is [n]. *)
Expand Down
5 changes: 2 additions & 3 deletions ocaml/typing/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ open Mode
open Typedtree
open Btype
open Ctype
open Uniqueness_analysis

type comprehension_type =
| List_comprehension
Expand Down Expand Up @@ -9702,11 +9701,11 @@ and type_send env loc explanation e met =
let maybe_check_uniqueness_exp exp =
if Language_extension.is_enabled Unique then
check_uniqueness_exp exp
Uniqueness_analysis.check_uniqueness_exp exp
let maybe_check_uniqueness_value_bindings vbl =
if Language_extension.is_enabled Unique then
check_uniqueness_value_bindings vbl
Uniqueness_analysis.check_uniqueness_value_bindings vbl
(* Typing of toplevel bindings *)
Expand Down
16 changes: 16 additions & 0 deletions ocaml/typing/typedtree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,26 @@ module Unique_barrier = struct
if Language_extension.is_enabled Unique then
Misc.fatal_error "A unique barrier was not enabled by the analysis"
else Uniqueness.Const.Aliased

let print ppf t =
let open Format in
let print = function
| Enabled u -> fprintf ppf "Enabled(%a)" (Mode.Uniqueness.print ()) u
| Resolved uc ->
fprintf ppf "Resolved(%a)" Mode.Uniqueness.Const.print uc
| Not_computed -> fprintf ppf "Not_computed"
in
print !t
end

type unique_use = Mode.Uniqueness.r * Mode.Linearity.l

let print_unique_use ppf (u,l) =
let open Format in
fprintf ppf "@[(%a,@ %a)@]"
(Mode.Uniqueness.print ()) u
(Mode.Linearity.print ()) l

type alloc_mode = {
mode : Mode.Alloc.r;
locality_context : Env.locality_context option;
Expand Down
4 changes: 4 additions & 0 deletions ocaml/typing/typedtree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ module Unique_barrier : sig

(* Resolve the unique barrier once type-checking is complete. *)
val resolve : t -> Mode.Uniqueness.Const.t

val print : Format.formatter -> t -> unit
end

(** A unique use annotates accesses to an allocation.
Expand All @@ -98,6 +100,8 @@ end
its actual_mode will have to be many. *)
type unique_use = Mode.Uniqueness.r * Mode.Linearity.l

val print_unique_use : Format.formatter -> unique_use -> unit

type alloc_mode = {
mode : Mode.Alloc.r;
locality_context : Env.locality_context option;
Expand Down
Loading

0 comments on commit fd050dc

Please sign in to comment.