Skip to content

Commit

Permalink
Reimplement depth variables as variables (#472)
Browse files Browse the repository at this point in the history
Depth variables will now work exactly like variables in most respects.
Like a normal variable, a depth variable has a type with an Flambda
kind, only the kind must be the new kind `Rec_info` established in #465.
  • Loading branch information
lukemaurer authored Jun 25, 2021
1 parent df10ad7 commit e9c60d4
Show file tree
Hide file tree
Showing 28 changed files with 83 additions and 481 deletions.
76 changes: 13 additions & 63 deletions .depend

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions compilerlibs/Makefile.compilerlibs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ MIDDLE_END_FLAMBDA_COMPILENV_DEPS=\
middle_end/flambda/compilenv_deps/target_imm.cmo \
middle_end/flambda/compilenv_deps/flambda_colours.cmo \
middle_end/flambda/compilenv_deps/compilation_unit.cmo \
middle_end/flambda/compilenv_deps/depth_variable.cmo \
middle_end/flambda/compilenv_deps/rec_info.cmo \
middle_end/flambda/compilenv_deps/coercion.cmo \
middle_end/flambda/compilenv_deps/reg_width_things.cmo \
Expand Down Expand Up @@ -247,7 +246,6 @@ MIDDLE_END_FLAMBDA_NAMING=\
middle_end/flambda/naming/var_in_binding_pos.cmo \
middle_end/flambda/naming/bindable.cmo \
middle_end/flambda/terms/bound_symbols.cmo \
middle_end/flambda/naming/bindable_depth_variable.cmo \
middle_end/flambda/naming/bindable_let_bound.cmo \
middle_end/flambda/naming/bindable_continuation.cmo \
middle_end/flambda/naming/bindable_exn_continuation.cmo \
Expand Down
94 changes: 0 additions & 94 deletions middle_end/flambda/compilenv_deps/depth_variable.ml

This file was deleted.

39 changes: 0 additions & 39 deletions middle_end/flambda/compilenv_deps/depth_variable.mli

This file was deleted.

2 changes: 1 addition & 1 deletion middle_end/flambda/from_lambda/closure_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ let close_one_function acc ~external_env ~by_closure_id decl
let my_closure = Variable.create "my_closure" in
let closure_id = Function_decl.closure_id decl in
let my_closure_id = closure_id in
let my_depth = Depth_variable.create "my_depth" in
let my_depth = Variable.create "my_depth" in
let our_let_rec_ident = Function_decl.let_rec_ident decl in
let compilation_unit = Compilation_unit.get_current_exn () in
let code_id =
Expand Down
39 changes: 0 additions & 39 deletions middle_end/flambda/naming/bindable_depth_variable.ml

This file was deleted.

27 changes: 0 additions & 27 deletions middle_end/flambda/naming/bindable_depth_variable.mli

This file was deleted.

48 changes: 10 additions & 38 deletions middle_end/flambda/naming/bindable_let_bound.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type t =
| Symbols of symbols
(* CR mshinwell: Add a case here for let-code and move it out of
Symbols *)
| Depth of Bindable_depth_variable.t

include Identifiable.Make (struct
type nonrec t = t
Expand All @@ -48,7 +47,6 @@ include Identifiable.Make (struct
)@]"
Bound_symbols.print bound_symbols
Symbol_scoping_rule.print scoping_rule
| Depth depth_variable -> Depth_variable.print ppf depth_variable

(* The following would only be required if using
[Name_abstraction.Make_map], which we don't with this module. *)
Expand Down Expand Up @@ -82,8 +80,6 @@ let free_names t =
closure_vars
| Symbols { bound_symbols; scoping_rule = _; } ->
Bound_symbols.free_names bound_symbols
| Depth depth_variable ->
Name_occurrences.singleton_depth_variable depth_variable

let apply_renaming t perm =
match t with
Expand All @@ -105,10 +101,6 @@ let apply_renaming t perm =
in
if bound_symbols == bound_symbols' then t
else Symbols { scoping_rule; bound_symbols = bound_symbols'; }
| Depth dv ->
let dv' = Bindable_depth_variable.apply_renaming dv perm in
if dv == dv' then t
else Depth dv'

let all_ids_for_export t =
match t with
Expand All @@ -122,8 +114,6 @@ let all_ids_for_export t =
closure_vars
| Symbols { bound_symbols; scoping_rule = _; } ->
Bound_symbols.all_ids_for_export bound_symbols
| Depth depth_variable ->
Bindable_depth_variable.all_ids_for_export depth_variable

let rename t =
match t with
Expand All @@ -134,7 +124,6 @@ let rename t =
in
Set_of_closures { name_mode; closure_vars; }
| Symbols _ -> t
| Depth d -> Depth (Bindable_depth_variable.rename d)

let add_to_name_permutation t1 ~guaranteed_fresh:t2 perm =
match t1, t2 with
Expand All @@ -160,9 +149,7 @@ let add_to_name_permutation t1 ~guaranteed_fresh:t2 perm =
print t1
print t2
| Symbols _, Symbols _ -> perm
| Depth dv1, Depth dv2 ->
Renaming.add_fresh_depth_variable perm dv1 ~guaranteed_fresh:dv2
| (Singleton _ | Set_of_closures _ | Symbols _ | Depth _), _ ->
| (Singleton _ | Set_of_closures _ | Symbols _), _ ->
Misc.fatal_errorf "Kind mismatch:@ %a@ and@ %a"
print t1
print t2
Expand Down Expand Up @@ -202,15 +189,11 @@ let set_of_closures ~closure_vars =
let symbols bound_symbols scoping_rule =
Symbols { bound_symbols; scoping_rule; }

let depth depth_variable =
Depth depth_variable

let name_mode t =
match t with
| Singleton var -> Var_in_binding_pos.name_mode var
| Set_of_closures { name_mode; _ } -> name_mode
| Symbols _ -> Name_mode.normal
| Depth _ -> Name_mode.normal

let with_name_mode t name_mode =
match t with
Expand All @@ -219,69 +202,58 @@ let with_name_mode t name_mode =
| Set_of_closures { name_mode = _; closure_vars; } ->
Set_of_closures { name_mode; closure_vars; }
| Symbols _ -> t
| Depth _ -> t

let must_be_singleton t =
match t with
| Singleton var -> var
| Set_of_closures _ | Symbols _ | Depth _ ->
| Set_of_closures _ | Symbols _ ->
Misc.fatal_errorf "Bound name is not a [Singleton]:@ %a" print t

let must_be_singleton_opt t =
match t with
| Singleton var -> Some var
| Set_of_closures _ | Symbols _ | Depth _ -> None
| Set_of_closures _ | Symbols _ -> None

let must_be_set_of_closures t =
match t with
| Set_of_closures { closure_vars; _ } -> closure_vars
| Singleton _ | Symbols _ | Depth _ ->
| Singleton _ | Symbols _ ->
Misc.fatal_errorf "Bound name is not a [Set_of_closures]:@ %a" print t

let must_be_symbols t =
match t with
| Symbols symbols -> symbols
| Singleton _ | Set_of_closures _ | Depth _ ->
| Singleton _ | Set_of_closures _ ->
Misc.fatal_errorf "Bound name is not a [Set_of_closures]:@ %a" print t

let must_be_depth t =
match t with
| Depth depth_variable -> depth_variable
| Singleton _ | Set_of_closures _ | Symbols _ ->
Misc.fatal_errorf "Bound name is not a [Depth_variable]:@ %a" print t

let exists_all_bound_vars t ~f =
match t with
| Singleton var -> f var
| Set_of_closures { closure_vars; _ } -> ListLabels.exists closure_vars ~f
| Symbols _
| Depth _ -> false
| Symbols _ -> false

let fold_all_bound_vars t ~init ~f =
match t with
| Singleton var -> f init var
| Set_of_closures { closure_vars; _ } ->
ListLabels.fold_left closure_vars ~init ~f
| Symbols _
| Depth _ -> init
| Symbols _ -> init

let all_bound_vars t =
match t with
| Singleton var -> Var_in_binding_pos.Set.singleton var
| Set_of_closures { closure_vars; _ } ->
Var_in_binding_pos.Set.of_list closure_vars
| Symbols _
| Depth _ -> Var_in_binding_pos.Set.empty
| Symbols _ -> Var_in_binding_pos.Set.empty

let all_bound_vars' t =
match t with
| Singleton var -> Variable.Set.singleton (Var_in_binding_pos.var var)
| Set_of_closures { closure_vars; _ } ->
Variable.Set.of_list (List.map Var_in_binding_pos.var closure_vars)
| Symbols _
| Depth _ -> Variable.Set.empty
| Symbols _ -> Variable.Set.empty

let let_symbol_scoping_rule t =
match t with
| Singleton _ | Set_of_closures _ | Depth _ -> None
| Singleton _ | Set_of_closures _ -> None
| Symbols { scoping_rule; _ } -> Some scoping_rule
Loading

0 comments on commit e9c60d4

Please sign in to comment.