Skip to content

Commit

Permalink
Revert back to old freeing scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
tjammer committed Dec 20, 2023
1 parent c0211c6 commit b7a7681
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 464 deletions.
6 changes: 3 additions & 3 deletions lib/codegen/autogen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Make (T : Lltypes_intf.S) (H : Helpers.S) (Arr : Arr_intf.S) = struct
open Arr
open Malloc_types

type func = Copy | Free | Free_except of Part_set.t
type func = Copy | Free | Free_except of Pset.t

let func_tbl = Hashtbl.create 64
let cls_func_tbl = Hashtbl.create 64
Expand All @@ -32,7 +32,7 @@ module Make (T : Lltypes_intf.S) (H : Helpers.S) (Arr : Arr_intf.S) = struct

let path_name pset =
let show_path path = String.concat "-" (List.map string_of_int path) in
String.concat "." (Part_set.ints pset |> Seq.map show_path |> List.of_seq)
String.concat "." (Pset.to_seq pset |> Seq.map show_path |> List.of_seq)

let name typ = function
| Copy -> "__copy_" ^ Monomorph_tree.short_name ~closure:false typ
Expand Down Expand Up @@ -338,7 +338,7 @@ module Make (T : Lltypes_intf.S) (H : Helpers.S) (Arr : Arr_intf.S) = struct
make_ptr param v |> free_call

let free_except param pset v =
if Part_set.is_empty pset then free param v
if Pset.is_empty pset then free param v
else if contains_allocation v.typ then
let () = decl_children_exc pset v v.typ in
make_ptr param v |> free_except_call pset
Expand Down
2 changes: 1 addition & 1 deletion lib/codegen/autogen_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module type S = sig

val copy : param -> Monomorph_tree.alloca -> llvar -> llvar
val free : param -> llvar -> unit
val free_except : param -> Malloc_types.Part_set.t -> llvar -> unit
val free_except : param -> Malloc_types.Pset.t -> llvar -> unit
val gen_functions : unit -> unit

(* Closures *)
Expand Down
13 changes: 6 additions & 7 deletions lib/codegen/codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ end = struct
List.iter
(fun i ->
(* Printf.printf "freeing except %i with paths %s, is %b\n" i.id *)
(* (Part_set.show i.paths) *)
(* (show_pset i.paths) *)
(* (Option.is_some (Hashtbl.find_opt free_tbl i.id)); *)
Option.iter
(Auto.free_except param i.paths)
Expand All @@ -1243,16 +1243,15 @@ end = struct
List.iter
(fun i ->
(* Printf.printf "freeing only %i with paths %s\n" i.id *)
(* (Part_set.show i.paths); *)
(* (show_pset i.paths); *)
Option.iter
(fun init ->
(* TODO check for empty in monomorph_tree *)
if Part_set.is_empty i.paths then Auto.free param init
if Pset.is_empty i.paths then Auto.free param init
else
Part_set.fold
(fun path () ->
get_path (Part.ints path) init |> Auto.free param)
i.paths ())
Pset.iter
(fun path -> get_path path init |> Auto.free param)
i.paths)
(Hashtbl.find_opt free_tbl i.id))
fs);

Expand Down
Loading

0 comments on commit b7a7681

Please sign in to comment.